+# Create and return a stream with the field classes part of its stream packet
+# context.
+#
+# The stream is part of a dummy trace created from trace class `tc`.
+
+def _create_stream(tc, ctx_field_classes):
+ packet_context_fc = tc.create_structure_field_class()
+ for name, fc in ctx_field_classes:
+ packet_context_fc.append_member(name, fc)
+
+ trace = tc()
+ stream_class = tc.create_stream_class(packet_context_field_class=packet_context_fc)
+
+ stream = trace.create_stream(stream_class)
+ return stream
+
+
+# Create a field of the given field class.
+#
+# The field is part of a dummy stream, itself part of a dummy trace created
+# from trace class `tc`.
+
+def _create_field(tc, field_class):
+ field_name = 'field'
+ stream = _create_stream(tc, [(field_name, field_class)])
+ packet = stream.create_packet()
+ return packet.context_field[field_name]
+
+
+# Create a field of type string.
+#
+# The field is part of a dummy stream, itself part of a dummy trace created
+# from trace class `tc`. It is made out of a dummy string field class.
+
+def _create_string_field(tc):
+ field_name = 'string_field'
+ stream = _create_stream(tc, [(field_name, tc.create_string_field_class())])
+ packet = stream.create_packet()
+ return packet.context_field[field_name]
+
+
+# Create a field of type static array of ints.
+#
+# The field is part of a dummy stream, itself part of a dummy trace created
+# from trace class `tc`. It is made out of a dummy static array field class,
+# with a dummy integer field class as element class.
+
+def _create_int_array_field(tc, length):
+ elem_fc = tc.create_signed_integer_field_class(32)
+ fc = tc.create_static_array_field_class(elem_fc, length)
+ field_name = 'int_array'
+ stream = _create_stream(tc, [(field_name, fc)])
+ packet = stream.create_packet()
+ return packet.context_field[field_name]
+
+
+# Create a field of type dynamic array of ints.
+#
+# The field is part of a dummy stream, itself part of a dummy trace created
+# from trace class `tc`. It is made out of a dummy static array field class,
+# with a dummy integer field class as element and length classes.
+
+def _create_dynamic_array(tc):
+ elem_fc = tc.create_signed_integer_field_class(32)
+ len_fc = tc.create_signed_integer_field_class(32)
+ fc = tc.create_dynamic_array_field_class(elem_fc)
+ field_name = 'int_dyn_array'
+ stream = _create_stream(tc, [('thelength', len_fc), (field_name, fc)])
+ packet = stream.create_packet()
+ packet.context_field[field_name].length = 3
+ return packet.context_field[field_name]
+
+
+# Create a field of type array of (empty) structures.
+#
+# The field is part of a dummy stream, itself part of a dummy trace created
+# from trace class `tc`. It is made out of a dummy static array field class,
+# with a dummy struct field class as element class.
+
+def _create_struct_array_field(tc, length):
+ elem_fc = tc.create_structure_field_class()
+ fc = tc.create_static_array_field_class(elem_fc, length)
+ field_name = 'struct_array'
+ stream = _create_stream(tc, [(field_name, fc)])
+ packet = stream.create_packet()
+ return packet.context_field[field_name]
+
+
+class _TestNumericField: