Move sourcecode into 'senf/' directory
[senf.git] / senf / PPI / Joins.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 Joins unit tests */
25
26 //#include "Joins.test.hh"
27 //#include "Joins.test.ih"
28
29 // Custom includes
30 #include "Joins.hh"
31 #include "DebugModules.hh"
32 #include "Setup.hh"
33 #include "../Packets/Packets.hh"
34
35 #include "../Utils/auto_unit_test.hh"
36 #include <boost/test/test_tools.hpp>
37
38 #define prefix_
39 ///////////////////////////////cc.p////////////////////////////////////////
40
41 namespace ppi = senf::ppi;
42 namespace connector = ppi::connector;
43 namespace module = ppi::module;
44 namespace debug = module::debug;
45
46 BOOST_AUTO_UNIT_TEST(passiveJoin)
47 {
48     debug::ActiveSource source1;
49     debug::ActiveSource source2;
50     module::PassiveJoin join;
51     debug::PassiveSink sink;
52
53     ppi::connect(source1, join);
54     ppi::connect(source2, join);
55     ppi::connect(join, sink);
56     ppi::init();
57
58     senf::Packet p (senf::DataPacket::create());
59
60     source1.submit(p);
61     BOOST_CHECK_EQUAL( sink.size(), 1u );
62     source2.submit(p);
63     BOOST_CHECK_EQUAL( sink.size(), 2u );
64
65     sink.input.throttle();
66     BOOST_CHECK( ! source1 );
67     BOOST_CHECK( ! source2 );
68     
69     source1.submit(p);
70     source2.submit(p);
71     BOOST_CHECK_EQUAL( sink.size(), 2u );
72     sink.input.unthrottle();
73     BOOST_CHECK_EQUAL( sink.size(), 4u );
74 }
75
76 BOOST_AUTO_UNIT_TEST(priorityJoin)
77 {
78     debug::PassiveSource source1;
79     debug::PassiveSource source2;
80     module::PriorityJoin join;
81     debug::ActiveSink sink;
82
83     ppi::connect(source1, join);
84     ppi::connect(source2, join);
85     ppi::connect(join,sink);
86     ppi::init();
87
88     BOOST_CHECK( ! sink );
89
90     senf::Packet p1 (senf::DataPacket::create());
91     senf::Packet p2 (senf::DataPacket::create());
92     
93     source1.submit(p1);
94     BOOST_CHECK( sink );
95     source2.submit(p2);
96     BOOST_CHECK( sink );
97     BOOST_CHECK( sink.request() == p1 );
98     BOOST_CHECK( sink );
99     BOOST_CHECK( sink.request() == p2 );
100     BOOST_CHECK( ! sink );
101
102     source1.submit(p1);
103     source2.submit(p2);
104     source1.submit(p1);
105     BOOST_CHECK( sink.request() == p1 );
106     BOOST_CHECK( sink.request() == p1 );
107     BOOST_CHECK( sink.request() == p2 );
108     BOOST_CHECK( ! sink );
109
110     debug::PassiveSource source3;
111     debug::PassiveSource source4;
112     ppi::connect(source3, join, 0);
113     ppi::connect(source4, join, -2);
114     // Ordering now: source3, source1, source4, source2
115  
116     senf::Packet p3 (senf::DataPacket::create());
117     senf::Packet p4 (senf::DataPacket::create());
118  
119     source4.submit(p4);
120     source3.submit(p3);
121     source2.submit(p2);
122     source1.submit(p1);
123     BOOST_CHECK( sink.request() == p3 );
124     BOOST_CHECK( sink.request() == p1 );
125     BOOST_CHECK( sink.request() == p4 );
126     BOOST_CHECK( sink.request() == p2 );
127     BOOST_CHECK( ! sink );
128 }
129
130 ///////////////////////////////cc.e////////////////////////////////////////
131 #undef prefix_
132
133 \f
134 // Local Variables:
135 // mode: c++
136 // fill-column: 100
137 // comment-column: 40
138 // c-file-style: "senf"
139 // indent-tabs-mode: nil
140 // ispell-local-dictionary: "american"
141 // compile-command: "scons -u test"
142 // End: