// $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 <tho@berlios.de>
//
// 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
// Custom includes
#include "GenericTLV.hh"
-#include <senf/Utils/hexdump.hh>
#include <senf/Utils/auto_unit_test.hh>
#include <boost/test/test_tools.hpp>
SENF_PARSER_FIELD ( type, senf::UInt8Parser );
SENF_PARSER_FIELD_RO ( length, senf::UInt8Parser );
SENF_PARSER_FINALIZE ( MyTLVParserBase );
+
+ typedef senf::GenericTLVParserRegistry<MyTLVParserBase> Registry;
};
struct MyGenericTLVParser
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
}
+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<MyConcreteTLVParser>());
+ 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<MyTLVParserBase>::instance()
+ .registerParser<MyConcreteTLVParser>();
+ ss.str(""); ss.clear();
+
+ (*tlvContainer.begin()).dump( ss);
+ BOOST_CHECK_EQUAL( ss.str().substr(0,21), " MyConcreteTLVParser" );
+}
+
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_