summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-01-21 18:35:18 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-01-21 18:35:18 +0000
commit8d6e19408cfdbd73ba7e5c9e5b8716d9dad8dcf9 (patch)
treeef7af9617a914cf7d85678540013135d320971a5 /tests/stdio_test.cpp
parentbe4f7429ca66d0652f31fc78fd88de5ee958f890 (diff)
parent2704bd13409a77237147f861c43796148326b2e3 (diff)
Merge "Simplify fseek/ftell."
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index d054bf59d..31acfec90 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1068,3 +1068,28 @@ TEST(STDIO_TEST, fclose_invalidates_fd) {
ASSERT_EQ(-1, fileno(stdin));
ASSERT_EQ(EBADF, errno);
}
+
+TEST(STDIO_TEST, fseek_ftell_unseekable) {
+#if defined(__BIONIC__) // glibc has fopencookie instead.
+ auto read_fn = [](void*, char*, int) { return -1; };
+ FILE* fp = funopen(nullptr, read_fn, nullptr, nullptr, nullptr);
+ ASSERT_TRUE(fp != nullptr);
+
+ // Check that ftell balks on an unseekable FILE*.
+ errno = 0;
+ ASSERT_EQ(-1, ftell(fp));
+ ASSERT_EQ(ESPIPE, errno);
+
+ // SEEK_CUR is rewritten as SEEK_SET internally...
+ errno = 0;
+ ASSERT_EQ(-1, fseek(fp, 0, SEEK_CUR));
+ ASSERT_EQ(ESPIPE, errno);
+
+ // ...so it's worth testing the direct seek path too.
+ errno = 0;
+ ASSERT_EQ(-1, fseek(fp, 0, SEEK_SET));
+ ASSERT_EQ(ESPIPE, errno);
+
+ fclose(fp);
+#endif
+}