diff options
Diffstat (limited to 'test/test_file.cpp')
-rw-r--r-- | test/test_file.cpp | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/test/test_file.cpp b/test/test_file.cpp index 9727e94..12cfb98 100644 --- a/test/test_file.cpp +++ b/test/test_file.cpp @@ -29,38 +29,27 @@ namespace fud { -auto rmFile(const auto& filename) -> int -{ - auto result = unlink(filename.c_str()); - if (result == -1) { - if (errno == ENOENT) { - return 0; - } - } - return result; -} - TEST(FudFile, Basic) { - constexpr const char* testDirCName = "/tmp/fud_directory_test"; - const auto testDirName{String::makeFromCString(testDirCName).takeOkay()}; + StringView testDirCName{StringView::makeFromCString("/tmp/fud_directory_test")}; + const auto testDirName{String::from(testDirCName).takeOkay()}; ASSERT_TRUE(testDirName.utf8Valid()); constexpr mode_t pathMode = 0777; - ASSERT_EQ(removeRecursive(testDirName), FudStatus::Success); + ASSERT_EQ(removeRecursive(testDirName.asView()), FudStatus::Success); - auto mkdirResult = mkdir(testDirName.c_str(), pathMode); + auto mkdirResult = mkdir(testDirCName.c_str(), pathMode); EXPECT_EQ(mkdirResult, 0); if (mkdirResult != 0) { - ASSERT_EQ(removeRecursive(testDirName), FudStatus::Success); + ASSERT_EQ(removeRecursive(testDirCName), FudStatus::Success); return; } - String testName1{String::makeFromCStrings(testDirCName, "/", "test1").takeOkay()}; - String testName2{String::makeFromCStrings(testDirCName, "/", "test2").takeOkay()}; + String testName1{String::makeFromCStrings(testDirCName.c_str(), "/", "test1").takeOkay()}; + String testName2{String::makeFromCStrings(testDirCName.c_str(), "/", "test2").takeOkay()}; - ASSERT_EQ(rmFile(testName1), 0); - ASSERT_EQ(rmFile(testName2), 0); + ASSERT_EQ(rmFile(testName1.asView()), 0); + ASSERT_EQ(rmFile(testName2.asView()), 0); auto fileResult{RegularFile::open(testName1.asView(), FileAccessMode::Read, OpenFlags{}, NullOpt)}; EXPECT_EQ(fileResult.takeErrorOr(FudStatus::Success), FudStatus::NotFound); @@ -83,8 +72,8 @@ TEST(FudFile, Basic) auto file{fileResult.takeOkay()}; ASSERT_EQ(file.close(), FudStatus::Success); - ASSERT_EQ(rmFile(testName1), 0); - ASSERT_GE(createFile(testName2), 0); + ASSERT_EQ(rmFile(testName1.asView()), 0); + ASSERT_GE(createFile(testName2.asView()), 0); ASSERT_EQ(symlink(testName2.c_str(), testName1.c_str()), 0); fileResult = RegularFile::open(testName2.asView(), FileAccessMode::Read, OpenFlags{}, NullOpt); @@ -99,9 +88,9 @@ TEST(FudFile, Basic) TEST(FudBufferedFile, OpenReadWrite) { - constexpr const char* testDirCName = "/tmp/fud_directory_test"; - const auto testDirName{String::makeFromCString(testDirCName).takeOkay()}; + StringView testDirName{StringView::makeFromCString("/tmp/fud_directory_test")}; ASSERT_TRUE(testDirName.utf8Valid()); + ASSERT_TRUE(testDirName.nullTerminated()); constexpr mode_t pathMode = 0777; ASSERT_EQ(removeRecursive(testDirName), FudStatus::Success); @@ -113,7 +102,7 @@ TEST(FudBufferedFile, OpenReadWrite) return; } - String testName{String::makeFromCStrings(testDirCName, "/", "test1").takeOkay()}; + String testName{String::makeFromCStrings(testDirName.c_str(), "/", "test1").takeOkay()}; auto fileResult{RegularFile::create( testName.asView(), FileAccessMode::ReadWrite, @@ -171,7 +160,7 @@ TEST(FudBufferedFile, OpenReadWrite) EXPECT_EQ(output[testName.size() - 1], testName.data()[testName.size() - 1]); EXPECT_EQ(bufferedFile.close(true), FudStatus::Success); - ASSERT_EQ(rmFile(testName), 0); + ASSERT_EQ(rmFile(testName.asView()), 0); } } // namespace fud |