X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=tests%2Flib%2Ftest_bt_values.c;h=bd8f22d54e5c54f69ae21566b705cb4b561fd8cb;hb=b203788ab367147e99df0e95dc9be62cd49c7f45;hp=4eb20ba51dbd4b80d4115dce22f246dab40410b4;hpb=3842465694945829d76452ff83924aa0103c6293;p=babeltrace.git diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index 4eb20ba5..bd8f22d5 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -1,7 +1,7 @@ /* * test_bt_values.c * - * Babeltrace value value objects tests + * Babeltrace value objects tests * * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation * Copyright (c) 2015 Philippe Proulx @@ -20,11 +20,14 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include #include #include #include #include "tap/tap.h" +#define NR_TESTS 249 + static void test_null(void) { @@ -49,18 +52,18 @@ static void test_bool(void) { int ret; - bool value; + bt_bool value; struct bt_value *obj; obj = bt_value_bool_create(); ok(obj && bt_value_is_bool(obj), "bt_value_bool_create() returns a boolean value object"); - value = true; + value = BT_TRUE; ret = bt_value_bool_get(obj, &value); - ok(!ret && !value, "default boolean value object value is false"); + ok(!ret && !value, "default boolean value object value is BT_FALSE"); - ret = bt_value_bool_set(NULL, true); + ret = bt_value_bool_set(NULL, BT_TRUE); ok(ret == BT_VALUE_STATUS_INVAL, "bt_value_bool_set() fails with an value object set to NULL"); ret = bt_value_bool_get(NULL, &value); @@ -70,8 +73,8 @@ void test_bool(void) ok(ret == BT_VALUE_STATUS_INVAL, "bt_value_bool_get() fails with a return value set to NULL"); - assert(!bt_value_bool_set(obj, false)); - ret = bt_value_bool_set(obj, true); + assert(!bt_value_bool_set(obj, BT_FALSE)); + ret = bt_value_bool_set(obj, BT_TRUE); ok(!ret, "bt_value_bool_set() succeeds"); ret = bt_value_bool_get(obj, &value); ok(!ret && value, "bt_value_bool_set() works"); @@ -79,8 +82,8 @@ void test_bool(void) BT_PUT(obj); pass("putting an existing boolean value object does not cause a crash") - value = false; - obj = bt_value_bool_create_init(true); + value = BT_FALSE; + obj = bt_value_bool_create_init(BT_TRUE); ok(obj && bt_value_is_bool(obj), "bt_value_bool_create_init() returns a boolean value object"); ret = bt_value_bool_get(obj, &value); @@ -88,9 +91,9 @@ void test_bool(void) "bt_value_bool_create_init() sets the appropriate initial value"); assert(!bt_value_freeze(obj)); - ok(bt_value_bool_set(obj, false) == BT_VALUE_STATUS_FROZEN, + ok(bt_value_bool_set(obj, BT_FALSE) == BT_VALUE_STATUS_FROZEN, "bt_value_bool_set() cannot be called on a frozen boolean value object"); - value = false; + value = BT_FALSE; ret = bt_value_bool_get(obj, &value); ok(!ret && value, "bt_value_bool_set() does not alter a frozen floating point number value object"); @@ -262,7 +265,7 @@ static void test_array(void) { int ret; - bool bool_value; + bt_bool bool_value; int64_t int_value; double float_value; struct bt_value *obj; @@ -272,8 +275,8 @@ void test_array(void) array_obj = bt_value_array_create(); ok(array_obj && bt_value_is_array(array_obj), "bt_value_array_create() returns an array value object"); - ok(bt_value_array_is_empty(NULL) == false, - "bt_value_array_is_empty() returns false with an value object set to NULL"); + ok(bt_value_array_is_empty(NULL) == BT_FALSE, + "bt_value_array_is_empty() returns BT_FALSE with an value object set to NULL"); ok(bt_value_array_is_empty(array_obj), "initial array value object size is 0"); ok(bt_value_array_size(NULL) == BT_VALUE_STATUS_INVAL, @@ -291,7 +294,7 @@ void test_array(void) obj = bt_value_float_create_init(-17.45); ret |= bt_value_array_append(array_obj, obj); BT_PUT(obj); - obj = bt_value_bool_create_init(true); + obj = bt_value_bool_create_init(BT_TRUE); ret |= bt_value_array_append(array_obj, obj); BT_PUT(obj); ret |= bt_value_array_append(array_obj, bt_value_null); @@ -354,9 +357,9 @@ void test_array(void) "bt_value_array_set() inserts an value object with the appropriate value"); BT_PUT(obj); - ret = bt_value_array_append_bool(array_obj, false); + ret = bt_value_array_append_bool(array_obj, BT_FALSE); ok(!ret, "bt_value_array_append_bool() succeeds"); - ok(bt_value_array_append_bool(NULL, true) == BT_VALUE_STATUS_INVAL, + ok(bt_value_array_append_bool(NULL, BT_TRUE) == BT_VALUE_STATUS_INVAL, "bt_value_array_append_bool() fails with an array value object set to NULL"); ret = bt_value_array_append_integer(array_obj, 98765); ok(!ret, "bt_value_array_append_integer() succeeds"); @@ -373,14 +376,14 @@ void test_array(void) ok(bt_value_array_append_string(NULL, "bt_obj") == BT_VALUE_STATUS_INVAL, "bt_value_array_append_string() fails with an array value object set to NULL"); - ret = bt_value_array_append_array(array_obj); - ok(!ret, "bt_value_array_append_array() succeeds"); - ok(bt_value_array_append_array(NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_array_append_array() fails with an array value object set to NULL"); - ret = bt_value_array_append_map(array_obj); - ok(!ret, "bt_value_array_append_map() succeeds"); - ok(bt_value_array_append_map(NULL) == BT_VALUE_STATUS_INVAL, - "bt_value_array_append_map() fails with an array value object set to NULL"); + ret = bt_value_array_append_empty_array(array_obj); + ok(!ret, "bt_value_array_append_empty_array() succeeds"); + ok(bt_value_array_append_empty_array(NULL) == BT_VALUE_STATUS_INVAL, + "bt_value_array_append_empty_array() fails with an array value object set to NULL"); + ret = bt_value_array_append_empty_map(array_obj); + ok(!ret, "bt_value_array_append_empty_map() succeeds"); + ok(bt_value_array_append_empty_map(NULL) == BT_VALUE_STATUS_INVAL, + "bt_value_array_append_empty_map() fails with an array value object set to NULL"); ok(bt_value_array_size(array_obj) == 10, "the bt_value_array_append_*() functions increment the array value object's size"); @@ -417,22 +420,22 @@ void test_array(void) BT_PUT(obj); obj = bt_value_array_get(array_obj, 8); ok(obj && bt_value_is_array(obj), - "bt_value_array_append_array() appends an array value object"); + "bt_value_array_append_empty_array() appends an array value object"); ok(bt_value_array_is_empty(obj), - "bt_value_array_append_array() an empty array value object"); + "bt_value_array_append_empty_array() an empty array value object"); BT_PUT(obj); obj = bt_value_array_get(array_obj, 9); ok(obj && bt_value_is_map(obj), - "bt_value_array_append_map() appends a map value object"); + "bt_value_array_append_empty_map() appends a map value object"); ok(bt_value_map_is_empty(obj), - "bt_value_array_append_map() an empty map value object"); + "bt_value_array_append_empty_map() an empty map value object"); BT_PUT(obj); assert(!bt_value_freeze(array_obj)); ok(bt_value_array_append(array_obj, bt_value_null) == BT_VALUE_STATUS_FROZEN, "bt_value_array_append() fails with a frozen array value object"); - ok(bt_value_array_append_bool(array_obj, false) == + ok(bt_value_array_append_bool(array_obj, BT_FALSE) == BT_VALUE_STATUS_FROZEN, "bt_value_array_append_bool() fails with a frozen array value object"); ok(bt_value_array_append_integer(array_obj, 23) == @@ -444,12 +447,12 @@ void test_array(void) ok(bt_value_array_append_string(array_obj, "yayayayaya") == BT_VALUE_STATUS_FROZEN, "bt_value_array_append_string() fails with a frozen array value object"); - ok(bt_value_array_append_array(array_obj) == + ok(bt_value_array_append_empty_array(array_obj) == BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_array() fails with a frozen array value object"); - ok(bt_value_array_append_map(array_obj) == + "bt_value_array_append_empty_array() fails with a frozen array value object"); + ok(bt_value_array_append_empty_map(array_obj) == BT_VALUE_STATUS_FROZEN, - "bt_value_array_append_map() fails with a frozen array value object"); + "bt_value_array_append_empty_map() fails with a frozen array value object"); ok(bt_value_array_set(array_obj, 2, bt_value_null) == BT_VALUE_STATUS_FROZEN, "bt_value_array_set() fails with a frozen array value object"); @@ -467,54 +470,54 @@ void test_array(void) } static -bool test_map_foreach_cb_count(const char *key, struct bt_value *object, +bt_bool test_map_foreach_cb_count(const char *key, struct bt_value *object, void *data) { int *count = data; if (*count == 3) { - return false; + return BT_FALSE; } (*count)++; - return true; + return BT_TRUE; } struct map_foreach_checklist { - bool bool1; - bool int1; - bool float1; - bool null1; - bool bool2; - bool int2; - bool float2; - bool string2; - bool array2; - bool map2; + bt_bool bool1; + bt_bool int1; + bt_bool float1; + bt_bool null1; + bt_bool bool2; + bt_bool int2; + bt_bool float2; + bt_bool string2; + bt_bool array2; + bt_bool map2; }; static -bool test_map_foreach_cb_check(const char *key, struct bt_value *object, +bt_bool test_map_foreach_cb_check(const char *key, struct bt_value *object, void *data) { int ret; struct map_foreach_checklist *checklist = data; - if (!strcmp(key, "bool")) { + if (!strcmp(key, "bt_bool")) { if (checklist->bool1) { - fail("test_map_foreach_cb_check(): duplicate key \"bool\""); + fail("test_map_foreach_cb_check(): duplicate key \"bt_bool\""); } else { - bool val = false; + bt_bool val = BT_FALSE; ret = bt_value_bool_get(object, &val); - ok(!ret, "test_map_foreach_cb_check(): success getting \"bool\" value"); + ok(!ret, "test_map_foreach_cb_check(): success getting \"bt_bool\" value"); if (val) { - pass("test_map_foreach_cb_check(): \"bool\" value object has the right value"); - checklist->bool1 = true; + pass("test_map_foreach_cb_check(): \"bt_bool\" value object has the right value"); + checklist->bool1 = BT_TRUE; } else { - fail("test_map_foreach_cb_check(): \"bool\" value object has the wrong value"); + fail("test_map_foreach_cb_check(): \"bt_bool\" value object has the wrong value"); } } } else if (!strcmp(key, "int")) { @@ -528,7 +531,7 @@ bool test_map_foreach_cb_check(const char *key, struct bt_value *object, if (val == 19457) { pass("test_map_foreach_cb_check(): \"int\" value object has the right value"); - checklist->int1 = true; + checklist->int1 = BT_TRUE; } else { fail("test_map_foreach_cb_check(): \"int\" value object has the wrong value"); } @@ -544,30 +547,30 @@ bool test_map_foreach_cb_check(const char *key, struct bt_value *object, if (val == 5.444) { pass("test_map_foreach_cb_check(): \"float\" value object has the right value"); - checklist->float1 = true; + checklist->float1 = BT_TRUE; } else { fail("test_map_foreach_cb_check(): \"float\" value object has the wrong value"); } } } else if (!strcmp(key, "null")) { if (checklist->null1) { - fail("test_map_foreach_cb_check(): duplicate key \"bool\""); + 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 = true; + checklist->null1 = BT_TRUE; } } else if (!strcmp(key, "bool2")) { if (checklist->bool2) { fail("test_map_foreach_cb_check(): duplicate key \"bool2\""); } else { - bool val = false; + bt_bool val = BT_FALSE; ret = bt_value_bool_get(object, &val); ok(!ret, "test_map_foreach_cb_check(): success getting \"bool2\" value"); if (val) { pass("test_map_foreach_cb_check(): \"bool2\" value object has the right value"); - checklist->bool2 = true; + checklist->bool2 = BT_TRUE; } else { fail("test_map_foreach_cb_check(): \"bool2\" value object has the wrong value"); } @@ -583,7 +586,7 @@ bool test_map_foreach_cb_check(const char *key, struct bt_value *object, if (val == 98765) { pass("test_map_foreach_cb_check(): \"int2\" value object has the right value"); - checklist->int2 = true; + checklist->int2 = BT_TRUE; } else { fail("test_map_foreach_cb_check(): \"int2\" value object has the wrong value"); } @@ -599,7 +602,7 @@ bool test_map_foreach_cb_check(const char *key, struct bt_value *object, if (val == -49.0001) { pass("test_map_foreach_cb_check(): \"float2\" value object has the right value"); - checklist->float2 = true; + checklist->float2 = BT_TRUE; } else { fail("test_map_foreach_cb_check(): \"float2\" value object has the wrong value"); } @@ -615,7 +618,7 @@ bool test_map_foreach_cb_check(const char *key, struct bt_value *object, if (val && !strcmp(val, "bt_value")) { pass("test_map_foreach_cb_check(): \"string2\" value object has the right value"); - checklist->string2 = true; + checklist->string2 = BT_TRUE; } else { fail("test_map_foreach_cb_check(): \"string2\" value object has the wrong value"); } @@ -627,7 +630,7 @@ bool test_map_foreach_cb_check(const char *key, struct bt_value *object, ok(bt_value_is_array(object), "test_map_foreach_cb_check(): success getting \"array2\" value object"); ok(bt_value_array_is_empty(object), "test_map_foreach_cb_check(): \"array2\" value object is empty"); - checklist->array2 = true; + checklist->array2 = BT_TRUE; } } else if (!strcmp(key, "map2")) { if (checklist->map2) { @@ -636,13 +639,13 @@ bool test_map_foreach_cb_check(const char *key, struct bt_value *object, ok(bt_value_is_map(object), "test_map_foreach_cb_check(): success getting \"map2\" value object"); ok(bt_value_map_is_empty(object), "test_map_foreach_cb_check(): \"map2\" value object is empty"); - checklist->map2 = true; + checklist->map2 = BT_TRUE; } } else { fail("test_map_foreach_cb_check(): unknown map key \"%s\"", key); } - return true; + return BT_TRUE; } static @@ -650,7 +653,7 @@ void test_map(void) { int ret; int count = 0; - bool bool_value; + bt_bool bool_value; int64_t int_value; double float_value; struct bt_value *obj; @@ -682,21 +685,21 @@ void test_map(void) ret |= bt_value_map_insert(map_obj, "float", obj); BT_PUT(obj); obj = bt_value_bool_create(); - ret |= bt_value_map_insert(map_obj, "bool", obj); + ret |= bt_value_map_insert(map_obj, "bt_bool", obj); BT_PUT(obj); ret |= bt_value_map_insert(map_obj, "null", bt_value_null); ok(!ret, "bt_value_map_insert() succeeds"); ok(bt_value_map_size(map_obj) == 4, "inserting an element into a map value object increment its size"); - obj = bt_value_bool_create_init(true); - ret = bt_value_map_insert(map_obj, "bool", obj); + obj = bt_value_bool_create_init(BT_TRUE); + ret = bt_value_map_insert(map_obj, "bt_bool", obj); BT_PUT(obj); ok(!ret, "bt_value_map_insert() accepts an existing key"); obj = bt_value_map_get(map_obj, NULL); ok(!obj, "bt_value_map_get() fails with a key set to NULL"); - obj = bt_value_map_get(NULL, "bool"); + obj = bt_value_map_get(NULL, "bt_bool"); ok(!obj, "bt_value_map_get() fails with a map value object set to NULL"); obj = bt_value_map_get(map_obj, "life"); @@ -718,7 +721,7 @@ void test_map(void) obj = bt_value_map_get(map_obj, "null"); ok(obj && bt_value_is_null(obj), "bt_value_map_get() returns an value object with the appropriate type (null)"); - obj = bt_value_map_get(map_obj, "bool"); + obj = bt_value_map_get(map_obj, "bt_bool"); ok(obj && bt_value_is_bool(obj), "bt_value_map_get() returns an value object with the appropriate type (boolean)"); ret = bt_value_bool_get(obj, &bool_value); @@ -726,9 +729,9 @@ void test_map(void) "bt_value_map_get() returns an value object with the appropriate value (boolean)"); BT_PUT(obj); - ret = bt_value_map_insert_bool(map_obj, "bool2", true); + ret = bt_value_map_insert_bool(map_obj, "bool2", BT_TRUE); ok(!ret, "bt_value_map_insert_bool() succeeds"); - ok(bt_value_map_insert_bool(NULL, "bool2", false) == + ok(bt_value_map_insert_bool(NULL, "bool2", BT_FALSE) == BT_VALUE_STATUS_INVAL, "bt_value_map_insert_bool() fails with a map value object set to NULL"); ret = bt_value_map_insert_integer(map_obj, "int2", 98765); @@ -746,22 +749,22 @@ void test_map(void) ok(bt_value_map_insert_string(NULL, "string2", "bt_obj") == BT_VALUE_STATUS_INVAL, "bt_value_map_insert_string() fails with a map value object set to NULL"); - ret = bt_value_map_insert_array(map_obj, "array2"); - ok(!ret, "bt_value_map_insert_array() succeeds"); - ok(bt_value_map_insert_array(NULL, "array2") == BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_array() fails with a map value object set to NULL"); - ret = bt_value_map_insert_map(map_obj, "map2"); - ok(!ret, "bt_value_map_insert_map() succeeds"); - ok(bt_value_map_insert_map(NULL, "map2") == BT_VALUE_STATUS_INVAL, - "bt_value_map_insert_map() fails with a map value object set to NULL"); + ret = bt_value_map_insert_empty_array(map_obj, "array2"); + ok(!ret, "bt_value_map_insert_empty_array() succeeds"); + ok(bt_value_map_insert_empty_array(NULL, "array2") == BT_VALUE_STATUS_INVAL, + "bt_value_map_insert_empty_array() fails with a map value object set to NULL"); + ret = bt_value_map_insert_empty_map(map_obj, "map2"); + ok(!ret, "bt_value_map_insert_empty_map() succeeds"); + ok(bt_value_map_insert_empty_map(NULL, "map2") == BT_VALUE_STATUS_INVAL, + "bt_value_map_insert_empty_map() fails with a map value object set to NULL"); ok(bt_value_map_size(map_obj) == 10, "the bt_value_map_insert*() functions increment the map value object's size"); ok(!bt_value_map_has_key(map_obj, "hello"), "map value object does not have key \"hello\""); - ok(bt_value_map_has_key(map_obj, "bool"), - "map value object has key \"bool\""); + ok(bt_value_map_has_key(map_obj, "bt_bool"), + "map value object has key \"bt_bool\""); ok(bt_value_map_has_key(map_obj, "int"), "map value object has key \"int\""); ok(bt_value_map_has_key(map_obj, "float"), @@ -789,7 +792,7 @@ void test_map(void) "bt_value_map_foreach() fails with a user function set to NULL"); ret = bt_value_map_foreach(map_obj, test_map_foreach_cb_count, &count); ok(ret == BT_VALUE_STATUS_CANCELLED && count == 3, - "bt_value_map_foreach() breaks the loop when the user function returns false"); + "bt_value_map_foreach() breaks the loop when the user function returns BT_FALSE"); memset(&checklist, 0, sizeof(checklist)); ret = bt_value_map_foreach(map_obj, test_map_foreach_cb_check, @@ -806,7 +809,7 @@ void test_map(void) ok(bt_value_map_insert(map_obj, "allo", bt_value_null) == BT_VALUE_STATUS_FROZEN, "bt_value_map_insert() fails with a frozen map value object"); - ok(bt_value_map_insert_bool(map_obj, "duh", false) == + ok(bt_value_map_insert_bool(map_obj, "duh", BT_FALSE) == BT_VALUE_STATUS_FROZEN, "bt_value_map_insert_bool() fails with a frozen array value object"); ok(bt_value_map_insert_integer(map_obj, "duh", 23) == @@ -818,12 +821,12 @@ void test_map(void) ok(bt_value_map_insert_string(map_obj, "duh", "yayayayaya") == BT_VALUE_STATUS_FROZEN, "bt_value_map_insert_string() fails with a frozen array value object"); - ok(bt_value_map_insert_array(map_obj, "duh") == + ok(bt_value_map_insert_empty_array(map_obj, "duh") == BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_array() fails with a frozen array value object"); - ok(bt_value_map_insert_map(map_obj, "duh") == + "bt_value_map_insert_empty_array() fails with a frozen array value object"); + ok(bt_value_map_insert_empty_map(map_obj, "duh") == BT_VALUE_STATUS_FROZEN, - "bt_value_map_insert_map() fails with a frozen array value object"); + "bt_value_map_insert_empty_map() fails with a frozen array value object"); ok(bt_value_map_size(map_obj) == 10, "appending to a frozen map value object does not change its size"); @@ -857,17 +860,17 @@ void test_compare_null(void) static void test_compare_bool(void) { - struct bt_value *bool1 = bt_value_bool_create_init(false); - struct bt_value *bool2 = bt_value_bool_create_init(true); - struct bt_value *bool3 = bt_value_bool_create_init(false); + struct bt_value *bool1 = bt_value_bool_create_init(BT_FALSE); + struct bt_value *bool2 = bt_value_bool_create_init(BT_TRUE); + struct bt_value *bool3 = bt_value_bool_create_init(BT_FALSE); assert(bool1 && bool2 && bool3); ok(!bt_value_compare(bt_value_null, bool1), - "cannot compare null value object and bool value object"); + "cannot compare null value object and bt_bool value object"); ok(!bt_value_compare(bool1, bool2), - "integer value objects are not equivalent (false and true)"); + "boolean value objects are not equivalent (BT_FALSE and BT_TRUE)"); ok(bt_value_compare(bool1, bool3), - "integer value objects are equivalent (false and false)"); + "boolean value objects are equivalent (BT_FALSE and BT_FALSE)"); BT_PUT(bool1); BT_PUT(bool2); @@ -950,13 +953,13 @@ void test_compare_array(void) assert(!bt_value_array_append_integer(array1, 23)); assert(!bt_value_array_append_float(array1, 14.2)); - assert(!bt_value_array_append_bool(array1, false)); + assert(!bt_value_array_append_bool(array1, BT_FALSE)); assert(!bt_value_array_append_float(array2, 14.2)); assert(!bt_value_array_append_integer(array2, 23)); - assert(!bt_value_array_append_bool(array2, false)); + assert(!bt_value_array_append_bool(array2, BT_FALSE)); assert(!bt_value_array_append_integer(array3, 23)); assert(!bt_value_array_append_float(array3, 14.2)); - assert(!bt_value_array_append_bool(array3, false)); + assert(!bt_value_array_append_bool(array3, BT_FALSE)); assert(bt_value_array_size(array1) == 3); assert(bt_value_array_size(array2) == 3); assert(bt_value_array_size(array3) == 3); @@ -964,9 +967,9 @@ void test_compare_array(void) ok(!bt_value_compare(bt_value_null, array1), "cannot compare null value object and array value object"); ok(!bt_value_compare(array1, array2), - "array value objects are not equivalent ([23, 14.2, false] and [14.2, 23, false])"); + "array value objects are not equivalent ([23, 14.2, BT_FALSE] and [14.2, 23, BT_FALSE])"); ok(bt_value_compare(array1, array3), - "array value objects are equivalent ([23, 14.2, false] and [23, 14.2, false])"); + "array value objects are equivalent ([23, 14.2, BT_FALSE] and [23, 14.2, BT_FALSE])"); BT_PUT(array1); BT_PUT(array2); @@ -987,11 +990,11 @@ void test_compare_map(void) assert(!bt_value_map_insert_integer(map1, "one", 23)); assert(!bt_value_map_insert_float(map1, "two", 14.2)); - assert(!bt_value_map_insert_bool(map1, "three", false)); + assert(!bt_value_map_insert_bool(map1, "three", BT_FALSE)); assert(!bt_value_map_insert_float(map2, "one", 14.2)); assert(!bt_value_map_insert_integer(map2, "two", 23)); - assert(!bt_value_map_insert_bool(map2, "three", false)); - assert(!bt_value_map_insert_bool(map3, "three", false)); + assert(!bt_value_map_insert_bool(map2, "three", BT_FALSE)); + assert(!bt_value_map_insert_bool(map3, "three", BT_FALSE)); assert(!bt_value_map_insert_integer(map3, "one", 23)); assert(!bt_value_map_insert_float(map3, "two", 14.2)); assert(bt_value_map_size(map1) == 3); @@ -1029,7 +1032,7 @@ void test_copy(void) /* * Here's the deal here. If we make sure that each value object * of our deep copy has a different address than its source, - * and that bt_value_compare() returns true for the top-level + * and that bt_value_compare() returns BT_TRUE for the top-level * value object, taking into account that we test the correctness of * bt_value_compare() elsewhere, then the deep copy is a * success. @@ -1042,7 +1045,7 @@ void test_copy(void) struct bt_value *array_obj, *array_copy_obj; struct bt_value *map_obj, *map_copy_obj; - bool_obj = bt_value_bool_create_init(true); + bool_obj = bt_value_bool_create_init(BT_TRUE); integer_obj = bt_value_integer_create_init(23); float_obj = bt_value_float_create_init(-3.1416); string_obj = bt_value_string_create_init("test"); @@ -1077,7 +1080,7 @@ void test_copy(void) "bt_value_copy() returns a different pointer (array)"); bool_copy_obj = bt_value_array_get(array_copy_obj, 0); ok(bool_copy_obj != bool_obj, - "bt_value_copy() returns a different pointer (bool)"); + "bt_value_copy() returns a different pointer (bt_bool)"); integer_copy_obj = bt_value_array_get(array_copy_obj, 1); ok(integer_copy_obj != integer_obj, "bt_value_copy() returns a different pointer (integer)"); @@ -1105,12 +1108,87 @@ void test_copy(void) BT_PUT(map_obj); } +static +bt_bool compare_map_elements(struct bt_value *map_a, struct bt_value *map_b, + const char *key) +{ + struct bt_value *elem_a = NULL; + struct bt_value *elem_b = NULL; + bt_bool equal; + + elem_a = bt_value_map_get(map_a, key); + elem_b = bt_value_map_get(map_b, key); + equal = bt_value_compare(elem_a, elem_b); + BT_PUT(elem_a); + BT_PUT(elem_b); + + return equal; +} + +static +void test_extend(void) +{ + struct bt_value *base_map = bt_value_map_create(); + struct bt_value *extension_map = bt_value_map_create(); + struct bt_value *extended_map = NULL; + struct bt_value *array = bt_value_array_create(); + enum bt_value_status status; + + assert(base_map); + assert(extension_map); + assert(array); + status = bt_value_map_insert_bool(base_map, "file", BT_TRUE); + assert(status == BT_VALUE_STATUS_OK); + status = bt_value_map_insert_bool(base_map, "edit", BT_FALSE); + assert(status == BT_VALUE_STATUS_OK); + status = bt_value_map_insert_integer(base_map, "selection", 17); + assert(status == BT_VALUE_STATUS_OK); + status = bt_value_map_insert_integer(base_map, "find", -34); + assert(status == BT_VALUE_STATUS_OK); + status = bt_value_map_insert_bool(extension_map, "edit", BT_TRUE); + assert(status == BT_VALUE_STATUS_OK); + status = bt_value_map_insert_integer(extension_map, "find", 101); + assert(status == BT_VALUE_STATUS_OK); + status = bt_value_map_insert_float(extension_map, "project", -404); + assert(status == BT_VALUE_STATUS_OK); + bt_value_freeze(base_map); + bt_value_freeze(extension_map); + bt_value_freeze(array); + ok(!bt_value_map_extend(NULL, extension_map), + "bt_value_map_extend() fails with a NULL base object"); + ok(!bt_value_map_extend(base_map, NULL), + "bt_value_map_extend() fails with a NULL extension object"); + ok(!bt_value_map_extend(array, extension_map), + "bt_value_map_extend() fails with a non-map base object"); + ok(!bt_value_map_extend(base_map, array), + "bt_value_map_extend() fails with a non-map extension object"); + extended_map = bt_value_map_extend(base_map, extension_map); + ok(extended_map, "bt_value_map_extend() succeeds"); + ok(bt_value_map_size(extended_map) == 5, + "bt_value_map_extend() returns a map object with the correct size"); + ok(compare_map_elements(base_map, extended_map, "file"), + "bt_value_map_extend() picks the appropriate element (file)"); + ok(compare_map_elements(extension_map, extended_map, "edit"), + "bt_value_map_extend() picks the appropriate element (edit)"); + ok(compare_map_elements(base_map, extended_map, "selection"), + "bt_value_map_extend() picks the appropriate element (selection)"); + ok(compare_map_elements(extension_map, extended_map, "find"), + "bt_value_map_extend() picks the appropriate element (find)"); + ok(compare_map_elements(extension_map, extended_map, "project"), + "bt_value_map_extend() picks the appropriate element (project)"); + + BT_PUT(array); + BT_PUT(base_map); + BT_PUT(extension_map); + BT_PUT(extended_map); +} + static void test_macros(void) { struct bt_value *obj = bt_value_bool_create(); struct bt_value *src; - struct bt_value *dst; + struct bt_value *dst = NULL; assert(obj); BT_PUT(obj); @@ -1142,25 +1220,26 @@ void test_freeze(void) obj = bt_value_integer_create(); assert(obj); ok(!bt_value_is_frozen(obj), - "bt_value_is_frozen() returns false with a fresh value object"); + "bt_value_is_frozen() returns BT_FALSE with a fresh value object"); assert(!bt_value_freeze(obj)); ok(!bt_value_freeze(obj), "bt_value_freeze() passes with a frozen value object"); ok(bt_value_is_frozen(obj), - "bt_value_is_frozen() returns true with a frozen value object"); + "bt_value_is_frozen() returns BT_TRUE with a frozen value object"); BT_PUT(obj); } int main(void) { - plan_no_plan(); + plan_tests(NR_TESTS); test_macros(); test_freeze(); test_types(); test_compare(); test_copy(); + test_extend(); return 0; }