MCPcopy Create free account
hub / github.com/chipsalliance/Surelog / TEST

Function TEST

src/Common/PlatformFileSystem_test.cpp:90–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88}
89
90TEST(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
145TEST(PlatformFileSystemTest, LoadSaveOperations) {
146 // GTEST_SKIP() << "Temporarily skipped";

Callers

nothing calls this directly

Calls 15

getUniqueTempFileNameFunction · 0.85
StrCatFunction · 0.85
transformFunction · 0.85
PathIdPPClass · 0.85
toPathIdMethod · 0.80
readContentMethod · 0.80
readLinesMethod · 0.80
writeLinesMethod · 0.80
clearMethod · 0.80
readLineMethod · 0.80
loadContentMethod · 0.80
writeContentMethod · 0.80

Tested by

no test coverage detected