From 7617a89d3ee08570a064709e60ef9029fcf16753 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 3 Apr 2019 11:30:40 -0400 Subject: [PATCH] bt2: Mass field_types -> field_class rename The concept of field_type has been renamed to field_class. This patch does a mostly mechanical rename across the Python bindings and their tests. Change-Id: I3c2a870262e3cfeddaec7d3565eb635a4c70d131 Signed-off-by: Simon Marchi Reviewed-on: https://review.gerrithub.io/c/eepp/babeltrace/+/452253 Reviewed-by: Philippe Proulx Tested-by: Philippe Proulx --- bindings/python/bt2/Makefile.am | 2 +- bindings/python/bt2/bt2/__init__.py.in | 4 +- bindings/python/bt2/bt2/event_class.py | 76 +- .../bt2/{field_types.py => field_class.py} | 286 +++---- bindings/python/bt2/bt2/fields.py | 44 +- bindings/python/bt2/bt2/stream_class.py | 112 +-- bindings/python/bt2/bt2/trace.py | 38 +- tests/bindings/python/bt2/Makefile.am | 2 +- tests/bindings/python/bt2/test_event.py | 68 +- tests/bindings/python/bt2/test_event_class.py | 130 ++-- tests/bindings/python/bt2/test_field_class.py | 707 ++++++++++++++++++ tests/bindings/python/bt2/test_field_types.py | 707 ------------------ tests/bindings/python/bt2/test_fields.py | 444 +++++------ tests/bindings/python/bt2/test_graph.py | 24 +- tests/bindings/python/bt2/test_message.py | 64 +- .../python/bt2/test_message_iterator.py | 8 +- tests/bindings/python/bt2/test_packet.py | 50 +- tests/bindings/python/bt2/test_stream.py | 50 +- .../bindings/python/bt2/test_stream_class.py | 198 ++--- tests/bindings/python/bt2/test_trace.py | 134 ++-- 20 files changed, 1574 insertions(+), 1574 deletions(-) rename bindings/python/bt2/bt2/{field_types.py => field_class.py} (57%) create mode 100644 tests/bindings/python/bt2/test_field_class.py delete mode 100644 tests/bindings/python/bt2/test_field_types.py diff --git a/bindings/python/bt2/Makefile.am b/bindings/python/bt2/Makefile.am index 6003f238f..f425922de 100644 --- a/bindings/python/bt2/Makefile.am +++ b/bindings/python/bt2/Makefile.am @@ -42,7 +42,7 @@ STATIC_BINDINGS_DEPS = \ bt2/event_class.py \ bt2/event.py \ bt2/fields.py \ - bt2/field_types.py \ + bt2/field_class.py \ bt2/graph.py \ bt2/logging.py \ bt2/message_iterator.py \ diff --git a/bindings/python/bt2/bt2/__init__.py.in b/bindings/python/bt2/bt2/__init__.py.in index da102f194..48668110f 100644 --- a/bindings/python/bt2/bt2/__init__.py.in +++ b/bindings/python/bt2/bt2/__init__.py.in @@ -43,8 +43,8 @@ from bt2.ctf_writer import * from bt2.ctf_writer import _CtfWriterStream from bt2.event import _Event from bt2.event_class import * -from bt2.field_types import * -from bt2.field_types import _FieldType +from bt2.field_class import * +from bt2.field_class import _FieldClass from bt2.fields import * from bt2.fields import _ArrayField from bt2.fields import _EnumerationField diff --git a/bindings/python/bt2/bt2/event_class.py b/bindings/python/bt2/bt2/event_class.py index b7a2c17e6..899a670b6 100644 --- a/bindings/python/bt2/bt2/event_class.py +++ b/bindings/python/bt2/bt2/event_class.py @@ -21,7 +21,7 @@ # THE SOFTWARE. from bt2 import native_bt, object, utils -import bt2.field_types +import bt2.field_class import collections.abc import bt2.values import bt2.event @@ -49,7 +49,7 @@ class EventClassLogLevel: class EventClass(object._Object): def __init__(self, name, id=None, log_level=None, emf_uri=None, - context_field_type=None, payload_field_type=None): + context_field_class=None, payload_field_class=None): utils._check_str(name) ptr = native_bt.event_class_create(name) @@ -67,11 +67,11 @@ class EventClass(object._Object): if emf_uri is not None: self.emf_uri = emf_uri - if context_field_type is not None: - self.context_field_type = context_field_type + if context_field_class is not None: + self.context_field_class = context_field_class - if payload_field_type is not None: - self.payload_field_type = payload_field_type + if payload_field_class is not None: + self.payload_field_class = payload_field_class @property def stream_class(self): @@ -138,44 +138,44 @@ class EventClass(object._Object): utils._handle_ret(ret, "cannot set event class object's EMF URI") @property - def context_field_type(self): - ft_ptr = native_bt.event_class_get_context_type(self._ptr) + def context_field_class(self): + fc_ptr = native_bt.event_class_get_context_type(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) + return bt2.field_class._create_from_ptr(fc_ptr) - @context_field_type.setter - def context_field_type(self, context_field_type): - context_field_type_ptr = None + @context_field_class.setter + def context_field_class(self, context_field_class): + context_field_class_ptr = None - if context_field_type is not None: - utils._check_type(context_field_type, bt2.field_types._FieldType) - context_field_type_ptr = context_field_type._ptr + if context_field_class is not None: + utils._check_type(context_field_class, bt2.field_class._FieldClass) + context_field_class_ptr = context_field_class._ptr - ret = native_bt.event_class_set_context_type(self._ptr, context_field_type_ptr) - utils._handle_ret(ret, "cannot set event class object's context field type") + ret = native_bt.event_class_set_context_type(self._ptr, context_field_class_ptr) + utils._handle_ret(ret, "cannot set event class object's context field class") @property - def payload_field_type(self): - ft_ptr = native_bt.event_class_get_payload_type(self._ptr) + def payload_field_class(self): + fc_ptr = native_bt.event_class_get_payload_type(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) + return bt2.field_class._create_from_ptr(fc_ptr) - @payload_field_type.setter - def payload_field_type(self, payload_field_type): - payload_field_type_ptr = None + @payload_field_class.setter + def payload_field_class(self, payload_field_class): + payload_field_class_ptr = None - if payload_field_type is not None: - utils._check_type(payload_field_type, bt2.field_types._FieldType) - payload_field_type_ptr = payload_field_type._ptr + if payload_field_class is not None: + utils._check_type(payload_field_class, bt2.field_class._FieldClass) + payload_field_class_ptr = payload_field_class._ptr - ret = native_bt.event_class_set_payload_type(self._ptr, payload_field_type_ptr) - utils._handle_ret(ret, "cannot set event class object's payload field type") + ret = native_bt.event_class_set_payload_type(self._ptr, payload_field_class_ptr) + utils._handle_ret(ret, "cannot set event class object's payload field class") def __call__(self): event_ptr = native_bt.event_create(self._ptr) @@ -197,20 +197,20 @@ class EventClass(object._Object): self.id, self.log_level, self.emf_uri, - self.context_field_type, - self.payload_field_type + self.context_field_class, + self.payload_field_class ) other_props = ( other.name, other.id, other.log_level, other.emf_uri, - other.context_field_type, - other.payload_field_type + other.context_field_class, + other.payload_field_class ) return self_props == other_props - def _copy(self, ft_copy_func): + def _copy(self, fc_copy_func): cpy = EventClass(self.name) cpy.id = self.id @@ -220,12 +220,12 @@ class EventClass(object._Object): if self.emf_uri is not None: cpy.emf_uri = self.emf_uri - cpy.context_field_type = ft_copy_func(self.context_field_type) - cpy.payload_field_type = ft_copy_func(self.payload_field_type) + cpy.context_field_class = fc_copy_func(self.context_field_class) + cpy.payload_field_class = fc_copy_func(self.payload_field_class) return cpy def __copy__(self): - return self._copy(lambda ft: ft) + return self._copy(lambda fc: fc) def __deepcopy__(self, memo): cpy = self._copy(copy.deepcopy) diff --git a/bindings/python/bt2/bt2/field_types.py b/bindings/python/bt2/bt2/field_class.py similarity index 57% rename from bindings/python/bt2/bt2/field_types.py rename to bindings/python/bt2/bt2/field_class.py index 27a3746bd..cd870ce85 100644 --- a/bindings/python/bt2/bt2/field_types.py +++ b/bindings/python/bt2/bt2/field_class.py @@ -28,11 +28,11 @@ import bt2 def _create_from_ptr(ptr): - typeid = native_bt.field_type_get_type_id(ptr) + typeid = native_bt.field_class_get_type_id(ptr) return _TYPE_ID_TO_OBJ[typeid]._create_from_ptr(ptr) -class _FieldType(object._Object, metaclass=abc.ABCMeta): +class _FieldClass(object._Object, metaclass=abc.ABCMeta): def __init__(self, ptr): super().__init__(ptr) @@ -44,17 +44,17 @@ class _FieldType(object._Object, metaclass=abc.ABCMeta): if self.addr == other.addr: return True - ret = native_bt.field_type_compare(self._ptr, other._ptr) - utils._handle_ret(ret, "cannot compare field types") + ret = native_bt.field_class_compare(self._ptr, other._ptr) + utils._handle_ret(ret, "cannot compare field classes") return ret == 0 def _check_create_status(self, ptr): if ptr is None: - raise bt2.CreationError('cannot create {} field type object'.format(self._NAME.lower())) + raise bt2.CreationError('cannot create {} field class object'.format(self._NAME.lower())) def __copy__(self): - ptr = native_bt.field_type_copy(self._ptr) - utils._handle_ptr(ptr, 'cannot copy {} field type object'.format(self._NAME.lower())) + ptr = native_bt.field_class_copy(self._ptr) + utils._handle_ptr(ptr, 'cannot copy {} field class object'.format(self._NAME.lower())) return _create_from_ptr(ptr) def __deepcopy__(self, memo): @@ -82,32 +82,32 @@ class _FieldType(object._Object, metaclass=abc.ABCMeta): class _AlignmentProp: @property def alignment(self): - alignment = native_bt.field_type_get_alignment(self._ptr) + alignment = native_bt.field_class_get_alignment(self._ptr) assert(alignment >= 0) return alignment @alignment.setter def alignment(self, alignment): utils._check_alignment(alignment) - ret = native_bt.field_type_set_alignment(self._ptr, alignment) - utils._handle_ret(ret, "cannot set field type object's alignment") + ret = native_bt.field_class_set_alignment(self._ptr, alignment) + utils._handle_ret(ret, "cannot set field class object's alignment") class _ByteOrderProp: @property def byte_order(self): - bo = native_bt.field_type_get_byte_order(self._ptr) + bo = native_bt.field_class_get_byte_order(self._ptr) assert(bo >= 0) return bo @byte_order.setter def byte_order(self, byte_order): utils._check_int(byte_order) - ret = native_bt.field_type_set_byte_order(self._ptr, byte_order) - utils._handle_ret(ret, "cannot set field type object's byte order") + ret = native_bt.field_class_set_byte_order(self._ptr, byte_order) + utils._handle_ret(ret, "cannot set field class object's byte order") -class IntegerFieldType(_FieldType, _AlignmentProp, _ByteOrderProp): +class IntegerFieldClass(_FieldClass, _AlignmentProp, _ByteOrderProp): _NAME = 'Integer' def __init__(self, size, alignment=None, byte_order=None, is_signed=None, @@ -117,7 +117,7 @@ class IntegerFieldType(_FieldType, _AlignmentProp, _ByteOrderProp): if size == 0: raise ValueError('size is 0 bits') - ptr = native_bt.field_type_integer_create(size) + ptr = native_bt.field_class_integer_create(size) self._check_create_status(ptr) super().__init__(ptr) @@ -141,49 +141,49 @@ class IntegerFieldType(_FieldType, _AlignmentProp, _ByteOrderProp): @property def size(self): - size = native_bt.field_type_integer_get_size(self._ptr) + size = native_bt.field_class_integer_get_size(self._ptr) assert(size >= 1) return size @property def is_signed(self): - is_signed = native_bt.field_type_integer_is_signed(self._ptr) + is_signed = native_bt.field_class_integer_is_signed(self._ptr) assert(is_signed >= 0) return is_signed > 0 @is_signed.setter def is_signed(self, is_signed): utils._check_bool(is_signed) - ret = native_bt.field_type_integer_set_is_signed(self._ptr, int(is_signed)) - utils._handle_ret(ret, "cannot set integer field type object's signedness") + ret = native_bt.field_class_integer_set_is_signed(self._ptr, int(is_signed)) + utils._handle_ret(ret, "cannot set integer field class object's signedness") @property def base(self): - base = native_bt.field_type_integer_get_base(self._ptr) + base = native_bt.field_class_integer_get_base(self._ptr) assert(base >= 0) return base @base.setter def base(self, base): utils._check_int(base) - ret = native_bt.field_type_integer_set_base(self._ptr, base) - utils._handle_ret(ret, "cannot set integer field type object's base") + ret = native_bt.field_class_integer_set_base(self._ptr, base) + utils._handle_ret(ret, "cannot set integer field class object's base") @property def encoding(self): - encoding = native_bt.field_type_integer_get_encoding(self._ptr) + encoding = native_bt.field_class_integer_get_encoding(self._ptr) assert(encoding >= 0) return encoding @encoding.setter def encoding(self, encoding): utils._check_int(encoding) - ret = native_bt.field_type_integer_set_encoding(self._ptr, encoding) - utils._handle_ret(ret, "cannot set integer field type object's encoding") + ret = native_bt.field_class_integer_set_encoding(self._ptr, encoding) + utils._handle_ret(ret, "cannot set integer field class object's encoding") @property def mapped_clock_class(self): - ptr = native_bt.field_type_integer_get_mapped_clock_class(self._ptr) + ptr = native_bt.field_class_integer_get_mapped_clock_class(self._ptr) if ptr is None: return @@ -193,16 +193,16 @@ class IntegerFieldType(_FieldType, _AlignmentProp, _ByteOrderProp): @mapped_clock_class.setter def mapped_clock_class(self, clock_class): utils._check_type(clock_class, bt2.ClockClass) - ret = native_bt.field_type_integer_set_mapped_clock_class(self._ptr, clock_class._ptr) - utils._handle_ret(ret, "cannot set integer field type object's mapped clock class") + ret = native_bt.field_class_integer_set_mapped_clock_class(self._ptr, clock_class._ptr) + utils._handle_ret(ret, "cannot set integer field class object's mapped clock class") -class FloatingPointNumberFieldType(_FieldType, _AlignmentProp, _ByteOrderProp): +class FloatingPointNumberFieldClass(_FieldClass, _AlignmentProp, _ByteOrderProp): _NAME = 'Floating point number' def __init__(self, alignment=None, byte_order=None, exponent_size=None, mantissa_size=None): - ptr = native_bt.field_type_floating_point_create() + ptr = native_bt.field_class_floating_point_create() self._check_create_status(ptr) super().__init__(ptr) @@ -220,30 +220,30 @@ class FloatingPointNumberFieldType(_FieldType, _AlignmentProp, _ByteOrderProp): @property def exponent_size(self): - exp_size = native_bt.field_type_floating_point_get_exponent_digits(self._ptr) + exp_size = native_bt.field_class_floating_point_get_exponent_digits(self._ptr) assert(exp_size >= 0) return exp_size @exponent_size.setter def exponent_size(self, exponent_size): utils._check_uint64(exponent_size) - ret = native_bt.field_type_floating_point_set_exponent_digits(self._ptr, exponent_size) - utils._handle_ret(ret, "cannot set floating point number field type object's exponent size") + ret = native_bt.field_class_floating_point_set_exponent_digits(self._ptr, exponent_size) + utils._handle_ret(ret, "cannot set floating point number field class object's exponent size") @property def mantissa_size(self): - mant_size = native_bt.field_type_floating_point_get_mantissa_digits(self._ptr) + mant_size = native_bt.field_class_floating_point_get_mantissa_digits(self._ptr) assert(mant_size >= 0) return mant_size @mantissa_size.setter def mantissa_size(self, mantissa_size): utils._check_uint64(mantissa_size) - ret = native_bt.field_type_floating_point_set_mantissa_digits(self._ptr, mantissa_size) - utils._handle_ret(ret, "cannot set floating point number field type object's mantissa size") + ret = native_bt.field_class_floating_point_set_mantissa_digits(self._ptr, mantissa_size) + utils._handle_ret(ret, "cannot set floating point number field class object's mantissa size") -class _EnumerationFieldTypeMapping: +class _EnumerationFieldClassMapping: def __init__(self, name, lower, upper): self._name = name self._lower = lower @@ -268,7 +268,7 @@ class _EnumerationFieldTypeMapping: return (self.name, self.lower, self.upper) == (other.name, other.lower, other.upper) -class _EnumerationFieldTypeMappingIterator(object._Object, +class _EnumerationFieldClassMappingIterator(object._Object, collections.abc.Iterator): def __init__(self, iter_ptr, is_signed): super().__init__(iter_ptr) @@ -279,100 +279,100 @@ class _EnumerationFieldTypeMappingIterator(object._Object, if self._done: raise StopIteration - ret = native_bt.field_type_enumeration_mapping_iterator_next(self._ptr) + ret = native_bt.field_class_enumeration_mapping_iterator_next(self._ptr) if ret < 0: self._done = True raise StopIteration if self._is_signed: - ret, name, lower, upper = native_bt.field_type_enumeration_mapping_iterator_get_signed(self._ptr) + ret, name, lower, upper = native_bt.field_class_enumeration_mapping_iterator_get_signed(self._ptr) else: - ret, name, lower, upper = native_bt.field_type_enumeration_mapping_iterator_get_unsigned(self._ptr) + ret, name, lower, upper = native_bt.field_class_enumeration_mapping_iterator_get_unsigned(self._ptr) assert(ret == 0) - mapping = _EnumerationFieldTypeMapping(name, lower, upper) + mapping = _EnumerationFieldClassMapping(name, lower, upper) return mapping -class EnumerationFieldType(IntegerFieldType, collections.abc.Sequence): +class EnumerationFieldClass(IntegerFieldClass, collections.abc.Sequence): _NAME = 'Enumeration' - def __init__(self, int_field_type=None, size=None, alignment=None, + def __init__(self, int_field_class=None, size=None, alignment=None, byte_order=None, is_signed=None, base=None, encoding=None, mapped_clock_class=None): - if int_field_type is None: - int_field_type = IntegerFieldType(size=size, alignment=alignment, + if int_field_class is None: + int_field_class = IntegerFieldClass(size=size, alignment=alignment, byte_order=byte_order, is_signed=is_signed, base=base, encoding=encoding, mapped_clock_class=mapped_clock_class) - utils._check_type(int_field_type, IntegerFieldType) - ptr = native_bt.field_type_enumeration_create(int_field_type._ptr) + utils._check_type(int_field_class, IntegerFieldClass) + ptr = native_bt.field_class_enumeration_create(int_field_class._ptr) self._check_create_status(ptr) - _FieldType.__init__(self, ptr) + _FieldClass.__init__(self, ptr) @property - def integer_field_type(self): - ptr = native_bt.field_type_enumeration_get_container_type(self._ptr) + def integer_field_class(self): + ptr = native_bt.field_class_enumeration_get_container_type(self._ptr) assert(ptr) return _create_from_ptr(ptr) @property def size(self): - return self.integer_field_type.size + return self.integer_field_class.size @property def alignment(self): - return self.integer_field_type.alignment + return self.integer_field_class.alignment @alignment.setter def alignment(self, alignment): - self.integer_field_type.alignment = alignment + self.integer_field_class.alignment = alignment @property def byte_order(self): - return self.integer_field_type.byte_order + return self.integer_field_class.byte_order @byte_order.setter def byte_order(self, byte_order): - self.integer_field_type.byte_order = byte_order + self.integer_field_class.byte_order = byte_order @property def is_signed(self): - return self.integer_field_type.is_signed + return self.integer_field_class.is_signed @is_signed.setter def is_signed(self, is_signed): - self.integer_field_type.is_signed = is_signed + self.integer_field_class.is_signed = is_signed @property def base(self): - return self.integer_field_type.base + return self.integer_field_class.base @base.setter def base(self, base): - self.integer_field_type.base = base + self.integer_field_class.base = base @property def encoding(self): - return self.integer_field_type.encoding + return self.integer_field_class.encoding @encoding.setter def encoding(self, encoding): - self.integer_field_type.encoding = encoding + self.integer_field_class.encoding = encoding @property def mapped_clock_class(self): - return self.integer_field_type.mapped_clock_class + return self.integer_field_class.mapped_clock_class @mapped_clock_class.setter def mapped_clock_class(self, mapped_clock_class): - self.integer_field_type.mapped_clock_class = mapped_clock_class + self.integer_field_class.mapped_clock_class = mapped_clock_class def __len__(self): - count = native_bt.field_type_enumeration_get_mapping_count(self._ptr) + count = native_bt.field_class_enumeration_get_mapping_count(self._ptr) assert(count >= 0) return count @@ -383,30 +383,30 @@ class EnumerationFieldType(IntegerFieldType, collections.abc.Sequence): raise IndexError if self.is_signed: - get_fn = native_bt.field_type_enumeration_get_mapping_signed + get_fn = native_bt.field_class_enumeration_get_mapping_signed else: - get_fn = native_bt.field_type_enumeration_get_mapping_unsigned + get_fn = native_bt.field_class_enumeration_get_mapping_unsigned ret, name, lower, upper = get_fn(self._ptr, index) assert(ret == 0) - return _EnumerationFieldTypeMapping(name, lower, upper) + return _EnumerationFieldClassMapping(name, lower, upper) def _get_mapping_iter(self, iter_ptr): - return _EnumerationFieldTypeMappingIterator(iter_ptr, self.is_signed) + return _EnumerationFieldClassMappingIterator(iter_ptr, self.is_signed) def mappings_by_name(self, name): utils._check_str(name) - iter_ptr = native_bt.field_type_enumeration_find_mappings_by_name(self._ptr, name) + iter_ptr = native_bt.field_class_enumeration_find_mappings_by_name(self._ptr, name) print('iter_ptr', iter_ptr) return self._get_mapping_iter(iter_ptr) def mappings_by_value(self, value): if self.is_signed: utils._check_int64(value) - iter_ptr = native_bt.field_type_enumeration_find_mappings_by_signed_value(self._ptr, value) + iter_ptr = native_bt.field_class_enumeration_find_mappings_by_signed_value(self._ptr, value) else: utils._check_uint64(value) - iter_ptr = native_bt.field_type_enumeration_find_mappings_by_unsigned_value(self._ptr, value) + iter_ptr = native_bt.field_class_enumeration_find_mappings_by_unsigned_value(self._ptr, value) return self._get_mapping_iter(iter_ptr) @@ -417,16 +417,16 @@ class EnumerationFieldType(IntegerFieldType, collections.abc.Sequence): upper = lower if self.is_signed: - add_fn = native_bt.field_type_enumeration_add_mapping_signed + add_fn = native_bt.field_class_enumeration_add_mapping_signed utils._check_int64(lower) utils._check_int64(upper) else: - add_fn = native_bt.field_type_enumeration_add_mapping_unsigned + add_fn = native_bt.field_class_enumeration_add_mapping_unsigned utils._check_uint64(lower) utils._check_uint64(upper) ret = add_fn(self._ptr, name, lower, upper) - utils._handle_ret(ret, "cannot add mapping to enumeration field type object") + utils._handle_ret(ret, "cannot add mapping to enumeration field class object") def __iadd__(self, mappings): for mapping in mappings: @@ -435,11 +435,11 @@ class EnumerationFieldType(IntegerFieldType, collections.abc.Sequence): return self -class StringFieldType(_FieldType): +class StringFieldClass(_FieldClass): _NAME = 'String' def __init__(self, encoding=None): - ptr = native_bt.field_type_string_create() + ptr = native_bt.field_class_string_create() self._check_create_status(ptr) super().__init__(ptr) @@ -448,15 +448,15 @@ class StringFieldType(_FieldType): @property def encoding(self): - encoding = native_bt.field_type_string_get_encoding(self._ptr) + encoding = native_bt.field_class_string_get_encoding(self._ptr) assert(encoding >= 0) return encoding @encoding.setter def encoding(self, encoding): utils._check_int(encoding) - ret = native_bt.field_type_string_set_encoding(self._ptr, encoding) - utils._handle_ret(ret, "cannot set string field type object's encoding") + ret = native_bt.field_class_string_set_encoding(self._ptr, encoding) + utils._handle_ret(ret, "cannot set string field class object's encoding") class _FieldContainer(collections.abc.Mapping): @@ -479,15 +479,15 @@ class _FieldContainer(collections.abc.Mapping): def __iter__(self): return self._ITER_CLS(self) - def append_field(self, name, field_type): + def append_field(self, name, field_class): utils._check_str(name) - utils._check_type(field_type, _FieldType) - ret = self._add_field(field_type._ptr, name) - utils._handle_ret(ret, "cannot add field to {} field type object".format(self._NAME.lower())) + utils._check_type(field_class, _FieldClass) + ret = self._add_field(field_class._ptr, name) + utils._handle_ret(ret, "cannot add field to {} field class object".format(self._NAME.lower())) def __iadd__(self, fields): - for name, field_type in fields.items(): - self.append_field(name, field_type) + for name, field_class in fields.items(): + self.append_field(name, field_class) return self @@ -496,30 +496,30 @@ class _FieldContainer(collections.abc.Mapping): return self._at(index) -class _StructureFieldTypeFieldIterator(collections.abc.Iterator): - def __init__(self, struct_field_type): - self._struct_field_type = struct_field_type +class _StructureFieldClassFieldIterator(collections.abc.Iterator): + def __init__(self, struct_field_class): + self._struct_field_class = struct_field_class self._at = 0 def __next__(self): - if self._at == len(self._struct_field_type): + if self._at == len(self._struct_field_class): raise StopIteration - get_ft_by_index = native_bt.field_type_structure_get_field_by_index - ret, name, field_type_ptr = get_ft_by_index(self._struct_field_type._ptr, + get_fc_by_index = native_bt.field_class_structure_get_field_by_index + ret, name, field_class_ptr = get_fc_by_index(self._struct_field_class._ptr, self._at) assert(ret == 0) - native_bt.put(field_type_ptr) + native_bt.put(field_class_ptr) self._at += 1 return name -class StructureFieldType(_FieldType, _FieldContainer, _AlignmentProp): +class StructureFieldClass(_FieldClass, _FieldContainer, _AlignmentProp): _NAME = 'Structure' - _ITER_CLS = _StructureFieldTypeFieldIterator + _ITER_CLS = _StructureFieldClassFieldIterator def __init__(self, min_alignment=None): - ptr = native_bt.field_type_structure_create() + ptr = native_bt.field_class_structure_create() self._check_create_status(ptr) super().__init__(ptr) @@ -527,145 +527,145 @@ class StructureFieldType(_FieldType, _FieldContainer, _AlignmentProp): self.min_alignment = min_alignment def _count(self): - return native_bt.field_type_structure_get_field_count(self._ptr) + return native_bt.field_class_structure_get_field_count(self._ptr) def _get_field_by_name(self, key): - return native_bt.field_type_structure_get_field_type_by_name(self._ptr, key) + return native_bt.field_class_structure_get_field_class_by_name(self._ptr, key) def _add_field(self, ptr, name): - return native_bt.field_type_structure_add_field(self._ptr, ptr, + return native_bt.field_class_structure_add_field(self._ptr, ptr, name) def _at(self, index): if index < 0 or index >= len(self): raise IndexError - ret, name, field_type_ptr = native_bt.field_type_structure_get_field_by_index(self._ptr, index) + ret, name, field_class_ptr = native_bt.field_class_structure_get_field_by_index(self._ptr, index) assert(ret == 0) - return _create_from_ptr(field_type_ptr) + return _create_from_ptr(field_class_ptr) -StructureFieldType.min_alignment = property(fset=StructureFieldType.alignment.fset) -StructureFieldType.alignment = property(fget=StructureFieldType.alignment.fget) +StructureFieldClass.min_alignment = property(fset=StructureFieldClass.alignment.fset) +StructureFieldClass.alignment = property(fget=StructureFieldClass.alignment.fget) -class _VariantFieldTypeFieldIterator(collections.abc.Iterator): - def __init__(self, variant_field_type): - self._variant_field_type = variant_field_type +class _VariantFieldClassFieldIterator(collections.abc.Iterator): + def __init__(self, variant_field_class): + self._variant_field_class = variant_field_class self._at = 0 def __next__(self): - if self._at == len(self._variant_field_type): + if self._at == len(self._variant_field_class): raise StopIteration - ret, name, field_type_ptr = native_bt.field_type_variant_get_field_by_index(self._variant_field_type._ptr, + ret, name, field_class_ptr = native_bt.field_class_variant_get_field_by_index(self._variant_field_class._ptr, self._at) assert(ret == 0) - native_bt.put(field_type_ptr) + native_bt.put(field_class_ptr) self._at += 1 return name -class VariantFieldType(_FieldType, _FieldContainer, _AlignmentProp): +class VariantFieldClass(_FieldClass, _FieldContainer, _AlignmentProp): _NAME = 'Variant' - _ITER_CLS = _VariantFieldTypeFieldIterator + _ITER_CLS = _VariantFieldClassFieldIterator - def __init__(self, tag_name, tag_field_type=None): + def __init__(self, tag_name, tag_field_class=None): utils._check_str(tag_name) - if tag_field_type is None: - tag_ft_ptr = None + if tag_field_class is None: + tag_fc_ptr = None else: - utils._check_type(tag_field_type, EnumerationFieldType) - tag_ft_ptr = tag_field_type._ptr + utils._check_type(tag_field_class, EnumerationFieldClass) + tag_fc_ptr = tag_field_class._ptr - ptr = native_bt.field_type_variant_create(tag_ft_ptr, + ptr = native_bt.field_class_variant_create(tag_fc_ptr, tag_name) self._check_create_status(ptr) super().__init__(ptr) @property def tag_name(self): - tag_name = native_bt.field_type_variant_get_tag_name(self._ptr) + tag_name = native_bt.field_class_variant_get_tag_name(self._ptr) assert(tag_name is not None) return tag_name @tag_name.setter def tag_name(self, tag_name): utils._check_str(tag_name) - ret = native_bt.field_type_variant_set_tag_name(self._ptr, tag_name) - utils._handle_ret(ret, "cannot set variant field type object's tag name") + ret = native_bt.field_class_variant_set_tag_name(self._ptr, tag_name) + utils._handle_ret(ret, "cannot set variant field class object's tag name") @property - def tag_field_type(self): - ft_ptr = native_bt.field_type_variant_get_tag_type(self._ptr) + def tag_field_class(self): + fc_ptr = native_bt.field_class_variant_get_tag_type(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return _create_from_ptr(ft_ptr) + return _create_from_ptr(fc_ptr) def _count(self): - return native_bt.field_type_variant_get_field_count(self._ptr) + return native_bt.field_class_variant_get_field_count(self._ptr) def _get_field_by_name(self, key): - return native_bt.field_type_variant_get_field_type_by_name(self._ptr, key) + return native_bt.field_class_variant_get_field_class_by_name(self._ptr, key) def _add_field(self, ptr, name): - return native_bt.field_type_variant_add_field(self._ptr, ptr, name) + return native_bt.field_class_variant_add_field(self._ptr, ptr, name) def _at(self, index): if index < 0 or index >= len(self): raise IndexError - ret, name, field_type_ptr = native_bt.field_type_variant_get_field_by_index(self._ptr, index) + ret, name, field_class_ptr = native_bt.field_class_variant_get_field_by_index(self._ptr, index) assert(ret == 0) - return _create_from_ptr(field_type_ptr) + return _create_from_ptr(field_class_ptr) -class ArrayFieldType(_FieldType): +class ArrayFieldClass(_FieldClass): _NAME = 'Array' - def __init__(self, element_field_type, length): - utils._check_type(element_field_type, _FieldType) + def __init__(self, element_field_class, length): + utils._check_type(element_field_class, _FieldClass) utils._check_uint64(length) - ptr = native_bt.field_type_array_create(element_field_type._ptr, length) + ptr = native_bt.field_class_array_create(element_field_class._ptr, length) self._check_create_status(ptr) super().__init__(ptr) @property def length(self): - length = native_bt.field_type_array_get_length(self._ptr) + length = native_bt.field_class_array_get_length(self._ptr) assert(length >= 0) return length @property - def element_field_type(self): - ptr = native_bt.field_type_array_get_element_type(self._ptr) + def element_field_class(self): + ptr = native_bt.field_class_array_get_element_type(self._ptr) assert(ptr) return _create_from_ptr(ptr) -class SequenceFieldType(_FieldType): +class SequenceFieldClass(_FieldClass): _NAME = 'Sequence' - def __init__(self, element_field_type, length_name): - utils._check_type(element_field_type, _FieldType) + def __init__(self, element_field_class, length_name): + utils._check_type(element_field_class, _FieldClass) utils._check_str(length_name) - ptr = native_bt.field_type_sequence_create(element_field_type._ptr, + ptr = native_bt.field_class_sequence_create(element_field_class._ptr, length_name) self._check_create_status(ptr) super().__init__(ptr) @property def length_name(self): - length_name = native_bt.field_type_sequence_get_length_field_name(self._ptr) + length_name = native_bt.field_class_sequence_get_length_field_name(self._ptr) assert(length_name is not None) return length_name @property - def element_field_type(self): - ptr = native_bt.field_type_sequence_get_element_type(self._ptr) + def element_field_class(self): + ptr = native_bt.field_class_sequence_get_element_type(self._ptr) assert(ptr) return _create_from_ptr(ptr) diff --git a/bindings/python/bt2/bt2/fields.py b/bindings/python/bt2/bt2/fields.py index 9871bce88..77c5803dd 100644 --- a/bindings/python/bt2/bt2/fields.py +++ b/bindings/python/bt2/bt2/fields.py @@ -21,7 +21,7 @@ # THE SOFTWARE. from bt2 import native_bt, object, utils -import bt2.field_types +import bt2.field_class import collections.abc import functools import numbers @@ -38,15 +38,15 @@ def _get_leaf_field(obj): def _create_from_ptr(ptr): - # recreate the field type wrapper of this field's type (the identity + # recreate the field class wrapper of this field's type (the identity # could be different, but the underlying address should be the # same) - field_type_ptr = native_bt.field_get_type(ptr) - utils._handle_ptr(field_type_ptr, "cannot get field object's type") - field_type = bt2.field_types._create_from_ptr(field_type_ptr) - typeid = native_bt.field_type_get_type_id(field_type._ptr) + field_class_ptr = native_bt.field_get_type(ptr) + utils._handle_ptr(field_class_ptr, "cannot get field object's type") + field_class = bt2.field_class._create_from_ptr(field_class_ptr) + typeid = native_bt.field_class_get_type_id(field_class._ptr) field = _TYPE_ID_TO_OBJ[typeid]._create_from_ptr(ptr) - field._field_type = field_type + field._field_class = field_class return field @@ -62,10 +62,10 @@ class _Field(object._Object, metaclass=abc.ABCMeta): return cpy def __eq__(self, other): - # special case: two unset fields with the same field type are equal + # special case: two unset fields with the same field class are equal if isinstance(other, _Field): if not self.is_set or not other.is_set: - if not self.is_set and not other.is_set and self.field_type == other.field_type: + if not self.is_set and not other.is_set and self.field_class == other.field_class: return True return False @@ -73,8 +73,8 @@ class _Field(object._Object, metaclass=abc.ABCMeta): return self._spec_eq(other) @property - def field_type(self): - return self._field_type + def field_class(self): + return self._field_class @property def is_set(self): @@ -296,7 +296,7 @@ class _IntegerField(_IntegralField): value = int(value) - if self.field_type.is_signed: + if self.field_class.is_signed: utils._check_int64(value) else: utils._check_uint64(value) @@ -305,7 +305,7 @@ class _IntegerField(_IntegralField): @property def _value(self): - if self.field_type.is_signed: + if self.field_class.is_signed: ret, value = native_bt.field_signed_integer_get_value(self._ptr) else: ret, value = native_bt.field_unsigned_integer_get_value(self._ptr) @@ -321,7 +321,7 @@ class _IntegerField(_IntegralField): def _set_value(self, value): value = self._value_to_int(value) - if self.field_type.is_signed: + if self.field_class.is_signed: ret = native_bt.field_signed_integer_set_value(self._ptr, value) else: ret = native_bt.field_unsigned_integer_set_value(self._ptr, value) @@ -386,8 +386,8 @@ class _EnumerationField(_IntegerField): def mappings(self): iter_ptr = native_bt.field_enumeration_get_mappings(self._ptr) assert(iter_ptr) - return bt2.field_types._EnumerationFieldTypeMappingIterator(iter_ptr, - self.field_type.is_signed) + return bt2.field_class._EnumerationFieldClassMappingIterator(iter_ptr, + self.field_class.is_signed) @functools.total_ordering @@ -468,7 +468,7 @@ class _StructureField(_ContainerField, collections.abc.MutableMapping): _NAME = 'Structure' def _count(self): - return len(self.field_type) + return len(self.field_class) def __getitem__(self, key): utils._check_str(key) @@ -499,7 +499,7 @@ class _StructureField(_ContainerField, collections.abc.MutableMapping): def __iter__(self): # same name iterator - return iter(self.field_type) + return iter(self.field_class) def _spec_eq(self, other): try: @@ -649,7 +649,7 @@ class _ArrayField(_ArraySequenceField): _NAME = 'Array' def _count(self): - return self.field_type.length + return self.field_class.length def _get_field_ptr_at_index(self, index): return native_bt.field_array_get_field(self._ptr, index) @@ -702,10 +702,10 @@ class _SequenceField(_ArraySequenceField): if len(values) != self.length_field: if self.length_field is not None: - length_ft = self.length_field.field_type + length_fc = self.length_field.field_class else: - length_ft = bt2.IntegerFieldType(size=64, is_signed=False) - self.length_field = length_ft(len(values)) + length_fc = bt2.IntegerFieldClass(size=64, is_signed=False) + self.length_field = length_fc(len(values)) try: for index, value in enumerate(values): diff --git a/bindings/python/bt2/bt2/stream_class.py b/bindings/python/bt2/bt2/stream_class.py index 514dfbb20..9c12a4082 100644 --- a/bindings/python/bt2/bt2/stream_class.py +++ b/bindings/python/bt2/bt2/stream_class.py @@ -21,7 +21,7 @@ # THE SOFTWARE. from bt2 import native_bt, object, utils -import bt2.field_types +import bt2.field_class import collections.abc import bt2.ctf_writer import bt2.stream @@ -49,8 +49,8 @@ class _EventClassIterator(collections.abc.Iterator): class StreamClass(object._Object, collections.abc.Mapping): - def __init__(self, name=None, id=None, packet_context_field_type=None, - event_header_field_type=None, event_context_field_type=None, + def __init__(self, name=None, id=None, packet_context_field_class=None, + event_header_field_class=None, event_context_field_class=None, event_classes=None): ptr = native_bt.stream_class_create_empty(None) @@ -65,14 +65,14 @@ class StreamClass(object._Object, collections.abc.Mapping): if id is not None: self.id = id - if packet_context_field_type is not None: - self.packet_context_field_type = packet_context_field_type + if packet_context_field_class is not None: + self.packet_context_field_class = packet_context_field_class - if event_header_field_type is not None: - self.event_header_field_type = event_header_field_type + if event_header_field_class is not None: + self.event_header_field_class = event_header_field_class - if event_context_field_type is not None: - self.event_context_field_type = event_context_field_type + if event_context_field_class is not None: + self.event_context_field_class = event_context_field_class if event_classes is not None: for event_class in event_classes: @@ -149,67 +149,67 @@ class StreamClass(object._Object, collections.abc.Mapping): utils._handle_ret(ret, "cannot set stream class object's CTF writer clock object") @property - def packet_context_field_type(self): - ft_ptr = native_bt.stream_class_get_packet_context_type(self._ptr) + def packet_context_field_class(self): + fc_ptr = native_bt.stream_class_get_packet_context_type(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) + return bt2.field_class._create_from_ptr(fc_ptr) - @packet_context_field_type.setter - def packet_context_field_type(self, packet_context_field_type): - packet_context_field_type_ptr = None + @packet_context_field_class.setter + def packet_context_field_class(self, packet_context_field_class): + packet_context_field_class_ptr = None - if packet_context_field_type is not None: - utils._check_type(packet_context_field_type, bt2.field_types._FieldType) - packet_context_field_type_ptr = packet_context_field_type._ptr + if packet_context_field_class is not None: + utils._check_type(packet_context_field_class, bt2.field_class._FieldClass) + packet_context_field_class_ptr = packet_context_field_class._ptr ret = native_bt.stream_class_set_packet_context_type(self._ptr, - packet_context_field_type_ptr) - utils._handle_ret(ret, "cannot set stream class object's packet context field type") + packet_context_field_class_ptr) + utils._handle_ret(ret, "cannot set stream class object's packet context field class") @property - def event_header_field_type(self): - ft_ptr = native_bt.stream_class_get_event_header_type(self._ptr) + def event_header_field_class(self): + fc_ptr = native_bt.stream_class_get_event_header_type(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) + return bt2.field_class._create_from_ptr(fc_ptr) - @event_header_field_type.setter - def event_header_field_type(self, event_header_field_type): - event_header_field_type_ptr = None + @event_header_field_class.setter + def event_header_field_class(self, event_header_field_class): + event_header_field_class_ptr = None - if event_header_field_type is not None: - utils._check_type(event_header_field_type, bt2.field_types._FieldType) - event_header_field_type_ptr = event_header_field_type._ptr + if event_header_field_class is not None: + utils._check_type(event_header_field_class, bt2.field_class._FieldClass) + event_header_field_class_ptr = event_header_field_class._ptr ret = native_bt.stream_class_set_event_header_type(self._ptr, - event_header_field_type_ptr) - utils._handle_ret(ret, "cannot set stream class object's event header field type") + event_header_field_class_ptr) + utils._handle_ret(ret, "cannot set stream class object's event header field class") @property - def event_context_field_type(self): - ft_ptr = native_bt.stream_class_get_event_context_type(self._ptr) + def event_context_field_class(self): + fc_ptr = native_bt.stream_class_get_event_context_type(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) + return bt2.field_class._create_from_ptr(fc_ptr) - @event_context_field_type.setter - def event_context_field_type(self, event_context_field_type): - event_context_field_type_ptr = None + @event_context_field_class.setter + def event_context_field_class(self, event_context_field_class): + event_context_field_class_ptr = None - if event_context_field_type is not None: - utils._check_type(event_context_field_type, bt2.field_types._FieldType) - event_context_field_type_ptr = event_context_field_type._ptr + if event_context_field_class is not None: + utils._check_type(event_context_field_class, bt2.field_class._FieldClass) + event_context_field_class_ptr = event_context_field_class._ptr ret = native_bt.stream_class_set_event_context_type(self._ptr, - event_context_field_type_ptr) - utils._handle_ret(ret, "cannot set stream class object's event context field type") + event_context_field_class_ptr) + utils._handle_ret(ret, "cannot set stream class object's event context field class") def __call__(self, name=None, id=None): if name is not None: @@ -238,24 +238,24 @@ class StreamClass(object._Object, collections.abc.Mapping): self_event_classes, self.name, self.id, - self.packet_context_field_type, - self.event_header_field_type, - self.event_context_field_type, + self.packet_context_field_class, + self.event_header_field_class, + self.event_context_field_class, self.clock, ) other_props = ( other_event_classes, other.name, other.id, - other.packet_context_field_type, - other.event_header_field_type, - other.event_context_field_type, + other.packet_context_field_class, + other.event_header_field_class, + other.event_context_field_class, other.clock, ) return self_props == other_props - def _copy(self, ft_copy_func, ev_copy_func): + def _copy(self, fc_copy_func, ev_copy_func): cpy = StreamClass() if self.id is not None: @@ -267,9 +267,9 @@ class StreamClass(object._Object, collections.abc.Mapping): if self.clock is not None: cpy.clock = self.clock - cpy.packet_context_field_type = ft_copy_func(self.packet_context_field_type) - cpy.event_header_field_type = ft_copy_func(self.event_header_field_type) - cpy.event_context_field_type = ft_copy_func(self.event_context_field_type) + cpy.packet_context_field_class = fc_copy_func(self.packet_context_field_class) + cpy.event_header_field_class = fc_copy_func(self.event_header_field_class) + cpy.event_context_field_class = fc_copy_func(self.event_context_field_class) for event_class in self.values(): cpy.add_event_class(ev_copy_func(event_class)) @@ -277,7 +277,7 @@ class StreamClass(object._Object, collections.abc.Mapping): return cpy def __copy__(self): - return self._copy(lambda ft: ft, copy.copy) + return self._copy(lambda fc: fc, copy.copy) def __deepcopy__(self, memo): cpy = self._copy(copy.deepcopy, copy.deepcopy) diff --git a/bindings/python/bt2/bt2/trace.py b/bindings/python/bt2/bt2/trace.py index cd0cd14b9..31548d6b2 100644 --- a/bindings/python/bt2/bt2/trace.py +++ b/bindings/python/bt2/bt2/trace.py @@ -21,7 +21,7 @@ # THE SOFTWARE. from bt2 import native_bt, object, utils -import bt2.field_types +import bt2.field_class import collections.abc import bt2.values import bt2.stream @@ -162,7 +162,7 @@ class _TraceEnv(collections.abc.MutableMapping): class Trace(object._Object, collections.abc.Mapping): def __init__(self, name=None, native_byte_order=None, env=None, - packet_header_field_type=None, clock_classes=None, + packet_header_field_class=None, clock_classes=None, stream_classes=None): ptr = native_bt.trace_create() @@ -177,8 +177,8 @@ class Trace(object._Object, collections.abc.Mapping): if native_byte_order is not None: self.native_byte_order = native_byte_order - if packet_header_field_type is not None: - self.packet_header_field_type = packet_header_field_type + if packet_header_field_class is not None: + self.packet_header_field_class = packet_header_field_class if env is not None: for key, value in env.items(): @@ -263,25 +263,25 @@ class Trace(object._Object, collections.abc.Mapping): return _TraceStreams(self) @property - def packet_header_field_type(self): - ft_ptr = native_bt.trace_get_packet_header_type(self._ptr) + def packet_header_field_class(self): + fc_ptr = native_bt.trace_get_packet_header_type(self._ptr) - if ft_ptr is None: + if fc_ptr is None: return - return bt2.field_types._create_from_ptr(ft_ptr) + return bt2.field_class._create_from_ptr(fc_ptr) - @packet_header_field_type.setter - def packet_header_field_type(self, packet_header_field_type): - packet_header_field_type_ptr = None + @packet_header_field_class.setter + def packet_header_field_class(self, packet_header_field_class): + packet_header_field_class_ptr = None - if packet_header_field_type is not None: - utils._check_type(packet_header_field_type, bt2.field_types._FieldType) - packet_header_field_type_ptr = packet_header_field_type._ptr + if packet_header_field_class is not None: + utils._check_type(packet_header_field_class, bt2.field_class._FieldClass) + packet_header_field_class_ptr = packet_header_field_class._ptr ret = native_bt.trace_set_packet_header_type(self._ptr, - packet_header_field_type_ptr) - utils._handle_ret(ret, "cannot set trace class object's packet header field type") + packet_header_field_class_ptr) + utils._handle_ret(ret, "cannot set trace class object's packet header field class") def __eq__(self, other): if type(other) is not type(self): @@ -303,7 +303,7 @@ class Trace(object._Object, collections.abc.Mapping): self_env, self.name, self.native_byte_order, - self.packet_header_field_type, + self.packet_header_field_class, ) other_props = ( other_stream_classes, @@ -311,7 +311,7 @@ class Trace(object._Object, collections.abc.Mapping): other_env, other.name, other.native_byte_order, - other.packet_header_field_type, + other.packet_header_field_class, ) return self_props == other_props @@ -321,7 +321,7 @@ class Trace(object._Object, collections.abc.Mapping): if self.name is not None: cpy.name = self.name - cpy.packet_header_field_type = gen_copy_func(self.packet_header_field_type) + cpy.packet_header_field_class = gen_copy_func(self.packet_header_field_class) for key, val in self.env.items(): cpy.env[key] = gen_copy_func(val) diff --git a/tests/bindings/python/bt2/Makefile.am b/tests/bindings/python/bt2/Makefile.am index ad74e25b6..bda53f93d 100644 --- a/tests/bindings/python/bt2/Makefile.am +++ b/tests/bindings/python/bt2/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ test_ctf_writer_clock.py \ test_event.py \ test_event_class.py \ - test_field_types.py \ + test_field_class.py \ test_fields.py \ test_graph.py \ test_message.py \ diff --git a/tests/bindings/python/bt2/test_event.py b/tests/bindings/python/bt2/test_event.py index 6cef201ee..09fa97660 100644 --- a/tests/bindings/python/bt2/test_event.py +++ b/tests/bindings/python/bt2/test_event.py @@ -16,62 +16,62 @@ class EventTestCase(unittest.TestCase): def _create_ec(self, with_eh=True, with_sec=True, with_ec=True, with_ep=True): # event header if with_eh: - eh = bt2.StructureFieldType() + eh = bt2.StructureFieldClass() eh += OrderedDict(( - ('id', bt2.IntegerFieldType(8)), - ('ts', bt2.IntegerFieldType(32)), + ('id', bt2.IntegerFieldClass(8)), + ('ts', bt2.IntegerFieldClass(32)), )) else: eh = None # stream event context if with_sec: - sec = bt2.StructureFieldType() + sec = bt2.StructureFieldClass() sec += OrderedDict(( - ('cpu_id', bt2.IntegerFieldType(8)), - ('stuff', bt2.FloatingPointNumberFieldType()), + ('cpu_id', bt2.IntegerFieldClass(8)), + ('stuff', bt2.FloatingPointNumberFieldClass()), )) else: sec = None # packet context - pc = bt2.StructureFieldType() + pc = bt2.StructureFieldClass() pc += OrderedDict(( - ('something', bt2.IntegerFieldType(8)), - ('something_else', bt2.FloatingPointNumberFieldType()), + ('something', bt2.IntegerFieldClass(8)), + ('something_else', bt2.FloatingPointNumberFieldClass()), )) # stream class sc = bt2.StreamClass() - sc.packet_context_field_type = pc - sc.event_header_field_type = eh - sc.event_context_field_type = sec + sc.packet_context_field_class = pc + sc.event_header_field_class = eh + sc.event_context_field_class = sec # event context if with_ec: - ec = bt2.StructureFieldType() + ec = bt2.StructureFieldClass() ec += OrderedDict(( - ('ant', bt2.IntegerFieldType(16, is_signed=True)), - ('msg', bt2.StringFieldType()), + ('ant', bt2.IntegerFieldClass(16, is_signed=True)), + ('msg', bt2.StringFieldClass()), )) else: ec = None # event payload if with_ep: - ep = bt2.StructureFieldType() + ep = bt2.StructureFieldClass() ep += OrderedDict(( - ('giraffe', bt2.IntegerFieldType(32)), - ('gnu', bt2.IntegerFieldType(8)), - ('mosquito', bt2.IntegerFieldType(8)), + ('giraffe', bt2.IntegerFieldClass(32)), + ('gnu', bt2.IntegerFieldClass(8)), + ('mosquito', bt2.IntegerFieldClass(8)), )) else: ep = None # event class event_class = bt2.EventClass('ec') - event_class.context_field_type = ec - event_class.payload_field_type = ep + event_class.context_field_class = ec + event_class.payload_field_class = ep sc.add_event_class(event_class) return event_class @@ -95,7 +95,7 @@ class EventTestCase(unittest.TestCase): self.assertEqual(ev.header_field['ts'], 1234) def test_set_event_header_field(self): - eh = self._ec.stream_class.event_header_field_type() + eh = self._ec.stream_class.event_header_field_class() eh['id'] = 17 eh['ts'] = 188 ev = self._ec() @@ -111,7 +111,7 @@ class EventTestCase(unittest.TestCase): self.assertEqual(ev.stream_event_context_field['stuff'], 13.194) def test_set_stream_event_context_field(self): - sec = self._ec.stream_class.event_context_field_type() + sec = self._ec.stream_class.event_context_field_class() sec['cpu_id'] = 2 sec['stuff'] = 19.19 ev = self._ec() @@ -132,7 +132,7 @@ class EventTestCase(unittest.TestCase): self.assertEqual(ev.context_field['msg'], 'hellooo') def test_set_event_context_field(self): - ec = self._ec.context_field_type() + ec = self._ec.context_field_class() ec['ant'] = 2 ec['msg'] = 'hi there' ev = self._ec() @@ -155,7 +155,7 @@ class EventTestCase(unittest.TestCase): self.assertEqual(ev.payload_field['mosquito'], 42) def test_set_event_payload_field(self): - ep = self._ec.payload_field_type() + ep = self._ec.payload_field_class() ep['giraffe'] = 2 ep['gnu'] = 124 ep['mosquito'] = 17 @@ -188,9 +188,9 @@ class EventTestCase(unittest.TestCase): def test_packet(self): tc = bt2.Trace() - tc.packet_header_field_type = bt2.StructureFieldType() - tc.packet_header_field_type.append_field('magic', bt2.IntegerFieldType(32)) - tc.packet_header_field_type.append_field('stream_id', bt2.IntegerFieldType(16)) + tc.packet_header_field_class = bt2.StructureFieldClass() + tc.packet_header_field_class.append_field('magic', bt2.IntegerFieldClass(32)) + tc.packet_header_field_class.append_field('stream_id', bt2.IntegerFieldClass(16)) tc.add_stream_class(self._ec.stream_class) ev = self._ec() self._fill_ev(ev) @@ -209,9 +209,9 @@ class EventTestCase(unittest.TestCase): def test_stream(self): tc = bt2.Trace() - tc.packet_header_field_type = bt2.StructureFieldType() - tc.packet_header_field_type.append_field('magic', bt2.IntegerFieldType(32)) - tc.packet_header_field_type.append_field('stream_id', bt2.IntegerFieldType(16)) + tc.packet_header_field_class = bt2.StructureFieldClass() + tc.packet_header_field_class.append_field('magic', bt2.IntegerFieldClass(32)) + tc.packet_header_field_class.append_field('stream_id', bt2.IntegerFieldClass(16)) tc.add_stream_class(self._ec.stream_class) ev = self._ec() self._fill_ev(ev) @@ -247,9 +247,9 @@ class EventTestCase(unittest.TestCase): def test_getitem(self): tc = bt2.Trace() - tc.packet_header_field_type = bt2.StructureFieldType() - tc.packet_header_field_type.append_field('magic', bt2.IntegerFieldType(32)) - tc.packet_header_field_type.append_field('stream_id', bt2.IntegerFieldType(16)) + tc.packet_header_field_class = bt2.StructureFieldClass() + tc.packet_header_field_class.append_field('magic', bt2.IntegerFieldClass(32)) + tc.packet_header_field_class.append_field('stream_id', bt2.IntegerFieldClass(16)) tc.add_stream_class(self._ec.stream_class) ev = self._ec() self._fill_ev(ev) diff --git a/tests/bindings/python/bt2/test_event_class.py b/tests/bindings/python/bt2/test_event_class.py index 891cc95b8..bd8636338 100644 --- a/tests/bindings/python/bt2/test_event_class.py +++ b/tests/bindings/python/bt2/test_event_class.py @@ -7,28 +7,28 @@ import bt2 @unittest.skip("this is broken") class EventClassTestCase(unittest.TestCase): def setUp(self): - self._context_ft = bt2.StructureFieldType() - self._context_ft.append_field('allo', bt2.StringFieldType()) - self._context_ft.append_field('zola', bt2.IntegerFieldType(18)) - self._payload_ft = bt2.StructureFieldType() - self._payload_ft.append_field('zoom', bt2.StringFieldType()) + self._context_fc = bt2.StructureFieldClass() + self._context_fc.append_field('allo', bt2.StringFieldClass()) + self._context_fc.append_field('zola', bt2.IntegerFieldClass(18)) + self._payload_fc = bt2.StructureFieldClass() + self._payload_fc.append_field('zoom', bt2.StringFieldClass()) self._ec = bt2.EventClass('my_event') self._ec.id = 18 self._ec.emf_uri = 'yes' self._ec.log_level = bt2.EventClassLogLevel.INFO - self._ec.context_field_type = self._context_ft - self._ec.payload_field_type = self._payload_ft + self._ec.context_field_class = self._context_fc + self._ec.payload_field_class = self._payload_fc def tearDown(self): - del self._context_ft - del self._payload_ft + del self._context_fc + del self._payload_fc del self._ec def test_create(self): self.assertEqual(self._ec.name, 'my_event') self.assertEqual(self._ec.id, 18) - self.assertEqual(self._ec.context_field_type, self._context_ft) - self.assertEqual(self._ec.payload_field_type, self._payload_ft) + self.assertEqual(self._ec.context_field_class, self._context_fc) + self.assertEqual(self._ec.payload_field_class, self._payload_fc) self.assertEqual(self._ec.emf_uri, 'yes') self.assertEqual(self._ec.log_level, bt2.EventClassLogLevel.INFO) @@ -38,14 +38,14 @@ class EventClassTestCase(unittest.TestCase): def test_create_full(self): ec = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) self.assertEqual(ec.name, 'name') self.assertEqual(ec.id, 23) - self.assertEqual(ec.context_field_type, self._context_ft) - self.assertEqual(ec.payload_field_type, self._payload_ft) + self.assertEqual(ec.context_field_class, self._context_fc) + self.assertEqual(ec.payload_field_class, self._payload_fc) self.assertEqual(ec.emf_uri, 'my URI') self.assertEqual(ec.log_level, bt2.EventClassLogLevel.WARNING) @@ -57,29 +57,29 @@ class EventClassTestCase(unittest.TestCase): with self.assertRaises(TypeError): self._ec.id = 'lel' - def test_assign_context_field_type(self): - self._ec.context_field_type = self._payload_ft - self.assertEqual(self._ec.context_field_type, self._payload_ft) + def test_assign_context_field_class(self): + self._ec.context_field_class = self._payload_fc + self.assertEqual(self._ec.context_field_class, self._payload_fc) - def test_assign_no_context_field_type(self): - self._ec.context_field_type = None - self.assertIsNone(self._ec.context_field_type) + def test_assign_no_context_field_class(self): + self._ec.context_field_class = None + self.assertIsNone(self._ec.context_field_class) - def test_assign_invalid_context_field_type(self): + def test_assign_invalid_context_field_class(self): with self.assertRaises(TypeError): - self._ec.context_field_type = 'lel' + self._ec.context_field_class = 'lel' - def test_assign_payload_field_type(self): - self._ec.payload_field_type = self._payload_ft - self.assertEqual(self._ec.payload_field_type, self._payload_ft) + def test_assign_payload_field_class(self): + self._ec.payload_field_class = self._payload_fc + self.assertEqual(self._ec.payload_field_class, self._payload_fc) - def test_assign_no_payload_field_type(self): - self._ec.payload_field_type = None - self.assertIsNone(self._ec.payload_field_type) + def test_assign_no_payload_field_class(self): + self._ec.payload_field_class = None + self.assertIsNone(self._ec.payload_field_class) - def test_assign_invalid_payload_field_type(self): + def test_assign_invalid_payload_field_class(self): with self.assertRaises(TypeError): - self._ec.payload_field_type = 'lel' + self._ec.payload_field_class = 'lel' def test_stream_class_prop_no_sc(self): self.assertIsNone(self._ec.stream_class) @@ -97,14 +97,14 @@ class EventClassTestCase(unittest.TestCase): def test_copy(self): cpy = copy.copy(self._ec) self._test_copy(cpy) - self.assertEqual(self._ec.context_field_type.addr, cpy.context_field_type.addr) - self.assertEqual(self._ec.payload_field_type.addr, cpy.payload_field_type.addr) + self.assertEqual(self._ec.context_field_class.addr, cpy.context_field_class.addr) + self.assertEqual(self._ec.payload_field_class.addr, cpy.payload_field_class.addr) def test_deepcopy(self): cpy = copy.deepcopy(self._ec) self._test_copy(cpy) - self.assertNotEqual(self._ec.context_field_type.addr, cpy.context_field_type.addr) - self.assertNotEqual(self._ec.payload_field_type.addr, cpy.payload_field_type.addr) + self.assertNotEqual(self._ec.context_field_class.addr, cpy.context_field_class.addr) + self.assertNotEqual(self._ec.payload_field_class.addr, cpy.payload_field_class.addr) def test_assign_emf_uri(self): self._ec.emf_uri = 'salut' @@ -124,91 +124,91 @@ class EventClassTestCase(unittest.TestCase): def test_eq(self): ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) self.assertEqual(ec1, ec2) def test_ne_name(self): ec1 = bt2.EventClass(name='name1', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) self.assertNotEqual(ec1, ec2) def test_ne_id(self): ec1 = bt2.EventClass(name='name', id=24, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) self.assertNotEqual(ec1, ec2) - def test_ne_context_field_type(self): + def test_ne_context_field_class(self): ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._payload_ft, - payload_field_type=self._payload_ft, + context_field_class=self._payload_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) self.assertNotEqual(ec1, ec2) - def test_ne_payload_field_type(self): + def test_ne_payload_field_class(self): ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._context_ft, + context_field_class=self._context_fc, + payload_field_class=self._context_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) self.assertNotEqual(ec1, ec2) def test_ne_emf_uri(self): ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my UR', log_level=bt2.EventClassLogLevel.WARNING) self.assertNotEqual(ec1, ec2) def test_ne_log_level(self): ec1 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.WARNING) ec2 = bt2.EventClass(name='name', id=23, - context_field_type=self._context_ft, - payload_field_type=self._payload_ft, + context_field_class=self._context_fc, + payload_field_class=self._payload_fc, emf_uri='my URI', log_level=bt2.EventClassLogLevel.ERROR) self.assertNotEqual(ec1, ec2) diff --git a/tests/bindings/python/bt2/test_field_class.py b/tests/bindings/python/bt2/test_field_class.py new file mode 100644 index 000000000..fbbadfdcc --- /dev/null +++ b/tests/bindings/python/bt2/test_field_class.py @@ -0,0 +1,707 @@ +import bt2.fields +import unittest +import copy +import bt2 + + +class _TestCopySimple: + def _test_copy(self, cpy): + self.assertIsNot(cpy, self._fc) + self.assertNotEqual(cpy.addr, self._fc.addr) + self.assertEqual(cpy, self._fc) + + def test_copy(self): + cpy = copy.copy(self._fc) + self._test_copy(cpy) + + def test_deepcopy(self): + cpy = copy.deepcopy(self._fc) + self._test_copy(cpy) + + +class _TestAlignmentProp: + def test_assign_alignment(self): + self._fc.alignment = 32 + self.assertEqual(self._fc.alignment, 32) + + def test_assign_invalid_alignment(self): + with self.assertRaises(ValueError): + self._fc.alignment = 23 + + +class _TestByteOrderProp: + def test_assign_byte_order(self): + self._fc.byte_order = bt2.ByteOrder.LITTLE_ENDIAN + self.assertEqual(self._fc.byte_order, bt2.ByteOrder.LITTLE_ENDIAN) + + def test_assign_invalid_byte_order(self): + with self.assertRaises(TypeError): + self._fc.byte_order = 'hey' + + +class _TestInvalidEq: + def test_eq_invalid(self): + self.assertFalse(self._fc == 23) + + +class _TestIntegerFieldClassProps: + def test_size_prop(self): + self.assertEqual(self._fc.size, 35) + + def test_assign_signed(self): + self._fc.is_signed = True + self.assertTrue(self._fc.is_signed) + + def test_assign_invalid_signed(self): + with self.assertRaises(TypeError): + self._fc.is_signed = 23 + + def test_assign_base(self): + self._fc.base = bt2.Base.HEXADECIMAL + self.assertEqual(self._fc.base, bt2.Base.HEXADECIMAL) + + def test_assign_invalid_base(self): + with self.assertRaises(TypeError): + self._fc.base = 'hey' + + def test_assign_encoding(self): + self._fc.encoding = bt2.Encoding.UTF8 + self.assertEqual(self._fc.encoding, bt2.Encoding.UTF8) + + def test_assign_invalid_encoding(self): + with self.assertRaises(TypeError): + self._fc.encoding = 'hey' + + def test_assign_mapped_clock_class(self): + cc = bt2.ClockClass('name', 1000) + self._fc.mapped_clock_class = cc + self.assertEqual(self._fc.mapped_clock_class, cc) + + def test_assign_invalid_mapped_clock_class(self): + with self.assertRaises(TypeError): + self._fc.mapped_clock_class = object() + + +@unittest.skip("this is broken") +class IntegerFieldClassTestCase(_TestIntegerFieldClassProps, _TestCopySimple, + _TestAlignmentProp, _TestByteOrderProp, + _TestInvalidEq, unittest.TestCase): + def setUp(self): + self._fc = bt2.IntegerFieldClass(35) + + def tearDown(self): + del self._fc + + def test_create_default(self): + self.assertEqual(self._fc.size, 35) + self.assertIsNone(self._fc.mapped_clock_class) + + def test_create_invalid_size(self): + with self.assertRaises(TypeError): + fc = bt2.IntegerFieldClass('yes') + + def test_create_neg_size(self): + with self.assertRaises(ValueError): + fc = bt2.IntegerFieldClass(-2) + + def test_create_neg_zero(self): + with self.assertRaises(ValueError): + fc = bt2.IntegerFieldClass(0) + + def test_create_full(self): + cc = bt2.ClockClass('name', 1000) + fc = bt2.IntegerFieldClass(24, alignment=16, + byte_order=bt2.ByteOrder.BIG_ENDIAN, + is_signed=True, base=bt2.Base.OCTAL, + encoding=bt2.Encoding.NONE, + mapped_clock_class=cc) + self.assertEqual(fc.size, 24) + self.assertEqual(fc.alignment, 16) + self.assertEqual(fc.byte_order, bt2.ByteOrder.BIG_ENDIAN) + self.assertTrue(fc.is_signed) + self.assertEqual(fc.base, bt2.Base.OCTAL) + self.assertEqual(fc.encoding, bt2.Encoding.NONE) + self.assertEqual(fc.mapped_clock_class, cc) + + def test_create_field(self): + field = self._fc() + self.assertIsInstance(field, bt2.fields._IntegerField) + + def test_create_field_init(self): + field = self._fc(23) + self.assertEqual(field, 23) + + +@unittest.skip("this is broken") +class FloatingPointNumberFieldClassTestCase(_TestCopySimple, _TestAlignmentProp, + _TestByteOrderProp, _TestInvalidEq, + unittest.TestCase): + def setUp(self): + self._fc = bt2.FloatingPointNumberFieldClass() + + def tearDown(self): + del self._fc + + def test_create_default(self): + pass + + def test_create_full(self): + fc = bt2.FloatingPointNumberFieldClass(alignment=16, + byte_order=bt2.ByteOrder.BIG_ENDIAN, + exponent_size=11, + mantissa_size=53) + self.assertEqual(fc.alignment, 16) + self.assertEqual(fc.byte_order, bt2.ByteOrder.BIG_ENDIAN) + self.assertEqual(fc.exponent_size, 11) + self.assertEqual(fc.mantissa_size, 53) + + def test_assign_exponent_size(self): + self._fc.exponent_size = 8 + self.assertEqual(self._fc.exponent_size, 8) + + def test_assign_invalid_exponent_size(self): + with self.assertRaises(TypeError): + self._fc.exponent_size = 'yes' + + def test_assign_mantissa_size(self): + self._fc.mantissa_size = 24 + self.assertEqual(self._fc.mantissa_size, 24) + + def test_assign_invalid_mantissa_size(self): + with self.assertRaises(TypeError): + self._fc.mantissa_size = 'no' + + def test_create_field(self): + field = self._fc() + self.assertIsInstance(field, bt2.fields._FloatingPointNumberField) + + def test_create_field_init(self): + field = self._fc(17.5) + self.assertEqual(field, 17.5) + + +@unittest.skip("this is broken") +class EnumerationFieldClassTestCase(_TestIntegerFieldClassProps, _TestInvalidEq, + _TestCopySimple, _TestAlignmentProp, + _TestByteOrderProp, unittest.TestCase): + def setUp(self): + self._fc = bt2.EnumerationFieldClass(size=35) + + def tearDown(self): + del self._fc + + def test_create_from_int_fc(self): + int_fc = bt2.IntegerFieldClass(23) + self._fc = bt2.EnumerationFieldClass(int_fc) + + def test_create_from_invalid_type(self): + with self.assertRaises(TypeError): + self._fc = bt2.EnumerationFieldClass('coucou') + + def test_create_from_invalid_fc(self): + with self.assertRaises(TypeError): + fc = bt2.FloatingPointNumberFieldClass() + self._fc = bt2.EnumerationFieldClass(fc) + + def test_create_full(self): + fc = bt2.EnumerationFieldClass(size=24, alignment=16, + byte_order=bt2.ByteOrder.BIG_ENDIAN, + is_signed=True, base=bt2.Base.OCTAL, + encoding=bt2.Encoding.NONE, + mapped_clock_class=None) + self.assertEqual(fc.size, 24) + self.assertEqual(fc.alignment, 16) + self.assertEqual(fc.byte_order, bt2.ByteOrder.BIG_ENDIAN) + self.assertTrue(fc.is_signed) + self.assertEqual(fc.base, bt2.Base.OCTAL) + self.assertEqual(fc.encoding, bt2.Encoding.NONE) + #self.assertIsNone(fc.mapped_clock_class) + + def test_integer_field_class_prop(self): + int_fc = bt2.IntegerFieldClass(23) + enum_fc = bt2.EnumerationFieldClass(int_fc) + self.assertEqual(enum_fc.integer_field_class.addr, int_fc.addr) + + def test_add_mapping_simple(self): + self._fc.add_mapping('hello', 24) + mapping = self._fc[0] + self.assertEqual(mapping.name, 'hello') + self.assertEqual(mapping.lower, 24) + self.assertEqual(mapping.upper, 24) + + def test_add_mapping_simple_kwargs(self): + self._fc.add_mapping(name='hello', lower=17, upper=23) + mapping = self._fc[0] + self.assertEqual(mapping.name, 'hello') + self.assertEqual(mapping.lower, 17) + self.assertEqual(mapping.upper, 23) + + def test_add_mapping_range(self): + self._fc.add_mapping('hello', 21, 199) + mapping = self._fc[0] + self.assertEqual(mapping.name, 'hello') + self.assertEqual(mapping.lower, 21) + self.assertEqual(mapping.upper, 199) + + def test_add_mapping_invalid_name(self): + with self.assertRaises(TypeError): + self._fc.add_mapping(17, 21, 199) + + def test_add_mapping_invalid_signedness_lower(self): + with self.assertRaises(ValueError): + self._fc.add_mapping('hello', -21, 199) + + def test_add_mapping_invalid_signedness_upper(self): + with self.assertRaises(ValueError): + self._fc.add_mapping('hello', 21, -199) + + def test_add_mapping_simple_signed(self): + self._fc.is_signed = True + self._fc.add_mapping('hello', -24) + mapping = self._fc[0] + self.assertEqual(mapping.name, 'hello') + self.assertEqual(mapping.lower, -24) + self.assertEqual(mapping.upper, -24) + + def test_add_mapping_range_signed(self): + self._fc.is_signed = True + self._fc.add_mapping('hello', -21, 199) + mapping = self._fc[0] + self.assertEqual(mapping.name, 'hello') + self.assertEqual(mapping.lower, -21) + self.assertEqual(mapping.upper, 199) + + def test_iadd(self): + enum_fc = bt2.EnumerationFieldClass(size=16) + enum_fc.add_mapping('c', 4, 5) + enum_fc.add_mapping('d', 6, 18) + enum_fc.add_mapping('e', 20, 27) + self._fc.add_mapping('a', 0, 2) + self._fc.add_mapping('b', 3) + self._fc += enum_fc + self.assertEqual(self._fc[0].name, 'a') + self.assertEqual(self._fc[0].lower, 0) + self.assertEqual(self._fc[0].upper, 2) + self.assertEqual(self._fc[1].name, 'b') + self.assertEqual(self._fc[1].lower, 3) + self.assertEqual(self._fc[1].upper, 3) + self.assertEqual(self._fc[2].name, 'c') + self.assertEqual(self._fc[2].lower, 4) + self.assertEqual(self._fc[2].upper, 5) + self.assertEqual(self._fc[3].name, 'd') + self.assertEqual(self._fc[3].lower, 6) + self.assertEqual(self._fc[3].upper, 18) + self.assertEqual(self._fc[4].name, 'e') + self.assertEqual(self._fc[4].lower, 20) + self.assertEqual(self._fc[4].upper, 27) + + def test_bool_op(self): + self.assertFalse(self._fc) + self._fc.add_mapping('a', 0) + self.assertTrue(self._fc) + + def test_len(self): + self._fc.add_mapping('a', 0) + self._fc.add_mapping('b', 1) + self._fc.add_mapping('c', 2) + self.assertEqual(len(self._fc), 3) + + def test_getitem(self): + self._fc.add_mapping('a', 0) + self._fc.add_mapping('b', 1, 3) + self._fc.add_mapping('c', 5) + mapping = self._fc[1] + self.assertEqual(mapping.name, 'b') + self.assertEqual(mapping.lower, 1) + self.assertEqual(mapping.upper, 3) + + def test_iter(self): + mappings = ( + ('a', 1, 5), + ('b', 10, 17), + ('c', 20, 1504), + ('d', 22510, 99999), + ) + + for mapping in mappings: + self._fc.add_mapping(*mapping) + + for fc_mapping, mapping in zip(self._fc, mappings): + self.assertEqual(fc_mapping.name, mapping[0]) + self.assertEqual(fc_mapping.lower, mapping[1]) + self.assertEqual(fc_mapping.upper, mapping[2]) + + def test_mapping_eq(self): + enum1 = bt2.EnumerationFieldClass(size=32) + enum2 = bt2.EnumerationFieldClass(size=16) + enum1.add_mapping('b', 1, 3) + enum2.add_mapping('b', 1, 3) + self.assertEqual(enum1[0], enum2[0]) + + def test_mapping_eq_invalid(self): + enum1 = bt2.EnumerationFieldClass(size=32) + enum1.add_mapping('b', 1, 3) + self.assertNotEqual(enum1[0], 23) + + def _test_find_by_name(self, fc): + fc.add_mapping('a', 0) + fc.add_mapping('b', 1, 3) + fc.add_mapping('a', 5) + fc.add_mapping('a', 17, 144) + fc.add_mapping('C', 5) + mapping_iter = fc.mappings_by_name('a') + mappings = list(mapping_iter) + a0 = False + a5 = False + a17_144 = False + i = 0 + + for mapping in mappings: + i += 1 + self.assertEqual(mapping.name, 'a') + + if mapping.lower == 0 and mapping.upper == 0: + a0 = True + elif mapping.lower == 5 and mapping.upper == 5: + a5 = True + elif mapping.lower == 17 and mapping.upper == 144: + a17_144 = True + + self.assertEqual(i, 3) + self.assertTrue(a0) + self.assertTrue(a5) + self.assertTrue(a17_144) + + def test_find_by_name_signed(self): + self._test_find_by_name(bt2.EnumerationFieldClass(size=8, is_signed=True)) + + def test_find_by_name_unsigned(self): + self._test_find_by_name(bt2.EnumerationFieldClass(size=8)) + + def _test_find_by_value(self, fc): + fc.add_mapping('a', 0) + fc.add_mapping('b', 1, 3) + fc.add_mapping('c', 5, 19) + fc.add_mapping('d', 8, 15) + fc.add_mapping('e', 10, 21) + fc.add_mapping('f', 0) + fc.add_mapping('g', 14) + mapping_iter = fc.mappings_by_value(14) + mappings = list(mapping_iter) + c = False + d = False + e = False + g = False + i = 0 + + for mapping in mappings: + i += 1 + + if mapping.name == 'c': + c = True + elif mapping.name == 'd': + d = True + elif mapping.name == 'e': + e = True + elif mapping.name == 'g': + g = True + + self.assertEqual(i, 4) + self.assertTrue(c) + self.assertTrue(d) + self.assertTrue(e) + self.assertTrue(g) + + def test_find_by_value_signed(self): + self._test_find_by_value(bt2.EnumerationFieldClass(size=8, is_signed=True)) + + def test_find_by_value_unsigned(self): + self._test_find_by_value(bt2.EnumerationFieldClass(size=8)) + + def test_create_field(self): + self._fc.add_mapping('c', 4, 5) + field = self._fc() + self.assertIsInstance(field, bt2.fields._EnumerationField) + + def test_create_field_init(self): + self._fc.add_mapping('c', 4, 5) + field = self._fc(4) + self.assertEqual(field, 4) + + +@unittest.skip("this is broken") +class StringFieldClassTestCase(_TestCopySimple, _TestInvalidEq, + unittest.TestCase): + def setUp(self): + self._fc = bt2.StringFieldClass() + + def tearDown(self): + del self._fc + + def test_create_default(self): + pass + + def test_create_full(self): + fc = bt2.StringFieldClass(encoding=bt2.Encoding.UTF8) + self.assertEqual(fc.encoding, bt2.Encoding.UTF8) + + def test_assign_encoding(self): + self._fc.encoding = bt2.Encoding.UTF8 + self.assertEqual(self._fc.encoding, bt2.Encoding.UTF8) + + def test_assign_invalid_encoding(self): + with self.assertRaises(TypeError): + self._fc.encoding = 'yes' + + def test_create_field(self): + field = self._fc() + self.assertIsInstance(field, bt2.fields._StringField) + + def test_create_field_init(self): + field = self._fc('hola') + self.assertEqual(field, 'hola') + + +class _TestFieldContainer(_TestInvalidEq, _TestCopySimple): + def test_append_field(self): + int_field_class = bt2.IntegerFieldClass(32) + self._fc.append_field('int32', int_field_class) + field_class = self._fc['int32'] + self.assertEqual(field_class, int_field_class) + + def test_append_field_kwargs(self): + int_field_class = bt2.IntegerFieldClass(32) + self._fc.append_field(name='int32', field_class=int_field_class) + field_class = self._fc['int32'] + self.assertEqual(field_class, int_field_class) + + def test_append_field_invalid_name(self): + with self.assertRaises(TypeError): + self._fc.append_field(23, bt2.StringFieldClass()) + + def test_append_field_invalid_field_class(self): + with self.assertRaises(TypeError): + self._fc.append_field('yes', object()) + + def test_iadd(self): + struct_fc = bt2.StructureFieldClass() + c_field_class = bt2.StringFieldClass() + d_field_class = bt2.EnumerationFieldClass(size=32) + e_field_class = bt2.StructureFieldClass() + struct_fc.append_field('c_string', c_field_class) + struct_fc.append_field('d_enum', d_field_class) + struct_fc.append_field('e_struct', e_field_class) + a_field_class = bt2.FloatingPointNumberFieldClass() + b_field_class = bt2.IntegerFieldClass(17) + self._fc.append_field('a_float', a_field_class) + self._fc.append_field('b_int', b_field_class) + self._fc += struct_fc + self.assertEqual(self._fc['a_float'], a_field_class) + self.assertEqual(self._fc['b_int'], b_field_class) + self.assertEqual(self._fc['c_string'], c_field_class) + self.assertEqual(self._fc['d_enum'], d_field_class) + self.assertEqual(self._fc['e_struct'], e_field_class) + + def test_bool_op(self): + self.assertFalse(self._fc) + self._fc.append_field('a', bt2.StringFieldClass()) + self.assertTrue(self._fc) + + def test_len(self): + fc = bt2.StringFieldClass() + self._fc.append_field('a', fc) + self._fc.append_field('b', fc) + self._fc.append_field('c', fc) + self.assertEqual(len(self._fc), 3) + + def test_getitem(self): + a_fc = bt2.IntegerFieldClass(32) + b_fc = bt2.StringFieldClass() + c_fc = bt2.FloatingPointNumberFieldClass() + self._fc.append_field('a', a_fc) + self._fc.append_field('b', b_fc) + self._fc.append_field('c', c_fc) + self.assertEqual(self._fc['b'], b_fc) + + def test_getitem_invalid_key_type(self): + with self.assertRaises(TypeError): + self._fc[0] + + def test_getitem_invalid_key(self): + with self.assertRaises(KeyError): + self._fc['no way'] + + def test_contains(self): + self.assertFalse('a' in self._fc) + self._fc.append_field('a', bt2.StringFieldClass()) + self.assertTrue('a' in self._fc) + + def test_iter(self): + a_fc = bt2.IntegerFieldClass(32) + b_fc = bt2.StringFieldClass() + c_fc = bt2.FloatingPointNumberFieldClass() + fields = ( + ('a', a_fc), + ('b', b_fc), + ('c', c_fc), + ) + + for field in fields: + self._fc.append_field(*field) + + for (name, fc_field_class), field in zip(self._fc.items(), fields): + self.assertEqual(name, field[0]) + self.assertEqual(fc_field_class, field[1]) + + def test_at_index(self): + a_fc = bt2.IntegerFieldClass(32) + b_fc = bt2.StringFieldClass() + c_fc = bt2.FloatingPointNumberFieldClass() + self._fc.append_field('c', c_fc) + self._fc.append_field('a', a_fc) + self._fc.append_field('b', b_fc) + self.assertEqual(self._fc.at_index(1), a_fc) + + def test_at_index_invalid(self): + self._fc.append_field('c', bt2.IntegerFieldClass(32)) + + with self.assertRaises(TypeError): + self._fc.at_index('yes') + + def test_at_index_out_of_bounds_after(self): + self._fc.append_field('c', bt2.IntegerFieldClass(32)) + + with self.assertRaises(IndexError): + self._fc.at_index(len(self._fc)) + + +@unittest.skip("this is broken") +class StructureFieldClassTestCase(_TestFieldContainer, unittest.TestCase): + def setUp(self): + self._fc = bt2.StructureFieldClass() + + def tearDown(self): + del self._fc + + def test_create_default(self): + self.assertEqual(self._fc.alignment, 1) + + def test_create_with_min_alignment(self): + fc = bt2.StructureFieldClass(8) + self.assertEqual(fc.alignment, 8) + + def test_assign_alignment(self): + with self.assertRaises(AttributeError): + self._fc.alignment = 32 + + def test_assign_min_alignment(self): + self._fc.min_alignment = 64 + self.assertTrue(self._fc.alignment >= 64) + + def test_assign_invalid_min_alignment(self): + with self.assertRaises(ValueError): + self._fc.min_alignment = 23 + + def test_assign_get_min_alignment(self): + with self.assertRaises(AttributeError): + self._fc.min_alignment + + def test_create_field(self): + field = self._fc() + self.assertIsInstance(field, bt2.fields._StructureField) + + def test_create_field_init_invalid(self): + with self.assertRaises(bt2.Error): + field = self._fc(23) + + +@unittest.skip("this is broken") +class VariantFieldClassTestCase(_TestFieldContainer, unittest.TestCase): + def setUp(self): + self._fc = bt2.VariantFieldClass('path.to.tag') + + def tearDown(self): + del self._fc + + def test_create_default(self): + self.assertEqual(self._fc.tag_name, 'path.to.tag') + + def test_create_invalid_tag_name(self): + with self.assertRaises(TypeError): + self._fc = bt2.VariantFieldClass(23) + + def test_assign_tag_name(self): + self._fc.tag_name = 'a.different.tag' + self.assertEqual(self._fc.tag_name, 'a.different.tag') + + def test_assign_invalid_tag_name(self): + with self.assertRaises(TypeError): + self._fc.tag_name = -17 + + +@unittest.skip("this is broken") +class ArrayFieldClassTestCase(_TestInvalidEq, _TestCopySimple, + unittest.TestCase): + def setUp(self): + self._elem_fc = bt2.IntegerFieldClass(23) + self._fc = bt2.ArrayFieldClass(self._elem_fc, 45) + + def tearDown(self): + del self._fc + del self._elem_fc + + def test_create_default(self): + self.assertEqual(self._fc.element_field_class, self._elem_fc) + self.assertEqual(self._fc.length, 45) + + def test_create_invalid_field_class(self): + with self.assertRaises(TypeError): + self._fc = bt2.ArrayFieldClass(object(), 45) + + def test_create_invalid_length(self): + with self.assertRaises(ValueError): + self._fc = bt2.ArrayFieldClass(bt2.StringFieldClass(), -17) + + def test_create_invalid_length_type(self): + with self.assertRaises(TypeError): + self._fc = bt2.ArrayFieldClass(bt2.StringFieldClass(), 'the length') + + def test_create_field(self): + field = self._fc() + self.assertIsInstance(field, bt2.fields._ArrayField) + + def test_create_field_init_invalid(self): + with self.assertRaises(bt2.Error): + field = self._fc(23) + + +@unittest.skip("this is broken") +class SequenceFieldClassTestCase(_TestInvalidEq, _TestCopySimple, + unittest.TestCase): + def setUp(self): + self._elem_fc = bt2.IntegerFieldClass(23) + self._fc = bt2.SequenceFieldClass(self._elem_fc, 'the.length') + + def tearDown(self): + del self._fc + del self._elem_fc + + def test_create_default(self): + self.assertEqual(self._fc.element_field_class, self._elem_fc) + self.assertEqual(self._fc.length_name, 'the.length') + + def test_create_invalid_field_class(self): + with self.assertRaises(TypeError): + self._fc = bt2.ArrayFieldClass(object(), 'the.length') + + def test_create_invalid_length_type(self): + with self.assertRaises(TypeError): + self._fc = bt2.SequenceFieldClass(bt2.StringFieldClass(), 17) + + def test_create_field(self): + field = self._fc() + self.assertIsInstance(field, bt2.fields._SequenceField) + + def test_create_field_init_invalid(self): + with self.assertRaises(bt2.Error): + field = self._fc(23) diff --git a/tests/bindings/python/bt2/test_field_types.py b/tests/bindings/python/bt2/test_field_types.py deleted file mode 100644 index ddf661a98..000000000 --- a/tests/bindings/python/bt2/test_field_types.py +++ /dev/null @@ -1,707 +0,0 @@ -import bt2.fields -import unittest -import copy -import bt2 - - -class _TestCopySimple: - def _test_copy(self, cpy): - self.assertIsNot(cpy, self._ft) - self.assertNotEqual(cpy.addr, self._ft.addr) - self.assertEqual(cpy, self._ft) - - def test_copy(self): - cpy = copy.copy(self._ft) - self._test_copy(cpy) - - def test_deepcopy(self): - cpy = copy.deepcopy(self._ft) - self._test_copy(cpy) - - -class _TestAlignmentProp: - def test_assign_alignment(self): - self._ft.alignment = 32 - self.assertEqual(self._ft.alignment, 32) - - def test_assign_invalid_alignment(self): - with self.assertRaises(ValueError): - self._ft.alignment = 23 - - -class _TestByteOrderProp: - def test_assign_byte_order(self): - self._ft.byte_order = bt2.ByteOrder.LITTLE_ENDIAN - self.assertEqual(self._ft.byte_order, bt2.ByteOrder.LITTLE_ENDIAN) - - def test_assign_invalid_byte_order(self): - with self.assertRaises(TypeError): - self._ft.byte_order = 'hey' - - -class _TestInvalidEq: - def test_eq_invalid(self): - self.assertFalse(self._ft == 23) - - -class _TestIntegerFieldTypeProps: - def test_size_prop(self): - self.assertEqual(self._ft.size, 35) - - def test_assign_signed(self): - self._ft.is_signed = True - self.assertTrue(self._ft.is_signed) - - def test_assign_invalid_signed(self): - with self.assertRaises(TypeError): - self._ft.is_signed = 23 - - def test_assign_base(self): - self._ft.base = bt2.Base.HEXADECIMAL - self.assertEqual(self._ft.base, bt2.Base.HEXADECIMAL) - - def test_assign_invalid_base(self): - with self.assertRaises(TypeError): - self._ft.base = 'hey' - - def test_assign_encoding(self): - self._ft.encoding = bt2.Encoding.UTF8 - self.assertEqual(self._ft.encoding, bt2.Encoding.UTF8) - - def test_assign_invalid_encoding(self): - with self.assertRaises(TypeError): - self._ft.encoding = 'hey' - - def test_assign_mapped_clock_class(self): - cc = bt2.ClockClass('name', 1000) - self._ft.mapped_clock_class = cc - self.assertEqual(self._ft.mapped_clock_class, cc) - - def test_assign_invalid_mapped_clock_class(self): - with self.assertRaises(TypeError): - self._ft.mapped_clock_class = object() - - -@unittest.skip("this is broken") -class IntegerFieldTypeTestCase(_TestIntegerFieldTypeProps, _TestCopySimple, - _TestAlignmentProp, _TestByteOrderProp, - _TestInvalidEq, unittest.TestCase): - def setUp(self): - self._ft = bt2.IntegerFieldType(35) - - def tearDown(self): - del self._ft - - def test_create_default(self): - self.assertEqual(self._ft.size, 35) - self.assertIsNone(self._ft.mapped_clock_class) - - def test_create_invalid_size(self): - with self.assertRaises(TypeError): - ft = bt2.IntegerFieldType('yes') - - def test_create_neg_size(self): - with self.assertRaises(ValueError): - ft = bt2.IntegerFieldType(-2) - - def test_create_neg_zero(self): - with self.assertRaises(ValueError): - ft = bt2.IntegerFieldType(0) - - def test_create_full(self): - cc = bt2.ClockClass('name', 1000) - ft = bt2.IntegerFieldType(24, alignment=16, - byte_order=bt2.ByteOrder.BIG_ENDIAN, - is_signed=True, base=bt2.Base.OCTAL, - encoding=bt2.Encoding.NONE, - mapped_clock_class=cc) - self.assertEqual(ft.size, 24) - self.assertEqual(ft.alignment, 16) - self.assertEqual(ft.byte_order, bt2.ByteOrder.BIG_ENDIAN) - self.assertTrue(ft.is_signed) - self.assertEqual(ft.base, bt2.Base.OCTAL) - self.assertEqual(ft.encoding, bt2.Encoding.NONE) - self.assertEqual(ft.mapped_clock_class, cc) - - def test_create_field(self): - field = self._ft() - self.assertIsInstance(field, bt2.fields._IntegerField) - - def test_create_field_init(self): - field = self._ft(23) - self.assertEqual(field, 23) - - -@unittest.skip("this is broken") -class FloatingPointNumberFieldTypeTestCase(_TestCopySimple, _TestAlignmentProp, - _TestByteOrderProp, _TestInvalidEq, - unittest.TestCase): - def setUp(self): - self._ft = bt2.FloatingPointNumberFieldType() - - def tearDown(self): - del self._ft - - def test_create_default(self): - pass - - def test_create_full(self): - ft = bt2.FloatingPointNumberFieldType(alignment=16, - byte_order=bt2.ByteOrder.BIG_ENDIAN, - exponent_size=11, - mantissa_size=53) - self.assertEqual(ft.alignment, 16) - self.assertEqual(ft.byte_order, bt2.ByteOrder.BIG_ENDIAN) - self.assertEqual(ft.exponent_size, 11) - self.assertEqual(ft.mantissa_size, 53) - - def test_assign_exponent_size(self): - self._ft.exponent_size = 8 - self.assertEqual(self._ft.exponent_size, 8) - - def test_assign_invalid_exponent_size(self): - with self.assertRaises(TypeError): - self._ft.exponent_size = 'yes' - - def test_assign_mantissa_size(self): - self._ft.mantissa_size = 24 - self.assertEqual(self._ft.mantissa_size, 24) - - def test_assign_invalid_mantissa_size(self): - with self.assertRaises(TypeError): - self._ft.mantissa_size = 'no' - - def test_create_field(self): - field = self._ft() - self.assertIsInstance(field, bt2.fields._FloatingPointNumberField) - - def test_create_field_init(self): - field = self._ft(17.5) - self.assertEqual(field, 17.5) - - -@unittest.skip("this is broken") -class EnumerationFieldTypeTestCase(_TestIntegerFieldTypeProps, _TestInvalidEq, - _TestCopySimple, _TestAlignmentProp, - _TestByteOrderProp, unittest.TestCase): - def setUp(self): - self._ft = bt2.EnumerationFieldType(size=35) - - def tearDown(self): - del self._ft - - def test_create_from_int_ft(self): - int_ft = bt2.IntegerFieldType(23) - self._ft = bt2.EnumerationFieldType(int_ft) - - def test_create_from_invalid_type(self): - with self.assertRaises(TypeError): - self._ft = bt2.EnumerationFieldType('coucou') - - def test_create_from_invalid_ft(self): - with self.assertRaises(TypeError): - ft = bt2.FloatingPointNumberFieldType() - self._ft = bt2.EnumerationFieldType(ft) - - def test_create_full(self): - ft = bt2.EnumerationFieldType(size=24, alignment=16, - byte_order=bt2.ByteOrder.BIG_ENDIAN, - is_signed=True, base=bt2.Base.OCTAL, - encoding=bt2.Encoding.NONE, - mapped_clock_class=None) - self.assertEqual(ft.size, 24) - self.assertEqual(ft.alignment, 16) - self.assertEqual(ft.byte_order, bt2.ByteOrder.BIG_ENDIAN) - self.assertTrue(ft.is_signed) - self.assertEqual(ft.base, bt2.Base.OCTAL) - self.assertEqual(ft.encoding, bt2.Encoding.NONE) - #self.assertIsNone(ft.mapped_clock_class) - - def test_integer_field_type_prop(self): - int_ft = bt2.IntegerFieldType(23) - enum_ft = bt2.EnumerationFieldType(int_ft) - self.assertEqual(enum_ft.integer_field_type.addr, int_ft.addr) - - def test_add_mapping_simple(self): - self._ft.add_mapping('hello', 24) - mapping = self._ft[0] - self.assertEqual(mapping.name, 'hello') - self.assertEqual(mapping.lower, 24) - self.assertEqual(mapping.upper, 24) - - def test_add_mapping_simple_kwargs(self): - self._ft.add_mapping(name='hello', lower=17, upper=23) - mapping = self._ft[0] - self.assertEqual(mapping.name, 'hello') - self.assertEqual(mapping.lower, 17) - self.assertEqual(mapping.upper, 23) - - def test_add_mapping_range(self): - self._ft.add_mapping('hello', 21, 199) - mapping = self._ft[0] - self.assertEqual(mapping.name, 'hello') - self.assertEqual(mapping.lower, 21) - self.assertEqual(mapping.upper, 199) - - def test_add_mapping_invalid_name(self): - with self.assertRaises(TypeError): - self._ft.add_mapping(17, 21, 199) - - def test_add_mapping_invalid_signedness_lower(self): - with self.assertRaises(ValueError): - self._ft.add_mapping('hello', -21, 199) - - def test_add_mapping_invalid_signedness_upper(self): - with self.assertRaises(ValueError): - self._ft.add_mapping('hello', 21, -199) - - def test_add_mapping_simple_signed(self): - self._ft.is_signed = True - self._ft.add_mapping('hello', -24) - mapping = self._ft[0] - self.assertEqual(mapping.name, 'hello') - self.assertEqual(mapping.lower, -24) - self.assertEqual(mapping.upper, -24) - - def test_add_mapping_range_signed(self): - self._ft.is_signed = True - self._ft.add_mapping('hello', -21, 199) - mapping = self._ft[0] - self.assertEqual(mapping.name, 'hello') - self.assertEqual(mapping.lower, -21) - self.assertEqual(mapping.upper, 199) - - def test_iadd(self): - enum_ft = bt2.EnumerationFieldType(size=16) - enum_ft.add_mapping('c', 4, 5) - enum_ft.add_mapping('d', 6, 18) - enum_ft.add_mapping('e', 20, 27) - self._ft.add_mapping('a', 0, 2) - self._ft.add_mapping('b', 3) - self._ft += enum_ft - self.assertEqual(self._ft[0].name, 'a') - self.assertEqual(self._ft[0].lower, 0) - self.assertEqual(self._ft[0].upper, 2) - self.assertEqual(self._ft[1].name, 'b') - self.assertEqual(self._ft[1].lower, 3) - self.assertEqual(self._ft[1].upper, 3) - self.assertEqual(self._ft[2].name, 'c') - self.assertEqual(self._ft[2].lower, 4) - self.assertEqual(self._ft[2].upper, 5) - self.assertEqual(self._ft[3].name, 'd') - self.assertEqual(self._ft[3].lower, 6) - self.assertEqual(self._ft[3].upper, 18) - self.assertEqual(self._ft[4].name, 'e') - self.assertEqual(self._ft[4].lower, 20) - self.assertEqual(self._ft[4].upper, 27) - - def test_bool_op(self): - self.assertFalse(self._ft) - self._ft.add_mapping('a', 0) - self.assertTrue(self._ft) - - def test_len(self): - self._ft.add_mapping('a', 0) - self._ft.add_mapping('b', 1) - self._ft.add_mapping('c', 2) - self.assertEqual(len(self._ft), 3) - - def test_getitem(self): - self._ft.add_mapping('a', 0) - self._ft.add_mapping('b', 1, 3) - self._ft.add_mapping('c', 5) - mapping = self._ft[1] - self.assertEqual(mapping.name, 'b') - self.assertEqual(mapping.lower, 1) - self.assertEqual(mapping.upper, 3) - - def test_iter(self): - mappings = ( - ('a', 1, 5), - ('b', 10, 17), - ('c', 20, 1504), - ('d', 22510, 99999), - ) - - for mapping in mappings: - self._ft.add_mapping(*mapping) - - for ft_mapping, mapping in zip(self._ft, mappings): - self.assertEqual(ft_mapping.name, mapping[0]) - self.assertEqual(ft_mapping.lower, mapping[1]) - self.assertEqual(ft_mapping.upper, mapping[2]) - - def test_mapping_eq(self): - enum1 = bt2.EnumerationFieldType(size=32) - enum2 = bt2.EnumerationFieldType(size=16) - enum1.add_mapping('b', 1, 3) - enum2.add_mapping('b', 1, 3) - self.assertEqual(enum1[0], enum2[0]) - - def test_mapping_eq_invalid(self): - enum1 = bt2.EnumerationFieldType(size=32) - enum1.add_mapping('b', 1, 3) - self.assertNotEqual(enum1[0], 23) - - def _test_find_by_name(self, ft): - ft.add_mapping('a', 0) - ft.add_mapping('b', 1, 3) - ft.add_mapping('a', 5) - ft.add_mapping('a', 17, 144) - ft.add_mapping('C', 5) - mapping_iter = ft.mappings_by_name('a') - mappings = list(mapping_iter) - a0 = False - a5 = False - a17_144 = False - i = 0 - - for mapping in mappings: - i += 1 - self.assertEqual(mapping.name, 'a') - - if mapping.lower == 0 and mapping.upper == 0: - a0 = True - elif mapping.lower == 5 and mapping.upper == 5: - a5 = True - elif mapping.lower == 17 and mapping.upper == 144: - a17_144 = True - - self.assertEqual(i, 3) - self.assertTrue(a0) - self.assertTrue(a5) - self.assertTrue(a17_144) - - def test_find_by_name_signed(self): - self._test_find_by_name(bt2.EnumerationFieldType(size=8, is_signed=True)) - - def test_find_by_name_unsigned(self): - self._test_find_by_name(bt2.EnumerationFieldType(size=8)) - - def _test_find_by_value(self, ft): - ft.add_mapping('a', 0) - ft.add_mapping('b', 1, 3) - ft.add_mapping('c', 5, 19) - ft.add_mapping('d', 8, 15) - ft.add_mapping('e', 10, 21) - ft.add_mapping('f', 0) - ft.add_mapping('g', 14) - mapping_iter = ft.mappings_by_value(14) - mappings = list(mapping_iter) - c = False - d = False - e = False - g = False - i = 0 - - for mapping in mappings: - i += 1 - - if mapping.name == 'c': - c = True - elif mapping.name == 'd': - d = True - elif mapping.name == 'e': - e = True - elif mapping.name == 'g': - g = True - - self.assertEqual(i, 4) - self.assertTrue(c) - self.assertTrue(d) - self.assertTrue(e) - self.assertTrue(g) - - def test_find_by_value_signed(self): - self._test_find_by_value(bt2.EnumerationFieldType(size=8, is_signed=True)) - - def test_find_by_value_unsigned(self): - self._test_find_by_value(bt2.EnumerationFieldType(size=8)) - - def test_create_field(self): - self._ft.add_mapping('c', 4, 5) - field = self._ft() - self.assertIsInstance(field, bt2.fields._EnumerationField) - - def test_create_field_init(self): - self._ft.add_mapping('c', 4, 5) - field = self._ft(4) - self.assertEqual(field, 4) - - -@unittest.skip("this is broken") -class StringFieldTypeTestCase(_TestCopySimple, _TestInvalidEq, - unittest.TestCase): - def setUp(self): - self._ft = bt2.StringFieldType() - - def tearDown(self): - del self._ft - - def test_create_default(self): - pass - - def test_create_full(self): - ft = bt2.StringFieldType(encoding=bt2.Encoding.UTF8) - self.assertEqual(ft.encoding, bt2.Encoding.UTF8) - - def test_assign_encoding(self): - self._ft.encoding = bt2.Encoding.UTF8 - self.assertEqual(self._ft.encoding, bt2.Encoding.UTF8) - - def test_assign_invalid_encoding(self): - with self.assertRaises(TypeError): - self._ft.encoding = 'yes' - - def test_create_field(self): - field = self._ft() - self.assertIsInstance(field, bt2.fields._StringField) - - def test_create_field_init(self): - field = self._ft('hola') - self.assertEqual(field, 'hola') - - -class _TestFieldContainer(_TestInvalidEq, _TestCopySimple): - def test_append_field(self): - int_field_type = bt2.IntegerFieldType(32) - self._ft.append_field('int32', int_field_type) - field_type = self._ft['int32'] - self.assertEqual(field_type, int_field_type) - - def test_append_field_kwargs(self): - int_field_type = bt2.IntegerFieldType(32) - self._ft.append_field(name='int32', field_type=int_field_type) - field_type = self._ft['int32'] - self.assertEqual(field_type, int_field_type) - - def test_append_field_invalid_name(self): - with self.assertRaises(TypeError): - self._ft.append_field(23, bt2.StringFieldType()) - - def test_append_field_invalid_field_type(self): - with self.assertRaises(TypeError): - self._ft.append_field('yes', object()) - - def test_iadd(self): - struct_ft = bt2.StructureFieldType() - c_field_type = bt2.StringFieldType() - d_field_type = bt2.EnumerationFieldType(size=32) - e_field_type = bt2.StructureFieldType() - struct_ft.append_field('c_string', c_field_type) - struct_ft.append_field('d_enum', d_field_type) - struct_ft.append_field('e_struct', e_field_type) - a_field_type = bt2.FloatingPointNumberFieldType() - b_field_type = bt2.IntegerFieldType(17) - self._ft.append_field('a_float', a_field_type) - self._ft.append_field('b_int', b_field_type) - self._ft += struct_ft - self.assertEqual(self._ft['a_float'], a_field_type) - self.assertEqual(self._ft['b_int'], b_field_type) - self.assertEqual(self._ft['c_string'], c_field_type) - self.assertEqual(self._ft['d_enum'], d_field_type) - self.assertEqual(self._ft['e_struct'], e_field_type) - - def test_bool_op(self): - self.assertFalse(self._ft) - self._ft.append_field('a', bt2.StringFieldType()) - self.assertTrue(self._ft) - - def test_len(self): - ft = bt2.StringFieldType() - self._ft.append_field('a', ft) - self._ft.append_field('b', ft) - self._ft.append_field('c', ft) - self.assertEqual(len(self._ft), 3) - - def test_getitem(self): - a_ft = bt2.IntegerFieldType(32) - b_ft = bt2.StringFieldType() - c_ft = bt2.FloatingPointNumberFieldType() - self._ft.append_field('a', a_ft) - self._ft.append_field('b', b_ft) - self._ft.append_field('c', c_ft) - self.assertEqual(self._ft['b'], b_ft) - - def test_getitem_invalid_key_type(self): - with self.assertRaises(TypeError): - self._ft[0] - - def test_getitem_invalid_key(self): - with self.assertRaises(KeyError): - self._ft['no way'] - - def test_contains(self): - self.assertFalse('a' in self._ft) - self._ft.append_field('a', bt2.StringFieldType()) - self.assertTrue('a' in self._ft) - - def test_iter(self): - a_ft = bt2.IntegerFieldType(32) - b_ft = bt2.StringFieldType() - c_ft = bt2.FloatingPointNumberFieldType() - fields = ( - ('a', a_ft), - ('b', b_ft), - ('c', c_ft), - ) - - for field in fields: - self._ft.append_field(*field) - - for (name, ft_field_type), field in zip(self._ft.items(), fields): - self.assertEqual(name, field[0]) - self.assertEqual(ft_field_type, field[1]) - - def test_at_index(self): - a_ft = bt2.IntegerFieldType(32) - b_ft = bt2.StringFieldType() - c_ft = bt2.FloatingPointNumberFieldType() - self._ft.append_field('c', c_ft) - self._ft.append_field('a', a_ft) - self._ft.append_field('b', b_ft) - self.assertEqual(self._ft.at_index(1), a_ft) - - def test_at_index_invalid(self): - self._ft.append_field('c', bt2.IntegerFieldType(32)) - - with self.assertRaises(TypeError): - self._ft.at_index('yes') - - def test_at_index_out_of_bounds_after(self): - self._ft.append_field('c', bt2.IntegerFieldType(32)) - - with self.assertRaises(IndexError): - self._ft.at_index(len(self._ft)) - - -@unittest.skip("this is broken") -class StructureFieldTypeTestCase(_TestFieldContainer, unittest.TestCase): - def setUp(self): - self._ft = bt2.StructureFieldType() - - def tearDown(self): - del self._ft - - def test_create_default(self): - self.assertEqual(self._ft.alignment, 1) - - def test_create_with_min_alignment(self): - ft = bt2.StructureFieldType(8) - self.assertEqual(ft.alignment, 8) - - def test_assign_alignment(self): - with self.assertRaises(AttributeError): - self._ft.alignment = 32 - - def test_assign_min_alignment(self): - self._ft.min_alignment = 64 - self.assertTrue(self._ft.alignment >= 64) - - def test_assign_invalid_min_alignment(self): - with self.assertRaises(ValueError): - self._ft.min_alignment = 23 - - def test_assign_get_min_alignment(self): - with self.assertRaises(AttributeError): - self._ft.min_alignment - - def test_create_field(self): - field = self._ft() - self.assertIsInstance(field, bt2.fields._StructureField) - - def test_create_field_init_invalid(self): - with self.assertRaises(bt2.Error): - field = self._ft(23) - - -@unittest.skip("this is broken") -class VariantFieldTypeTestCase(_TestFieldContainer, unittest.TestCase): - def setUp(self): - self._ft = bt2.VariantFieldType('path.to.tag') - - def tearDown(self): - del self._ft - - def test_create_default(self): - self.assertEqual(self._ft.tag_name, 'path.to.tag') - - def test_create_invalid_tag_name(self): - with self.assertRaises(TypeError): - self._ft = bt2.VariantFieldType(23) - - def test_assign_tag_name(self): - self._ft.tag_name = 'a.different.tag' - self.assertEqual(self._ft.tag_name, 'a.different.tag') - - def test_assign_invalid_tag_name(self): - with self.assertRaises(TypeError): - self._ft.tag_name = -17 - - -@unittest.skip("this is broken") -class ArrayFieldTypeTestCase(_TestInvalidEq, _TestCopySimple, - unittest.TestCase): - def setUp(self): - self._elem_ft = bt2.IntegerFieldType(23) - self._ft = bt2.ArrayFieldType(self._elem_ft, 45) - - def tearDown(self): - del self._ft - del self._elem_ft - - def test_create_default(self): - self.assertEqual(self._ft.element_field_type, self._elem_ft) - self.assertEqual(self._ft.length, 45) - - def test_create_invalid_field_type(self): - with self.assertRaises(TypeError): - self._ft = bt2.ArrayFieldType(object(), 45) - - def test_create_invalid_length(self): - with self.assertRaises(ValueError): - self._ft = bt2.ArrayFieldType(bt2.StringFieldType(), -17) - - def test_create_invalid_length_type(self): - with self.assertRaises(TypeError): - self._ft = bt2.ArrayFieldType(bt2.StringFieldType(), 'the length') - - def test_create_field(self): - field = self._ft() - self.assertIsInstance(field, bt2.fields._ArrayField) - - def test_create_field_init_invalid(self): - with self.assertRaises(bt2.Error): - field = self._ft(23) - - -@unittest.skip("this is broken") -class SequenceFieldTypeTestCase(_TestInvalidEq, _TestCopySimple, - unittest.TestCase): - def setUp(self): - self._elem_ft = bt2.IntegerFieldType(23) - self._ft = bt2.SequenceFieldType(self._elem_ft, 'the.length') - - def tearDown(self): - del self._ft - del self._elem_ft - - def test_create_default(self): - self.assertEqual(self._ft.element_field_type, self._elem_ft) - self.assertEqual(self._ft.length_name, 'the.length') - - 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.SequenceFieldType(bt2.StringFieldType(), 17) - - def test_create_field(self): - field = self._ft() - self.assertIsInstance(field, bt2.fields._SequenceField) - - def test_create_field_init_invalid(self): - with self.assertRaises(bt2.Error): - field = self._ft(23) diff --git a/tests/bindings/python/bt2/test_fields.py b/tests/bindings/python/bt2/test_fields.py index 6ea248e84..f4446222c 100644 --- a/tests/bindings/python/bt2/test_fields.py +++ b/tests/bindings/python/bt2/test_fields.py @@ -519,19 +519,19 @@ class _TestNumericField(_TestCopySimple): def test_is_set(self): raw = self._def_value - field = self._ft() + field = self._fc() self.assertFalse(field.is_set) field.value = raw self.assertTrue(field.is_set) def test_reset(self): raw = self._def_value - field = self._ft() + field = self._fc() field.value = raw self.assertTrue(field.is_set) field.reset() self.assertFalse(field.is_set) - other = self._ft() + other = self._fc() self.assertEqual(other, field) @@ -736,7 +736,7 @@ class _TestIntegerFieldCommon(_TestNumericField): def test_assign_int_field(self): raw = 999 - field = self._ft() + field = self._fc() field.value = raw self._def.value = field self.assertEqual(self._def, raw) @@ -751,15 +751,15 @@ class _TestIntegerFieldCommon(_TestNumericField): self._def.value = 'yes' def test_assign_uint(self): - ft = bt2.IntegerFieldType(size=32, is_signed=False) - field = ft() + fc = bt2.IntegerFieldClass(size=32, is_signed=False) + field = fc() raw = 1777 field.value = 1777 self.assertEqual(field, raw) def test_assign_uint_invalid_neg(self): - ft = bt2.IntegerFieldType(size=32, is_signed=False) - field = ft() + fc = bt2.IntegerFieldClass(size=32, is_signed=False) + field = fc() with self.assertRaises(ValueError): field.value = -23 @@ -768,7 +768,7 @@ class _TestIntegerFieldCommon(_TestNumericField): self.assertEqual(str(self._def), str(self._def_value)) def test_str_op_unset(self): - self.assertEqual(str(self._ft()), 'Unset') + self.assertEqual(str(self._fc()), 'Unset') _inject_numeric_testing_methods(_TestIntegerFieldCommon) @@ -777,15 +777,15 @@ _inject_numeric_testing_methods(_TestIntegerFieldCommon) @unittest.skip("this is broken") class IntegerFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase): def setUp(self): - self._ft = bt2.IntegerFieldType(25, is_signed=True) - self._field = self._ft() - self._def = self._ft() + self._fc = bt2.IntegerFieldClass(25, is_signed=True) + self._field = self._fc() + self._def = self._fc() self._def.value = 17 self._def_value = 17 self._def_new_value = -101 def tearDown(self): - del self._ft + del self._fc del self._field del self._def @@ -793,19 +793,19 @@ class IntegerFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase): @unittest.skip("this is broken") class EnumerationFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase): def setUp(self): - self._ft = bt2.EnumerationFieldType(size=32, is_signed=True) - self._ft.add_mapping('whole range', -(2 ** 31), (2 ** 31) - 1) - self._ft.add_mapping('something', 17) - self._ft.add_mapping('speaker', 12, 16) - self._ft.add_mapping('can', 18, 2540) - self._ft.add_mapping('zip', -45, 1001) - self._def = self._ft() + self._fc = bt2.EnumerationFieldClass(size=32, is_signed=True) + self._fc.add_mapping('whole range', -(2 ** 31), (2 ** 31) - 1) + self._fc.add_mapping('something', 17) + self._fc.add_mapping('speaker', 12, 16) + self._fc.add_mapping('can', 18, 2540) + self._fc.add_mapping('zip', -45, 1001) + self._def = self._fc() self._def.value = 17 self._def_value = 17 self._def_new_value = -101 def tearDown(self): - del self._ft + del self._fc del self._def def test_mappings(self): @@ -844,21 +844,21 @@ class EnumerationFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase): self.assertTrue(expected_string_found) def test_str_op_unset(self): - self.assertEqual(str(self._ft()), 'Unset') + self.assertEqual(str(self._fc()), 'Unset') @unittest.skip("this is broken") class FloatingPointNumberFieldTestCase(_TestNumericField, unittest.TestCase): def setUp(self): - self._ft = bt2.FloatingPointNumberFieldType() - self._field = self._ft() - self._def = self._ft() + self._fc = bt2.FloatingPointNumberFieldClass() + self._field = self._fc() + self._def = self._fc() self._def.value = 52.7 self._def_value = 52.7 self._def_new_value = -17.164857 def tearDown(self): - del self._ft + del self._fc del self._field del self._def @@ -885,8 +885,8 @@ class FloatingPointNumberFieldTestCase(_TestNumericField, unittest.TestCase): self.assertEqual(self._def, float(raw)) def test_assign_int_field(self): - ft = bt2.IntegerFieldType(32) - field = ft() + fc = bt2.IntegerFieldClass(32) + field = fc() raw = 999 field.value = raw self._def.value = field @@ -898,8 +898,8 @@ class FloatingPointNumberFieldTestCase(_TestNumericField, unittest.TestCase): self.assertEqual(self._def, raw) def test_assign_float_field(self): - ft = bt2.FloatingPointNumberFieldType(32) - field = ft() + fc = bt2.FloatingPointNumberFieldClass(32) + field = fc() raw = 101.32 field.value = raw self._def.value = field @@ -931,7 +931,7 @@ class FloatingPointNumberFieldTestCase(_TestNumericField, unittest.TestCase): self.assertEqual(str(self._def), str(self._def_value)) def test_str_op_unset(self): - self.assertEqual(str(self._ft()), 'Unset') + self.assertEqual(str(self._fc()), 'Unset') _inject_numeric_testing_methods(FloatingPointNumberFieldTestCase) @@ -939,14 +939,14 @@ _inject_numeric_testing_methods(FloatingPointNumberFieldTestCase) @unittest.skip("this is broken") class StringFieldTestCase(_TestCopySimple, unittest.TestCase): def setUp(self): - self._ft = bt2.StringFieldType() + self._fc = bt2.StringFieldClass() self._def_value = 'Hello, World!' - self._def = self._ft() + self._def = self._fc() self._def.value = self._def_value self._def_new_value = 'Yes!' def tearDown(self): - del self._ft + del self._fc del self._def def test_assign_int(self): @@ -954,8 +954,8 @@ class StringFieldTestCase(_TestCopySimple, unittest.TestCase): self._def.value = 283 def test_assign_string_field(self): - ft = bt2.StringFieldType() - field = ft() + fc = bt2.StringFieldClass() + field = fc() raw = 'zorg' field.value = raw self.assertEqual(field, raw) @@ -967,50 +967,50 @@ class StringFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertNotEqual(self._def, 23) def test_lt_vstring(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' - s2 = self._ft() + s2 = self._fc() s2.value = 'bateau' self.assertLess(s1, s2) def test_lt_string(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' self.assertLess(s1, 'bateau') def test_le_vstring(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' - s2 = self._ft() + s2 = self._fc() s2.value = 'bateau' self.assertLessEqual(s1, s2) def test_le_string(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' self.assertLessEqual(s1, 'bateau') def test_gt_vstring(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' - s2 = self._ft() + s2 = self._fc() s2.value = 'bateau' self.assertGreater(s2, s1) def test_gt_string(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' self.assertGreater('bateau', s1) def test_ge_vstring(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' - s2 = self._ft() + s2 = self._fc() s2.value = 'bateau' self.assertGreaterEqual(s2, s1) def test_ge_string(self): - s1 = self._ft() + s1 = self._fc() s1.value = 'allo' self.assertGreaterEqual('bateau', s1) @@ -1021,7 +1021,7 @@ class StringFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertEqual(str(self._def), str(self._def_value)) def test_str_op_unset(self): - self.assertEqual(str(self._ft()), 'Unset') + self.assertEqual(str(self._fc()), 'Unset') def test_len(self): self.assertEqual(len(self._def), len(self._def_value)) @@ -1036,8 +1036,8 @@ class StringFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertEqual(self._def, self._def_value) def test_append_string_field(self): - ft = bt2.StringFieldType() - field = ft() + fc = bt2.StringFieldClass() + field = fc() to_append = 'meow meow meow' field.value = to_append self._def += field @@ -1046,19 +1046,19 @@ class StringFieldTestCase(_TestCopySimple, unittest.TestCase): def test_is_set(self): raw = self._def_value - field = self._ft() + field = self._fc() self.assertFalse(field.is_set) field.value = raw self.assertTrue(field.is_set) def test_reset(self): raw = self._def_value - field = self._ft() + field = self._fc() field.value = raw self.assertTrue(field.is_set) field.reset() self.assertFalse(field.is_set) - other = self._ft() + other = self._fc() self.assertEqual(other, field) @@ -1078,8 +1078,8 @@ class _TestArraySequenceFieldCommon(_TestCopySimple): self.assertEqual(field, 1847) def test_eq(self): - ft = bt2.ArrayFieldType(self._elem_ft, 3) - field = ft() + fc = bt2.ArrayFieldClass(self._elem_fc, 3) + field = fc() field[0] = 45 field[1] = 1847 field[2] = 1948754 @@ -1089,15 +1089,15 @@ class _TestArraySequenceFieldCommon(_TestCopySimple): self.assertNotEqual(self._def, 23) def test_eq_diff_len(self): - ft = bt2.ArrayFieldType(self._elem_ft, 2) - field = ft() + fc = bt2.ArrayFieldClass(self._elem_fc, 2) + field = fc() field[0] = 45 field[1] = 1847 self.assertNotEqual(self._def, field) def test_eq_diff_content_same_len(self): - ft = bt2.ArrayFieldType(self._elem_ft, 3) - field = ft() + fc = bt2.ArrayFieldClass(self._elem_fc, 3) + field = fc() field[0] = 45 field[1] = 1846 field[2] = 1948754 @@ -1108,16 +1108,16 @@ class _TestArraySequenceFieldCommon(_TestCopySimple): self.assertEqual(self._def[2], 24) def test_setitem_int_field(self): - int_field = self._elem_ft() + int_field = self._elem_fc() int_field.value = 19487 self._def[1] = int_field self.assertEqual(self._def[1], 19487) def test_setitem_non_basic_field(self): - elem_ft = bt2.StructureFieldType() - array_ft = bt2.ArrayFieldType(elem_ft, 3) - elem_field = elem_ft() - array_field = array_ft() + elem_fc = bt2.StructureFieldClass() + array_fc = bt2.ArrayFieldClass(elem_fc, 3) + elem_field = elem_fc() + array_field = array_fc() with self.assertRaises(TypeError): array_field[1] = 23 @@ -1170,13 +1170,13 @@ class _TestArraySequenceFieldCommon(_TestCopySimple): self._def.value = values def test_value_complex_type(self): - struct_ft = bt2.StructureFieldType() - int_ft = bt2.IntegerFieldType(32) - str_ft = bt2.StringFieldType() - struct_ft.append_field(field_type=int_ft, name='an_int') - struct_ft.append_field(field_type=str_ft, name='a_string') - struct_ft.append_field(field_type=int_ft, name='another_int') - array_ft = bt2.ArrayFieldType(struct_ft, 3) + struct_fc = bt2.StructureFieldClass() + int_fc = bt2.IntegerFieldClass(32) + str_fc = bt2.StringFieldClass() + struct_fc.append_field(field_class=int_fc, name='an_int') + struct_fc.append_field(field_class=str_fc, name='a_string') + struct_fc.append_field(field_class=int_fc, name='another_int') + array_fc = bt2.ArrayFieldClass(struct_fc, 3) values = [ { 'an_int': 42, @@ -1195,7 +1195,7 @@ class _TestArraySequenceFieldCommon(_TestCopySimple): }, ] - array = array_ft() + array = array_fc() array.value = values self.assertEqual(values, array) values[0]['an_int'] = 'a string' @@ -1204,19 +1204,19 @@ class _TestArraySequenceFieldCommon(_TestCopySimple): def test_is_set(self): raw = self._def_value - field = self._ft() + field = self._fc() self.assertFalse(field.is_set) field.value = raw self.assertTrue(field.is_set) def test_reset(self): raw = self._def_value - field = self._ft() + field = self._fc() field.value = raw self.assertTrue(field.is_set) field.reset() self.assertFalse(field.is_set) - other = self._ft() + other = self._fc() self.assertEqual(other, field) def test_str_op(self): @@ -1226,23 +1226,23 @@ class _TestArraySequenceFieldCommon(_TestCopySimple): self.assertEqual(expected_string, s) def test_str_op_unset(self): - self.assertEqual(str(self._ft()), 'Unset') + self.assertEqual(str(self._fc()), 'Unset') @unittest.skip("this is broken") class ArrayFieldTestCase(_TestArraySequenceFieldCommon, unittest.TestCase): def setUp(self): - self._elem_ft = bt2.IntegerFieldType(32) - self._ft = bt2.ArrayFieldType(self._elem_ft, 3) - self._def = self._ft() + self._elem_fc = bt2.IntegerFieldClass(32) + self._fc = bt2.ArrayFieldClass(self._elem_fc, 3) + self._def = self._fc() self._def[0] = 45 self._def[1] = 1847 self._def[2] = 1948754 self._def_value = [45, 1847, 1948754] def tearDown(self): - del self._elem_ft - del self._ft + del self._elem_fc + del self._fc del self._def def test_value_wrong_len(self): @@ -1254,10 +1254,10 @@ class ArrayFieldTestCase(_TestArraySequenceFieldCommon, unittest.TestCase): @unittest.skip("this is broken") class SequenceFieldTestCase(_TestArraySequenceFieldCommon, unittest.TestCase): def setUp(self): - self._elem_ft = bt2.IntegerFieldType(32) - self._ft = bt2.SequenceFieldType(self._elem_ft, 'the.length') - self._def = self._ft() - self._length_field = self._elem_ft(3) + self._elem_fc = bt2.IntegerFieldClass(32) + self._fc = bt2.SequenceFieldClass(self._elem_fc, 'the.length') + self._def = self._fc() + self._length_field = self._elem_fc(3) self._def.length_field = self._length_field self._def[0] = 45 self._def[1] = 1847 @@ -1265,8 +1265,8 @@ class SequenceFieldTestCase(_TestArraySequenceFieldCommon, unittest.TestCase): self._def_value = [45, 1847, 1948754] def tearDown(self): - del self._elem_ft - del self._ft + del self._elem_fc + del self._fc del self._def del self._length_field @@ -1289,16 +1289,16 @@ class SequenceFieldTestCase(_TestArraySequenceFieldCommon, unittest.TestCase): @unittest.skip("this is broken") class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): def setUp(self): - self._ft0 = bt2.IntegerFieldType(32, is_signed=True) - self._ft1 = bt2.StringFieldType() - self._ft2 = bt2.FloatingPointNumberFieldType() - self._ft3 = bt2.IntegerFieldType(17) - self._ft = bt2.StructureFieldType() - self._ft.append_field('A', self._ft0) - self._ft.append_field('B', self._ft1) - self._ft.append_field('C', self._ft2) - self._ft.append_field('D', self._ft3) - self._def = self._ft() + self._fc0 = bt2.IntegerFieldClass(32, is_signed=True) + self._fc1 = bt2.StringFieldClass() + self._fc2 = bt2.FloatingPointNumberFieldClass() + self._fc3 = bt2.IntegerFieldClass(17) + self._fc = bt2.StructureFieldClass() + self._fc.append_field('A', self._fc0) + self._fc.append_field('B', self._fc1) + self._fc.append_field('C', self._fc2) + self._fc.append_field('D', self._fc3) + self._def = self._fc() self._def['A'] = -1872 self._def['B'] = 'salut' self._def['C'] = 17.5 @@ -1311,11 +1311,11 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): } def tearDown(self): - del self._ft0 - del self._ft1 - del self._ft2 - del self._ft3 - del self._ft + del self._fc0 + del self._fc1 + del self._fc2 + del self._fc3 + del self._fc del self._def def _modify_def(self): @@ -1325,8 +1325,8 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertTrue(self._def) def test_bool_op_false(self): - ft = bt2.StructureFieldType() - field = ft() + fc = bt2.StructureFieldClass() + field = fc() self.assertFalse(field) def test_len(self): @@ -1339,15 +1339,15 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): def test_at_index_out_of_bounds_after(self): with self.assertRaises(IndexError): - self._def.at_index(len(self._ft)) + self._def.at_index(len(self._fc)) def test_eq(self): - ft = bt2.StructureFieldType() - ft.append_field('A', self._ft0) - ft.append_field('B', self._ft1) - ft.append_field('C', self._ft2) - ft.append_field('D', self._ft3) - field = ft() + fc = bt2.StructureFieldClass() + fc.append_field('A', self._fc0) + fc.append_field('B', self._fc1) + fc.append_field('C', self._fc2) + fc.append_field('D', self._fc3) + field = fc() field['A'] = -1872 field['B'] = 'salut' field['C'] = 17.5 @@ -1358,23 +1358,23 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertNotEqual(self._def, 23) def test_eq_diff_len(self): - ft = bt2.StructureFieldType() - ft.append_field('A', self._ft0) - ft.append_field('B', self._ft1) - ft.append_field('C', self._ft2) - field = ft() + fc = bt2.StructureFieldClass() + fc.append_field('A', self._fc0) + fc.append_field('B', self._fc1) + fc.append_field('C', self._fc2) + field = fc() field['A'] = -1872 field['B'] = 'salut' field['C'] = 17.5 self.assertNotEqual(self._def, field) def test_eq_diff_content_same_len(self): - ft = bt2.StructureFieldType() - ft.append_field('A', self._ft0) - ft.append_field('B', self._ft1) - ft.append_field('C', self._ft2) - ft.append_field('D', self._ft3) - field = ft() + fc = bt2.StructureFieldClass() + fc.append_field('A', self._fc0) + fc.append_field('B', self._fc1) + fc.append_field('C', self._fc2) + fc.append_field('D', self._fc3) + field = fc() field['A'] = -1872 field['B'] = 'salut' field['C'] = 17.4 @@ -1382,12 +1382,12 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertNotEqual(self._def, field) def test_eq_same_content_diff_keys(self): - ft = bt2.StructureFieldType() - ft.append_field('A', self._ft0) - ft.append_field('B', self._ft1) - ft.append_field('E', self._ft2) - ft.append_field('D', self._ft3) - field = ft() + fc = bt2.StructureFieldClass() + fc.append_field('A', self._fc0) + fc.append_field('B', self._fc1) + fc.append_field('E', self._fc2) + fc.append_field('D', self._fc3) + field = fc() field['A'] = -1872 field['B'] = 'salut' field['E'] = 17.4 @@ -1399,18 +1399,18 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertEqual(self._def['C'], -18.47) def test_setitem_int_field(self): - int_ft = bt2.IntegerFieldType(16) - int_field = int_ft() + int_fc = bt2.IntegerFieldClass(16) + int_field = int_fc() int_field.value = 19487 self._def['D'] = int_field self.assertEqual(self._def['D'], 19487) def test_setitem_non_basic_field(self): - elem_ft = bt2.StructureFieldType() - elem_field = elem_ft() - struct_ft = bt2.StructureFieldType() - struct_ft.append_field('A', elem_ft) - struct_field = struct_ft() + elem_fc = bt2.StructureFieldClass() + elem_field = elem_fc() + struct_fc = bt2.StructureFieldClass() + struct_fc.append_field('A', elem_fc) + struct_field = struct_fc() # Will fail on access to .items() of the value with self.assertRaises(AttributeError): @@ -1453,19 +1453,19 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertEqual(self._def, orig_values) def test_set_value(self): - int_ft = bt2.IntegerFieldType(32) - str_ft = bt2.StringFieldType() - struct_ft = bt2.StructureFieldType() - struct_ft.append_field(field_type=int_ft, name='an_int') - struct_ft.append_field(field_type=str_ft, name='a_string') - struct_ft.append_field(field_type=int_ft, name='another_int') + int_fc = bt2.IntegerFieldClass(32) + str_fc = bt2.StringFieldClass() + struct_fc = bt2.StructureFieldClass() + struct_fc.append_field(field_class=int_fc, name='an_int') + struct_fc.append_field(field_class=str_fc, name='a_string') + struct_fc.append_field(field_class=int_fc, name='another_int') values = { 'an_int': 42, 'a_string': 'hello', 'another_int': 66 } - struct = struct_ft() + struct = struct_fc() struct.value = values self.assertEqual(values, struct) @@ -1480,12 +1480,12 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): struct.value = unknown_key_values def test_value_rollback(self): - int_ft = bt2.IntegerFieldType(32) - str_ft = bt2.StringFieldType() - struct_ft = bt2.StructureFieldType() - struct_ft.append_field(field_type=int_ft, name='an_int') - struct_ft.append_field(field_type=str_ft, name='a_string') - struct_ft.append_field(field_type=int_ft, name='another_int') + int_fc = bt2.IntegerFieldClass(32) + str_fc = bt2.StringFieldClass() + struct_fc = bt2.StructureFieldClass() + struct_fc.append_field(field_class=int_fc, name='an_int') + struct_fc.append_field(field_class=str_fc, name='a_string') + struct_fc.append_field(field_class=int_fc, name='another_int') values = { 'an_int': 42, 'a_string': 'hello', @@ -1499,19 +1499,19 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): 'another_int': 66 } - int_ft = bt2.IntegerFieldType(32) - str_ft = bt2.StringFieldType() - struct_ft = bt2.StructureFieldType() - struct_ft.append_field(field_type=int_ft, name='an_int') - struct_ft.append_field(field_type=str_ft, name='a_string') - struct_ft.append_field(field_type=int_ft, name='another_int') + int_fc = bt2.IntegerFieldClass(32) + str_fc = bt2.StringFieldClass() + struct_fc = bt2.StructureFieldClass() + struct_fc.append_field(field_class=int_fc, name='an_int') + struct_fc.append_field(field_class=str_fc, name='a_string') + struct_fc.append_field(field_class=int_fc, name='another_int') - struct = struct_ft() + struct = struct_fc() self.assertFalse(struct.is_set) struct.value = values self.assertTrue(struct.is_set) - struct = struct_ft() + struct = struct_fc() struct['an_int'].value = 42 self.assertFalse(struct.is_set) @@ -1522,18 +1522,18 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): 'another_int': 66 } - int_ft = bt2.IntegerFieldType(32) - str_ft = bt2.StringFieldType() - struct_ft = bt2.StructureFieldType() - struct_ft.append_field(field_type=int_ft, name='an_int') - struct_ft.append_field(field_type=str_ft, name='a_string') - struct_ft.append_field(field_type=int_ft, name='another_int') + int_fc = bt2.IntegerFieldClass(32) + str_fc = bt2.StringFieldClass() + struct_fc = bt2.StructureFieldClass() + struct_fc.append_field(field_class=int_fc, name='an_int') + struct_fc.append_field(field_class=str_fc, name='a_string') + struct_fc.append_field(field_class=int_fc, name='another_int') - struct = struct_ft() + struct = struct_fc() struct.value = values self.assertTrue(struct.is_set) struct.reset() - self.assertEqual(struct_ft(), struct) + self.assertEqual(struct_fc(), struct) def test_str_op(self): expected_string_found = False @@ -1551,39 +1551,39 @@ class StructureFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertTrue(expected_string_found) def test_str_op_unset(self): - self.assertEqual(str(self._ft()), 'Unset') + self.assertEqual(str(self._fc()), 'Unset') @unittest.skip("this is broken") class VariantFieldTestCase(_TestCopySimple, unittest.TestCase): def setUp(self): - self._tag_ft = bt2.EnumerationFieldType(size=32) - self._tag_ft.add_mapping('corner', 23) - self._tag_ft.add_mapping('zoom', 17, 20) - self._tag_ft.add_mapping('mellotron', 1001) - self._tag_ft.add_mapping('giorgio', 2000, 3000) - self._ft0 = bt2.IntegerFieldType(32, is_signed=True) - self._ft1 = bt2.StringFieldType() - self._ft2 = bt2.FloatingPointNumberFieldType() - self._ft3 = bt2.IntegerFieldType(17) - self._ft = bt2.VariantFieldType('salut', self._tag_ft) - self._ft.append_field('corner', self._ft0) - self._ft.append_field('zoom', self._ft1) - self._ft.append_field('mellotron', self._ft2) - self._ft.append_field('giorgio', self._ft3) - self._def = self._ft() + self._tag_fc = bt2.EnumerationFieldClass(size=32) + self._tag_fc.add_mapping('corner', 23) + self._tag_fc.add_mapping('zoom', 17, 20) + self._tag_fc.add_mapping('mellotron', 1001) + self._tag_fc.add_mapping('giorgio', 2000, 3000) + self._fc0 = bt2.IntegerFieldClass(32, is_signed=True) + self._fc1 = bt2.StringFieldClass() + self._fc2 = bt2.FloatingPointNumberFieldClass() + self._fc3 = bt2.IntegerFieldClass(17) + self._fc = bt2.VariantFieldClass('salut', self._tag_fc) + self._fc.append_field('corner', self._fc0) + self._fc.append_field('zoom', self._fc1) + self._fc.append_field('mellotron', self._fc2) + self._fc.append_field('giorgio', self._fc3) + self._def = self._fc() def tearDown(self): - del self._tag_ft - del self._ft0 - del self._ft1 - del self._ft2 - del self._ft3 - del self._ft + del self._tag_fc + del self._fc0 + del self._fc1 + del self._fc2 + del self._fc3 + del self._fc del self._def def test_bool_op_true(self): - tag_field = self._tag_ft(1001) + tag_field = self._tag_fc(1001) self._def.field(tag_field).value = -17.34 self.assertTrue(self._def) @@ -1594,7 +1594,7 @@ class VariantFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertIsNone(self._def.tag_field) def test_tag_field(self): - tag_field = self._tag_ft(2800) + tag_field = self._tag_fc(2800) self._def.field(tag_field).value = 1847 self.assertEqual(self._def.tag_field, tag_field) self.assertEqual(self._def.tag_field.addr, tag_field.addr) @@ -1603,35 +1603,35 @@ class VariantFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertIsNone(self._def.selected_field) def test_selected_field(self): - var_field1 = self._ft() - tag_field1 = self._tag_ft(1001) + var_field1 = self._fc() + tag_field1 = self._tag_fc(1001) var_field1.field(tag_field1).value = -17.34 self.assertEqual(var_field1.field(), -17.34) self.assertEqual(var_field1.selected_field, -17.34) - var_field2 = self._ft() - tag_field2 = self._tag_ft(2500) + var_field2 = self._fc() + tag_field2 = self._tag_fc(2500) var_field2.field(tag_field2).value = 1921 self.assertEqual(var_field2.field(), 1921) self.assertEqual(var_field2.selected_field, 1921) def test_eq(self): - tag_ft = bt2.EnumerationFieldType(size=32) - tag_ft.add_mapping('corner', 23) - tag_ft.add_mapping('zoom', 17, 20) - tag_ft.add_mapping('mellotron', 1001) - tag_ft.add_mapping('giorgio', 2000, 3000) - ft0 = bt2.IntegerFieldType(32, is_signed=True) - ft1 = bt2.StringFieldType() - ft2 = bt2.FloatingPointNumberFieldType() - ft3 = bt2.IntegerFieldType(17) - ft = bt2.VariantFieldType('salut', tag_ft) - ft.append_field('corner', ft0) - ft.append_field('zoom', ft1) - ft.append_field('mellotron', ft2) - ft.append_field('giorgio', ft3) - field = ft() - field_tag = tag_ft(23) - def_tag = self._tag_ft(23) + tag_fc = bt2.EnumerationFieldClass(size=32) + tag_fc.add_mapping('corner', 23) + tag_fc.add_mapping('zoom', 17, 20) + tag_fc.add_mapping('mellotron', 1001) + tag_fc.add_mapping('giorgio', 2000, 3000) + fc0 = bt2.IntegerFieldClass(32, is_signed=True) + fc1 = bt2.StringFieldClass() + fc2 = bt2.FloatingPointNumberFieldClass() + fc3 = bt2.IntegerFieldClass(17) + fc = bt2.VariantFieldClass('salut', tag_fc) + fc.append_field('corner', fc0) + fc.append_field('zoom', fc1) + fc.append_field('mellotron', fc2) + fc.append_field('giorgio', fc3) + field = fc() + field_tag = tag_fc(23) + def_tag = self._tag_fc(23) field.field(field_tag).value = 1774 self._def.field(def_tag).value = 1774 self.assertEqual(self._def, field) @@ -1641,12 +1641,12 @@ class VariantFieldTestCase(_TestCopySimple, unittest.TestCase): def test_is_set(self): self.assertFalse(self._def.is_set) - tag_field = self._tag_ft(2800) + tag_field = self._tag_fc(2800) self._def.field(tag_field).value = 684 self.assertTrue(self._def.is_set) def test_reset(self): - tag_field = self._tag_ft(2800) + tag_field = self._tag_fc(2800) self._def.field(tag_field).value = 684 self._def.reset() self.assertFalse(self._def.is_set) @@ -1654,22 +1654,22 @@ class VariantFieldTestCase(_TestCopySimple, unittest.TestCase): self.assertIsNone(self._def.tag_field) def test_str_op_int(self): - v = self._ft() - v.field(self._tag_ft(23)).value = 42 - f = self._ft0(42) + v = self._fc() + v.field(self._tag_fc(23)).value = 42 + f = self._fc0(42) self.assertEqual(str(f), str(v)) def test_str_op_str(self): - v = self._ft() - v.field(self._tag_ft(18)).value = 'some test string' - f = self._ft1('some test string') + v = self._fc() + v.field(self._tag_fc(18)).value = 'some test string' + f = self._fc1('some test string') self.assertEqual(str(f), str(v)) def test_str_op_flt(self): - v = self._ft() - v.field(self._tag_ft(1001)).value = 14.4245 - f = self._ft2(14.4245) + v = self._fc() + v.field(self._tag_fc(1001)).value = 14.4245 + f = self._fc2(14.4245) self.assertEqual(str(f), str(v)) def test_str_op_unset(self): - self.assertEqual(str(self._ft()), 'Unset') + self.assertEqual(str(self._fc()), 'Unset') diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 6d8bf5902..9021821a1 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -240,10 +240,10 @@ class GraphTestCase(unittest.TestCase): self._trace = bt2.Trace() self._sc = bt2.StreamClass() self._ec = bt2.EventClass('salut') - self._my_int_ft = bt2.IntegerFieldType(32) - self._ec.payload_field_type = bt2.StructureFieldType() - self._ec.payload_field_type += collections.OrderedDict([ - ('my_int', self._my_int_ft), + self._my_int_fc = bt2.IntegerFieldClass(32) + self._ec.payload_field_class = bt2.StructureFieldClass() + self._ec.payload_field_class += collections.OrderedDict([ + ('my_int', self._my_int_fc), ]) self._sc.add_event_class(self._ec) self._trace.add_stream_class(self._sc) @@ -312,10 +312,10 @@ class GraphTestCase(unittest.TestCase): self._trace = bt2.Trace() self._sc = bt2.StreamClass() self._ec = bt2.EventClass('salut') - self._my_int_ft = bt2.IntegerFieldType(32) - self._ec.payload_field_type = bt2.StructureFieldType() - self._ec.payload_field_type += collections.OrderedDict([ - ('my_int', self._my_int_ft), + self._my_int_fc = bt2.IntegerFieldClass(32) + self._ec.payload_field_class = bt2.StructureFieldClass() + self._ec.payload_field_class += collections.OrderedDict([ + ('my_int', self._my_int_fc), ]) self._sc.add_event_class(self._ec) self._trace.add_stream_class(self._sc) @@ -403,10 +403,10 @@ class GraphTestCase(unittest.TestCase): self._trace = bt2.Trace() self._sc = bt2.StreamClass() self._ec = bt2.EventClass('salut') - self._my_int_ft = bt2.IntegerFieldType(32) - self._ec.payload_field_type = bt2.StructureFieldType() - self._ec.payload_field_type += collections.OrderedDict([ - ('my_int', self._my_int_ft), + self._my_int_fc = bt2.IntegerFieldClass(32) + self._ec.payload_field_class = bt2.StructureFieldClass() + self._ec.payload_field_class += collections.OrderedDict([ + ('my_int', self._my_int_fc), ]) self._sc.add_event_class(self._ec) self._trace.add_stream_class(self._sc) diff --git a/tests/bindings/python/bt2/test_message.py b/tests/bindings/python/bt2/test_message.py index 6a61189ec..ac0f4bc19 100644 --- a/tests/bindings/python/bt2/test_message.py +++ b/tests/bindings/python/bt2/test_message.py @@ -10,17 +10,17 @@ class _MessageTestCase(unittest.TestCase): self._trace = bt2.Trace() self._sc = bt2.StreamClass() self._ec = bt2.EventClass('salut') - self._my_int_ft = bt2.IntegerFieldType(32) - self._ec.payload_field_type = bt2.StructureFieldType() - self._ec.payload_field_type += collections.OrderedDict([ - ('my_int', self._my_int_ft), + self._my_int_fc = bt2.IntegerFieldClass(32) + self._ec.payload_field_class = bt2.StructureFieldClass() + self._ec.payload_field_class += collections.OrderedDict([ + ('my_int', self._my_int_fc), ]) self._sc.add_event_class(self._ec) self._clock_class = bt2.ClockClass('allo', 1000) self._trace.add_clock_class(self._clock_class) - self._trace.packet_header_field_type = bt2.StructureFieldType() - self._trace.packet_header_field_type += collections.OrderedDict([ - ('hello', self._my_int_ft), + self._trace.packet_header_field_class = bt2.StructureFieldClass() + self._trace.packet_header_field_class += collections.OrderedDict([ + ('hello', self._my_int_fc), ]) self._trace.add_stream_class(self._sc) self._cc_prio_map = bt2.ClockClassPriorityMap() @@ -37,7 +37,7 @@ class _MessageTestCase(unittest.TestCase): del self._trace del self._sc del self._ec - del self._my_int_ft + del self._my_int_fc del self._clock_class del self._cc_prio_map del self._stream @@ -331,18 +331,18 @@ class DiscardedPacketsMessageTestCase(unittest.TestCase): self._sc = bt2.StreamClass() self._ec = bt2.EventClass('salut') self._clock_class = bt2.ClockClass('yo', 1000) - self._uint64_int_ft = bt2.IntegerFieldType(64, mapped_clock_class=self._clock_class) - self._my_int_ft = bt2.IntegerFieldType(32) - self._ec.payload_field_type = bt2.StructureFieldType() - self._ec.payload_field_type += collections.OrderedDict([ - ('my_int', self._my_int_ft), + self._uint64_int_fc = bt2.IntegerFieldClass(64, mapped_clock_class=self._clock_class) + self._my_int_fc = bt2.IntegerFieldClass(32) + self._ec.payload_field_class = bt2.StructureFieldClass() + self._ec.payload_field_class += collections.OrderedDict([ + ('my_int', self._my_int_fc), ]) self._sc.add_event_class(self._ec) - self._sc.packet_context_field_type = bt2.StructureFieldType() - self._sc.packet_context_field_type += collections.OrderedDict([ - ('packet_seq_num', self._my_int_ft), - ('timestamp_begin', self._uint64_int_ft), - ('timestamp_end', self._uint64_int_ft), + self._sc.packet_context_field_class = bt2.StructureFieldClass() + self._sc.packet_context_field_class += collections.OrderedDict([ + ('packet_seq_num', self._my_int_fc), + ('timestamp_begin', self._uint64_int_fc), + ('timestamp_end', self._uint64_int_fc), ]) self._trace.add_clock_class(self._clock_class) self._trace.add_stream_class(self._sc) @@ -353,8 +353,8 @@ class DiscardedPacketsMessageTestCase(unittest.TestCase): del self._sc del self._ec del self._clock_class - del self._uint64_int_ft - del self._my_int_ft + del self._uint64_int_fc + del self._my_int_fc del self._stream def _create_event(self, packet): @@ -456,18 +456,18 @@ class DiscardedEventsMessageTestCase(unittest.TestCase): self._sc = bt2.StreamClass() self._ec = bt2.EventClass('salut') self._clock_class = bt2.ClockClass('yo', 1000) - self._uint64_int_ft = bt2.IntegerFieldType(64, mapped_clock_class=self._clock_class) - self._my_int_ft = bt2.IntegerFieldType(32) - self._ec.payload_field_type = bt2.StructureFieldType() - self._ec.payload_field_type += collections.OrderedDict([ - ('my_int', self._my_int_ft), + self._uint64_int_fc = bt2.IntegerFieldClass(64, mapped_clock_class=self._clock_class) + self._my_int_fc = bt2.IntegerFieldClass(32) + self._ec.payload_field_class = bt2.StructureFieldClass() + self._ec.payload_field_class += collections.OrderedDict([ + ('my_int', self._my_int_fc), ]) self._sc.add_event_class(self._ec) - self._sc.packet_context_field_type = bt2.StructureFieldType() - self._sc.packet_context_field_type += collections.OrderedDict([ - ('events_discarded', self._my_int_ft), - ('timestamp_begin', self._uint64_int_ft), - ('timestamp_end', self._uint64_int_ft), + self._sc.packet_context_field_class = bt2.StructureFieldClass() + self._sc.packet_context_field_class += collections.OrderedDict([ + ('events_discarded', self._my_int_fc), + ('timestamp_begin', self._uint64_int_fc), + ('timestamp_end', self._uint64_int_fc), ]) self._trace.add_clock_class(self._clock_class) self._trace.add_stream_class(self._sc) @@ -478,8 +478,8 @@ class DiscardedEventsMessageTestCase(unittest.TestCase): del self._sc del self._ec del self._clock_class - del self._uint64_int_ft - del self._my_int_ft + del self._uint64_int_fc + del self._my_int_fc del self._stream def _create_event(self, packet): diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index 445612606..3f7e121af 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -135,10 +135,10 @@ class OutputPortMessageIteratorTestCase(unittest.TestCase): self._trace = bt2.Trace() self._sc = bt2.StreamClass() self._ec = bt2.EventClass('salut') - self._my_int_ft = bt2.IntegerFieldType(32) - self._ec.payload_field_type = bt2.StructureFieldType() - self._ec.payload_field_type += collections.OrderedDict([ - ('my_int', self._my_int_ft), + self._my_int_fc = bt2.IntegerFieldClass(32) + self._ec.payload_field_class = bt2.StructureFieldClass() + self._ec.payload_field_class += collections.OrderedDict([ + ('my_int', self._my_int_fc), ]) self._sc.add_event_class(self._ec) self._trace.add_stream_class(self._sc) diff --git a/tests/bindings/python/bt2/test_packet.py b/tests/bindings/python/bt2/test_packet.py index 65c268e87..bd5482ef9 100644 --- a/tests/bindings/python/bt2/test_packet.py +++ b/tests/bindings/python/bt2/test_packet.py @@ -15,69 +15,69 @@ class PacketTestCase(unittest.TestCase): def _create_packet(self, with_ph=True, with_pc=True): # event header - eh = bt2.StructureFieldType() + eh = bt2.StructureFieldClass() eh += OrderedDict(( - ('id', bt2.IntegerFieldType(8)), - ('ts', bt2.IntegerFieldType(32)), + ('id', bt2.IntegerFieldClass(8)), + ('ts', bt2.IntegerFieldClass(32)), )) # stream event context - sec = bt2.StructureFieldType() + sec = bt2.StructureFieldClass() sec += OrderedDict(( - ('cpu_id', bt2.IntegerFieldType(8)), - ('stuff', bt2.FloatingPointNumberFieldType()), + ('cpu_id', bt2.IntegerFieldClass(8)), + ('stuff', bt2.FloatingPointNumberFieldClass()), )) # packet context if with_pc: - pc = bt2.StructureFieldType() + pc = bt2.StructureFieldClass() pc += OrderedDict(( - ('something', bt2.IntegerFieldType(8)), - ('something_else', bt2.FloatingPointNumberFieldType()), + ('something', bt2.IntegerFieldClass(8)), + ('something_else', bt2.FloatingPointNumberFieldClass()), )) else: pc = None # stream class sc = bt2.StreamClass() - sc.packet_context_field_type = pc - sc.event_header_field_type = eh - sc.event_context_field_type = sec + sc.packet_context_field_class = pc + sc.event_header_field_class = eh + sc.event_context_field_class = sec # event context - ec = bt2.StructureFieldType() + ec = bt2.StructureFieldClass() ec += OrderedDict(( - ('ant', bt2.IntegerFieldType(16, is_signed=True)), - ('msg', bt2.StringFieldType()), + ('ant', bt2.IntegerFieldClass(16, is_signed=True)), + ('msg', bt2.StringFieldClass()), )) # event payload - ep = bt2.StructureFieldType() + ep = bt2.StructureFieldClass() ep += OrderedDict(( - ('giraffe', bt2.IntegerFieldType(32)), - ('gnu', bt2.IntegerFieldType(8)), - ('mosquito', bt2.IntegerFieldType(8)), + ('giraffe', bt2.IntegerFieldClass(32)), + ('gnu', bt2.IntegerFieldClass(8)), + ('mosquito', bt2.IntegerFieldClass(8)), )) # event class event_class = bt2.EventClass('ec') - event_class.context_field_type = ec - event_class.payload_field_type = ep + event_class.context_field_class = ec + event_class.payload_field_class = ep sc.add_event_class(event_class) # packet header if with_ph: - ph = bt2.StructureFieldType() + ph = bt2.StructureFieldClass() ph += OrderedDict(( - ('magic', bt2.IntegerFieldType(32)), - ('stream_id', bt2.IntegerFieldType(16)), + ('magic', bt2.IntegerFieldClass(32)), + ('stream_id', bt2.IntegerFieldClass(16)), )) else: ph = None # trace c;ass tc = bt2.Trace() - tc.packet_header_field_type = ph + tc.packet_header_field_class = ph tc.add_stream_class(sc) # stream diff --git a/tests/bindings/python/bt2/test_stream.py b/tests/bindings/python/bt2/test_stream.py index d1d37cc32..c3b7f65f5 100644 --- a/tests/bindings/python/bt2/test_stream.py +++ b/tests/bindings/python/bt2/test_stream.py @@ -15,63 +15,63 @@ class StreamTestCase(unittest.TestCase): def _create_stream(self, name='my_stream', stream_id=None): # event header - eh = bt2.StructureFieldType() + eh = bt2.StructureFieldClass() eh += OrderedDict(( - ('id', bt2.IntegerFieldType(8)), - ('ts', bt2.IntegerFieldType(32)), + ('id', bt2.IntegerFieldClass(8)), + ('ts', bt2.IntegerFieldClass(32)), )) # stream event context - sec = bt2.StructureFieldType() + sec = bt2.StructureFieldClass() sec += OrderedDict(( - ('cpu_id', bt2.IntegerFieldType(8)), - ('stuff', bt2.FloatingPointNumberFieldType()), + ('cpu_id', bt2.IntegerFieldClass(8)), + ('stuff', bt2.FloatingPointNumberFieldClass()), )) # packet context - pc = bt2.StructureFieldType() + pc = bt2.StructureFieldClass() pc += OrderedDict(( - ('something', bt2.IntegerFieldType(8)), - ('something_else', bt2.FloatingPointNumberFieldType()), + ('something', bt2.IntegerFieldClass(8)), + ('something_else', bt2.FloatingPointNumberFieldClass()), )) # stream class sc = bt2.StreamClass() - sc.packet_context_field_type = pc - sc.event_header_field_type = eh - sc.event_context_field_type = sec + sc.packet_context_field_class = pc + sc.event_header_field_class = eh + sc.event_context_field_class = sec # event context - ec = bt2.StructureFieldType() + ec = bt2.StructureFieldClass() ec += OrderedDict(( - ('ant', bt2.IntegerFieldType(16, is_signed=True)), - ('msg', bt2.StringFieldType()), + ('ant', bt2.IntegerFieldClass(16, is_signed=True)), + ('msg', bt2.StringFieldClass()), )) # event payload - ep = bt2.StructureFieldType() + ep = bt2.StructureFieldClass() ep += OrderedDict(( - ('giraffe', bt2.IntegerFieldType(32)), - ('gnu', bt2.IntegerFieldType(8)), - ('mosquito', bt2.IntegerFieldType(8)), + ('giraffe', bt2.IntegerFieldClass(32)), + ('gnu', bt2.IntegerFieldClass(8)), + ('mosquito', bt2.IntegerFieldClass(8)), )) # event class event_class = bt2.EventClass('ec') - event_class.context_field_type = ec - event_class.payload_field_type = ep + event_class.context_field_class = ec + event_class.payload_field_class = ep sc.add_event_class(event_class) # packet header - ph = bt2.StructureFieldType() + ph = bt2.StructureFieldClass() ph += OrderedDict(( - ('magic', bt2.IntegerFieldType(32)), - ('stream_id', bt2.IntegerFieldType(16)), + ('magic', bt2.IntegerFieldClass(32)), + ('stream_id', bt2.IntegerFieldClass(16)), )) # trace c;ass tc = bt2.Trace() - tc.packet_header_field_type = ph + tc.packet_header_field_class = ph tc.add_stream_class(sc) # stream diff --git a/tests/bindings/python/bt2/test_stream_class.py b/tests/bindings/python/bt2/test_stream_class.py index a1e320aee..5f8267bf0 100644 --- a/tests/bindings/python/bt2/test_stream_class.py +++ b/tests/bindings/python/bt2/test_stream_class.py @@ -7,45 +7,45 @@ import bt2 @unittest.skip("this is broken") class StreamClassTestCase(unittest.TestCase): def setUp(self): - self._packet_context_ft = bt2.StructureFieldType() - self._packet_context_ft.append_field('menu', bt2.FloatingPointNumberFieldType()) - self._packet_context_ft.append_field('sticker', bt2.StringFieldType()) - self._event_header_ft = bt2.StructureFieldType() - self._event_header_ft.append_field('id', bt2.IntegerFieldType(19)) - self._event_context_ft = bt2.StructureFieldType() - self._event_context_ft.append_field('msg', bt2.StringFieldType()) + self._packet_context_fc = bt2.StructureFieldClass() + self._packet_context_fc.append_field('menu', bt2.FloatingPointNumberFieldClass()) + self._packet_context_fc.append_field('sticker', bt2.StringFieldClass()) + self._event_header_fc = bt2.StructureFieldClass() + self._event_header_fc.append_field('id', bt2.IntegerFieldClass(19)) + self._event_context_fc = bt2.StructureFieldClass() + self._event_context_fc.append_field('msg', bt2.StringFieldClass()) self._ec1, self._ec2 = self._create_event_classes() self._sc = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(self._ec1, self._ec2)) def tearDown(self): - del self._packet_context_ft - del self._event_header_ft - del self._event_context_ft + del self._packet_context_fc + del self._event_header_fc + del self._event_context_fc del self._ec1 del self._sc def _create_event_classes(self): - context_ft = bt2.StructureFieldType() - context_ft.append_field('allo', bt2.StringFieldType()) - context_ft.append_field('zola', bt2.IntegerFieldType(18)) - payload_ft = bt2.StructureFieldType() - payload_ft.append_field('zoom', bt2.StringFieldType()) - ec1 = bt2.EventClass('event23', id=23, context_field_type=context_ft, - payload_field_type=payload_ft) - ec2 = bt2.EventClass('event17', id=17, context_field_type=payload_ft, - payload_field_type=context_ft) + context_fc = bt2.StructureFieldClass() + context_fc.append_field('allo', bt2.StringFieldClass()) + context_fc.append_field('zola', bt2.IntegerFieldClass(18)) + payload_fc = bt2.StructureFieldClass() + payload_fc.append_field('zoom', bt2.StringFieldClass()) + ec1 = bt2.EventClass('event23', id=23, context_field_class=context_fc, + payload_field_class=payload_fc) + ec2 = bt2.EventClass('event17', id=17, context_field_class=payload_fc, + payload_field_class=context_fc) return ec1, ec2 def test_create(self): self.assertEqual(self._sc.name, 'my_stream_class') self.assertEqual(self._sc.id, 12) - self.assertEqual(self._sc.packet_context_field_type, self._packet_context_ft) - self.assertEqual(self._sc.event_header_field_type, self._event_header_ft) - self.assertEqual(self._sc.event_context_field_type, self._event_context_ft) + self.assertEqual(self._sc.packet_context_field_class, self._packet_context_fc) + self.assertEqual(self._sc.event_header_field_class, self._event_header_fc) + self.assertEqual(self._sc.event_context_field_class, self._event_context_fc) self.assertEqual(self._sc[23], self._ec1) self.assertEqual(self._sc[17], self._ec2) self.assertEqual(len(self._sc), 2) @@ -70,41 +70,41 @@ class StreamClassTestCase(unittest.TestCase): sc = bt2.StreamClass() self.assertIsNone(sc.id) - def test_assign_packet_context_field_type(self): - self._sc.packet_context_field_type = self._event_context_ft - self.assertEqual(self._sc.packet_context_field_type, self._event_context_ft) + def test_assign_packet_context_field_class(self): + self._sc.packet_context_field_class = self._event_context_fc + self.assertEqual(self._sc.packet_context_field_class, self._event_context_fc) - def test_assign_no_packet_context_field_type(self): - self._sc.packet_context_field_type = None - self.assertIsNone(self._sc.packet_context_field_type) + def test_assign_no_packet_context_field_class(self): + self._sc.packet_context_field_class = None + self.assertIsNone(self._sc.packet_context_field_class) - def test_assign_invalid_packet_context_field_type(self): + def test_assign_invalid_packet_context_field_class(self): with self.assertRaises(TypeError): - self._sc.packet_context_field_type = 'lel' + self._sc.packet_context_field_class = 'lel' - def test_assign_event_header_field_type(self): - self._sc.event_header_field_type = self._event_header_ft - self.assertEqual(self._sc.event_header_field_type, self._event_header_ft) + def test_assign_event_header_field_class(self): + self._sc.event_header_field_class = self._event_header_fc + self.assertEqual(self._sc.event_header_field_class, self._event_header_fc) - def test_assign_no_event_header_field_type(self): - self._sc.event_header_field_type = None - self.assertIsNone(self._sc.event_header_field_type) + def test_assign_no_event_header_field_class(self): + self._sc.event_header_field_class = None + self.assertIsNone(self._sc.event_header_field_class) - def test_assign_invalid_event_header_field_type(self): + def test_assign_invalid_event_header_field_class(self): with self.assertRaises(TypeError): - self._sc.event_header_field_type = 'lel' + self._sc.event_header_field_class = 'lel' - def test_assign_event_context_field_type(self): - self._sc.event_context_field_type = self._packet_context_ft - self.assertEqual(self._sc.event_context_field_type, self._packet_context_ft) + def test_assign_event_context_field_class(self): + self._sc.event_context_field_class = self._packet_context_fc + self.assertEqual(self._sc.event_context_field_class, self._packet_context_fc) - def test_assign_no_event_context_field_type(self): - self._sc.event_context_field_type = None - self.assertIsNone(self._sc.event_context_field_type) + def test_assign_no_event_context_field_class(self): + self._sc.event_context_field_class = None + self.assertIsNone(self._sc.event_context_field_class) - def test_assign_invalid_event_context_field_type(self): + def test_assign_invalid_event_context_field_class(self): with self.assertRaises(TypeError): - self._sc.event_context_field_type = 'lel' + self._sc.event_context_field_class = 'lel' def test_trace_prop_no_tc(self): self.assertIsNone(self._sc.trace) @@ -122,16 +122,16 @@ class StreamClassTestCase(unittest.TestCase): def test_copy(self): cpy = copy.copy(self._sc) self._test_copy(cpy) - self.assertEqual(self._sc.packet_context_field_type.addr, cpy.packet_context_field_type.addr) - self.assertEqual(self._sc.event_header_field_type.addr, cpy.event_header_field_type.addr) - self.assertEqual(self._sc.event_context_field_type.addr, cpy.event_context_field_type.addr) + self.assertEqual(self._sc.packet_context_field_class.addr, cpy.packet_context_field_class.addr) + self.assertEqual(self._sc.event_header_field_class.addr, cpy.event_header_field_class.addr) + self.assertEqual(self._sc.event_context_field_class.addr, cpy.event_context_field_class.addr) def test_deepcopy(self): cpy = copy.deepcopy(self._sc) self._test_copy(cpy) - self.assertNotEqual(self._sc.packet_context_field_type.addr, cpy.packet_context_field_type.addr) - self.assertNotEqual(self._sc.event_header_field_type.addr, cpy.event_header_field_type.addr) - self.assertNotEqual(self._sc.event_context_field_type.addr, cpy.event_context_field_type.addr) + self.assertNotEqual(self._sc.packet_context_field_class.addr, cpy.packet_context_field_class.addr) + self.assertNotEqual(self._sc.event_header_field_class.addr, cpy.event_header_field_class.addr) + self.assertNotEqual(self._sc.event_context_field_class.addr, cpy.event_context_field_class.addr) def test_getitem(self): self.assertEqual(self._sc[23], self._ec1) @@ -160,104 +160,104 @@ class StreamClassTestCase(unittest.TestCase): def test_eq(self): ec1, ec2 = self._create_event_classes() sc1 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) ec1, ec2 = self._create_event_classes() sc2 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) self.assertEqual(sc1, sc2) def test_ne_name(self): ec1, ec2 = self._create_event_classes() sc1 = bt2.StreamClass(name='my_stream_class1', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) ec1, ec2 = self._create_event_classes() sc2 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) self.assertNotEqual(sc1, sc2) def test_ne_id(self): ec1, ec2 = self._create_event_classes() sc1 = bt2.StreamClass(name='my_stream_class', id=13, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) ec1, ec2 = self._create_event_classes() sc2 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) self.assertNotEqual(sc1, sc2) - def test_ne_packet_context_field_type(self): + def test_ne_packet_context_field_class(self): ec1, ec2 = self._create_event_classes() sc1 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._event_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._event_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) ec1, ec2 = self._create_event_classes() sc2 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) self.assertNotEqual(sc1, sc2) - def test_ne_event_header_field_type(self): + def test_ne_event_header_field_class(self): ec1, ec2 = self._create_event_classes() sc1 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) ec1, ec2 = self._create_event_classes() sc2 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) self.assertNotEqual(sc1, sc2) - def test_ne_event_context_field_type(self): + def test_ne_event_context_field_class(self): ec1, ec2 = self._create_event_classes() sc1 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._packet_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._packet_context_fc, event_classes=(ec1, ec2)) ec1, ec2 = self._create_event_classes() sc2 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) self.assertNotEqual(sc1, sc2) def test_ne_event_class(self): ec1, ec2 = self._create_event_classes() sc1 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1,)) ec1, ec2 = self._create_event_classes() sc2 = bt2.StreamClass(name='my_stream_class', id=12, - packet_context_field_type=self._packet_context_ft, - event_header_field_type=self._event_header_ft, - event_context_field_type=self._event_context_ft, + packet_context_field_class=self._packet_context_fc, + event_header_field_class=self._event_header_fc, + event_context_field_class=self._event_context_fc, event_classes=(ec1, ec2)) self.assertNotEqual(sc1, sc2) diff --git a/tests/bindings/python/bt2/test_trace.py b/tests/bindings/python/bt2/test_trace.py index 462f9b91e..b82cf12c9 100644 --- a/tests/bindings/python/bt2/test_trace.py +++ b/tests/bindings/python/bt2/test_trace.py @@ -17,39 +17,39 @@ class TraceTestCase(unittest.TestCase): def _create_stream_class(self, name, id): ec1, ec2 = self._create_event_classes() - packet_context_ft = bt2.StructureFieldType() - packet_context_ft.append_field('menu', bt2.FloatingPointNumberFieldType()) - packet_context_ft.append_field('sticker', bt2.StringFieldType()) - event_header_ft = bt2.StructureFieldType() - event_header_ft.append_field('id', bt2.IntegerFieldType(19)) - event_context_ft = bt2.StructureFieldType() - event_context_ft.append_field('msg', bt2.StringFieldType()) + packet_context_fc = bt2.StructureFieldClass() + packet_context_fc.append_field('menu', bt2.FloatingPointNumberFieldClass()) + packet_context_fc.append_field('sticker', bt2.StringFieldClass()) + event_header_fc = bt2.StructureFieldClass() + event_header_fc.append_field('id', bt2.IntegerFieldClass(19)) + event_context_fc = bt2.StructureFieldClass() + event_context_fc.append_field('msg', bt2.StringFieldClass()) return bt2.StreamClass(name=name, id=id, - packet_context_field_type=packet_context_ft, - event_header_field_type=event_header_ft, - event_context_field_type=event_context_ft, + packet_context_field_class=packet_context_fc, + event_header_field_class=event_header_fc, + event_context_field_class=event_context_fc, event_classes=(ec1, ec2)) def _create_event_classes(self): - context_ft = bt2.StructureFieldType() - context_ft.append_field('allo', bt2.StringFieldType()) - context_ft.append_field('zola', bt2.IntegerFieldType(18)) - payload_ft = bt2.StructureFieldType() - payload_ft.append_field('zoom', bt2.StringFieldType()) - ec1 = bt2.EventClass('event23', id=23, context_field_type=context_ft, - payload_field_type=payload_ft) - ec2 = bt2.EventClass('event17', id=17, context_field_type=payload_ft, - payload_field_type=context_ft) + context_fc = bt2.StructureFieldClass() + context_fc.append_field('allo', bt2.StringFieldClass()) + context_fc.append_field('zola', bt2.IntegerFieldClass(18)) + payload_fc = bt2.StructureFieldClass() + payload_fc.append_field('zoom', bt2.StringFieldClass()) + ec1 = bt2.EventClass('event23', id=23, context_field_class=context_fc, + payload_field_class=payload_fc) + ec2 = bt2.EventClass('event17', id=17, context_field_class=payload_fc, + payload_field_class=context_fc) return ec1, ec2 def test_create_default(self): self.assertEqual(len(self._tc), 0) def _get_std_header(self): - header_ft = bt2.StructureFieldType() - header_ft.append_field('magic', bt2.IntegerFieldType(32)) - header_ft.append_field('stream_id', bt2.IntegerFieldType(32)) - return header_ft + header_fc = bt2.StructureFieldClass() + header_fc.append_field('magic', bt2.IntegerFieldClass(32)) + header_fc.append_field('stream_id', bt2.IntegerFieldClass(32)) + return header_fc def test_create_full(self): clock_classes = bt2.ClockClass('cc1', 1000), bt2.ClockClass('cc2', 30) @@ -57,14 +57,14 @@ class TraceTestCase(unittest.TestCase): tc = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=self._get_std_header(), + packet_header_field_class=self._get_std_header(), clock_classes=clock_classes, stream_classes=(sc,)) self.assertEqual(tc.name, 'my name') self.assertEqual(tc.native_byte_order, bt2.ByteOrder.LITTLE_ENDIAN) self.assertEqual(tc.env['the_string'], 'value') self.assertEqual(tc.env['the_int'], 23) - self.assertEqual(tc.packet_header_field_type, self._get_std_header()) + self.assertEqual(tc.packet_header_field_class, self._get_std_header()) self.assertEqual(tc.clock_classes['cc1'], clock_classes[0]) self.assertEqual(tc.clock_classes['cc2'], clock_classes[1]) self.assertEqual(tc[3], sc) @@ -89,15 +89,15 @@ class TraceTestCase(unittest.TestCase): with self.assertRaises(TypeError): self._tc.native_byte_order = 'lel' - def test_assign_packet_header_field_type(self): - header_ft = bt2.StructureFieldType() - header_ft.append_field('magic', bt2.IntegerFieldType(32)) - self._tc.packet_header_field_type = header_ft - self.assertEqual(self._tc.packet_header_field_type, header_ft) + def test_assign_packet_header_field_class(self): + header_fc = bt2.StructureFieldClass() + header_fc.append_field('magic', bt2.IntegerFieldClass(32)) + self._tc.packet_header_field_class = header_fc + self.assertEqual(self._tc.packet_header_field_class, header_fc) - def test_assign_no_packet_header_field_type(self): - self._tc.packet_header_field_type = None - self.assertIsNone(self._tc.packet_header_field_type) + def test_assign_no_packet_header_field_class(self): + self._tc.packet_header_field_class = None + self.assertIsNone(self._tc.packet_header_field_class) def _test_copy(self, cpy): self.assertIsNot(cpy, self._tc) @@ -106,7 +106,7 @@ class TraceTestCase(unittest.TestCase): self.assertEqual(len(self._tc), len(cpy)) def _pre_copy(self): - self._tc.packet_header_field_type = self._get_std_header() + self._tc.packet_header_field_class = self._get_std_header() self._tc.name = 'the trace class' sc1 = self._create_stream_class('sc1', 3) sc2 = self._create_stream_class('sc2', 9) @@ -123,7 +123,7 @@ class TraceTestCase(unittest.TestCase): self._pre_copy() cpy = copy.copy(self._tc) self._test_copy(cpy) - self.assertEqual(self._tc.packet_header_field_type.addr, cpy.packet_header_field_type.addr) + self.assertEqual(self._tc.packet_header_field_class.addr, cpy.packet_header_field_class.addr) self.assertEqual(self._tc.clock_classes['cc1'].addr, cpy.clock_classes['cc1'].addr) self.assertEqual(self._tc.clock_classes['cc2'].addr, cpy.clock_classes['cc2'].addr) self.assertEqual(self._tc.env['allo'].addr, cpy.env['allo'].addr) @@ -133,7 +133,7 @@ class TraceTestCase(unittest.TestCase): self._pre_copy() cpy = copy.deepcopy(self._tc) self._test_copy(cpy) - self.assertNotEqual(self._tc.packet_header_field_type.addr, cpy.packet_header_field_type.addr) + self.assertNotEqual(self._tc.packet_header_field_class.addr, cpy.packet_header_field_class.addr) self.assertNotEqual(self._tc.clock_classes['cc1'].addr, cpy.clock_classes['cc1'].addr) self.assertNotEqual(self._tc.clock_classes['cc2'].addr, cpy.clock_classes['cc2'].addr) self.assertNotEqual(self._tc.env['allo'].addr, cpy.env['allo'].addr) @@ -159,7 +159,7 @@ class TraceTestCase(unittest.TestCase): self.assertEqual(len(self._tc), 1) def test_iter(self): - self._tc.packet_header_field_type = self._get_std_header() + self._tc.packet_header_field_class = self._get_std_header() sc1 = self._create_stream_class('sc1', 3) sc2 = self._create_stream_class('sc2', 9) sc3 = self._create_stream_class('sc3', 17) @@ -218,123 +218,123 @@ class TraceTestCase(unittest.TestCase): return cc1, cc2, sc1, sc2, self._get_std_header() def test_eq(self): - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertEqual(tc1, tc2) def test_ne_name(self): - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name2', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertNotEqual(tc1, tc2) - def test_ne_packet_header_field_type(self): - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + def test_ne_packet_header_field_class(self): + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() - header_ft.append_field('yes', bt2.StringFieldType()) + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() + header_fc.append_field('yes', bt2.StringFieldClass()) tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertNotEqual(tc1, tc2) def test_ne_native_byte_order(self): - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.BIG_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertNotEqual(tc1, tc2) def test_ne_env(self): - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int2': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertNotEqual(tc1, tc2) def test_ne_clock_classes(self): - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() cc2.frequency = 1234 tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertNotEqual(tc1, tc2) def test_ne_stream_classes(self): - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() tc1 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) - cc1, cc2, sc1, sc2, header_ft = self._test_eq_create_objects() + cc1, cc2, sc1, sc2, header_fc = self._test_eq_create_objects() sc2.id = 72632 tc2 = bt2.Trace(name='my name', native_byte_order=bt2.ByteOrder.LITTLE_ENDIAN, env={'the_string': 'value', 'the_int': 23}, - packet_header_field_type=header_ft, + packet_header_field_class=header_fc, clock_classes=(cc1, cc2), stream_classes=(sc1, sc2)) self.assertNotEqual(tc1, tc2) -- 2.34.1