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;
47 void runPPI(senf::ClockService::clock_type t) {
48 senf::scheduler::TimerEvent timeout(
49 "emulatedDvbInterface test timer", &senf::scheduler::terminate, senf::scheduler::now() + t);
54 SENF_AUTO_UNIT_TEST(rateFilter)
56 module::RateFilter rateFilter ( senf::ClockService::milliseconds(200) );
57 debug::PassiveSource source;
58 debug::PassiveSink sink;
60 ppi::connect(source, rateFilter);
61 ppi::connect(rateFilter, sink);
63 std::string data ("TEST");
64 senf::Packet p (senf::DataPacket::create(data));
65 for (int i=0; i<10; i++)
68 runPPI( senf::ClockService::milliseconds(500));
70 BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(200) );
71 BOOST_CHECK_EQUAL( sink.size(), 2u );
75 // just a helper class for the test
76 struct RateFilter_IntervalChanger {
77 module::RateFilter & rateFilter_;
78 RateFilter_IntervalChanger( module::RateFilter & rateFilter)
79 : rateFilter_( rateFilter) {};
80 void changeInterval() {
81 rateFilter_.interval( senf::ClockService::milliseconds(200));
86 SENF_AUTO_UNIT_TEST(rateFilter_changeInterval)
88 char const * enabled (getenv("SENF_TIMING_CRITICAL_TESTS"));
90 BOOST_WARN_MESSAGE(false, "Set SENF_TIMING_CRITICAL_TESTS to not skip timing critical tests");
93 module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
94 debug::PassiveSource source;
95 debug::PassiveSink sink;
97 ppi::connect(source, rateFilter);
98 ppi::connect(rateFilter, sink);
100 std::string data ("TEST");
101 senf::Packet p (senf::DataPacket::create(data));
102 for (int i=0; i<10; i++)
105 RateFilter_IntervalChanger intervalChanger (rateFilter);
106 senf::scheduler::TimerEvent timer ( "RateFilter_IntervalChanger timer",
107 senf::membind(&RateFilter_IntervalChanger::changeInterval, intervalChanger),
108 senf::ClockService::now() + senf::ClockService::milliseconds(250));
110 runPPI( senf::ClockService::milliseconds(675));
112 BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(200) );
114 BOOST_CHECK_EQUAL( sink.size(), 4);
117 //-/////////////////////////////////////////////////////////////////////////////////////////////////
124 // comment-column: 40
125 // c-file-style: "senf"
126 // indent-tabs-mode: nil
127 // ispell-local-dictionary: "american"
128 // compile-command: "scons -u test"