summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2015-12-25 22:54:01 +0000
committerChris Wilson <chris+github@qwirx.com>2015-12-25 22:54:01 +0000
commitcbb347eed395050107cc56a0849678b8efb8194b (patch)
tree4231fd0186d2452d7ace66c7d6e9ff396fb0e369 /lib
parent0b8901506e2a47585edbdada41130d3aabf721c5 (diff)
Fix deletion of test fixture directories with unicode names on Windows.
We need to use CreateProcessW() instead of system() to pass these filenames to the rd command. Fixes every test that runs after test_unicode_filenames_can_be_backed_up in test/bbackupd.
Diffstat (limited to 'lib')
-rw-r--r--lib/common/Test.cpp69
-rw-r--r--lib/win32/emu.h1
2 files changed, 63 insertions, 7 deletions
diff --git a/lib/common/Test.cpp b/lib/common/Test.cpp
index 1035864f..2c51cd61 100644
--- a/lib/common/Test.cpp
+++ b/lib/common/Test.cpp
@@ -104,9 +104,11 @@ bool setUp(const char* function_name)
filename == "bbackupd-data" ||
filename == "syncallowscript.control" ||
StartsWith("syncallowscript.notifyran.", filename) ||
- filename == "test2.downloaded")
+ filename == "test2.downloaded" ||
+ EndsWith("testfile", filename))
{
std::string filepath = std::string("testfiles\\") + filename;
+
int filetype = ObjectExists(filepath);
if(filetype == ObjectExists_File)
{
@@ -118,14 +120,67 @@ bool setUp(const char* function_name)
}
else if(filetype == ObjectExists_Dir)
{
- std::string cmd = "rd /s /q " + filepath;
- int status = system(cmd.c_str());
- if(status != 0)
+ std::string cmd = "cmd /c rd /s /q " + filepath;
+ WCHAR* wide_cmd = ConvertUtf8ToWideString(cmd.c_str());
+ if(wide_cmd == NULL)
+ {
+ TEST_FAIL_WITH_MESSAGE("Failed to convert string "
+ "to wide string: " << cmd);
+ continue;
+ }
+
+ STARTUPINFOW si;
+ PROCESS_INFORMATION pi;
+
+ ZeroMemory( &si, sizeof(si) );
+ si.cb = sizeof(si);
+ ZeroMemory( &pi, sizeof(pi) );
+
+ BOOL result = CreateProcessW(
+ NULL, // lpApplicationName
+ wide_cmd, // lpCommandLine
+ NULL, // lpProcessAttributes
+ NULL, // lpThreadAttributes
+ TRUE, // bInheritHandles
+ 0, // dwCreationFlags
+ NULL, // lpEnvironment
+ NULL, // lpCurrentDirectory
+ &si, // lpStartupInfo
+ &pi // lpProcessInformation
+ );
+ delete [] wide_cmd;
+
+ if(result == FALSE)
{
- TEST_FAIL_WITH_MESSAGE("Failed to delete test fixture "
- "file: command '" << cmd << "' exited with "
- "status " << status);
+ TEST_FAIL_WITH_MESSAGE("Failed to delete test "
+ "fixture file: failed to execute command "
+ "'" << cmd << "': " <<
+ GetErrorMessage(GetLastError()));
+ continue;
}
+
+ // Wait until child process exits.
+ WaitForSingleObject(pi.hProcess, INFINITE);
+ DWORD exit_code;
+ result = GetExitCodeProcess(pi.hProcess, &exit_code);
+
+ if(result == FALSE)
+ {
+ TEST_FAIL_WITH_MESSAGE("Failed to delete "
+ "test fixture file: failed to get "
+ "command exit status: '" <<
+ cmd << "': " <<
+ GetErrorMessage(GetLastError()));
+ }
+ else if(exit_code != 0)
+ {
+ TEST_FAIL_WITH_MESSAGE("Failed to delete test "
+ "fixture file: command '" << cmd << "' "
+ "exited with status " << exit_code);
+ }
+
+ CloseHandle(pi.hProcess);
+ CloseHandle(pi.hThread);
}
else
{
diff --git a/lib/win32/emu.h b/lib/win32/emu.h
index 80c1d5d8..b8539bb6 100644
--- a/lib/win32/emu.h
+++ b/lib/win32/emu.h
@@ -391,6 +391,7 @@ bool ConvertConsoleToUtf8(const std::string& rSource, std::string& rDest);
char* ConvertFromWideString(const WCHAR* pString, unsigned int codepage);
bool ConvertFromWideString(const std::wstring& rInput,
std::string* pOutput, unsigned int codepage);
+WCHAR* ConvertUtf8ToWideString(const char* pString);
std::string ConvertPathToAbsoluteUnicode(const char *pFileName);
// Utility function which returns a default config file name,