X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FPackets%2FGenericTLV.test.cc;h=535875b801e089c5ac86d9259e363517a28268a4;hb=ddb2132be4265f8a0d7d4c954c7c9401e59d027c;hp=2af6ed63b1c9a12b2a69ac5d4a7e61d3a7e24b4d;hpb=767a76da8e5b96a69b620e44d32e0a1b04005679;p=senf.git diff --git a/senf/Packets/GenericTLV.test.cc b/senf/Packets/GenericTLV.test.cc index 2af6ed6..535875b 100644 --- a/senf/Packets/GenericTLV.test.cc +++ b/senf/Packets/GenericTLV.test.cc @@ -2,23 +2,28 @@ // // Copyright (C) 2009 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// 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 -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Thorsten Horstmann /** \file \brief GenericTLV unit tests */ @@ -31,27 +36,27 @@ #include #define prefix_ -///////////////////////////////cc.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace { - struct MyTLVParserBase + struct MyTLVParserBase : public senf::PacketParserBase { # include SENF_PARSER() SENF_PARSER_FIELD ( type, senf::UInt8Parser ); SENF_PARSER_FIELD_RO ( length, senf::UInt8Parser ); SENF_PARSER_FINALIZE ( MyTLVParserBase ); - + typedef senf::GenericTLVParserRegistry Registry; }; - + struct MyGenericTLVParser : public senf::GenericTLVParserBase { typedef senf::GenericTLVParserBase base; MyGenericTLVParser(data_iterator i, state_type s) : base(i,s) {} }; - + struct MyConcreteTLVParser : public MyTLVParserBase { @@ -59,13 +64,13 @@ namespace { SENF_PARSER_INHERIT ( MyTLVParserBase ); SENF_PARSER_FIELD ( myValue, senf::UInt32Parser ); SENF_PARSER_FINALIZE ( MyConcreteTLVParser ); - + SENF_PARSER_INIT() { type() = typeId; length_() = 4; } static type_t::value_type const typeId = 0x42; - + void dump(std::ostream & os) const { boost::io::ios_all_saver ias(os); os << " MyConcreteTLVParser\n" @@ -74,7 +79,7 @@ namespace { << " value: " << senf::format::dumpint(myValue()) << "\n"; } }; - + struct MyConcrete2TLVParser : public MyTLVParserBase { @@ -82,13 +87,13 @@ namespace { 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" @@ -97,7 +102,7 @@ namespace { << " value: " << senf::format::dumpint(myValue()) << "\n"; } }; - + class MyTestPacketParser : public senf::PacketParserBase { @@ -106,7 +111,7 @@ namespace { SENF_PARSER_LIST ( tlv_list, list_length, MyGenericTLVParser ); SENF_PARSER_FINALIZE ( MyTestPacketParser ); }; - + struct MyTestPacketType : public senf::PacketTypeBase, public senf::PacketTypeMixin @@ -124,7 +129,7 @@ namespace { SENF_AUTO_UNIT_TEST(GenericTLV_parser) { - BOOST_CHECK_EQUAL( senf::init_bytes::value, + BOOST_CHECK_EQUAL( senf::init_bytes::value, senf::init_bytes::value) ; unsigned char data[] = { @@ -144,9 +149,9 @@ SENF_AUTO_UNIT_TEST(GenericTLV_parser) SENF_CHECK_EQUAL_COLLECTIONS( data, data+sizeof(data), genericTLVParser.value().begin(), genericTLVParser.value().end() ); - std::vector value (4, 0xab); + std::vector value (4, 0xab); genericTLVParser.value( std::make_pair(0x42, value)); - + BOOST_CHECK( genericTLVParser.is()); MyConcreteTLVParser concreteTLVParser ( genericTLVParser.as()); @@ -162,7 +167,7 @@ SENF_AUTO_UNIT_TEST(GenericTLV_packet) MyConcreteTLVParser tlv ( tlvContainer.push_back_space().init()); tlv.myValue() << 0xffff; p.finalizeThis(); - + unsigned char data[] = { 0x01, // tlv list length // first tlv: @@ -176,23 +181,29 @@ SENF_AUTO_UNIT_TEST(GenericTLV_packet) SENF_AUTO_UNIT_TEST(GenericTLV_registry) { + typedef senf::GenericTLVParserRegistry MyTLVParserRegistry; MyTestPacket p ( MyTestPacket::create()); MyTestPacket::Parser::tlv_list_t::container tlvContainer (p->tlv_list() ); - MyConcreteTLVParser conreteTLVParser ( + 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), + tlvContainer.begin()->dump( ss); + BOOST_CHECK_EQUAL( ss.str().substr(0,58), " GenericTLVParser<(anonymous namespace)::MyTLVParserBase>" ); - - senf::GenericTLVParserRegistry::instance() - .registerParser(); + BOOST_CHECK( ! MyTLVParserRegistry::instance().isRegistered( tlvContainer.begin()->type())); + + MyTLVParserRegistry::instance().registerParser(); + BOOST_CHECK( MyTLVParserRegistry::instance().isRegistered( tlvContainer.begin()->type())); + BOOST_CHECK_EQUAL( + MyTLVParserRegistry::instance().bytes( *tlvContainer.begin()), + senf::bytes( *tlvContainer.begin()) ); + ss.str(""); ss.clear(); - - (*tlvContainer.begin()).dump( ss); + + tlvContainer.begin()->dump( ss); BOOST_CHECK_EQUAL( ss.str().substr(0,21), " MyConcreteTLVParser" ); } @@ -200,25 +211,25 @@ SENF_AUTO_UNIT_TEST(GenericTLV_predicate) { MyTestPacket p ( MyTestPacket::create() ); MyTestPacket::Parser::tlv_list_t::container tlvContainer (p->tlv_list() ); - MyConcreteTLVParser conreteTLVParser ( + MyConcreteTLVParser conreteTLVParser ( tlvContainer.push_back_space().init()); conreteTLVParser.myValue() << 0xffff; - MyConcrete2TLVParser conreteTLVParser2 ( + MyConcrete2TLVParser conreteTLVParser2 ( tlvContainer.push_back_space().init()); conreteTLVParser2.myValue() << 0xdddd; p.finalizeThis(); - -// typedef senf::IPv6HopByHopOptionsPacket::Parser::options_t::container optContainer_t; + +// 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(), + testTlvContainer.begin(), testTlvContainer.end(), senf::detail::Predicate< senf::GenericTLVParserBase, MyConcreteTLVParser>() ); BOOST_CHECK( it->is()) ; } -///////////////////////////////cc.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// #undef prefix_