4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Thorsten Horstmann <tho@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 RateFilter unit tests */
27 #include "RateFilter.hh"
28 #include "DebugModules.hh"
30 #include "../Utils/membind.hh"
32 #include "../Utils/auto_unit_test.hh"
33 #include <boost/test/test_tools.hpp>
36 ///////////////////////////////cc.p////////////////////////////////////////
37 namespace ppi = senf::ppi;
38 namespace module = ppi::module;
39 namespace debug = module::debug;
43 senf::scheduler::terminate();
47 BOOST_AUTO_UNIT_TEST(rateFilter)
49 module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
50 debug::PassiveSource source;
51 debug::PassiveSink sink;
53 ppi::connect(source, rateFilter);
54 ppi::connect(rateFilter, sink);
56 std::string data ("TEST");
57 senf::Packet p (senf::DataPacket::create(data));
58 for (int i=0; i<10; i++)
61 senf::scheduler::TimerEvent timer (
62 "rateFilter test timer", &timeout,
63 senf::ClockService::now() + senf::ClockService::milliseconds(250));
67 BOOST_CHECK_EQUAL( sink.size(), 2);
71 // just a helper class for the test
72 struct RateFilter_IntervalChanger {
73 module::RateFilter & rateFilter_;
74 RateFilter_IntervalChanger( module::RateFilter & rateFilter)
75 : rateFilter_( rateFilter) {};
76 void changeInterval() {
77 rateFilter_.interval( senf::ClockService::milliseconds(200));
82 BOOST_AUTO_UNIT_TEST(rateFilter_changeInterval)
84 module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
85 debug::PassiveSource source;
86 debug::PassiveSink sink;
88 ppi::connect(source, rateFilter);
89 ppi::connect(rateFilter, sink);
91 std::string data ("TEST");
92 senf::Packet p (senf::DataPacket::create(data));
93 for (int i=0; i<10; i++)
96 senf::scheduler::TimerEvent timeoutTimer (
97 "rateFilter test timer", &timeout,
98 senf::ClockService::now() + senf::ClockService::milliseconds(675));
100 RateFilter_IntervalChanger intervalChanger (rateFilter);
101 senf::scheduler::TimerEvent timer ( "RateFilter_IntervalChanger timer",
102 senf::membind(&RateFilter_IntervalChanger::changeInterval, intervalChanger),
103 senf::ClockService::now() + senf::ClockService::milliseconds(250));
107 BOOST_CHECK_EQUAL( sink.size(), 4);
110 ///////////////////////////////cc.e////////////////////////////////////////
117 // comment-column: 40
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"