4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Thorsten Horstmann <thorsten.horstmann@fokus.fraunhofer.de>
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.
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.
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.
25 //#include "TLVPacket.test.hh"
26 //#include "TLVPacket.test.ih"
29 #include "TLVPacket.hh"
30 #include <senf/Packets.hh>
31 #include <senf/Utils/hexdump.hh>
33 #include <boost/test/auto_unit_test.hpp>
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
41 BOOST_AUTO_UNIT_TEST(tlvPacket_parser)
43 // number of bytes to allocate for a new TLVPacket should be 5
44 BOOST_CHECK_EQUAL( init_bytes<Parse_TLVPacket>::value, 5u );
47 BOOST_AUTO_UNIT_TEST(tlvPacket_parse_packet_with_simple_length)
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)
55 senf::TLVPacket p (senf::TLVPacket::create(data));
57 BOOST_CHECK_EQUAL( p->type(), 0x01234567u );
58 BOOST_CHECK_EQUAL( p->length(), 0x0Au );
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);
66 BOOST_AUTO_UNIT_TEST(tlvPacket_parse_packet_with_extended_length)
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)
75 senf::TLVPacket p (senf::TLVPacket::create(data));
77 BOOST_CHECK_EQUAL( p->type(), 0x01234567u );
78 BOOST_CHECK_EQUAL( p->length(), 0x0Au );
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);
86 ///////////////////////////////cc.e////////////////////////////////////////
93 // c-file-style: "senf"
94 // indent-tabs-mode: nil
95 // ispell-local-dictionary: "american"
96 // compile-command: "scons -u test"