Fix documentation build under maverick (doxygen 1.7.1)
[senf.git] / senf / PPI / MonitorModule.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 //     Stefan Bund <g0dil@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 MonitorModule unit tests */
25
26 //#include "MonitorModule.test.hh"
27 //#include "MonitorModule.test.ih"
28
29 // Custom includes
30 #include "MonitorModule.hh"
31 #include "DebugModules.hh"
32
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 //-/////////////////////////////////////////////////////////////////////////////////////////////////
38
39 namespace {
40
41     class PacketCounter : public senf::ppi::module::MonitorModule<>
42     {
43         SENF_PPI_MODULE(PacketCounter);
44     public:
45         PacketCounter() : count (0) {}
46         void v_handlePacket(senf::Packet const & p) { ++count; }
47         unsigned count;
48     };
49
50 }
51
52 SENF_AUTO_UNIT_TEST(monitorModulePassthrough)
53 {
54     senf::ppi::module::debug::ActiveSource source;
55     senf::ppi::module::debug::PassiveSink sink;
56     PacketCounter counter;
57
58     senf::ppi::connect(source, counter);
59     senf::ppi::connect(counter, sink);
60
61     senf::ppi::init();
62
63     senf::Packet p (senf::DataPacket::create());
64
65     BOOST_CHECK_EQUAL( counter.count, 0u );
66     source.submit(p);
67     BOOST_CHECK_EQUAL( counter.count, 1u );
68     BOOST_CHECK( sink.pop_front() == p );
69     BOOST_CHECK( source );
70     sink.throttle();
71     BOOST_CHECK( ! source );
72     sink.unthrottle();
73     BOOST_CHECK( source );
74 }
75
76 SENF_AUTO_UNIT_TEST(monitorModuleNoPassthrough)
77 {
78     senf::ppi::module::debug::ActiveSource source;
79     PacketCounter counter;
80
81     senf::ppi::connect(source, counter);
82
83     senf::ppi::init();
84
85     senf::Packet p (senf::DataPacket::create());
86
87     BOOST_CHECK_EQUAL( counter.count, 0u );
88     source.submit(p);
89     BOOST_CHECK_EQUAL( counter.count, 1u );
90     BOOST_CHECK( source );
91 }
92
93 SENF_AUTO_UNIT_TEST(monitorModuleDynamicConnect)
94 {
95     senf::ppi::module::debug::ActiveSource source;
96     PacketCounter counter;
97
98     senf::ppi::connect(source, counter);
99
100     senf::ppi::init();
101
102     senf::Packet p (senf::DataPacket::create());
103
104     BOOST_CHECK_EQUAL( counter.count, 0u );
105     source.submit(p);
106     BOOST_CHECK_EQUAL( counter.count, 1u );
107     BOOST_CHECK( source );
108
109     senf::ppi::module::debug::PassiveSink sink;
110     senf::ppi::connect(counter, sink);
111     senf::ppi::init(); // Needs to be called since I'm not running in the scheduler !!
112
113     BOOST_CHECK( source );
114     source.submit(p);
115     BOOST_CHECK_EQUAL( counter.count, 2u );
116     BOOST_CHECK( sink.pop_front() == p );
117     sink.throttle();
118     BOOST_CHECK( ! source );
119     sink.unthrottle();
120     BOOST_CHECK( source );
121
122     counter.output.disconnect();
123     senf::ppi::init(); // Needs to be called since I'm not running in the scheduler !!
124
125     BOOST_CHECK( source );
126     source.submit(p);
127     BOOST_CHECK_EQUAL( counter.count, 3u );
128
129 }
130
131 //-/////////////////////////////////////////////////////////////////////////////////////////////////
132 #undef prefix_
133
134 \f
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // comment-column: 40
139 // c-file-style: "senf"
140 // indent-tabs-mode: nil
141 // ispell-local-dictionary: "american"
142 // compile-command: "scons -u test"
143 // End: