Browse Source

Tested DirectoryReference.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@33 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz 10 years ago
parent
commit
ae26e0f408
1 changed files with 117 additions and 7 deletions
  1. 117
    7
      TestFilesystem/testFilesystem.cpp

+ 117
- 7
TestFilesystem/testFilesystem.cpp View File

#include <string> #include <string>
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include <unordered_set>
#include "CodeDweller/filesystem.hpp" #include "CodeDweller/filesystem.hpp"
return contents.size(); return contents.size();
} }
bool
testFileReferenceFile() {
bool testFileReferenceFile() {
try { try {
} }
bool
testFileReferenceNoFile() {
bool testFileReferenceNoFile() {
try { try {
} }
bool
testFileReferenceDir() {
bool testFileReferenceDir() {
try { try {
} }
// 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 //////////////////////////////////////////////////////////////// // End of tests ////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
RUN_TEST(testFileReferenceFile); RUN_TEST(testFileReferenceFile);
RUN_TEST(testFileReferenceNoFile); RUN_TEST(testFileReferenceNoFile);
RUN_TEST(testFileReferenceDir); RUN_TEST(testFileReferenceDir);
RUN_TEST(testDirectoryReferenceFiles);
RUN_TEST(testDirectoryReferenceNoDir);
SUMMARY; SUMMARY;
return 0; return 0;

Loading…
Cancel
Save