8084a7ab187e0367e771d1052061cf87006b5a4a
[senf.git] / PPI / AnnotationRouter.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
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.
12 //
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.
17 //
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.
22
23 /** \file
24     \brief AnnotationRouter.test unit tests */
25
26 //#include "AnnotationRouter.test.hh"
27 //#include "AnnotationRouter.test.ih"
28
29 // Custom includes
30 #include "AnnotationRouter.hh"
31 #include "DebugModules.hh"
32
33 #include "../Utils//auto_unit_test.hh"
34 #include <boost/test/test_tools.hpp>
35
36 #define prefix_
37 ///////////////////////////////cc.p////////////////////////////////////////
38
39 namespace {
40     struct IntAnnotation {
41         int value;
42         bool operator<(IntAnnotation const & other) const { return value < other.value; }
43         bool operator==(IntAnnotation const & other) const { return value == other.value; }
44         IntAnnotation(int v) : value(v) {}
45         IntAnnotation & operator=(int v) { value=v; return *this; }
46         operator int () const { return value; }
47     };
48
49     std::ostream & operator<<(std::ostream & os, IntAnnotation const & value)
50     { os << value.value; return os; }
51 }
52
53 BOOST_AUTO_UNIT_TEST(annotationRouter)
54 {
55     senf::ppi::module::debug::ActiveSource source;
56     senf::ppi::module::debug::PassiveSink sink1;
57     senf::ppi::module::debug::PassiveSink sink2;
58
59     senf::ppi::module::AnnotationRouter<IntAnnotation> router;
60     
61     senf::ppi::connect(source, router);
62     senf::ppi::connect(router, sink1, 1);
63     senf::ppi::connect(router, sink2, 2);
64
65     senf::ppi::init();
66
67     senf::Packet p1 (senf::DataPacket::create());
68     p1.annotation<IntAnnotation>() = 1;
69     senf::Packet p2 (senf::DataPacket::create());
70     p2.annotation<IntAnnotation>() = 2;
71
72     source.submit(p1);
73     source.submit(p2);
74     source.submit(senf::DataPacket::create());
75
76     BOOST_CHECK_EQUAL( sink1.size(), 1u );
77     BOOST_CHECK_EQUAL( sink2.size(), 1u );
78     BOOST_CHECK( sink1.front() == p1 );
79     BOOST_CHECK( sink2.front() == p2 );
80 }
81
82 ///////////////////////////////cc.e////////////////////////////////////////
83 #undef prefix_
84
85 \f
86 // Local Variables:
87 // mode: c++
88 // fill-column: 100
89 // comment-column: 40
90 // c-file-style: "senf"
91 // indent-tabs-mode: nil
92 // ispell-local-dictionary: "american"
93 // compile-command: "scons -u test"
94 // End: