| 88 | } |
| 89 | |
| 90 | TEST(PlatformFileSystemTest, ReadWriteOperations) { |
| 91 | // GTEST_SKIP() << "Temporarily skipped"; |
| 92 | const fs::path testdir = testing::TempDir(); |
| 93 | const fs::path filename = getUniqueTempFileName(); |
| 94 | const fs::path filepath = testdir / filename; |
| 95 | const std::string_view line1 = "Line1: This file contains some bytes."; |
| 96 | const std::string_view line2 = "Line2: This file contains more bytes."; |
| 97 | const std::string_view line3 = "Line3: This is the last line."; |
| 98 | |
| 99 | std::unique_ptr<TestFileSystem> fileSystem(new TestFileSystem(testdir)); |
| 100 | std::unique_ptr<SymbolTable> symbolTable(new SymbolTable); |
| 101 | |
| 102 | PathId fileId = fileSystem->toPathId(filepath.string(), symbolTable.get()); |
| 103 | |
| 104 | EXPECT_FALSE(fileSystem->exists(fileId)); |
| 105 | EXPECT_FALSE(fileSystem->isDirectory(fileId)); |
| 106 | EXPECT_FALSE(fileSystem->isRegularFile(fileId)); |
| 107 | |
| 108 | std::string content; |
| 109 | EXPECT_FALSE(fileSystem->readContent(fileId, content)); |
| 110 | |
| 111 | std::vector<std::string> lines; |
| 112 | EXPECT_FALSE(fileSystem->readLines(fileId, lines)); |
| 113 | |
| 114 | lines.emplace_back(line1); |
| 115 | lines.emplace_back(line2); |
| 116 | lines.emplace_back(line3); |
| 117 | EXPECT_TRUE(fileSystem->writeLines(fileId, lines)); |
| 118 | |
| 119 | EXPECT_TRUE(fileSystem->exists(fileId)); |
| 120 | EXPECT_FALSE(fileSystem->isDirectory(fileId)); |
| 121 | EXPECT_TRUE(fileSystem->isRegularFile(fileId)); |
| 122 | |
| 123 | std::string actualContent; |
| 124 | EXPECT_TRUE(fileSystem->readContent(fileId, actualContent)); |
| 125 | |
| 126 | const std::string expectedContent = |
| 127 | StrCat(line1, "\n", line2, "\n", line3, "\n"); |
| 128 | EXPECT_EQ(actualContent, expectedContent); |
| 129 | |
| 130 | std::vector<std::string> actualLines; |
| 131 | EXPECT_TRUE(fileSystem->readLines(fileId, actualLines)); |
| 132 | |
| 133 | const std::vector<std::string> &expectedLines = lines; |
| 134 | EXPECT_EQ(actualLines, expectedLines); |
| 135 | |
| 136 | for (size_t i = 0, n = expectedLines.size(); i < n; ++i) { |
| 137 | content.clear(); |
| 138 | EXPECT_TRUE(fileSystem->readLine(fileId, i + 1, content)); |
| 139 | EXPECT_EQ(content, expectedLines[i]); |
| 140 | } |
| 141 | content.clear(); |
| 142 | EXPECT_FALSE(fileSystem->readLine(fileId, expectedLines.size() + 1, content)); |
| 143 | } |
| 144 | |
| 145 | TEST(PlatformFileSystemTest, LoadSaveOperations) { |
| 146 | // GTEST_SKIP() << "Temporarily skipped"; |
nothing calls this directly
no test coverage detected