Browse Source

Tested FileOps::moveFile under Linux.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@50 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz 9 years ago
parent
commit
2a871c49d9
2 changed files with 67 additions and 1 deletions
  1. 9
    1
      TestFilesystem/buildAndRun
  2. 58
    0
      TestFilesystem/testFilesystem.cpp

+ 9
- 1
TestFilesystem/buildAndRun View File

CFLAGS='-I.. -std=c++11 -g -O0' CFLAGS='-I.. -std=c++11 -g -O0'
g++ $CFLAGS testFilesystem.cpp ../CodeDweller/filesystem.cpp -lShlwapi -o testFilesystem

if [ "$(uname --operating-system)" == "Msys" ]
then
LDFLAGS=-lShlwapi
else
LDFLAGS=
fi

g++ $CFLAGS testFilesystem.cpp ../CodeDweller/filesystem.cpp $LDFLAGS -o testFilesystem
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
exit -1 exit -1

+ 58
- 0
TestFilesystem/testFilesystem.cpp View File

// 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);

Loading…
Cancel
Save