ir: add tests for bt_ctf_trace_get_clock_by_name()
[babeltrace.git] / formats / ctf / ir / clock.c
index f0213868c3ad32a4ab9b1fb17f244a562ceabd22..d1f435d50ae567ed6d879b32ce8647ca962bb2ac 100644 (file)
@@ -26,8 +26,8 @@
  * SOFTWARE.
  */
 
-#include <babeltrace/ctf-writer/clock.h>
 #include <babeltrace/ctf-ir/clock-internal.h>
+#include <babeltrace/ctf-ir/utils.h>
 #include <babeltrace/ctf-writer/writer-internal.h>
 #include <babeltrace/compiler.h>
 #include <inttypes.h>
@@ -47,7 +47,6 @@ struct bt_ctf_clock *_bt_ctf_clock_create(void)
 
        clock->precision = 1;
        clock->frequency = 1000000000;
-       uuid_generate(clock->uuid);
        bt_ctf_ref_init(&clock->ref_count);
 end:
        return clock;
@@ -59,20 +58,21 @@ int bt_ctf_clock_set_name(struct bt_ctf_clock *clock,
 {
        int ret = 0;
 
-       if (validate_identifier(name)) {
+       if (bt_ctf_validate_identifier(name)) {
                ret = -1;
                goto end;
        }
 
        if (clock->name) {
-               g_string_free(clock->name, TRUE);
+               g_string_assign(clock->name, name);
+       } else {
+               clock->name = g_string_new(name);
+               if (!clock->name) {
+                       ret = -1;
+                       goto end;
+               }
        }
 
-       clock->name = g_string_new(name);
-       if (!clock->name) {
-               ret = -1;
-               goto end;
-       }
 end:
        return ret;
 }
@@ -92,6 +92,12 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
                goto error_destroy;
        }
 
+       ret = babeltrace_uuid_generate(clock->uuid);
+       if (ret) {
+               goto error_destroy;
+       }
+
+       clock->uuid_set = 1;
        return clock;
 error_destroy:
        bt_ctf_clock_destroy(&clock->ref_count);
@@ -284,7 +290,7 @@ const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock)
 {
        const unsigned char *ret;
 
-       if (!clock) {
+       if (!clock || !clock->uuid_set) {
                ret = NULL;
                goto end;
        }
@@ -298,12 +304,13 @@ int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock, const unsigned char *uuid)
 {
        int ret = 0;
 
-       if (!clock || !uuid) {
+       if (!clock || !uuid || clock->frozen) {
                ret = -1;
                goto end;
        }
 
        memcpy(clock->uuid, uuid, sizeof(uuid_t));
+       clock->uuid_set = 1;
 end:
        return ret;
 }
@@ -384,7 +391,7 @@ void bt_ctf_clock_serialize(struct bt_ctf_clock *clock,
                uuid[4], uuid[5], uuid[6], uuid[7],
                uuid[8], uuid[9], uuid[10], uuid[11],
                uuid[12], uuid[13], uuid[14], uuid[15]);
-       if (clock->description->len) {
+       if (clock->description) {
                g_string_append_printf(context->string, "\tdescription = \"%s\";\n",
                        clock->description->str);
        }
This page took 0.04197 seconds and 4 git commands to generate.