mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2025-08-08 17:22:05 +03:00
Tests for module 'vfprintf-posix'.
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
2007-03-08 Bruno Haible <bruno@clisp.org>
|
2007-03-08 Bruno Haible <bruno@clisp.org>
|
||||||
|
|
||||||
|
* 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.
|
* modules/vfprintf-posix: New file.
|
||||||
* lib/vfprintf.c: New file.
|
* lib/vfprintf.c: New file.
|
||||||
* m4/vfprintf-posix.m4: New file.
|
* m4/vfprintf-posix.m4: New file.
|
||||||
|
16
modules/vfprintf-posix-tests
Normal file
16
modules/vfprintf-posix-tests
Normal file
@@ -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
|
61
tests/test-fprintf-posix.h
Normal file
61
tests/test-fprintf-posix.h
Normal file
@@ -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 <bruno@clisp.org>, 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);
|
||||||
|
}
|
11
tests/test-fprintf-posix.out
Normal file
11
tests/test-fprintf-posix.out
Normal file
@@ -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
|
53
tests/test-vfprintf-posix.c
Normal file
53
tests/test-vfprintf-posix.c
Normal file
@@ -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 <bruno@clisp.org>, 2007. */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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;
|
||||||
|
}
|
15
tests/test-vfprintf-posix.sh
Executable file
15
tests/test-vfprintf-posix.sh
Executable file
@@ -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
|
Reference in New Issue
Block a user