Packets: added tests for dump methods
[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
34 #define prefix_
35 ///////////////////////////////cc.p////////////////////////////////////////
36
37 using namespace senf;
38
39 BOOST_AUTO_UNIT_TEST(transportPacket_parse)
40 {
41     // TransportStream-Packet containing a ULE encoded IPv6 ping packet,
42     // captured with dvbsnoop
43     unsigned char data[] = {
44             // Transport Packet Header
45             0x47, 0x41, 0x0f, 0x1e,
46             // Payload Pointer
47             0x00,
48             // SNDU Header
49             0x80, 0x4c, 0x86, 0xdd,
50             // IPv6 Packet
51             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
52             0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
53             0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
54             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55             0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
56             0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
57             0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
58             0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
59             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
60             // SNDU footer (crc-32)
61             0x1d, 0xc4, 0xe8, 0xc1,
62             // Transport Packet stuffing
63             0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
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
76     };
77
78     TransportPacket p (TransportPacket::create(data));
79
80     BOOST_CHECK_EQUAL(   p->sync_byte(),                TransportPacketType::SYNC_BYTE+0 );
81     BOOST_CHECK(       ! p->transport_error_indicator()                                  );
82     BOOST_CHECK(         p->pusi()                                                       );
83     BOOST_CHECK(       ! p->transport_priority()                                         );
84     BOOST_CHECK_EQUAL(   p->pid(),                      0x010fu                          );
85     BOOST_CHECK_EQUAL(   p->transport_scrmbl_ctrl(),    0x0u                             );
86     BOOST_CHECK_EQUAL(   p->adaptation_field_ctrl(),    0x1u                             );
87     BOOST_CHECK_EQUAL(   p->continuity_counter(),       0x0eu                            );
88     BOOST_CHECK_EQUAL(   p->pointer_field(),            0x0u                             );
89
90     std::ostringstream oss (std::ostringstream::out);
91     SENF_CHECK_NO_THROW( p.dump( oss));
92 }
93
94
95 BOOST_AUTO_UNIT_TEST(transportPacket_create_with_pusi)
96 {
97     TransportPacket ts_packet (TransportPacket::create());
98     ts_packet->setPUSI(true);
99     ts_packet->pid() = 0x010fu;
100     ts_packet->continuity_counter() = 0x0eu;
101
102     unsigned char payload_data[] = {  // see test above
103             // SNDU Header
104             0x80, 0x4c, 0x86, 0xdd,
105             // IPv6 Packet
106             0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x40,
107             0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
108             0x48, 0x7c, 0x7e, 0xff, 0xfe, 0x23, 0x68, 0xaf,
109             0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
110             0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,
111             0x02, 0x8c, 0x02, 0x8c, 0x00, 0x20, 0x58, 0xe1,
112             0x11, 0x05, 0x12, 0x67, 0x06, 0x2f, 0x01, 0x00,
113             0x20, 0x01, 0x06, 0x38, 0x04, 0x09, 0x10, 0x00,
114             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00,
115             // SNDU footer (crc-32)
116             0x1d, 0xc4, 0xe8, 0xc1
117     };
118     senf::DataPacket payload (senf::DataPacket::createAfter( ts_packet, payload_data));
119 }
120
121 ///////////////////////////////cc.e////////////////////////////////////////
122 #undef prefix_
123
124
125 // Local Variables:
126 // mode: c++
127 // fill-column: 100
128 // c-file-style: "senf"
129 // indent-tabs-mode: nil
130 // ispell-local-dictionary: "american"
131 // compile-command: "scons -u test"
132 // comment-column: 40
133 // End: