summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2007-03-09 02:43:32 +0000
committerBruno Haible <bruno@clisp.org>2007-03-09 02:43:32 +0000
commit3691d594546687454e493b28b2a9b2c8f4d2bc12 (patch)
treeb6ff71f89c67df16c90f09a5ee9f3dc01331e2f2 /tests
parent20b319a6d47d029941507a8db8b5a2a67b40cd23 (diff)
downloadgnulib-3691d594546687454e493b28b2a9b2c8f4d2bc12.tar.gz
Tests for module 'vfprintf-posix'.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-fprintf-posix.h61
-rw-r--r--tests/test-fprintf-posix.out11
-rw-r--r--tests/test-vfprintf-posix.c53
-rwxr-xr-xtests/test-vfprintf-posix.sh15
4 files changed, 140 insertions, 0 deletions
diff --git a/tests/test-fprintf-posix.h b/tests/test-fprintf-posix.h
new file mode 100644
index 0000000000..9f1e3fa8e3
--- /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 <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);
+}
diff --git a/tests/test-fprintf-posix.out b/tests/test-fprintf-posix.out
new file mode 100644
index 0000000000..6f2e3d6db6
--- /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
index 0000000000..67e50bcf80
--- /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 <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;
+}
diff --git a/tests/test-vfprintf-posix.sh b/tests/test-vfprintf-posix.sh
new file mode 100755
index 0000000000..3141f24bea
--- /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