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 "PacketRegistry.test.hh"
26 //#include "PacketRegistry.test.ih"
30 #include "PacketRegistry.hh"
31 #include "DataPacket.hh"
32 #include "ParseInt.hh"
34 #include <boost/test/auto_unit_test.hpp>
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
45 typedef unsigned key_t;
49 typedef std::string key_t;
53 : public Packet, public PacketRegistryMixin<BaseTag,BasePacket>
55 using PacketRegistryMixin<BaseTag,BasePacket>::registerInterpreter;
57 typedef ptr_t<BasePacket>::ptr ptr;
58 typedef iterator byte_iterator;
60 typedef Parse_UInt16<iterator> Parse_Type;
62 Parse_Type type() const { return Parse_Type(begin()); }
63 static bool check(iterator b, iterator e) { return true; }
67 BasePacket(Arg const & arg) : Packet(arg) {}
69 virtual void v_nextInterpreter() const
70 { registerInterpreter(type(), begin()+2, end()); }
71 virtual void v_finalize() {}
72 virtual void v_dump(std::ostream & os) const {}
77 class FooPacket : public Packet
80 typedef ptr_t<FooPacket>::ptr ptr;
81 typedef iterator byte_iterator;
83 static bool check(iterator b, iterator e) { return true; }
87 FooPacket(Arg const & arg) : Packet(arg) {}
89 virtual void v_nextInterpreter() const {}
90 virtual void v_finalize() {}
91 virtual void v_dump(std::ostream & os) const {}
96 class BarPacket : public Packet
99 typedef ptr_t<BarPacket>::ptr ptr;
100 typedef iterator byte_iterator;
102 static bool check(iterator b, iterator e) { return true; }
106 BarPacket(Arg const & arg) : Packet(arg) {}
108 virtual void v_nextInterpreter() const {}
109 virtual void v_finalize() {}
110 virtual void v_dump(std::ostream & os) const {}
116 PacketRegistry<StringTag>::RegistrationProxy<FooPacket> registerFoo ("foo");
117 PacketRegistry<StringTag>::RegistrationProxy<BarPacket> registerBar ("bar");
122 BOOST_AUTO_UNIT_TEST(packetRegistry_test)
124 unsigned char data[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
125 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
128 BasePacket::ptr p (Packet::create<BasePacket>(data, data+sizeof(data)));
129 BOOST_CHECK( p->next()->is<DataPacket>() );
132 PacketRegistry<BaseTag>::registerPacket<FooPacket>(1u);
133 PacketRegistry<BaseTag>::registerPacket<BarPacket>(2u);
135 BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<FooPacket>(), 1u );
136 BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<BarPacket>(), 2u );
137 BOOST_CHECK_THROW( PacketRegistry<BaseTag>::key<DataPacket>(), PacketTypeNotRegistered );
140 BasePacket::ptr p (Packet::create<BasePacket>(data, data+sizeof(data)));
141 BOOST_CHECK( p->next()->is<FooPacket>() );
147 BasePacket::ptr p (Packet::create<BasePacket>(data, data+sizeof(data)));
148 BOOST_CHECK( p->next()->is<BarPacket>() );
154 BasePacket::ptr p (Packet::create<BasePacket>(data, data+sizeof(data)));
155 BOOST_CHECK( p->next()->is<DataPacket>() );
158 BOOST_CHECK_EQUAL( PacketRegistry<StringTag>::key<FooPacket>(), "foo" );
159 BOOST_CHECK( PacketRegistry<StringTag>::create("foo",data,data+sizeof(data))
164 ///////////////////////////////cc.e////////////////////////////////////////
171 // c-file-style: "senf"
172 // indent-tabs-mode: nil
173 // ispell-local-dictionary: "american"