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"
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
36 ///////////////////////////////cc.p////////////////////////////////////////
37 namespace ppi = senf::ppi;
38 namespace connector = ppi::connector;
39 namespace module = ppi::module;
40 namespace debug = module::debug;
45 class SequenceContainerModule
46 : public module::Module,
47 public module::MultiConnectorMixin<SequenceContainerModule, connector::PassiveInput<> >
49 SENF_PPI_MODULE(SequenceContainerModule);
50 typedef module::MultiConnectorMixin<SequenceContainerModule, connector::PassiveInput<> > base;
53 connector::ActiveOutput<> output;
55 using base::connectors;
57 SequenceContainerModule() : count (0u)
65 void connectorSetup(connector::PassiveInput<> & c)
68 c.onRequest(boost::bind(&SequenceContainerModule::request, this, boost::ref(c)));
72 void connectorDestroy(connector::PassiveInput<> const & c)
77 void request(connector::PassiveInput<> & c)
82 friend class module::MultiConnectorMixin<SequenceContainerModule, connector::PassiveInput<> >;
85 // Primitive duplicator
86 class UserContainerModule
87 : public module::Module,
88 public module::MultiConnectorMixin<UserContainerModule, connector::ActiveOutput<>, void, void>
90 SENF_PPI_MODULE(UserContainerModule);
91 typedef std::vector< boost::shared_ptr<UserContainerModule::ConnectorType> > Connectors;
93 connector::PassiveInput<> input;
98 input.onRequest(&UserContainerModule::request);
101 Connectors const & connectors() const
102 { return connectors_; }
105 void connectorSetup(std::auto_ptr<ConnectorType> c)
108 connectors_.push_back(boost::shared_ptr<ConnectorType>(c));
111 void connectorDestroy(ConnectorType const * c)
113 Connectors::iterator i (
114 std::find_if(connectors_.begin(), connectors_.end(),
115 boost::bind(&Connectors::value_type::get,_1) == c));
116 if (i != connectors_.end())
117 connectors_.erase(i);
122 senf::Packet p (input());
123 for (Connectors::iterator i (connectors_.begin()), i_end (connectors_.end());
128 Connectors connectors_;
130 friend class module::MultiConnectorMixin<UserContainerModule, connector::ActiveOutput<>, void, void>;
133 struct IntAnnotation {
135 bool operator<(IntAnnotation const & other) const { return value < other.value; }
137 IntAnnotation(int v) : value(v) {}
140 std::ostream & operator<<(std::ostream & os, IntAnnotation const & value)
141 { os << value.value; return os; }
144 SENF_AUTO_UNIT_TEST(multiConnectorMixin_sequenceContainer)
146 debug::ActiveSource source1;
147 debug::ActiveSource source2;
148 SequenceContainerModule module;
149 debug::PassiveSink sink;
151 ppi::connect(source1, module);
152 ppi::connect(source2, module);
153 ppi::connect(module, sink);
156 senf::Packet p (senf::DataPacket::create());
159 BOOST_CHECK_EQUAL( sink.size(), 1u );
160 BOOST_CHECK( sink.pop_front() == p );
162 BOOST_CHECK_EQUAL( sink.size(), 1u );
163 BOOST_CHECK( sink.pop_front() == p );
165 BOOST_CHECK_EQUAL( module.connectors().size(), 2u );
166 BOOST_CHECK_EQUAL( module.count, 2u );
167 source1.output.disconnect();
168 BOOST_CHECK_EQUAL( module.connectors().size(), 1u );
169 BOOST_CHECK_EQUAL( module.count, 1u );
172 SENF_AUTO_UNIT_TEST(multiConnectorMixin_userContainer)
174 debug::ActiveSource source;
175 UserContainerModule module;
176 debug::PassiveSink sink1;
177 debug::PassiveSink sink2;
179 ppi::connect(source, module);
180 ppi::connect(module, sink1);
181 ppi::connect(module, sink2);
184 senf::Packet p (senf::DataPacket::create());
187 BOOST_CHECK_EQUAL( sink1.size(), 1u );
188 BOOST_CHECK_EQUAL( sink2.size(), 1u );
189 BOOST_CHECK( sink1.pop_front() == p );
190 BOOST_CHECK( sink2.pop_front() == p );
192 BOOST_CHECK_EQUAL( module.connectors().size(), 2u );
193 sink1.input.disconnect();
194 BOOST_CHECK_EQUAL( module.connectors().size(), 1u );
197 SENF_AUTO_UNIT_TEST(multiConnectorMixin_multipleModules)
199 debug::ActiveSource source;
200 debug::PassiveSink sink;
201 module::PassiveJoin join1;
202 module::PassiveJoin join2;
203 module::AnnotationRouter<IntAnnotation> router;
204 UserContainerModule module;
206 ppi::connect(source, join1);
207 ppi::connect(join1, router);
208 ppi::connect(router, 1, join2);
209 ppi::connect(join2, module);
210 ppi::connect(module, sink);
212 senf::Packet p (senf::DataPacket::create());
213 p.annotation<IntAnnotation>().value = 1;
216 BOOST_CHECK_EQUAL( sink.size(), 1u );
217 BOOST_CHECK( sink.pop_front() == p );
220 ///////////////////////////////cc.e////////////////////////////////////////
227 // comment-column: 40
228 // c-file-style: "senf"
229 // indent-tabs-mode: nil
230 // ispell-local-dictionary: "american"
231 // compile-command: "scons -u test"