5c6f7e951781f6512001a7728a2a45735bbb99dc
[senf.git] / senf / PPI / DebugModules.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2007
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 DebubgModules unit tests */
25
26 //#include "DebubgModules.test.hh"
27 //#include "DebubgModules.test.ih"
28
29 // Custom includes
30 #include <algorithm>
31 #include <sstream>
32
33 #define SENF_LOG_CONF (( (senf)(log)(Debug), (_), VERBOSE ))
34
35 #include <senf/Packets/Packets.hh>
36 #include "DebugModules.hh"
37 #include "Setup.hh"
38
39 #include <senf/Utils/auto_unit_test.hh>
40 #include <boost/test/test_tools.hpp>
41
42 #define prefix_
43 //-/////////////////////////////////////////////////////////////////////////////////////////////////
44
45 namespace debug = senf::ppi::module::debug;
46 namespace ppi = senf::ppi;
47
48 SENF_AUTO_UNIT_TEST(debugModules)
49 {
50     {
51         debug::ActiveSource source;
52         debug::PassiveSink sink;
53
54         ppi::connect(source, sink);
55         ppi::init();
56
57         senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u };
58         senf::Packet p (senf::DataPacket::create(data));
59
60         BOOST_CHECK( ! sink.input.throttled() );
61
62         source.submit(p);
63
64         BOOST_CHECK( ! sink.input.throttled() );
65         BOOST_CHECK_EQUAL( sink.size(), 1u );
66         BOOST_CHECK( ! sink.empty() );
67         BOOST_CHECK_EQUAL(
68             debug::PassiveSink::size_type(std::distance(sink.begin(),sink.end())),
69             sink.size() );
70         BOOST_CHECK( *sink.begin() == p );
71         BOOST_CHECK( sink.front() == p );
72
73         sink.clear();
74
75         BOOST_CHECK( ! sink.front() );
76         BOOST_CHECK( sink.empty() );
77     }
78
79     {
80         debug::PassiveSource source;
81         debug::ActiveSink sink;
82
83         ppi::connect(source, sink);
84         ppi::init();
85
86         senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u };
87         senf::Packet p (senf::DataPacket::create(data));
88
89         source.submit(p);
90
91         BOOST_CHECK_EQUAL( source.size(), 1u );
92         BOOST_CHECK_EQUAL( sink.request(), p );
93         BOOST_CHECK_EQUAL( source.size(), 0u );
94         BOOST_CHECK( source.empty() );
95     }
96 }
97
98 SENF_AUTO_UNIT_TEST(activeFeederSource)
99 {
100     debug::ActiveFeederSource source;
101     debug::PassiveSink sink;
102
103     ppi::connect(source,sink);
104     source.submit(senf::DataPacket::create());
105     ppi::run();
106
107     BOOST_CHECK( source.empty() );
108     BOOST_CHECK_EQUAL( source.size(), 0u );
109     BOOST_CHECK_EQUAL( sink.size(), 1u );
110 }
111
112 SENF_AUTO_UNIT_TEST(activeFeederSink)
113 {
114     debug::PassiveSource source;
115     debug::ActiveFeederSink sink;
116
117     ppi::connect(source,sink);
118     source.submit(senf::DataPacket::create());
119     ppi::run();
120
121     BOOST_CHECK( ! sink.empty() );
122     BOOST_CHECK_EQUAL( sink.size(), 1u );
123     BOOST_CHECK_EQUAL( debug::ActiveFeederSink::size_type(std::distance(sink.begin(), sink.end())),
124                        sink.size() );
125     BOOST_CHECK( sink.front().data().empty() );
126     BOOST_CHECK( sink.pop_front().data().empty() );
127     BOOST_CHECK( sink.empty() );
128     BOOST_CHECK( source.empty() );
129 }
130
131 SENF_AUTO_UNIT_TEST(logSink)
132 {
133     senf::log::StringTarget logTarget;
134     logTarget.route<senf::log::Debug,senf::log::VERBOSE>();
135
136     debug::ActiveFeederSource source;
137     debug::Logger<> logger ("Prefix text");
138
139     ppi::connect(source,logger);
140     senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u };
141     source.submit( senf::DataPacket::create(data) );
142     senf::ppi::run();
143
144     BOOST_CHECK( ! logTarget.str().empty() );
145 }
146
147 //-/////////////////////////////////////////////////////////////////////////////////////////////////
148 #undef prefix_
149
150 \f
151 // Local Variables:
152 // mode: c++
153 // fill-column: 100
154 // comment-column: 40
155 // c-file-style: "senf"
156 // indent-tabs-mode: nil
157 // ispell-local-dictionary: "american"
158 // compile-command: "scons -u test"
159 // End: