4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief MultiConnectorMixin.test unit tests */
26 //#include "MultiConnectorMixin.test.hh"
27 //#include "MultiConnectorMixin.test.ih"
30 #include "MultiConnectorMixin.hh"
31 #include "DebugModules.hh"
33 #include "AnnotationRouter.hh"
35 #include <senf/Utils/auto_unit_test.hh>
36 #include <boost/test/test_tools.hpp>
39 ///////////////////////////////cc.p////////////////////////////////////////
40 namespace ppi = senf::ppi;
41 namespace connector = ppi::connector;
42 namespace module = ppi::module;
43 namespace debug = module::debug;
48 class SequenceContainerModule
49 : public module::Module,
50 public module::MultiConnectorMixin<SequenceContainerModule, connector::PassiveInput<> >
52 SENF_PPI_MODULE(SequenceContainerModule);
53 typedef module::MultiConnectorMixin<SequenceContainerModule, connector::PassiveInput<> > base;
56 connector::ActiveOutput<> output;
58 using base::connectors;
60 SequenceContainerModule() : count (0u)
68 void connectorSetup(connector::PassiveInput<> & c)
71 c.onRequest(boost::bind(&SequenceContainerModule::request, this, boost::ref(c)));
75 void connectorDestroy(connector::PassiveInput<> const & c)
80 void request(connector::PassiveInput<> & c)
85 friend class module::MultiConnectorMixin<SequenceContainerModule, connector::PassiveInput<> >;
88 // Primitive duplicator
89 class UserContainerModule
90 : public module::Module,
91 public module::MultiConnectorMixin<UserContainerModule, connector::ActiveOutput<>, void, void>
93 SENF_PPI_MODULE(UserContainerModule);
94 typedef std::vector< boost::shared_ptr<UserContainerModule::ConnectorType> > Connectors;
96 connector::PassiveInput<> input;
101 input.onRequest(&UserContainerModule::request);
104 Connectors const & connectors() const
105 { return connectors_; }
108 void connectorSetup(std::auto_ptr<ConnectorType> c)
111 connectors_.push_back(boost::shared_ptr<ConnectorType>(c));
114 void connectorDestroy(ConnectorType const * c)
116 Connectors::iterator i (
117 std::find_if(connectors_.begin(), connectors_.end(),
118 boost::bind(&Connectors::value_type::get,_1) == c));
119 if (i != connectors_.end())
120 connectors_.erase(i);
125 senf::Packet p (input());
126 for (Connectors::iterator i (connectors_.begin()), i_end (connectors_.end());
131 Connectors connectors_;
133 friend class module::MultiConnectorMixin<UserContainerModule, connector::ActiveOutput<>, void, void>;
136 struct IntAnnotation {
138 bool operator<(IntAnnotation const & other) const { return value < other.value; }
140 IntAnnotation(int v) : value(v) {}
143 std::ostream & operator<<(std::ostream & os, IntAnnotation const & value)
144 { os << value.value; return os; }
147 SENF_AUTO_UNIT_TEST(multiConnectorMixin_sequenceContainer)
149 debug::ActiveSource source1;
150 debug::ActiveSource source2;
151 SequenceContainerModule module;
152 debug::PassiveSink sink;
154 ppi::connect(source1, module);
155 ppi::connect(source2, module);
156 ppi::connect(module, sink);
159 senf::Packet p (senf::DataPacket::create());
162 BOOST_CHECK_EQUAL( sink.size(), 1u );
163 BOOST_CHECK( sink.pop_front() == p );
165 BOOST_CHECK_EQUAL( sink.size(), 1u );
166 BOOST_CHECK( sink.pop_front() == p );
168 BOOST_CHECK_EQUAL( module.connectors().size(), 2u );
169 BOOST_CHECK_EQUAL( module.count, 2u );
170 source1.output.disconnect();
171 BOOST_CHECK_EQUAL( module.connectors().size(), 1u );
172 BOOST_CHECK_EQUAL( module.count, 1u );
175 SENF_AUTO_UNIT_TEST(multiConnectorMixin_userContainer)
177 debug::ActiveSource source;
178 UserContainerModule module;
179 debug::PassiveSink sink1;
180 debug::PassiveSink sink2;
182 ppi::connect(source, module);
183 ppi::connect(module, sink1);
184 ppi::connect(module, sink2);
187 senf::Packet p (senf::DataPacket::create());
190 BOOST_CHECK_EQUAL( sink1.size(), 1u );
191 BOOST_CHECK_EQUAL( sink2.size(), 1u );
192 BOOST_CHECK( sink1.pop_front() == p );
193 BOOST_CHECK( sink2.pop_front() == p );
195 BOOST_CHECK_EQUAL( module.connectors().size(), 2u );
196 sink1.input.disconnect();
197 BOOST_CHECK_EQUAL( module.connectors().size(), 1u );
200 SENF_AUTO_UNIT_TEST(multiConnectorMixin_multipleModules)
202 debug::ActiveSource source;
203 debug::PassiveSink sink;
204 module::PassiveJoin join1;
205 module::PassiveJoin join2;
206 module::AnnotationRouter<IntAnnotation> router;
207 UserContainerModule module;
209 ppi::connect(source, join1);
210 ppi::connect(join1, router);
211 ppi::connect(router, 1, join2);
212 ppi::connect(join2, module);
213 ppi::connect(module, sink);
215 senf::Packet p (senf::DataPacket::create());
216 p.annotation<IntAnnotation>().value = 1;
219 BOOST_CHECK_EQUAL( sink.size(), 1u );
220 BOOST_CHECK( sink.pop_front() == p );
223 ///////////////////////////////cc.e////////////////////////////////////////
230 // comment-column: 40
231 // c-file-style: "senf"
232 // indent-tabs-mode: nil
233 // ispell-local-dictionary: "american"
234 // compile-command: "scons -u test"