X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacket.test.cc;h=e61d67adf2818d03850cf552466f9defea254ea7;hb=958bdb52c39fa39f4ef91cafd9628bcb4f85a03c;hp=b88993e4bc67132b3144a8dc9f4704a974a3fc95;hpb=9348e1098d66ac2684c8e280abf8d7143c887982;p=senf.git diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index b88993e..e61d67a 100644 --- a/Packets/Packet.test.cc +++ b/Packets/Packet.test.cc @@ -28,6 +28,7 @@ // Custom includes #include +#include #include "Packets.hh" #include "../Utils/auto_unit_test.hh" @@ -110,14 +111,27 @@ namespace { } struct IntAnnotation { - int value; + unsigned value; + }; + + struct LargeAnnotation { + char value[32]; }; - struct ComplexAnnotation { + struct ComplexAnnotation : senf::ComplexAnnotation + { std::string s; int i; }; + struct ComplexEmptyAnnotation : senf::ComplexAnnotation + {}; + + struct InvalidAnnotation + { + std::string value; + }; + } BOOST_AUTO_UNIT_TEST(packet) @@ -125,10 +139,6 @@ BOOST_AUTO_UNIT_TEST(packet) senf::Packet packet (FooPacket::create()); BarPacket::createAfter(packet); - SENF_CHECK_NO_THROW( packet.annotation().value = 0xDEADBEEF ); - ComplexAnnotation & ca (packet.annotation()); - ca.s = "dead beef"; - ca.i = 0x12345678; BOOST_REQUIRE( packet ); BOOST_CHECK( packet.next() ); BOOST_CHECK( ! packet.next().next(senf::nothrow) ); @@ -247,6 +257,46 @@ BOOST_AUTO_UNIT_TEST(concretePacket) BOOST_CHECK_EQUAL( BarPacket::create()->reserved(), 0xA0A0u ); } +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) +{ +# ifdef BOOST_HAS_TYPE_TRAITS_INTRINSICS + + senf::Packet packet (FooPacket::create()); + (void) packet.annotation(); + +# else + + invalid_annotation_check_disabled(); + +# endif +} + +#endif + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_