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 ArrayParser unit tests */
31 //#include "ArrayParser.test.hh"
32 //#include "ArrayParser.test.ih"
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44 struct VoidPacket : public senf::PacketTypeBase
47 struct SomePacketParser : public senf::PacketParserBase
49 # include SENF_FIXED_PARSER()
51 typedef senf::ArrayParser<2,senf::UInt24Parser> ArrayParser2;
53 SENF_PARSER_FIELD( array, ArrayParser2 );
54 SENF_PARSER_FIELD( index, senf::UInt16Parser );
56 SENF_PARSER_FINALIZE(SomePacketParser);
59 struct SomeOtherParser : public senf::PacketParserBase
61 # include SENF_FIXED_PARSER()
63 typedef senf::ArrayParser<1,SomePacketParser> ArrayParser1;
65 SENF_PARSER_FIELD( fields, ArrayParser1 );
67 SENF_PARSER_FINALIZE(SomeOtherParser);
71 SENF_AUTO_UNIT_TEST(ArrayParser_test)
73 senf::PacketParserBase::byte data[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 };
74 senf::PacketInterpreterBase::ptr p (senf::PacketInterpreter<VoidPacket>::create(data));
77 typedef senf::ArrayParser<6,senf::UInt8Parser> UInt8ParserArray6;
78 UInt8ParserArray6 v (p->data().begin(),&p->data());
80 BOOST_CHECK_EQUAL( v[0], 0x00 );
81 BOOST_CHECK_EQUAL( v[5], 0x05 );
82 BOOST_CHECK_EQUAL( *v.begin(), 0x00 );
83 BOOST_CHECK_EQUAL( std::distance(v.begin(),v.end()),
84 UInt8ParserArray6::difference_type(v.size()) );
85 BOOST_CHECK_EQUAL( v.size(), 6u );
86 UInt8ParserArray6::iterator i1 (v.begin());
87 UInt8ParserArray6::iterator i2 (v.begin());
89 BOOST_CHECK_EQUAL( *i1, 0x01 );
90 BOOST_CHECK_EQUAL( i1[-1], 0x00 );
91 BOOST_CHECK_EQUAL( i1-i2, 1 );
92 BOOST_CHECK_EQUAL( i2-i1, -1 );
94 BOOST_CHECK( i1==i2 );
98 SomeOtherParser v (p->data().begin(),&p->data());
100 BOOST_CHECK_THROW( v.fields(), senf::TruncatedPacketException );
104 //-/////////////////////////////////////////////////////////////////////////////////////////////////
111 // c-file-style: "senf"
112 // indent-tabs-mode: nil
113 // ispell-local-dictionary: "american"
114 // compile-command: "scons -u test"
115 // comment-column: 40