ir: add tests for bt_ctf_event_copy()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 8 Apr 2015 00:04:47 +0000 (20:04 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 28 Apr 2015 19:48:04 +0000 (15:48 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/lib/test_ctf_writer.c

index d0c5136948adfaeb8c37ad334be6f9e9d895ab58..d1a61eaa1aed70e51d07b7a4d7c484ba175f380b 100644 (file)
@@ -276,6 +276,89 @@ close_fp:
        }
 }
 
+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)
 {
@@ -599,6 +682,7 @@ void append_simple_event(struct bt_ctf_stream_class *stream_class,
        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");
 
This page took 0.026837 seconds and 4 git commands to generate.