|
|
|
|
|
|
|
|
// Tests ///////////////////////////////////////////////////////////////////////
|
|
|
// Tests ///////////////////////////////////////////////////////////////////////
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
bool testFileOpsMoveFile() {
|
|
|
|
|
|
|
|
|
|
|
|
std::string fromName = "from.txt";
|
|
|
|
|
|
std::string toName = "to.txt";
|
|
|
|
|
|
std::string const expectedContent = "fileContentForMoveTest";
|
|
|
|
|
|
std::string content;
|
|
|
|
|
|
|
|
|
|
|
|
// Test nominal case.
|
|
|
|
|
|
std::ofstream out(fromName.c_str());
|
|
|
|
|
|
out << expectedContent;
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
|
|
CodeDweller::FileOps::moveFile(fromName, toName);
|
|
|
|
|
|
|
|
|
|
|
|
std::ifstream in(toName.c_str());
|
|
|
|
|
|
in >> content;
|
|
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
|
|
|
|
if (expectedContent != content) {
|
|
|
|
|
|
RETURN_FALSE("FileOps::moveFile() failure");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test moving to a file that exists.
|
|
|
|
|
|
out.open(fromName.c_str());
|
|
|
|
|
|
out << expectedContent;
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
|
|
out.open(toName.c_str());
|
|
|
|
|
|
out << "not" + expectedContent;
|
|
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
|
|
|
|
CodeDweller::FileOps::moveFile(fromName, toName);
|
|
|
|
|
|
|
|
|
|
|
|
in.open(toName.c_str());
|
|
|
|
|
|
in >> content;
|
|
|
|
|
|
in.close();
|
|
|
|
|
|
|
|
|
|
|
|
if (expectedContent != content) {
|
|
|
|
|
|
RETURN_FALSE("FileOps::moveFile() failure");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test moving file that doesn't exist.
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
(void) CodeDweller::FileOps::moveFile("doesNotExist", "alsoDoesNotExist");
|
|
|
|
|
|
|
|
|
|
|
|
NO_EXCEPTION_TERM("FileOps::moveFile()");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
bool testFilePathIsAbsolute() {
|
|
|
bool testFilePathIsAbsolute() {
|
|
|
|
|
|
|
|
|
char const dirSep = CodeDweller::FilePath::DirectorySeparator;
|
|
|
char const dirSep = CodeDweller::FilePath::DirectorySeparator;
|
|
|
|
|
|
|
|
|
{
|
|
|
{
|
|
|
std::cout << "CodeDweller::Filesystem unit tests" << std::endl << std::endl;
|
|
|
std::cout << "CodeDweller::Filesystem unit tests" << std::endl << std::endl;
|
|
|
|
|
|
|
|
|
|
|
|
RUN_TEST(testFileOpsMoveFile);
|
|
|
RUN_TEST(testFilePathIsAbsolute);
|
|
|
RUN_TEST(testFilePathIsAbsolute);
|
|
|
RUN_TEST(testFilePathJoin);
|
|
|
RUN_TEST(testFilePathJoin);
|
|
|
RUN_TEST(testFileReferenceFile);
|
|
|
RUN_TEST(testFileReferenceFile);
|