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 // Thorsten Horstmann <tho@berlios.de>
29 \brief RateFilter unit tests */
32 #include "RateFilter.hh"
33 #include "DebugModules.hh"
35 #include <senf/Utils/membind.hh>
37 #include <senf/Utils/auto_unit_test.hh>
38 #include <boost/test/test_tools.hpp>
41 //-/////////////////////////////////////////////////////////////////////////////////////////////////
42 namespace ppi = senf::ppi;
43 namespace module = ppi::module;
44 namespace debug = module::debug;
48 senf::scheduler::terminate();
52 SENF_AUTO_UNIT_TEST(rateFilter)
54 module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
55 debug::PassiveSource source;
56 debug::PassiveSink sink;
58 ppi::connect(source, rateFilter);
59 ppi::connect(rateFilter, sink);
61 std::string data ("TEST");
62 senf::Packet p (senf::DataPacket::create(data));
63 for (int i=0; i<10; i++)
66 senf::scheduler::TimerEvent timer (
67 "rateFilter test timer", &timeout,
68 senf::ClockService::now() + senf::ClockService::milliseconds(250));
72 BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(100) );
73 BOOST_CHECK_EQUAL( sink.size(), 2u );
77 // just a helper class for the test
78 struct RateFilter_IntervalChanger {
79 module::RateFilter & rateFilter_;
80 RateFilter_IntervalChanger( module::RateFilter & rateFilter)
81 : rateFilter_( rateFilter) {};
82 void changeInterval() {
83 rateFilter_.interval( senf::ClockService::milliseconds(200));
88 SENF_AUTO_UNIT_TEST(rateFilter_changeInterval)
90 char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
92 BOOST_WARN_MESSAGE(false, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
95 module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
96 debug::PassiveSource source;
97 debug::PassiveSink sink;
99 ppi::connect(source, rateFilter);
100 ppi::connect(rateFilter, sink);
102 std::string data ("TEST");
103 senf::Packet p (senf::DataPacket::create(data));
104 for (int i=0; i<10; i++)
107 senf::scheduler::TimerEvent timeoutTimer (
108 "rateFilter test timer", &timeout,
109 senf::ClockService::now() + senf::ClockService::milliseconds(675));
111 RateFilter_IntervalChanger intervalChanger (rateFilter);
112 senf::scheduler::TimerEvent timer ( "RateFilter_IntervalChanger timer",
113 senf::membind(&RateFilter_IntervalChanger::changeInterval, intervalChanger),
114 senf::ClockService::now() + senf::ClockService::milliseconds(250));
118 BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(200) );
120 BOOST_CHECK_EQUAL( sink.size(), 4);
123 //-/////////////////////////////////////////////////////////////////////////////////////////////////
130 // comment-column: 40
131 // c-file-style: "senf"
132 // indent-tabs-mode: nil
133 // ispell-local-dictionary: "american"
134 // compile-command: "scons -u test"