]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
tests/unit/: Use more generic strings and names for testing exit_if_null()
authorAlejandro Colomar <alx@kernel.org>
Tue, 4 Nov 2025 12:46:01 +0000 (13:46 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Thu, 6 Nov 2025 12:31:01 +0000 (13:31 +0100)
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 <github@infinisil.com>
Reviewed-by: Iker Pedrosa <ipedrosa@redhat.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
tests/unit/Makefile.am
tests/unit/test_exit_if_null.c [moved from tests/unit/test_xaprintf.c with 84% similarity]

index e10c0ca38c7b242ebb50d0ac670fa82390a03a98..a0e1fad61537dbaeceeafbcdba7ba90d208c0604 100644 (file)
@@ -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)
 
similarity index 84%
rename from tests/unit/test_xaprintf.c
rename to tests/unit/test_exit_if_null.c
index 995a29e00e389fcbb22dfb519883f54540014cf2..0dda1592ad0d8ce421f087d35deecd77ff97da9d 100644 (file)
@@ -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;