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.
25 //#include "ArrayParser.test.hh"
26 //#include "ArrayParser.test.ih"
31 #include "../Utils/auto_unit_test.hh"
32 #include <boost/test/test_tools.hpp>
35 ///////////////////////////////cc.p////////////////////////////////////////
38 struct VoidPacket : public senf::PacketTypeBase
41 struct SomePacketParser : public senf::PacketParserBase
43 # include SENF_FIXED_PARSER()
45 typedef senf::ArrayParser<2,senf::UInt24Parser> ArrayParser2;
47 SENF_PARSER_FIELD( array, ArrayParser2 );
48 SENF_PARSER_FIELD( index, senf::UInt16Parser );
50 SENF_PARSER_FINALIZE(SomePacketParser);
53 struct SomeOtherParser : public senf::PacketParserBase
55 # include SENF_FIXED_PARSER()
57 typedef senf::ArrayParser<1,SomePacketParser> ArrayParser1;
59 SENF_PARSER_FIELD( fields, ArrayParser1 );
61 SENF_PARSER_FINALIZE(SomeOtherParser);
65 BOOST_AUTO_UNIT_TEST(ArrayParser_test)
67 senf::PacketParserBase::byte data[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
68 senf::PacketInterpreterBase::ptr p (senf::PacketInterpreter<VoidPacket>::create(data));
71 typedef senf::ArrayParser<6,senf::UInt8Parser> UInt8ParserArray6;
72 UInt8ParserArray6 v (p->data().begin(),&p->data());
74 BOOST_CHECK_EQUAL( v[0], 0x00 );
75 BOOST_CHECK_EQUAL( v[5], 0x05 );
76 BOOST_CHECK_EQUAL( *v.begin(), 0x00 );
77 BOOST_CHECK_EQUAL( std::distance(v.begin(),v.end()),
78 UInt8ParserArray6::difference_type(v.size()) );
79 BOOST_CHECK_EQUAL( v.size(), 6u );
80 UInt8ParserArray6::iterator i1 (v.begin());
81 UInt8ParserArray6::iterator i2 (v.begin());
83 BOOST_CHECK_EQUAL( *i1, 0x01 );
84 BOOST_CHECK_EQUAL( i1[-1], 0x00 );
85 BOOST_CHECK_EQUAL( i1-i2, 1 );
86 BOOST_CHECK_EQUAL( i2-i1, -1 );
88 BOOST_CHECK( i1==i2 );
92 SomeOtherParser v (p->data().begin(),&p->data());
94 BOOST_CHECK_THROW( v.fields(), senf::TruncatedPacketException );
98 ///////////////////////////////cc.e////////////////////////////////////////
105 // c-file-style: "senf"
106 // indent-tabs-mode: nil
107 // ispell-local-dictionary: "american"
108 // compile-command: "scons -u test"
109 // comment-column: 40