Merged revisions 262,264-265,267-282,284-298,300-311 via svnmerge from
[senf.git] / Packets / PacketRegistry.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 "PacketRegistry.test.hh"
26 //#include "PacketRegistry.test.ih"
27
28 // Custom includes
29 #include <string>
30 #include "PacketRegistry.hh"
31 #include "PacketType.hh"
32 #include "ParseInt.hh"
33
34 #include <boost/test/auto_unit_test.hpp>
35 #include <boost/test/test_tools.hpp>
36
37 #define prefix_
38 ///////////////////////////////cc.p////////////////////////////////////////
39
40 namespace {
41
42     using namespace senf;
43
44     struct BaseTag {
45         typedef unsigned key_t;
46     };
47
48     struct StringTag {
49         typedef std::string key_t;
50     };
51
52     struct FooPacketType : public PacketTypeBase {};
53     struct BarPacketType : public PacketTypeBase {};
54     struct OtherPacketType : public PacketTypeBase {};
55
56     namespace reg {
57         PacketRegistry<StringTag>::RegistrationProxy<FooPacketType> registerFoo ("foo");
58         PacketRegistry<StringTag>::RegistrationProxy<BarPacketType> registerBar ("bar");
59     }
60
61 }
62
63 BOOST_AUTO_UNIT_TEST(packetRegistry_test)
64 {
65     PacketRegistry<BaseTag>::registerPacket<FooPacketType>(1u);
66     PacketRegistry<BaseTag>::registerPacket<BarPacketType>(2u);
67
68     BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<FooPacketType>(), 1u );
69     BOOST_CHECK_EQUAL( PacketRegistry<BaseTag>::key<BarPacketType>(), 2u );
70     BOOST_CHECK_THROW( PacketRegistry<BaseTag>::key<OtherPacketType>(), 
71                        PacketTypeNotRegisteredException );
72
73     BOOST_CHECK_EQUAL( PacketRegistry<StringTag>::key<FooPacketType>(), "foo" );
74     BOOST_CHECK( ! PacketRegistry<StringTag>::lookup("blub", senf::nothrow) );
75     BOOST_CHECK( PacketRegistry<BaseTag>::lookup(1u, senf::nothrow) );
76
77 }
78
79 ///////////////////////////////cc.e////////////////////////////////////////
80 #undef prefix_
81
82 \f
83 // Local Variables:
84 // mode: c++
85 // fill-column: 100
86 // c-file-style: "senf"
87 // indent-tabs-mode: nil
88 // ispell-local-dictionary: "american"
89 // compile-command: "scons -u test"
90 // comment-column: 40
91 // End: