X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FPacketRegistry.test.cc;h=b315ae8d460dac9b1fea877560acb7e8546696ae;hb=refs%2Fheads%2Fmaster;hp=ddb10889ac92fff63122cf1374339cd293c0fb34;hpb=3e2082d6966ef4e61ff8a2070b157251e5cb08a6;p=senf.git diff --git a/senf/Packets/PacketRegistry.test.cc b/senf/Packets/PacketRegistry.test.cc index ddb1088..b315ae8 100644 --- a/senf/Packets/PacketRegistry.test.cc +++ b/senf/Packets/PacketRegistry.test.cc @@ -2,23 +2,28 @@ // // Copyright (C) 2006 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Stefan Bund // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief PacketRegistry unit tests */ @@ -35,7 +40,7 @@ #include #define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace { @@ -64,14 +69,15 @@ namespace { } -SENF_PACKET_REGISTRY_REGISTER(StringTag, "foo", FooPacket); +SENF_PACKET_REGISTRY_REGISTER(StringTag, "foo", OtherPacket); +SENF_PACKET_REGISTRY_REGISTER_PRIORITY(StringTag, "foo", 1, FooPacket); SENF_AUTO_UNIT_TEST(packetRegistry_test) { { PacketRegistry::registerPacket("bar"); PacketRegistry::registerPacket(1u); - senf::PacketRegistry::RegistrationProxy registerBarInBase (2u); + senf::PacketRegistry::ScopedRegistrationProxy registerBarInBase (2u); BOOST_CHECK_EQUAL( PacketRegistry::key(), 1u ); BOOST_CHECK_EQUAL( PacketRegistry::key(), 2u ); @@ -79,18 +85,33 @@ SENF_AUTO_UNIT_TEST(packetRegistry_test) PacketTypeNotRegisteredException ); BOOST_CHECK_EQUAL( PacketRegistry::key(), "foo" ); + BOOST_CHECK( PacketRegistry::lookup("foo").type() == typeid(FooPacket) ); BOOST_CHECK( ! PacketRegistry::lookup("blub", senf::nothrow) ); BOOST_CHECK( PacketRegistry::lookup(1u, senf::nothrow) ); unsigned elts1[] = { 1u, 2u }; - BOOST_CHECK_EQUAL_COLLECTIONS( PacketRegistry::begin(), - PacketRegistry::end(), - elts1+0, elts1+sizeof(elts1)/sizeof(elts1[0]) ); - - std::string elts2[] = { "bar", "foo" }; - BOOST_CHECK_EQUAL_COLLECTIONS( PacketRegistry::begin(), - PacketRegistry::end(), - elts2+0, elts2+sizeof(elts2)/sizeof(elts2[0]) ); + BOOST_CHECK_EQUAL_COLLECTIONS( + boost::make_transform_iterator( + PacketRegistry::begin(), + boost::multi_index::member::Entry, unsigned, + &senf::PacketRegistry::Entry::key>()), + boost::make_transform_iterator( + PacketRegistry::end(), + boost::multi_index::member::Entry, unsigned, + &senf::PacketRegistry::Entry::key>()), + elts1+0, elts1+sizeof(elts1)/sizeof(elts1[0]) ); + + std::string elts2[] = { "bar", "foo", "foo" }; + BOOST_CHECK_EQUAL_COLLECTIONS( + boost::make_transform_iterator( + PacketRegistry::begin(), + boost::multi_index::member::Entry, std::string, + &senf::PacketRegistry::Entry::key>()), + boost::make_transform_iterator( + PacketRegistry::end(), + boost::multi_index::member::Entry, std::string, + &senf::PacketRegistry::Entry::key>()), + elts2+0, elts2+sizeof(elts2)/sizeof(elts2[0]) ); std::stringstream s; senf::dumpPacketRegistries(s); @@ -98,15 +119,16 @@ SENF_AUTO_UNIT_TEST(packetRegistry_test) contains, (s.str()) ("(anonymous namespace)::BaseTag:\n" - " 0x00000001 ( 1) (....) (anonymous namespace)::FooPacketType\n" - " 0x00000002 ( 2) (....) (anonymous namespace)::BarPacketType\n" + " 0x00000001 ( 1) (....) 0 (anonymous namespace)::FooPacketType\n" + " 0x00000002 ( 2) (....) 0 (anonymous namespace)::BarPacketType\n" "\n")); BOOST_CHECK_PREDICATE( contains, (s.str()) ("(anonymous namespace)::StringTag:\n" - " bar (anonymous namespace)::BarPacketType\n" - " foo (anonymous namespace)::FooPacketType\n" + " bar 0 (anonymous namespace)::BarPacketType\n" + " foo 1 (anonymous namespace)::FooPacketType\n" + " foo 0 (anonymous namespace)::OtherPacketType\n" "\n" )); } @@ -117,14 +139,15 @@ SENF_AUTO_UNIT_TEST(packetRegistry_test) contains, (s.str()) ("(anonymous namespace)::BaseTag:\n" - " 0x00000001 ( 1) (....) (anonymous namespace)::FooPacketType\n" + " 0x00000001 ( 1) (....) 0 (anonymous namespace)::FooPacketType\n" "\n")); BOOST_CHECK_PREDICATE( contains, (s.str()) ("(anonymous namespace)::StringTag:\n" - " bar (anonymous namespace)::BarPacketType\n" - " foo (anonymous namespace)::FooPacketType\n" + " bar 0 (anonymous namespace)::BarPacketType\n" + " foo 1 (anonymous namespace)::FooPacketType\n" + " foo 0 (anonymous namespace)::OtherPacketType\n" "\n" )); SENF_CHECK_NO_THROW( PacketRegistry::unregisterPacket(1u) ); @@ -140,12 +163,13 @@ SENF_AUTO_UNIT_TEST(packetRegistry_test) contains, (s.str()) ("(anonymous namespace)::StringTag:\n" - " foo (anonymous namespace)::FooPacketType\n" + " foo 1 (anonymous namespace)::FooPacketType\n" + " foo 0 (anonymous namespace)::OtherPacketType\n" "\n" )); } } -///////////////////////////////cc.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_