From 8c5e6f236e3e1d15b0ddf4b2e7305d1e3a7fe77a Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 31 Oct 2007 02:25:22 +0100 Subject: [PATCH] Tests for module 'xprintf-posix'. --- ChangeLog | 5 +++++ modules/xprintf-posix-tests | 18 ++++++++++++++++ tests/test-xfprintf-posix.c | 52 +++++++++++++++++++++++++++++++++++++++++++++ tests/test-xprintf-posix.c | 51 ++++++++++++++++++++++++++++++++++++++++++++ tests/test-xprintf-posix.sh | 24 +++++++++++++++++++++ 5 files changed, 150 insertions(+) create mode 100644 modules/xprintf-posix-tests create mode 100644 tests/test-xfprintf-posix.c create mode 100644 tests/test-xprintf-posix.c create mode 100755 tests/test-xprintf-posix.sh diff --git a/ChangeLog b/ChangeLog index 9cdaef1b6..8799bb792 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2007-10-30 Bruno Haible + * 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 diff --git a/modules/xprintf-posix-tests b/modules/xprintf-posix-tests new file mode 100644 index 000000000..b81932b6b --- /dev/null +++ b/modules/xprintf-posix-tests @@ -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 index 000000000..ce69b0b53 --- /dev/null +++ b/tests/test-xfprintf-posix.c @@ -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 . */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "xprintf.h" + +#include +#include +#include +#include +#include +#include + +#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 index 000000000..a935e3253 --- /dev/null +++ b/tests/test-xprintf-posix.c @@ -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 . */ + +/* Written by Bruno Haible , 2007. */ + +#include + +#include "xprintf.h" + +#include +#include +#include +#include +#include + +#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 index 000000000..b9ed7fcf9 --- /dev/null +++ b/tests/test-xprintf-posix.sh @@ -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 -- 2.11.0