changeset 8393:744a1a36452c

Tests for module 'vfprintf-posix'.
author Bruno Haible <bruno@clisp.org>
date Fri, 09 Mar 2007 02:43:32 +0000
parents ac5d6be5a627
children fbb6e4d5f75b
files ChangeLog modules/vfprintf-posix-tests tests/test-fprintf-posix.h tests/test-fprintf-posix.out tests/test-vfprintf-posix.c tests/test-vfprintf-posix.sh
diffstat 6 files changed, 162 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 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.
 	* lib/vfprintf.c: New file.
 	* m4/vfprintf-posix.m4: New file.
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
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 <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);
+}
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
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 <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;
+}
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