8 @unittest.skip("this is broken")
9 class TraceTestCase(unittest
.TestCase
):
11 self
._sc
= self
._create
_stream
_class
('sc1', 3)
12 self
._tc
= bt2
.Trace()
18 def _create_stream_class(self
, name
, id):
19 ec1
, ec2
= self
._create
_event
_classes
()
20 packet_context_fc
= bt2
.StructureFieldClass()
21 packet_context_fc
.append_field('menu', bt2
.FloatingPointNumberFieldClass())
22 packet_context_fc
.append_field('sticker', bt2
.StringFieldClass())
23 event_header_fc
= bt2
.StructureFieldClass()
24 event_header_fc
.append_field('id', bt2
.IntegerFieldClass(19))
25 event_context_fc
= bt2
.StructureFieldClass()
26 event_context_fc
.append_field('msg', bt2
.StringFieldClass())
27 return bt2
.StreamClass(name
=name
, id=id,
28 packet_context_field_class
=packet_context_fc
,
29 event_header_field_class
=event_header_fc
,
30 event_context_field_class
=event_context_fc
,
31 event_classes
=(ec1
, ec2
))
33 def _create_event_classes(self
):
34 context_fc
= bt2
.StructureFieldClass()
35 context_fc
.append_field('allo', bt2
.StringFieldClass())
36 context_fc
.append_field('zola', bt2
.IntegerFieldClass(18))
37 payload_fc
= bt2
.StructureFieldClass()
38 payload_fc
.append_field('zoom', bt2
.StringFieldClass())
39 ec1
= bt2
.EventClass('event23', id=23, context_field_class
=context_fc
,
40 payload_field_class
=payload_fc
)
41 ec2
= bt2
.EventClass('event17', id=17, context_field_class
=payload_fc
,
42 payload_field_class
=context_fc
)
45 def test_create_default(self
):
46 self
.assertEqual(len(self
._tc
), 0)
48 def _get_std_header(self
):
49 header_fc
= bt2
.StructureFieldClass()
50 header_fc
.append_field('magic', bt2
.IntegerFieldClass(32))
51 header_fc
.append_field('stream_id', bt2
.IntegerFieldClass(32))
54 def test_create_full(self
):
55 clock_classes
= bt2
.ClockClass('cc1', 1000), bt2
.ClockClass('cc2', 30)
56 sc
= self
._create
_stream
_class
('sc1', 3)
57 tc
= bt2
.Trace(name
='my name',
58 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
59 env
={'the_string': 'value', 'the_int': 23},
60 packet_header_field_class
=self
._get
_std
_header
(),
61 clock_classes
=clock_classes
,
63 self
.assertEqual(tc
.name
, 'my name')
64 self
.assertEqual(tc
.native_byte_order
, bt2
.ByteOrder
.LITTLE_ENDIAN
)
65 self
.assertEqual(tc
.env
['the_string'], 'value')
66 self
.assertEqual(tc
.env
['the_int'], 23)
67 self
.assertEqual(tc
.packet_header_field_class
, self
._get
_std
_header
())
68 self
.assertEqual(tc
.clock_classes
['cc1'], clock_classes
[0])
69 self
.assertEqual(tc
.clock_classes
['cc2'], clock_classes
[1])
70 self
.assertEqual(tc
[3], sc
)
72 def test_assign_name(self
):
74 self
.assertEqual(self
._tc
.name
, 'lel')
76 def test_assign_invalid_name(self
):
77 with self
.assertRaises(TypeError):
80 def test_assign_static(self
):
81 self
._tc
.set_is_static()
82 self
.assertTrue(self
._tc
.is_static
)
84 def test_assign_native_byte_order(self
):
85 self
._tc
.native_byte_order
= bt2
.ByteOrder
.BIG_ENDIAN
86 self
.assertEqual(self
._tc
.native_byte_order
, bt2
.ByteOrder
.BIG_ENDIAN
)
88 def test_assign_invalid_native_byte_order(self
):
89 with self
.assertRaises(TypeError):
90 self
._tc
.native_byte_order
= 'lel'
92 def test_assign_packet_header_field_class(self
):
93 header_fc
= bt2
.StructureFieldClass()
94 header_fc
.append_field('magic', bt2
.IntegerFieldClass(32))
95 self
._tc
.packet_header_field_class
= header_fc
96 self
.assertEqual(self
._tc
.packet_header_field_class
, header_fc
)
98 def test_assign_no_packet_header_field_class(self
):
99 self
._tc
.packet_header_field_class
= None
100 self
.assertIsNone(self
._tc
.packet_header_field_class
)
102 def _test_copy(self
, cpy
):
103 self
.assertIsNot(cpy
, self
._tc
)
104 self
.assertNotEqual(cpy
.addr
, self
._tc
.addr
)
105 self
.assertEqual(cpy
, self
._tc
)
106 self
.assertEqual(len(self
._tc
), len(cpy
))
109 self
._tc
.packet_header_field_class
= self
._get
_std
_header
()
110 self
._tc
.name
= 'the trace class'
111 sc1
= self
._create
_stream
_class
('sc1', 3)
112 sc2
= self
._create
_stream
_class
('sc2', 9)
113 sc3
= self
._create
_stream
_class
('sc3', 17)
114 self
._tc
.add_clock_class(bt2
.ClockClass('cc1', 1000))
115 self
._tc
.add_clock_class(bt2
.ClockClass('cc2', 30))
116 self
._tc
.env
['allo'] = 'bateau'
117 self
._tc
.env
['bateau'] = 'cart'
118 self
._tc
.add_stream_class(sc1
)
119 self
._tc
.add_stream_class(sc2
)
120 self
._tc
.add_stream_class(sc3
)
124 cpy
= copy
.copy(self
._tc
)
126 self
.assertEqual(self
._tc
.packet_header_field_class
.addr
, cpy
.packet_header_field_class
.addr
)
127 self
.assertEqual(self
._tc
.clock_classes
['cc1'].addr
, cpy
.clock_classes
['cc1'].addr
)
128 self
.assertEqual(self
._tc
.clock_classes
['cc2'].addr
, cpy
.clock_classes
['cc2'].addr
)
129 self
.assertEqual(self
._tc
.env
['allo'].addr
, cpy
.env
['allo'].addr
)
130 self
.assertEqual(self
._tc
.env
['bateau'].addr
, cpy
.env
['bateau'].addr
)
132 def test_deepcopy(self
):
134 cpy
= copy
.deepcopy(self
._tc
)
136 self
.assertNotEqual(self
._tc
.packet_header_field_class
.addr
, cpy
.packet_header_field_class
.addr
)
137 self
.assertNotEqual(self
._tc
.clock_classes
['cc1'].addr
, cpy
.clock_classes
['cc1'].addr
)
138 self
.assertNotEqual(self
._tc
.clock_classes
['cc2'].addr
, cpy
.clock_classes
['cc2'].addr
)
139 self
.assertNotEqual(self
._tc
.env
['allo'].addr
, cpy
.env
['allo'].addr
)
140 self
.assertNotEqual(self
._tc
.env
['bateau'].addr
, cpy
.env
['bateau'].addr
)
142 def test_getitem(self
):
143 self
._tc
.add_stream_class(self
._sc
)
144 self
.assertEqual(self
._tc
[3].addr
, self
._sc
.addr
)
146 def test_getitem_wrong_key_type(self
):
147 self
._tc
.add_stream_class(self
._sc
)
148 with self
.assertRaises(TypeError):
151 def test_getitem_wrong_key(self
):
152 self
._tc
.add_stream_class(self
._sc
)
153 with self
.assertRaises(KeyError):
157 self
.assertEqual(len(self
._tc
), 0)
158 self
._tc
.add_stream_class(self
._sc
)
159 self
.assertEqual(len(self
._tc
), 1)
162 self
._tc
.packet_header_field_class
= self
._get
_std
_header
()
163 sc1
= self
._create
_stream
_class
('sc1', 3)
164 sc2
= self
._create
_stream
_class
('sc2', 9)
165 sc3
= self
._create
_stream
_class
('sc3', 17)
166 self
._tc
.add_stream_class(sc1
)
167 self
._tc
.add_stream_class(sc2
)
168 self
._tc
.add_stream_class(sc3
)
170 for sid
, stream_class
in self
._tc
.items():
171 self
.assertIsInstance(stream_class
, bt2
.StreamClass
)
174 self
.assertEqual(stream_class
.addr
, sc1
.addr
)
176 self
.assertEqual(stream_class
.addr
, sc2
.addr
)
178 self
.assertEqual(stream_class
.addr
, sc3
.addr
)
180 def test_env_getitem_wrong_key(self
):
181 with self
.assertRaises(KeyError):
184 def test_clock_classes_getitem_wrong_key(self
):
185 with self
.assertRaises(KeyError):
186 self
._tc
.clock_classes
['lel']
188 def test_streams_none(self
):
189 self
.assertEqual(len(self
._tc
.streams
), 0)
191 def test_streams_len(self
):
192 self
._tc
.add_stream_class(self
._create
_stream
_class
('sc1', 3))
193 stream0
= self
._tc
[3]()
194 stream1
= self
._tc
[3]()
195 stream2
= self
._tc
[3]()
196 self
.assertEqual(len(self
._tc
.streams
), 3)
198 def test_streams_iter(self
):
199 self
._tc
.add_stream_class(self
._create
_stream
_class
('sc1', 3))
200 stream0
= self
._tc
[3](id=12)
201 stream1
= self
._tc
[3](id=15)
202 stream2
= self
._tc
[3](id=17)
205 for stream
in self
._tc
.streams
:
208 self
.assertEqual(len(sids
), 3)
209 self
.assertTrue(12 in sids
and 15 in sids
and 17 in sids
)
211 def _test_eq_create_objects(self
):
212 cc1_uuid
= uuid
.UUID('bc7f2f2d-2ee4-4e03-ab1f-2e0e1304e94f')
213 cc1
= bt2
.ClockClass('cc1', 1000, uuid
=cc1_uuid
)
214 cc2_uuid
= uuid
.UUID('da7d6b6f-3108-4706-89bd-ab554732611b')
215 cc2
= bt2
.ClockClass('cc2', 30, uuid
=cc2_uuid
)
216 sc1
= self
._create
_stream
_class
('sc1', 3)
217 sc2
= self
._create
_stream
_class
('sc2', 9)
218 return cc1
, cc2
, sc1
, sc2
, self
._get
_std
_header
()
221 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
222 tc1
= bt2
.Trace(name
='my name',
223 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
224 env
={'the_string': 'value', 'the_int': 23},
225 packet_header_field_class
=header_fc
,
226 clock_classes
=(cc1
, cc2
),
227 stream_classes
=(sc1
, sc2
))
228 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
229 tc2
= bt2
.Trace(name
='my name',
230 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
231 env
={'the_string': 'value', 'the_int': 23},
232 packet_header_field_class
=header_fc
,
233 clock_classes
=(cc1
, cc2
),
234 stream_classes
=(sc1
, sc2
))
235 self
.assertEqual(tc1
, tc2
)
237 def test_ne_name(self
):
238 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
239 tc1
= bt2
.Trace(name
='my name2',
240 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
241 env
={'the_string': 'value', 'the_int': 23},
242 packet_header_field_class
=header_fc
,
243 clock_classes
=(cc1
, cc2
),
244 stream_classes
=(sc1
, sc2
))
245 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
246 tc2
= bt2
.Trace(name
='my name',
247 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
248 env
={'the_string': 'value', 'the_int': 23},
249 packet_header_field_class
=header_fc
,
250 clock_classes
=(cc1
, cc2
),
251 stream_classes
=(sc1
, sc2
))
252 self
.assertNotEqual(tc1
, tc2
)
254 def test_ne_packet_header_field_class(self
):
255 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
256 tc1
= bt2
.Trace(name
='my name',
257 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
258 env
={'the_string': 'value', 'the_int': 23},
259 packet_header_field_class
=header_fc
,
260 clock_classes
=(cc1
, cc2
),
261 stream_classes
=(sc1
, sc2
))
262 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
263 header_fc
.append_field('yes', bt2
.StringFieldClass())
264 tc2
= bt2
.Trace(name
='my name',
265 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
266 env
={'the_string': 'value', 'the_int': 23},
267 packet_header_field_class
=header_fc
,
268 clock_classes
=(cc1
, cc2
),
269 stream_classes
=(sc1
, sc2
))
270 self
.assertNotEqual(tc1
, tc2
)
272 def test_ne_native_byte_order(self
):
273 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
274 tc1
= bt2
.Trace(name
='my name',
275 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
276 env
={'the_string': 'value', 'the_int': 23},
277 packet_header_field_class
=header_fc
,
278 clock_classes
=(cc1
, cc2
),
279 stream_classes
=(sc1
, sc2
))
280 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
281 tc2
= bt2
.Trace(name
='my name',
282 native_byte_order
=bt2
.ByteOrder
.BIG_ENDIAN
,
283 env
={'the_string': 'value', 'the_int': 23},
284 packet_header_field_class
=header_fc
,
285 clock_classes
=(cc1
, cc2
),
286 stream_classes
=(sc1
, sc2
))
287 self
.assertNotEqual(tc1
, tc2
)
289 def test_ne_env(self
):
290 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
291 tc1
= bt2
.Trace(name
='my name',
292 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
293 env
={'the_string': 'value', 'the_int2': 23},
294 packet_header_field_class
=header_fc
,
295 clock_classes
=(cc1
, cc2
),
296 stream_classes
=(sc1
, sc2
))
297 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
298 tc2
= bt2
.Trace(name
='my name',
299 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
300 env
={'the_string': 'value', 'the_int': 23},
301 packet_header_field_class
=header_fc
,
302 clock_classes
=(cc1
, cc2
),
303 stream_classes
=(sc1
, sc2
))
304 self
.assertNotEqual(tc1
, tc2
)
306 def test_ne_clock_classes(self
):
307 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
308 tc1
= bt2
.Trace(name
='my name',
309 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
310 env
={'the_string': 'value', 'the_int': 23},
311 packet_header_field_class
=header_fc
,
312 clock_classes
=(cc1
, cc2
),
313 stream_classes
=(sc1
, sc2
))
314 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
316 tc2
= bt2
.Trace(name
='my name',
317 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
318 env
={'the_string': 'value', 'the_int': 23},
319 packet_header_field_class
=header_fc
,
320 clock_classes
=(cc1
, cc2
),
321 stream_classes
=(sc1
, sc2
))
322 self
.assertNotEqual(tc1
, tc2
)
324 def test_ne_stream_classes(self
):
325 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
326 tc1
= bt2
.Trace(name
='my name',
327 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
328 env
={'the_string': 'value', 'the_int': 23},
329 packet_header_field_class
=header_fc
,
330 clock_classes
=(cc1
, cc2
),
331 stream_classes
=(sc1
, sc2
))
332 cc1
, cc2
, sc1
, sc2
, header_fc
= self
._test
_eq
_create
_objects
()
334 tc2
= bt2
.Trace(name
='my name',
335 native_byte_order
=bt2
.ByteOrder
.LITTLE_ENDIAN
,
336 env
={'the_string': 'value', 'the_int': 23},
337 packet_header_field_class
=header_fc
,
338 clock_classes
=(cc1
, cc2
),
339 stream_classes
=(sc1
, sc2
))
340 self
.assertNotEqual(tc1
, tc2
)
342 def test_eq_invalid(self
):
343 self
.assertFalse(self
._tc
== 23)