4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 // http://senf.berlios.de/license.html
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on,
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
15 // Software distributed under the License is distributed on an "AS IS" basis,
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
17 // for the specific language governing rights and limitations under the License.
19 // The Original Code is Fraunhofer FOKUS code.
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V.
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
26 // Philipp Batroff <pug@berlios.de>
29 #include <senf/Packets/Packets.hh>
30 #include "IPv6ExtOptions.hh"
31 #include "ListOptionTypeParser.hh"
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
40 struct VoidPacket : public senf::PacketTypeBase
43 struct OptionParser : public senf::PacketParserBase
45 # include SENF_PARSER()
47 SENF_PARSER_FIELD( size, senf::UInt8Parser );
48 typedef senf::detail::FixedAuxParserPolicy<senf::UInt8Parser, 1u> ListOptionTypeAuxPolicy;
49 typedef senf::detail::ListOptionTypeParser_Policy<
50 senf::IPv6GenericOptionParser, ListOptionTypeAuxPolicy> ListOptionTypePolicy;
51 typedef senf::ListParser<ListOptionTypePolicy> ListOptionTypeParser;
52 SENF_PARSER_FIELD ( list, ListOptionTypeParser);
54 SENF_PARSER_FINALIZE(OptionParser);
58 SENF_AUTO_UNIT_TEST(ListOptionTypeParser)
60 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
61 OptionParser::init_bytes));
62 OptionParser p ( pi->data().begin() ,&pi->data());
63 BOOST_CHECK_EQUAL(OptionParser::init_bytes +0, 7u);
67 BOOST_CHECK_EQUAL( p.list().size(), 0u );
68 BOOST_CHECK_EQUAL( p.list().bytes(), 6u ); //padding has to be accounted for!
69 BOOST_CHECK( p.list().empty() );
71 // the mutators are really tested together with the container wrappers since they are based
72 // on the container wrapper. Here we only need one call to make the list larger ...
74 // this doesn't make sense, since padding is added and the size doesn't really change
75 // should be tested later with the container
76 p.list().push_back_space();
77 p = OptionParser(pi->data().begin(),&pi->data());
78 BOOST_CHECK_EQUAL( p.list().bytes(), 6u ); //padding bytes
79 BOOST_CHECK_EQUAL( p.list().size(), 1u ); //padding
80 BOOST_CHECK_EQUAL( p.list().empty(), false );
83 SENF_AUTO_UNIT_TEST(ListOptionTypeParser_container)
85 senf::PacketInterpreterBase::ptr pi (senf::PacketInterpreter<VoidPacket>::create(
86 OptionParser::init_bytes));
89 OptionParser p ( pi->data().begin() ,&pi->data());
91 OptionParser::list_t::container c (p.list());
93 BOOST_CHECK_EQUAL( c.size(), 0u );
94 BOOST_CHECK_EQUAL( c.bytes(), 0u ); // padding bytes wont be in here, added/removed automatically in destructor
95 BOOST_CHECK( c.begin() == c.end() );
97 std::vector<unsigned char> d (2, 0xab);
98 std::vector<unsigned char> d1 (1, 0x77);
99 std::vector<unsigned char> d2 (1, 0x13);
101 SENF_CHECK_NO_THROW( c.push_back( std::make_pair(0x65, d) ));
102 BOOST_CHECK_EQUAL( c.bytes(), 4u );
103 BOOST_CHECK_EQUAL( c.size(), 1u );
105 SENF_CHECK_NO_THROW( c.push_back( std::make_pair(0x03, d1) ));
106 BOOST_CHECK_EQUAL( c.bytes(), 7u );
107 BOOST_CHECK_EQUAL( c.size(), 2u );
109 SENF_CHECK_NO_THROW( c.push_back( std::make_pair(0x07, d2) ));
110 BOOST_CHECK_EQUAL( c.bytes(), 10u );
111 BOOST_CHECK_EQUAL( c.size(), 3u );
113 OptionParser::list_t::container::iterator cIter (c.begin());
114 BOOST_CHECK_EQUAL( cIter->altAction(), 1u);
115 BOOST_CHECK_EQUAL( cIter->changeFlag(), 1u);
116 BOOST_CHECK_EQUAL( cIter->optionType(), 5u);
117 BOOST_CHECK_EQUAL( cIter->length(), 2u);
118 BOOST_CHECK_EQUAL( *(boost::begin(cIter->value()) ), 0xab);
119 BOOST_CHECK_EQUAL( *(boost::next(boost::begin(cIter->value()) )), 0xab);
121 BOOST_CHECK_EQUAL( cIter->optionType(), 3u);
122 BOOST_CHECK_EQUAL( cIter->length(), 1u);
123 BOOST_CHECK_EQUAL( *(boost::begin(cIter->value() )), 0x77);
125 BOOST_CHECK_EQUAL( cIter->optionType(), 7u);
126 BOOST_CHECK_EQUAL( cIter->length(), 1u);
127 BOOST_CHECK_EQUAL( *(boost::begin(cIter->value())), 0x13);
129 //deletes first element
130 c.erase(c.begin(),1);
131 BOOST_CHECK_EQUAL( c.size(), 2u );
132 BOOST_CHECK_EQUAL( c.bytes(), 6u );
133 //deletes first 2 elements
134 c.erase(c.begin(),1);
135 BOOST_CHECK_EQUAL( c.size(), 1u );
136 BOOST_CHECK_EQUAL( c.bytes(), 3u );
137 BOOST_CHECK_EQUAL( c.empty(), false);
140 SENF_CHECK_NO_THROW( c.clear() );
141 BOOST_CHECK_EQUAL( c.size(), 0u );
142 BOOST_CHECK_EQUAL( c.bytes(), 0u );
143 BOOST_CHECK_EQUAL( c.empty(), true);
146 //-/////////////////////////////////////////////////////////////////////////////////////////////////
152 // comment-column: 40
153 // c-file-style: "senf"
154 // indent-tabs-mode: nil
155 // ispell-local-dictionary: "american"
156 // compile-command: "scons -u test"