Packets/DefaultBundle: IPv6ExtensionsHeaders: set nextHeader to 59 if their is no...
[senf.git] / senf / Packets / GenericTLV.test.cc
index 84be10c..6b93252 100644 (file)
@@ -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 <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
@@ -25,7 +25,6 @@
 
 // Custom includes
 #include "GenericTLV.hh"
-#include <senf/Utils/hexdump.hh>
 
 #include <senf/Utils/auto_unit_test.hh>
 #include <boost/test/test_tools.hpp>
@@ -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<MyTLVParserBase> 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<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_