}
}
+void event_copy_tests(struct bt_ctf_event *event)
+{
+ struct bt_ctf_event *copy;
+ struct bt_ctf_event_class *orig_event_class;
+ struct bt_ctf_event_class *copy_event_class;
+ struct bt_ctf_stream *orig_stream;
+ struct bt_ctf_stream *copy_stream;
+ struct bt_ctf_field *orig_field;
+ struct bt_ctf_field *copy_field;
+
+ /* copy */
+ ok(!bt_ctf_event_copy(NULL),
+ "bt_ctf_event_copy handles NULL correctly");
+ copy = bt_ctf_event_copy(event);
+ ok(copy, "bt_ctf_event_copy returns a valid pointer");
+
+ /* validate event class */
+ orig_event_class = bt_ctf_event_get_class(event);
+ assert(orig_event_class);
+ copy_event_class = bt_ctf_event_get_class(copy);
+ ok(orig_event_class == copy_event_class,
+ "original and copied events share the same event class pointer");
+ bt_ctf_event_class_put(orig_event_class);
+ bt_ctf_event_class_put(copy_event_class);
+
+ /* validate stream */
+ orig_stream = bt_ctf_event_get_stream(event);
+ copy_stream = bt_ctf_event_get_stream(copy);
+
+ if (!orig_stream) {
+ ok(!copy_stream, "original and copied events have no stream");
+ } else {
+ ok(orig_stream == copy_stream,
+ "original and copied events share the same stream pointer");
+ }
+ bt_ctf_stream_put(orig_stream);
+ bt_ctf_stream_put(copy_stream);
+
+ /* header */
+ orig_field = bt_ctf_event_get_header(event);
+ copy_field = bt_ctf_event_get_header(copy);
+
+ if (!orig_field) {
+ ok(!copy_field, "original and copied events have no header");
+ } else {
+ ok(orig_field != copy_field,
+ "original and copied events headers are different pointers");
+ }
+
+ bt_ctf_field_put(orig_field);
+ bt_ctf_field_put(copy_field);
+
+ /* context */
+ orig_field = bt_ctf_event_get_event_context(event);
+ copy_field = bt_ctf_event_get_event_context(copy);
+
+ if (!orig_field) {
+ ok(!copy_field, "original and copied events have no context");
+ } else {
+ ok(orig_field != copy_field,
+ "original and copied events contexts are different pointers");
+ }
+
+ bt_ctf_field_put(orig_field);
+ bt_ctf_field_put(copy_field);
+
+ /* payload */
+ orig_field = bt_ctf_event_get_payload_field(event);
+ copy_field = bt_ctf_event_get_payload_field(copy);
+
+ if (!orig_field) {
+ ok(!copy_field, "original and copied events have no payload");
+ } else {
+ ok(orig_field != copy_field,
+ "original and copied events payloads are different pointers");
+ }
+
+ bt_ctf_field_put(orig_field);
+ bt_ctf_field_put(copy_field);
+
+ bt_ctf_event_put(copy);
+}
+
void append_simple_event(struct bt_ctf_stream_class *stream_class,
struct bt_ctf_stream *stream, struct bt_ctf_clock *clock)
{
ok(!bt_ctf_event_set_event_context(simple_event, event_context),
"Set an event context successfully");
+ event_copy_tests(simple_event);
ok(bt_ctf_stream_append_event(stream, simple_event) == 0,
"Append simple event to trace stream");
ok(bt_ctf_field_type_variant_get_tag_name(NULL) == NULL,
"bt_ctf_field_type_variant_get_tag_name handles NULL correctly");
ret_string = bt_ctf_field_type_variant_get_tag_name(variant_type);
- ok(!strcmp(ret_string, "variant_selector"),
+ ok(ret_string ? !strcmp(ret_string, "variant_selector") : 0,
"bt_ctf_field_type_variant_get_tag_name returns the correct variant tag name");
ok(bt_ctf_field_type_variant_get_field_type_by_name(NULL,
"INT16_TYPE") == NULL,
ok(bt_ctf_field_type_variant_get_field(NULL, &ret_string, &ret_field_type, 0) < 0,
"bt_ctf_field_type_variant_get_field handles a NULL type correctly");
- ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) < 0,
+ ok(bt_ctf_field_type_variant_get_field(variant_type, NULL, &ret_field_type, 0) == 0,
"bt_ctf_field_type_variant_get_field handles a NULL field name correctly");
- ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) < 0,
+ bt_ctf_field_type_put(ret_field_type);
+ ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, NULL, 0) == 0,
"bt_ctf_field_type_variant_get_field handles a NULL field type correctly");
ok(bt_ctf_field_type_variant_get_field(variant_type, &ret_string, &ret_field_type, 200) < 0,
"bt_ctf_field_type_variant_get_field handles an invalid index correctly");
&ret_field_type, 0) < 0,
"bt_ctf_event_class_get_field handles a NULL event class correctly");
ok(bt_ctf_event_class_get_field(event_class, NULL,
- &ret_field_type, 0) < 0,
+ &ret_field_type, 0) == 0,
"bt_ctf_event_class_get_field handles a NULL field name correctly");
+ bt_ctf_field_type_put(ret_field_type);
ok(bt_ctf_event_class_get_field(event_class, &ret_string,
- NULL, 0) < 0,
+ NULL, 0) == 0,
"bt_ctf_event_class_get_field handles a NULL field type correctly");
ok(bt_ctf_event_class_get_field(event_class, &ret_string,
&ret_field_type, 42) < 0,
struct bt_ctf_field *e = NULL;
struct bt_ctf_field *v = NULL;
struct bt_ctf_field *v_selected = NULL;
+ struct bt_ctf_field *v_selected_cur = NULL;
struct bt_ctf_field *v_selected_0 = NULL;
struct bt_ctf_field *v_selected_1 = NULL;
struct bt_ctf_field *v_selected_2 = NULL;
/* set v field */
v_selected = bt_ctf_field_variant_get_field(v, e);
assert(v_selected);
+ ok(!bt_ctf_field_variant_get_current_field(NULL),
+ "bt_ctf_field_variant_get_current_field handles NULL correctly");
+ v_selected_cur = bt_ctf_field_variant_get_current_field(v);
+ ok(v_selected_cur == v_selected,
+ "bt_ctf_field_variant_get_current_field returns the current field");
+ bt_ctf_field_put(v_selected_cur);
/* set selected v field */
ret = bt_ctf_field_sequence_set_length(v_selected, len);
&ret_string, &returned_type, 1) < 0,
"bt_ctf_field_type_structure_get_field handles a NULL type correctly");
ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
- NULL, &returned_type, 1) < 0,
+ NULL, &returned_type, 1) == 0,
"bt_ctf_field_type_structure_get_field handles a NULL name correctly");
+ bt_ctf_field_type_put(returned_type);
ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
- &ret_string, NULL, 1) < 0,
+ &ret_string, NULL, 1) == 0,
"bt_ctf_field_type_structure_get_field handles a NULL return type correctly");
ok(bt_ctf_field_type_structure_get_field(structure_seq_type,
&ret_string, &returned_type, 10) < 0,