|
|
@@ -5,6 +5,7 @@ |
|
|
|
#include <string>
|
|
|
|
#include <chrono>
|
|
|
|
#include <thread>
|
|
|
|
#include <unordered_set>
|
|
|
|
|
|
|
|
#include "CodeDweller/filesystem.hpp"
|
|
|
|
|
|
|
@@ -69,8 +70,7 @@ long createTestFile(std::string fileName) { |
|
|
|
return contents.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
testFileReferenceFile() {
|
|
|
|
bool testFileReferenceFile() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
@@ -118,8 +118,7 @@ testFileReferenceFile() { |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
testFileReferenceNoFile() {
|
|
|
|
bool testFileReferenceNoFile() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
@@ -181,8 +180,7 @@ testFileReferenceNoFile() { |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
testFileReferenceDir() {
|
|
|
|
bool testFileReferenceDir() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
@@ -231,6 +229,117 @@ testFileReferenceDir() { |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter for files whose name contains "f1".
|
|
|
|
bool filter(std::string name) {
|
|
|
|
if (name.find("f1") != std::string::npos) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool testDirectoryReferenceFiles() {
|
|
|
|
|
|
|
|
std::unordered_set<std::string> fileNames;
|
|
|
|
std::string filteredFileName = testDirName + "/f1.txt";
|
|
|
|
|
|
|
|
fileNames.emplace(testDirName + "/" + testFileName);
|
|
|
|
fileNames.emplace(filteredFileName);
|
|
|
|
fileNames.emplace(testDirName + "/f2.txt");
|
|
|
|
fileNames.emplace(testDirName + "/f3.txt");
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
for (auto &name : fileNames) {
|
|
|
|
std::remove(name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeDweller::DirectoryReference dirRef(testDirName);
|
|
|
|
|
|
|
|
if (dirRef.size() != 2) {
|
|
|
|
RETURN_FALSE("Incorrect number of files were found by "
|
|
|
|
"DirectoryReference");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &name : fileNames) {
|
|
|
|
(void) createTestFile(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
dirRef.refresh();
|
|
|
|
|
|
|
|
for (auto &name : fileNames) {
|
|
|
|
|
|
|
|
bool foundFile;
|
|
|
|
|
|
|
|
foundFile = false;
|
|
|
|
|
|
|
|
for (auto &fileRef : dirRef) {
|
|
|
|
if (fileRef.FullPath().find(name) != std::string::npos) {
|
|
|
|
foundFile = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundFile) {
|
|
|
|
RETURN_FALSE("Not all files were found by DirectoryReference");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirRef.size() != fileNames.size() + 2) {
|
|
|
|
RETURN_FALSE("Incorrect number of files were found by "
|
|
|
|
"DirectoryReference");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeDweller::DirectoryReference dirRefFilter(testDirName, filter);
|
|
|
|
|
|
|
|
bool foundFile = false;
|
|
|
|
for (auto &fileRef : dirRefFilter) {
|
|
|
|
if (fileRef.FullPath().find(filteredFileName) != std::string::npos) {
|
|
|
|
foundFile = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!foundFile) {
|
|
|
|
RETURN_FALSE("Filtered file was not found by DirectoryReference");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirRefFilter.size() != 3) {
|
|
|
|
RETURN_FALSE("Incorrect number of filtered files were found by "
|
|
|
|
"DirectoryReference");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
EXCEPTION_TERM("FileReference()");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &name : fileNames) {
|
|
|
|
std::remove(name.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool testDirectoryReferenceNoDir() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
CodeDweller::DirectoryReference dirRef("Doesntexist");
|
|
|
|
|
|
|
|
NO_EXCEPTION_TERM("DirectoryReference with non-existant directory");
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// End of tests ////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
@@ -242,7 +351,8 @@ int main() |
|
|
|
RUN_TEST(testFileReferenceFile);
|
|
|
|
RUN_TEST(testFileReferenceNoFile);
|
|
|
|
RUN_TEST(testFileReferenceDir);
|
|
|
|
|
|
|
|
RUN_TEST(testDirectoryReferenceFiles);
|
|
|
|
RUN_TEST(testDirectoryReferenceNoDir);
|
|
|
|
SUMMARY;
|
|
|
|
|
|
|
|
return 0;
|