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