From: Bruno Haible Date: Fri, 9 Mar 2007 03:43:46 +0000 (+0000) Subject: Tests for module 'vprintf-posix'. X-Git-Tag: cvs-readonly~821 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=ed91d0417a5d9abb08f7e3de0a5656e8974dbc76;p=gnulib.git Tests for module 'vprintf-posix'. --- diff --git a/ChangeLog b/ChangeLog index eef8e0664..4940bef4b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-03-08 Bruno Haible + * modules/vprintf-posix-tests: New file. + * tests/test-vprintf-posix.sh: New file. + * tests/test-vprintf-posix.c: New file. + * tests/test-printf-posix.h: New file. + * modules/vprintf-posix: New file. * lib/vprintf.c: New file. * m4/vprintf-posix.m4: New file. diff --git a/modules/vprintf-posix-tests b/modules/vprintf-posix-tests new file mode 100644 index 000000000..26631b78e --- /dev/null +++ b/modules/vprintf-posix-tests @@ -0,0 +1,16 @@ +Files: +tests/test-vprintf-posix.sh +tests/test-vprintf-posix.c +tests/test-printf-posix.h +tests/test-fprintf-posix.out + +Depends-on: +stdint + +configure.ac: + +Makefile.am: +TESTS += test-vprintf-posix.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)' +check_PROGRAMS += test-vprintf-posix +EXTRA_DIST += test-vprintf-posix.sh test-printf-posix.h test-fprintf-posix.out diff --git a/tests/test-printf-posix.h b/tests/test-printf-posix.h new file mode 100644 index 000000000..04d3e550d --- /dev/null +++ b/tests/test-printf-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_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. */ + + /* Test support of size specifiers as in C99. */ + + my_printf ("%ju %d\n", (uintmax_t) 12345671, 33, 44, 55); + + my_printf ("%zu %d\n", (size_t) 12345672, 33, 44, 55); + + my_printf ("%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_printf ("%a %d\n", 0.0, 33, 44, 55); + + /* Negative zero. */ + my_printf ("%a %d\n", -0.0, 33, 44, 55); + + /* Positive infinity. */ + my_printf ("%a %d\n", 1.0 / 0.0, 33, 44, 55); + + /* Negative infinity. */ + my_printf ("%a %d\n", -1.0 / 0.0, 33, 44, 55); + + /* NaN. */ + my_printf ("%a %d\n", 0.0 / 0.0, 33, 44, 55); + + /* FLAG_ZERO with infinite number. */ + my_printf ("%010a %d\n", 1.0 / 0.0, 33, 44, 55); + + /* FLAG_ZERO with NaN. */ + my_printf ("%010a %d\n", 0.0 / 0.0, 33, 44, 55); + + /* Test the support of the POSIX/XSI format strings with positions. */ + + my_printf ("%2$d %1$d\n", 33, 55); +} diff --git a/tests/test-vprintf-posix.c b/tests/test-vprintf-posix.c new file mode 100644 index 000000000..6f7f141d1 --- /dev/null +++ b/tests/test-vprintf-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_printf (const char *format, ...) +{ + va_list args; + int ret; + + va_start (args, format); + ret = vprintf (format, args); + va_end (args); + return ret; +} + +#include "test-printf-posix.h" + +int +main (int argc, char *argv[]) +{ + test_function (my_printf); + return 0; +} diff --git a/tests/test-vprintf-posix.sh b/tests/test-vprintf-posix.sh new file mode 100755 index 000000000..1f27b39ca --- /dev/null +++ b/tests/test-vprintf-posix.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles t-vprintf-posix.tmp" +./test-vprintf-posix${EXEEXT} > t-vprintf-posix.tmp || exit 1 + +: ${DIFF=diff} +${DIFF} "${srcdir}/test-fprintf-posix.out" t-vprintf-posix.tmp +result=$? + +rm -fr $tmpfiles + +exit $result