4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief PacketData unit tests */
31 //#include "PacketData.test.hh"
32 //#include "PacketData.test.ih"
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 struct VoidPacket : public senf::PacketTypeBase {};
47 SENF_AUTO_UNIT_TEST(packetData)
49 // We cannot simply allocate a packetData instance .. we must go through PacketInterpreterBase
52 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create());
54 senf::PacketData & d (pi->data());\
56 BOOST_CHECK( d.begin() == d.end() );
57 BOOST_CHECK_EQUAL( d.size(), 0u );
58 BOOST_CHECK( d.empty() );
60 d.insert(d.begin(), 0xabu);
61 BOOST_CHECK_EQUAL( d.size(), 1u );
62 BOOST_CHECK_EQUAL( d[0], 0xabu );
63 BOOST_CHECK( !d.empty() );
65 d.insert(d.begin(), 10, 0xcdu );
66 BOOST_CHECK_EQUAL( d.size(), 11u );
67 BOOST_CHECK_EQUAL( d[0], 0xcdu );
68 BOOST_CHECK_EQUAL( d[9], 0xcdu );
69 BOOST_CHECK_EQUAL( d[10], 0xabu );
71 senf::PacketData::byte data[] =
72 { 0xf0u, 0xf1u, 0xf2u, 0xf3u, 0xf4u, 0xf5u, 0xf6u, 0xf7u };
73 d.insert(d.begin()+5, data, data+sizeof(data)/sizeof(data[0]));
74 BOOST_CHECK_EQUAL( d.size(), 19u );
75 BOOST_CHECK_EQUAL( d[4], 0xcdu );
76 BOOST_CHECK_EQUAL( d[5], 0xf0u );
77 BOOST_CHECK_EQUAL( d[12], 0xf7u );
80 BOOST_CHECK_EQUAL( d.size(), 18u );
81 BOOST_CHECK_EQUAL( d[4], 0xf0u );
83 d.erase(d.begin(), d.begin()+11);
84 BOOST_CHECK_EQUAL( d.size(), 7u );
85 BOOST_CHECK_EQUAL( d[0], 0xf7u );
88 BOOST_CHECK_EQUAL( d.size(), 16u );
89 BOOST_CHECK_EQUAL( d[15], 0xefu );
90 BOOST_CHECK_EQUAL( d[6], 0xabu );
93 BOOST_CHECK_EQUAL( d.size(), 8u );
94 BOOST_CHECK_EQUAL( d[7], 0xefu );
97 BOOST_CHECK_EQUAL( d.size(), 0u );
98 BOOST_CHECK( d.empty() );
101 SENF_AUTO_UNIT_TEST(safePacketIterator)
103 // We cannot simply allocate a packetData instance .. we must go through PacketInterpreterBase
106 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create());
108 senf::PacketData & d (pi->data());
110 senf::safe_data_iterator i;
113 i = senf::safe_data_iterator(d);
116 BOOST_CHECK( i == senf::safe_data_iterator(d,d.begin()) );
117 BOOST_CHECK( senf::PacketData::iterator(i) == d.begin() );
119 senf::PacketData::byte data[] =
120 { 0xf0u, 0xf1u, 0xf2u, 0xf3u, 0xf4u, 0xf5u, 0xf6u, 0xf7u };
121 d.resize(sizeof(data)/sizeof(data[0]));
122 BOOST_CHECK( senf::PacketData::iterator(i) == d.begin() );
123 std::copy(data,data+sizeof(data)/sizeof(data[0]),i);
125 BOOST_CHECK_EQUAL( d.size(), sizeof(data)/sizeof(data[0]) );
126 BOOST_CHECK_EQUAL( *(i+sizeof(data)/sizeof(data[0])-1), 0xf7u );
127 BOOST_CHECK_EQUAL( std::distance(i,senf::safe_data_iterator(d,d.end())),
128 senf::PacketData::difference_type(d.size()) );
130 BOOST_CHECK_EQUAL( d[1], 0x01u );
132 BOOST_CHECK_EQUAL( d[0], 0x02u );
133 BOOST_CHECK( &d == &i.data() );
136 //-/////////////////////////////////////////////////////////////////////////////////////////////////
143 // c-file-style: "senf"
144 // indent-tabs-mode: nil
145 // ispell-local-dictionary: "american"
146 // compile-command: "scons -u test"
147 // comment-column: 40