test-pread: cover failure with ESPIPE and EINVAL
authorJim Meyering <meyering@redhat.com>
Wed, 25 Nov 2009 17:26:35 +0000 (18:26 +0100)
committerJim Meyering <meyering@redhat.com>
Wed, 25 Nov 2009 17:26:35 +0000 (18:26 +0100)
* tests/test-pread.c (main): Test for failure, too.
* tests/test-pread.sh: Invoke with stdin on a pipe.
Suggested by Eric Blake.

ChangeLog
tests/test-pread.c
tests/test-pread.sh

index 2e5f9fbe61f2f92f8533e8f841393236969d53d5..2ec9906c436dab316c96a541f07e95c39c8fe131 100644 (file)
--- 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.
index cf4179f32f73070e79efb9750603f4f6184edec6..fd5db8e8a159406e11ac51648314749e1b69a796 100644 (file)
@@ -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 @@ main (void)
        }
     }
 
+  {
+    /* 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;
 }
index 98971a4c58cebab3ec9303450642cba8493e4030..5ab88eb6ffe343529ded45acddd6b203896e88a1 100755 (executable)
@@ -3,6 +3,6 @@
 . $srcdir/init.sh --set-path=.
 
 fail=0;
-test-pread || fail=1
+echo abc | test-pread || fail=1
 
 Exit $fail