X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacket.test.cc;h=e79f172932839ca0223a7e7bb5a207dcc4fc403a;hb=2371b3e67e650b7e829c35e8b4441a8ce2931ac0;hp=a33ccd4faaf804174273748ee1e3e86d6bc8a4ff;hpb=2d6585ff852e9d282c17003ba1db0b73eb3a8500;p=senf.git diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index a33ccd4..e79f172 100644 --- a/Packets/Packet.test.cc +++ b/Packets/Packet.test.cc @@ -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 // // This program is free software; you can redistribute it and/or modify @@ -28,7 +30,7 @@ #include #include "Packets.hh" -#include +#include "../Utils/auto_unit_test.hh" #include #define prefix_ @@ -55,15 +57,13 @@ namespace { struct BarPacketParser : public senf::PacketParserBase { - SENF_PACKET_PARSER_INIT(BarPacketParser); +# include SENF_FIXED_PARSER() - typedef senf::Parse_UInt16 Parse_Type; - typedef senf::Parse_Int32 Parse_Length; - typedef senf::Parse_UInt16 Parse_Reserved; + SENF_PARSER_FIELD( type, senf::UInt16Parser ); + SENF_PARSER_FIELD( length, senf::Int32Parser ); + SENF_PARSER_FIELD( reserved, senf::UInt16Parser ); - Parse_Type type() const { return parse (i()); } - Parse_Length length() const { return parse (i()+2); } - Parse_Reserved reserved() const { return parse (i()+6); } + SENF_PARSER_FINALIZE(BarPacketParser); }; struct BarPacketType @@ -88,7 +88,7 @@ namespace { << "length: " << p->length() << "\n"; } static void finalize(packet p) { - if (p.next()) + if (p.next(senf::nothrow)) p->type() = senf::PacketRegistry::key(p.next()); else p->type() = -1; @@ -113,8 +113,8 @@ BOOST_AUTO_UNIT_TEST(packet) BOOST_REQUIRE( packet ); BOOST_CHECK( packet.next() ); - BOOST_CHECK( ! packet.next().next() ); - BOOST_CHECK( ! packet.prev() ); + BOOST_CHECK( ! packet.next().next(senf::nothrow) ); + BOOST_CHECK( ! packet.prev(senf::nothrow) ); BOOST_CHECK( packet.next().prev() == packet ); BOOST_CHECK( packet.next() != packet ); BOOST_CHECK_EQUAL( packet.size(), 12u ); @@ -152,10 +152,10 @@ BOOST_AUTO_UNIT_TEST(packet) packet.finalize(); BOOST_CHECK_EQUAL( packet.last().as()->type(), - BarPacket::type::parser::Parse_Type::value_type(-1) ); + BarPacket::type::parser::type_t::value_type(-1) ); packet.last().append(FooPacket::create()); packet.finalize(); - BOOST_CHECK_EQUAL( packet.next()->type(), 1u ); + BOOST_CHECK_EQUAL( packet.find()->type(), 1u ); BOOST_CHECK( packet.factory() == FooPacket::factory() ); @@ -166,25 +166,19 @@ BOOST_AUTO_UNIT_TEST(packet) BOOST_REQUIRE( packet.next() ); BOOST_REQUIRE( packet.next().is() ); BOOST_CHECK( packet.last().is() ); - BOOST_CHECK_EQUAL( packet.last()->type(), 1u ); + BOOST_CHECK_EQUAL( packet.last().rfind()->type(), 1u ); BOOST_CHECK_EQUAL( packet.next().size(), 11u ); BOOST_REQUIRE( packet.next().next() ); BOOST_CHECK( packet.next().next().is() ); - BOOST_CHECK( ! packet.next().next().next() ); + BOOST_CHECK( ! packet.next().next().next(senf::nothrow) ); BOOST_CHECK_EQUAL( packet.next().next().data()[0], 0x81u ); - BOOST_CHECK( packet.first() == packet ); - BOOST_CHECK( packet.first(senf::nothrow) == packet ); - BOOST_CHECK( packet.last() == packet.last().prev() ); - BOOST_CHECK( packet.last(senf::nothrow) == packet.last().prev() ); - BOOST_CHECK( packet.findNext() == packet ); - BOOST_CHECK( packet.findNext(senf::nothrow) == packet ); - BOOST_CHECK( packet.last().findPrev() == packet.last() ); - BOOST_CHECK( packet.last().findPrev(senf::nothrow) == packet.last() ); + BOOST_CHECK( packet.first().find() == packet ); + BOOST_CHECK( packet.last().rfind() == packet.last().prev() ); + BOOST_CHECK( packet.find() == packet ); + BOOST_CHECK( packet.last().rfind() == packet.last() ); BOOST_CHECK( packet.next() == packet.next() ); - BOOST_CHECK( packet.next(senf::nothrow) == packet.next() ); - BOOST_CHECK( packet.last().prev() == packet ); - BOOST_CHECK( packet.last().prev(senf::nothrow) == packet ); + BOOST_CHECK( packet.last().prev().prev() == packet ); } BOOST_AUTO_UNIT_TEST(concretePacket)