4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
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 AuxParser unit tests */
26 //#include "AuxParser.test.hh"
27 //#include "AuxParser.test.ih"
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
36 ///////////////////////////////cc.p////////////////////////////////////////
38 // The other aux policies are tested with the corresponding container classes
40 SENF_AUTO_UNIT_TEST(vectorPacketSizeAuxPolicy)
42 unsigned char data[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
43 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
44 senf::Packet p (senf::DataPacket::create(data));
46 typedef senf::VectorParser<
48 senf::detail::PacketSizeAuxParserPolicy
52 UInt8VectorParser v (p.data().begin(), &p.data());
54 BOOST_CHECK_EQUAL( v.size(), p.data().size() );
55 BOOST_CHECK_EQUAL_COLLECTIONS( v.begin(), v.end(), data, data+sizeof(data) );
59 UInt8VectorParser v (p.data().begin(), &p.data());
60 UInt8VectorParser::container w (v);
62 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(), data, data+sizeof(data) );
65 BOOST_CHECK_EQUAL( w.size(), p.data().size() );
67 w.erase(w.begin()+3, w.begin()+5);
68 BOOST_CHECK_EQUAL( w.size(), p.data().size() );
70 unsigned char data2[] = { 0x10, 0x00, 0x11, 0x14, 0x15,
71 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
73 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(), data2, data2+sizeof(data2) );
77 SENF_AUTO_UNIT_TEST(vectorPacketSizeAuxPolicy_transformed)
79 unsigned char data[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
80 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
81 senf::Packet p (senf::DataPacket::create(data));
83 typedef senf::VectorParser<
85 senf::detail::TransformAuxParserPolicy<
86 senf::detail::PacketSizeAuxParserPolicy,
87 senf::detail::VectorParserBytesTransform<senf::UInt16Parser::fixed_bytes> >
91 UInt16VectorParser v (p.data().begin(), &p.data());
93 BOOST_REQUIRE_EQUAL( v.size(), p.data().size()/2 );
94 BOOST_CHECK_EQUAL( v[0], 0x1011u );
95 BOOST_CHECK_EQUAL( v[1], 0x1213u );
96 BOOST_CHECK_EQUAL( v[5], 0x2425u );
100 UInt16VectorParser v (p.data().begin(), &p.data());
101 UInt16VectorParser::container w (v);
103 BOOST_REQUIRE_EQUAL( w.size(), p.data().size()/2 );
104 BOOST_CHECK_EQUAL( w[0], 0x1011u );
105 BOOST_CHECK_EQUAL( w[1], 0x1213u );
106 BOOST_CHECK_EQUAL( w[5], 0x2425u );
108 w.shift(w.begin()+1);
109 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
111 w.erase(w.begin()+3, w.begin()+5);
112 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
114 senf::UInt16Parser::value_type data2[] =
115 { 0x1011u, 0x0000u, 0x1213u, 0x2223u, 0x2425u };
117 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(),
118 data2, data2+sizeof(data2)/sizeof(data2[0]) );
122 SENF_AUTO_UNIT_TEST(listPacketSizeAuxPolicy)
124 unsigned char data[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
125 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
126 senf::Packet p (senf::DataPacket::create(data));
128 typedef senf::ListParser<
129 senf::detail::ListBParser_Policy<
131 senf::detail::PacketSizeAuxParserPolicy>
135 ListParser l (p.data().begin(), &p.data());
137 BOOST_REQUIRE_EQUAL( l.size(), p.data().size()/2 );
138 BOOST_CHECK_EQUAL( l.front(), 0x1011u );
139 BOOST_CHECK_EQUAL( l.back(), 0x2425u );
143 ListParser l (p.data().begin(), &p.data());
144 ListParser::container w (l);
146 BOOST_REQUIRE_EQUAL( w.size(), p.data().size()/2 );
147 BOOST_CHECK_EQUAL( *w.begin(), 0x1011u );
148 BOOST_CHECK_EQUAL( *boost::next(w.begin()), 0x1213u );
149 BOOST_CHECK_EQUAL( *boost::next(w.begin(),5), 0x2425u );
151 w.shift(boost::next(w.begin()));
152 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
154 w.erase(boost::next(w.begin(),3), boost::next(w.begin(),5));
155 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
157 senf::UInt16Parser::value_type data2[] =
158 { 0x1011u, 0x0000u, 0x1213u, 0x2223u, 0x2425u };
160 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(),
161 data2, data2+sizeof(data2)/sizeof(data2[0]) );
165 ///////////////////////////////cc.e////////////////////////////////////////
172 // comment-column: 40
173 // c-file-style: "senf"
174 // indent-tabs-mode: nil
175 // ispell-local-dictionary: "american"
176 // compile-command: "scons -u test"