summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-12-13 23:44:05 +0000
committerChris Wilson <chris+github@qwirx.com>2015-12-13 23:50:09 +0000
commit004c1d3b39f045f0f3935f6ca7cb9cb1960573ea (patch)
tree0382f1c6a41f3530c01fc5b78eb02eb2de18f017 /lib
parent2cf3fbbfe6888115ca63909fd48dc0357b46a56a (diff)
Add CTest configurations to CMake. Make some tests work on Windows/MSVC.
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Test.cpp59
1 files changed, 58 insertions, 1 deletions
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp
index 9385d8c3..df2c3bc6 100644
--- a/lib/common/Test.cpp
+++ b/lib/common/Test.cpp
@@ -22,7 +22,9 @@
#endif
#include "BoxTime.h"
+#include "FileStream.h"
#include "Test.h"
+#include "Utils.h"
int num_tests_selected = 0;
int num_failures = 0;
@@ -81,6 +83,60 @@ bool setUp(const char* function_name)
}
}
+#ifdef _MSC_VER
+ DIR* pDir = opendir("testfiles");
+ if(!pDir)
+ {
+ THROW_SYS_FILE_ERROR("Failed to open test temporary directory",
+ "testfiles", CommonException, Internal);
+ }
+ struct dirent* pEntry;
+ for(pEntry = readdir(pDir); pEntry; pEntry = readdir(pDir))
+ {
+ std::string filename = pEntry->d_name;
+ if(StartsWith("TestDir", filename) ||
+ StartsWith("0_", filename) ||
+ filename == "accounts.txt" ||
+ StartsWith("file", filename) ||
+ StartsWith("notifyran", filename) ||
+ StartsWith("notifyscript.tag", filename) ||
+ StartsWith("restore", filename) ||
+ filename == "bbackupd-data" ||
+ filename == "syncallowscript.control" ||
+ StartsWith("syncallowscript.notifyran.", filename) ||
+ filename == "test2.downloaded")
+ {
+ int filetype = ObjectExists(std::string("testfiles/") + filename);
+ if(filetype == ObjectExists_File)
+ {
+ if(!::unlink(filename.c_str()))
+ {
+ TEST_FAIL_WITH_MESSAGE(BOX_SYS_ERROR_MESSAGE("Failed to delete "
+ "test fixture file: unlink(\"" << filename << "\")"));
+ }
+ }
+ else if(filetype == ObjectExists_Dir)
+ {
+ std::string cmd = "rmdir /s /q testfiles\\" + filename;
+ int status = system(cmd.c_str());
+ if(status != 0)
+ {
+ TEST_FAIL_WITH_MESSAGE("Failed to delete test fixture "
+ "file: command '" << cmd << "' exited with "
+ "status " << status);
+ }
+ }
+ else
+ {
+ TEST_FAIL_WITH_MESSAGE("Don't know how to delete file " << filename <<
+ " of type " << filetype);
+ }
+ }
+ }
+ closedir(pDir);
+ FileStream touch("testfiles/accounts.txt", O_WRONLY | O_CREAT | O_TRUNC,
+ S_IRUSR | S_IWUSR);
+#else
TEST_THAT_THROWONFAIL(system(
"rm -rf testfiles/TestDir* testfiles/0_0 testfiles/0_1 "
"testfiles/0_2 testfiles/accounts.txt " // testfiles/test* .tgz!
@@ -91,11 +147,12 @@ bool setUp(const char* function_name)
"testfiles/syncallowscript.notifyran.* "
"testfiles/test2.downloaded"
) == 0);
+ TEST_THAT_THROWONFAIL(system("touch testfiles/accounts.txt") == 0);
+#endif
TEST_THAT_THROWONFAIL(mkdir("testfiles/0_0", 0755) == 0);
TEST_THAT_THROWONFAIL(mkdir("testfiles/0_1", 0755) == 0);
TEST_THAT_THROWONFAIL(mkdir("testfiles/0_2", 0755) == 0);
TEST_THAT_THROWONFAIL(mkdir("testfiles/bbackupd-data", 0755) == 0);
- TEST_THAT_THROWONFAIL(system("touch testfiles/accounts.txt") == 0);
return true;
}