4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief AuxParser unit tests */
31 //#include "AuxParser.test.hh"
32 //#include "AuxParser.test.ih"
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 // The other aux policies are tested with the corresponding container classes
45 SENF_AUTO_UNIT_TEST(vectorPacketSizeAuxPolicy)
47 unsigned char data[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
48 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
49 senf::Packet p (senf::DataPacket::create(data));
51 typedef senf::VectorParser<
53 senf::detail::PacketSizeAuxParserPolicy
57 UInt8VectorParser v (p.data().begin(), &p.data());
59 BOOST_CHECK_EQUAL( v.size(), p.data().size() );
60 BOOST_CHECK_EQUAL_COLLECTIONS( v.begin(), v.end(), data, data+sizeof(data) );
64 UInt8VectorParser v (p.data().begin(), &p.data());
65 UInt8VectorParser::container w (v);
67 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(), data, data+sizeof(data) );
70 BOOST_CHECK_EQUAL( w.size(), p.data().size() );
72 w.erase(w.begin()+3, w.begin()+5);
73 BOOST_CHECK_EQUAL( w.size(), p.data().size() );
75 unsigned char data2[] = { 0x10, 0x00, 0x11, 0x14, 0x15,
76 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
78 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(), data2, data2+sizeof(data2) );
82 SENF_AUTO_UNIT_TEST(vectorPacketSizeAuxPolicy_transformed)
84 unsigned char data[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
85 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
86 senf::Packet p (senf::DataPacket::create(data));
88 typedef senf::VectorParser<
90 senf::detail::TransformAuxParserPolicy<
91 senf::detail::PacketSizeAuxParserPolicy,
92 senf::detail::VectorParserBytesTransform<senf::UInt16Parser::fixed_bytes> >
96 UInt16VectorParser v (p.data().begin(), &p.data());
98 BOOST_REQUIRE_EQUAL( v.size(), p.data().size()/2 );
99 BOOST_CHECK_EQUAL( v[0], 0x1011u );
100 BOOST_CHECK_EQUAL( v[1], 0x1213u );
101 BOOST_CHECK_EQUAL( v[5], 0x2425u );
105 UInt16VectorParser v (p.data().begin(), &p.data());
106 UInt16VectorParser::container w (v);
108 BOOST_REQUIRE_EQUAL( w.size(), p.data().size()/2 );
109 BOOST_CHECK_EQUAL( w[0], 0x1011u );
110 BOOST_CHECK_EQUAL( w[1], 0x1213u );
111 BOOST_CHECK_EQUAL( w[5], 0x2425u );
113 w.shift(w.begin()+1);
114 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
116 w.erase(w.begin()+3, w.begin()+5);
117 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
119 senf::UInt16Parser::value_type data2[] =
120 { 0x1011u, 0x0000u, 0x1213u, 0x2223u, 0x2425u };
122 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(),
123 data2, data2+sizeof(data2)/sizeof(data2[0]) );
127 SENF_AUTO_UNIT_TEST(listPacketSizeAuxPolicy)
129 unsigned char data[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
130 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 };
131 senf::Packet p (senf::DataPacket::create(data));
133 typedef senf::ListParser<
134 senf::detail::ListBParser_Policy<
136 senf::detail::PacketSizeAuxParserPolicy>
140 ListParser l (p.data().begin(), &p.data());
142 BOOST_REQUIRE_EQUAL( l.size(), p.data().size()/2 );
143 BOOST_CHECK_EQUAL( l.front(), 0x1011u );
144 BOOST_CHECK_EQUAL( l.back(), 0x2425u );
148 ListParser l (p.data().begin(), &p.data());
149 ListParser::container w (l);
151 BOOST_REQUIRE_EQUAL( w.size(), p.data().size()/2 );
152 BOOST_CHECK_EQUAL( *w.begin(), 0x1011u );
153 BOOST_CHECK_EQUAL( *boost::next(w.begin()), 0x1213u );
154 BOOST_CHECK_EQUAL( *boost::next(w.begin(),5), 0x2425u );
156 w.shift(boost::next(w.begin()));
157 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
159 w.erase(boost::next(w.begin(),3), boost::next(w.begin(),5));
160 BOOST_CHECK_EQUAL( w.size(), p.data().size()/2 );
162 senf::UInt16Parser::value_type data2[] =
163 { 0x1011u, 0x0000u, 0x1213u, 0x2223u, 0x2425u };
165 BOOST_CHECK_EQUAL_COLLECTIONS( w.begin(), w.end(),
166 data2, data2+sizeof(data2)/sizeof(data2[0]) );
170 //-/////////////////////////////////////////////////////////////////////////////////////////////////
177 // comment-column: 40
178 // c-file-style: "senf"
179 // indent-tabs-mode: nil
180 // ispell-local-dictionary: "american"
181 // compile-command: "scons -u test"