+// $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
// Custom includes
#include <sstream>
-#include "PacketType.hh"
-#include "PacketRegistry.hh"
-#include "Packet.hh"
-#include "ParseInt.hh"
-#include "PacketParser.hh"
-#include "DataPacket.hh"
-
-#include <boost/test/auto_unit_test.hpp>
+#include "Packets.hh"
+
+#include "../Utils/auto_unit_test.hh"
#include <boost/test/test_tools.hpp>
#define prefix_
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<Parse_Type> (i()); }
- Parse_Length length() const { return parse<Parse_Length> (i()+2); }
- Parse_Reserved reserved() const { return parse<Parse_Reserved> (i()+6); }
+ SENF_PARSER_FINALIZE(BarPacketParser);
};
struct BarPacketType
<< "length: " << p->length() << "\n";
}
static void finalize(packet p) {
- if (p.next())
+ if (p.next(senf::nothrow))
p->type() = senf::PacketRegistry<RegTag>::key(p.next());
else
p->type() = -1;
typedef BarPacketType::packet BarPacket;
namespace reg {
- senf::PacketRegistry<RegTag>::RegistrationProxy<FooPacketType> registerFoo(1u);
- senf::PacketRegistry<RegTag>::RegistrationProxy<BarPacketType> registerBar(2u);
+ senf::PacketRegistry<RegTag>::RegistrationProxy<FooPacket> registerFoo(1u);
+ senf::PacketRegistry<RegTag>::RegistrationProxy<BarPacket> registerBar(2u);
}
}
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 );
packet.finalize();
BOOST_CHECK_EQUAL( packet.last().as<BarPacket>()->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<BarPacket>()->type(), 1u );
+ BOOST_CHECK_EQUAL( packet.find<BarPacket>()->type(), 1u );
BOOST_CHECK( packet.factory() == FooPacket::factory() );
- senf::Packet::byte data[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x81, 0x82, 0x83 };
+ senf::PacketData::byte data[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x81, 0x82, 0x83 };
BarPacket::createAfter(packet,data);
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( ! packet.next().next().next(senf::nothrow) );
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)
{
- FooPacket::byte data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
+ senf::PacketData::byte data[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
BOOST_CHECK_EQUAL( FooPacket::create().size(), 4u );
BOOST_CHECK_EQUAL( FooPacket::create(FooPacket::noinit).size(), 0u );