Standardize `strcmp(a, b) == 0` instead of `!strcmp(a, b)`
[babeltrace.git] / tests / lib / test_bt_values.c
index f9526379ca2ed5c907f28e075d756c370549c113..b0cd85931f19108b926017151b15e30e2185df55 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #include <babeltrace2/babeltrace.h>
-#include <babeltrace2/assert-internal.h>
+#include "common/assert.h"
 #include <string.h>
 #include "tap/tap.h"
 
@@ -177,12 +177,12 @@ void test_string(void)
                "bt_value_string_create() returns a string value object");
 
        value = bt_value_string_get(obj);
-       ok(value && !strcmp(value, ""),
+       ok(value && strcmp(value, "") == 0,
                "default string value object value is \"\"");
 
        bt_value_string_set(obj, "hello worldz");
        value = bt_value_string_get(obj);
-       ok(value && !strcmp(value, "hello worldz"),
+       ok(value && strcmp(value, "hello worldz") == 0,
                "bt_value_string_get() works");
 
        BT_VALUE_PUT_REF_AND_RESET(obj);
@@ -192,7 +192,7 @@ void test_string(void)
        ok(obj && bt_value_is_string(obj),
                "bt_value_string_create_init() returns a string value object");
        value = bt_value_string_get(obj);
-       ok(value && !strcmp(value, "initial value"),
+       ok(value && strcmp(value, "initial value") == 0,
                "bt_value_string_create_init() sets the appropriate initial value");
 
        BT_VALUE_PUT_REF_AND_RESET(obj);
@@ -327,7 +327,7 @@ void test_array(void)
        ok(obj && bt_value_is_string(obj),
                "bt_value_array_append_string_element() appends a string value object");
        string_value = bt_value_string_get(obj);
-       ok(!ret && string_value && !strcmp(string_value, "bt_value"),
+       ok(!ret && string_value && strcmp(string_value, "bt_value") == 0,
                "bt_value_array_append_string_element() appends the appropriate value");
        obj = bt_value_array_borrow_element_by_index(array_obj, 10);
        ok(obj && bt_value_is_array(obj),
@@ -379,7 +379,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
 {
        struct map_foreach_checklist *checklist = data;
 
-       if (!strcmp(key, "bt_bool")) {
+       if (strcmp(key, "bt_bool") == 0) {
                if (checklist->bool1) {
                        fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
                } else {
@@ -394,7 +394,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"bt_bool\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "uint")) {
+       } else if (strcmp(key, "uint") == 0) {
                if (checklist->uint) {
                        fail("test_map_foreach_cb_check(): duplicate key \"uint\"");
                } else {
@@ -409,7 +409,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"uint\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "int")) {
+       } else if (strcmp(key, "int") == 0) {
                if (checklist->int1) {
                        fail("test_map_foreach_cb_check(): duplicate key \"int\"");
                } else {
@@ -424,7 +424,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"int\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "real")) {
+       } else if (strcmp(key, "real") == 0) {
                if (checklist->real1) {
                        fail("test_map_foreach_cb_check(): duplicate key \"real\"");
                } else {
@@ -439,14 +439,14 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"real\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "null")) {
+       } else if (strcmp(key, "null") == 0) {
                if (checklist->null1) {
                        fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\"");
                } else {
                        ok(bt_value_is_null(object), "test_map_foreach_cb_check(): success getting \"null\" value object");
                        checklist->null1 = BT_TRUE;
                }
-       } else if (!strcmp(key, "bool2")) {
+       } else if (strcmp(key, "bool2") == 0) {
                if (checklist->bool2) {
                        fail("test_map_foreach_cb_check(): duplicate key \"bool2\"");
                } else {
@@ -461,7 +461,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"bool2\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "int2")) {
+       } else if (strcmp(key, "int2") == 0) {
                if (checklist->int2) {
                        fail("test_map_foreach_cb_check(): duplicate key \"int2\"");
                } else {
@@ -476,7 +476,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"int2\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "real2")) {
+       } else if (strcmp(key, "real2") == 0) {
                if (checklist->real2) {
                        fail("test_map_foreach_cb_check(): duplicate key \"real2\"");
                } else {
@@ -491,7 +491,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"real2\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "string2")) {
+       } else if (strcmp(key, "string2") == 0) {
                if (checklist->string2) {
                        fail("test_map_foreach_cb_check(): duplicate key \"string2\"");
                } else {
@@ -499,14 +499,14 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
 
                        val = bt_value_string_get(object);
 
-                       if (val && !strcmp(val, "bt_value")) {
+                       if (val && strcmp(val, "bt_value") == 0) {
                                pass("test_map_foreach_cb_check(): \"string2\" value object has the right value");
                                checklist->string2 = BT_TRUE;
                        } else {
                                fail("test_map_foreach_cb_check(): \"string2\" value object has the wrong value");
                        }
                }
-       } else if (!strcmp(key, "array2")) {
+       } else if (strcmp(key, "array2") == 0) {
                if (checklist->array2) {
                        fail("test_map_foreach_cb_check(): duplicate key \"array2\"");
                } else {
@@ -515,7 +515,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                "test_map_foreach_cb_check(): \"array2\" value object is empty");
                        checklist->array2 = BT_TRUE;
                }
-       } else if (!strcmp(key, "map2")) {
+       } else if (strcmp(key, "map2") == 0) {
                if (checklist->map2) {
                        fail("test_map_foreach_cb_check(): duplicate key \"map2\"");
                } else {
@@ -651,13 +651,13 @@ void test_map(void)
 
        ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_count,
                &count);
-       ok(ret == BT_VALUE_STATUS_CANCELED && count == 3,
+       ok(ret == BT_VALUE_MAP_FOREACH_ENTRY_STATUS_CANCELED && count == 3,
                "bt_value_map_foreach_entry() breaks the loop when the user function returns BT_FALSE");
 
        memset(&checklist, 0, sizeof(checklist));
        ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_check,
                &checklist);
-       ok(ret == BT_VALUE_STATUS_OK,
+       ok(ret == BT_VALUE_MAP_FOREACH_ENTRY_STATUS_OK,
                "bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()");
        ok(checklist.bool1 && checklist.uint && checklist.int1 &&
                checklist.real1 && checklist.null1 && checklist.bool2 &&
@@ -822,31 +822,31 @@ void test_compare_array(void)
        bt_value *array1 = bt_value_array_create();
        bt_value *array2 = bt_value_array_create();
        bt_value *array3 = bt_value_array_create();
-       bt_value_status status;
+       bt_value_array_append_element_status append_status;
 
        BT_ASSERT(array1 && array2 && array3);
 
        ok(bt_value_compare(array1, array2),
                "empty array value objects are equivalent");
 
-       status = bt_value_array_append_signed_integer_element(array1, 23);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_real_element(array1, 14.2);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_bool_element(array1, BT_FALSE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_real_element(array2, 14.2);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_signed_integer_element(array2, 23);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_bool_element(array2, BT_FALSE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_signed_integer_element(array3, 23);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_real_element(array3, 14.2);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_bool_element(array3, BT_FALSE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
+       append_status = bt_value_array_append_signed_integer_element(array1, 23);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_real_element(array1, 14.2);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_bool_element(array1, BT_FALSE);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_real_element(array2, 14.2);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_signed_integer_element(array2, 23);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_bool_element(array2, BT_FALSE);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_signed_integer_element(array3, 23);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_real_element(array3, 14.2);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_bool_element(array3, BT_FALSE);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
        BT_ASSERT(bt_value_array_get_size(array1) == 3);
        BT_ASSERT(bt_value_array_get_size(array2) == 3);
        BT_ASSERT(bt_value_array_get_size(array3) == 3);
@@ -872,7 +872,7 @@ void test_compare_map(void)
        bt_value *map1 = bt_value_map_create();
        bt_value *map2 = bt_value_map_create();
        bt_value *map3 = bt_value_map_create();
-       bt_value_status status;
+       bt_value_map_insert_entry_status insert_status;
 
        BT_ASSERT(map1 && map2 && map3);
 
@@ -881,27 +881,27 @@ void test_compare_map(void)
                "empty map value objects are equivalent");
 
 
-       status = bt_value_map_insert_signed_integer_entry(map1, "one", 23);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_real_entry(map1, "two", 14.2);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_bool_entry(map1, "three",
+       insert_status = bt_value_map_insert_signed_integer_entry(map1, "one", 23);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_real_entry(map1, "two", 14.2);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_bool_entry(map1, "three",
                BT_FALSE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_real_entry(map2, "one", 14.2);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_signed_integer_entry(map2, "two", 23);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_bool_entry(map2, "three",
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_real_entry(map2, "one", 14.2);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_signed_integer_entry(map2, "two", 23);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_bool_entry(map2, "three",
                BT_FALSE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_bool_entry(map3, "three",
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_bool_entry(map3, "three",
                BT_FALSE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_signed_integer_entry(map3, "one", 23);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_real_entry(map3, "two", 14.2);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_signed_integer_entry(map3, "one", 23);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_real_entry(map3, "two", 14.2);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
        BT_ASSERT(bt_value_map_get_size(map1) == 3);
        BT_ASSERT(bt_value_map_get_size(map2) == 3);
        BT_ASSERT(bt_value_map_get_size(map3) == 3);
@@ -953,7 +953,9 @@ void test_copy(void)
        bt_value *string_obj, *string_copy_obj;
        bt_value *array_obj, *array_copy_obj;
        bt_value *map_obj, *map_copy_obj;
-       bt_value_status status;
+       bt_value_array_append_element_status append_status;
+       bt_value_map_insert_entry_status insert_status;
+       bt_value_copy_status copy_status;
 
        bool_obj = bt_value_bool_create_init(BT_TRUE);
        unsigned_integer_obj = bt_value_unsigned_integer_create_init(23);
@@ -966,23 +968,23 @@ void test_copy(void)
        BT_ASSERT(bool_obj && unsigned_integer_obj && signed_integer_obj &&
                real_obj && string_obj && array_obj && map_obj);
 
-       status = bt_value_array_append_element(array_obj, bool_obj);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_element(array_obj, unsigned_integer_obj);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_element(array_obj, signed_integer_obj);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_element(array_obj, real_obj);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_element(array_obj, bt_value_null);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_entry(map_obj, "array", array_obj);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_entry(map_obj, "string", string_obj);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-
-       status = bt_value_copy(map_obj, &map_copy_obj);
-       ok(status == BT_VALUE_STATUS_OK && map_copy_obj,
+       append_status = bt_value_array_append_element(array_obj, bool_obj);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_element(array_obj, unsigned_integer_obj);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_element(array_obj, signed_integer_obj);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_element(array_obj, real_obj);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       append_status = bt_value_array_append_element(array_obj, bt_value_null);
+       BT_ASSERT(append_status == BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK);
+       insert_status = bt_value_map_insert_entry(map_obj, "array", array_obj);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_entry(map_obj, "string", string_obj);
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+
+       copy_status = bt_value_copy(map_obj, &map_copy_obj);
+       ok(copy_status == BT_VALUE_COPY_STATUS_OK && map_copy_obj,
                "bt_value_copy() succeeds");
 
        ok(map_obj != map_copy_obj,
@@ -1050,34 +1052,35 @@ void test_extend(void)
        bt_value *extension_map = bt_value_map_create();
        bt_value *extended_map = NULL;
        bt_value *array = bt_value_array_create();
-       bt_value_status status;
+       bt_value_map_insert_entry_status insert_status;
+       bt_value_map_extend_status extend_status;
 
        BT_ASSERT(base_map);
        BT_ASSERT(extension_map);
        BT_ASSERT(array);
-       status = bt_value_map_insert_bool_entry(base_map, "file",
+       insert_status = bt_value_map_insert_bool_entry(base_map, "file",
                BT_TRUE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_bool_entry(base_map, "edit",
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_bool_entry(base_map, "edit",
                BT_FALSE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_signed_integer_entry(base_map,
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_signed_integer_entry(base_map,
                "selection", 17);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_signed_integer_entry(base_map, "find",
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_signed_integer_entry(base_map, "find",
                -34);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_bool_entry(extension_map, "edit",
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_bool_entry(extension_map, "edit",
                BT_TRUE);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_signed_integer_entry(extension_map,
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_signed_integer_entry(extension_map,
                "find", 101);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_real_entry(extension_map,
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       insert_status = bt_value_map_insert_real_entry(extension_map,
                "project", -404);
-       BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_extend(base_map, extension_map, &extended_map);
-       ok(status == BT_VALUE_STATUS_OK &&
+       BT_ASSERT(insert_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK);
+       extend_status = bt_value_map_extend(base_map, extension_map, &extended_map);
+       ok(extend_status == BT_VALUE_MAP_EXTEND_STATUS_OK &&
                extended_map, "bt_value_map_extend() succeeds");
        ok(bt_value_map_get_size(extended_map) == 5,
                "bt_value_map_extend() returns a map object with the correct size");
This page took 0.031397 seconds and 4 git commands to generate.