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 | ||
9cf643d1 | 19 | import unittest |
9cf643d1 | 20 | import bt2 |
65531d55 | 21 | from utils import get_default_trace_class |
9cf643d1 PP |
22 | |
23 | ||
24 | class EventClassTestCase(unittest.TestCase): | |
25 | def setUp(self): | |
65531d55 SM |
26 | self._tc = get_default_trace_class() |
27 | ||
28 | self._context_fc = self._tc.create_structure_field_class() | |
d47b87ac | 29 | self._context_fc.append_member('allo', self._tc.create_string_field_class()) |
cfbd7cf3 FD |
30 | self._context_fc.append_member( |
31 | 'zola', self._tc.create_signed_integer_field_class(18) | |
32 | ) | |
65531d55 SM |
33 | |
34 | self._payload_fc = self._tc.create_structure_field_class() | |
d47b87ac | 35 | self._payload_fc.append_member('zoom', self._tc.create_string_field_class()) |
9cf643d1 | 36 | |
cfbd7cf3 FD |
37 | self._stream_class = self._tc.create_stream_class( |
38 | assigns_automatic_event_class_id=True | |
39 | ) | |
9cf643d1 | 40 | |
65531d55 SM |
41 | def test_create_default(self): |
42 | ec = self._stream_class.create_event_class() | |
9cf643d1 | 43 | |
65531d55 SM |
44 | self.assertIsNone(ec.name, 'my_event') |
45 | self.assertTrue(type(ec.id), int) | |
46 | self.assertIsNone(ec.specific_context_field_class) | |
47 | self.assertIsNone(ec.payload_field_class) | |
48 | self.assertIsNone(ec.emf_uri) | |
49 | self.assertIsNone(ec.log_level) | |
50 | ||
51 | def test_create_invalid_id(self): | |
52 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False) | |
9cf643d1 | 53 | with self.assertRaises(TypeError): |
65531d55 SM |
54 | sc.create_event_class(id='lel') |
55 | ||
56 | def test_create_specific_context_field_class(self): | |
57 | fc = self._tc.create_structure_field_class() | |
58 | ec = self._stream_class.create_event_class(specific_context_field_class=fc) | |
59 | self.assertEqual(ec.specific_context_field_class.addr, fc.addr) | |
9cf643d1 | 60 | |
65531d55 SM |
61 | def test_create_invalid_specific_context_field_class(self): |
62 | with self.assertRaises(TypeError): | |
63 | self._stream_class.create_event_class(specific_context_field_class='lel') | |
9cf643d1 | 64 | |
65531d55 SM |
65 | def test_create_payload_field_class(self): |
66 | fc = self._tc.create_structure_field_class() | |
67 | ec = self._stream_class.create_event_class(payload_field_class=fc) | |
68 | self.assertEqual(ec.payload_field_class.addr, fc.addr) | |
9cf643d1 | 69 | |
65531d55 | 70 | def test_create_invalid_payload_field_class(self): |
9cf643d1 | 71 | with self.assertRaises(TypeError): |
65531d55 SM |
72 | self._stream_class.create_event_class(payload_field_class='lel') |
73 | ||
74 | def test_create_name(self): | |
75 | ec = self._stream_class.create_event_class(name='viande à chien') | |
76 | self.assertEqual(ec.name, 'viande à chien') | |
77 | ||
78 | def test_create_invalid_name(self): | |
79 | with self.assertRaises(TypeError): | |
80 | self._stream_class.create_event_class(name=2) | |
81 | ||
82 | def test_emf_uri(self): | |
83 | ec = self._stream_class.create_event_class(emf_uri='salut') | |
84 | self.assertEqual(ec.emf_uri, 'salut') | |
85 | ||
86 | def test_create_invalid_emf_uri(self): | |
811644b8 | 87 | with self.assertRaises(TypeError): |
65531d55 | 88 | self._stream_class.create_event_class(emf_uri=23) |
9cf643d1 | 89 | |
65531d55 | 90 | def test_create_log_level(self): |
cfbd7cf3 FD |
91 | ec = self._stream_class.create_event_class( |
92 | log_level=bt2.EventClassLogLevel.EMERGENCY | |
93 | ) | |
65531d55 | 94 | self.assertEqual(ec.log_level, bt2.EventClassLogLevel.EMERGENCY) |
9cf643d1 | 95 | |
65531d55 | 96 | def test_create_invalid_log_level(self): |
811644b8 | 97 | with self.assertRaises(ValueError): |
65531d55 SM |
98 | self._stream_class.create_event_class(log_level='zoom') |
99 | ||
100 | def test_stream_class(self): | |
101 | ec = self._stream_class.create_event_class() | |
102 | self.assertEqual(ec.stream_class.addr, self._stream_class.addr) |