X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.test.cc;h=6b93252cbd210406434562385e4788772c7166f9;hb=8bab2fbb2a8272199adc7034ddcd43ecdeb942a9;hp=84be10c9df42ff8e6afa96dfde0b26d283b3f8cc;hpb=a79c5e98760ea8232c13d8266eb7ca0ac5cdefd3;p=senf.git diff --git a/senf/Packets/GenericTLV.test.cc b/senf/Packets/GenericTLV.test.cc index 84be10c..6b93252 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,6 @@ // Custom includes #include "GenericTLV.hh" -#include #include #include @@ -41,6 +40,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 @@ -59,10 +60,18 @@ namespace { SENF_PARSER_FINALIZE ( MyConcreteTLVParser ); SENF_PARSER_INIT() { - type() = TYPEID; + type() = typeId; length_() = 4; - } - static const type_t::value_type TYPEID = 0x42; + } + 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"; + } }; class MyTestPacketParser @@ -141,6 +150,29 @@ BOOST_AUTO_UNIT_TEST(GenericTLV_packet) } +BOOST_AUTO_UNIT_TEST(GenericTLV_registry) +{ + MyTestPacket p ( MyTestPacket::create()); + MyTestPacket::Parser::tlv_list_t::container tlvContainer (p->tlv_list() ); + MyConcreteTLVParser conreteTLVParser ( + tlvContainer.push_back_space().init()); + conreteTLVParser.myValue() << 0xffff; + p.finalizeThis(); + + std::stringstream ss; + (*tlvContainer.begin()).dump( ss); + BOOST_CHECK_EQUAL( ss.str().substr(0,58), + " GenericTLVParser<(anonymous namespace)::MyTLVParserBase>" ); + + senf::GenericTLVParserRegistry::instance() + .registerParser(); + ss.str(""); ss.clear(); + + (*tlvContainer.begin()).dump( ss); + BOOST_CHECK_EQUAL( ss.str().substr(0,21), " MyConcreteTLVParser" ); +} + + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_