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 AnnotationRouter unit tests */
31 //#include "AnnotationRouter.test.hh"
32 //#include "AnnotationRouter.test.ih"
35 #include "AnnotationRouter.hh"
36 #include "DebugModules.hh"
38 #include <senf/Utils/auto_unit_test.hh>
39 #include <boost/test/test_tools.hpp>
42 //-/////////////////////////////////////////////////////////////////////////////////////////////////
43 namespace ppi = senf::ppi;
44 namespace connector = ppi::connector;
45 namespace module = ppi::module;
46 namespace debug = module::debug;
49 struct IntAnnotation {
51 bool operator<(IntAnnotation const & other) const { return value < other.value; }
52 bool operator==(IntAnnotation const & other) const { return value == other.value; }
54 IntAnnotation(int v) : value(v) {}
55 IntAnnotation & operator=(int v) { value=v; return *this; }
56 operator int () const { return value; }
59 std::ostream & operator<<(std::ostream & os, IntAnnotation const & value)
60 { os << value.value; return os; }
62 struct AnnotationRouter : public module::AnnotationRouter<IntAnnotation>
64 using module::AnnotationRouter<IntAnnotation>::connectors;
68 SENF_AUTO_UNIT_TEST(annotationRouter)
70 debug::ActiveSource source;
71 debug::PassiveSink sink1;
72 debug::PassiveSink sink2;
74 AnnotationRouter router;
76 ppi::connect(source, router);
77 ppi::connect(router, 1, sink1);
78 ppi::connect(router, 2, sink2);
80 BOOST_CHECK_THROW( connect(router, 2, sink2),
81 module::AnnotationRouter<IntAnnotation>::DuplicateKeyException);
85 senf::Packet p1 (senf::DataPacket::create());
86 p1.annotation<IntAnnotation>() = 1;
87 senf::Packet p2 (senf::DataPacket::create());
88 p2.annotation<IntAnnotation>() = 2;
92 source.submit(senf::DataPacket::create());
94 BOOST_CHECK_EQUAL( sink1.size(), 1u );
95 BOOST_CHECK_EQUAL( sink2.size(), 1u );
96 BOOST_CHECK( sink1.front() == p1 );
97 BOOST_CHECK( sink2.front() == p2 );
98 BOOST_CHECK_EQUAL(router.connectors().size(), 2u);
100 sink1.input.disconnect();
101 BOOST_CHECK_EQUAL(router.connectors().size(), 1u);
103 senf::ppi::connect(router, 1, sink1);
107 BOOST_CHECK_EQUAL( sink1.size(), 2u );
108 BOOST_CHECK_EQUAL( sink2.size(), 1u );
111 //-/////////////////////////////////////////////////////////////////////////////////////////////////
118 // comment-column: 40
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"