From: tho Date: Fri, 20 Mar 2009 09:29:29 +0000 (+0000) Subject: PPI/Ratefilter: added interval setter and unit tests X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=b64ffc44397d5853a677a1b4494105c4756af8d3;p=senf.git PPI/Ratefilter: added interval setter and unit tests Utils/Console: doc: added example for adding an overloaded member method to the console git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1160 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/RateFilter.cc b/PPI/RateFilter.cc index c9b4793..953bba7 100644 --- a/PPI/RateFilter.cc +++ b/PPI/RateFilter.cc @@ -1,3 +1,5 @@ +// $Id$ +// // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY @@ -49,13 +51,11 @@ senf::ClockService::clock_type senf::ppi::module::RateFilter::interval() return timer_.interval().first; } - -/* this should be what should happen. but _this_ most likely won't work -void senf::ppi::module::RateFilter::changeInterval(senf::ClockService::clock_type interval) +void senf::ppi::module::RateFilter::interval(senf::ClockService::clock_type interval) { - //timer = ppi::IntervalTimer(interval); + timer_.interval(interval); } -*/ + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ diff --git a/PPI/RateFilter.hh b/PPI/RateFilter.hh index 9877124..dca0fbd 100644 --- a/PPI/RateFilter.hh +++ b/PPI/RateFilter.hh @@ -1,3 +1,5 @@ +// $Id$ +// // Copyright (C) 2007 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY @@ -43,7 +45,7 @@ class RateFilter public: RateFilter(senf::ClockService::clock_type interval); -// void changeInterval(senf::ClockService::clock_type interval); not yet implemented! + void interval(senf::ClockService::clock_type interval); senf::ClockService::clock_type interval() const; connector::ActiveInput<> input; diff --git a/PPI/RateFilter.test.cc b/PPI/RateFilter.test.cc new file mode 100644 index 0000000..22a5a1c --- /dev/null +++ b/PPI/RateFilter.test.cc @@ -0,0 +1,122 @@ +// $Id$ +// +// Copyright (C) 2009 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Thorsten Horstmann +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the +// Free Software Foundation, Inc., +// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +/** \file + \brief RateFilter unit tests */ + +// Custom includes +#include "RateFilter.hh" +#include "DebugModules.hh" +#include "Setup.hh" +#include "../Utils/membind.hh" + +#include "../Utils/auto_unit_test.hh" +#include + +#define prefix_ +///////////////////////////////cc.p//////////////////////////////////////// +namespace ppi = senf::ppi; +namespace module = ppi::module; +namespace debug = module::debug; + +namespace { + void timeout() { + senf::scheduler::terminate(); + } +} + +BOOST_AUTO_UNIT_TEST(rateFilter) +{ + module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) ); + debug::PassiveSource source; + debug::PassiveSink sink; + + ppi::connect(source, rateFilter); + ppi::connect(rateFilter, sink); + + std::string data ("TEST"); + senf::Packet p (senf::DataPacket::create(data)); + for (int i=0; i<10; i++) + source.submit(p); + + senf::scheduler::TimerEvent timer ( + "rateFilter test timer", &timeout, + senf::ClockService::now() + senf::ClockService::milliseconds(250)); + + senf::ppi::run(); + + BOOST_CHECK_EQUAL( sink.size(), 2); +} + +namespace { + // just a helper class for the test + struct RateFilter_IntervalChanger { + module::RateFilter & rateFilter_; + RateFilter_IntervalChanger( module::RateFilter & rateFilter) + : rateFilter_( rateFilter) {}; + void changeInterval() { + rateFilter_.interval( senf::ClockService::milliseconds(200)); + } + }; +} + +BOOST_AUTO_UNIT_TEST(rateFilter_changeInterval) +{ + module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) ); + debug::PassiveSource source; + debug::PassiveSink sink; + + ppi::connect(source, rateFilter); + ppi::connect(rateFilter, sink); + + std::string data ("TEST"); + senf::Packet p (senf::DataPacket::create(data)); + for (int i=0; i<10; i++) + source.submit(p); + + senf::scheduler::TimerEvent timeoutTimer ( + "rateFilter test timer", &timeout, + senf::ClockService::now() + senf::ClockService::milliseconds(675)); + + RateFilter_IntervalChanger intervalChanger (rateFilter); + senf::scheduler::TimerEvent timer ( "RateFilter_IntervalChanger timer", + senf::membind(&RateFilter_IntervalChanger::changeInterval, intervalChanger), + senf::ClockService::now() + senf::ClockService::milliseconds(250)); + + senf::ppi::run(); + + BOOST_CHECK_EQUAL( sink.size(), 4); +} + +///////////////////////////////cc.e//////////////////////////////////////// +#undef prefix_ + + +// Local Variables: +// mode: c++ +// fill-column: 100 +// comment-column: 40 +// c-file-style: "senf" +// indent-tabs-mode: nil +// ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// End: diff --git a/PPI/SocketSink.test.cc b/PPI/SocketSink.test.cc index 3cd3651..5b7f420 100644 --- a/PPI/SocketSink.test.cc +++ b/PPI/SocketSink.test.cc @@ -39,9 +39,7 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// - namespace ppi = senf::ppi; -namespace connector = ppi::connector; namespace module = ppi::module; namespace debug = module::debug; diff --git a/PPI/SocketSource.test.cc b/PPI/SocketSource.test.cc index f922db8..c8947a1 100644 --- a/PPI/SocketSource.test.cc +++ b/PPI/SocketSource.test.cc @@ -39,9 +39,7 @@ #define prefix_ ///////////////////////////////cc.p//////////////////////////////////////// - namespace ppi = senf::ppi; -namespace connector = ppi::connector; namespace module = ppi::module; namespace debug = module::debug; diff --git a/Utils/Console/Mainpage.dox b/Utils/Console/Mainpage.dox index eb39f76..16e7376 100644 --- a/Utils/Console/Mainpage.dox +++ b/Utils/Console/Mainpage.dox @@ -779,6 +779,20 @@ .add("over", static_cast(&over)); senf::console::root() .add("over", static_cast(&over)); + + class SomeModule { + senf::console::ScopedDirectory dir; + + unsigned int overlodedMethod() const {....}; + void overlodedMethod(unsigned int) {....}; + + void addConsoleCommands() { + dir.node().add("overlodedMethod", senf::membind( + static_cast(&SomeModule::overlodedMethod), this)); + dir.node().add("overlodedMethod", senf::membind( + static_cast(&SomeModule::overlodedMethod), this)); + } + } \endcode