From: Alejandro Colomar Date: Tue, 4 Nov 2025 12:46:01 +0000 (+0100) Subject: tests/unit/: Use more generic strings and names for testing exit_if_null() X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=17ad06b379623b1fc6efd58c1ff0db4c37d99bd0;p=thirdparty%2Fshadow.git tests/unit/: Use more generic strings and names for testing exit_if_null() This test is actually for exit_if_null(), not xaprintf(). Rename the test file and functions, and make strings more generic. Tested-by: Silvan Mosberger Reviewed-by: Iker Pedrosa Signed-off-by: Alejandro Colomar --- diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index e10c0ca38..a0e1fad61 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -11,7 +11,7 @@ check_PROGRAMS = \ test_strncpy \ test_strtcpy \ test_typetraits \ - test_xaprintf + test_exit_if_null if ENABLE_LOGIND check_PROGRAMS += \ @@ -129,21 +129,21 @@ test_typetraits_LDADD = \ $(CMOCKA_LIBS) \ $(NULL) -test_xaprintf_SOURCES = \ +test_exit_if_null_SOURCES = \ ../../lib/exit_if_null.c \ ../../lib/shadowlog.c \ ../../lib/string/sprintf/aprintf.c \ ../../lib/string/strcmp/streq.c \ - test_xaprintf.c \ + test_exit_if_null.c \ $(NULL) -test_xaprintf_CFLAGS = \ +test_exit_if_null_CFLAGS = \ $(AM_CFLAGS) \ $(NULL) -test_xaprintf_LDFLAGS = \ +test_exit_if_null_LDFLAGS = \ -Wl,-wrap,vasprintf \ -Wl,-wrap,exit \ $(NULL) -test_xaprintf_LDADD = \ +test_exit_if_null_LDADD = \ $(CMOCKA_LIBS) \ $(NULL) diff --git a/tests/unit/test_xaprintf.c b/tests/unit/test_exit_if_null.c similarity index 84% rename from tests/unit/test_xaprintf.c rename to tests/unit/test_exit_if_null.c index 995a29e00..0dda1592a 100644 --- a/tests/unit/test_xaprintf.c +++ b/tests/unit/test_exit_if_null.c @@ -32,16 +32,16 @@ int __real_vasprintf(char **restrict p, const char *restrict fmt, va_list ap); int __wrap_vasprintf(char **restrict p, const char *restrict fmt, va_list ap); void __wrap_exit(int status); -static void test_xaprintf_exit(void **state); -static void test_xaprintf_ok(void **state); +static void test_exit_if_null_exit(void **state); +static void test_exit_if_null_ok(void **state); int main(void) { const struct CMUnitTest tests[] = { - cmocka_unit_test(test_xaprintf_exit), - cmocka_unit_test(test_xaprintf_ok), + cmocka_unit_test(test_exit_if_null_exit), + cmocka_unit_test(test_exit_if_null_ok), }; return cmocka_run_group_tests(tests, NULL, NULL); @@ -63,7 +63,7 @@ __wrap_exit(int status) static void -test_xaprintf_exit(void **state) +test_exit_if_null_exit(void **state) { char *volatile p; @@ -73,12 +73,12 @@ test_xaprintf_exit(void **state) switch (setjmp(jmpb)) { case 0: - p = "xaprintf_called"; + p = "called"; p = xaprintf("foo%s", "bar"); assert_unreachable(); break; case EXIT_CALLED: - assert_true(streq(p, "xaprintf_called")); + assert_true(streq(p, "called")); p = "test_ok"; break; default: @@ -91,7 +91,7 @@ test_xaprintf_exit(void **state) static void -test_xaprintf_ok(void **state) +test_exit_if_null_ok(void **state) { char *p;