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 Module unit tests */
26 //#include "Module.test.hh"
27 //#include "Module.test.ih"
30 #include <boost/scoped_ptr.hpp>
31 #include "../Utils/membind.hh"
32 #include "DebugEvent.hh"
33 #include "DebugModules.hh"
37 #include "../Utils/auto_unit_test.hh"
38 #include <boost/test/test_tools.hpp>
39 #include <boost/type_traits.hpp>
42 ///////////////////////////////cc.p////////////////////////////////////////
44 namespace ppi = senf::ppi;
45 namespace connector = ppi::connector;
46 namespace debug = ppi::module::debug;
49 class TestModule : public ppi::module::Module
51 SENF_PPI_MODULE(TestModule);
54 connector::ActiveOutput<> output;
56 ppi::DebugEvent event;
60 registerEvent(event, &TestModule::onEvent);
64 output(senf::DataPacket::create());
67 using ppi::module::Module::time;
71 BOOST_AUTO_UNIT_TEST(module)
73 // route and registerEvent are tested in Route.test.cc
76 debug::PassiveSink sink;
77 ppi::connect(tester, sink);
80 tester.event.trigger();
81 BOOST_CHECK_EQUAL( sink.size(), 1u );
82 BOOST_CHECK( senf::ClockService::now() - tester.time() < senf::ClockService::seconds(1) );
88 senf::scheduler::terminate();
91 class InitTest : public ppi::module::Module
93 SENF_PPI_MODULE(InitTest);
95 InitTest() : init (false) {}
96 void v_init() { init = true; }
102 boost::scoped_ptr<InitTest> tester;
104 tester.reset(new InitTest());
107 BOOST_REQUIRE( tester );
108 BOOST_CHECK( tester->init );
114 BOOST_AUTO_UNIT_TEST(delayedInit)
117 senf::scheduler::TimerEvent timer (
119 senf::membind(&MakeInit::make, &maker),
120 senf::ClockService::now() + senf::ClockService::milliseconds(250) );
121 senf::scheduler::TimerEvent testTimer (
123 senf::membind(&MakeInit::test, &maker),
124 senf::ClockService::now() + senf::ClockService::milliseconds(500) );
125 senf::scheduler::TimerEvent timeoutTimer (
126 "delayedInit timeout",
128 senf::ClockService::now() + senf::ClockService::milliseconds(750) );
132 BOOST_REQUIRE( maker.tester );
133 BOOST_CHECK( maker.tester->init );
136 ///////////////////////////////cc.e////////////////////////////////////////
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"