X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.test.cc;h=b80d3fef67f06eb9fe13c55013640a7c5c4a0c39;hb=33adfa86c0b25cb6eeda0fa12d47e077e488375a;hp=d35523cdc696bdd72eb3a81955d8ade38c97063e;hpb=cf48e83de9d4793ca5bd67d1e5acdb5b20968638;p=senf.git diff --git a/senf/Packets/GenericTLV.test.cc b/senf/Packets/GenericTLV.test.cc index d35523c..b80d3fe 100644 --- a/senf/Packets/GenericTLV.test.cc +++ b/senf/Packets/GenericTLV.test.cc @@ -1,9 +1,9 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY -// @AUTHOR@ +// Thorsten Horstmann // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ // Custom includes #include "GenericTLV.hh" -#include +#include #include #include @@ -41,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 @@ -62,17 +64,39 @@ namespace { type() = typeId; length_() = 4; } - static type_t::value_type const typeId; + static type_t::value_type const typeId = 0x42; + + 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"; + } + }; + + 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"; + os << " MyConcreteTLVParser\n" + << " type: " << senf::format::dumpint(type()) << "\n" + << " length: " << senf::format::dumpint(length()) << "\n" + << " value: " << senf::format::dumpint(myValue()) << "\n"; } }; - MyConcreteTLVParser::type_t::value_type const MyConcreteTLVParser::typeId = 0x42; class MyTestPacketParser : public senf::PacketParserBase @@ -159,19 +183,40 @@ BOOST_AUTO_UNIT_TEST(GenericTLV_registry) conreteTLVParser.myValue() << 0xffff; p.finalizeThis(); - typedef senf::GenericTLVParserRegistry MyTLVParserRegistry; - std::stringstream ss; - MyTLVParserRegistry::instance().dump(ss, *tlvContainer.begin()); - BOOST_CHECK_EQUAL( ss.str().substr(0,56), "GenericTLVParser<(anonymous namespace)::MyTLVParserBase>" ); + (*tlvContainer.begin()).dump( ss); + BOOST_CHECK_EQUAL( ss.str().substr(0,58), + " GenericTLVParser<(anonymous namespace)::MyTLVParserBase>" ); - MyTLVParserRegistry::instance().registerParser(); + senf::GenericTLVParserRegistry::instance() + .registerParser(); ss.str(""); ss.clear(); - MyTLVParserRegistry::instance().dump(ss, *tlvContainer.begin()); - BOOST_CHECK_EQUAL( ss.str().substr(0,19), "MyConcreteTLVParser" ); + (*tlvContainer.begin()).dump( ss); + 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_