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 AnnotationRouter unit tests */
26 //#include "AnnotationRouter.test.hh"
27 //#include "AnnotationRouter.test.ih"
30 #include "AnnotationRouter.hh"
31 #include "DebugModules.hh"
33 #include <senf/Utils/auto_unit_test.hh>
34 #include <boost/test/test_tools.hpp>
37 ///////////////////////////////cc.p////////////////////////////////////////
40 struct IntAnnotation {
42 bool operator<(IntAnnotation const & other) const { return value < other.value; }
43 bool operator==(IntAnnotation const & other) const { return value == other.value; }
45 IntAnnotation(int v) : value(v) {}
46 IntAnnotation & operator=(int v) { value=v; return *this; }
47 operator int () const { return value; }
50 std::ostream & operator<<(std::ostream & os, IntAnnotation const & value)
51 { os << value.value; return os; }
53 struct AnnotationRouter : public senf::ppi::module::AnnotationRouter<IntAnnotation>
55 using senf::ppi::module::AnnotationRouter<IntAnnotation>::connectors;
59 BOOST_AUTO_UNIT_TEST(annotationRouter)
61 senf::ppi::module::debug::ActiveSource source;
62 senf::ppi::module::debug::PassiveSink sink1;
63 senf::ppi::module::debug::PassiveSink sink2;
65 AnnotationRouter router;
67 senf::ppi::connect(source, router);
68 senf::ppi::connect(router, 1, sink1);
69 senf::ppi::connect(router, 2, sink2);
71 BOOST_CHECK_THROW( senf::ppi::connect(router, 2, sink2),
72 senf::ppi::module::AnnotationRouter<IntAnnotation>::DuplicateKeyException);
76 senf::Packet p1 (senf::DataPacket::create());
77 p1.annotation<IntAnnotation>() = 1;
78 senf::Packet p2 (senf::DataPacket::create());
79 p2.annotation<IntAnnotation>() = 2;
83 source.submit(senf::DataPacket::create());
85 BOOST_CHECK_EQUAL( sink1.size(), 1u );
86 BOOST_CHECK_EQUAL( sink2.size(), 1u );
87 BOOST_CHECK( sink1.front() == p1 );
88 BOOST_CHECK( sink2.front() == p2 );
90 BOOST_CHECK_EQUAL(router.connectors().size(), 2u);
91 sink1.input.disconnect();
94 ///////////////////////////////cc.e////////////////////////////////////////
101 // comment-column: 40
102 // c-file-style: "senf"
103 // indent-tabs-mode: nil
104 // ispell-local-dictionary: "american"
105 // compile-command: "scons -u test"