14 static void createFile(
const std::string
filename,
const std::string content)
20 static std::vector<std::string> readLines(
const std::string&
filename)
22 std::vector<std::string> result;
25 while (std::getline(is, line)) {
26 result.push_back(line);
36 createFile(tmp +
"/a",
"aaa");
37 createFile(tmp +
"/a2",
"aaa");
38 createFile(tmp +
"/b",
"bbb");
40 auto getDirectories = [&] {
50 [](std::string_view) { });
55 CHECK(file.is_open());
56 CHECK(file.getURL() ==
one_of(tmp +
"/a", tmp +
"/a2"));
61 CHECK(!file.is_open());
66 CHECK(file.is_open());
67 CHECK(file.getURL() == tmp +
"/b");
70 createFile(tmp +
"/c",
"ccc");
73 CHECK(file.is_open());
74 CHECK(file.getURL() == tmp +
"/c");
79 createFile(tmp +
"/b",
"BBB");
82 CHECK(!file1.is_open());
84 CHECK(file2.is_open());
85 CHECK(file2.getURL() == tmp +
"/b");
90 createFile(tmp +
"/b",
"BBB");
93 CHECK(file.is_open());
94 CHECK(file.getURL() == tmp +
"/b");
100 CHECK(!file.is_open());
105 File file(tmp +
"/a2");
107 auto sum = pool.getSha1Sum(file);
111 createFile(tmp +
"/e",
"eee");
113 File file(tmp +
"/e");
115 auto sum = pool.getSha1Sum(file);
121 auto lines = readLines(tmp +
"/cache");
122 CHECK(lines.size() == 4);
TEST_CASE("FilePoolCore")
File getFile(FileType fileType, const Sha1Sum &sha1sum)
Search file with the given sha1sum.
std::vector< Dir > Directories
bool is_open() const
Return true iff this file handle refers to an open file.
This class represents the result of a sha1 calculation (a 160-bit value).
bool endsWith(string_view total, string_view part)
bool startsWith(string_view total, string_view part)
string getTempDir()
Get the name of the temp directory on the system.
int deleteRecursive(zstring_view path)
Recursively delete a file or directory and (in case of a directory) all its sub-components.
void mkdirp(string path)
Acts like the unix command "mkdir -p".
int unlink(zstring_view path)
Call unlink() in a platform-independent manner.
void sleep(uint64_t us)
Sleep for the specified amount of time (in us).
This file implemented 3 utility functions:
constexpr const char *const filename
auto sum(InputRange &&range)