X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=PPI%2FModule.test.cc;h=2f6df29839a26bdbaae6475e4c39b52920f8b25d;hb=a1fdb7bb122f0b05be809a922d4b7ef5e125fa67;hp=1fe9b7b433165f06f91950e4d4c21231b43c7b35;hpb=48bbf27e9e89d6eba4754fba65d70a15b115ac8b;p=senf.git diff --git a/PPI/Module.test.cc b/PPI/Module.test.cc index 1fe9b7b..2f6df29 100644 --- a/PPI/Module.test.cc +++ b/PPI/Module.test.cc @@ -1,6 +1,8 @@ -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// $Id$ +// +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -19,18 +21,20 @@ // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. /** \file - \brief Module.test unit tests */ + \brief Module unit tests */ //#include "Module.test.hh" //#include "Module.test.ih" // Custom includes +#include +#include "../Utils/membind.hh" #include "DebugEvent.hh" #include "DebugModules.hh" #include "Setup.hh" #include "Module.hh" -#include +#include "../Utils/auto_unit_test.hh" #include #include @@ -44,21 +48,23 @@ namespace debug = ppi::module::debug; namespace { class TestModule : public ppi::module::Module { + SENF_PPI_MODULE(TestModule); + public: - connector::ActiveOutput output; + connector::ActiveOutput<> output; ppi::DebugEvent event; TestModule() { noroute(output); - registerEvent(&TestModule::onEvent, event); + registerEvent(event, &TestModule::onEvent); } void onEvent() { output(senf::DataPacket::create()); } - using ppi::module::Module::eventTime; + using ppi::module::Module::time; }; } @@ -67,14 +73,64 @@ BOOST_AUTO_UNIT_TEST(module) // route and registerEvent are tested in Route.test.cc TestModule tester; - debug::PassivePacketSink sink; - ppi::connect(tester.output, sink.input); + debug::PassiveSink sink; + ppi::connect(tester, sink); ppi::init(); tester.event.trigger(); BOOST_CHECK_EQUAL( sink.size(), 1u ); - BOOST_CHECK_EQUAL( (boost::posix_time::microsec_clock::universal_time() - - tester.eventTime()).total_seconds(), 0 ); + BOOST_CHECK( senf::ClockService::now() - tester.time() < senf::ClockService::seconds(1) ); +} + +namespace { + + void timeout() { + senf::scheduler::terminate(); + } + + class InitTest : public ppi::module::Module + { + SENF_PPI_MODULE(InitTest); + public: + InitTest() : init (false) {} + void v_init() { init = true; } + + bool init; + }; + + struct MakeInit { + boost::scoped_ptr tester; + void make() { + tester.reset(new InitTest()); + } + void test() { + BOOST_REQUIRE( tester ); + BOOST_CHECK( tester->init ); + } + }; + +} + +BOOST_AUTO_UNIT_TEST(delayedInit) +{ + MakeInit maker; + senf::scheduler::TimerEvent timer ( + "delayedInit timer", + senf::membind(&MakeInit::make, &maker), + senf::ClockService::now() + senf::ClockService::milliseconds(250) ); + senf::scheduler::TimerEvent testTimer ( + "delayedInit test", + senf::membind(&MakeInit::test, &maker), + senf::ClockService::now() + senf::ClockService::milliseconds(500) ); + senf::scheduler::TimerEvent timeoutTimer ( + "delayedInit timeout", + &timeout, + senf::ClockService::now() + senf::ClockService::milliseconds(750) ); + + senf::ppi::run(); + + BOOST_REQUIRE( maker.tester ); + BOOST_CHECK( maker.tester->init ); } ///////////////////////////////cc.e////////////////////////////////////////