Tests for module 'xprintf-posix'.
authorBruno Haible <bruno@clisp.org>
Wed, 31 Oct 2007 01:25:22 +0000 (02:25 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 31 Oct 2007 01:25:22 +0000 (02:25 +0100)
ChangeLog
modules/xprintf-posix-tests [new file with mode: 0644]
tests/test-xfprintf-posix.c [new file with mode: 0644]
tests/test-xprintf-posix.c [new file with mode: 0644]
tests/test-xprintf-posix.sh [new file with mode: 0755]

index 9cdaef1..8799bb7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2007-10-30  Bruno Haible  <bruno@clisp.org>
 
+       * modules/xprintf-posix-tests: New file.
+       * tests/test-xprintf-posix.sh: New file.
+       * tests/test-xprintf-posix.c: New file.
+       * tests/test-xfprintf-posix.c: New file.
+
        * modules/xprintf-posix: New file.
 
 2007-10-30  Ralf Wildenhues  <Ralf.Wildenhues@gmx.de>
diff --git a/modules/xprintf-posix-tests b/modules/xprintf-posix-tests
new file mode 100644 (file)
index 0000000..b81932b
--- /dev/null
@@ -0,0 +1,18 @@
+Files:
+tests/test-xprintf-posix.sh
+tests/test-xfprintf-posix.c
+tests/test-xprintf-posix.c
+tests/test-fprintf-posix.h
+tests/test-printf-posix.h
+tests/test-printf-posix.output
+
+Depends-on:
+stdint
+progname
+
+configure.ac:
+
+Makefile.am:
+TESTS += test-xprintf-posix.sh
+TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)'
+check_PROGRAMS += test-xfprintf-posix test-xprintf-posix
diff --git a/tests/test-xfprintf-posix.c b/tests/test-xfprintf-posix.c
new file mode 100644 (file)
index 0000000..ce69b0b
--- /dev/null
@@ -0,0 +1,52 @@
+/* Test of error-checking xfprintf() function with POSIX compatible formatting.
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#include <config.h>
+
+#include "xprintf.h"
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "progname.h"
+
+#define ASSERT(expr) \
+  do                                                                        \
+    {                                                                       \
+      if (!(expr))                                                          \
+        {                                                                   \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          abort ();                                                         \
+        }                                                                   \
+    }                                                                       \
+  while (0)
+
+#include "test-fprintf-posix.h"
+
+int
+main (int argc, char *argv[])
+{
+  set_program_name (argv[0]);
+
+  test_function (xfprintf);
+  return 0;
+}
diff --git a/tests/test-xprintf-posix.c b/tests/test-xprintf-posix.c
new file mode 100644 (file)
index 0000000..a935e32
--- /dev/null
@@ -0,0 +1,51 @@
+/* Test of error-checking xprintf() function with POSIX compatible formatting.
+   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 3 of the License, 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, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
+
+#include <config.h>
+
+#include "xprintf.h"
+
+#include <stddef.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "progname.h"
+
+#define ASSERT(expr) \
+  do                                                                        \
+    {                                                                       \
+      if (!(expr))                                                          \
+        {                                                                   \
+          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+          abort ();                                                         \
+        }                                                                   \
+    }                                                                       \
+  while (0)
+
+#include "test-printf-posix.h"
+
+int
+main (int argc, char *argv[])
+{
+  set_program_name (argv[0]);
+
+  test_function (xprintf);
+  return 0;
+}
diff --git a/tests/test-xprintf-posix.sh b/tests/test-xprintf-posix.sh
new file mode 100755 (executable)
index 0000000..b9ed7fc
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles t-xprintf-posix.tmp t-xprintf-posix.out"
+./test-xprintf-posix${EXEEXT} > t-xprintf-posix.tmp || exit 1
+tr -d '\r' < t-xprintf-posix.tmp > t-xprintf-posix.out || exit 1
+
+: ${DIFF=diff}
+${DIFF} "${srcdir}/test-printf-posix.output" t-xprintf-posix.out
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+tmpfiles="$tmpfiles t-xfprintf-posix.tmp t-xfprintf-posix.out"
+./test-xfprintf-posix${EXEEXT} > t-xfprintf-posix.tmp || exit 1
+tr -d '\r' < t-xfprintf-posix.tmp > t-xfprintf-posix.out || exit 1
+
+: ${DIFF=diff}
+${DIFF} "${srcdir}/test-printf-posix.output" t-xfprintf-posix.out
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+rm -fr $tmpfiles
+
+exit 0