# HG changeset patch # User Bruno Haible # Date 1232243429 -3600 # Node ID c1aeb2f8dd656122ee05099fe5c2363ff9f138cc # Parent 049c445485ee2492caf510f576cf64a054bf05f4 Tests for module 'vdprintf-posix'. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2009-01-17 Bruno Haible + * modules/vdprintf-posix-tests: New file. + * tests/test-vdprintf-posix.sh: New file. + * tests/test-vdprintf-posix.c: New file. + New modules 'vdprintf', 'vdprintf-posix'. * lib/stdio.in.h (vdprintf): New declaration. * lib/vdprintf.c: New file. diff --git a/modules/vdprintf-posix-tests b/modules/vdprintf-posix-tests new file mode 100644 --- /dev/null +++ b/modules/vdprintf-posix-tests @@ -0,0 +1,15 @@ +Files: +tests/test-vdprintf-posix.sh +tests/test-vdprintf-posix.c +tests/test-fprintf-posix.h +tests/test-printf-posix.output + +Depends-on: +stdint + +configure.ac: + +Makefile.am: +TESTS += test-vdprintf-posix.sh +TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' srcdir='$(srcdir)' +check_PROGRAMS += test-vdprintf-posix diff --git a/tests/test-vdprintf-posix.c b/tests/test-vdprintf-posix.c new file mode 100644 --- /dev/null +++ b/tests/test-vdprintf-posix.c @@ -0,0 +1,60 @@ +/* Test of POSIX compatible vdprintf() function. + Copyright (C) 2007-2009 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 , 2009. */ + +#include + +#include + +#include +#include +#include +#include +#include + +#define ASSERT(expr) \ + do \ + { \ + if (!(expr)) \ + { \ + fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \ + fflush (stderr); \ + abort (); \ + } \ + } \ + while (0) + +#include "test-fprintf-posix.h" + +static int +my_fprintf (FILE *fp, const char *format, ...) +{ + va_list args; + int ret; + + va_start (args, format); + ret = vdprintf (fileno (fp), format, args); + va_end (args); + return ret; +} + +int +main (int argc, char *argv[]) +{ + test_function (my_fprintf); + return 0; +} diff --git a/tests/test-vdprintf-posix.sh b/tests/test-vdprintf-posix.sh new file mode 100755 --- /dev/null +++ b/tests/test-vdprintf-posix.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +tmpfiles="" +trap 'rm -fr $tmpfiles' 1 2 3 15 + +tmpfiles="$tmpfiles t-vdprintf-posix.tmp t-vdprintf-posix.out" +./test-vdprintf-posix${EXEEXT} > t-vdprintf-posix.tmp || exit 1 +LC_ALL=C tr -d '\r' < t-vdprintf-posix.tmp > t-vdprintf-posix.out || exit 1 + +: ${DIFF=diff} +${DIFF} "${srcdir}/test-printf-posix.output" t-vdprintf-posix.out +result=$? + +rm -fr $tmpfiles + +exit $result