Packets: Fix next()/prev() etc. semantics, naming and doc
[senf.git] / Packets / Packet.test.cc
index baa89f0..d738f60 100644 (file)
@@ -1,6 +1,8 @@
+// $Id$
+//
 // Copyright (C) 2007 
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
+// 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
@@ -28,7 +30,7 @@
 #include <sstream>
 #include "Packets.hh"
 
-#include <boost/test/auto_unit_test.hpp>
+#include "../Utils/auto_unit_test.hh"
 #include <boost/test/test_tools.hpp>
 
 #define prefix_
@@ -57,9 +59,9 @@ namespace {
     {
 #       include SENF_FIXED_PARSER()
         
-        SENF_PARSER_FIELD( type,     senf::Parse_UInt16 );
-        SENF_PARSER_FIELD( length,   senf::Parse_Int32  );
-        SENF_PARSER_FIELD( reserved, senf::Parse_UInt16 );
+        SENF_PARSER_FIELD( type,     senf::UInt16Parser );
+        SENF_PARSER_FIELD( length,   senf::Int32Parser  );
+        SENF_PARSER_FIELD( reserved, senf::UInt16Parser );
 
         SENF_PARSER_FINALIZE(BarPacketParser);
     };
@@ -153,7 +155,7 @@ BOOST_AUTO_UNIT_TEST(packet)
                        BarPacket::type::parser::type_t::value_type(-1) );
     packet.last().append(FooPacket::create());
     packet.finalize();
-    BOOST_CHECK_EQUAL( packet.next<BarPacket>()->type(), 1u );
+    BOOST_CHECK_EQUAL( packet.find<BarPacket>()->type(), 1u );
 
     BOOST_CHECK( packet.factory() == FooPacket::factory() );
 
@@ -164,25 +166,19 @@ BOOST_AUTO_UNIT_TEST(packet)
     BOOST_REQUIRE( packet.next() );
     BOOST_REQUIRE( packet.next().is<BarPacket>() );
     BOOST_CHECK( packet.last().is<FooPacket>() );
-    BOOST_CHECK_EQUAL( packet.last<BarPacket>()->type(), 1u );
+    BOOST_CHECK_EQUAL( packet.last().rfind<BarPacket>()->type(), 1u );
     BOOST_CHECK_EQUAL( packet.next().size(), 11u );
     BOOST_REQUIRE( packet.next().next() );
     BOOST_CHECK( packet.next().next().is<FooPacket>() );
     BOOST_CHECK( ! packet.next().next().next() );
     BOOST_CHECK_EQUAL( packet.next().next().data()[0], 0x81u );
 
-    BOOST_CHECK( packet.first<FooPacket>() == packet );
-    BOOST_CHECK( packet.first<FooPacket>(senf::nothrow) == packet );
-    BOOST_CHECK( packet.last<BarPacket>() == packet.last().prev() );
-    BOOST_CHECK( packet.last<BarPacket>(senf::nothrow) == packet.last().prev() );
-    BOOST_CHECK( packet.findNext<FooPacket>() == packet );
-    BOOST_CHECK( packet.findNext<FooPacket>(senf::nothrow) == packet );
-    BOOST_CHECK( packet.last().findPrev<FooPacket>() == packet.last() );
-    BOOST_CHECK( packet.last().findPrev<FooPacket>(senf::nothrow) == packet.last() );
+    BOOST_CHECK( packet.first().find<FooPacket>() == packet );
+    BOOST_CHECK( packet.last().rfind<BarPacket>() == packet.last().prev() );
+    BOOST_CHECK( packet.find<FooPacket>() == packet );
+    BOOST_CHECK( packet.last().rfind<FooPacket>() == packet.last() );
     BOOST_CHECK( packet.next<BarPacket>() == packet.next() );
-    BOOST_CHECK( packet.next<BarPacket>(senf::nothrow) == packet.next() );
-    BOOST_CHECK( packet.last().prev<FooPacket>() == packet );
-    BOOST_CHECK( packet.last().prev<FooPacket>(senf::nothrow) == packet );
+    BOOST_CHECK( packet.last().prev().prev<FooPacket>() == packet );
 }
 
 BOOST_AUTO_UNIT_TEST(concretePacket)