Add static trace tests
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Wed, 26 Apr 2017 18:49:19 +0000 (14:49 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:41 +0000 (12:57 -0400)
Those new tests validate that you cannot indeed modify a trace (add
clock classes, add stream classes, create streams) when it's static.

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 1995d3d93bb79ab7e7e03d750de186e80023320a..e05b3d285fec49242e47a00317d759614055ca29 100644 (file)
@@ -28,6 +28,7 @@
 #include <babeltrace/ctf-writer/stream-class.h>
 #include <babeltrace/ctf-ir/packet.h>
 #include <babeltrace/ctf-ir/clock-class.h>
+#include <babeltrace/ctf-ir/trace.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/ctf/events.h>
 #include <babeltrace/values.h>
@@ -60,7 +61,7 @@
 #define DEFAULT_CLOCK_TIME 0
 #define DEFAULT_CLOCK_VALUE 0
 
-#define NR_TESTS 601
+#define NR_TESTS 611
 
 static int64_t current_time = 42;
 
@@ -2772,6 +2773,51 @@ void test_set_clock_non_writer_stream_class(void)
        bt_put(sc);
 }
 
+static
+void test_static_trace(void)
+{
+       struct bt_ctf_trace *trace;
+       struct bt_ctf_stream_class *stream_class;
+       struct bt_ctf_stream_class *stream_class2;
+       struct bt_ctf_stream *stream;
+       struct bt_ctf_clock_class *clock_class;
+       int ret;
+
+       trace = bt_ctf_trace_create();
+       assert(trace);
+       ret = bt_ctf_trace_set_native_byte_order(trace,
+               BT_CTF_BYTE_ORDER_LITTLE_ENDIAN);
+       assert(ret == 0);
+       stream_class = bt_ctf_stream_class_create(NULL);
+       assert(stream_class);
+       ret = bt_ctf_trace_add_stream_class(trace, stream_class);
+       assert(ret == 0);
+       stream = bt_ctf_stream_create(stream_class, "hello");
+       ok(stream, "bt_ctf_stream_create() succeeds with a non-static trace");
+       bt_put(stream);
+       ok(!bt_ctf_trace_is_static(trace),
+               "bt_ctf_trace_is_static() returns the expected value");
+       ok(bt_ctf_trace_set_is_static(trace) == 0,
+               "bt_ctf_trace_set_is_static() succeeds");
+       ok(bt_ctf_trace_is_static(trace),
+               "bt_ctf_trace_is_static() returns the expected value");
+       clock_class = bt_ctf_clock_class_create("yes");
+       assert(clock_class);
+       stream_class2 = bt_ctf_stream_class_create(NULL);
+       assert(stream_class2);
+       ok(bt_ctf_trace_add_stream_class(trace, stream_class2),
+               "bt_ctf_trace_add_stream_class() fails with a static trace");
+       ok(bt_ctf_trace_add_clock_class(trace, clock_class),
+               "bt_ctf_trace_add_clock_class() fails with a static trace");
+       ok(!bt_ctf_stream_create(stream_class, "hello2"),
+               "bt_ctf_stream_create() fails with a static trace");
+
+       bt_put(trace);
+       bt_put(stream_class);
+       bt_put(stream_class2);
+       bt_put(clock_class);
+}
+
 int main(int argc, char **argv)
 {
        char trace_path[] = "/tmp/ctfwriter_XXXXXX";
@@ -3425,6 +3471,8 @@ int main(int argc, char **argv)
 
        test_custom_event_header_stream(writer, clock);
 
+       test_static_trace();
+
        metadata_string = bt_ctf_writer_get_metadata_string(writer);
        ok(metadata_string, "Get metadata string");
 
This page took 0.027411 seconds and 4 git commands to generate.