X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacket.test.cc;h=18b8fe9ed174a8ee2b3453fe00b93299ca011622;hb=92f8630b75f3ef50e73c48cde58645dcd1534e27;hp=937901c977e6d7ca475dc3acb355789cb10d3b7c;hpb=784b5901486e0bcb0eb5dadd3a2f4fc31810bd66;p=senf.git diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index 937901c..18b8fe9 100644 --- a/Packets/Packet.test.cc +++ b/Packets/Packet.test.cc @@ -21,13 +21,14 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief Packet.test unit tests */ + \brief Packet unit tests */ //#include "Packet.test.hh" //#include "Packet.test.ih" // Custom includes #include +#include #include "Packets.hh" #include "../Utils/auto_unit_test.hh" @@ -109,11 +110,33 @@ namespace { senf::PacketRegistry::RegistrationProxy registerBar(2u); } + struct IntAnnotation { + unsigned value; + }; + + struct LargeAnnotation { + char value[32]; + }; + + struct ComplexAnnotation : senf::ComplexAnnotation + { + std::string s; + int i; + }; + + struct ComplexEmptyAnnotation : senf::ComplexAnnotation + {}; + + struct InvalidAnnotation + { + std::string value; + }; + } BOOST_AUTO_UNIT_TEST(packet) { - senf::Packet packet (FooPacket::create()); + senf::Packet packet (FooPacket::create()); BarPacket::createAfter(packet); BOOST_REQUIRE( packet ); @@ -159,11 +182,14 @@ BOOST_AUTO_UNIT_TEST(packet) packet.dump(s); BOOST_CHECK_EQUAL( s.str(), "BarPacket:\ntype: 0\nlength: 0\n" ); - packet.finalize(); + packet.finalizeAll(); BOOST_CHECK_EQUAL( packet.last().as()->type(), - BarPacket::type::parser::type_t::value_type(-1) ); + BarPacket::Parser::type_t::value_type(-1) ); packet.last().append(FooPacket::create()); - packet.finalize(); + packet.finalizeThis(); + packet.finalizeTo(); + packet.finalizeTo(packet.find()); + packet.finalizeAll(); BOOST_CHECK_EQUAL( packet.find()->type(), 1u ); BOOST_CHECK( packet.factory() == FooPacket::factory() ); @@ -171,7 +197,7 @@ BOOST_AUTO_UNIT_TEST(packet) senf::PacketData::byte data[] = { 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x82, 0x83 }; - BarPacket::createAfter(packet,data); + BarPacket::createAfter(packet, data); BOOST_REQUIRE( packet.next() ); BOOST_REQUIRE( packet.next().is() ); BOOST_CHECK( packet.last().is() ); @@ -188,6 +214,10 @@ BOOST_AUTO_UNIT_TEST(packet) BOOST_CHECK( packet.last().rfind() == packet.last() ); BOOST_CHECK( packet.next() == packet.next() ); BOOST_CHECK( packet.last().prev().prev() == packet ); + + senf::DataPacket::createAfter(packet); + BOOST_CHECK_THROW( packet.next().next().next().parseNextAs(), + senf::InvalidPacketChainException ); } BOOST_AUTO_UNIT_TEST(concretePacket) @@ -231,6 +261,59 @@ BOOST_AUTO_UNIT_TEST(concretePacket) BOOST_CHECK_EQUAL( BarPacket::create()->reserved(), 0xA0A0u ); } +BOOST_AUTO_UNIT_TEST(packetAssign) +{ + BarPacket bar1 (BarPacket::create()); + BarPacket bar2 (BarPacket::create()); + + bar2->type() << 0x2A2Bu; + bar1.parser() << bar2; + + BOOST_CHECK_EQUAL( bar1->type(), 0x2A2Bu ); +} + +BOOST_AUTO_UNIT_TEST(packetAnnotation) +{ + senf::Packet packet (FooPacket::create()); + BarPacket::createAfter(packet); + + ComplexAnnotation & ca (packet.annotation()); + ca.s = "dead beef"; + ca.i = 0x12345678; + SENF_CHECK_NO_THROW( packet.annotation().value = 0xDEADBEEF ); + + senf::Packet p2 (packet.next()); + + BOOST_CHECK_EQUAL( p2.annotation().value, 0xDEADBEEFu ); + BOOST_CHECK_EQUAL( p2.annotation().s, "dead beef" ); + BOOST_CHECK_EQUAL( p2.annotation().i, 0x12345678 ); + + BOOST_CHECK( senf::detail::AnnotationIndexer::Small ); + BOOST_CHECK( ! senf::detail::AnnotationIndexer::Small ); + BOOST_CHECK( ! senf::detail::AnnotationIndexer::Small ); + BOOST_CHECK( ! senf::detail::AnnotationIndexer::Small ); +} + +#ifdef COMPILE_CHECK + +COMPILE_FAIL(invalidAnnotation) +{ +#if 0 // The traits check fails for user defined but trivial constructors so ... +# ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS + + senf::Packet packet (FooPacket::create()); + (void) packet.annotation(); + +# else +# endif +#endif + + invalid_annotation_check_disabled(); + +} + +#endif + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_