switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / Packet.test.cc
index 72e0569..c714924 100644 (file)
@@ -2,23 +2,28 @@
 //
 // Copyright (C) 2007
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
-// Competence Center NETwork research (NET), St. Augustin, GERMANY
-//     Stefan Bund <g0dil@berlios.de>
 //
-// 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 <g0dil@berlios.de>
 
 /** \file
     \brief Packet unit tests */
@@ -36,7 +41,7 @@
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
-///////////////////////////////cc.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
 namespace {
 
@@ -160,6 +165,9 @@ SENF_AUTO_UNIT_TEST(packet)
     senf::Packet packet (FooPacket::create());
     BarPacket::createAfter(packet);
 
+    BOOST_CHECK_THROW( senf::Packet().as<BarPacket>(), senf::WrapException<std::bad_cast> );
+    BOOST_CHECK_THROW( packet.as<BarPacket>(), senf::WrapException<std::bad_cast> );
+
     BOOST_REQUIRE( packet );
     BOOST_CHECK( packet.next() );
     BOOST_CHECK( ! packet.next().next(senf::nothrow) );
@@ -178,8 +186,18 @@ SENF_AUTO_UNIT_TEST(packet)
     BOOST_CHECK( packet.first() == packet );
     BOOST_CHECK( packet.last() == packet.next() );
 
+    BOOST_CHECK( ! packet.is_shared() );
+    {
+        senf::Packet p2 (packet);
+        BOOST_CHECK( packet.is_shared() );
+        BOOST_CHECK( p2.is_shared() );
+    }
+    BOOST_CHECK( ! packet.is_shared() );
+
     senf::Packet p2 (packet.next());
     BOOST_CHECK( p2 );
+    BOOST_CHECK( packet.is_shared() );
+    BOOST_CHECK( p2.is_shared() );
     packet.parseNextAs<FooPacket>();
     BOOST_CHECK_EQUAL( packet.size(), 12u );
     BOOST_CHECK_EQUAL( packet.next().size(), 8u );
@@ -188,6 +206,7 @@ SENF_AUTO_UNIT_TEST(packet)
     BOOST_CHECK( packet.next().as<FooPacket>() );
 
     p2 = packet.next().clone();
+    BOOST_CHECK( ! packet.is_shared() );
     BOOST_REQUIRE( p2 );
     packet.next().append( p2 );
     BOOST_REQUIRE( packet.next().next() );
@@ -338,14 +357,23 @@ SENF_AUTO_UNIT_TEST(packetAnnotation)
     BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().s, "dead beef" );
     BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().i, 0x12345678 );
 
+    senf::Packet pClone (packet.clone());
+
+    p2.clearAnnotations();
+    BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().s, "empty" );
+    BOOST_CHECK_EQUAL( p2.annotation<ComplexAnnotation>().i, -1 );
+    BOOST_CHECK_EQUAL( p2.annotation<IntAnnotation>().value, 0 );
+
+    BOOST_CHECK_EQUAL( pClone.annotation<IntAnnotation>().value, 0xDEADBEEFu );
+    BOOST_CHECK_EQUAL( pClone.annotation<ComplexAnnotation>().s, "dead beef" );
+    BOOST_CHECK_EQUAL( pClone.annotation<ComplexAnnotation>().i, 0x12345678 );
+
     BOOST_CHECK( Reg::lookup<IntAnnotation>() >= 0 );
     BOOST_CHECK( Reg::lookup<LargeAnnotation>() < 0 );
     BOOST_CHECK( Reg::lookup<ComplexAnnotation>() < 0 );
     BOOST_CHECK( Reg::lookup<ComplexEmptyAnnotation>() < 0 );
 
-#ifdef SENF_DEBUG
     std::stringstream ss;
-
     senf::dumpPacketAnnotationRegistry(ss);
     BOOST_CHECK_EQUAL(
         ss.str(),
@@ -356,7 +384,6 @@ SENF_AUTO_UNIT_TEST(packetAnnotation)
         "(anonymous namespace)::ComplexEmptyAnnotation             no    yes          1\n"
         "(anonymous namespace)::IntAnnotation                      yes   no           4\n"
         "(anonymous namespace)::LargeAnnotation                    no    no          32\n" );
-#endif
 }
 
 #ifdef COMPILE_CHECK
@@ -379,7 +406,7 @@ COMPILE_FAIL(invalidAnnotation)
 
 #endif
 
-///////////////////////////////cc.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #undef prefix_
 
 \f