From: Bruno Haible Date: Sun, 30 Jun 2024 20:12:41 +0000 (+0200) Subject: vzprintf-posix: Add tests. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=76effdd6989637de1e99ac3d3dbd446f942117b5;p=gnulib.git vzprintf-posix: Add tests. * tests/test-printf-posix.h (test_function): Use RETTYPE instead of 'int'. * tests/test-printf-posix.c (RETTYPE): New macro. * tests/test-vprintf-posix.c (RETTYPE): New macro. * tests/test-xprintf-posix.c (RETTYPE): New macro. * tests/test-vzprintf-posix.c: New file, based on tests/test-vprintf-posix.c. * tests/test-vzprintf-posix.sh: New file, based on tests/test-vprintf-posix.sh. * modules/vzprintf-posix-tests: New file. --- diff --git a/ChangeLog b/ChangeLog index 4962f24cf2..4d4489279a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,17 @@ 2024-06-30 Bruno Haible + vzprintf-posix: Add tests. + * tests/test-printf-posix.h (test_function): Use RETTYPE instead of + 'int'. + * tests/test-printf-posix.c (RETTYPE): New macro. + * tests/test-vprintf-posix.c (RETTYPE): New macro. + * tests/test-xprintf-posix.c (RETTYPE): New macro. + * tests/test-vzprintf-posix.c: New file, based on + tests/test-vprintf-posix.c. + * tests/test-vzprintf-posix.sh: New file, based on + tests/test-vprintf-posix.sh. + * modules/vzprintf-posix-tests: New file. + vzprintf-posix: New module. * modules/vzprintf-posix: New file. diff --git a/modules/vzprintf-posix-tests b/modules/vzprintf-posix-tests new file mode 100644 index 0000000000..c6e4b8eaa9 --- /dev/null +++ b/modules/vzprintf-posix-tests @@ -0,0 +1,16 @@ +Files: +tests/test-vzprintf-posix.sh +tests/test-vzprintf-posix.c +tests/test-printf-posix.h +tests/test-printf-posix.output +tests/infinity.h +tests/macros.h + +Depends-on: +stdint + +configure.ac: + +Makefile.am: +TESTS += test-vzprintf-posix.sh +check_PROGRAMS += test-vzprintf-posix diff --git a/tests/test-printf-posix.c b/tests/test-printf-posix.c index f24a0297ef..8e7667740e 100644 --- a/tests/test-printf-posix.c +++ b/tests/test-printf-posix.c @@ -29,6 +29,7 @@ SIGNATURE_CHECK (printf, int, (char const *, ...)); #include "macros.h" +#define RETTYPE int #include "test-printf-posix.h" int diff --git a/tests/test-printf-posix.h b/tests/test-printf-posix.h index 68e8edb175..60b6cf9c84 100644 --- a/tests/test-printf-posix.h +++ b/tests/test-printf-posix.h @@ -1,4 +1,4 @@ -/* Test of POSIX compatible vprintf() and printf() functions. +/* Test of POSIX compatible v[z]printf() and printf() functions. Copyright (C) 2007-2024 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -19,7 +19,7 @@ #include "infinity.h" static void -test_function (int (*my_printf) (const char *, ...)) +test_function (RETTYPE (*my_printf) (const char *, ...)) { /* Here we don't test output that may be platform dependent. The bulk of the tests is done as part of the 'vasnprintf-posix' module. */ diff --git a/tests/test-vprintf-posix.c b/tests/test-vprintf-posix.c index 795b09366b..b25274ab9d 100644 --- a/tests/test-vprintf-posix.c +++ b/tests/test-vprintf-posix.c @@ -30,6 +30,7 @@ SIGNATURE_CHECK (vprintf, int, (char const *, va_list)); #include "macros.h" +#define RETTYPE int #include "test-printf-posix.h" static int diff --git a/tests/test-vzprintf-posix.c b/tests/test-vzprintf-posix.c new file mode 100644 index 0000000000..daf6e97b0f --- /dev/null +++ b/tests/test-vzprintf-posix.c @@ -0,0 +1,50 @@ +/* Test of POSIX compatible vzprintf() function. + Copyright (C) 2007-2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include + +#include +#include +#include +#include + +#include "macros.h" + +#define RETTYPE off64_t +#include "test-printf-posix.h" + +static off64_t +my_zprintf (const char *format, ...) +{ + va_list args; + off64_t ret; + + va_start (args, format); + ret = vzprintf (format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + test_function (my_zprintf); + return test_exit_status; +} diff --git a/tests/test-vzprintf-posix.sh b/tests/test-vzprintf-posix.sh new file mode 100755 index 0000000000..fc55247be3 --- /dev/null +++ b/tests/test-vzprintf-posix.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' HUP INT QUIT TERM + +tmpfiles="$tmpfiles t-vzprintf-posix.tmp t-vzprintf-posix.out" +${CHECKER} ./test-vzprintf-posix${EXEEXT} > t-vzprintf-posix.tmp || exit 1 +LC_ALL=C tr -d '\r' < t-vzprintf-posix.tmp > t-vzprintf-posix.out || exit 1 + +: "${DIFF=diff}" +${DIFF} "${srcdir}/test-printf-posix.output" t-vzprintf-posix.out +result=$? + +rm -fr $tmpfiles + +exit $result diff --git a/tests/test-xprintf-posix.c b/tests/test-xprintf-posix.c index 29758ef42c..c9e79c0e26 100644 --- a/tests/test-xprintf-posix.c +++ b/tests/test-xprintf-posix.c @@ -26,6 +26,7 @@ #include "macros.h" +#define RETTYPE int #include "test-printf-posix.h" int