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"
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 typedef senf::Parse_VectorN<senf::Parse_UInt16,senf::Parse_UInt8>::parser ParseVec;
41 typedef senf::Parse_ListB<ParseVec,senf::Parse_UInt16>::parser ParseList;
44 BOOST_AUTO_UNIT_TEST(parseListB)
46 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
47 ParseList::init_bytes));
49 ParseList p (pi->data().begin(),&pi->data());
51 BOOST_CHECK_EQUAL( p.size(), 0u );
52 BOOST_CHECK_EQUAL( p.bytes(), 2u );
53 BOOST_CHECK( p.empty() );
54 BOOST_CHECK( p.begin() == p.end() );
56 // the mutators are really tested together with the container wrappers since they are based
57 // on the container wrapper. Here we only need one call to make the list larger ...
60 p = ParseList(pi->data().begin(),&pi->data());
61 BOOST_CHECK_EQUAL( p.bytes(), 3u );
62 BOOST_CHECK_EQUAL( p.size(), 1u );
63 BOOST_CHECK( ! p.empty() );
64 BOOST_CHECK( p.begin() != p.end() );
67 BOOST_AUTO_UNIT_TEST(parseListB_container)
69 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
70 ParseList::init_bytes));
73 ParseList::container c (ParseList(pi->data().begin(),&pi->data()));
75 BOOST_CHECK_EQUAL( c.size(), 0u );
76 BOOST_CHECK_EQUAL( c.bytes(), 2u );
77 BOOST_CHECK( c.begin() == c.end() );
80 BOOST_CHECK_EQUAL( c.size(), 1u );
81 BOOST_CHECK_EQUAL( c.bytes(), 3u );
83 BOOST_CHECK_EQUAL( c.front().size(), 0u );
84 c.front().push_back(0x1234u);
85 BOOST_CHECK_EQUAL( c.bytes(), 5u );
88 senf::PacketInterpreterBase::ptr pi2 (senf::PacketInterpreter<VoidPacket>::create(
89 ParseList::init_bytes));
90 ParseList::container c2 (ParseList(pi2->data().begin(),&pi2->data()));
93 ParseVec::container c2v (c2.front());
94 c2v.push_back(0x2345u);
95 c2v.push_back(0x3456u);
98 BOOST_CHECK_EQUAL(c2.size(), 1u);
99 BOOST_CHECK_EQUAL(c2.bytes(), 7u);
101 c.insert(c.end(),c2.back());
102 BOOST_CHECK_EQUAL( c.size(), 2u );
103 BOOST_CHECK_EQUAL( c.bytes(), 10u );
104 BOOST_CHECK_EQUAL( c.back()[0], 0x2345u );
105 BOOST_CHECK_EQUAL( c.back().bytes(), c2.back().bytes() );
107 c2.back()[0] << 0x1357u;
108 c.insert(boost::next(c.begin()), 2u, c2.back());
109 BOOST_CHECK_EQUAL( c.size(), 4u );
110 BOOST_CHECK_EQUAL( c.bytes(), 20u );
111 BOOST_CHECK_EQUAL( (*boost::next(c.begin()))[0], 0x1357u );
112 BOOST_CHECK_EQUAL( (*boost::next(c.begin(),2))[0], 0x1357u );
114 c2.back()[0] << 0x2468u;
115 c.insert(c.begin(),c2.begin(),c2.end());
116 BOOST_CHECK_EQUAL( c.size(), 5u );
117 BOOST_CHECK_EQUAL( c.bytes(), 25u );
118 BOOST_CHECK_EQUAL( c.front()[0], 0x2468u );
120 c.erase(c.begin(),2);
121 BOOST_CHECK_EQUAL( c.size(), 3u );
122 BOOST_CHECK_EQUAL( c.bytes(), 17u );
123 BOOST_CHECK_EQUAL( c.front()[0],0x1357u );
124 BOOST_CHECK_EQUAL( c.back()[0], 0x2345u );
126 c.erase((boost::next(c.begin(),2)),c.end());
127 BOOST_CHECK_EQUAL( c.size(), 2u );
128 BOOST_CHECK_EQUAL( c.bytes(), 12u );
129 BOOST_CHECK_EQUAL( c.front()[0],0x1357u );
130 BOOST_CHECK_EQUAL( c.back()[0], 0x1357u );
133 BOOST_CHECK_EQUAL( c.size(), 0u );
134 BOOST_CHECK_EQUAL( c.bytes(), 2u );
139 ///////////////////////////////cc.e////////////////////////////////////////
146 // comment-column: 40
147 // c-file-style: "senf"
148 // indent-tabs-mode: nil
149 // ispell-local-dictionary: "american"
150 // compile-command: "scons -u test"