2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 // Stefan Bund <g0dil@berlios.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief PacketData.test unit tests */
24 //#include "PacketData.test.hh"
25 //#include "PacketData.test.ih"
30 #include <boost/test/auto_unit_test.hpp>
31 #include <boost/test/test_tools.hpp>
34 ///////////////////////////////cc.p////////////////////////////////////////
37 struct VoidPacket : public senf::PacketTypeBase {};
40 BOOST_AUTO_UNIT_TEST(packetData)
42 // We cannot simply allocate a packetData instance .. we must go through PacketInterpreterBase
45 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create());
47 senf::PacketData & d (pi->data());\
49 BOOST_CHECK( d.begin() == d.end() );
50 BOOST_CHECK_EQUAL( d.size(), 0u );
51 BOOST_CHECK( d.empty() );
53 d.insert(d.begin(), 0xabu);
54 BOOST_CHECK_EQUAL( d.size(), 1u );
55 BOOST_CHECK_EQUAL( d[0], 0xabu );
56 BOOST_CHECK( !d.empty() );
58 d.insert(d.begin(), 10, 0xcdu );
59 BOOST_CHECK_EQUAL( d.size(), 11u );
60 BOOST_CHECK_EQUAL( d[0], 0xcdu );
61 BOOST_CHECK_EQUAL( d[9], 0xcdu );
62 BOOST_CHECK_EQUAL( d[10], 0xabu );
64 senf::PacketData::byte data[] =
65 { 0xf0u, 0xf1u, 0xf2u, 0xf3u, 0xf4u, 0xf5u, 0xf6u, 0xf7u };
66 d.insert(d.begin()+5, data, data+sizeof(data)/sizeof(data[0]));
67 BOOST_CHECK_EQUAL( d.size(), 19u );
68 BOOST_CHECK_EQUAL( d[4], 0xcdu );
69 BOOST_CHECK_EQUAL( d[5], 0xf0u );
70 BOOST_CHECK_EQUAL( d[12], 0xf7u );
73 BOOST_CHECK_EQUAL( d.size(), 18u );
74 BOOST_CHECK_EQUAL( d[4], 0xf0u );
76 d.erase(d.begin(), d.begin()+11);
77 BOOST_CHECK_EQUAL( d.size(), 7u );
78 BOOST_CHECK_EQUAL( d[0], 0xf7u );
81 BOOST_CHECK_EQUAL( d.size(), 16u );
82 BOOST_CHECK_EQUAL( d[15], 0xefu );
83 BOOST_CHECK_EQUAL( d[6], 0xabu );
86 BOOST_CHECK_EQUAL( d.size(), 8u );
87 BOOST_CHECK_EQUAL( d[7], 0xefu );
90 BOOST_CHECK_EQUAL( d.size(), 0u );
91 BOOST_CHECK( d.empty() );
94 BOOST_AUTO_UNIT_TEST(safePacketIterator)
96 // We cannot simply allocate a packetData instance .. we must go through PacketInterpreterBase
99 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create());
101 senf::PacketData & d (pi->data());
103 senf::safe_data_iterator i;
106 i = senf::safe_data_iterator(d);
109 BOOST_CHECK( i == senf::safe_data_iterator(d,d.begin()) );
110 BOOST_CHECK( senf::PacketData::iterator(i) == d.begin() );
112 senf::PacketData::byte data[] =
113 { 0xf0u, 0xf1u, 0xf2u, 0xf3u, 0xf4u, 0xf5u, 0xf6u, 0xf7u };
114 d.resize(sizeof(data)/sizeof(data[0]));
115 BOOST_CHECK( senf::PacketData::iterator(i) == d.begin() );
116 std::copy(data,data+sizeof(data)/sizeof(data[0]),i);
118 BOOST_CHECK_EQUAL( d.size(), sizeof(data)/sizeof(data[0]) );
119 BOOST_CHECK_EQUAL( *(i+sizeof(data)/sizeof(data[0])-1), 0xf7u );
120 BOOST_CHECK_EQUAL( std::distance(i,senf::safe_data_iterator(d,d.end())),
121 senf::PacketData::difference_type(d.size()) );
123 BOOST_CHECK_EQUAL( d[1], 0x01u );
125 BOOST_CHECK_EQUAL( d[0], 0x02u );
126 BOOST_CHECK( &d == &i.data() );
129 ///////////////////////////////cc.e////////////////////////////////////////
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"
140 // comment-column: 40