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 ArrayParser unit tests */
26 //#include "ArrayParser.test.hh"
27 //#include "ArrayParser.test.ih"
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
36 ///////////////////////////////cc.p////////////////////////////////////////
39 struct VoidPacket : public senf::PacketTypeBase
42 struct SomePacketParser : public senf::PacketParserBase
44 # include SENF_FIXED_PARSER()
46 typedef senf::ArrayParser<2,senf::UInt24Parser> ArrayParser2;
48 SENF_PARSER_FIELD( array, ArrayParser2 );
49 SENF_PARSER_FIELD( index, senf::UInt16Parser );
51 SENF_PARSER_FINALIZE(SomePacketParser);
54 struct SomeOtherParser : public senf::PacketParserBase
56 # include SENF_FIXED_PARSER()
58 typedef senf::ArrayParser<1,SomePacketParser> ArrayParser1;
60 SENF_PARSER_FIELD( fields, ArrayParser1 );
62 SENF_PARSER_FINALIZE(SomeOtherParser);
66 BOOST_AUTO_UNIT_TEST(ArrayParser_test)
68 senf::PacketParserBase::byte data[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
69 senf::PacketInterpreterBase::ptr p (senf::PacketInterpreter<VoidPacket>::create(data));
72 typedef senf::ArrayParser<6,senf::UInt8Parser> UInt8ParserArray6;
73 UInt8ParserArray6 v (p->data().begin(),&p->data());
75 BOOST_CHECK_EQUAL( v[0], 0x00 );
76 BOOST_CHECK_EQUAL( v[5], 0x05 );
77 BOOST_CHECK_EQUAL( *v.begin(), 0x00 );
78 BOOST_CHECK_EQUAL( std::distance(v.begin(),v.end()),
79 UInt8ParserArray6::difference_type(v.size()) );
80 BOOST_CHECK_EQUAL( v.size(), 6u );
81 UInt8ParserArray6::iterator i1 (v.begin());
82 UInt8ParserArray6::iterator i2 (v.begin());
84 BOOST_CHECK_EQUAL( *i1, 0x01 );
85 BOOST_CHECK_EQUAL( i1[-1], 0x00 );
86 BOOST_CHECK_EQUAL( i1-i2, 1 );
87 BOOST_CHECK_EQUAL( i2-i1, -1 );
89 BOOST_CHECK( i1==i2 );
93 SomeOtherParser v (p->data().begin(),&p->data());
95 BOOST_CHECK_THROW( v.fields(), senf::TruncatedPacketException );
99 ///////////////////////////////cc.e////////////////////////////////////////
106 // c-file-style: "senf"
107 // indent-tabs-mode: nil
108 // ispell-local-dictionary: "american"
109 // compile-command: "scons -u test"
110 // comment-column: 40