diff options
author | Michael Jones <michaelrj@google.com> | 2022-09-20 16:58:05 -0700 |
---|---|---|
committer | Michael Jones <michaelrj@google.com> | 2022-09-21 11:10:20 -0700 |
commit | a9e0dbefdd1ae5d46ae4a462d71d6352d2f1c105 (patch) | |
tree | f8878a39b91bd09fb55b3b83f0d4262443fe9c87 /libc/test/src/stdio/fileop_test.cpp | |
parent | f40266603e56d02d678604ace508024e0fc51b50 (diff) | |
download | llvm-a9e0dbefdd1ae5d46ae4a462d71d6352d2f1c105.zip llvm-a9e0dbefdd1ae5d46ae4a462d71d6352d2f1c105.tar.gz llvm-a9e0dbefdd1ae5d46ae4a462d71d6352d2f1c105.tar.bz2 |
[libc] add fputs and puts
add fputs, puts, and the EOF macro that they use.
Reviewed By: sivachandra
Differential Revision: https://reviews.llvm.org/D134328
Diffstat (limited to 'libc/test/src/stdio/fileop_test.cpp')
-rw-r--r-- | libc/test/src/stdio/fileop_test.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp index ab98fa5..399cc79 100644 --- a/libc/test/src/stdio/fileop_test.cpp +++ b/libc/test/src/stdio/fileop_test.cpp @@ -12,6 +12,7 @@ #include "src/stdio/ferror.h" #include "src/stdio/fflush.h" #include "src/stdio/fopen.h" +#include "src/stdio/fputs.h" #include "src/stdio/fread.h" #include "src/stdio/fseek.h" #include "src/stdio/fwrite.h" @@ -67,8 +68,37 @@ TEST(LlvmLibcFILETest, SimpleFileOperations) { errno = 0; __llvm_libc::clearerr(file); + + // Should be an error to puts. + ASSERT_EQ(EOF, __llvm_libc::fputs(CONTENT, file)); + ASSERT_NE(__llvm_libc::ferror(file), 0); + ASSERT_NE(errno, 0); + errno = 0; + + __llvm_libc::clearerr(file); + ASSERT_EQ(__llvm_libc::ferror(file), 0); + + ASSERT_EQ(__llvm_libc::fclose(file), 0); + + // Now try puts. + file = __llvm_libc::fopen(FILENAME, "w"); + ASSERT_FALSE(file == nullptr); + // fputs returns a negative value on error (EOF) or any non-negative value on + // success. This assert checks that the return value is non-negative. + ASSERT_GE(__llvm_libc::fputs(CONTENT, file), 0); + + __llvm_libc::clearerr(file); ASSERT_EQ(__llvm_libc::ferror(file), 0); + ASSERT_EQ(0, __llvm_libc::fclose(file)); + + file = __llvm_libc::fopen(FILENAME, "r"); + ASSERT_FALSE(file == nullptr); + + ASSERT_EQ(__llvm_libc::fread(read_data, 1, sizeof(CONTENT) - 1, file), + sizeof(CONTENT) - 1); + read_data[sizeof(CONTENT) - 1] = '\0'; + ASSERT_STREQ(read_data, CONTENT); ASSERT_EQ(__llvm_libc::fclose(file), 0); } |