On 9/21/21 09:54, Florian Eder wrote:
diff --git a/programs/robocopy/tests/robocopy.c b/programs/robocopy/tests/robocopy.c new file mode 100644 index 00000000000..f99a027baec --- /dev/null +++ b/programs/robocopy/tests/robocopy.c @@ -0,0 +1,103 @@ +/*
- Copyright 2021 Florian Eder
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
- */
+#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <wchar.h> +#include <wine/test.h>
+static BOOL execute_robocopy(const WCHAR *args, DWORD *exit_code)
One alternative (suggested to me by Hugh) is to put robocopy.exe back into the args string, for clarity, and then call this function run_exe() or something similar for brevity. Ultimately I think it's up to personal taste, though.
+{
- STARTUPINFOW startup_info;
- PROCESS_INFORMATION process_info;
- WCHAR cmd[256];
- memset(&startup_info, 0, sizeof(STARTUPINFOW));
- startup_info.dwFlags = STARTF_USESTDHANDLES;
- startup_info.hStdInput = INVALID_HANDLE_VALUE;
- startup_info.hStdOutput = INVALID_HANDLE_VALUE;
- startup_info.hStdError = INVALID_HANDLE_VALUE;
- swprintf(cmd, ARRAY_SIZE(cmd), L"%s%s", L"robocopy.exe ", args);
- if (!CreateProcessW(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &startup_info, &process_info))
return FALSE;
- if (WaitForSingleObject(process_info.hProcess, 30000) == WAIT_TIMEOUT)
return FALSE;
- GetExitCodeProcess(process_info.hProcess, exit_code);
- CloseHandle(process_info.hThread);
- CloseHandle(process_info.hProcess);
- return TRUE;
+}
+START_TEST(robocopy) +{
- DWORD exit_code;
- WCHAR temp_path[MAX_PATH];
- /* robocopy is only available from Vista onwards, abort test if not available */
- if (!execute_robocopy(L"", &exit_code)) return;
- ok(GetTempPathW(ARRAY_SIZE(temp_path), temp_path) != 0, "couldn't get temp folder path");
- ok(SetCurrentDirectoryW(temp_path), "couldn't set CWD to temp folder "%s"", debugstr_w(temp_path));
- winetest_push_context("syntax test 1");
These calls to winetest_push_context() don't really make sense in this patch. The only ok() calls they encompass are already unambiguous due to their line number.
That said, you might consider folding all of these calls together into a single array
- execute_robocopy(L"", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
- winetest_push_context("syntax test 2");
- execute_robocopy(L"invalid_folder", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
- winetest_push_context("syntax test 3");
- execute_robocopy(L"-flag invalid_folder", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
- winetest_push_context("syntax test 4");
- execute_robocopy(L"invalid_folder robocopy_destination", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
- winetest_push_context("syntax test 5");
- execute_robocopy(L"-?", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
- winetest_push_context("syntax test 6");
- execute_robocopy(L"invalid_folder -?", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
- winetest_push_context("syntax test 7");
- execute_robocopy(L"/?", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
- winetest_push_context("syntax test 8");
- execute_robocopy(L"invalid_folder /?", &exit_code);
- todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code);
- winetest_pop_context();
+}