4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.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 "ParserBase.test.hh"
26 //#include "ParserBase.test.ih"
29 #include "ParserBase.hh"
31 #include <boost/static_assert.hpp>
33 #include <boost/test/auto_unit_test.hpp>
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
39 namespace pkf = satcom::pkf;
41 // The non-inherited Version is extensively tested in PaseInt.test.hh
43 BOOST_AUTO_UNIT_TEST(parserBase_inherited)
50 template <class Iterator=pkf::nil, class IPacket=pkf::nil>
51 struct Parse_Test : public pkf::ParserBase<Iterator,IPacket>
53 template <class I=pkf::nil, class P=pkf::nil>
54 struct rebind { typedef Parse_Test<I,P> parser; };
55 typedef Iterator byte_iterator;
58 Parse_Test(Iterator const & i) : pkf::ParserBase<Iterator,IPacket>(i) {}
60 static unsigned bytes() { return 14; }
62 ///////////////////////////////////////////////////////////////////////////
66 template <class Iterator=pkf::nil, class IPacket=pkf::nil>
67 struct Parse_Test2 : public pkf::ParserBase<Iterator,IPacket>
69 template <class I=pkf::nil, class P=pkf::nil>
70 struct rebind { typedef Parse_Test<I,P> parser; };
71 typedef Iterator byte_iterator;
74 Parse_Test2(Iterator const & i) : pkf::ParserBase<Iterator,IPacket>(i) {}
76 unsigned bytes() const { return 14; }
77 static unsigned check(Iterator a, Iterator b)
79 static unsigned min_bytes() { return 10; }
81 ///////////////////////////////////////////////////////////////////////////
87 BOOST_AUTO_UNIT_TEST(parserBase_construction)
89 BOOST_STATIC_ASSERT( pkf::Parser_traits< Parse_Test<> >::fixed_size );
90 BOOST_STATIC_ASSERT( ! pkf::Parser_traits< Parse_Test2<> >::fixed_size );
92 BOOST_CHECK_EQUAL( pkf::min_bytes< Parse_Test<int> >(), 14u );
93 BOOST_CHECK( pkf::check< Parse_Test<int> >(0,14) );
94 BOOST_CHECK( ! pkf::check< Parse_Test<int> >(2,15) );
96 BOOST_CHECK_EQUAL( pkf::min_bytes< Parse_Test2<int> >(), 10u );
97 BOOST_CHECK( pkf::check< Parse_Test2<int> >(2,13) );
98 BOOST_CHECK( pkf::check< Parse_Test2<int> >(2,12) );
101 ///////////////////////////////cc.e////////////////////////////////////////
107 // c-file-style: "satcom"