From 089311a6ed4a67fff8ceceb14964268a11fc8a24 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 20 Sep 2011 23:09:06 +0200 Subject: [PATCH] ftello tests: EBADF tests. * tests/test-ftello4.sh: New file. * tests/test-ftello4.c: New file. * modules/ftello-tests (Files): Add them. (Makefile.am): Arrange to compile test-ftello4 and run test-ftello4.sh. --- ChangeLog | 6 +++++ modules/ftello-tests | 6 +++-- tests/test-ftello4.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/test-ftello4.sh | 5 ++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 tests/test-ftello4.c create mode 100755 tests/test-ftello4.sh diff --git a/ChangeLog b/ChangeLog index 9054e98fd..c616f52e1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2011-09-20 Bruno Haible + ftello tests: EBADF tests. + * tests/test-ftello4.sh: New file. + * tests/test-ftello4.c: New file. + * modules/ftello-tests (Files): Add them. + (Makefile.am): Arrange to compile test-ftello4 and run test-ftello4.sh. + fseeko tests: EBADF tests. * tests/test-fseeko4.sh: New file. * tests/test-fseeko4.c: New file. diff --git a/modules/ftello-tests b/modules/ftello-tests index 2a668dadf..3c216d85a 100644 --- a/modules/ftello-tests +++ b/modules/ftello-tests @@ -3,6 +3,8 @@ tests/test-ftello.c tests/test-ftello.sh tests/test-ftello2.sh tests/test-ftello3.c +tests/test-ftello4.c +tests/test-ftello4.sh tests/signature.h tests/macros.h m4/ungetc.m4 @@ -14,6 +16,6 @@ configure.ac: gl_FUNC_UNGETC_WORKS Makefile.am: -TESTS += test-ftello.sh test-ftello2.sh test-ftello3 -check_PROGRAMS += test-ftello test-ftello3 +TESTS += test-ftello.sh test-ftello2.sh test-ftello3 test-ftello4.sh +check_PROGRAMS += test-ftello test-ftello3 test-ftello4 MOSTLYCLEANFILES += t-ftello3.tmp diff --git a/tests/test-ftello4.c b/tests/test-ftello4.c new file mode 100644 index 000000000..d503f7138 --- /dev/null +++ b/tests/test-ftello4.c @@ -0,0 +1,68 @@ +/* Test of ftello() function. + Copyright (C) 2011 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 . */ + +#include + +#include + +#include +#include + +#include "macros.h" + +int +main (int argc, char **argv) +{ + const char *filename = argv[1]; + + /* Test that ftello() sets errno if someone else closes the stream + fd behind the back of stdio. */ + { + FILE *fp = fopen (filename, "r"); + ASSERT (fp != NULL); + setvbuf (fp, NULL, _IONBF, 0); + ASSERT (close (fileno (fp)) == 0); + errno = 0; + ASSERT (ftello (fp) == (off_t)-1); + ASSERT (errno == EBADF); + fclose (fp); + } + + /* Test that ftello() sets errno if the stream was constructed with + an invalid file descriptor. */ + { + FILE *fp = fdopen (-1, "w"); + if (fp != NULL) + { + errno = 0; + ASSERT (ftello (fp) == (off_t)-1); + ASSERT (errno == EBADF); + fclose (fp); + } + } + { + FILE *fp = fdopen (99, "w"); + if (fp != NULL) + { + errno = 0; + ASSERT (ftello (fp) == (off_t)-1); + ASSERT (errno == EBADF); + fclose (fp); + } + } + + return 0; +} diff --git a/tests/test-ftello4.sh b/tests/test-ftello4.sh new file mode 100755 index 000000000..e3702bb60 --- /dev/null +++ b/tests/test-ftello4.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +./test-ftello4${EXEEXT} "$srcdir/test-ftello4.sh" || exit 1 + +exit 0 -- 2.11.0