diff options
| author | Elliott Hughes <enh@google.com> | 2016-01-21 18:35:18 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2016-01-21 18:35:18 +0000 |
| commit | 8d6e19408cfdbd73ba7e5c9e5b8716d9dad8dcf9 (patch) | |
| tree | ef7af9617a914cf7d85678540013135d320971a5 /tests/stdio_test.cpp | |
| parent | be4f7429ca66d0652f31fc78fd88de5ee958f890 (diff) | |
| parent | 2704bd13409a77237147f861c43796148326b2e3 (diff) | |
Merge "Simplify fseek/ftell."
Diffstat (limited to 'tests/stdio_test.cpp')
| -rw-r--r-- | tests/stdio_test.cpp | 25 |
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 +} |
