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 \
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
# 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
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)
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):
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)
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
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)
--- /dev/null
+# The MIT License (MIT)
+#
+# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+
+from bt2 import native_bt, object, utils
+import collections.abc
+import bt2.fields
+import abc
+import bt2
+
+
+def _create_from_ptr(ptr):
+ typeid = native_bt.field_class_get_type_id(ptr)
+ return _TYPE_ID_TO_OBJ[typeid]._create_from_ptr(ptr)
+
+
+class _FieldClass(object._Object, metaclass=abc.ABCMeta):
+ def __init__(self, ptr):
+ super().__init__(ptr)
+
+ def __eq__(self, other):
+ if not isinstance(other, self.__class__):
+ # not comparing apples to apples
+ return False
+
+ if self.addr == other.addr:
+ return True
+
+ 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 class object'.format(self._NAME.lower()))
+
+ def __copy__(self):
+ 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):
+ cpy = self.__copy__()
+ memo[id(self)] = cpy
+ return cpy
+
+ def __call__(self, value=None):
+ field_ptr = native_bt.field_create(self._ptr)
+
+ if field_ptr is None:
+ raise bt2.CreationError('cannot create {} field object'.format(self._NAME.lower()))
+
+ field = bt2.fields._create_from_ptr(field_ptr)
+
+ if value is not None:
+ if not isinstance(field, (bt2.fields._IntegerField, bt2.fields._FloatingPointNumberField, bt2.fields._StringField)):
+ raise bt2.Error('cannot assign an initial value to a {} field object'.format(field._NAME))
+
+ field.value = value
+
+ return field
+
+
+class _AlignmentProp:
+ @property
+ def alignment(self):
+ 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_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_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_class_set_byte_order(self._ptr, byte_order)
+ utils._handle_ret(ret, "cannot set field class object's byte order")
+
+
+class IntegerFieldClass(_FieldClass, _AlignmentProp, _ByteOrderProp):
+ _NAME = 'Integer'
+
+ def __init__(self, size, alignment=None, byte_order=None, is_signed=None,
+ base=None, encoding=None, mapped_clock_class=None):
+ utils._check_uint64(size)
+
+ if size == 0:
+ raise ValueError('size is 0 bits')
+
+ ptr = native_bt.field_class_integer_create(size)
+ self._check_create_status(ptr)
+ super().__init__(ptr)
+
+ if alignment is not None:
+ self.alignment = alignment
+
+ if byte_order is not None:
+ self.byte_order = byte_order
+
+ if is_signed is not None:
+ self.is_signed = is_signed
+
+ if base is not None:
+ self.base = base
+
+ if encoding is not None:
+ self.encoding = encoding
+
+ if mapped_clock_class is not None:
+ self.mapped_clock_class = mapped_clock_class
+
+ @property
+ def size(self):
+ 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_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_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_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_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_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_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_class_integer_get_mapped_clock_class(self._ptr)
+
+ if ptr is None:
+ return
+
+ return bt2.ClockClass._create_from_ptr(ptr)
+
+ @mapped_clock_class.setter
+ def mapped_clock_class(self, clock_class):
+ utils._check_type(clock_class, bt2.ClockClass)
+ 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 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_class_floating_point_create()
+ self._check_create_status(ptr)
+ super().__init__(ptr)
+
+ if alignment is not None:
+ self.alignment = alignment
+
+ if byte_order is not None:
+ self.byte_order = byte_order
+
+ if exponent_size is not None:
+ self.exponent_size = exponent_size
+
+ if mantissa_size is not None:
+ self.mantissa_size = mantissa_size
+
+ @property
+ def exponent_size(self):
+ 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_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_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_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 _EnumerationFieldClassMapping:
+ def __init__(self, name, lower, upper):
+ self._name = name
+ self._lower = lower
+ self._upper = upper
+
+ @property
+ def name(self):
+ return self._name
+
+ @property
+ def lower(self):
+ return self._lower
+
+ @property
+ def upper(self):
+ return self._upper
+
+ def __eq__(self, other):
+ if type(other) is not self.__class__:
+ return False
+
+ return (self.name, self.lower, self.upper) == (other.name, other.lower, other.upper)
+
+
+class _EnumerationFieldClassMappingIterator(object._Object,
+ collections.abc.Iterator):
+ def __init__(self, iter_ptr, is_signed):
+ super().__init__(iter_ptr)
+ self._is_signed = is_signed
+ self._done = (iter_ptr is None)
+
+ def __next__(self):
+ if self._done:
+ raise StopIteration
+
+ 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_class_enumeration_mapping_iterator_get_signed(self._ptr)
+ else:
+ ret, name, lower, upper = native_bt.field_class_enumeration_mapping_iterator_get_unsigned(self._ptr)
+
+ assert(ret == 0)
+ mapping = _EnumerationFieldClassMapping(name, lower, upper)
+
+ return mapping
+
+
+class EnumerationFieldClass(IntegerFieldClass, collections.abc.Sequence):
+ _NAME = 'Enumeration'
+
+ 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_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_class, IntegerFieldClass)
+ ptr = native_bt.field_class_enumeration_create(int_field_class._ptr)
+ self._check_create_status(ptr)
+ _FieldClass.__init__(self, ptr)
+
+ @property
+ 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_class.size
+
+ @property
+ def alignment(self):
+ return self.integer_field_class.alignment
+
+ @alignment.setter
+ def alignment(self, alignment):
+ self.integer_field_class.alignment = alignment
+
+ @property
+ def byte_order(self):
+ return self.integer_field_class.byte_order
+
+ @byte_order.setter
+ def byte_order(self, byte_order):
+ self.integer_field_class.byte_order = byte_order
+
+ @property
+ def is_signed(self):
+ return self.integer_field_class.is_signed
+
+ @is_signed.setter
+ def is_signed(self, is_signed):
+ self.integer_field_class.is_signed = is_signed
+
+ @property
+ def base(self):
+ return self.integer_field_class.base
+
+ @base.setter
+ def base(self, base):
+ self.integer_field_class.base = base
+
+ @property
+ def encoding(self):
+ return self.integer_field_class.encoding
+
+ @encoding.setter
+ def encoding(self, encoding):
+ self.integer_field_class.encoding = encoding
+
+ @property
+ def mapped_clock_class(self):
+ return self.integer_field_class.mapped_clock_class
+
+ @mapped_clock_class.setter
+ def mapped_clock_class(self, mapped_clock_class):
+ self.integer_field_class.mapped_clock_class = mapped_clock_class
+
+ def __len__(self):
+ count = native_bt.field_class_enumeration_get_mapping_count(self._ptr)
+ assert(count >= 0)
+ return count
+
+ def __getitem__(self, index):
+ utils._check_uint64(index)
+
+ if index >= len(self):
+ raise IndexError
+
+ if self.is_signed:
+ get_fn = native_bt.field_class_enumeration_get_mapping_signed
+ else:
+ get_fn = native_bt.field_class_enumeration_get_mapping_unsigned
+
+ ret, name, lower, upper = get_fn(self._ptr, index)
+ assert(ret == 0)
+ return _EnumerationFieldClassMapping(name, lower, upper)
+
+ def _get_mapping_iter(self, iter_ptr):
+ return _EnumerationFieldClassMappingIterator(iter_ptr, self.is_signed)
+
+ def mappings_by_name(self, name):
+ utils._check_str(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_class_enumeration_find_mappings_by_signed_value(self._ptr, value)
+ else:
+ utils._check_uint64(value)
+ iter_ptr = native_bt.field_class_enumeration_find_mappings_by_unsigned_value(self._ptr, value)
+
+ return self._get_mapping_iter(iter_ptr)
+
+ def add_mapping(self, name, lower, upper=None):
+ utils._check_str(name)
+
+ if upper is None:
+ upper = lower
+
+ if self.is_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_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 class object")
+
+ def __iadd__(self, mappings):
+ for mapping in mappings:
+ self.add_mapping(mapping.name, mapping.lower, mapping.upper)
+
+ return self
+
+
+class StringFieldClass(_FieldClass):
+ _NAME = 'String'
+
+ def __init__(self, encoding=None):
+ ptr = native_bt.field_class_string_create()
+ self._check_create_status(ptr)
+ super().__init__(ptr)
+
+ if encoding is not None:
+ self.encoding = encoding
+
+ @property
+ def encoding(self):
+ 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_class_string_set_encoding(self._ptr, encoding)
+ utils._handle_ret(ret, "cannot set string field class object's encoding")
+
+
+class _FieldContainer(collections.abc.Mapping):
+ def __len__(self):
+ count = self._count()
+ assert(count >= 0)
+ return count
+
+ def __getitem__(self, key):
+ if not isinstance(key, str):
+ raise TypeError("'{}' is not a 'str' object".format(key.__class__.__name__))
+
+ ptr = self._get_field_by_name(key)
+
+ if ptr is None:
+ raise KeyError(key)
+
+ return _create_from_ptr(ptr)
+
+ def __iter__(self):
+ return self._ITER_CLS(self)
+
+ def append_field(self, name, field_class):
+ utils._check_str(name)
+ 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_class in fields.items():
+ self.append_field(name, field_class)
+
+ return self
+
+ def at_index(self, index):
+ utils._check_uint64(index)
+ return self._at(index)
+
+
+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_class):
+ raise StopIteration
+
+ 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_class_ptr)
+ self._at += 1
+ return name
+
+
+class StructureFieldClass(_FieldClass, _FieldContainer, _AlignmentProp):
+ _NAME = 'Structure'
+ _ITER_CLS = _StructureFieldClassFieldIterator
+
+ def __init__(self, min_alignment=None):
+ ptr = native_bt.field_class_structure_create()
+ self._check_create_status(ptr)
+ super().__init__(ptr)
+
+ if min_alignment is not None:
+ self.min_alignment = min_alignment
+
+ def _count(self):
+ return native_bt.field_class_structure_get_field_count(self._ptr)
+
+ def _get_field_by_name(self, 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_class_structure_add_field(self._ptr, ptr,
+ name)
+
+ def _at(self, index):
+ if index < 0 or index >= len(self):
+ raise IndexError
+
+ 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_class_ptr)
+
+
+StructureFieldClass.min_alignment = property(fset=StructureFieldClass.alignment.fset)
+StructureFieldClass.alignment = property(fget=StructureFieldClass.alignment.fget)
+
+
+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_class):
+ raise StopIteration
+
+ 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_class_ptr)
+ self._at += 1
+ return name
+
+
+class VariantFieldClass(_FieldClass, _FieldContainer, _AlignmentProp):
+ _NAME = 'Variant'
+ _ITER_CLS = _VariantFieldClassFieldIterator
+
+ def __init__(self, tag_name, tag_field_class=None):
+ utils._check_str(tag_name)
+
+ if tag_field_class is None:
+ tag_fc_ptr = None
+ else:
+ utils._check_type(tag_field_class, EnumerationFieldClass)
+ tag_fc_ptr = tag_field_class._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_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_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_class(self):
+ fc_ptr = native_bt.field_class_variant_get_tag_type(self._ptr)
+
+ if fc_ptr is None:
+ return
+
+ return _create_from_ptr(fc_ptr)
+
+ def _count(self):
+ return native_bt.field_class_variant_get_field_count(self._ptr)
+
+ def _get_field_by_name(self, 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_class_variant_add_field(self._ptr, ptr, name)
+
+ def _at(self, index):
+ if index < 0 or index >= len(self):
+ raise IndexError
+
+ 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_class_ptr)
+
+
+class ArrayFieldClass(_FieldClass):
+ _NAME = 'Array'
+
+ def __init__(self, element_field_class, length):
+ utils._check_type(element_field_class, _FieldClass)
+ utils._check_uint64(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_class_array_get_length(self._ptr)
+ assert(length >= 0)
+ return length
+
+ @property
+ def element_field_class(self):
+ ptr = native_bt.field_class_array_get_element_type(self._ptr)
+ assert(ptr)
+ return _create_from_ptr(ptr)
+
+
+class SequenceFieldClass(_FieldClass):
+ _NAME = 'Sequence'
+
+ def __init__(self, element_field_class, length_name):
+ utils._check_type(element_field_class, _FieldClass)
+ utils._check_str(length_name)
+ 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_class_sequence_get_length_field_name(self._ptr)
+ assert(length_name is not None)
+ return length_name
+
+ @property
+ def element_field_class(self):
+ ptr = native_bt.field_class_sequence_get_element_type(self._ptr)
+ assert(ptr)
+ return _create_from_ptr(ptr)
+
+
+_TYPE_ID_TO_OBJ = {
+}
+++ /dev/null
-# The MIT License (MIT)
-#
-# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-
-from bt2 import native_bt, object, utils
-import collections.abc
-import bt2.fields
-import abc
-import bt2
-
-
-def _create_from_ptr(ptr):
- typeid = native_bt.field_type_get_type_id(ptr)
- return _TYPE_ID_TO_OBJ[typeid]._create_from_ptr(ptr)
-
-
-class _FieldType(object._Object, metaclass=abc.ABCMeta):
- def __init__(self, ptr):
- super().__init__(ptr)
-
- def __eq__(self, other):
- if not isinstance(other, self.__class__):
- # not comparing apples to apples
- return False
-
- 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")
- 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()))
-
- def __copy__(self):
- ptr = native_bt.field_type_copy(self._ptr)
- utils._handle_ptr(ptr, 'cannot copy {} field type object'.format(self._NAME.lower()))
- return _create_from_ptr(ptr)
-
- def __deepcopy__(self, memo):
- cpy = self.__copy__()
- memo[id(self)] = cpy
- return cpy
-
- def __call__(self, value=None):
- field_ptr = native_bt.field_create(self._ptr)
-
- if field_ptr is None:
- raise bt2.CreationError('cannot create {} field object'.format(self._NAME.lower()))
-
- field = bt2.fields._create_from_ptr(field_ptr)
-
- if value is not None:
- if not isinstance(field, (bt2.fields._IntegerField, bt2.fields._FloatingPointNumberField, bt2.fields._StringField)):
- raise bt2.Error('cannot assign an initial value to a {} field object'.format(field._NAME))
-
- field.value = value
-
- return field
-
-
-class _AlignmentProp:
- @property
- def alignment(self):
- alignment = native_bt.field_type_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")
-
-
-class _ByteOrderProp:
- @property
- def byte_order(self):
- bo = native_bt.field_type_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")
-
-
-class IntegerFieldType(_FieldType, _AlignmentProp, _ByteOrderProp):
- _NAME = 'Integer'
-
- def __init__(self, size, alignment=None, byte_order=None, is_signed=None,
- base=None, encoding=None, mapped_clock_class=None):
- utils._check_uint64(size)
-
- if size == 0:
- raise ValueError('size is 0 bits')
-
- ptr = native_bt.field_type_integer_create(size)
- self._check_create_status(ptr)
- super().__init__(ptr)
-
- if alignment is not None:
- self.alignment = alignment
-
- if byte_order is not None:
- self.byte_order = byte_order
-
- if is_signed is not None:
- self.is_signed = is_signed
-
- if base is not None:
- self.base = base
-
- if encoding is not None:
- self.encoding = encoding
-
- if mapped_clock_class is not None:
- self.mapped_clock_class = mapped_clock_class
-
- @property
- def size(self):
- size = native_bt.field_type_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)
- 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")
-
- @property
- def base(self):
- base = native_bt.field_type_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")
-
- @property
- def encoding(self):
- encoding = native_bt.field_type_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")
-
- @property
- def mapped_clock_class(self):
- ptr = native_bt.field_type_integer_get_mapped_clock_class(self._ptr)
-
- if ptr is None:
- return
-
- return bt2.ClockClass._create_from_ptr(ptr)
-
- @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")
-
-
-class FloatingPointNumberFieldType(_FieldType, _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()
- self._check_create_status(ptr)
- super().__init__(ptr)
-
- if alignment is not None:
- self.alignment = alignment
-
- if byte_order is not None:
- self.byte_order = byte_order
-
- if exponent_size is not None:
- self.exponent_size = exponent_size
-
- if mantissa_size is not None:
- self.mantissa_size = mantissa_size
-
- @property
- def exponent_size(self):
- exp_size = native_bt.field_type_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")
-
- @property
- def mantissa_size(self):
- mant_size = native_bt.field_type_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")
-
-
-class _EnumerationFieldTypeMapping:
- def __init__(self, name, lower, upper):
- self._name = name
- self._lower = lower
- self._upper = upper
-
- @property
- def name(self):
- return self._name
-
- @property
- def lower(self):
- return self._lower
-
- @property
- def upper(self):
- return self._upper
-
- def __eq__(self, other):
- if type(other) is not self.__class__:
- return False
-
- return (self.name, self.lower, self.upper) == (other.name, other.lower, other.upper)
-
-
-class _EnumerationFieldTypeMappingIterator(object._Object,
- collections.abc.Iterator):
- def __init__(self, iter_ptr, is_signed):
- super().__init__(iter_ptr)
- self._is_signed = is_signed
- self._done = (iter_ptr is None)
-
- def __next__(self):
- if self._done:
- raise StopIteration
-
- ret = native_bt.field_type_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)
- else:
- ret, name, lower, upper = native_bt.field_type_enumeration_mapping_iterator_get_unsigned(self._ptr)
-
- assert(ret == 0)
- mapping = _EnumerationFieldTypeMapping(name, lower, upper)
-
- return mapping
-
-
-class EnumerationFieldType(IntegerFieldType, collections.abc.Sequence):
- _NAME = 'Enumeration'
-
- def __init__(self, int_field_type=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,
- 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)
- self._check_create_status(ptr)
- _FieldType.__init__(self, ptr)
-
- @property
- def integer_field_type(self):
- ptr = native_bt.field_type_enumeration_get_container_type(self._ptr)
- assert(ptr)
- return _create_from_ptr(ptr)
-
- @property
- def size(self):
- return self.integer_field_type.size
-
- @property
- def alignment(self):
- return self.integer_field_type.alignment
-
- @alignment.setter
- def alignment(self, alignment):
- self.integer_field_type.alignment = alignment
-
- @property
- def byte_order(self):
- return self.integer_field_type.byte_order
-
- @byte_order.setter
- def byte_order(self, byte_order):
- self.integer_field_type.byte_order = byte_order
-
- @property
- def is_signed(self):
- return self.integer_field_type.is_signed
-
- @is_signed.setter
- def is_signed(self, is_signed):
- self.integer_field_type.is_signed = is_signed
-
- @property
- def base(self):
- return self.integer_field_type.base
-
- @base.setter
- def base(self, base):
- self.integer_field_type.base = base
-
- @property
- def encoding(self):
- return self.integer_field_type.encoding
-
- @encoding.setter
- def encoding(self, encoding):
- self.integer_field_type.encoding = encoding
-
- @property
- def mapped_clock_class(self):
- return self.integer_field_type.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
-
- def __len__(self):
- count = native_bt.field_type_enumeration_get_mapping_count(self._ptr)
- assert(count >= 0)
- return count
-
- def __getitem__(self, index):
- utils._check_uint64(index)
-
- if index >= len(self):
- raise IndexError
-
- if self.is_signed:
- get_fn = native_bt.field_type_enumeration_get_mapping_signed
- else:
- get_fn = native_bt.field_type_enumeration_get_mapping_unsigned
-
- ret, name, lower, upper = get_fn(self._ptr, index)
- assert(ret == 0)
- return _EnumerationFieldTypeMapping(name, lower, upper)
-
- def _get_mapping_iter(self, iter_ptr):
- return _EnumerationFieldTypeMappingIterator(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)
- 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)
- else:
- utils._check_uint64(value)
- iter_ptr = native_bt.field_type_enumeration_find_mappings_by_unsigned_value(self._ptr, value)
-
- return self._get_mapping_iter(iter_ptr)
-
- def add_mapping(self, name, lower, upper=None):
- utils._check_str(name)
-
- if upper is None:
- upper = lower
-
- if self.is_signed:
- add_fn = native_bt.field_type_enumeration_add_mapping_signed
- utils._check_int64(lower)
- utils._check_int64(upper)
- else:
- add_fn = native_bt.field_type_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")
-
- def __iadd__(self, mappings):
- for mapping in mappings:
- self.add_mapping(mapping.name, mapping.lower, mapping.upper)
-
- return self
-
-
-class StringFieldType(_FieldType):
- _NAME = 'String'
-
- def __init__(self, encoding=None):
- ptr = native_bt.field_type_string_create()
- self._check_create_status(ptr)
- super().__init__(ptr)
-
- if encoding is not None:
- self.encoding = encoding
-
- @property
- def encoding(self):
- encoding = native_bt.field_type_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")
-
-
-class _FieldContainer(collections.abc.Mapping):
- def __len__(self):
- count = self._count()
- assert(count >= 0)
- return count
-
- def __getitem__(self, key):
- if not isinstance(key, str):
- raise TypeError("'{}' is not a 'str' object".format(key.__class__.__name__))
-
- ptr = self._get_field_by_name(key)
-
- if ptr is None:
- raise KeyError(key)
-
- return _create_from_ptr(ptr)
-
- def __iter__(self):
- return self._ITER_CLS(self)
-
- def append_field(self, name, field_type):
- 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()))
-
- def __iadd__(self, fields):
- for name, field_type in fields.items():
- self.append_field(name, field_type)
-
- return self
-
- def at_index(self, index):
- utils._check_uint64(index)
- return self._at(index)
-
-
-class _StructureFieldTypeFieldIterator(collections.abc.Iterator):
- def __init__(self, struct_field_type):
- self._struct_field_type = struct_field_type
- self._at = 0
-
- def __next__(self):
- if self._at == len(self._struct_field_type):
- 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,
- self._at)
- assert(ret == 0)
- native_bt.put(field_type_ptr)
- self._at += 1
- return name
-
-
-class StructureFieldType(_FieldType, _FieldContainer, _AlignmentProp):
- _NAME = 'Structure'
- _ITER_CLS = _StructureFieldTypeFieldIterator
-
- def __init__(self, min_alignment=None):
- ptr = native_bt.field_type_structure_create()
- self._check_create_status(ptr)
- super().__init__(ptr)
-
- if min_alignment is not None:
- self.min_alignment = min_alignment
-
- def _count(self):
- return native_bt.field_type_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)
-
- def _add_field(self, ptr, name):
- return native_bt.field_type_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)
- assert(ret == 0)
- return _create_from_ptr(field_type_ptr)
-
-
-StructureFieldType.min_alignment = property(fset=StructureFieldType.alignment.fset)
-StructureFieldType.alignment = property(fget=StructureFieldType.alignment.fget)
-
-
-class _VariantFieldTypeFieldIterator(collections.abc.Iterator):
- def __init__(self, variant_field_type):
- self._variant_field_type = variant_field_type
- self._at = 0
-
- def __next__(self):
- if self._at == len(self._variant_field_type):
- raise StopIteration
-
- ret, name, field_type_ptr = native_bt.field_type_variant_get_field_by_index(self._variant_field_type._ptr,
- self._at)
- assert(ret == 0)
- native_bt.put(field_type_ptr)
- self._at += 1
- return name
-
-
-class VariantFieldType(_FieldType, _FieldContainer, _AlignmentProp):
- _NAME = 'Variant'
- _ITER_CLS = _VariantFieldTypeFieldIterator
-
- def __init__(self, tag_name, tag_field_type=None):
- utils._check_str(tag_name)
-
- if tag_field_type is None:
- tag_ft_ptr = None
- else:
- utils._check_type(tag_field_type, EnumerationFieldType)
- tag_ft_ptr = tag_field_type._ptr
-
- ptr = native_bt.field_type_variant_create(tag_ft_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)
- 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")
-
- @property
- def tag_field_type(self):
- ft_ptr = native_bt.field_type_variant_get_tag_type(self._ptr)
-
- if ft_ptr is None:
- return
-
- return _create_from_ptr(ft_ptr)
-
- def _count(self):
- return native_bt.field_type_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)
-
- def _add_field(self, ptr, name):
- return native_bt.field_type_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)
- assert(ret == 0)
- return _create_from_ptr(field_type_ptr)
-
-
-class ArrayFieldType(_FieldType):
- _NAME = 'Array'
-
- def __init__(self, element_field_type, length):
- utils._check_type(element_field_type, _FieldType)
- utils._check_uint64(length)
- ptr = native_bt.field_type_array_create(element_field_type._ptr, length)
- self._check_create_status(ptr)
- super().__init__(ptr)
-
- @property
- def length(self):
- length = native_bt.field_type_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)
- assert(ptr)
- return _create_from_ptr(ptr)
-
-
-class SequenceFieldType(_FieldType):
- _NAME = 'Sequence'
-
- def __init__(self, element_field_type, length_name):
- utils._check_type(element_field_type, _FieldType)
- utils._check_str(length_name)
- ptr = native_bt.field_type_sequence_create(element_field_type._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)
- 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)
- assert(ptr)
- return _create_from_ptr(ptr)
-
-
-_TYPE_ID_TO_OBJ = {
-}
# THE SOFTWARE.
from bt2 import native_bt, object, utils
-import bt2.field_types
+import bt2.field_class
import collections.abc
import functools
import numbers
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
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
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):
value = int(value)
- if self.field_type.is_signed:
+ if self.field_class.is_signed:
utils._check_int64(value)
else:
utils._check_uint64(value)
@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)
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)
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
_NAME = 'Structure'
def _count(self):
- return len(self.field_type)
+ return len(self.field_class)
def __getitem__(self, key):
utils._check_str(key)
def __iter__(self):
# same name iterator
- return iter(self.field_type)
+ return iter(self.field_class)
def _spec_eq(self, other):
try:
_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)
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):
# 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
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)
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:
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:
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:
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))
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)
# 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
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()
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():
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):
self_env,
self.name,
self.native_byte_order,
- self.packet_header_field_type,
+ self.packet_header_field_class,
)
other_props = (
other_stream_classes,
other_env,
other.name,
other.native_byte_order,
- other.packet_header_field_type,
+ other.packet_header_field_class,
)
return self_props == other_props
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)
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 \
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
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()
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()
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()
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
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)
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)
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)
@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)
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)
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)
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'
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)
--- /dev/null
+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)
+++ /dev/null
-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)
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_assign_int_field(self):
raw = 999
- field = self._ft()
+ field = self._fc()
field.value = raw
self._def.value = field
self.assertEqual(self._def, raw)
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
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)
@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
@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):
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
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
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
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)
@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):
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)
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)
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))
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
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)
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
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
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
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,
},
]
- array = array_ft()
+ array = array_fc()
array.value = values
self.assertEqual(values, array)
values[0]['an_int'] = 'a string'
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):
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):
@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
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
@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
}
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):
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):
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
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
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
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):
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)
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',
'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)
'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
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)
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)
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)
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)
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')
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)
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)
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)
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()
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
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)
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):
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)
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):
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)
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
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
@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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)