1f6f668812af28d3dd3b49f331870f832b309c25
[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 // Custom includes
30 #include <algorithm>
31 #include "Packets/Packets.hh"
32 #include "DebugModules.hh"
33 #include "Setup.hh"
34
35 #include <boost/test/auto_unit_test.hpp>
36 #include <boost/test/test_tools.hpp>
37
38 #define prefix_
39 ///////////////////////////////cc.p////////////////////////////////////////
40
41 namespace debug = senf::ppi::module::debug;
42 namespace ppi = senf::ppi;
43
44 BOOST_AUTO_UNIT_TEST(debugModules)
45 {
46     {
47         debug::ActiveSource source;
48         debug::PassiveSink sink;
49
50         ppi::connect(source, sink);
51         ppi::init();
52     
53         senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u };
54         senf::Packet p (senf::DataPacket::create(data));
55
56         BOOST_CHECK( ! sink.input.throttled() );
57
58         source.submit(p);
59
60         BOOST_CHECK( ! sink.input.throttled() );
61         BOOST_CHECK_EQUAL( sink.size(), 1u );
62         BOOST_CHECK( ! sink.empty() );
63         BOOST_CHECK_EQUAL( 
64             debug::PassiveSink::size_type(std::distance(sink.begin(),sink.end())),
65             sink.size() );
66         BOOST_CHECK( *sink.begin() == p );
67         BOOST_CHECK( sink.front() == p );
68
69         sink.clear();
70
71         BOOST_CHECK( ! sink.front() );
72         BOOST_CHECK( sink.empty() );
73     }
74
75     {
76         debug::PassiveSource source;
77         debug::ActiveSink sink;
78
79         ppi::connect(source, sink);
80         ppi::init();
81
82         senf::PacketData::byte data[] = { 0x13u, 0x24u, 0x35u };
83         senf::Packet p (senf::DataPacket::create(data));
84
85         source.submit(p);
86         
87         BOOST_CHECK_EQUAL( source.size(), 1u );
88         BOOST_CHECK_EQUAL( sink.request(), p );
89         BOOST_CHECK_EQUAL( source.size(), 0u );
90         BOOST_CHECK( source.empty() );
91     }
92 }
93
94 BOOST_AUTO_UNIT_TEST(activeFeederSource)
95 {
96     debug::ActiveFeederSource source;
97     debug::PassiveSink sink;
98
99     ppi::connect(source,sink);
100
101     source.submit(senf::DataPacket::create());
102     
103     ppi::run();
104
105     BOOST_CHECK( source.empty() );
106     BOOST_CHECK_EQUAL( source.size(), 0u );
107     BOOST_CHECK_EQUAL( sink.size(), 1u );
108 }
109
110 BOOST_AUTO_UNIT_TEST(activeFeederSink)
111 {
112     debug::PassiveSource source;
113     debug::ActiveFeederSink sink;
114
115     ppi::connect(source,sink);
116
117     source.submit(senf::DataPacket::create());
118     
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 ///////////////////////////////cc.e////////////////////////////////////////
132 #undef prefix_
133
134 \f
135 // Local Variables:
136 // mode: c++
137 // fill-column: 100
138 // comment-column: 40
139 // c-file-style: "senf"
140 // indent-tabs-mode: nil
141 // ispell-local-dictionary: "american"
142 // compile-command: "scons -u test"
143 // End: