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( rateFilter.interval(), senf::ClockService::milliseconds(100) );
68 BOOST_CHECK_EQUAL( sink.size(), 2u );
72 // just a helper class for the test
73 struct RateFilter_IntervalChanger {
74 module::RateFilter & rateFilter_;
75 RateFilter_IntervalChanger( module::RateFilter & rateFilter)
76 : rateFilter_( rateFilter) {};
77 void changeInterval() {
78 rateFilter_.interval( senf::ClockService::milliseconds(200));
83 BOOST_AUTO_UNIT_TEST(rateFilter_changeInterval)
85 module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
86 debug::PassiveSource source;
87 debug::PassiveSink sink;
89 ppi::connect(source, rateFilter);
90 ppi::connect(rateFilter, sink);
92 std::string data ("TEST");
93 senf::Packet p (senf::DataPacket::create(data));
94 for (int i=0; i<10; i++)
97 senf::scheduler::TimerEvent timeoutTimer (
98 "rateFilter test timer", &timeout,
99 senf::ClockService::now() + senf::ClockService::milliseconds(675));
101 RateFilter_IntervalChanger intervalChanger (rateFilter);
102 senf::scheduler::TimerEvent timer ( "RateFilter_IntervalChanger timer",
103 senf::membind(&RateFilter_IntervalChanger::changeInterval, intervalChanger),
104 senf::ClockService::now() + senf::ClockService::milliseconds(250));
108 BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(200) );
109 BOOST_CHECK_EQUAL( sink.size(), 4);
112 ///////////////////////////////cc.e////////////////////////////////////////
119 // comment-column: 40
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"