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