diff --git a/lib/common/tests/io/pcmk__get_tmpdir_test.c b/lib/common/tests/io/pcmk__get_tmpdir_test.c index 3843a780c4..7fbad8f47d 100644 --- a/lib/common/tests/io/pcmk__get_tmpdir_test.c +++ b/lib/common/tests/io/pcmk__get_tmpdir_test.c @@ -1,93 +1,93 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include "mock_private.h" #include #include #include #include #include #include #include #include static bool use_mocked = false; char * __wrap_getenv(const char *name) { /* If coverage is enabled, something in "make check" will want to call * the real getenv(), which will of course fail if the mocked version gets * used. This bool needs to be set and unset around every unit test so * the mocked version is only called in that time. */ if (use_mocked) { - return mock_type(char *); + return mock_ptr_type(char *); } else { return __real_getenv(name); } } static void getenv_returns_invalid(void **state) { const char *result; use_mocked = true; will_return(__wrap_getenv, NULL); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp"); will_return(__wrap_getenv, ""); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp"); will_return(__wrap_getenv, "subpath"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp"); use_mocked = false; } static void getenv_returns_valid(void **state) { const char *result; use_mocked = true; will_return(__wrap_getenv, "/var/tmp"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/var/tmp"); will_return(__wrap_getenv, "/"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/"); will_return(__wrap_getenv, "/tmp/abcd.1234"); // getenv("TMPDIR") return value result = pcmk__get_tmpdir(); assert_string_equal(result, "/tmp/abcd.1234"); use_mocked = false; } int main(int argc, char **argv) { const struct CMUnitTest tests[] = { cmocka_unit_test(getenv_returns_invalid), cmocka_unit_test(getenv_returns_valid), }; cmocka_set_message_output(CM_OUTPUT_TAP); return cmocka_run_group_tests(tests, NULL, NULL); } diff --git a/lib/common/tests/utils/pcmk_hostname_test.c b/lib/common/tests/utils/pcmk_hostname_test.c index 7eb747b1b1..2af27da2aa 100644 --- a/lib/common/tests/utils/pcmk_hostname_test.c +++ b/lib/common/tests/utils/pcmk_hostname_test.c @@ -1,71 +1,71 @@ /* * Copyright 2021 the Pacemaker project contributors * * The version control history for this file may have further details. * * This source code is licensed under the GNU Lesser General Public License * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY. */ #include #include "mock_private.h" #include #include #include #include #include #include #include #include int __wrap_uname(struct utsname *buf) { int retval = mock_type(int); if (retval == 0) { - strcpy(buf->nodename, mock_type(char *)); + strcpy(buf->nodename, mock_ptr_type(char *)); } return retval; } static void uname_succeeded_test(void **state) { char *retval; will_return(__wrap_uname, 0); // uname() return value will_return(__wrap_uname, "somename"); // uname() buf->nodename retval = pcmk_hostname(); assert_non_null(retval); assert_string_equal("somename", retval); free(retval); } static void uname_failed_test(void **state) { char *retval; will_return(__wrap_uname, -1); // uname() return value retval = pcmk_hostname(); assert_null(retval); } int main(int argc, char **argv) { const struct CMUnitTest tests[] = { cmocka_unit_test(uname_succeeded_test), cmocka_unit_test(uname_failed_test), }; cmocka_set_message_output(CM_OUTPUT_TAP); return cmocka_run_group_tests(tests, NULL, NULL); }