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