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 "../Utils/auto_unit_test.hh"
31 #include <boost/test/test_tools.hpp>
34 ///////////////////////////////cc.p////////////////////////////////////////
37 struct VoidPacket : public senf::PacketTypeBase
40 struct ParseVec : public senf::PacketParserBase
42 # include SENF_PARSER()
44 SENF_PARSER_PRIVATE_FIELD( size, senf::Parse_UInt8 );
45 SENF_PARSER_VEC_N( vec, size, senf::Parse_UInt16 );
47 SENF_PARSER_FINALIZE(ParseVec);
50 typedef senf::Parse_ListB<ParseVec,senf::Parse_UInt16>::parser ParseList;
53 BOOST_AUTO_UNIT_TEST(parseListB)
55 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
56 ParseList::init_bytes));
58 ParseList p (pi->data().begin(),&pi->data());
60 BOOST_CHECK_EQUAL( p.size(), 0u );
61 BOOST_CHECK_EQUAL( p.bytes(), 2u );
62 BOOST_CHECK( p.empty() );
63 BOOST_CHECK( p.begin() == p.end() );
65 // the mutators are really tested together with the container wrappers since they are based
66 // on the container wrapper. Here we only need one call to make the list larger ...
69 p = ParseList(pi->data().begin(),&pi->data());
70 BOOST_CHECK_EQUAL( p.bytes(), 3u );
71 BOOST_CHECK_EQUAL( p.size(), 1u );
72 BOOST_CHECK( ! p.empty() );
73 BOOST_CHECK( p.begin() != p.end() );
76 BOOST_AUTO_UNIT_TEST(parseListB_container)
78 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
79 ParseList::init_bytes));
82 ParseList::container c (ParseList(pi->data().begin(),&pi->data()));
84 BOOST_CHECK_EQUAL( c.size(), 0u );
85 BOOST_CHECK_EQUAL( c.bytes(), 2u );
86 BOOST_CHECK( c.begin() == c.end() );
89 BOOST_CHECK_EQUAL( c.size(), 1u );
90 BOOST_CHECK_EQUAL( c.bytes(), 3u );
92 BOOST_CHECK_EQUAL( c.front().vec().size(), 0u );
93 c.front().vec().push_back(0x1234u);
94 BOOST_CHECK_EQUAL( c.bytes(), 5u );
97 senf::PacketInterpreterBase::ptr pi2 (senf::PacketInterpreter<VoidPacket>::create(
98 ParseList::init_bytes));
99 ParseList::container c2 (ParseList(pi2->data().begin(),&pi2->data()));
100 c2.push_back_space();
102 ParseVec::vec_t::container c2v (c2.front().vec());
103 c2v.push_back(0x2345u);
104 c2v.push_back(0x3456u);
107 BOOST_CHECK_EQUAL(c2.size(), 1u);
108 BOOST_CHECK_EQUAL(c2.bytes(), 7u);
110 c.insert(c.end(),c2.back());
111 BOOST_CHECK_EQUAL( c.size(), 2u );
112 BOOST_CHECK_EQUAL( c.bytes(), 10u );
113 BOOST_CHECK_EQUAL( c.back().vec()[0], 0x2345u );
114 BOOST_CHECK_EQUAL( c.back().bytes(), c2.back().bytes() );
116 c2.back().vec()[0] << 0x1357u;
117 c.insert(boost::next(c.begin()), 2u, c2.back());
118 BOOST_CHECK_EQUAL( c.size(), 4u );
119 BOOST_CHECK_EQUAL( c.bytes(), 20u );
120 BOOST_CHECK_EQUAL( (*boost::next(c.begin())).vec()[0], 0x1357u );
121 BOOST_CHECK_EQUAL( (*boost::next(c.begin(),2)).vec()[0], 0x1357u );
123 c2.back().vec()[0] << 0x2468u;
124 c.insert(c.begin(),c2.begin(),c2.end());
125 BOOST_CHECK_EQUAL( c.size(), 5u );
126 BOOST_CHECK_EQUAL( c.bytes(), 25u );
127 BOOST_CHECK_EQUAL( c.front().vec()[0], 0x2468u );
129 c.erase(c.begin(),2);
130 BOOST_CHECK_EQUAL( c.size(), 3u );
131 BOOST_CHECK_EQUAL( c.bytes(), 17u );
132 BOOST_CHECK_EQUAL( c.front().vec()[0],0x1357u );
133 BOOST_CHECK_EQUAL( c.back().vec()[0], 0x2345u );
135 c.erase((boost::next(c.begin(),2)),c.end());
136 BOOST_CHECK_EQUAL( c.size(), 2u );
137 BOOST_CHECK_EQUAL( c.bytes(), 12u );
138 BOOST_CHECK_EQUAL( c.front().vec()[0],0x1357u );
139 BOOST_CHECK_EQUAL( c.back().vec()[0], 0x1357u );
142 BOOST_CHECK_EQUAL( c.size(), 0u );
143 BOOST_CHECK_EQUAL( c.bytes(), 2u );
148 ///////////////////////////////cc.e////////////////////////////////////////
155 // comment-column: 40
156 // c-file-style: "senf"
157 // indent-tabs-mode: nil
158 // ispell-local-dictionary: "american"
159 // compile-command: "scons -u test"