import math
import copy
import itertools
+import collections
import bt2
from utils import get_default_trace_class
packet_context_fc.append_member(name, fc)
trace = tc()
- stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc)
+ stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc,
+ supports_packets=True)
stream = trace.create_stream(stream_class)
return stream
def _test_binop_rhs_zero_vfloat(self, test_cb, op):
test_cb(op, bt2.create_value(0.0))
+ def _test_binop_rhs_complex(self, test_cb, op):
+ test_cb(op, -23+19j)
+
+ def _test_binop_rhs_zero_complex(self, test_cb, op):
+ test_cb(op, 0j)
+
def _test_binop_type_false(self, op):
self._test_binop_rhs_false(self._test_binop_type, op)
def _test_binop_type_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_type, op)
+ def _test_binop_type_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_type, op)
+
+ def _test_binop_type_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_type, op)
+
def _test_binop_value_false(self, op):
self._test_binop_rhs_false(self._test_binop_value, op)
def _test_binop_value_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_value, op)
+ def _test_binop_value_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_value, op)
+
+ def _test_binop_value_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_value, op)
+
def _test_binop_lhs_addr_same_false(self, op):
self._test_binop_rhs_false(self._test_binop_lhs_addr_same, op)
def _test_binop_lhs_addr_same_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_lhs_addr_same, op)
+ def _test_binop_lhs_addr_same_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_lhs_addr_same, op)
+
+ def _test_binop_lhs_addr_same_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_lhs_addr_same, op)
+
def _test_binop_lhs_value_same_false(self, op):
self._test_binop_rhs_false(self._test_binop_lhs_value_same, op)
def _test_binop_lhs_value_same_zero_vfloat(self, op):
self._test_binop_rhs_zero_vfloat(self._test_binop_lhs_value_same, op)
+ def _test_binop_lhs_value_same_complex(self, op):
+ self._test_binop_rhs_complex(self._test_binop_lhs_value_same, op)
+
+ def _test_binop_lhs_value_same_zero_complex(self, op):
+ self._test_binop_rhs_zero_complex(self._test_binop_lhs_value_same, op)
+
def test_bool_op(self):
self.assertEqual(bool(self._def), bool(self._def_value))
setattr(cls, test_binop_name('lhs_addr_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_vfloat, op=binop))
setattr(cls, test_binop_name('lhs_value_same_zero_float'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_float, op=binop))
setattr(cls, test_binop_name('lhs_value_same_zero_vfloat'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_vfloat, op=binop))
+ setattr(cls, test_binop_name('type_complex'), partialmethod(_TestNumericField._test_binop_type_complex, op=binop))
+ setattr(cls, test_binop_name('type_zero_complex'), partialmethod(_TestNumericField._test_binop_type_zero_complex, op=binop))
+ setattr(cls, test_binop_name('value_complex'), partialmethod(_TestNumericField._test_binop_value_complex, op=binop))
+ setattr(cls, test_binop_name('value_zero_complex'), partialmethod(_TestNumericField._test_binop_value_zero_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_addr_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_addr_same_zero_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_complex, op=binop))
+ setattr(cls, test_binop_name('lhs_value_same_zero_complex'), partialmethod(_TestNumericField._test_binop_lhs_value_same_zero_complex, op=binop))
# inject testing methods for each unary operation
for name, unaryop in _UNARYOPS:
class SignedEnumerationFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase):
def _create_fc(self, tc):
fc = tc.create_signed_enumeration_field_class(32)
- fc.map_range('something', 17)
- fc.map_range('speaker', 12, 16)
- fc.map_range('can', 18, 2540)
- fc.map_range('whole range', -(2 ** 31), (2 ** 31) - 1)
- fc.map_range('zip', -45, 1001)
+ fc.add_mapping('something', bt2.SignedIntegerRangeSet([(17, 17)]))
+ fc.add_mapping('speaker', bt2.SignedIntegerRangeSet([(12, 16)]))
+ fc.add_mapping('can', bt2.SignedIntegerRangeSet([(18, 2540)]))
+ fc.add_mapping('whole range', bt2.SignedIntegerRangeSet([(-(2 ** 31), (2 ** 31) - 1)]))
+ fc.add_mapping('zip', bt2.SignedIntegerRangeSet([(-45, 1001)]))
return fc
def setUp(self):
field[2] = 1948754
self.assertNotEqual(self._def, field)
+ def test_eq_non_sequence_iterable(self):
+ dct = collections.OrderedDict([(1, 2), (3, 4), (5, 6)])
+ field = _create_int_array_field(self._tc, 3)
+ field[0] = 1
+ field[1] = 3
+ field[2] = 5
+ self.assertEqual(field, list(dct.keys()))
+ self.assertNotEqual(field, dct)
+
def test_setitem(self):
self._def[2] = 24
self.assertEqual(self._def[2], 24)
class VariantFieldTestCase(unittest.TestCase):
def _create_fc(self, tc):
- selector_fc = tc.create_signed_enumeration_field_class(field_value_range=32)
- selector_fc.map_range('corner', 23)
- selector_fc.map_range('zoom', 17, 20)
- selector_fc.map_range('mellotron', 1001)
- selector_fc.map_range('giorgio', 2000, 3000)
-
ft0 = tc.create_signed_integer_field_class(32)
ft1 = tc.create_string_field_class()
ft2 = tc.create_real_field_class()
ft3 = tc.create_signed_integer_field_class(17)
-
fc = tc.create_variant_field_class()
fc.append_option('corner', ft0)
fc.append_option('zoom', ft1)
fc.append_option('mellotron', ft2)
fc.append_option('giorgio', ft3)
- fc.selector_field_class = selector_fc
-
top_fc = tc.create_structure_field_class()
- top_fc.append_member('selector_field', selector_fc)
top_fc.append_member('variant_field', fc)
return top_fc