Преглед изворни кода

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 година
родитељ
комит
2a871c49d9
2 измењених фајлова са 67 додато и 1 уклоњено
  1. 9
    1
      TestFilesystem/buildAndRun
  2. 58
    0
      TestFilesystem/testFilesystem.cpp

+ 9
- 1
TestFilesystem/buildAndRun Прегледај датотеку

@@ -1,5 +1,13 @@
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 ]
then
exit -1

+ 58
- 0
TestFilesystem/testFilesystem.cpp Прегледај датотеку

@@ -61,6 +61,63 @@ bool result;
// 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() {
char const dirSep = CodeDweller::FilePath::DirectorySeparator;
@@ -517,6 +574,7 @@ int main()
{
std::cout << "CodeDweller::Filesystem unit tests" << std::endl << std::endl;
RUN_TEST(testFileOpsMoveFile);
RUN_TEST(testFilePathIsAbsolute);
RUN_TEST(testFilePathJoin);
RUN_TEST(testFileReferenceFile);

Loading…
Откажи
Сачувај