Fix SCons 1.2.0 build failure
[senf.git] / senf / PPI / RateFilter.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2009
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Thorsten Horstmann <tho@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief RateFilter unit tests */
25
26 // Custom includes
27 #include "RateFilter.hh"
28 #include "DebugModules.hh"
29 #include "Setup.hh"
30 #include "../Utils/membind.hh"
31
32 #include "../Utils/auto_unit_test.hh"
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 ///////////////////////////////cc.p////////////////////////////////////////
37 namespace ppi = senf::ppi;
38 namespace module = ppi::module;
39 namespace debug = module::debug;
40
41 namespace {
42     void timeout() {
43         senf::scheduler::terminate();
44     }
45 }
46
47 BOOST_AUTO_UNIT_TEST(rateFilter)
48 {
49     module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
50     debug::PassiveSource source;
51     debug::PassiveSink sink;
52     
53     ppi::connect(source, rateFilter);
54     ppi::connect(rateFilter, sink);
55     
56     std::string data ("TEST");
57     senf::Packet p (senf::DataPacket::create(data));
58     for (int i=0; i<10; i++)
59         source.submit(p); 
60     
61     senf::scheduler::TimerEvent timer (
62         "rateFilter test timer", &timeout,
63         senf::ClockService::now() + senf::ClockService::milliseconds(250));
64     
65     senf::ppi::run();
66
67     BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(100) );
68     BOOST_CHECK_EQUAL( sink.size(), 2u );
69 }
70
71 namespace {
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));
79         }
80     };
81 }
82
83 BOOST_AUTO_UNIT_TEST(rateFilter_changeInterval)
84 {
85     module::RateFilter rateFilter ( senf::ClockService::milliseconds(100) );
86     debug::PassiveSource source;
87     debug::PassiveSink sink;
88     
89     ppi::connect(source, rateFilter);
90     ppi::connect(rateFilter, sink);
91     
92     std::string data ("TEST");
93     senf::Packet p (senf::DataPacket::create(data));
94     for (int i=0; i<10; i++)
95         source.submit(p); 
96     
97     senf::scheduler::TimerEvent timeoutTimer (
98         "rateFilter test timer", &timeout,
99         senf::ClockService::now() + senf::ClockService::milliseconds(675));
100     
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));
105     
106     senf::ppi::run();
107
108     BOOST_CHECK_EQUAL( rateFilter.interval(), senf::ClockService::milliseconds(200) );
109     BOOST_CHECK_EQUAL( sink.size(), 4);
110 }
111
112 ///////////////////////////////cc.e////////////////////////////////////////
113 #undef prefix_
114
115 \f
116 // Local Variables:
117 // mode: c++
118 // fill-column: 100
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"
124 // End: