summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/test_file.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/test/test_file.cpp b/test/test_file.cpp
index 62df1ae..9727e94 100644
--- a/test/test_file.cpp
+++ b/test/test_file.cpp
@@ -143,15 +143,33 @@ TEST(FudBufferedFile, OpenReadWrite)
ASSERT_EQ(bufferedFile.seekStart(), FudStatus::Success);
Vector<utf8> output{Vector<utf8>::withSize(testName.size()).takeOkay()};
- auto readResult = bufferedFile.read(
- reinterpret_cast<std::byte*>(output.data()),
- testName.size(),
- testName.size());
+ auto readResult = bufferedFile.read(reinterpret_cast<std::byte*>(output.data()), testName.size(), NullOpt);
ASSERT_EQ(readResult, expected);
-
+
EXPECT_EQ(output.size(), testName.size());
EXPECT_EQ(0, compareMem(output.data(), output.size(), testName.data(), testName.size()).takeOkayOr(-1));
+ ASSERT_EQ(bufferedFile.flush(), nullExpected);
+ ASSERT_EQ(bufferedFile.seekStart(), FudStatus::Success);
+
+ expected.bytesDrained = 1;
+ readResult = bufferedFile.read(reinterpret_cast<std::byte*>(output.data()), 1, NullOpt);
+ ASSERT_EQ(readResult, expected);
+ EXPECT_EQ(output[0], testName.data()[0]);
+
+ expected.bytesDrained = testName.size() - 2;
+ readResult = bufferedFile.read(reinterpret_cast<std::byte*>(output.data()) + 1, testName.size() - 2, NullOpt);
+ ASSERT_EQ(readResult, expected);
+ EXPECT_EQ(
+ 0,
+ compareMem(output.data() + 1, output.size() - 1, testName.data() + 1, testName.size() - 2).takeOkayOr(-1));
+
+ expected.bytesDrained = 1;
+ readResult = bufferedFile.read(reinterpret_cast<std::byte*>(output.data()), 1, NullOpt);
+
+ EXPECT_TRUE(readResult.status == FudStatus::Success || readResult.status == FudStatus::Partial);
+ EXPECT_EQ(output[testName.size() - 1], testName.data()[testName.size() - 1]);
+
EXPECT_EQ(bufferedFile.close(true), FudStatus::Success);
ASSERT_EQ(rmFile(testName), 0);
}