Commit | Line | Data |
---|---|---|
32d2d479 MJ |
1 | # |
2 | # Copyright (C) 2019 EfficiOS Inc. | |
3 | # | |
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; only version 2 | |
7 | # of the License. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | # | |
18 | ||
f6a5e476 | 19 | import unittest |
f6a5e476 PP |
20 | import bt2 |
21 | ||
22 | ||
23 | class ConnectionTestCase(unittest.TestCase): | |
24 | def test_create(self): | |
fa4c33e3 | 25 | class MyIter(bt2._UserMessageIterator): |
f6a5e476 PP |
26 | def __next__(self): |
27 | raise bt2.Stop | |
28 | ||
61d96b89 | 29 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
b20382e2 | 30 | def __init__(self, params, obj): |
f6a5e476 PP |
31 | self._add_output_port('out') |
32 | ||
33 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 34 | def __init__(self, params, obj): |
f6a5e476 PP |
35 | self._add_input_port('in') |
36 | ||
819d0ae7 | 37 | def _user_consume(self): |
f6a5e476 PP |
38 | raise bt2.Stop |
39 | ||
40 | graph = bt2.Graph() | |
41 | src = graph.add_component(MySource, 'src') | |
42 | sink = graph.add_component(MySink, 'sink') | |
61d96b89 | 43 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
f6a5e476 PP |
44 | |
45 | def test_downstream_port(self): | |
fa4c33e3 | 46 | class MyIter(bt2._UserMessageIterator): |
f6a5e476 PP |
47 | def __next__(self): |
48 | raise bt2.Stop | |
49 | ||
61d96b89 | 50 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
b20382e2 | 51 | def __init__(self, params, obj): |
f6a5e476 PP |
52 | self._add_output_port('out') |
53 | ||
54 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 55 | def __init__(self, params, obj): |
f6a5e476 PP |
56 | self._add_input_port('in') |
57 | ||
819d0ae7 | 58 | def _user_consume(self): |
f6a5e476 PP |
59 | raise bt2.Stop |
60 | ||
61 | graph = bt2.Graph() | |
62 | src = graph.add_component(MySource, 'src') | |
63 | sink = graph.add_component(MySink, 'sink') | |
61d96b89 | 64 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
f6a5e476 PP |
65 | self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr) |
66 | ||
67 | def test_upstream_port(self): | |
fa4c33e3 | 68 | class MyIter(bt2._UserMessageIterator): |
f6a5e476 PP |
69 | def __next__(self): |
70 | raise bt2.Stop | |
71 | ||
61d96b89 | 72 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
b20382e2 | 73 | def __init__(self, params, obj): |
f6a5e476 PP |
74 | self._add_output_port('out') |
75 | ||
76 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 77 | def __init__(self, params, obj): |
f6a5e476 PP |
78 | self._add_input_port('in') |
79 | ||
819d0ae7 | 80 | def _user_consume(self): |
f6a5e476 PP |
81 | raise bt2.Stop |
82 | ||
83 | graph = bt2.Graph() | |
84 | src = graph.add_component(MySource, 'src') | |
85 | sink = graph.add_component(MySink, 'sink') | |
61d96b89 | 86 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
f6a5e476 | 87 | self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr) |