diff --git a/lib/common/tests/io/pcmk__full_path_test.c b/lib/common/tests/io/pcmk__full_path_test.c index 2f514aa59b..da6b3f177e 100644 --- a/lib/common/tests/io/pcmk__full_path_test.c +++ b/lib/common/tests/io/pcmk__full_path_test.c @@ -1,58 +1,58 @@ /* - * Copyright 2020-2024 the Pacemaker project contributors + * Copyright 2020-2025 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 #include #include "mock_private.h" static void function_asserts(void **state) { pcmk__assert_asserts(pcmk__full_path(NULL, "/dir")); pcmk__assert_asserts(pcmk__full_path("file", NULL)); } static void function_exits(void **state) { pcmk__assert_exits( CRM_EX_OSERR, { pcmk__mock_strdup = true; // strdup() will return NULL expect_string(__wrap_strdup, s, "/full/path"); pcmk__full_path("/full/path", "/dir"); pcmk__mock_strdup = false; // Use real strdup() } ); } static void full_path(void **state) { char *path = NULL; path = pcmk__full_path("file", "/dir"); - assert_int_equal(strcmp(path, "/dir/file"), 0); + assert_string_equal(path, "/dir/file"); free(path); path = pcmk__full_path("/full/path", "/dir"); - assert_int_equal(strcmp(path, "/full/path"), 0); + assert_string_equal(path, "/full/path"); free(path); path = pcmk__full_path("../relative/path", "/dir"); - assert_int_equal(strcmp(path, "/dir/../relative/path"), 0); + assert_string_equal(path, "/dir/../relative/path"); free(path); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(function_asserts), cmocka_unit_test(function_exits), cmocka_unit_test(full_path)) diff --git a/lib/common/tests/rules/pcmk__replace_submatches_test.c b/lib/common/tests/rules/pcmk__replace_submatches_test.c index d404fcc855..f2a48f7b68 100644 --- a/lib/common/tests/rules/pcmk__replace_submatches_test.c +++ b/lib/common/tests/rules/pcmk__replace_submatches_test.c @@ -1,81 +1,81 @@ /* - * Copyright 2024 the Pacemaker project contributors + * Copyright 2024-2025 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 #include // regmatch_t #include #include // An example matched string with submatches static const char *match = "this is a string"; static const regmatch_t submatches[] = { { .rm_so = 0, .rm_eo = 16 }, // %0 = entire string { .rm_so = 5, .rm_eo = 7 }, // %1 = "is" { .rm_so = 9, .rm_eo = 9 }, // %2 = empty match }; static const int nmatches = 3; static void assert_submatch(const char *string, const char *reference) { char *expanded = NULL; expanded = pcmk__replace_submatches(string, match, submatches, nmatches); if ((expanded == NULL) || (reference == NULL)) { assert_null(expanded); assert_null(reference); } else { - assert_int_equal(strcmp(expanded, reference), 0); + assert_string_equal(expanded, reference); } free(expanded); } static void no_source(void **state) { assert_null(pcmk__replace_submatches(NULL, NULL, NULL, 0)); assert_submatch(NULL, NULL); assert_submatch("", NULL); } static void source_has_no_variables(void **state) { assert_null(pcmk__replace_submatches("this has no submatch variables", match, submatches, nmatches)); assert_null(pcmk__replace_submatches("this ends in a %", match, submatches, nmatches)); assert_null(pcmk__replace_submatches("%this starts with one", match, submatches, nmatches)); } static void without_matches(void **state) { assert_submatch("this has an empty submatch %2", "this has an empty submatch "); assert_submatch("this has a nonexistent submatch %3", "this has a nonexistent submatch "); } static void with_matches(void **state) { assert_submatch("%0", match); // %0 matches entire string assert_submatch("this %1", "this is"); assert_submatch("%1 this %ok", "is this %ok"); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(no_source), cmocka_unit_test(source_has_no_variables), cmocka_unit_test(without_matches), cmocka_unit_test(with_matches)) diff --git a/lib/common/tests/strings/pcmk__add_word_test.c b/lib/common/tests/strings/pcmk__add_word_test.c index 2e7ad513d7..a3deceb43d 100644 --- a/lib/common/tests/strings/pcmk__add_word_test.c +++ b/lib/common/tests/strings/pcmk__add_word_test.c @@ -1,89 +1,87 @@ /* * Copyright 2020-2025 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 #include static void add_words(void **state) { GString *list = NULL; pcmk__add_word(&list, 16, "hello"); pcmk__add_word(&list, 16, "world"); - assert_int_equal(strcmp((const char *) list->str, "hello world"), 0); + assert_string_equal(list->str, "hello world"); g_string_free(list, TRUE); } static void add_with_no_len(void **state) { GString *list = NULL; pcmk__add_word(&list, 0, "hello"); pcmk__add_word(&list, 0, "world"); - assert_int_equal(strcmp((const char *) list->str, "hello world"), 0); + assert_string_equal(list->str, "hello world"); g_string_free(list, TRUE); } static void add_nothing(void **state) { GString *list = NULL; pcmk__add_word(&list, 0, "hello"); pcmk__add_word(&list, 0, NULL); pcmk__add_word(&list, 0, ""); - assert_int_equal(strcmp((const char *) list->str, "hello"), 0); + assert_string_equal(list->str, "hello"); g_string_free(list, TRUE); } static void null_separator_asserts(void **state) { GString *list = NULL; pcmk__assert_asserts(pcmk__add_separated_word(&list, 32, "hello", NULL)); assert_null(list); } static void add_with_comma(void **state) { GString *list = NULL; pcmk__add_separated_word(&list, 32, "hello", ","); pcmk__add_separated_word(&list, 32, "world", ","); pcmk__add_separated_word(&list, 32, "I am a unit test", ","); - assert_int_equal(strcmp((const char *) list->str, - "hello,world,I am a unit test"), 0); + assert_string_equal(list->str, "hello,world,I am a unit test"); g_string_free(list, TRUE); } static void add_with_comma_and_space(void **state) { GString *list = NULL; pcmk__add_separated_word(&list, 32, "hello", ", "); pcmk__add_separated_word(&list, 32, "world", ", "); pcmk__add_separated_word(&list, 32, "I am a unit test", ", "); - assert_int_equal(strcmp((const char *) list->str, - "hello, world, I am a unit test"), 0); + assert_string_equal(list->str, "hello, world, I am a unit test"); g_string_free(list, TRUE); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(add_words), cmocka_unit_test(add_with_no_len), cmocka_unit_test(add_nothing), cmocka_unit_test(null_separator_asserts), cmocka_unit_test(add_with_comma), cmocka_unit_test(add_with_comma_and_space)) diff --git a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c index 86500c22f5..35c0c1a073 100644 --- a/lib/common/tests/xpath/pcmk__xpath_node_id_test.c +++ b/lib/common/tests/xpath/pcmk__xpath_node_id_test.c @@ -1,60 +1,60 @@ /* - * Copyright 2021-2024 the Pacemaker project contributors + * Copyright 2021-2025 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 #include #include #include static void empty_input(void **state) { assert_null(pcmk__xpath_node_id(NULL, PCMK__XE_LRM)); assert_null(pcmk__xpath_node_id("", PCMK__XE_LRM)); assert_null(pcmk__xpath_node_id("/blah/blah", NULL)); assert_null(pcmk__xpath_node_id("/blah/blah", "")); assert_null(pcmk__xpath_node_id(NULL, NULL)); } static void no_quotes(void **state) { const char *xpath = "/some/xpath/" PCMK__XE_LRM "[@" PCMK_XA_ID "=xyz]"; pcmk__assert_asserts(pcmk__xpath_node_id(xpath, PCMK__XE_LRM)); } static void not_present(void **state) { const char *xpath = "/some/xpath/string[@" PCMK_XA_ID "='xyz']"; assert_null(pcmk__xpath_node_id(xpath, PCMK__XE_LRM)); xpath = "/some/xpath/containing[@" PCMK_XA_ID "='" PCMK__XE_LRM "']"; assert_null(pcmk__xpath_node_id(xpath, PCMK__XE_LRM)); } static void present(void **state) { char *s = NULL; const char *xpath = "/some/xpath/containing" "/" PCMK__XE_LRM "[@" PCMK_XA_ID "='xyz']"; s = pcmk__xpath_node_id(xpath, PCMK__XE_LRM); - assert_int_equal(strcmp(s, "xyz"), 0); + assert_string_equal(s, "xyz"); free(s); xpath = "/some/other/" PCMK__XE_LRM "[@" PCMK_XA_ID "='xyz']/xpath"; s = pcmk__xpath_node_id(xpath, PCMK__XE_LRM); - assert_int_equal(strcmp(s, "xyz"), 0); + assert_string_equal(s, "xyz"); free(s); } PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(empty_input), cmocka_unit_test(no_quotes), cmocka_unit_test(not_present), cmocka_unit_test(present))