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 PacketRegistry unit tests */
26 //#include "PacketRegistry.test.hh"
27 //#include "PacketRegistry.test.ih"
34 #include <senf/Utils/auto_unit_test.hh>
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
45 typedef unsigned key_t;
49 typedef std::string key_t;
52 struct FooPacketType : public PacketTypeBase {};
53 typedef senf::ConcretePacket<FooPacketType> FooPacket;
54 struct BarPacketType : public PacketTypeBase {};
55 typedef senf::ConcretePacket<BarPacketType> BarPacket;
56 struct OtherPacketType : public PacketTypeBase {};
57 typedef senf::ConcretePacket<OtherPacketType> OtherPacket;
61 SENF_PACKET_REGISTRY_REGISTER(StringTag, "foo", FooPacket);
62 SENF_PACKET_REGISTRY_REGISTER(StringTag, "bar", BarPacket);
64 BOOST_AUTO_UNIT_TEST(packetRegistry_test)
66 PacketRegistry<BaseTag>::registerPacket<FooPacket>(1u);
67 PacketRegistry<BaseTag>::registerPacket<BarPacket>(2u);
69 BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<FooPacket>(), 1u );
70 BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<BarPacket>(), 2u );
71 BOOST_CHECK_THROW( PacketRegistry<BaseTag>::key<OtherPacket>(),
72 PacketTypeNotRegisteredException );
74 BOOST_CHECK_EQUAL( PacketRegistry<StringTag>::key<FooPacket>(), "foo" );
75 BOOST_CHECK( ! PacketRegistry<StringTag>::lookup("blub", senf::nothrow) );
76 BOOST_CHECK( PacketRegistry<BaseTag>::lookup(1u, senf::nothrow) );
78 unsigned elts1[] = { 1u, 2u };
79 BOOST_CHECK_EQUAL_COLLECTIONS( PacketRegistry<BaseTag>::begin(), PacketRegistry<BaseTag>::end(),
80 elts1+0, elts1+sizeof(elts1)/sizeof(elts1[0]) );
82 std::string elts2[] = { "bar", "foo" };
83 BOOST_CHECK_EQUAL_COLLECTIONS( PacketRegistry<StringTag>::begin(), PacketRegistry<StringTag>::end(),
84 elts2+0, elts2+sizeof(elts2)/sizeof(elts2[0]) );
87 senf::dumpPacketRegistries(s);
88 BOOST_CHECK_EQUAL( s.str(),
89 "(anonymous namespace)::BaseTag:\n"
90 " 0x00000001 ( 1) (....) (anonymous namespace)::FooPacketType\n"
91 " 0x00000002 ( 2) (....) (anonymous namespace)::BarPacketType\n"
93 "(anonymous namespace)::RegTag:\n"
94 " 0x00000001 ( 1) (....) (anonymous namespace)::FooPacketType\n"
95 " 0x00000002 ( 2) (....) (anonymous namespace)::BarPacketType\n"
97 "(anonymous namespace)::StringTag:\n"
98 " bar (anonymous namespace)::BarPacketType\n"
99 " foo (anonymous namespace)::FooPacketType\n"
103 ///////////////////////////////cc.e////////////////////////////////////////
110 // c-file-style: "senf"
111 // indent-tabs-mode: nil
112 // ispell-local-dictionary: "american"
113 // compile-command: "scons -u test"
114 // comment-column: 40