summaryrefslogtreecommitdiffstats
path: root/lib/common/tests/strings
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:45:52 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:45:52 +0000
commitcbe4cdc48486fbedede448aa59aa6a367efa1038 (patch)
tree6fc30a23fe7642fd93c5c6c702c4bc8ed5640b38 /lib/common/tests/strings
parentAdding debian version 2.1.6-5. (diff)
downloadpacemaker-cbe4cdc48486fbedede448aa59aa6a367efa1038.tar.xz
pacemaker-cbe4cdc48486fbedede448aa59aa6a367efa1038.zip
Merging upstream version 2.1.7.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/common/tests/strings')
-rw-r--r--lib/common/tests/strings/Makefile.am54
-rw-r--r--lib/common/tests/strings/pcmk__compress_test.c2
-rw-r--r--lib/common/tests/strings/pcmk__guint_from_hash_test.c4
-rw-r--r--lib/common/tests/strings/pcmk__scan_ll_test.c64
4 files changed, 96 insertions, 28 deletions
diff --git a/lib/common/tests/strings/Makefile.am b/lib/common/tests/strings/Makefile.am
index 9abb8e9..e66af0d 100644
--- a/lib/common/tests/strings/Makefile.am
+++ b/lib/common/tests/strings/Makefile.am
@@ -1,5 +1,5 @@
#
-# Copyright 2020-2022 the Pacemaker project contributors
+# Copyright 2020-2023 the Pacemaker project contributors
#
# The version control history for this file may have further details.
#
@@ -11,31 +11,31 @@ include $(top_srcdir)/mk/tap.mk
include $(top_srcdir)/mk/unittest.mk
# Add "_test" to the end of all test program names to simplify .gitignore.
-check_PROGRAMS = \
- crm_get_msec_test \
- crm_is_true_test \
- crm_str_to_boolean_test \
- pcmk__add_word_test \
- pcmk__btoa_test \
- pcmk__char_in_any_str_test \
- pcmk__compress_test \
- pcmk__ends_with_test \
- pcmk__g_strcat_test \
- pcmk__guint_from_hash_test \
- pcmk__numeric_strcasecmp_test \
- pcmk__parse_ll_range_test \
- pcmk__s_test \
- pcmk__scan_double_test \
- pcmk__scan_min_int_test \
- pcmk__scan_port_test \
- pcmk__starts_with_test \
- pcmk__str_any_of_test \
- pcmk__str_in_list_test \
- pcmk__str_table_dup_test \
- pcmk__str_update_test \
- pcmk__strcmp_test \
- pcmk__strkey_table_test \
- pcmk__strikey_table_test \
- pcmk__trim_test
+check_PROGRAMS = crm_get_msec_test \
+ crm_is_true_test \
+ crm_str_to_boolean_test \
+ pcmk__add_word_test \
+ pcmk__btoa_test \
+ pcmk__char_in_any_str_test \
+ pcmk__compress_test \
+ pcmk__ends_with_test \
+ pcmk__g_strcat_test \
+ pcmk__guint_from_hash_test \
+ pcmk__numeric_strcasecmp_test \
+ pcmk__parse_ll_range_test \
+ pcmk__s_test \
+ pcmk__scan_double_test \
+ pcmk__scan_ll_test \
+ pcmk__scan_min_int_test \
+ pcmk__scan_port_test \
+ pcmk__starts_with_test \
+ pcmk__str_any_of_test \
+ pcmk__str_in_list_test \
+ pcmk__str_table_dup_test \
+ pcmk__str_update_test \
+ pcmk__strcmp_test \
+ pcmk__strkey_table_test \
+ pcmk__strikey_table_test \
+ pcmk__trim_test
TESTS = $(check_PROGRAMS)
diff --git a/lib/common/tests/strings/pcmk__compress_test.c b/lib/common/tests/strings/pcmk__compress_test.c
index 7480937..7b59d9d 100644
--- a/lib/common/tests/strings/pcmk__compress_test.c
+++ b/lib/common/tests/strings/pcmk__compress_test.c
@@ -33,7 +33,7 @@ max_too_small(void **state)
char *result = calloc(1024, sizeof(char));
unsigned int len;
- assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 10, &result, &len), pcmk_rc_error);
+ assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 10, &result, &len), EFBIG);
}
static void
diff --git a/lib/common/tests/strings/pcmk__guint_from_hash_test.c b/lib/common/tests/strings/pcmk__guint_from_hash_test.c
index e2b4762..225c5b3 100644
--- a/lib/common/tests/strings/pcmk__guint_from_hash_test.c
+++ b/lib/common/tests/strings/pcmk__guint_from_hash_test.c
@@ -59,6 +59,7 @@ conversion_errors(void **state)
g_hash_table_insert(tbl, strdup("negative"), strdup("-3"));
g_hash_table_insert(tbl, strdup("toobig"), strdup("20000000000000000"));
+ g_hash_table_insert(tbl, strdup("baddata"), strdup("asdf"));
assert_int_equal(pcmk__guint_from_hash(tbl, "negative", 456, &result), ERANGE);
assert_int_equal(result, 456);
@@ -66,6 +67,9 @@ conversion_errors(void **state)
assert_int_equal(pcmk__guint_from_hash(tbl, "toobig", 456, &result), ERANGE);
assert_int_equal(result, 456);
+ assert_int_equal(pcmk__guint_from_hash(tbl, "baddata", 456, &result), EINVAL);
+ assert_int_equal(result, 456);
+
g_hash_table_destroy(tbl);
}
diff --git a/lib/common/tests/strings/pcmk__scan_ll_test.c b/lib/common/tests/strings/pcmk__scan_ll_test.c
new file mode 100644
index 0000000..645ecb4
--- /dev/null
+++ b/lib/common/tests/strings/pcmk__scan_ll_test.c
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2023 the Pacemaker project contributors
+ *
+ * The version control history for this file may have further details.
+ *
+ * This source code is licensed under the GNU General Public License version 2
+ * or later (GPLv2+) WITHOUT ANY WARRANTY.
+ */
+
+#include <crm_internal.h>
+
+#include <crm/common/unittest_internal.h>
+
+static void
+empty_input_string(void **state)
+{
+ long long result;
+
+ assert_int_equal(pcmk__scan_ll(NULL, &result, 47), pcmk_rc_ok);
+ assert_int_equal(result, 47);
+}
+
+static void
+bad_input_string(void **state)
+{
+ long long result;
+
+ assert_int_equal(pcmk__scan_ll("asdf", &result, 47), EINVAL);
+ assert_int_equal(result, 47);
+ assert_int_equal(pcmk__scan_ll("as12", &result, 47), EINVAL);
+ assert_int_equal(result, 47);
+}
+
+static void
+trailing_chars(void **state)
+{
+ long long result;
+
+ assert_int_equal(pcmk__scan_ll("12as", &result, 47), pcmk_rc_ok);
+ assert_int_equal(result, 12);
+}
+
+static void
+no_result_variable(void **state)
+{
+ assert_int_equal(pcmk__scan_ll("1234", NULL, 47), pcmk_rc_ok);
+ assert_int_equal(pcmk__scan_ll("asdf", NULL, 47), EINVAL);
+}
+
+static void
+typical_case(void **state)
+{
+ long long result;
+
+ assert_int_equal(pcmk__scan_ll("1234", &result, 47), pcmk_rc_ok);
+ assert_int_equal(result, 1234);
+}
+
+PCMK__UNIT_TEST(NULL, NULL,
+ cmocka_unit_test(empty_input_string),
+ cmocka_unit_test(bad_input_string),
+ cmocka_unit_test(trailing_chars),
+ cmocka_unit_test(no_result_variable),
+ cmocka_unit_test(typical_case))