switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / PPI / Queueing.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 Queueing unit tests */
30
31 //#include "Queueing.test.hh"
32 //#include "Queueing.test.ih"
33
34 // Custom includes
35 #include "Queueing.hh"
36 #include "Module.hh"
37 #include "Connectors.hh"
38 #include "DebugModules.hh"
39 #include <senf/Packets/Packets.hh>
40 #include "Setup.hh"
41
42 #include <senf/Utils/auto_unit_test.hh>
43 #include <boost/test/test_tools.hpp>
44
45 #define prefix_
46 //-/////////////////////////////////////////////////////////////////////////////////////////////////
47
48 namespace ppi = senf::ppi;
49 namespace connector = ppi::connector;
50 namespace module = ppi::module;
51 namespace debug = module::debug;
52
53 namespace {
54     class QueueTester : public module::Module
55     {
56         SENF_PPI_MODULE(QueueTester);
57     public:
58         connector::PassiveInput<> input;
59         connector::ActiveOutput<> output;
60
61         QueueTester() {
62             route(input, output);
63             input.qdisc(ppi::ThresholdQueueing(2,1));
64             input.onRequest(&QueueTester::nop);
65         }
66
67         void nop() { /* no operation */ }
68
69         void forward() {
70             if (input && output)
71                 output(input());
72         }
73
74     };
75 }
76
77 SENF_AUTO_UNIT_TEST(PPI_Queueing)
78 {
79     debug::ActiveSource source;
80     QueueTester tester;
81     debug::PassiveSink sink;
82
83     ppi::connect(source, tester);
84     ppi::connect(tester, sink);
85     ppi::init();
86
87     senf::Packet p (senf::DataPacket::create());
88     {
89         BOOST_CHECK( source );
90         source.submit(p);
91         BOOST_CHECK( source );
92         source.submit(p);
93         BOOST_CHECK( ! source );
94         BOOST_CHECK_EQUAL( tester.input.queueSize(), 2u );
95         tester.forward();
96         BOOST_CHECK_EQUAL( tester.input.queueSize(), 1u );
97         BOOST_CHECK( source );
98         tester.forward();
99         BOOST_CHECK_EQUAL( tester.input.queueSize(), 0u );
100         BOOST_CHECK( source );
101         BOOST_CHECK_EQUAL( sink.size(), 2u);
102         sink.clear();
103     }
104     {
105         tester.input.qdisc(ppi::QueueingDiscipline::NONE);
106         BOOST_CHECK( source );
107         source.submit(p);
108         BOOST_CHECK( source );
109         source.submit(p);
110         BOOST_CHECK( source );
111         BOOST_CHECK_EQUAL( tester.input.queueSize(), 2u );
112         tester.forward();
113         tester.forward();
114         BOOST_CHECK( source );
115         BOOST_CHECK_EQUAL( tester.input.queueSize(), 0u );
116         BOOST_CHECK_EQUAL( sink.size(), 2u);
117     }
118 }
119
120 //-/////////////////////////////////////////////////////////////////////////////////////////////////
121 #undef prefix_
122
123 \f
124 // Local Variables:
125 // mode: c++
126 // fill-column: 100
127 // comment-column: 40
128 // c-file-style: "senf"
129 // indent-tabs-mode: nil
130 // ispell-local-dictionary: "american"
131 // compile-command: "scons -u test"
132 // End: