+# SPDX-License-Identifier: GPL-2.0-only
#
# Copyright (C) 2019 EfficiOS Inc.
#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; only version 2
-# of the License.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
import unittest
import bt2
_create_default_field_class = _create_field_class
-class _VariantFieldClassWithSelectorTestCase:
+class _VariantFieldClassWithIntegerSelectorTestCase:
@staticmethod
def _const_value_setter(field):
field['variant'].selected_option_index = 0
class VariantFieldClassWithUnsignedSelectorTestCase(
- _VariantFieldClassWithSelectorTestCase, unittest.TestCase
+ _VariantFieldClassWithIntegerSelectorTestCase, unittest.TestCase
):
def _spec_set_up(self):
self._ranges1 = bt2.UnsignedIntegerRangeSet([(1, 4), (18, 47)])
class VariantFieldClassWithSignedSelectorTestCase(
- _VariantFieldClassWithSelectorTestCase, unittest.TestCase
+ _VariantFieldClassWithIntegerSelectorTestCase, unittest.TestCase
):
def _spec_set_up(self):
self._ranges1 = bt2.SignedIntegerRangeSet([(-10, -4), (18, 47)])
type(fc.element_field_class), bt2_field_class._SignedIntegerFieldClass
)
+
+class _ArrayFieldClassConstTestCase:
def test_const_attr_element_field_class(self):
fc = self._create_const_array()
self.assertIs(
)
-class StaticArrayFieldClassTestCase(_ArrayFieldClassTestCase, unittest.TestCase):
+class StaticArrayFieldClassTestCase(
+ _ArrayFieldClassTestCase, _ArrayFieldClassConstTestCase, unittest.TestCase
+):
@staticmethod
def _const_value_setter(field):
field.value = [9] * 45
)
-class DynamicArrayFieldClassTestCase(_ArrayFieldClassTestCase, unittest.TestCase):
+class DynamicArrayFieldClassTestCase(
+ _ArrayFieldClassTestCase, _ArrayFieldClassConstTestCase, unittest.TestCase
+):
@staticmethod
def _const_value_setter(field):
field.value = []
def setUp(self):
self._tc = get_default_trace_class()
self._elem_fc = self._tc.create_signed_integer_field_class(23)
- self._len_fc = self._tc.create_unsigned_integer_field_class(12)
def test_create_default(self):
fc = self._tc.create_dynamic_array_field_class(self._elem_fc)
self.assertEqual(fc.element_field_class.addr, self._elem_fc.addr)
+ self.assertEqual(len(fc.user_attributes), 0)
+
+ def test_create_invalid_field_class(self):
+ with self.assertRaises(TypeError):
+ self._tc.create_dynamic_array_field_class(object())
+
+
+class DynamicArrayWithLengthFieldFieldClassTestCase(
+ _ArrayFieldClassTestCase, unittest.TestCase
+):
+ @staticmethod
+ def _const_value_setter(field):
+ field.value = []
+
+ def _create_array(self):
+ return self._tc.create_dynamic_array_field_class(self._elem_fc, self._len_fc)
+
+ def setUp(self):
+ self._tc = get_default_trace_class()
+ self._elem_fc = self._tc.create_signed_integer_field_class(23)
+ self._len_fc = self._tc.create_unsigned_integer_field_class(12)
+
+ def test_create_default(self):
+ fc = self._create_array()
+ self.assertEqual(fc.element_field_class.addr, self._elem_fc.addr)
self.assertIsNone(fc.length_field_path, None)
self.assertEqual(len(fc.user_attributes), 0)
# } inner_struct[2];
# };
- fc = self._tc.create_dynamic_array_field_class(self._elem_fc, self._len_fc)
+ fc = self._create_array()
foo_fc = self._tc.create_single_precision_real_field_class()
bar_fc = self._tc.create_string_field_class()
fc.length_field_path.root_scope, bt2.FieldPathScope.PACKET_CONTEXT
)
- def test_create_invalid_field_class(self):
- with self.assertRaises(TypeError):
- self._tc.create_dynamic_array_field_class(object())
-
def test_create_invalid_length_type(self):
with self.assertRaises(TypeError):
self._tc.create_dynamic_array_field_class(