added FormFeed character for emacs to end of files
[senf.git] / senf / Packets / MPEGDVBBundle / TransportPacket.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief TransportPacket unit tests */
25
26 //#include "TransportPacket.test.hh"
27 //#include "TransportPacket.test.ih"
28
29 // Custom includes
30 #include "TransportPacket.hh"
31
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 ///////////////////////////////cc.p////////////////////////////////////////
37
38 using namespace senf;
39
40 BOOST_AUTO_UNIT_TEST(transportPacket_parse)
41 {
42     // TransportStream-Packet containing a ULE encoded IPv6 ping packet,
43     // captured with dvbsnoop
44     unsigned char data[] = {
45             // Transport Packet Header
46             0x47, 0x41, 0x0f, 0x1e,
47             // Payload Pointer
48             0x00,
49             // SNDU Header
50             0x80, 0x4c, 0x86, 0xdd,
51             // IPv6 Packet
52             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
53             0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
54             0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
55             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
56             0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
57             0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
58             0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
59             0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
60             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
61             // SNDU footer (crc-32)
62             0x1d, 0xc4, 0xe8, 0xc1,
63             // Transport Packet stuffing
64             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
65             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
66             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
67             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
68             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
69             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
70             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
71             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
72             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
73             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
74             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
75             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
76             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
77     };
78
79     TransportPacket p (TransportPacket::create(data));
80
81     BOOST_CHECK_EQUAL(   p->sync_byte(),                TransportPacketType::SYNC_BYTE+0 );
82     BOOST_CHECK(       ! p->transport_error_indicator()                                  );
83     BOOST_CHECK(         p->pusi()                                                       );
84     BOOST_CHECK(       ! p->transport_priority()                                         );
85     BOOST_CHECK_EQUAL(   p->pid(),                      0x010fu                          );
86     BOOST_CHECK_EQUAL(   p->transport_scrmbl_ctrl(),    0x0u                             );
87     BOOST_CHECK_EQUAL(   p->adaptation_field_ctrl(),    0x1u                             );
88     BOOST_CHECK_EQUAL(   p->continuity_counter(),       0x0eu                            );
89     BOOST_CHECK_EQUAL(   p->pointer_field(),            0x0u                             );
90
91     std::ostringstream oss (std::ostringstream::out);
92     SENF_CHECK_NO_THROW( p.dump( oss));
93 }
94
95
96 BOOST_AUTO_UNIT_TEST(transportPacket_create_with_pusi)
97 {
98     TransportPacket ts_packet (TransportPacket::create());
99     ts_packet->setPUSI(true);
100     ts_packet->pid() = 0x010fu;
101     ts_packet->continuity_counter() = 0x0eu;
102
103     unsigned char payload_data[] = {  // see test above
104             // SNDU Header
105             0x80, 0x4c, 0x86, 0xdd,
106             // IPv6 Packet
107             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
108             0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
109             0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
110             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
111             0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
112             0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
113             0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
114             0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
115             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
116             // SNDU footer (crc-32)
117             0x1d, 0xc4, 0xe8, 0xc1
118     };
119     senf::DataPacket payload (senf::DataPacket::createAfter( ts_packet, payload_data));
120
121     // TODO: add method for stuffing
122 }
123
124 ///////////////////////////////cc.e////////////////////////////////////////
125 #undef prefix_
126
127 \f
128 // Local Variables:
129 // mode: c++
130 // fill-column: 100
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"
135 // comment-column: 40
136 // End: