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 | 20 | import bt2 |
9012866a | 21 | from bt2 import connection as bt2_connection |
49e6b55c | 22 | from bt2 import port as bt2_port |
f6a5e476 PP |
23 | |
24 | ||
25 | class ConnectionTestCase(unittest.TestCase): | |
26 | def test_create(self): | |
fa4c33e3 | 27 | class MyIter(bt2._UserMessageIterator): |
f6a5e476 PP |
28 | def __next__(self): |
29 | raise bt2.Stop | |
30 | ||
61d96b89 | 31 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
b20382e2 | 32 | def __init__(self, params, obj): |
f6a5e476 PP |
33 | self._add_output_port('out') |
34 | ||
35 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 36 | def __init__(self, params, obj): |
f6a5e476 PP |
37 | self._add_input_port('in') |
38 | ||
819d0ae7 | 39 | def _user_consume(self): |
f6a5e476 PP |
40 | raise bt2.Stop |
41 | ||
42 | graph = bt2.Graph() | |
43 | src = graph.add_component(MySource, 'src') | |
44 | sink = graph.add_component(MySink, 'sink') | |
9012866a FD |
45 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
46 | self.assertIs(type(conn), bt2_connection._ConnectionConst) | |
f6a5e476 PP |
47 | |
48 | def test_downstream_port(self): | |
fa4c33e3 | 49 | class MyIter(bt2._UserMessageIterator): |
f6a5e476 PP |
50 | def __next__(self): |
51 | raise bt2.Stop | |
52 | ||
61d96b89 | 53 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
b20382e2 | 54 | def __init__(self, params, obj): |
f6a5e476 PP |
55 | self._add_output_port('out') |
56 | ||
57 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 58 | def __init__(self, params, obj): |
f6a5e476 PP |
59 | self._add_input_port('in') |
60 | ||
819d0ae7 | 61 | def _user_consume(self): |
f6a5e476 PP |
62 | raise bt2.Stop |
63 | ||
64 | graph = bt2.Graph() | |
65 | src = graph.add_component(MySource, 'src') | |
66 | sink = graph.add_component(MySink, 'sink') | |
61d96b89 | 67 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
f6a5e476 | 68 | self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr) |
9012866a | 69 | self.assertIs(type(conn), bt2_connection._ConnectionConst) |
49e6b55c | 70 | self.assertIs(type(conn.downstream_port), bt2_port._InputPortConst) |
f6a5e476 PP |
71 | |
72 | def test_upstream_port(self): | |
fa4c33e3 | 73 | class MyIter(bt2._UserMessageIterator): |
f6a5e476 PP |
74 | def __next__(self): |
75 | raise bt2.Stop | |
76 | ||
61d96b89 | 77 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
b20382e2 | 78 | def __init__(self, params, obj): |
f6a5e476 PP |
79 | self._add_output_port('out') |
80 | ||
81 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 82 | def __init__(self, params, obj): |
f6a5e476 PP |
83 | self._add_input_port('in') |
84 | ||
819d0ae7 | 85 | def _user_consume(self): |
f6a5e476 PP |
86 | raise bt2.Stop |
87 | ||
88 | graph = bt2.Graph() | |
89 | src = graph.add_component(MySource, 'src') | |
90 | sink = graph.add_component(MySink, 'sink') | |
61d96b89 | 91 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
f6a5e476 | 92 | self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr) |
49e6b55c | 93 | self.assertIs(type(conn.upstream_port), bt2_port._OutputPortConst) |