Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / Packets / PacketParser.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief PacketParser unit tests */
25
26 //#include "PacketParser.test.hh"
27 //#include "PacketParser.test.ih"
28
29 // Custom includes
30 #include "Packets.hh"
31
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 //-/////////////////////////////////////////////////////////////////////////////////////////////////
37
38 namespace {
39     struct VoidPacket : public senf::PacketTypeBase {};
40
41     struct SimpleParser : public senf::PacketParserBase
42     {
43 #       include SENF_FIXED_PARSER()
44         SENF_PARSER_FINALIZE(SimpleParser);
45
46         using senf::PacketParserBase::check;
47         using senf::PacketParserBase::validate;
48     };
49
50     struct FooParser : public senf::PacketParserBase
51     {
52 #       include SENF_FIXED_PARSER()
53
54         SENF_PARSER_FIELD( name, senf::UInt16Parser );
55         SENF_PARSER_FIELD( id,   senf::Int32Parser  );
56
57         SENF_PARSER_FINALIZE(FooParser);
58     };
59
60     struct BarParser : public senf::PacketParserBase
61     {
62 #       include SENF_PARSER()
63
64         SENF_PARSER_FIELD( name, senf::UInt16Parser );
65         SENF_PARSER_FIELD( id,   senf::Int32Parser  );
66
67         SENF_PARSER_FINALIZE(BarParser);
68     };
69 }
70
71 SENF_AUTO_UNIT_TEST(packetParserBase)
72 {
73     senf::PacketInterpreter<VoidPacket>::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
74             senf::PacketInterpreterBase::size_type(6u)));
75     SimpleParser p (pi->data().begin(),&pi->data());
76
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 );
82
83     // ?? Why the heck do I need the +0? I get an 'undefined symbol FooParser::fixed_bytes'
84     // otherwise ...
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 );
90
91     BOOST_CHECK_EQUAL( senf::init_bytes<FooParser>::value, 6u );
92     BOOST_CHECK_EQUAL( senf::init_bytes<BarParser>::value, 6u );
93 }
94
95 //-/////////////////////////////////////////////////////////////////////////////////////////////////
96 #undef prefix_
97
98 \f
99 // Local Variables:
100 // mode: c++
101 // fill-column: 100
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
107 // End: