4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
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
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.
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.
19 // The Original Code is Fraunhofer FOKUS code.
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.
26 // Stefan Bund <g0dil@berlios.de>
29 \brief Joins unit tests */
31 //#include "Joins.test.hh"
32 //#include "Joins.test.ih"
36 #include "DebugModules.hh"
38 #include <senf/Packets/Packets.hh>
40 #include <senf/Utils/auto_unit_test.hh>
41 #include <boost/test/test_tools.hpp>
44 //-/////////////////////////////////////////////////////////////////////////////////////////////////
46 namespace ppi = senf::ppi;
47 namespace connector = ppi::connector;
48 namespace module = ppi::module;
49 namespace debug = module::debug;
53 struct PassiveJoin : public module::PassiveJoin
55 using module::PassiveJoin::connectors;
60 SENF_AUTO_UNIT_TEST(passiveJoin)
62 debug::ActiveSource source1;
63 debug::ActiveSource source2;
65 debug::PassiveSink sink;
67 ppi::connect(source1, join);
68 ppi::connect(source2, join);
69 ppi::connect(join, sink);
72 senf::Packet p (senf::DataPacket::create());
75 BOOST_CHECK_EQUAL( sink.size(), 1u );
77 BOOST_CHECK_EQUAL( sink.size(), 2u );
79 sink.input.throttle();
80 BOOST_CHECK( ! source1 );
81 BOOST_CHECK( ! source2 );
85 BOOST_CHECK_EQUAL( sink.size(), 2u );
86 sink.input.unthrottle();
87 BOOST_CHECK_EQUAL( sink.size(), 4u );
89 BOOST_CHECK_EQUAL( join.connectors().size(), 2u);
90 source1.output.disconnect();
91 BOOST_CHECK_EQUAL( join.connectors().size(), 1u);
92 ppi::connect(source1, join);
94 BOOST_CHECK_EQUAL( join.connectors().size(), 2u);
97 SENF_AUTO_UNIT_TEST(priorityJoin)
99 debug::PassiveSource source1;
100 debug::PassiveSource source2;
101 module::PriorityJoin join;
102 debug::ActiveSink sink;
104 ppi::connect(source1, join);
105 ppi::connect(source2, join);
106 ppi::connect(join,sink);
109 BOOST_CHECK( ! sink );
111 senf::Packet p1 (senf::DataPacket::create());
112 senf::Packet p2 (senf::DataPacket::create());
118 BOOST_CHECK( sink.request() == p1 );
120 BOOST_CHECK( sink.request() == p2 );
121 BOOST_CHECK( ! sink );
126 BOOST_CHECK( sink.request() == p1 );
127 BOOST_CHECK( sink.request() == p1 );
128 BOOST_CHECK( sink.request() == p2 );
129 BOOST_CHECK( ! sink );
131 debug::PassiveSource source3;
132 debug::PassiveSource source4;
133 ppi::connect(source3, join, 0);
134 ppi::connect(source4, join, -2);
135 // Ordering now: source3, source1, source4, source2
137 senf::Packet p3 (senf::DataPacket::create());
138 senf::Packet p4 (senf::DataPacket::create());
144 BOOST_CHECK( sink.request() == p3 );
145 BOOST_CHECK( sink.request() == p1 );
146 BOOST_CHECK( sink.request() == p4 );
147 BOOST_CHECK( sink.request() == p2 );
148 BOOST_CHECK( ! sink );
152 struct ActiveJackSource
154 senf::ppi::connector::ActiveOutputJack<> output;
156 debug::ActiveSource source1;
157 debug::ActiveSource source2;
160 : output (source1.output) {}
163 output.reset( source2.output);
168 //SENF_AUTO_UNIT_TEST(jack_passiveJoin)
170 // ActiveJackSource jackSource;
172 // debug::PassiveSink sink;
174 // ppi::connect(jackSource, join);
175 // ppi::connect(join, sink);
178 // senf::Packet p1 (senf::DataPacket::create());
179 // senf::Packet p2 (senf::DataPacket::create());
181 // jackSource.source1.submit( p1);
182 // BOOST_CHECK_EQUAL( sink.pop_front(), p1);
184 // jackSource.flip();
186 // jackSource.source2.submit( p2);
187 // BOOST_CHECK_EQUAL( sink.pop_front(), p2);
190 //-/////////////////////////////////////////////////////////////////////////////////////////////////
197 // comment-column: 40
198 // c-file-style: "senf"
199 // indent-tabs-mode: nil
200 // ispell-local-dictionary: "american"
201 // compile-command: "scons -u test"