Parser for TLVPacket is working now, thanx to Stefan for the hint.
[senf.git] / Packets / MPEGDVBBundle / TLVPacket.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.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 "TLVPacket.test.hh"
26 //#include "TLVPacket.test.ih"
27
28 // Custom includes
29 #include "TLVPacket.hh"
30 #include <senf/Packets.hh>
31 #include <senf/Utils/hexdump.hh>
32
33 #include <boost/test/auto_unit_test.hpp>
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 using namespace senf;
40
41 BOOST_AUTO_UNIT_TEST(tlvPacket_parser)
42 {
43     // number of bytes to allocate for a new TLVPacket should be 5
44     BOOST_CHECK_EQUAL( init_bytes<Parse_TLVPacket>::value, 5u );
45 }
46
47 BOOST_AUTO_UNIT_TEST(tlvPacket_parse_packet_with_simple_length)
48 {
49     unsigned char data[] = { 
50         0x01, 0x23, 0x45, 0x67, // type
51         0x0A, // first not set, length=10
52         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // value (payload)
53     };
54             
55     senf::TLVPacket p (senf::TLVPacket::create(data));
56     
57     BOOST_CHECK_EQUAL( p->type(), 0x01234567u );
58     BOOST_CHECK_EQUAL( p->length(), 0x0Au );
59
60     PacketData & p_value (p.next().data());
61     BOOST_CHECK_EQUAL( p_value.size(), 0x0Au);
62     for (int i=0, j=p_value.size(); i<j; i++)
63         BOOST_CHECK_EQUAL( p_value[i], i);
64 }
65
66 BOOST_AUTO_UNIT_TEST(tlvPacket_parse_packet_with_extended_length)
67 {
68     unsigned char data[] = { 
69         0x01, 0x23, 0x45, 0x67, // type
70         0x81, // first and last bit set => one byte length following
71         0x0A, // length (10 bytes value)
72         0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09 // value (payload)
73     };
74             
75     senf::TLVPacket p (senf::TLVPacket::create(data));
76     
77     BOOST_CHECK_EQUAL( p->type(), 0x01234567u );
78     BOOST_CHECK_EQUAL( p->length(), 0x0Au );
79
80     PacketData & p_value (p.next().data());
81     BOOST_CHECK_EQUAL( p_value.size(), 0x0Au);
82     for (int i=0, j=p_value.size(); i<j; i++)
83         BOOST_CHECK_EQUAL( p_value[i], i);
84 }
85
86 ///////////////////////////////cc.e////////////////////////////////////////
87 #undef prefix_
88
89 \f
90 // Local Variables:
91 // mode: c++
92 // fill-column: 100
93 // c-file-style: "senf"
94 // indent-tabs-mode: nil
95 // ispell-local-dictionary: "american"
96 // compile-command: "scons -u test"
97 // comment-column: 40
98 // End: