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