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 PacketParser unit tests */
26 //#include "PacketParser.test.hh"
27 //#include "PacketParser.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 {};
41 struct SimpleParser : public senf::PacketParserBase
43 # include SENF_FIXED_PARSER()
44 SENF_PARSER_FINALIZE(SimpleParser);
46 using senf::PacketParserBase::check;
47 using senf::PacketParserBase::validate;
50 struct FooParser : public senf::PacketParserBase
52 # include SENF_FIXED_PARSER()
54 SENF_PARSER_FIELD( name, senf::UInt16Parser );
55 SENF_PARSER_FIELD( id, senf::Int32Parser );
57 SENF_PARSER_FINALIZE(FooParser);
60 struct BarParser : public senf::PacketParserBase
62 # include SENF_PARSER()
64 SENF_PARSER_FIELD( name, senf::UInt16Parser );
65 SENF_PARSER_FIELD( id, senf::Int32Parser );
67 SENF_PARSER_FINALIZE(BarParser);
71 BOOST_AUTO_UNIT_TEST(packetParserBase)
73 senf::PacketInterpreter<VoidPacket>::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
74 senf::PacketInterpreterBase::size_type(6u)));
75 SimpleParser p (pi->data().begin(),&pi->data());
77 BOOST_CHECK( pi->data().begin() == p.i() );
78 BOOST_CHECK( p.check(6u) );
79 BOOST_CHECK( ! p.check(7u) );
80 SENF_CHECK_NO_THROW( p.validate(6u) );
81 BOOST_CHECK_THROW( p.validate(7u), senf::TruncatedPacketException );
83 // ?? Why the heck do I need the +0? I get an 'undefined symbol FooParser::fixed_bytes'
85 BOOST_CHECK_EQUAL( FooParser::fixed_bytes+0, 6u );
86 BOOST_CHECK_EQUAL( BarParser(pi->data().begin(),&pi->data()).bytes(), 6u );
87 BOOST_CHECK_EQUAL( senf::bytes(senf::UInt16Parser(pi->data().begin(),&pi->data())), 2u );
88 BOOST_CHECK_EQUAL( senf::bytes(FooParser(pi->data().begin(),&pi->data())), 6u );
89 BOOST_CHECK_EQUAL( senf::bytes(BarParser(pi->data().begin(),&pi->data())), 6u );
91 BOOST_CHECK_EQUAL( senf::init_bytes<FooParser>::value, 6u );
92 BOOST_CHECK_EQUAL( senf::init_bytes<BarParser>::value, 6u );
95 ///////////////////////////////cc.e////////////////////////////////////////
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"
106 // comment-column: 40