From: tho Date: Wed, 6 Oct 2010 13:53:51 +0000 (+0000) Subject: Packets: added unit test for last ListBParser and ListNParser fix X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=5d7f7add811bc8fa87b91653811583f9593aeea2;p=senf.git Packets: added unit test for last ListBParser and ListNParser fix git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1728 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/senf/Packets/ListBParser.test.cc b/senf/Packets/ListBParser.test.cc index 0d30cb5..8825100 100644 --- a/senf/Packets/ListBParser.test.cc +++ b/senf/Packets/ListBParser.test.cc @@ -47,6 +47,21 @@ namespace { SENF_PARSER_VECTOR( vec, size, senf::UInt16Parser ); SENF_PARSER_FINALIZE(VectorParser); + + typedef std::vector value_type; + + value_type value() const { + value_type v (vec().begin(), vec().end()); + return v; + } + void value(value_type const & v) { + vec_t::container container (vec()); + container.clear(); + for (value_type::const_iterator i=v.begin(); i!=v.end(); ++i) + container.push_back( *i); + } + operator value_type() const { return value(); } + VectorParser const & operator= (value_type const & other) { value(other); return *this; } }; typedef senf::ListParser< @@ -171,6 +186,20 @@ namespace { SENF_PARSER_FINALIZE(TestListParser); }; + struct TestListPacketType + : public senf::PacketTypeBase, + public senf::PacketTypeMixin + { + typedef senf::PacketTypeMixin mixin; + typedef senf::ConcretePacket packet; + typedef TestListParser parser; + + using mixin::nextPacketRange; + using mixin::initSize; + using mixin::init; + }; + typedef senf::ConcretePacket TestListPacket; + } SENF_AUTO_UNIT_TEST(listBytesMacro) @@ -249,8 +278,6 @@ namespace { SENF_PARSER_FINALIZE(TestPacketSizeList); }; - - } SENF_AUTO_UNIT_TEST(listBytesParser_packetSize) @@ -341,6 +368,17 @@ SENF_AUTO_UNIT_TEST(listBytesParser_packetSize) } } +SENF_AUTO_UNIT_TEST(listBytesMacro_stress) +{ + TestListPacket testListPacket (TestListPacket::create()); + for (unsigned i=0; i<12; ++i) { + VectorParser::value_type vec( 4, 42); + testListPacket->list2().push_back( vec); + } + BOOST_CHECK_EQUAL( testListPacket->list2().size(), 12u ); + +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ diff --git a/senf/Packets/ListNParser.test.cc b/senf/Packets/ListNParser.test.cc index a28f765..8b30ba7 100644 --- a/senf/Packets/ListNParser.test.cc +++ b/senf/Packets/ListNParser.test.cc @@ -48,6 +48,21 @@ namespace { SENF_PARSER_VECTOR( vec, size, senf::UInt16Parser ); SENF_PARSER_FINALIZE(MyVec); + + typedef std::vector value_type; + + value_type value() const { + value_type v (vec().begin(), vec().end()); + return v; + } + void value(value_type const & v) { + vec_t::container container (vec()); + container.clear(); + for (value_type::const_iterator i=v.begin(); i!=v.end(); ++i) + container.push_back( *i); + } + operator value_type() const { return value(); } + MyVec const & operator= (value_type const & other) { value(other); return *this; } }; typedef senf::ListParser< @@ -151,20 +166,44 @@ namespace { static unsigned set(unsigned v) { return 2*v; } }; - struct TestListParser + struct TestListParserBase : public senf::PacketParserBase { # include SENF_PARSER() - SENF_PARSER_PRIVATE_FIELD ( size1 , senf::UInt8Parser ); - SENF_PARSER_PRIVATE_FIELD ( size2 , senf::UInt8Parser ); - SENF_PARSER_FIELD ( dummy , senf::UInt32Parser ); - SENF_PARSER_LIST ( list1 , transform(TestTransform, size1) , MyVec ); - SENF_PARSER_LIST ( list2 , size2 , MyVec ); + SENF_PARSER_FIELD_RO ( size1 , senf::UInt8Parser ); + SENF_PARSER_FIELD_RO ( size2 , senf::UInt8Parser ); + + SENF_PARSER_FINALIZE(TestListParserBase); + }; + + struct TestListParser + : public TestListParserBase + { +# include SENF_PARSER() + SENF_PARSER_INHERIT ( TestListParserBase ); + + SENF_PARSER_FIELD ( dummy , senf::UInt32Parser ); + SENF_PARSER_LIST ( list1 , transform(TestTransform, size1) , MyVec ); + SENF_PARSER_LIST ( list2 , size2 , MyVec ); SENF_PARSER_FINALIZE(TestListParser); }; + struct TestListPacketType + : public senf::PacketTypeBase, + public senf::PacketTypeMixin + { + typedef senf::PacketTypeMixin mixin; + typedef senf::ConcretePacket packet; + typedef TestListParser parser; + + using mixin::nextPacketRange; + using mixin::initSize; + using mixin::init; + }; + typedef senf::ConcretePacket TestListPacket; + } SENF_AUTO_UNIT_TEST(listMacro) @@ -229,6 +268,16 @@ SENF_AUTO_UNIT_TEST(listMacro) ++i; BOOST_CHECK( i == list.end() ); } +} + +SENF_AUTO_UNIT_TEST(listMacro_stress) +{ + TestListPacket testListPacket (TestListPacket::create()); + for (unsigned i=0; i<42; ++i) { + MyVec::value_type vec( 4, 42); + testListPacket->list2().push_back( vec); + } + BOOST_CHECK_EQUAL( testListPacket->list2().size(), 42u ); }