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