Browse Source

Tested DirectoryReference on Windows, implemented FilePath::join().


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

+ 65
- 5
TestFilesystem/testFilesystem.cpp View File

// Tests /////////////////////////////////////////////////////////////////////// // 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) { long createTestFile(std::string fileName) {
std::ofstream out(fileName.c_str()); std::ofstream out(fileName.c_str());
std::string contents = "Content"; std::string contents = "Content";
bool testDirectoryReferenceFiles() { bool testDirectoryReferenceFiles() {
char const dirSep = CodeDweller::FilePath::DirectorySeparator;
std::unordered_set<std::string> fileNames; 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(filteredFileName);
fileNames.emplace(testDirName + "/f2.txt");
fileNames.emplace(testDirName + "/f3.txt");
fileNames.emplace(testDirName + dirSep + "f2.txt");
fileNames.emplace(testDirName + dirSep + "f3.txt");
try { try {
return false; return false;
} }
#if 0
for (auto &name : fileNames) { for (auto &name : fileNames) {
std::remove(name.c_str()); std::remove(name.c_str());
} }
#endif
return true; return true;
} }
{ {
std::cout << "CodeDweller::Filesystem unit tests" << std::endl << std::endl; std::cout << "CodeDweller::Filesystem unit tests" << std::endl << std::endl;
RUN_TEST(testFilePathJoin);
RUN_TEST(testFileReferenceFile); RUN_TEST(testFileReferenceFile);
RUN_TEST(testFileReferenceNoFile); RUN_TEST(testFileReferenceNoFile);
RUN_TEST(testFileReferenceDir); RUN_TEST(testFileReferenceDir);

Loading…
Cancel
Save