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 | ||
9cf643d1 | 19 | import unittest |
9cf643d1 | 20 | import bt2 |
52c65bda | 21 | from utils import get_default_trace_class |
9cf643d1 PP |
22 | |
23 | ||
24 | class EventClassTestCase(unittest.TestCase): | |
25 | def setUp(self): | |
52c65bda SM |
26 | self._tc = get_default_trace_class() |
27 | ||
28 | self._context_fc = self._tc.create_structure_field_class() | |
c8820b76 | 29 | self._context_fc.append_member('allo', self._tc.create_string_field_class()) |
61d96b89 FD |
30 | self._context_fc.append_member( |
31 | 'zola', self._tc.create_signed_integer_field_class(18) | |
32 | ) | |
52c65bda SM |
33 | |
34 | self._payload_fc = self._tc.create_structure_field_class() | |
c8820b76 | 35 | self._payload_fc.append_member('zoom', self._tc.create_string_field_class()) |
9cf643d1 | 36 | |
61d96b89 FD |
37 | self._stream_class = self._tc.create_stream_class( |
38 | assigns_automatic_event_class_id=True | |
39 | ) | |
9cf643d1 | 40 | |
52c65bda SM |
41 | def test_create_default(self): |
42 | ec = self._stream_class.create_event_class() | |
9cf643d1 | 43 | |
52c65bda 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) | |
b2df5780 | 50 | self.assertEqual(len(ec.user_attributes), 0) |
52c65bda SM |
51 | |
52 | def test_create_invalid_id(self): | |
53 | sc = self._tc.create_stream_class(assigns_automatic_event_class_id=False) | |
9cf643d1 | 54 | with self.assertRaises(TypeError): |
52c65bda SM |
55 | sc.create_event_class(id='lel') |
56 | ||
57 | def test_create_specific_context_field_class(self): | |
58 | fc = self._tc.create_structure_field_class() | |
59 | ec = self._stream_class.create_event_class(specific_context_field_class=fc) | |
60 | self.assertEqual(ec.specific_context_field_class.addr, fc.addr) | |
9cf643d1 | 61 | |
52c65bda SM |
62 | def test_create_invalid_specific_context_field_class(self): |
63 | with self.assertRaises(TypeError): | |
64 | self._stream_class.create_event_class(specific_context_field_class='lel') | |
9cf643d1 | 65 | |
52c65bda SM |
66 | def test_create_payload_field_class(self): |
67 | fc = self._tc.create_structure_field_class() | |
68 | ec = self._stream_class.create_event_class(payload_field_class=fc) | |
69 | self.assertEqual(ec.payload_field_class.addr, fc.addr) | |
9cf643d1 | 70 | |
52c65bda | 71 | def test_create_invalid_payload_field_class(self): |
9cf643d1 | 72 | with self.assertRaises(TypeError): |
52c65bda SM |
73 | self._stream_class.create_event_class(payload_field_class='lel') |
74 | ||
75 | def test_create_name(self): | |
76 | ec = self._stream_class.create_event_class(name='viande à chien') | |
77 | self.assertEqual(ec.name, 'viande à chien') | |
78 | ||
79 | def test_create_invalid_name(self): | |
80 | with self.assertRaises(TypeError): | |
81 | self._stream_class.create_event_class(name=2) | |
82 | ||
83 | def test_emf_uri(self): | |
84 | ec = self._stream_class.create_event_class(emf_uri='salut') | |
85 | self.assertEqual(ec.emf_uri, 'salut') | |
86 | ||
87 | def test_create_invalid_emf_uri(self): | |
f6a5e476 | 88 | with self.assertRaises(TypeError): |
52c65bda | 89 | self._stream_class.create_event_class(emf_uri=23) |
9cf643d1 | 90 | |
52c65bda | 91 | def test_create_log_level(self): |
61d96b89 FD |
92 | ec = self._stream_class.create_event_class( |
93 | log_level=bt2.EventClassLogLevel.EMERGENCY | |
94 | ) | |
52c65bda | 95 | self.assertEqual(ec.log_level, bt2.EventClassLogLevel.EMERGENCY) |
9cf643d1 | 96 | |
52c65bda | 97 | def test_create_invalid_log_level(self): |
f6a5e476 | 98 | with self.assertRaises(ValueError): |
52c65bda SM |
99 | self._stream_class.create_event_class(log_level='zoom') |
100 | ||
b2df5780 PP |
101 | def test_create_user_attributes(self): |
102 | ec = self._stream_class.create_event_class(user_attributes={'salut': 23}) | |
103 | self.assertEqual(ec.user_attributes, {'salut': 23}) | |
104 | ||
105 | def test_create_invalid_user_attributes(self): | |
106 | with self.assertRaises(TypeError): | |
107 | self._stream_class.create_event_class(user_attributes=object()) | |
108 | ||
109 | def test_create_invalid_user_attributes_value_type(self): | |
110 | with self.assertRaises(TypeError): | |
111 | self._stream_class.create_event_class(user_attributes=23) | |
112 | ||
52c65bda SM |
113 | def test_stream_class(self): |
114 | ec = self._stream_class.create_event_class() | |
115 | self.assertEqual(ec.stream_class.addr, self._stream_class.addr) |