7c1cbe5715de45e2e2d8e61dd064ab0930c6eba0
[babeltrace.git] / tests / bindings / python / bt2 / test_connection.py
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
19 import unittest
20 import bt2
21
22
23 class ConnectionTestCase(unittest.TestCase):
24 def test_create(self):
25 class MyIter(bt2._UserMessageIterator):
26 def __next__(self):
27 raise bt2.Stop
28
29 class MySource(bt2._UserSourceComponent,
30 message_iterator_class=MyIter):
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
41 def _graph_is_configured(self):
42 pass
43
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)
50
51 def test_downstream_port(self):
52 class MyIter(bt2._UserMessageIterator):
53 def __next__(self):
54 raise bt2.Stop
55
56 class MySource(bt2._UserSourceComponent,
57 message_iterator_class=MyIter):
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
68 def _graph_is_configured(self):
69 pass
70
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):
79 class MyIter(bt2._UserMessageIterator):
80 def __next__(self):
81 raise bt2.Stop
82
83 class MySource(bt2._UserSourceComponent,
84 message_iterator_class=MyIter):
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
95 def _graph_is_configured(self):
96 pass
97
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)
This page took 0.030565 seconds and 3 git commands to generate.