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////////////////////////////////////////
38 namespace ppi = senf::ppi;
39 namespace connector = ppi::connector;
40 namespace module = ppi::module;
41 namespace debug = module::debug;
44 // We only test the user-collection case, all other cases are already handled by
47 // Primitive duplicator
49 : public module::Module,
50 public module::MultiConnectorMixin<MyModule, connector::ActiveOutput<>, void, void>
52 SENF_PPI_MODULE(MyModule);
53 typedef std::vector< boost::shared_ptr<MyModule::ConnectorType> > Connectors;
55 connector::PassiveInput<> input;
60 input.onRequest(&MyModule::request);
63 Connectors const & connectors() const
64 { return connectors_; }
67 void connectorSetup(std::auto_ptr<ConnectorType> c)
70 connectors_.push_back(boost::shared_ptr<ConnectorType>(c));
73 void connectorDestroy(ConnectorType const * c)
75 Connectors::iterator i (
76 std::find_if(connectors_.begin(), connectors_.end(),
77 boost::bind(&Connectors::value_type::get,_1) == c));
78 if (i != connectors_.end())
84 senf::Packet p (input());
85 for (Connectors::iterator i (connectors_.begin()), i_end (connectors_.end());
90 Connectors connectors_;
92 friend class module::MultiConnectorMixin<MyModule, connector::ActiveOutput<>, void, void>;
95 struct IntAnnotation {
97 bool operator<(IntAnnotation const & other) const { return value < other.value; }
99 IntAnnotation(int v) : value(v) {}
102 std::ostream & operator<<(std::ostream & os, IntAnnotation const & value)
103 { os << value.value; return os; }
106 BOOST_AUTO_UNIT_TEST(multiConnectorMixin_userContainer)
108 debug::ActiveSource source;
110 debug::PassiveSink sink1;
111 debug::PassiveSink sink2;
113 ppi::connect(source, module);
114 ppi::connect(module, sink1);
115 ppi::connect(module, sink2);
118 senf::Packet p (senf::DataPacket::create());
121 BOOST_CHECK_EQUAL( sink1.size(), 1u );
122 BOOST_CHECK_EQUAL( sink2.size(), 1u );
123 BOOST_CHECK( sink1.pop_front() == p );
124 BOOST_CHECK( sink2.pop_front() == p );
126 BOOST_CHECK_EQUAL( module.connectors().size(), 2u );
127 sink1.input.disconnect();
128 BOOST_CHECK_EQUAL( module.connectors().size(), 1u );
131 BOOST_AUTO_UNIT_TEST(multiConnectorMixin_multipleModules)
133 debug::ActiveSource source;
134 debug::PassiveSink sink;
135 module::PassiveJoin join1;
136 module::PassiveJoin join2;
137 module::AnnotationRouter<IntAnnotation> router;
140 ppi::connect(source, join1);
141 ppi::connect(join1, router);
142 ppi::connect(router, 1, join2);
143 ppi::connect(join2, module);
144 ppi::connect(module, sink);
146 senf::Packet p (senf::DataPacket::create());
147 p.annotation<IntAnnotation>().value = 1;
150 BOOST_CHECK_EQUAL( sink.size(), 1u );
151 BOOST_CHECK( sink.pop_front() == p );
154 ///////////////////////////////cc.e////////////////////////////////////////
161 // comment-column: 40
162 // c-file-style: "senf"
163 // indent-tabs-mode: nil
164 // ispell-local-dictionary: "american"
165 // compile-command: "scons -u test"