Move to kernel style SPDX license identifiers
[babeltrace.git] / tests / lib / test_bt_values.c
index 1dbb9b8d8c60b93cf977c90199522ee580ee57d0..0a7aeb1ccb6b5330a37b91d5cef6c6e14980406e 100644 (file)
@@ -1,23 +1,10 @@
 /*
- * test_bt_values.c
+ * SPDX-License-Identifier: GPL-2.0-only
  *
- * Babeltrace value objects tests
- *
- * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
- * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; under version 2 of the License.
+ * Copyright (C) 2015 EfficiOS Inc. and Linux Foundation
+ * Copyright (C) 2015 Philippe Proulx <pproulx@efficios.com>
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Babeltrace value objects tests
  */
 
 #include <babeltrace2/babeltrace.h>
@@ -25,7 +12,7 @@
 #include <string.h>
 #include "tap/tap.h"
 
-#define NR_TESTS 188
+#define NR_TESTS 190
 
 static
 void test_null(void)
@@ -235,31 +222,31 @@ void test_array(void)
                "appending an element to an array value object increment its size");
 
        obj = bt_value_array_borrow_element_by_index(array_obj, 0);
-       ok(obj && bt_value_is_unsigned_integer(obj),
+       ok(bt_value_is_unsigned_integer(obj),
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (unsigned integer)");
        int_value = bt_value_integer_unsigned_get(obj);
        ok(int_value == 345,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (unsigned integer)");
        obj = bt_value_array_borrow_element_by_index(array_obj, 1);
-       ok(obj && bt_value_is_signed_integer(obj),
+       ok(bt_value_is_signed_integer(obj),
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (signed integer)");
        int_value = bt_value_integer_signed_get(obj);
        ok(int_value == -507,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (signed integer)");
        obj = bt_value_array_borrow_element_by_index(array_obj, 2);
-       ok(obj && bt_value_is_real(obj),
+       ok(bt_value_is_real(obj),
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
        real_value = bt_value_real_get(obj);
        ok(real_value == -17.45,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)");
        obj = bt_value_array_borrow_element_by_index(array_obj, 3);
-       ok(obj && bt_value_is_bool(obj),
+       ok(bt_value_is_bool(obj),
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
        bool_value = bt_value_bool_get(obj);
        ok(bool_value,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)");
        obj = bt_value_array_borrow_element_by_index(array_obj, 4);
-       ok(obj == bt_value_null,
+       ok(bt_value_null,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
 
        obj = bt_value_integer_signed_create_init(1001);
@@ -268,7 +255,7 @@ void test_array(void)
                "bt_value_array_set_element_by_index() succeeds");
        BT_VALUE_PUT_REF_AND_RESET(obj);
        obj = bt_value_array_borrow_element_by_index(array_obj, 2);
-       ok(obj && bt_value_is_signed_integer(obj),
+       ok(bt_value_is_signed_integer(obj),
                "bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
        int_value = bt_value_integer_signed_get(obj);
        BT_ASSERT(!ret);
@@ -313,52 +300,52 @@ void test_array(void)
                "map value object is not empty");
 
        obj = bt_value_array_borrow_element_by_index(array_obj, 5);
-       ok(obj && bt_value_is_bool(obj),
+       ok(bt_value_is_bool(obj),
                "bt_value_array_append_bool_element() appends a boolean value object");
        bool_value = bt_value_bool_get(obj);
        ok(!bool_value,
                "bt_value_array_append_bool_element() appends the appropriate value");
        obj = bt_value_array_borrow_element_by_index(array_obj, 6);
-       ok(obj && bt_value_is_unsigned_integer(obj),
+       ok(bt_value_is_unsigned_integer(obj),
                "bt_value_array_append_unsigned_integer_element() appends an unsigned integer value object");
        int_value = bt_value_integer_unsigned_get(obj);
        ok(int_value == 98765,
                "bt_value_array_append_unsigned_integer_element() appends the appropriate value");
        obj = bt_value_array_borrow_element_by_index(array_obj, 7);
-       ok(obj && bt_value_is_signed_integer(obj),
+       ok(bt_value_is_signed_integer(obj),
                "bt_value_array_append_signed_integer_element() appends a signed integer value object");
        int_value = bt_value_integer_signed_get(obj);
        ok(int_value == -10101,
                "bt_value_array_append_signed_integer_element() appends the appropriate value");
        obj = bt_value_array_borrow_element_by_index(array_obj, 8);
-       ok(obj && bt_value_is_real(obj),
+       ok(bt_value_is_real(obj),
                "bt_value_array_append_real_element() appends a real number value object");
        real_value = bt_value_real_get(obj);
        ok(real_value == 2.49578,
                "bt_value_array_append_real_element() appends the appropriate value");
        obj = bt_value_array_borrow_element_by_index(array_obj, 9);
-       ok(obj && bt_value_is_string(obj),
+       ok(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") == 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),
+       ok(bt_value_is_array(obj),
                "bt_value_array_append_empty_array_element() appends an array value object");
        ok(bt_value_array_is_empty(obj),
                "bt_value_array_append_empty_array_element() an empty array value object");
        obj = bt_value_array_borrow_element_by_index(array_obj, 11);
-       ok(obj && bt_value_is_array(obj),
+       ok(bt_value_is_array(obj),
                "bt_value_array_append_empty_array_element() appends an array value object");
        ok(bt_value_array_is_empty(obj),
                "bt_value_array_append_empty_array_element() an empty array value object");
        obj = bt_value_array_borrow_element_by_index(array_obj, 12);
-       ok(obj && bt_value_is_map(obj),
+       ok(bt_value_is_map(obj),
                "bt_value_array_append_empty_map_element() appends a map value object");
        ok(bt_value_map_is_empty(obj),
                "bt_value_array_append_empty_map_element() an empty map value object");
        obj = bt_value_array_borrow_element_by_index(array_obj, 13);
-       ok(obj && bt_value_is_map(obj),
+       ok(bt_value_is_map(obj),
                "bt_value_array_append_empty_map_element() appends a map value object");
        ok(bt_value_map_is_empty(obj),
                "bt_value_array_append_empty_map_element() an empty map value object");
@@ -368,18 +355,23 @@ void test_array(void)
 }
 
 static
-bt_bool test_map_foreach_cb_count(const char *key, bt_value *object,
+bt_value_map_foreach_entry_func_status test_map_foreach_cb_count(
+               const char *key, bt_value *object,
        void *data)
 {
        int *count = data;
 
        if (*count == 3) {
-               return BT_FALSE;
+               return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT;
+       } else if (*count == 4) {
+               return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR;
+       } else if (*count == 5) {
+               return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR;
        }
 
        (*count)++;
 
-       return BT_TRUE;
+       return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK;
 }
 
 struct map_foreach_checklist {
@@ -399,8 +391,8 @@ struct map_foreach_checklist {
 };
 
 static
-bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
-       void *data)
+bt_value_map_foreach_entry_func_status test_map_foreach_cb_check(
+               const char *key, bt_value *object, void *data)
 {
        struct map_foreach_checklist *checklist = data;
 
@@ -572,7 +564,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                        key);
        }
 
-       return BT_TRUE;
+       return BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_OK;
 }
 
 static
@@ -711,7 +703,21 @@ void test_map(void)
        ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_count,
                &count);
        ok(ret == BT_VALUE_MAP_FOREACH_ENTRY_STATUS_INTERRUPTED && count == 3,
-               "bt_value_map_foreach_entry() breaks the loop when the user function returns BT_FALSE");
+               "bt_value_map_foreach_entry() breaks the loop when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_INTERRUPT");
+
+       count = 4;
+       ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_count,
+               &count);
+       ok(ret == BT_VALUE_MAP_FOREACH_ENTRY_STATUS_USER_ERROR,
+               "bt_value_map_foreach_entry() fails when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_ERROR");
+       bt_current_thread_clear_error();
+
+       count = 5;
+       ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_count,
+               &count);
+       ok(ret == BT_VALUE_MAP_FOREACH_ENTRY_STATUS_MEMORY_ERROR,
+               "bt_value_map_foreach_entry() fails when the user function returns BT_VALUE_MAP_FOREACH_ENTRY_FUNC_STATUS_MEMORY_ERROR");
+       bt_current_thread_clear_error();
 
        memset(&checklist, 0, sizeof(checklist));
        ret = bt_value_map_foreach_entry(map_obj, test_map_foreach_cb_check,
@@ -794,6 +800,7 @@ void test_is_equal_unsigned_integer(void)
        BT_VALUE_PUT_REF_AND_RESET(int3);
 }
 
+static
 void test_is_equal_signed_integer(void)
 {
        bt_value *int1 =
This page took 0.02602 seconds and 4 git commands to generate.