Replace all relative includes with abolute ones
[senf.git] / senf / PPI / Jack.test.cc
1 // $Id$
2 //
3 // Copyright (C) 2009 
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 Jack unit tests */
25
26 //#include "Jack.test.hh"
27 //#include "Jack.test.ih"
28
29 // Custom includes
30 #include "PPI.hh"
31
32 #include <senf/Utils/auto_unit_test.hh>
33 #include <boost/test/test_tools.hpp>
34
35 #define prefix_
36 ///////////////////////////////cc.p////////////////////////////////////////
37
38 namespace {
39
40     class ActiveDummyForward 
41         : public senf::ppi::module::Module
42     {
43         SENF_PPI_MODULE(ActiveDummyForward);
44     public:
45         senf::ppi::connector::ActiveInput<> input;
46         senf::ppi::connector::PassiveOutput<> output;
47
48         ActiveDummyForward() : n (0)
49             { route(input, output); output.onRequest(&ActiveDummyForward::request); }
50
51         unsigned n;
52
53     private:
54         void request()
55             { ++n; output(input()); }
56     };
57
58     class PassiveDummyForward 
59         : public senf::ppi::module::Module
60     {
61         SENF_PPI_MODULE(PassiveDummyForward);
62     public:
63         senf::ppi::connector::PassiveInput<> input;
64         senf::ppi::connector::ActiveOutput<> output;
65
66         PassiveDummyForward() : n (0)
67             { route(input, output); input.onRequest(&PassiveDummyForward::request); }
68
69         unsigned n;
70
71     private:
72         void request()
73             { ++n; output(input()); }
74     };
75
76     struct ActiveGroup
77     {
78         senf::ppi::connector::ActiveInputJack<> input;
79         senf::ppi::connector::PassiveOutputJack<> output;
80
81         ActiveGroup()
82             : input (forward1.input), output (forward1.output) {}
83
84         void flip()
85         {
86             input.reset(forward2.input);
87             output.reset(forward2.output);
88         }
89
90         ActiveDummyForward forward1;
91         ActiveDummyForward forward2;
92     };
93
94     struct PassiveGroup
95     {
96         senf::ppi::connector::PassiveInputJack<> input;
97         senf::ppi::connector::ActiveOutputJack<> output;
98
99         PassiveGroup()
100             : input (forward1.input), output (forward1.output) {}
101         
102         void flip()
103         {
104             input.reset(forward2.input);
105             output.reset(forward2.output);
106         }
107
108         PassiveDummyForward forward1;
109         PassiveDummyForward forward2;
110     };
111
112 }
113
114 BOOST_AUTO_UNIT_TEST(jacks)
115 {
116     {
117         ActiveGroup group;
118         senf::ppi::module::debug::PassiveSource source;
119         senf::ppi::module::debug::ActiveSink sink;
120
121         senf::ppi::connect(source, group);
122         senf::ppi::connect(group, sink);
123         
124         senf::ppi::init();
125         
126         {
127             senf::Packet p (senf::DataPacket::create());
128             source.submit(p);
129
130             BOOST_CHECK(p == sink.request());
131         }
132
133         group.flip();
134         senf::ppi::init();
135         
136         {
137             senf::Packet p (senf::DataPacket::create());
138             source.submit(p);
139
140             BOOST_CHECK(p == sink.request());
141         }
142
143         BOOST_CHECK_EQUAL( group.forward1.n, 1u );
144         BOOST_CHECK_EQUAL( group.forward2.n, 1u );
145     }
146      
147     {
148         PassiveGroup group;
149         senf::ppi::module::debug::ActiveSource source;
150         senf::ppi::module::debug::PassiveSink sink;
151
152         senf::ppi::connect(source, group);
153         senf::ppi::connect(group, sink);
154
155         senf::ppi::init();
156
157         {
158             senf::Packet p (senf::DataPacket::create());
159             source.submit(p);
160
161             BOOST_CHECK(p == sink.pop_front());
162         }
163
164         group.flip();
165         senf::ppi::init();
166
167         {
168             senf::Packet p (senf::DataPacket::create());
169             source.submit(p);
170
171             BOOST_CHECK(p == sink.pop_front());
172         }
173
174         BOOST_CHECK_EQUAL( group.forward1.n, 1u );
175         BOOST_CHECK_EQUAL( group.forward2.n, 1u );
176     }
177 }
178
179 ///////////////////////////////cc.e////////////////////////////////////////
180 #undef prefix_
181
182 \f
183 // Local Variables:
184 // mode: c++
185 // fill-column: 100
186 // comment-column: 40
187 // c-file-style: "senf"
188 // indent-tabs-mode: nil
189 // ispell-local-dictionary: "american"
190 // compile-command: "scons -u test"
191 // End: