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 //-/////////////////////////////////////////////////////////////////////////////////////////////////
39 // we cannot put these test classes into the anonymous namespace because of a g++ bug
40 // see https://svn.boost.org/trac/boost/ticket/3729
45 class TestMessagePacketParser
46 : public senf::PacketParserBase
48 # include SENF_PARSER()
49 SENF_PARSER_FIELD ( registerRequestCodeTLV, senf::MIHRegisterReqCodeTLVParser );
50 SENF_PARSER_FINALIZE ( TestMessagePacketParser );
54 struct TestMessagePacketType
55 : public senf::PacketTypeBase,
56 public senf::PacketTypeMixin<TestMessagePacketType>
58 typedef senf::ConcretePacket<TestMessagePacketType> packet;
59 typedef senf::PacketTypeMixin<TestMessagePacketType> mixin;
60 typedef TestMessagePacketParser parser;
62 using mixin::nextPacketRange;
64 using mixin::initSize;
66 static const boost::uint16_t MESSAGE_ID;
69 struct ValidatedTestMessagePacketType
70 : public senf::PacketTypeBase,
71 public senf::PacketTypeMixin<ValidatedTestMessagePacketType>
73 typedef senf::ConcretePacket<ValidatedTestMessagePacketType> packet;
74 typedef senf::PacketTypeMixin<ValidatedTestMessagePacketType> mixin;
75 typedef TestMessagePacketParser parser;
77 using mixin::nextPacketRange;
79 using mixin::initSize;
81 static const boost::uint16_t MESSAGE_ID;
83 static void validate(packet message) {
84 message->registerRequestCodeTLV().validate();
88 typedef senf::ConcretePacket<TestMessagePacketType> TestMessagePacket;
89 typedef senf::ConcretePacket<ValidatedTestMessagePacketType> ValidatedTestMessagePacket;
91 const boost::uint16_t TestMessagePacketType::MESSAGE_ID = 42;
92 const boost::uint16_t ValidatedTestMessagePacketType::MESSAGE_ID = 43;
98 SENF_MIH_PACKET_REGISTRY_REGISTER( test::TestMessagePacket );
99 SENF_MIH_PACKET_REGISTRY_REGISTER( test::ValidatedTestMessagePacket );
102 SENF_AUTO_UNIT_TEST(MIHMessageRegistry_validate)
104 MIHPacket mihPacket (MIHPacket::create());
105 mihPacket->transactionId() = 21;
106 mihPacket->src_mihfId().value( "senf@berlios.de");
107 mihPacket->dst_mihfId().value( "test");
109 BOOST_CHECK_THROW( MIHPacketType::validate( mihPacket), InvalidMIHPacketException);
111 mihPacket.finalizeThis();
112 BOOST_CHECK_NO_THROW( MIHPacketType::validate( mihPacket));
115 test::TestMessagePacket testMessage (test::TestMessagePacket::createAfter(mihPacket));
116 mihPacket.finalizeAll();
117 BOOST_CHECK_NO_THROW( MIHPacketType::validate( mihPacket));
120 test::ValidatedTestMessagePacket testMessage (test::ValidatedTestMessagePacket::createAfter(mihPacket));
121 mihPacket.finalizeAll();
122 testMessage->registerRequestCodeTLV().value() << 3;
123 BOOST_CHECK_THROW( MIHPacketType::validate( mihPacket), InvalidMIHPacketException);
124 testMessage->registerRequestCodeTLV().value() << 1;
125 BOOST_CHECK_NO_THROW( MIHPacketType::validate( mihPacket));
129 //-/////////////////////////////////////////////////////////////////////////////////////////////////
136 // c-file-style: "senf"
137 // indent-tabs-mode: nil
138 // ispell-local-dictionary: "american"
139 // compile-command: "scons -u test"
140 // comment-column: 40