Browse Source

Tested DirectoryReference.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@33 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz 9 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

@@ -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;

Loading…
Cancel
Save