4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.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.
24 \brief PacketData.test unit tests */
26 //#include "PacketData.test.hh"
27 //#include "PacketData.test.ih"
32 #include "../Utils/auto_unit_test.hh"
33 #include <boost/test/test_tools.hpp>
36 ///////////////////////////////cc.p////////////////////////////////////////
39 struct VoidPacket : public senf::PacketTypeBase {};
42 BOOST_AUTO_UNIT_TEST(packetData)
44 // We cannot simply allocate a packetData instance .. we must go through PacketInterpreterBase
47 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create());
49 senf::PacketData & d (pi->data());\
51 BOOST_CHECK( d.begin() == d.end() );
52 BOOST_CHECK_EQUAL( d.size(), 0u );
53 BOOST_CHECK( d.empty() );
55 d.insert(d.begin(), 0xabu);
56 BOOST_CHECK_EQUAL( d.size(), 1u );
57 BOOST_CHECK_EQUAL( d[0], 0xabu );
58 BOOST_CHECK( !d.empty() );
60 d.insert(d.begin(), 10, 0xcdu );
61 BOOST_CHECK_EQUAL( d.size(), 11u );
62 BOOST_CHECK_EQUAL( d[0], 0xcdu );
63 BOOST_CHECK_EQUAL( d[9], 0xcdu );
64 BOOST_CHECK_EQUAL( d[10], 0xabu );
66 senf::PacketData::byte data[] =
67 { 0xf0u, 0xf1u, 0xf2u, 0xf3u, 0xf4u, 0xf5u, 0xf6u, 0xf7u };
68 d.insert(d.begin()+5, data, data+sizeof(data)/sizeof(data[0]));
69 BOOST_CHECK_EQUAL( d.size(), 19u );
70 BOOST_CHECK_EQUAL( d[4], 0xcdu );
71 BOOST_CHECK_EQUAL( d[5], 0xf0u );
72 BOOST_CHECK_EQUAL( d[12], 0xf7u );
75 BOOST_CHECK_EQUAL( d.size(), 18u );
76 BOOST_CHECK_EQUAL( d[4], 0xf0u );
78 d.erase(d.begin(), d.begin()+11);
79 BOOST_CHECK_EQUAL( d.size(), 7u );
80 BOOST_CHECK_EQUAL( d[0], 0xf7u );
83 BOOST_CHECK_EQUAL( d.size(), 16u );
84 BOOST_CHECK_EQUAL( d[15], 0xefu );
85 BOOST_CHECK_EQUAL( d[6], 0xabu );
88 BOOST_CHECK_EQUAL( d.size(), 8u );
89 BOOST_CHECK_EQUAL( d[7], 0xefu );
92 BOOST_CHECK_EQUAL( d.size(), 0u );
93 BOOST_CHECK( d.empty() );
96 BOOST_AUTO_UNIT_TEST(safePacketIterator)
98 // We cannot simply allocate a packetData instance .. we must go through PacketInterpreterBase
101 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create());
103 senf::PacketData & d (pi->data());
105 senf::safe_data_iterator i;
108 i = senf::safe_data_iterator(d);
111 BOOST_CHECK( i == senf::safe_data_iterator(d,d.begin()) );
112 BOOST_CHECK( senf::PacketData::iterator(i) == d.begin() );
114 senf::PacketData::byte data[] =
115 { 0xf0u, 0xf1u, 0xf2u, 0xf3u, 0xf4u, 0xf5u, 0xf6u, 0xf7u };
116 d.resize(sizeof(data)/sizeof(data[0]));
117 BOOST_CHECK( senf::PacketData::iterator(i) == d.begin() );
118 std::copy(data,data+sizeof(data)/sizeof(data[0]),i);
120 BOOST_CHECK_EQUAL( d.size(), sizeof(data)/sizeof(data[0]) );
121 BOOST_CHECK_EQUAL( *(i+sizeof(data)/sizeof(data[0])-1), 0xf7u );
122 BOOST_CHECK_EQUAL( std::distance(i,senf::safe_data_iterator(d,d.end())),
123 senf::PacketData::difference_type(d.size()) );
125 BOOST_CHECK_EQUAL( d[1], 0x01u );
127 BOOST_CHECK_EQUAL( d[0], 0x02u );
128 BOOST_CHECK( &d == &i.data() );
131 ///////////////////////////////cc.e////////////////////////////////////////
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // comment-column: 40