X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacket.test.cc;h=e61d67adf2818d03850cf552466f9defea254ea7;hb=78807b8db22aec579bc99f9aca673f81ecfff6b0;hp=70b3e1d5e5e9bf4fc1fcaffaf5773de3a33ae637;hpb=914aedddb62c3ca4fcabc881ad12b398a1c120f3;p=senf.git diff --git a/Packets/Packet.test.cc b/Packets/Packet.test.cc index 70b3e1d..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" @@ -109,6 +110,28 @@ 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) @@ -234,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_