# HG changeset patch # User Bruno Haible # Date 1316552851 -7200 # Node ID afb8fd88097634257bc4eefc60b51fc447dae11d # Parent 21f71993f3db981ef21196bd994872311ecdc7aa fseeko tests: EBADF tests. * tests/test-fseeko4.sh: New file. * tests/test-fseeko4.c: New file. * modules/fseeko-tests (Files): Add them. (Makefile.am): Arrange to compile test-fseeko4 and run test-fseeko4.sh. diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2011-09-20 Bruno Haible + fseeko tests: EBADF tests. + * tests/test-fseeko4.sh: New file. + * tests/test-fseeko4.c: New file. + * modules/fseeko-tests (Files): Add them. + (Makefile.am): Arrange to compile test-fseeko4 and run test-fseeko4.sh. + Tests for function fputc(). * modules/fputc-tests: New file. * tests/test-fputc.c: New file. diff --git a/modules/fseeko-tests b/modules/fseeko-tests --- a/modules/fseeko-tests +++ b/modules/fseeko-tests @@ -4,6 +4,8 @@ tests/test-fseeko2.sh tests/test-fseeko3.c tests/test-fseeko3.sh +tests/test-fseeko4.c +tests/test-fseeko4.sh tests/signature.h tests/macros.h m4/ungetc.m4 @@ -14,5 +16,5 @@ gl_FUNC_UNGETC_WORKS Makefile.am: -TESTS += test-fseeko.sh test-fseeko2.sh test-fseeko3.sh -check_PROGRAMS += test-fseeko test-fseeko3 +TESTS += test-fseeko.sh test-fseeko2.sh test-fseeko3.sh test-fseeko4.sh +check_PROGRAMS += test-fseeko test-fseeko3 test-fseeko4 diff --git a/tests/test-fseeko4.c b/tests/test-fseeko4.c new file mode 100644 --- /dev/null +++ b/tests/test-fseeko4.c @@ -0,0 +1,71 @@ +/* Test of fseeko() 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 fseeko() 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 (ftell (fp) == 0); + ASSERT (fseeko (fp, 0, SEEK_END) == 0); + ASSERT (ftell (fp) > 0); + ASSERT (close (fileno (fp)) == 0); + errno = 0; + ASSERT (fseeko (fp, 0, SEEK_SET) == -1); + ASSERT (errno == EBADF); + fclose (fp); + } + + /* Test that fseeko() sets errno if the stream was constructed with + an invalid file descriptor. */ + { + FILE *fp = fdopen (-1, "w"); + if (fp != NULL) + { + errno = 0; + ASSERT (fseeko (fp, 0, SEEK_END) == -1); + ASSERT (errno == EBADF); + fclose (fp); + } + } + { + FILE *fp = fdopen (99, "w"); + if (fp != NULL) + { + errno = 0; + ASSERT (fseeko (fp, 0, SEEK_END) == -1); + ASSERT (errno == EBADF); + fclose (fp); + } + } + + return 0; +} diff --git a/tests/test-fseeko4.sh b/tests/test-fseeko4.sh new file mode 100755 --- /dev/null +++ b/tests/test-fseeko4.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +./test-fseeko4${EXEEXT} "$srcdir/test-fseeko4.sh" || exit 1 + +exit 0