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 PP |
20 | import bt2 |
21 | ||
22 | ||
23 | class UserComponentTestCase(unittest.TestCase): | |
24 | @staticmethod | |
9bc3e785 | 25 | def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE): |
f6a5e476 PP |
26 | graph = bt2.Graph() |
27 | ||
28 | if name is None: | |
29 | name = 'comp' | |
30 | ||
9bc3e785 | 31 | return graph.add_component(comp_cls, name, logging_level=log_level) |
f6a5e476 PP |
32 | |
33 | def test_name(self): | |
34 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 35 | def __init__(comp_self, params, obj): |
f6a5e476 PP |
36 | self.assertEqual(comp_self.name, 'yaes') |
37 | ||
819d0ae7 | 38 | def _user_consume(self): |
8a08af82 SM |
39 | pass |
40 | ||
36153ada | 41 | self._create_comp(MySink, 'yaes') |
f6a5e476 | 42 | |
9bc3e785 PP |
43 | def test_logging_level(self): |
44 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 45 | def __init__(comp_self, params, obj): |
9bc3e785 PP |
46 | self.assertEqual(comp_self.logging_level, bt2.LoggingLevel.INFO) |
47 | ||
819d0ae7 | 48 | def _user_consume(self): |
8a08af82 SM |
49 | pass |
50 | ||
36153ada | 51 | self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) |
9bc3e785 | 52 | |
253a9ecc PP |
53 | def test_graph_mip_version(self): |
54 | class MySink(bt2._UserSinkComponent): | |
55 | def __init__(comp_self, params, obj): | |
56 | self.assertEqual(comp_self._graph_mip_version, 0) | |
57 | ||
58 | def _user_consume(self): | |
59 | pass | |
60 | ||
36153ada | 61 | self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO) |
253a9ecc | 62 | |
f6a5e476 PP |
63 | def test_class(self): |
64 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 65 | def __init__(comp_self, params, obj): |
c88be1c8 | 66 | self.assertEqual(comp_self.cls, MySink) |
f6a5e476 | 67 | |
819d0ae7 | 68 | def _user_consume(self): |
8a08af82 SM |
69 | pass |
70 | ||
f6a5e476 PP |
71 | self._create_comp(MySink) |
72 | ||
73 | def test_addr(self): | |
74 | class MySink(bt2._UserSinkComponent): | |
b20382e2 | 75 | def __init__(comp_self, params, obj): |
f6a5e476 PP |
76 | self.assertIsInstance(comp_self.addr, int) |
77 | self.assertNotEqual(comp_self.addr, 0) | |
78 | ||
819d0ae7 | 79 | def _user_consume(self): |
8a08af82 SM |
80 | pass |
81 | ||
f6a5e476 PP |
82 | self._create_comp(MySink) |
83 | ||
84 | def test_finalize(self): | |
85 | finalized = False | |
86 | ||
87 | class MySink(bt2._UserSinkComponent): | |
819d0ae7 | 88 | def _user_consume(self): |
8a08af82 SM |
89 | pass |
90 | ||
819d0ae7 | 91 | def _user_finalize(comp_self): |
f6a5e476 PP |
92 | nonlocal finalized |
93 | finalized = True | |
94 | ||
95 | graph = bt2.Graph() | |
bc5c9924 | 96 | comp = graph.add_component(MySink, 'lel') |
e34fb94a | 97 | |
f6a5e476 PP |
98 | del graph |
99 | del comp | |
100 | self.assertTrue(finalized) | |
101 | ||
102 | ||
103 | class GenericComponentTestCase(unittest.TestCase): | |
104 | @staticmethod | |
9bc3e785 | 105 | def _create_comp(comp_cls, name=None, log_level=bt2.LoggingLevel.NONE): |
f6a5e476 PP |
106 | graph = bt2.Graph() |
107 | ||
108 | if name is None: | |
109 | name = 'comp' | |
110 | ||
9bc3e785 | 111 | return graph.add_component(comp_cls, name, logging_level=log_level) |
f6a5e476 PP |
112 | |
113 | def test_name(self): | |
114 | class MySink(bt2._UserSinkComponent): | |
819d0ae7 | 115 | def _user_consume(self): |
8a08af82 SM |
116 | pass |
117 | ||
f6a5e476 PP |
118 | comp = self._create_comp(MySink, 'yaes') |
119 | self.assertEqual(comp.name, 'yaes') | |
120 | ||
9bc3e785 PP |
121 | def test_logging_level(self): |
122 | class MySink(bt2._UserSinkComponent): | |
819d0ae7 | 123 | def _user_consume(self): |
8a08af82 SM |
124 | pass |
125 | ||
e9d0e821 PP |
126 | comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.WARNING) |
127 | self.assertEqual(comp.logging_level, bt2.LoggingLevel.WARNING) | |
9bc3e785 | 128 | |
f6a5e476 PP |
129 | def test_class(self): |
130 | class MySink(bt2._UserSinkComponent): | |
819d0ae7 | 131 | def _user_consume(self): |
8a08af82 SM |
132 | pass |
133 | ||
f6a5e476 | 134 | comp = self._create_comp(MySink) |
c88be1c8 | 135 | self.assertEqual(comp.cls, MySink) |
f6a5e476 PP |
136 | |
137 | def test_addr(self): | |
138 | class MySink(bt2._UserSinkComponent): | |
819d0ae7 | 139 | def _user_consume(self): |
8a08af82 SM |
140 | pass |
141 | ||
f6a5e476 PP |
142 | comp = self._create_comp(MySink) |
143 | self.assertIsInstance(comp.addr, int) | |
144 | self.assertNotEqual(comp.addr, 0) | |
3db06b1d SM |
145 | |
146 | ||
147 | if __name__ == '__main__': | |
148 | unittest.main() |