git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@129 270642c3-0616-0410...
[senf.git] / Packets / ParserBase.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.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 // Unit tests
24
25 //#include "ParserBase.test.hh"
26 //#include "ParserBase.test.ih"
27
28 // Custom includes
29 #include "ParserBase.hh"
30 #include "Packet.hh"
31
32 #include <boost/test/auto_unit_test.hpp>
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 ///////////////////////////////cc.p////////////////////////////////////////
37
38 namespace pkf = satcom::pkf;
39
40 // The non-inherited Version is extensively tested in PaseInt.test.hh
41
42 BOOST_AUTO_UNIT_TEST(parserBase_inherited)
43 {
44     // TODO: Implement
45 }
46
47 namespace {
48
49     template <class Iterator=pkf::nil, class IPacket=pkf::nil>
50     struct Parse_Test : public pkf::ParserBase<Iterator,IPacket>
51     {
52         template <class I=pkf::nil, class P=pkf::nil>
53         struct rebind { typedef Parse_Test<I,P> parser; };
54         typedef Iterator byte_iterator;
55         
56         Parse_Test() {}
57         Parse_Test(Iterator const & i) : pkf::ParserBase<Iterator,IPacket>(i) {}
58         
59         static unsigned bytes() { return 14; }
60
61         ///////////////////////////////////////////////////////////////////////////
62
63     };
64
65     template <class Iterator=pkf::nil, class IPacket=pkf::nil>
66     struct Parse_Test2 : public pkf::ParserBase<Iterator,IPacket>
67     {
68         template <class I=pkf::nil, class P=pkf::nil>
69         struct rebind { typedef Parse_Test<I,P> parser; };
70         typedef Iterator byte_iterator;
71         
72         Parse_Test2() {}
73         Parse_Test2(Iterator const & i) : pkf::ParserBase<Iterator,IPacket>(i) {}
74         
75         unsigned bytes() const { return 14; }
76         static unsigned check(Iterator a, Iterator b)
77             { return true; }
78         static unsigned min_bytes() { return 10; }
79
80         ///////////////////////////////////////////////////////////////////////////
81
82     };
83
84 }
85
86 BOOST_AUTO_UNIT_TEST(parserBase_construction)
87 {
88     BOOST_CHECK_EQUAL( pkf::min_bytes< Parse_Test<int> >(), 14u );
89     BOOST_CHECK( pkf::check< Parse_Test<int> >(0,14) );
90     BOOST_CHECK( ! pkf::check< Parse_Test<int> >(2,15) );
91
92     BOOST_CHECK_EQUAL( pkf::min_bytes< Parse_Test2<int> >(), 10u );
93     BOOST_CHECK( pkf::check< Parse_Test2<int> >(2,13) );
94     BOOST_CHECK( pkf::check< Parse_Test2<int> >(2,12) );
95 }
96
97 ///////////////////////////////cc.e////////////////////////////////////////
98 #undef prefix_
99
100 \f
101 // Local Variables:
102 // mode: c++
103 // c-file-style: "satcom"
104 // End: