From: Bruno Haible Date: Sun, 30 Jun 2024 21:04:37 +0000 (+0200) Subject: vzprintf-gnu: Add tests. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=c630fd2fce49231adca9a58eccce0ec71be782d1;p=gnulib.git vzprintf-gnu: Add tests. * tests/test-printf-gnu.h (test_function): Use RETTYPE instead of 'int'. * tests/test-printf-gnu.c (RETTYPE): New macro. * tests/test-vprintf-gnu.c (RETTYPE): New macro. * tests/test-vzprintf-gnu.c: New file, based on tests/test-vprintf-gnu.c. * tests/test-vzprintf-gnu.sh: New file, based on tests/test-vprintf-gnu.sh. * modules/vzprintf-gnu-tests: New file. --- diff --git a/ChangeLog b/ChangeLog index 0a450fe9db..d6c8927bcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2024-06-30 Bruno Haible + vzprintf-gnu: Add tests. + * tests/test-printf-gnu.h (test_function): Use RETTYPE instead of 'int'. + * tests/test-printf-gnu.c (RETTYPE): New macro. + * tests/test-vprintf-gnu.c (RETTYPE): New macro. + * tests/test-vzprintf-gnu.c: New file, based on + tests/test-vprintf-gnu.c. + * tests/test-vzprintf-gnu.sh: New file, based on + tests/test-vprintf-gnu.sh. + * modules/vzprintf-gnu-tests: New file. + vzprintf-gnu: New module. * modules/vzprintf-gnu: New file. diff --git a/modules/vzprintf-gnu-tests b/modules/vzprintf-gnu-tests new file mode 100644 index 0000000000..d08e58f813 --- /dev/null +++ b/modules/vzprintf-gnu-tests @@ -0,0 +1,14 @@ +Files: +tests/test-vzprintf-gnu.sh +tests/test-vzprintf-gnu.c +tests/test-printf-gnu.h +tests/test-printf-gnu.output +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-vzprintf-gnu.sh +check_PROGRAMS += test-vzprintf-gnu diff --git a/tests/test-printf-gnu.c b/tests/test-printf-gnu.c index ccd4f8bd67..f229f5fd59 100644 --- a/tests/test-printf-gnu.c +++ b/tests/test-printf-gnu.c @@ -25,6 +25,7 @@ #include "macros.h" +#define RETTYPE int #include "test-printf-gnu.h" int diff --git a/tests/test-printf-gnu.h b/tests/test-printf-gnu.h index 1ee541669a..b9a9effe04 100644 --- a/tests/test-printf-gnu.h +++ b/tests/test-printf-gnu.h @@ -1,4 +1,4 @@ -/* Test of POSIX and GNU compatible vprintf() and printf() functions. +/* Test of POSIX and GNU compatible [v][z]printf() functions. Copyright (C) 2007-2024 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -17,7 +17,7 @@ /* Written by Bruno Haible , 2023. */ 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-gnu.c b/tests/test-vprintf-gnu.c index 1655d26140..638ac70a6f 100644 --- a/tests/test-vprintf-gnu.c +++ b/tests/test-vprintf-gnu.c @@ -1,4 +1,4 @@ -/* Test of POSIX and GNU compatible vfprintf() function. +/* Test of POSIX and GNU compatible vprintf() function. Copyright (C) 2007-2024 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify @@ -26,6 +26,7 @@ #include "macros.h" +#define RETTYPE int #include "test-printf-gnu.h" static int diff --git a/tests/test-vzprintf-gnu.c b/tests/test-vzprintf-gnu.c new file mode 100644 index 0000000000..1056f0e45b --- /dev/null +++ b/tests/test-vzprintf-gnu.c @@ -0,0 +1,49 @@ +/* Test of POSIX and GNU 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 "macros.h" + +#define RETTYPE off64_t +#include "test-printf-gnu.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-gnu.sh b/tests/test-vzprintf-gnu.sh new file mode 100755 index 0000000000..471a4af02f --- /dev/null +++ b/tests/test-vzprintf-gnu.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' HUP INT QUIT TERM + +tmpfiles="$tmpfiles t-vzprintf-gnu.tmp t-vzprintf-gnu.out" +${CHECKER} ./test-vzprintf-gnu${EXEEXT} > t-vzprintf-gnu.tmp || exit 1 +LC_ALL=C tr -d '\r' < t-vzprintf-gnu.tmp > t-vzprintf-gnu.out || exit 1 + +: "${DIFF=diff}" +${DIFF} "${srcdir}/test-printf-gnu.output" t-vzprintf-gnu.out +result=$? + +rm -fr $tmpfiles + +exit $result