X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.test.cc;h=b80d3fef67f06eb9fe13c55013640a7c5c4a0c39;hb=b0918b010bd5ebfb4cce6900c6889dbe4767b5f3;hp=5a1d3d6556d4d7cd3f96947dd6c3b9ecdb85b32a;hpb=9ffdaae4804503c4f36a53747c852a87ee626b9e;p=senf.git diff --git a/senf/Packets/GenericTLV.test.cc b/senf/Packets/GenericTLV.test.cc index 5a1d3d6..b80d3fe 100644 --- a/senf/Packets/GenericTLV.test.cc +++ b/senf/Packets/GenericTLV.test.cc @@ -25,6 +25,7 @@ // Custom includes #include "GenericTLV.hh" +#include #include #include @@ -40,6 +41,8 @@ namespace { SENF_PARSER_FIELD ( type, senf::UInt8Parser ); SENF_PARSER_FIELD_RO ( length, senf::UInt8Parser ); SENF_PARSER_FINALIZE ( MyTLVParserBase ); + + typedef senf::GenericTLVParserRegistry Registry; }; struct MyGenericTLVParser @@ -71,6 +74,29 @@ namespace { << " value: " << senf::format::dumpint(myValue()) << "\n"; } }; + + struct MyConcrete2TLVParser + : public MyTLVParserBase + { + # include SENF_PARSER() + SENF_PARSER_INHERIT ( MyTLVParserBase ); + SENF_PARSER_FIELD ( myValue, senf::UInt32Parser ); + SENF_PARSER_FINALIZE ( MyConcrete2TLVParser ); + + SENF_PARSER_INIT() { + type() = typeId; + length_() = 4; + } + static type_t::value_type const typeId = 0x47; + + void dump(std::ostream & os) const { + boost::io::ios_all_saver ias(os); + os << " MyConcreteTLVParser\n" + << " type: " << senf::format::dumpint(type()) << "\n" + << " length: " << senf::format::dumpint(length()) << "\n" + << " value: " << senf::format::dumpint(myValue()) << "\n"; + } + }; class MyTestPacketParser : public senf::PacketParserBase @@ -170,6 +196,27 @@ BOOST_AUTO_UNIT_TEST(GenericTLV_registry) BOOST_CHECK_EQUAL( ss.str().substr(0,21), " MyConcreteTLVParser" ); } +BOOST_AUTO_UNIT_TEST(GenericTLV_predicate) +{ + MyTestPacket p ( MyTestPacket::create() ); + MyTestPacket::Parser::tlv_list_t::container tlvContainer (p->tlv_list() ); + MyConcreteTLVParser conreteTLVParser ( + tlvContainer.push_back_space().init()); + conreteTLVParser.myValue() << 0xffff; + MyConcrete2TLVParser conreteTLVParser2 ( + tlvContainer.push_back_space().init()); + conreteTLVParser2.myValue() << 0xdddd; + p.finalizeThis(); + +// typedef senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t; +// optContainer_t optC (p->tlv_list() ); + + MyTestPacket::Parser::tlv_list_t::container testTlvContainer (p->tlv_list() ); + MyTestPacket::Parser::tlv_list_t::container::iterator it = std::find_if ( + testTlvContainer.begin(), testTlvContainer.end(), + senf::detail::Predicate< senf::GenericTLVParserBase, MyConcreteTLVParser>() ); + BOOST_CHECK( it->is()) ; +} ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_