X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FPacket.test.cc;h=8fe977146782417937dd220dcaebcf4e33c56b3c;hb=9bc655e14d2d8c204ed835896cb51e42d49bd68f;hp=aeca47db3b076fb4d5e377069f8f60f9ce6bf609;hpb=fe0d7de8d8f1044759fabdbb534fef41f9944ffc;p=senf.git diff --git a/senf/Packets/Packet.test.cc b/senf/Packets/Packet.test.cc index aeca47d..8fe9771 100644 --- a/senf/Packets/Packet.test.cc +++ b/senf/Packets/Packet.test.cc @@ -29,6 +29,7 @@ // Custom includes #include #include +#include #include "Packets.hh" #include @@ -90,8 +91,8 @@ namespace { using mixin::init; static void dump(packet p, std::ostream & os) { os << "BarPacket:\n" - << " type: " << p->type() << "\n" - << " length: " << p->length() << "\n"; + << senf::fieldName("type") << p->type() << "\n" + << senf::fieldName("length") << p->length() << "\n"; } static void finalize(packet p) { if (p.next(senf::nothrow)) @@ -106,12 +107,12 @@ namespace { typedef BarPacketType::packet BarPacket; namespace reg { - senf::PacketRegistry::RegistrationProxy registerFoo(1u); - senf::PacketRegistry::RegistrationProxy registerBar(2u); + senf::PacketRegistry::ScopedRegistrationProxy registerFoo(1u); + senf::PacketRegistry::ScopedRegistrationProxy registerBar(2u); } struct IntAnnotation { - unsigned value; + boost::uint32_t value; }; std::ostream & operator<<(std::ostream & os, IntAnnotation const & v) @@ -126,9 +127,12 @@ namespace { struct ComplexAnnotation : senf::ComplexAnnotation { - ComplexAnnotation() : s(), i() {} + ComplexAnnotation() : s("empty"), i(-1) {} std::string s; - int i; + boost::int32_t i; + // padding so the size does not depend on the platform ... + struct _ {std::string s;boost::int32_t i;}; + char __ [32-sizeof(_)]; }; std::ostream & operator<<(std::ostream & os, ComplexAnnotation const & v) @@ -200,11 +204,10 @@ SENF_AUTO_UNIT_TEST(packet) packet.dump(s); BOOST_CHECK_EQUAL( s.str(), "Annotations:\n" - " (anonymous namespace)::ComplexAnnotation: no value\n" - " (anonymous namespace)::IntAnnotation: 0\n" + " (anonymous namespace)::IntAnnotation : 0\n" "BarPacket:\n" - " type: 0\n" - " length: 0\n" ); + " type : 0\n" + " length : 0\n" ); packet.finalizeAll(); BOOST_CHECK_EQUAL( packet.last().as()->type(), @@ -315,10 +318,16 @@ SENF_AUTO_UNIT_TEST(packetAssign) SENF_AUTO_UNIT_TEST(packetAnnotation) { + typedef senf::detail::AnnotationRegistry Reg; + senf::Packet packet (FooPacket::create()); BarPacket::createAfter(packet); ComplexAnnotation & ca (packet.annotation()); + + BOOST_CHECK_EQUAL( ca.s, "empty" ); + BOOST_CHECK_EQUAL( ca.i, -1 ); + ca.s = "dead beef"; ca.i = 0x12345678; SENF_CHECK_NO_THROW( packet.annotation().value = 0xDEADBEEF ); @@ -329,10 +338,22 @@ SENF_AUTO_UNIT_TEST(packetAnnotation) 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 ); + BOOST_CHECK( Reg::lookup() >= 0 ); + BOOST_CHECK( Reg::lookup() < 0 ); + BOOST_CHECK( Reg::lookup() < 0 ); + BOOST_CHECK( Reg::lookup() < 0 ); + + std::stringstream ss; + senf::dumpPacketAnnotationRegistry(ss); + BOOST_CHECK_EQUAL( + ss.str(), + "SENF_PACKET_ANNOTATION_SLOTS = 8\n" + "SENF_PACKET_ANNOTATION_SLOTSIZE = 16\n" + "TYPE FAST COMPLEX SIZE\n" + "(anonymous namespace)::ComplexAnnotation no yes 32\n" + "(anonymous namespace)::ComplexEmptyAnnotation no yes 1\n" + "(anonymous namespace)::IntAnnotation yes no 4\n" + "(anonymous namespace)::LargeAnnotation no no 32\n" ); } #ifdef COMPILE_CHECK