Mercurial > hg > octave-lojdl > gnulib-hg
changeset 12363:6fe970af0447
test-pread: cover failure with ESPIPE and EINVAL
* tests/test-pread.c (main): Test for failure, too.
* tests/test-pread.sh: Invoke with stdin on a pipe.
Suggested by Eric Blake.
author | Jim Meyering <meyering@redhat.com> |
---|---|
date | Wed, 25 Nov 2009 18:26:35 +0100 |
parents | 7d728682ee08 |
children | ed32b5a7bd26 |
files | ChangeLog tests/test-pread.c tests/test-pread.sh |
diffstat | 3 files changed, 22 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2009-11-25 Jim Meyering <meyering@redhat.com> + test-pread: cover failure with ESPIPE and EINVAL + * tests/test-pread.c (main): Test for failure, too. + * tests/test-pread.sh: Invoke with stdin on a pipe. + Suggested by Eric Blake. + pread: improvement and fix * modules/pread (Depends-on): Depend on lseek, for portability to e.g., mingw. Suggested by Eric Blake.
--- a/tests/test-pread.c +++ b/tests/test-pread.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include <sys/types.h> #include <fcntl.h> +#include <errno.h> #define ASSERT(expr) \ do \ @@ -72,7 +73,22 @@ } } + { + /* Invalid offset must evoke failure with EINVAL. */ + char byte; + ASSERT (pread (fd, &byte, 1, (off_t) -1) == -1); + ASSERT (errno == EINVAL); + } + ASSERT (close (fd) == 0); + { + char byte; + /* Trying to operate on a pipe must evoke failure with ESPIPE. + This assumes that stdin is a pipe, and hence not seekable. */ + ASSERT (pread (STDIN_FILENO, &byte, 1, 1) == -1); + ASSERT (errno == ESPIPE); + } + return 0; }