diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:39:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-03 13:39:28 +0000 |
commit | 7332b914bff2786ff70ccace103fc9ebdfb61a23 (patch) | |
tree | 3a8a60c4edba014c7e350be41839e3edbf2a315f /lib/common/tests/strings | |
parent | Adding debian version 2.1.7-1. (diff) | |
download | pacemaker-7332b914bff2786ff70ccace103fc9ebdfb61a23.tar.xz pacemaker-7332b914bff2786ff70ccace103fc9ebdfb61a23.zip |
Merging upstream version 2.1.8~rc1.
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.am | 3 | ||||
-rw-r--r-- | lib/common/tests/strings/crm_get_msec_test.c | 30 | ||||
-rw-r--r-- | lib/common/tests/strings/crm_str_to_boolean_test.c | 16 | ||||
-rw-r--r-- | lib/common/tests/strings/pcmk__char_in_any_str_test.c | 46 | ||||
-rw-r--r-- | lib/common/tests/strings/pcmk__compress_test.c | 11 | ||||
-rw-r--r-- | lib/common/tests/strings/pcmk__str_update_test.c | 3 |
6 files changed, 53 insertions, 56 deletions
diff --git a/lib/common/tests/strings/Makefile.am b/lib/common/tests/strings/Makefile.am index e66af0d..439b6bf 100644 --- a/lib/common/tests/strings/Makefile.am +++ b/lib/common/tests/strings/Makefile.am @@ -1,5 +1,5 @@ # -# Copyright 2020-2023 the Pacemaker project contributors +# Copyright 2020-2024 the Pacemaker project contributors # # The version control history for this file may have further details. # @@ -16,7 +16,6 @@ check_PROGRAMS = crm_get_msec_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 \ diff --git a/lib/common/tests/strings/crm_get_msec_test.c b/lib/common/tests/strings/crm_get_msec_test.c index 5da548b..14b87cf 100644 --- a/lib/common/tests/strings/crm_get_msec_test.c +++ b/lib/common/tests/strings/crm_get_msec_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2021 the Pacemaker project contributors + * Copyright 2021-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -19,6 +19,11 @@ bad_input(void **state) { assert_int_equal(crm_get_msec("100xs"), PCMK__PARSE_INT_DEFAULT); assert_int_equal(crm_get_msec(" 100 xs "), PCMK__PARSE_INT_DEFAULT); assert_int_equal(crm_get_msec("-100ms"), PCMK__PARSE_INT_DEFAULT); + + assert_int_equal(crm_get_msec("3.xs"), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec(" 3. xs "), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec("3.14xs"), PCMK__PARSE_INT_DEFAULT); + assert_int_equal(crm_get_msec(" 3.14 xs "), PCMK__PARSE_INT_DEFAULT); } static void @@ -28,6 +33,7 @@ good_input(void **state) { assert_int_equal(crm_get_msec("\t100\n"), 100000); assert_int_equal(crm_get_msec("100ms"), 100); + assert_int_equal(crm_get_msec(" 100 ms "), 100); assert_int_equal(crm_get_msec("100 MSEC"), 100); assert_int_equal(crm_get_msec("1000US"), 1); assert_int_equal(crm_get_msec("1000usec"), 1); @@ -37,6 +43,28 @@ good_input(void **state) { assert_int_equal(crm_get_msec("13 min"), 780000); assert_int_equal(crm_get_msec("2\th"), 7200000); assert_int_equal(crm_get_msec("1 hr"), 3600000); + + assert_int_equal(crm_get_msec("3."), 3000); + assert_int_equal(crm_get_msec(" 3. ms "), 3); + assert_int_equal(crm_get_msec("3.14"), 3000); + assert_int_equal(crm_get_msec(" 3.14 ms "), 3); + + // Questionable + assert_int_equal(crm_get_msec("3.14."), 3000); + assert_int_equal(crm_get_msec(" 3.14. ms "), 3); + assert_int_equal(crm_get_msec("3.14.159"), 3000); + assert_int_equal(crm_get_msec(" 3.14.159 "), 3000); + assert_int_equal(crm_get_msec("3.14.159ms"), 3); + assert_int_equal(crm_get_msec(" 3.14.159 ms "), 3); + + // Questionable + assert_int_equal(crm_get_msec(" 100 mshr "), 100); + assert_int_equal(crm_get_msec(" 100 ms hr "), 100); + assert_int_equal(crm_get_msec(" 100 sasdf "), 100000); + assert_int_equal(crm_get_msec(" 100 s asdf "), 100000); + assert_int_equal(crm_get_msec(" 3.14 shour "), 3000); + assert_int_equal(crm_get_msec(" 3.14 s hour "), 3000); + assert_int_equal(crm_get_msec(" 3.14 ms!@#$ "), 3); } static void diff --git a/lib/common/tests/strings/crm_str_to_boolean_test.c b/lib/common/tests/strings/crm_str_to_boolean_test.c index 3bd2e5d..1b0ba45 100644 --- a/lib/common/tests/strings/crm_str_to_boolean_test.c +++ b/lib/common/tests/strings/crm_str_to_boolean_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2021 the Pacemaker project contributors + * Copyright 2021-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -40,6 +40,13 @@ is_true(void **state) { assert_true(ret); assert_int_equal(crm_str_to_boolean("1", &ret), 1); assert_true(ret); + + // Ensure it still validates the string with a NULL result argument + assert_int_equal(crm_str_to_boolean("true", NULL), 1); + assert_int_equal(crm_str_to_boolean("on", NULL), 1); + assert_int_equal(crm_str_to_boolean("yes", NULL), 1); + assert_int_equal(crm_str_to_boolean("y", NULL), 1); + assert_int_equal(crm_str_to_boolean("1", NULL), 1); } static void @@ -73,6 +80,13 @@ is_false(void **state) { assert_false(ret); assert_int_equal(crm_str_to_boolean("0", &ret), 1); assert_false(ret); + + // Ensure it still validates the string with a NULL result argument + assert_int_equal(crm_str_to_boolean("false", NULL), 1); + assert_int_equal(crm_str_to_boolean("off", NULL), 1); + assert_int_equal(crm_str_to_boolean("no", NULL), 1); + assert_int_equal(crm_str_to_boolean("n", NULL), 1); + assert_int_equal(crm_str_to_boolean("0", NULL), 1); } static void diff --git a/lib/common/tests/strings/pcmk__char_in_any_str_test.c b/lib/common/tests/strings/pcmk__char_in_any_str_test.c deleted file mode 100644 index e70dfb4..0000000 --- a/lib/common/tests/strings/pcmk__char_in_any_str_test.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2020-2021 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_list(void **state) -{ - assert_false(pcmk__char_in_any_str('x', NULL)); - assert_false(pcmk__char_in_any_str('\0', NULL)); -} - -static void -null_char(void **state) -{ - assert_true(pcmk__char_in_any_str('\0', "xxx", "yyy", NULL)); - assert_true(pcmk__char_in_any_str('\0', "", NULL)); -} - -static void -in_list(void **state) -{ - assert_true(pcmk__char_in_any_str('x', "aaa", "bbb", "xxx", NULL)); -} - -static void -not_in_list(void **state) -{ - assert_false(pcmk__char_in_any_str('x', "aaa", "bbb", NULL)); - assert_false(pcmk__char_in_any_str('A', "aaa", "bbb", NULL)); - assert_false(pcmk__char_in_any_str('x', "", NULL)); -} - -PCMK__UNIT_TEST(NULL, NULL, - cmocka_unit_test(empty_list), - cmocka_unit_test(null_char), - cmocka_unit_test(in_list), - cmocka_unit_test(not_in_list)) diff --git a/lib/common/tests/strings/pcmk__compress_test.c b/lib/common/tests/strings/pcmk__compress_test.c index 7b59d9d..813bcdb 100644 --- a/lib/common/tests/strings/pcmk__compress_test.c +++ b/lib/common/tests/strings/pcmk__compress_test.c @@ -1,5 +1,5 @@ /* - * Copyright 2022 the Pacemaker project contributors + * Copyright 2022-2024 the Pacemaker project contributors * * The version control history for this file may have further details. * @@ -20,7 +20,7 @@ const char *SIMPLE_COMPRESSED = "BZh41AY&SYO\x1ai"; static void simple_compress(void **state) { - char *result = calloc(1024, sizeof(char)); + char *result = pcmk__assert_alloc(1024, sizeof(char)); unsigned int len; assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 0, &result, &len), pcmk_rc_ok); @@ -30,7 +30,7 @@ simple_compress(void **state) static void max_too_small(void **state) { - char *result = calloc(1024, sizeof(char)); + char *result = pcmk__assert_alloc(1024, sizeof(char)); unsigned int len; assert_int_equal(pcmk__compress(SIMPLE_DATA, 40, 10, &result, &len), EFBIG); @@ -38,10 +38,11 @@ max_too_small(void **state) static void calloc_fails(void **state) { - char *result = calloc(1024, sizeof(char)); + char *result = pcmk__assert_alloc(1024, sizeof(char)); unsigned int len; - pcmk__assert_asserts( + pcmk__assert_exits( + CRM_EX_OSERR, { pcmk__mock_calloc = true; // calloc() will return NULL expect_value(__wrap_calloc, nmemb, (size_t) ((40 * 1.01) + 601)); diff --git a/lib/common/tests/strings/pcmk__str_update_test.c b/lib/common/tests/strings/pcmk__str_update_test.c index 571031d..4a44fba 100644 --- a/lib/common/tests/strings/pcmk__str_update_test.c +++ b/lib/common/tests/strings/pcmk__str_update_test.c @@ -59,7 +59,8 @@ strdup_fails(void **state) { str = strdup("hello"); - pcmk__assert_asserts( + pcmk__assert_exits( + CRM_EX_OSERR, { pcmk__mock_strdup = true; // strdup() will return NULL expect_string(__wrap_strdup, s, "world"); |