2 # Copyright (C) 2019 EfficiOS Inc.
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
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.
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.
21 from utils
import get_default_trace_class
24 class EventClassTestCase(unittest
.TestCase
):
26 self
._tc
= get_default_trace_class()
28 self
._context
_fc
= self
._tc
.create_structure_field_class()
29 self
._context
_fc
.append_member('allo', self
._tc
.create_string_field_class())
30 self
._context
_fc
.append_member('zola', self
._tc
.create_signed_integer_field_class(18))
32 self
._payload
_fc
= self
._tc
.create_structure_field_class()
33 self
._payload
_fc
.append_member('zoom', self
._tc
.create_string_field_class())
35 self
._stream
_class
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=True)
37 def test_create_default(self
):
38 ec
= self
._stream
_class
.create_event_class()
40 self
.assertIsNone(ec
.name
, 'my_event')
41 self
.assertTrue(type(ec
.id), int)
42 self
.assertIsNone(ec
.specific_context_field_class
)
43 self
.assertIsNone(ec
.payload_field_class
)
44 self
.assertIsNone(ec
.emf_uri
)
45 self
.assertIsNone(ec
.log_level
)
47 def test_create_invalid_id(self
):
48 sc
= self
._tc
.create_stream_class(assigns_automatic_event_class_id
=False)
49 with self
.assertRaises(TypeError):
50 sc
.create_event_class(id='lel')
52 def test_create_specific_context_field_class(self
):
53 fc
= self
._tc
.create_structure_field_class()
54 ec
= self
._stream
_class
.create_event_class(specific_context_field_class
=fc
)
55 self
.assertEqual(ec
.specific_context_field_class
.addr
, fc
.addr
)
57 def test_create_invalid_specific_context_field_class(self
):
58 with self
.assertRaises(TypeError):
59 self
._stream
_class
.create_event_class(specific_context_field_class
='lel')
61 def test_create_payload_field_class(self
):
62 fc
= self
._tc
.create_structure_field_class()
63 ec
= self
._stream
_class
.create_event_class(payload_field_class
=fc
)
64 self
.assertEqual(ec
.payload_field_class
.addr
, fc
.addr
)
66 def test_create_invalid_payload_field_class(self
):
67 with self
.assertRaises(TypeError):
68 self
._stream
_class
.create_event_class(payload_field_class
='lel')
70 def test_create_name(self
):
71 ec
= self
._stream
_class
.create_event_class(name
='viande à chien')
72 self
.assertEqual(ec
.name
, 'viande à chien')
74 def test_create_invalid_name(self
):
75 with self
.assertRaises(TypeError):
76 self
._stream
_class
.create_event_class(name
=2)
78 def test_emf_uri(self
):
79 ec
= self
._stream
_class
.create_event_class(emf_uri
='salut')
80 self
.assertEqual(ec
.emf_uri
, 'salut')
82 def test_create_invalid_emf_uri(self
):
83 with self
.assertRaises(TypeError):
84 self
._stream
_class
.create_event_class(emf_uri
=23)
86 def test_create_log_level(self
):
87 ec
= self
._stream
_class
.create_event_class(log_level
=bt2
.EventClassLogLevel
.EMERGENCY
)
88 self
.assertEqual(ec
.log_level
, bt2
.EventClassLogLevel
.EMERGENCY
)
90 def test_create_invalid_log_level(self
):
91 with self
.assertRaises(ValueError):
92 self
._stream
_class
.create_event_class(log_level
='zoom')
94 def test_stream_class(self
):
95 ec
= self
._stream
_class
.create_event_class()
96 self
.assertEqual(ec
.stream_class
.addr
, self
._stream
_class
.addr
)