summaryrefslogtreecommitdiff
path: root/tests/stdio_test.cpp
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-01-20 11:23:50 -0800
committerElliott Hughes <enh@google.com>2015-01-20 15:59:17 -0800
commit75b99387dd3a8833f09e2139e7062be5d38c5511 (patch)
tree7b4c44035fd12bbfb6a9de3f22fdc95aca57cb9f /tests/stdio_test.cpp
parent3bbf4639080bc2f42435b4a7fd400c44aab7fd70 (diff)
Optimized fread.
This makes us competitive with glibc for fully-buffered and unbuffered reads, except in single-threaded situations where glibc avoids locking, but since we're never really single-threaded anyway, that isn't a priority. Bug: 18593728 Change-Id: Ib776bfba422ccf46209581fc0dc54f3567645b8f
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r--tests/stdio_test.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index de5eea347..6d7e72bc2 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -888,3 +888,25 @@ TEST(stdio, fread_unbuffered_pathological_performance) {
ASSERT_EQ('\xff', buf[i]);
}
}
+
+TEST(fread, fread_EOF) {
+ const char* digits = "0123456789";
+ FILE* fp = fmemopen((char*) digits, sizeof(digits), "r");
+
+ // Try to read too much, but little enough that it still fits in the FILE's internal buffer.
+ char buf1[4 * 4];
+ memset(buf1, 0, sizeof(buf1));
+ ASSERT_EQ(2U, fread(buf1, 4, 4, fp));
+ ASSERT_STREQ(buf1, "01234567");
+ ASSERT_TRUE(feof(fp));
+
+ rewind(fp);
+
+ char buf2[4 * 4];
+ memset(buf2, 0, sizeof(buf2));
+ ASSERT_EQ(2U, fread(buf2, 4, 4096, fp));
+ ASSERT_STREQ(buf2, "01234567");
+ ASSERT_TRUE(feof(fp));
+
+ fclose(fp);
+}