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 Module unit tests */
31 //#include "Module.test.hh"
32 //#include "Module.test.ih"
35 #include <boost/scoped_ptr.hpp>
36 #include <senf/Utils/membind.hh>
37 #include "DebugEvent.hh"
38 #include "DebugModules.hh"
42 #include <senf/Utils/auto_unit_test.hh>
43 #include <boost/test/test_tools.hpp>
44 #include <boost/type_traits.hpp>
47 //-/////////////////////////////////////////////////////////////////////////////////////////////////
49 namespace ppi = senf::ppi;
50 namespace connector = ppi::connector;
51 namespace debug = ppi::module::debug;
54 class TestModule : public ppi::module::Module
56 SENF_PPI_MODULE(TestModule);
59 connector::ActiveOutput<> output;
61 ppi::DebugEvent event;
65 registerEvent(event, &TestModule::onEvent);
69 output(senf::DataPacket::create());
72 using ppi::module::Module::time;
76 SENF_AUTO_UNIT_TEST(module)
78 // route and registerEvent are tested in Route.test.cc
81 debug::PassiveSink sink;
82 ppi::connect(tester, sink);
85 tester.event.trigger();
86 BOOST_CHECK_EQUAL( sink.size(), 1u );
87 BOOST_CHECK( senf::ClockService::now() - tester.time() < senf::ClockService::seconds(1) );
93 senf::scheduler::terminate();
96 class InitTest : public ppi::module::Module
98 SENF_PPI_MODULE(InitTest);
100 InitTest() : init (false) {}
101 void v_init() { init = true; }
107 boost::scoped_ptr<InitTest> tester;
109 tester.reset(new InitTest());
112 BOOST_REQUIRE( tester );
113 BOOST_CHECK( tester->init );
119 SENF_AUTO_UNIT_TEST(delayedInit)
122 senf::scheduler::TimerEvent timer (
124 senf::membind(&MakeInit::make, &maker),
125 senf::ClockService::now() + senf::ClockService::milliseconds(250) );
126 senf::scheduler::TimerEvent testTimer (
128 senf::membind(&MakeInit::test, &maker),
129 senf::ClockService::now() + senf::ClockService::milliseconds(500) );
130 senf::scheduler::TimerEvent timeoutTimer (
131 "delayedInit timeout",
133 senf::ClockService::now() + senf::ClockService::milliseconds(750) );
137 BOOST_REQUIRE( maker.tester );
138 BOOST_CHECK( maker.tester->init );
141 //-/////////////////////////////////////////////////////////////////////////////////////////////////
148 // comment-column: 40
149 // c-file-style: "senf"
150 // indent-tabs-mode: nil
151 // ispell-local-dictionary: "american"
152 // compile-command: "scons -u test"