def test_array_element_declaration(self): int_ft = bt2.IntegerFieldType(size=32, is_signed=True, base=8) array_ft = bt2.ArrayFieldType(int_ft, 5) declaration = self._get_declaration(array_ft) element_declaration = declaration.element_declaration self.assertEqual(element_declaration.type, babeltrace.CTFTypeId.INTEGER) self.assertEqual(element_declaration.size, 32) self.assertEqual(element_declaration.base, 8)
def test_type(self): int_ft = bt2.IntegerFieldType(32) enum_ft = bt2.EnumerationFieldType(int_ft) enum_ft.append_mapping('corner', 23) enum_ft.append_mapping('zoom', 17, 20) enum_ft.append_mapping('mellotron', 1001) enum_ft.append_mapping('giorgio', 2000, 3000) array_ft = bt2.ArrayFieldType(int_ft, 5) seq_ft = bt2.SequenceFieldType(int_ft, 'the_len_field') float_ft = bt2.FloatingPointNumberFieldType() struct_ft = bt2.StructureFieldType() struct_ft.append_field('a', int_ft) struct_ft.append_field('b', int_ft) struct_ft.append_field('c', int_ft) _string_ft = bt2.StringFieldType() variant_ft = bt2.VariantFieldType('tag', enum_ft) variant_ft.append_field('corner', int_ft) variant_ft.append_field('zoom', array_ft) variant_ft.append_field('mellotron', float_ft) variant_ft.append_field('giorgio', struct_ft) expected_types = { babeltrace.CTFTypeId.INTEGER: int_ft, babeltrace.CTFTypeId.FLOAT: float_ft, babeltrace.CTFTypeId.ENUM: enum_ft, babeltrace.CTFTypeId.STRING: _string_ft, babeltrace.CTFTypeId.STRUCT: struct_ft, babeltrace.CTFTypeId.VARIANT: variant_ft, babeltrace.CTFTypeId.ARRAY: array_ft, babeltrace.CTFTypeId.SEQUENCE: seq_ft, } for type_id, ft in expected_types.items(): declaration = self._get_declaration(ft) self.assertIsNotNone(declaration) self.assertEqual(declaration.type, type_id)
def test_create_invalid_field_type(self): with self.assertRaises(TypeError): self._ft = bt2.ArrayFieldType(object(), 'the.length')
def test_create_invalid_length_type(self): with self.assertRaises(TypeError): self._ft = bt2.ArrayFieldType(bt2.StringFieldType(), 'the length')
def test_create_invalid_length(self): with self.assertRaises(ValueError): self._ft = bt2.ArrayFieldType(bt2.StringFieldType(), -17)
def setUp(self): self._elem_ft = bt2.IntegerFieldType(23) self._ft = bt2.ArrayFieldType(self._elem_ft, 45)
def test_array_length(self): int_ft = bt2.IntegerFieldType(32) array_ft = bt2.ArrayFieldType(int_ft, 5) declaration = self._get_declaration(array_ft) self.assertEqual(declaration.length, 5)