4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
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 ParseListB.test unit tests */
26 //#include "ParseListB.test.hh"
27 //#include "ParseListB.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 struct ParseVec : public senf::PacketParserBase
44 # include SENF_PARSER()
46 SENF_PARSER_PRIVATE_FIELD( size, senf::Parse_UInt8 );
47 SENF_PARSER_VEC_N( vec, size, senf::Parse_UInt16 );
49 SENF_PARSER_FINALIZE(ParseVec);
52 typedef senf::Parse_ListB<ParseVec,senf::Parse_UInt16>::parser ParseList;
55 BOOST_AUTO_UNIT_TEST(parseListB)
57 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
58 ParseList::init_bytes));
60 ParseList p (pi->data().begin(),&pi->data());
62 BOOST_CHECK_EQUAL( p.size(), 0u );
63 BOOST_CHECK_EQUAL( p.bytes(), 2u );
64 BOOST_CHECK( p.empty() );
65 BOOST_CHECK( p.begin() == p.end() );
67 // the mutators are really tested together with the container wrappers since they are based
68 // on the container wrapper. Here we only need one call to make the list larger ...
71 p = ParseList(pi->data().begin(),&pi->data());
72 BOOST_CHECK_EQUAL( p.bytes(), 3u );
73 BOOST_CHECK_EQUAL( p.size(), 1u );
74 BOOST_CHECK( ! p.empty() );
75 BOOST_CHECK( p.begin() != p.end() );
78 BOOST_AUTO_UNIT_TEST(parseListB_container)
80 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
81 ParseList::init_bytes));
84 ParseList::container c (ParseList(pi->data().begin(),&pi->data()));
86 BOOST_CHECK_EQUAL( c.size(), 0u );
87 BOOST_CHECK_EQUAL( c.bytes(), 2u );
88 BOOST_CHECK( c.begin() == c.end() );
91 BOOST_CHECK_EQUAL( c.size(), 1u );
92 BOOST_CHECK_EQUAL( c.bytes(), 3u );
94 BOOST_CHECK_EQUAL( c.front().vec().size(), 0u );
95 c.front().vec().push_back(0x1234u);
96 BOOST_CHECK_EQUAL( c.bytes(), 5u );
99 senf::PacketInterpreterBase::ptr pi2 (senf::PacketInterpreter<VoidPacket>::create(
100 ParseList::init_bytes));
101 ParseList::container c2 (ParseList(pi2->data().begin(),&pi2->data()));
102 c2.push_back_space();
104 ParseVec::vec_t::container c2v (c2.front().vec());
105 c2v.push_back(0x2345u);
106 c2v.push_back(0x3456u);
109 BOOST_CHECK_EQUAL(c2.size(), 1u);
110 BOOST_CHECK_EQUAL(c2.bytes(), 7u);
112 c.insert(c.end(),c2.back());
113 BOOST_CHECK_EQUAL( c.size(), 2u );
114 BOOST_CHECK_EQUAL( c.bytes(), 10u );
115 BOOST_CHECK_EQUAL( c.back().vec()[0], 0x2345u );
116 BOOST_CHECK_EQUAL( c.back().bytes(), c2.back().bytes() );
118 c2.back().vec()[0] << 0x1357u;
119 c.insert(boost::next(c.begin()), 2u, c2.back());
120 BOOST_CHECK_EQUAL( c.size(), 4u );
121 BOOST_CHECK_EQUAL( c.bytes(), 20u );
122 BOOST_CHECK_EQUAL( (*boost::next(c.begin())).vec()[0], 0x1357u );
123 BOOST_CHECK_EQUAL( (*boost::next(c.begin(),2)).vec()[0], 0x1357u );
125 c2.back().vec()[0] << 0x2468u;
126 c.insert(c.begin(),c2.begin(),c2.end());
127 BOOST_CHECK_EQUAL( c.size(), 5u );
128 BOOST_CHECK_EQUAL( c.bytes(), 25u );
129 BOOST_CHECK_EQUAL( c.front().vec()[0], 0x2468u );
131 c.erase(c.begin(),2);
132 BOOST_CHECK_EQUAL( c.size(), 3u );
133 BOOST_CHECK_EQUAL( c.bytes(), 17u );
134 BOOST_CHECK_EQUAL( c.front().vec()[0],0x1357u );
135 BOOST_CHECK_EQUAL( c.back().vec()[0], 0x2345u );
137 c.erase((boost::next(c.begin(),2)),c.end());
138 BOOST_CHECK_EQUAL( c.size(), 2u );
139 BOOST_CHECK_EQUAL( c.bytes(), 12u );
140 BOOST_CHECK_EQUAL( c.front().vec()[0],0x1357u );
141 BOOST_CHECK_EQUAL( c.back().vec()[0], 0x1357u );
144 BOOST_CHECK_EQUAL( c.size(), 0u );
145 BOOST_CHECK_EQUAL( c.bytes(), 2u );
150 ///////////////////////////////cc.e////////////////////////////////////////
157 // comment-column: 40
158 // c-file-style: "senf"
159 // indent-tabs-mode: nil
160 // ispell-local-dictionary: "american"
161 // compile-command: "scons -u test"