|
|
@@ -61,6 +61,63 @@ bool result; |
|
|
|
// Tests ///////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool testFilePathJoin() {
|
|
|
|
|
|
|
|
char const dirSep = CodeDweller::FilePath::DirectorySeparator;
|
|
|
|
std::vector<std::string> comp0 = {"comp0", "comp1", "comp2"};
|
|
|
|
std::string expectedComp;
|
|
|
|
|
|
|
|
// Test normal joining.
|
|
|
|
for (auto &comp : comp0) {
|
|
|
|
expectedComp += comp + dirSep;
|
|
|
|
}
|
|
|
|
expectedComp.pop_back();
|
|
|
|
|
|
|
|
if (expectedComp !=
|
|
|
|
CodeDweller::FilePath::join({comp0[0], comp0[1], comp0[2]})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test null component.
|
|
|
|
if (expectedComp !=
|
|
|
|
CodeDweller::FilePath::join({comp0[0], comp0[1], "", comp0[2]})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedComp !=
|
|
|
|
CodeDweller::FilePath::join({"", comp0[0], comp0[1], "", comp0[2]})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedComp !=
|
|
|
|
CodeDweller::FilePath::join({"", comp0[0], comp0[1], "", comp0[2], ""})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test single input.
|
|
|
|
expectedComp = "test";
|
|
|
|
if (expectedComp != CodeDweller::FilePath::join({expectedComp})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedComp != CodeDweller::FilePath::join({"", expectedComp})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedComp != CodeDweller::FilePath::join({"", expectedComp, ""})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedComp != CodeDweller::FilePath::join({"", expectedComp, "", ""})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedComp != CodeDweller::FilePath::join({"", "", expectedComp, ""})) {
|
|
|
|
RETURN_FALSE("join() failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
long createTestFile(std::string fileName) {
|
|
|
|
std::ofstream out(fileName.c_str());
|
|
|
|
std::string contents = "Content";
|
|
|
@@ -239,13 +296,14 @@ bool filter(std::string name) { |
|
|
|
|
|
|
|
bool testDirectoryReferenceFiles() {
|
|
|
|
|
|
|
|
char const dirSep = CodeDweller::FilePath::DirectorySeparator;
|
|
|
|
std::unordered_set<std::string> fileNames;
|
|
|
|
std::string filteredFileName = testDirName + "/f1.txt";
|
|
|
|
std::string filteredFileName = testDirName + dirSep + "f1.txt";
|
|
|
|
|
|
|
|
fileNames.emplace(testDirName + "/" + testFileName);
|
|
|
|
fileNames.emplace(testDirName + dirSep + testFileName);
|
|
|
|
fileNames.emplace(filteredFileName);
|
|
|
|
fileNames.emplace(testDirName + "/f2.txt");
|
|
|
|
fileNames.emplace(testDirName + "/f3.txt");
|
|
|
|
fileNames.emplace(testDirName + dirSep + "f2.txt");
|
|
|
|
fileNames.emplace(testDirName + dirSep + "f3.txt");
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
@@ -315,10 +373,11 @@ bool testDirectoryReferenceFiles() { |
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
for (auto &name : fileNames) {
|
|
|
|
std::remove(name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
@@ -348,6 +407,7 @@ int main() |
|
|
|
{
|
|
|
|
std::cout << "CodeDweller::Filesystem unit tests" << std::endl << std::endl;
|
|
|
|
|
|
|
|
RUN_TEST(testFilePathJoin);
|
|
|
|
RUN_TEST(testFileReferenceFile);
|
|
|
|
RUN_TEST(testFileReferenceNoFile);
|
|
|
|
RUN_TEST(testFileReferenceDir);
|