# HG changeset patch # User Bruno Haible # Date 1173408212 0 # Node ID 744a1a36452c5a36ee0a06324e827aed26382915 # Parent ac5d6be5a6278eb61c1d5ccedfc9b74966185119 Tests for module 'vfprintf-posix'. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-03-08 Bruno Haible + * modules/vfprintf-posix-tests: New file. + * tests/test-vfprintf-posix.sh: New file. + * tests/test-vfprintf-posix.c: New file. + * tests/test-fprintf-posix.h: New file. + * tests/test-fprintf-posix.out: New file. + * modules/vfprintf-posix: New file. * lib/vfprintf.c: New file. * m4/vfprintf-posix.m4: New file. diff --git a/modules/vfprintf-posix-tests b/modules/vfprintf-posix-tests new file mode 100644 --- /dev/null +++ b/modules/vfprintf-posix-tests @@ -0,0 +1,16 @@ +Files: +tests/test-vfprintf-posix.sh +tests/test-vfprintf-posix.c +tests/test-fprintf-posix.h +tests/test-fprintf-posix.out + +Depends-on: +stdint + +configure.ac: + +Makefile.am: +TESTS += test-vfprintf-posix.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)' +check_PROGRAMS += test-vfprintf-posix +EXTRA_DIST += test-vfprintf-posix.sh test-fprintf-posix.h test-fprintf-posix.out diff --git a/tests/test-fprintf-posix.h b/tests/test-fprintf-posix.h new file mode 100644 --- /dev/null +++ b/tests/test-fprintf-posix.h @@ -0,0 +1,61 @@ +/* Test of POSIX compatible vsprintf() and sprintf() functions. + Copyright (C) 2007 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +static void +test_function (int (*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. */ + + /* Test support of size specifiers as in C99. */ + + my_fprintf (stdout, "%ju %d\n", (uintmax_t) 12345671, 33, 44, 55); + + my_fprintf (stdout, "%zu %d\n", (size_t) 12345672, 33, 44, 55); + + my_fprintf (stdout, "%tu %d\n", (ptrdiff_t) 12345673, 33, 44, 55); + + /* Test the support of the 'a' and 'A' conversion specifier for hexadecimal + output of floating-point numbers. */ + + /* Positive zero. */ + my_fprintf (stdout, "%a %d\n", 0.0, 33, 44, 55); + + /* Negative zero. */ + my_fprintf (stdout, "%a %d\n", -0.0, 33, 44, 55); + + /* Positive infinity. */ + my_fprintf (stdout, "%a %d\n", 1.0 / 0.0, 33, 44, 55); + + /* Negative infinity. */ + my_fprintf (stdout, "%a %d\n", -1.0 / 0.0, 33, 44, 55); + + /* NaN. */ + my_fprintf (stdout, "%a %d\n", 0.0 / 0.0, 33, 44, 55); + + /* FLAG_ZERO with infinite number. */ + my_fprintf (stdout, "%010a %d\n", 1.0 / 0.0, 33, 44, 55); + + /* FLAG_ZERO with NaN. */ + my_fprintf (stdout, "%010a %d\n", 0.0 / 0.0, 33, 44, 55); + + /* Test the support of the POSIX/XSI format strings with positions. */ + + my_fprintf (stdout, "%2$d %1$d\n", 33, 55); +} diff --git a/tests/test-fprintf-posix.out b/tests/test-fprintf-posix.out new file mode 100644 --- /dev/null +++ b/tests/test-fprintf-posix.out @@ -0,0 +1,11 @@ +12345671 33 +12345672 33 +12345673 33 +0x0p+0 33 +-0x0p+0 33 +inf 33 +-inf 33 +nan 33 + inf 33 + nan 33 +55 33 diff --git a/tests/test-vfprintf-posix.c b/tests/test-vfprintf-posix.c new file mode 100644 --- /dev/null +++ b/tests/test-vfprintf-posix.c @@ -0,0 +1,53 @@ +/* Test of POSIX compatible vfprintf() function. + Copyright (C) 2007 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 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* Written by Bruno Haible , 2007. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include + +#include +#include +#include +#include +#include + +#define ASSERT(expr) if (!(expr)) abort (); + +static int +my_fprintf (FILE *fp, const char *format, ...) +{ + va_list args; + int ret; + + va_start (args, format); + ret = vfprintf (fp, format, args); + va_end (args); + return ret; +} + +#include "test-fprintf-posix.h" + +int +main (int argc, char *argv[]) +{ + test_function (my_fprintf); + return 0; +} diff --git a/tests/test-vfprintf-posix.sh b/tests/test-vfprintf-posix.sh new file mode 100755 --- /dev/null +++ b/tests/test-vfprintf-posix.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles t-vfprintf-posix.tmp" +./test-vfprintf-posix${EXEEXT} > t-vfprintf-posix.tmp || exit 1 + +: ${DIFF=diff} +${DIFF} "${srcdir}/test-fprintf-posix.out" t-vfprintf-posix.tmp +result=$? + +rm -fr $tmpfiles + +exit $result