Skip to content

Commit b3f9c7a

Browse files
author
codefaber
committed
[libc] Implement test case for copy/paste error in file.cpp
1 parent 268d890 commit b3f9c7a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

libc/test/src/__support/File/file_test.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,3 +493,22 @@ TEST(LlvmLibcFileTest, WriteNothing) {
493493
ASSERT_EQ(f_lbf->close(), 0);
494494
ASSERT_EQ(f_nbf->close(), 0);
495495
}
496+
497+
TEST(LlvmLibcFileTest, WriteSplit)
498+
{
499+
constexpr size_t FILE_BUFFER_SIZE = 8;
500+
char file_buffer[FILE_BUFFER_SIZE];
501+
StringFile *f =
502+
new_string_file(file_buffer, FILE_BUFFER_SIZE, _IOFBF, false, "w");
503+
504+
static constexpr size_t AVAIL = 12;
505+
f->seek(-AVAIL, SEEK_END);
506+
507+
const char data[] = "hello";
508+
ASSERT_EQ(sizeof(data) - 1, f->write(data, sizeof(data) - 1).value);
509+
510+
const char data2[] = " extra data";
511+
static constexpr size_t WR_EXPECTED = AVAIL - (sizeof(data) - 1);
512+
ASSERT_EQ(WR_EXPECTED, f->write(data2, sizeof(data2) - 1).value);
513+
EXPECT_TRUE(f->error());
514+
}

0 commit comments

Comments
 (0)