4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@berlios.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 \brief MIH Message-Registry unit tests */
26 //#include "MIHPacket.test.hh"
27 //#include "MIHPacket.test.ih"
30 #include "MIHMessageRegistry.hh"
31 #include "MIHPacket.hh"
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 class TestMessagePacketParser
43 : public senf::PacketParserBase
45 # include SENF_PARSER()
46 SENF_PARSER_FIELD ( registerRequestCodeTLV, senf::MIHRegisterReqCodeTLVParser );
47 SENF_PARSER_FINALIZE ( TestMessagePacketParser );
51 struct TestMessagePacketType
52 : public senf::PacketTypeBase,
53 public senf::PacketTypeMixin<TestMessagePacketType>
55 typedef senf::ConcretePacket<TestMessagePacketType> packet;
56 typedef senf::PacketTypeMixin<TestMessagePacketType> mixin;
57 typedef TestMessagePacketParser parser;
59 using mixin::nextPacketRange;
61 using mixin::initSize;
63 static const boost::uint16_t MESSAGE_ID;
66 struct ValidatedTestMessagePacketType
67 : public senf::PacketTypeBase,
68 public senf::PacketTypeMixin<ValidatedTestMessagePacketType>
70 typedef senf::ConcretePacket<ValidatedTestMessagePacketType> packet;
71 typedef senf::PacketTypeMixin<ValidatedTestMessagePacketType> mixin;
72 typedef TestMessagePacketParser parser;
74 using mixin::nextPacketRange;
76 using mixin::initSize;
78 static const boost::uint16_t MESSAGE_ID;
80 static std::pair<bool, std::string> validate(packet message) {
81 return std::make_pair(message->registerRequestCodeTLV().value() == 1, "");
85 typedef senf::ConcretePacket<TestMessagePacketType> TestMessagePacket;
86 typedef senf::ConcretePacket<ValidatedTestMessagePacketType> ValidatedTestMessagePacket;
88 const boost::uint16_t TestMessagePacketType::MESSAGE_ID = 42;
89 const boost::uint16_t ValidatedTestMessagePacketType::MESSAGE_ID = 43;
91 SENF_MIH_PACKET_REGISTRY_REGISTER( TestMessagePacket );
92 SENF_MIH_PACKET_REGISTRY_REGISTER( ValidatedTestMessagePacket );
96 SENF_AUTO_UNIT_TEST(MIHMessageRegistry_validate)
98 MIHPacket mihPacket (MIHPacket::create());
99 mihPacket->transactionId() = 21;
100 mihPacket->src_mihfId().value( "senf@berlios.de");
101 mihPacket->dst_mihfId().value( "test");
103 BOOST_CHECK(! MIHPacketType::validate( mihPacket).first);
105 mihPacket.finalizeThis();
106 BOOST_CHECK( MIHPacketType::validate( mihPacket).first);
109 TestMessagePacket testMessage (TestMessagePacket::createAfter(mihPacket));
110 mihPacket.finalizeAll();
111 BOOST_CHECK( MIHPacketType::validate( mihPacket).first);
114 ValidatedTestMessagePacket testMessage (ValidatedTestMessagePacket::createAfter(mihPacket));
115 mihPacket.finalizeAll();
116 BOOST_CHECK(! MIHPacketType::validate( mihPacket).first);
117 testMessage->registerRequestCodeTLV().value() << 1;
118 BOOST_CHECK( MIHPacketType::validate( mihPacket).first);
122 //-/////////////////////////////////////////////////////////////////////////////////////////////////
129 // c-file-style: "senf"
130 // indent-tabs-mode: nil
131 // ispell-local-dictionary: "american"
132 // compile-command: "scons -u test"
133 // comment-column: 40