From 5aecec4e4370e72304ca13a0f690306835474204 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 30 Jun 2024 17:21:04 +0200 Subject: [PATCH] vdzprintf-posix: Add tests. * tests/test-fprintf-posix.h (test_function): Use RETTYPE instead of 'int'. * tests/test-fprintf-posix.c (RETTYPE): New macro. * tests/test-vdprintf-posix.c (RETTYPE): New macro. * tests/test-vfprintf-posix.c (RETTYPE): New macro. * tests/test-xfprintf-posix.c (RETTYPE): New macro. * tests/test-vdzprintf-posix.c: New file, based on tests/test-vdprintf-posix.c. * tests/test-vdzprintf-posix.sh: New file, based on tests/test-vdprintf-posix.sh. * modules/vdzprintf-posix-tests: New file. --- ChangeLog | 13 +++++++++ modules/vdzprintf-posix-tests | 16 +++++++++++ tests/test-fprintf-posix.c | 1 + tests/test-fprintf-posix.h | 4 +-- tests/test-vdprintf-posix.c | 1 + tests/test-vdzprintf-posix.c | 50 +++++++++++++++++++++++++++++++++++ tests/test-vdzprintf-posix.sh | 16 +++++++++++ tests/test-vfprintf-posix.c | 1 + tests/test-xfprintf-posix.c | 1 + 9 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 modules/vdzprintf-posix-tests create mode 100644 tests/test-vdzprintf-posix.c create mode 100755 tests/test-vdzprintf-posix.sh diff --git a/ChangeLog b/ChangeLog index a13e83c694..4b2988dea5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,18 @@ 2024-06-30 Bruno Haible + vdzprintf-posix: Add tests. + * tests/test-fprintf-posix.h (test_function): Use RETTYPE instead of + 'int'. + * tests/test-fprintf-posix.c (RETTYPE): New macro. + * tests/test-vdprintf-posix.c (RETTYPE): New macro. + * tests/test-vfprintf-posix.c (RETTYPE): New macro. + * tests/test-xfprintf-posix.c (RETTYPE): New macro. + * tests/test-vdzprintf-posix.c: New file, based on + tests/test-vdprintf-posix.c. + * tests/test-vdzprintf-posix.sh: New file, based on + tests/test-vdprintf-posix.sh. + * modules/vdzprintf-posix-tests: New file. + vdzprintf-posix: New module. * modules/vdzprintf-posix: New file. diff --git a/modules/vdzprintf-posix-tests b/modules/vdzprintf-posix-tests new file mode 100644 index 0000000000..8cbf0d61b4 --- /dev/null +++ b/modules/vdzprintf-posix-tests @@ -0,0 +1,16 @@ +Files: +tests/test-vdzprintf-posix.sh +tests/test-vdzprintf-posix.c +tests/test-fprintf-posix.h +tests/test-printf-posix.output +tests/infinity.h +tests/macros.h + +Depends-on: +stdint + +configure.ac: + +Makefile.am: +TESTS += test-vdzprintf-posix.sh +check_PROGRAMS += test-vdzprintf-posix diff --git a/tests/test-fprintf-posix.c b/tests/test-fprintf-posix.c index f929faeca7..019cdcf2bc 100644 --- a/tests/test-fprintf-posix.c +++ b/tests/test-fprintf-posix.c @@ -30,6 +30,7 @@ SIGNATURE_CHECK (fprintf, int, (FILE *, char const *, ...)); #include "macros.h" +#define RETTYPE int #include "test-fprintf-posix.h" int diff --git a/tests/test-fprintf-posix.h b/tests/test-fprintf-posix.h index 8576f58324..eac279ddb8 100644 --- a/tests/test-fprintf-posix.h +++ b/tests/test-fprintf-posix.h @@ -1,4 +1,4 @@ -/* Test of POSIX compatible [v]fprintf() and vdprintf() functions. +/* Test of POSIX compatible [v]fprintf() and vd[z]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_fprintf) (FILE *, const char *, ...)) +test_function (RETTYPE (*my_fprintf) (FILE *, 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-vdprintf-posix.c b/tests/test-vdprintf-posix.c index 0d6b6e39b3..eec47b0bc6 100644 --- a/tests/test-vdprintf-posix.c +++ b/tests/test-vdprintf-posix.c @@ -30,6 +30,7 @@ SIGNATURE_CHECK (vdprintf, int, (int, char const *, va_list)); #include "macros.h" +#define RETTYPE int #include "test-fprintf-posix.h" static int diff --git a/tests/test-vdzprintf-posix.c b/tests/test-vdzprintf-posix.c new file mode 100644 index 0000000000..f9573fc18d --- /dev/null +++ b/tests/test-vdzprintf-posix.c @@ -0,0 +1,50 @@ +/* Test of POSIX compatible vdzprintf() 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 , 2009. */ + +#include + +#include + +#include +#include +#include +#include + +#include "macros.h" + +#define RETTYPE off64_t +#include "test-fprintf-posix.h" + +static off64_t +my_fzprintf (FILE *fp, const char *format, ...) +{ + va_list args; + off64_t ret; + + va_start (args, format); + ret = vdzprintf (fileno (fp), format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + test_function (my_fzprintf); + return test_exit_status; +} diff --git a/tests/test-vdzprintf-posix.sh b/tests/test-vdzprintf-posix.sh new file mode 100755 index 0000000000..be2f5d79b9 --- /dev/null +++ b/tests/test-vdzprintf-posix.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' HUP INT QUIT TERM + +tmpfiles="$tmpfiles t-vdzprintf-posix.tmp t-vdzprintf-posix.out" +${CHECKER} ./test-vdzprintf-posix${EXEEXT} > t-vdzprintf-posix.tmp || exit 1 +LC_ALL=C tr -d '\r' < t-vdzprintf-posix.tmp > t-vdzprintf-posix.out || exit 1 + +: "${DIFF=diff}" +${DIFF} "${srcdir}/test-printf-posix.output" t-vdzprintf-posix.out +result=$? + +rm -fr $tmpfiles + +exit $result diff --git a/tests/test-vfprintf-posix.c b/tests/test-vfprintf-posix.c index ae9c8f35bc..c64c1d2c4d 100644 --- a/tests/test-vfprintf-posix.c +++ b/tests/test-vfprintf-posix.c @@ -30,6 +30,7 @@ SIGNATURE_CHECK (vfprintf, int, (FILE *, char const *, va_list)); #include "macros.h" +#define RETTYPE int #include "test-fprintf-posix.h" static int diff --git a/tests/test-xfprintf-posix.c b/tests/test-xfprintf-posix.c index e17f5cbac3..372a8fd830 100644 --- a/tests/test-xfprintf-posix.c +++ b/tests/test-xfprintf-posix.c @@ -27,6 +27,7 @@ #include "macros.h" +#define RETTYPE int #include "test-fprintf-posix.h" int -- 2.39.5