4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <g0dil@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 Connectors.test unit tests */
26 //#include "Connectors.test.hh"
27 //#include "Connectors.test.ih"
30 #include "Connectors.hh"
31 #include "DebugModules.hh"
34 #include <boost/test/auto_unit_test.hpp>
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
40 namespace ppi = senf::ppi;
41 namespace debug = ppi::module::debug;
43 // For each type of connector we use the corresponding debug module. Additionally, we always need
44 // the corresponding connected module since otherwise the connectors cannot be connected anywhere
45 // and will be unusable.
47 BOOST_AUTO_UNIT_TEST(connector)
49 // It doesn't matter, which type of connectors we use here since they are all based on
52 debug::ActivePacketSource source;
53 debug::PassivePacketSink target;
55 ppi::connect(source.output,target.input);
58 BOOST_CHECK_EQUAL( & source.output.module(), & source );
59 BOOST_CHECK_EQUAL( & target.input.module(), & target );
60 BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
61 BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
64 BOOST_AUTO_UNIT_TEST(passiveConnector)
66 debug::ActivePacketSource source;
67 debug::PassivePacketSink target;
69 ppi::connect(source.output,target.input);
72 // onRequest is implicitly tested within the PassivePacketSink implementation which is tested
73 // in DebugModules.test.cc
75 target.input.throttle();
76 BOOST_CHECK( target.input.throttled() );
77 BOOST_CHECK( target.input.nativeThrottled() );
79 target.input.unthrottle();
80 BOOST_CHECK( ! target.input.throttled() );
81 BOOST_CHECK( ! target.input.nativeThrottled() );
83 BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
90 void handler() { called = true; }
93 BOOST_AUTO_UNIT_TEST(activeConnector)
95 debug::ActivePacketSource source;
96 debug::PassivePacketSink target;
98 ppi::connect(source.output,target.input);
101 source.output.onThrottle(handler);
102 BOOST_CHECK( ! called );
103 target.input.throttle();
104 BOOST_CHECK( called );
106 target.input.unthrottle();
107 BOOST_CHECK( ! called );
108 source.output.onThrottle();
109 source.output.onUnthrottle(handler);
110 BOOST_CHECK( ! called );
111 target.input.throttle();
112 BOOST_CHECK( ! called );
113 target.input.unthrottle();
114 BOOST_CHECK( called );
115 source.output.onUnthrottle();
117 BOOST_CHECK( ! called );
118 target.input.throttle();
119 target.input.unthrottle();
120 BOOST_CHECK( ! called );
122 BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
125 BOOST_AUTO_UNIT_TEST(inputConnector)
127 debug::ActivePacketSource source;
128 debug::PassivePacketSink target;
130 ppi::connect(source.output,target.input);
133 // operator() is implicitly tested within the Active/PassivePacketSink implementation which is
134 // tested in DebugModules.test.cc
136 // peek() is implicitly tested within the Active/PassivePacketSink implementation
138 BOOST_CHECK_EQUAL ( & target.input.peer(), & source.output );
140 BOOST_CHECK( target.input.begin() == target.input.end() );
141 BOOST_CHECK_EQUAL( target.input.queueSize(), 0u );
142 BOOST_CHECK( target.input.empty() );
145 BOOST_AUTO_UNIT_TEST(outputConnector)
147 debug::ActivePacketSource source;
148 debug::PassivePacketSink target;
150 ppi::connect(source.output,target.input);
153 // operator() is implicitly tested within the Active/PassivePacketSource implementation which is
154 // tested in DebugModules.test.cc
156 BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
161 class PassiveInputTest
162 : public ppi::module::Module
165 ppi::connector::PassiveInput input;
167 PassiveInputTest() : counter() {
169 input.onRequest(&PassiveInputTest::request);
180 BOOST_AUTO_UNIT_TEST(passiveInput)
182 debug::ActivePacketSource source;
183 PassiveInputTest target;
185 ppi::connect(source.output,target.input);
188 BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
190 target.input.throttle();
191 senf::Packet p (senf::DataPacket::create());
194 BOOST_CHECK_EQUAL( target.counter, 0u );
195 BOOST_CHECK( target.input );
196 BOOST_CHECK_EQUAL( target.input.queueSize(), 1u );
197 target.input.unthrottle();
198 BOOST_CHECK( target.input );
199 BOOST_CHECK_EQUAL( target.counter, 1u );
201 BOOST_CHECK( target.input() == p );
202 BOOST_CHECK( ! target.input );
206 BOOST_CHECK_EQUAL( target.counter, 2u );
207 BOOST_CHECK( target.input.throttled() );
208 BOOST_CHECK( target.input() == p );
209 BOOST_CHECK( ! target.input.throttled() );
211 target.input.qdisc(ppi::ThresholdQueueing(2,0));
214 BOOST_CHECK ( ! target.input.throttled() );
216 BOOST_CHECK( target.input.throttled() );
218 BOOST_CHECK( target.input.throttled() );
220 BOOST_CHECK( ! target.input.throttled() );
223 BOOST_AUTO_UNIT_TEST(passiveOutput)
225 debug::PassivePacketSource source;
226 debug::ActivePacketSink target;
228 ppi::connect(source.output,target.input);
231 senf::Packet p (senf::DataPacket::create());
234 BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
236 BOOST_CHECK( source.output );
239 BOOST_CHECK( target.request() == p );
241 // connect() is tested indirectly via ppi::connect
244 BOOST_AUTO_UNIT_TEST(activeInput)
246 debug::PassivePacketSource source;
247 debug::ActivePacketSink target;
249 ppi::connect(source.output,target.input);
252 BOOST_CHECK_EQUAL( & target.input.peer(), & source.output );
254 BOOST_CHECK ( ! target.input );
256 senf::Packet p (senf::DataPacket::create());
259 BOOST_CHECK( target.input );
260 BOOST_CHECK( target.request() == p );
263 target.input.request();
264 BOOST_CHECK_EQUAL( target.input.queueSize(), 1u );
265 BOOST_CHECK( target.input );
266 BOOST_CHECK( target.request() == p );
269 BOOST_AUTO_UNIT_TEST(activeOutput)
271 debug::ActivePacketSource source;
272 debug::PassivePacketSink target;
274 ppi::connect(source.output,target.input);
277 BOOST_CHECK_EQUAL( & source.output.peer(), & target.input );
278 BOOST_CHECK( source.output );
279 target.input.throttle();
280 BOOST_CHECK( ! source.output );
282 // connect() is tested indirectly via ppi::connect
286 ///////////////////////////////cc.e////////////////////////////////////////
293 // comment-column: 40
294 // c-file-style: "senf"
295 // indent-tabs-mode: nil
296 // ispell-local-dictionary: "american"
297 // compile-command: "scons -u test"