4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
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 MonitorModule.test unit tests */
26 //#include "MonitorModule.test.hh"
27 //#include "MonitorModule.test.ih"
30 #include "MonitorModule.hh"
31 #include "DebugModules.hh"
33 #include "../Utils/auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
41 class PacketCounter : public senf::ppi::module::MonitorModule<>
43 SENF_PPI_MODULE(PacketCounter);
45 PacketCounter() : count (0) {}
46 void v_handlePacket(senf::Packet const & p) { ++count; }
52 BOOST_AUTO_UNIT_TEST(monitorModulePassthrough)
54 senf::ppi::module::debug::ActiveSource source;
55 senf::ppi::module::debug::PassiveSink sink;
56 PacketCounter counter;
58 senf::ppi::connect(source, counter);
59 senf::ppi::connect(counter, sink);
63 senf::Packet p (senf::DataPacket::create());
65 BOOST_CHECK_EQUAL( counter.count, 0u );
67 BOOST_CHECK_EQUAL( counter.count, 1u );
68 BOOST_CHECK( sink.pop_front() == p );
69 BOOST_CHECK( source );
71 BOOST_CHECK( ! source );
73 BOOST_CHECK( source );
76 BOOST_AUTO_UNIT_TEST(monitorModuleNoPassthrough)
78 senf::ppi::module::debug::ActiveSource source;
79 PacketCounter counter;
81 senf::ppi::connect(source, counter);
85 senf::Packet p (senf::DataPacket::create());
87 BOOST_CHECK_EQUAL( counter.count, 0u );
89 BOOST_CHECK_EQUAL( counter.count, 1u );
90 BOOST_CHECK( source );
93 BOOST_AUTO_UNIT_TEST(monitorModuleDynamicConnect)
95 senf::ppi::module::debug::ActiveSource source;
96 PacketCounter counter;
98 senf::ppi::connect(source, counter);
102 senf::Packet p (senf::DataPacket::create());
104 BOOST_CHECK_EQUAL( counter.count, 0u );
106 BOOST_CHECK_EQUAL( counter.count, 1u );
107 BOOST_CHECK( source );
109 senf::ppi::module::debug::PassiveSink sink;
110 senf::ppi::connect(counter, sink);
111 senf::ppi::init(); // Needs to be called since I'm not running in the scheduler !!
113 BOOST_CHECK( source );
115 BOOST_CHECK_EQUAL( counter.count, 2u );
116 BOOST_CHECK( sink.pop_front() == p );
118 BOOST_CHECK( ! source );
120 BOOST_CHECK( source );
122 counter.output.disconnect();
123 senf::ppi::init(); // Needs to be called since I'm not running in the scheduler !!
125 BOOST_CHECK( source );
127 BOOST_CHECK_EQUAL( counter.count, 3u );
131 ///////////////////////////////cc.e////////////////////////////////////////
138 // comment-column: 40
139 // c-file-style: "senf"
140 // indent-tabs-mode: nil
141 // ispell-local-dictionary: "american"
142 // compile-command: "scons -u test"