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 // Stefan Bund <g0dil@berlios.de>
29 \brief MonitorModule unit tests */
31 //#include "MonitorModule.test.hh"
32 //#include "MonitorModule.test.ih"
35 #include "MonitorModule.hh"
36 #include "DebugModules.hh"
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 class PacketCounter : public senf::ppi::module::MonitorModule<>
48 SENF_PPI_MODULE(PacketCounter);
50 PacketCounter() : count (0) {}
51 void v_handlePacket(senf::Packet const & p) { ++count; }
57 SENF_AUTO_UNIT_TEST(monitorModulePassthrough)
59 senf::ppi::module::debug::ActiveSource source;
60 senf::ppi::module::debug::PassiveSink sink;
61 PacketCounter counter;
63 senf::ppi::connect(source, counter);
64 senf::ppi::connect(counter, sink);
68 senf::Packet p (senf::DataPacket::create());
70 BOOST_CHECK_EQUAL( counter.count, 0u );
72 BOOST_CHECK_EQUAL( counter.count, 1u );
73 BOOST_CHECK( sink.pop_front() == p );
74 BOOST_CHECK( source );
76 BOOST_CHECK( ! source );
78 BOOST_CHECK( source );
81 SENF_AUTO_UNIT_TEST(monitorModuleNoPassthrough)
83 senf::ppi::module::debug::ActiveSource source;
84 PacketCounter counter;
86 senf::ppi::connect(source, counter);
90 senf::Packet p (senf::DataPacket::create());
92 BOOST_CHECK_EQUAL( counter.count, 0u );
94 BOOST_CHECK_EQUAL( counter.count, 1u );
95 BOOST_CHECK( source );
98 SENF_AUTO_UNIT_TEST(monitorModuleDynamicConnect)
100 senf::ppi::module::debug::ActiveSource source;
101 PacketCounter counter;
103 senf::ppi::connect(source, counter);
107 senf::Packet p (senf::DataPacket::create());
109 BOOST_CHECK_EQUAL( counter.count, 0u );
111 BOOST_CHECK_EQUAL( counter.count, 1u );
112 BOOST_CHECK( source );
114 senf::ppi::module::debug::PassiveSink sink;
115 senf::ppi::connect(counter, sink);
116 senf::ppi::init(); // Needs to be called since I'm not running in the scheduler !!
118 BOOST_CHECK( source );
120 BOOST_CHECK_EQUAL( counter.count, 2u );
121 BOOST_CHECK( sink.pop_front() == p );
123 BOOST_CHECK( ! source );
125 BOOST_CHECK( source );
127 counter.output.disconnect();
128 senf::ppi::init(); // Needs to be called since I'm not running in the scheduler !!
130 BOOST_CHECK( source );
132 BOOST_CHECK_EQUAL( counter.count, 3u );
136 //-/////////////////////////////////////////////////////////////////////////////////////////////////
143 // comment-column: 40
144 // c-file-style: "senf"
145 // indent-tabs-mode: nil
146 // ispell-local-dictionary: "american"
147 // compile-command: "scons -u test"