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