hopefully this commit will not break other things....
[senf.git] / 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 // Unit tests
24
25 //#include "TransportPacket.test.hh"
26 //#include "TransportPacket.test.ih"
27
28 // Custom includes
29 #include "TransportPacket.hh"
30
31 #include "../../Utils/auto_unit_test.hh"
32 #include <boost/test/test_tools.hpp>
33 #include <senf/Utils/hexdump.hh>
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
92
93 BOOST_AUTO_UNIT_TEST(transportPacket_create_with_pusi)
94 {
95     TransportPacket ts_packet (TransportPacket::create());
96     ts_packet->setPUSI(true);
97     ts_packet->pid() = 0x010fu;
98     ts_packet->continuity_counter() = 0x0eu;
99     
100     unsigned char payload_data[] = {  // see test above 
101             // SNDU Header
102             0x80, 0x4c, 0x86, 0xdd,
103             // IPv6 Packet
104             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
105             0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106             0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
107             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
108             0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
109             0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
110             0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
111             0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
112             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
113             // SNDU footer (crc-32)
114             0x1d, 0xc4, 0xe8, 0xc1
115     };
116     senf::DataPacket payload (senf::DataPacket::createAfter( ts_packet, payload_data));
117     
118     //TransportPacketType::addStuffingPacketAfter( ts_packet);
119     
120     //senf::hexdump(ts_packet.data().begin(), ts_packet.data().end(), std::cout);
121 }
122
123 ///////////////////////////////cc.e////////////////////////////////////////
124 #undef prefix_
125
126 \f
127 // Local Variables:
128 // mode: c++
129 // fill-column: 100
130 // c-file-style: "senf"
131 // indent-tabs-mode: nil
132 // ispell-local-dictionary: "american"
133 // compile-command: "scons -u test"
134 // comment-column: 40
135 // End: