Add tests for stdio functions not setting the error indicator.
From https://reviews.llvm.org/D150044#4597254.
Bug: http://b/302742247
Test: treehugger
Change-Id: I001e7a995aabef37bdcdb53791c4af36c77d7b57
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index bfe8406..5cb634c 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -2153,6 +2153,27 @@
test_fread_from_write_only_stream(64*1024);
}
+TEST(STDIO_TEST, fwrite_to_read_only_stream) {
+ FILE* fp = fopen("/proc/version", "re");
+ ASSERT_FALSE(ferror(fp));
+ ASSERT_EQ(0U, fwrite("hello", 1, 5, fp));
+ ASSERT_TRUE(ferror(fp));
+}
+
+TEST(STDIO_TEST, fputc_to_read_only_stream) {
+ FILE* fp = fopen("/proc/version", "re");
+ ASSERT_FALSE(ferror(fp));
+ ASSERT_EQ(EOF, fputc('x', fp));
+ ASSERT_TRUE(ferror(fp));
+}
+
+TEST(STDIO_TEST, fprintf_to_read_only_stream) {
+ FILE* fp = fopen("/proc/version", "re");
+ ASSERT_FALSE(ferror(fp));
+ ASSERT_EQ(-1, fprintf(fp, "%s%d", "hello", 123));
+ ASSERT_TRUE(ferror(fp));
+}
+
static void test_fwrite_after_fread(size_t n) {
TemporaryFile tf;