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 ParseListB.test unit tests */
24 //#include "ParseListB.test.hh"
25 //#include "ParseListB.test.ih"
28 #include "ParseListB.hh"
29 #include "ParseVec.hh"
30 #include "PacketType.hh"
31 #include "ParseInt.hh"
33 #include <boost/test/auto_unit_test.hpp>
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
40 struct VoidPacket : public senf::PacketTypeBase
43 typedef senf::Parse_VectorN<senf::Parse_UInt16,senf::Parse_UInt8>::parser ParseVec;
44 typedef senf::Parse_ListB<ParseVec,senf::Parse_UInt16>::parser ParseList;
47 BOOST_AUTO_UNIT_TEST(parseListB)
49 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
50 ParseList::init_bytes));
52 ParseList p (pi->data().begin(),&pi->data());
54 BOOST_CHECK_EQUAL( p.size(), 0u );
55 BOOST_CHECK_EQUAL( p.bytes(), 2u );
56 BOOST_CHECK( p.empty() );
57 BOOST_CHECK( p.begin() == p.end() );
59 // the mutators are really tested together with the container wrappers since they are based
60 // on the container wrapper. Here we only need one call to make the list larger ...
63 p = ParseList(pi->data().begin(),&pi->data());
64 BOOST_CHECK_EQUAL( p.bytes(), 3u );
65 BOOST_CHECK_EQUAL( p.size(), 1u );
66 BOOST_CHECK( ! p.empty() );
67 BOOST_CHECK( p.begin() != p.end() );
70 BOOST_AUTO_UNIT_TEST(parseListB_container)
72 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
73 ParseList::init_bytes));
76 ParseList::container c (ParseList(pi->data().begin(),&pi->data()));
78 BOOST_CHECK_EQUAL( c.size(), 0u );
79 BOOST_CHECK_EQUAL( c.bytes(), 2u );
80 BOOST_CHECK( c.begin() == c.end() );
83 BOOST_CHECK_EQUAL( c.size(), 1u );
84 BOOST_CHECK_EQUAL( c.bytes(), 3u );
86 BOOST_CHECK_EQUAL( c.front().size(), 0u );
87 c.front().push_back(0x1234u);
88 BOOST_CHECK_EQUAL( c.bytes(), 5u );
91 senf::PacketInterpreterBase::ptr pi2 (senf::PacketInterpreter<VoidPacket>::create(
92 ParseList::init_bytes));
93 ParseList::container c2 (ParseList(pi2->data().begin(),&pi2->data()));
96 ParseVec::container c2v (c2.front());
97 c2v.push_back(0x2345u);
98 c2v.push_back(0x3456u);
101 BOOST_CHECK_EQUAL(c2.size(), 1u);
102 BOOST_CHECK_EQUAL(c2.bytes(), 7u);
104 c.insert(c.end(),c2.back());
105 BOOST_CHECK_EQUAL( c.size(), 2u );
106 BOOST_CHECK_EQUAL( c.bytes(), 10u );
107 BOOST_CHECK_EQUAL( c.back()[0], 0x2345u );
108 BOOST_CHECK_EQUAL( c.back().bytes(), c2.back().bytes() );
110 c2.back()[0] << 0x1357u;
111 c.insert(boost::next(c.begin()), 2u, c2.back());
112 BOOST_CHECK_EQUAL( c.size(), 4u );
113 BOOST_CHECK_EQUAL( c.bytes(), 20u );
114 BOOST_CHECK_EQUAL( (*boost::next(c.begin()))[0], 0x1357u );
115 BOOST_CHECK_EQUAL( (*boost::next(c.begin(),2))[0], 0x1357u );
117 c2.back()[0] << 0x2468u;
118 c.insert(c.begin(),c2.begin(),c2.end());
119 BOOST_CHECK_EQUAL( c.size(), 5u );
120 BOOST_CHECK_EQUAL( c.bytes(), 25u );
121 BOOST_CHECK_EQUAL( c.front()[0], 0x2468u );
123 c.erase(c.begin(),2);
124 BOOST_CHECK_EQUAL( c.size(), 3u );
125 BOOST_CHECK_EQUAL( c.bytes(), 17u );
126 BOOST_CHECK_EQUAL( c.front()[0],0x1357u );
127 BOOST_CHECK_EQUAL( c.back()[0], 0x2345u );
129 c.erase((boost::next(c.begin(),2)),c.end());
130 BOOST_CHECK_EQUAL( c.size(), 2u );
131 BOOST_CHECK_EQUAL( c.bytes(), 12u );
132 BOOST_CHECK_EQUAL( c.front()[0],0x1357u );
133 BOOST_CHECK_EQUAL( c.back()[0], 0x1357u );
136 BOOST_CHECK_EQUAL( c.size(), 0u );
137 BOOST_CHECK_EQUAL( c.bytes(), 2u );
142 ///////////////////////////////cc.e////////////////////////////////////////
149 // comment-column: 40
150 // c-file-style: "senf"
151 // indent-tabs-mode: nil
152 // ispell-local-dictionary: "american"
153 // compile-command: "scons -u test"