Commit | Line | Data |
---|---|---|
d2d857a8 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 | ||
811644b8 | 19 | import unittest |
811644b8 PP |
20 | import bt2 |
21 | ||
22 | ||
23 | class ConnectionTestCase(unittest.TestCase): | |
24 | def test_create(self): | |
5602ef81 | 25 | class MyIter(bt2._UserMessageIterator): |
811644b8 PP |
26 | def __next__(self): |
27 | raise bt2.Stop | |
28 | ||
cfbd7cf3 | 29 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
811644b8 PP |
30 | def __init__(self, params): |
31 | self._add_output_port('out') | |
32 | ||
33 | class MySink(bt2._UserSinkComponent): | |
34 | def __init__(self, params): | |
35 | self._add_input_port('in') | |
36 | ||
37 | def _consume(self): | |
38 | raise bt2.Stop | |
39 | ||
a01b452b SM |
40 | def _graph_is_configured(self): |
41 | pass | |
42 | ||
811644b8 PP |
43 | graph = bt2.Graph() |
44 | src = graph.add_component(MySource, 'src') | |
45 | sink = graph.add_component(MySink, 'sink') | |
cfbd7cf3 | 46 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
811644b8 | 47 | self.assertIsInstance(conn, bt2._Connection) |
811644b8 PP |
48 | |
49 | def test_downstream_port(self): | |
5602ef81 | 50 | class MyIter(bt2._UserMessageIterator): |
811644b8 PP |
51 | def __next__(self): |
52 | raise bt2.Stop | |
53 | ||
cfbd7cf3 | 54 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
811644b8 PP |
55 | def __init__(self, params): |
56 | self._add_output_port('out') | |
57 | ||
58 | class MySink(bt2._UserSinkComponent): | |
59 | def __init__(self, params): | |
60 | self._add_input_port('in') | |
61 | ||
62 | def _consume(self): | |
63 | raise bt2.Stop | |
64 | ||
a01b452b SM |
65 | def _graph_is_configured(self): |
66 | pass | |
67 | ||
811644b8 PP |
68 | graph = bt2.Graph() |
69 | src = graph.add_component(MySource, 'src') | |
70 | sink = graph.add_component(MySink, 'sink') | |
cfbd7cf3 | 71 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
811644b8 PP |
72 | self.assertEqual(conn.downstream_port.addr, sink.input_ports['in'].addr) |
73 | ||
74 | def test_upstream_port(self): | |
5602ef81 | 75 | class MyIter(bt2._UserMessageIterator): |
811644b8 PP |
76 | def __next__(self): |
77 | raise bt2.Stop | |
78 | ||
cfbd7cf3 | 79 | class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): |
811644b8 PP |
80 | def __init__(self, params): |
81 | self._add_output_port('out') | |
82 | ||
83 | class MySink(bt2._UserSinkComponent): | |
84 | def __init__(self, params): | |
85 | self._add_input_port('in') | |
86 | ||
87 | def _consume(self): | |
88 | raise bt2.Stop | |
89 | ||
a01b452b SM |
90 | def _graph_is_configured(self): |
91 | pass | |
92 | ||
811644b8 PP |
93 | graph = bt2.Graph() |
94 | src = graph.add_component(MySource, 'src') | |
95 | sink = graph.add_component(MySink, 'sink') | |
cfbd7cf3 | 96 | conn = graph.connect_ports(src.output_ports['out'], sink.input_ports['in']) |
811644b8 | 97 | self.assertEqual(conn.upstream_port.addr, src.output_ports['out'].addr) |