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): | |
a797a36f SM |
27 | class MySource( |
28 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
29 | ): | |
e3250e61 | 30 | def __init__(self, config, params, obj): |
f6a5e476 PP |
31 | self._add_output_port('out') |
32 | ||
33 | class MySink(bt2._UserSinkComponent): | |
e3250e61 | 34 | def __init__(self, config, 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') | |
9012866a FD |
43 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
44 | self.assertIs(type(conn), bt2_connection._ConnectionConst) | |
f6a5e476 PP |
45 | |
46 | def test_downstream_port(self): | |
a797a36f SM |
47 | class MySource( |
48 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
49 | ): | |
e3250e61 | 50 | def __init__(self, config, params, obj): |
f6a5e476 PP |
51 | self._add_output_port('out') |
52 | ||
53 | class MySink(bt2._UserSinkComponent): | |
e3250e61 | 54 | def __init__(self, config, params, obj): |
f6a5e476 PP |
55 | self._add_input_port('in') |
56 | ||
819d0ae7 | 57 | def _user_consume(self): |
f6a5e476 PP |
58 | raise bt2.Stop |
59 | ||
60 | graph = bt2.Graph() | |
61 | src = graph.add_component(MySource, 'src') | |
62 | sink = graph.add_component(MySink, 'sink') | |
61d96b89 | 63 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
f6a5e476 | 64 | self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr) |
9012866a | 65 | self.assertIs(type(conn), bt2_connection._ConnectionConst) |
49e6b55c | 66 | self.assertIs(type(conn.downstream_port), bt2_port._InputPortConst) |
f6a5e476 PP |
67 | |
68 | def test_upstream_port(self): | |
a797a36f SM |
69 | class MySource( |
70 | bt2._UserSourceComponent, message_iterator_class=bt2._UserMessageIterator | |
71 | ): | |
e3250e61 | 72 | def __init__(self, config, params, obj): |
f6a5e476 PP |
73 | self._add_output_port('out') |
74 | ||
75 | class MySink(bt2._UserSinkComponent): | |
e3250e61 | 76 | def __init__(self, config, params, obj): |
f6a5e476 PP |
77 | self._add_input_port('in') |
78 | ||
819d0ae7 | 79 | def _user_consume(self): |
f6a5e476 PP |
80 | raise bt2.Stop |
81 | ||
82 | graph = bt2.Graph() | |
83 | src = graph.add_component(MySource, 'src') | |
84 | sink = graph.add_component(MySink, 'sink') | |
61d96b89 | 85 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
f6a5e476 | 86 | self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr) |
49e6b55c | 87 | self.assertIs(type(conn.upstream_port), bt2_port._OutputPortConst) |
3db06b1d SM |
88 | |
89 | ||
90 | if __name__ == '__main__': | |
91 | unittest.main() |