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