Basic files and required changes to configure(.ac) to create basic syntax tests and a scaffolding for the conformance tests to follow for the robocopy utility
Signed-off-by: Florian Eder others.meder@gmail.com --- v5: Added *very* basic syntax tests, as the unit tests following the implementation of each switch / flag will automatically test the correct syntax also Made execute_robocopy only accept args instead of the whole commandline, dynamically allocate the commandline string, changed the return value of execute_robocopy from -1 to explicitly MAXDWORD and reduced the size of temp_path to MAX_PATH, which is the max size that GetTempPathW can return --- configure | 1 + configure.ac | 1 + programs/robocopy/tests/Makefile.in | 4 ++ programs/robocopy/tests/robocopy.c | 87 +++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 programs/robocopy/tests/Makefile.in create mode 100644 programs/robocopy/tests/robocopy.c
diff --git a/configure b/configure index a5767af3c60..d63321522f4 100755 --- a/configure +++ b/configure @@ -21235,6 +21235,7 @@ wine_fn_config_makefile programs/regini enable_regini wine_fn_config_makefile programs/regsvcs enable_regsvcs wine_fn_config_makefile programs/regsvr32 enable_regsvr32 wine_fn_config_makefile programs/robocopy enable_robocopy +wine_fn_config_makefile programs/robocopy/tests enable_tests wine_fn_config_makefile programs/rpcss enable_rpcss wine_fn_config_makefile programs/rundll.exe16 enable_win16 wine_fn_config_makefile programs/rundll32 enable_rundll32 diff --git a/configure.ac b/configure.ac index 97c46565db3..6d89ceea089 100644 --- a/configure.ac +++ b/configure.ac @@ -3959,6 +3959,7 @@ WINE_CONFIG_MAKEFILE(programs/regini) WINE_CONFIG_MAKEFILE(programs/regsvcs) WINE_CONFIG_MAKEFILE(programs/regsvr32) WINE_CONFIG_MAKEFILE(programs/robocopy) +WINE_CONFIG_MAKEFILE(programs/robocopy/tests) WINE_CONFIG_MAKEFILE(programs/rpcss) WINE_CONFIG_MAKEFILE(programs/rundll.exe16,enable_win16) WINE_CONFIG_MAKEFILE(programs/rundll32) diff --git a/programs/robocopy/tests/Makefile.in b/programs/robocopy/tests/Makefile.in new file mode 100644 index 00000000000..d86e70f4c43 --- /dev/null +++ b/programs/robocopy/tests/Makefile.in @@ -0,0 +1,4 @@ +TESTDLL = robocopy.exe + +C_SRCS = \ + robocopy.c diff --git a/programs/robocopy/tests/robocopy.c b/programs/robocopy/tests/robocopy.c new file mode 100644 index 00000000000..8c594b78d92 --- /dev/null +++ b/programs/robocopy/tests/robocopy.c @@ -0,0 +1,87 @@ +/* + * 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 DWORD execute_robocopy(const WCHAR *args) +{ + STARTUPINFOW startup_info; + PROCESS_INFORMATION process_info; + DWORD exit_code; + WCHAR *cmd; + + 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; + + cmd = calloc(ARRAY_SIZE(L"robocopy.exe ") + wcslen(args), sizeof(WCHAR)); + wcscpy(cmd, L"robocopy.exe "); + wcscat(cmd, args); + + if (!CreateProcessW(NULL, cmd, NULL, NULL, TRUE, 0, NULL, NULL, &startup_info, &process_info)) + return MAXDWORD; + + if (WaitForSingleObject(process_info.hProcess, 30000) == WAIT_TIMEOUT) + return MAXDWORD; + + GetExitCodeProcess(process_info.hProcess, &exit_code); + + CloseHandle(process_info.hThread); + CloseHandle(process_info.hProcess); + + return exit_code; +} + +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"") == MAXDWORD) 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"); + RemoveDirectoryW(L"invalid_folder"); + exit_code = execute_robocopy(L""); + todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code); + winetest_pop_context(); + + winetest_push_context("syntax test 2"); + exit_code = execute_robocopy(L"invalid_folder"); + todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code); + winetest_pop_context(); + + winetest_push_context("syntax test 3"); + exit_code = execute_robocopy(L"-flag invalid_folder"); + todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code); + winetest_pop_context(); + + winetest_push_context("syntax test 4"); + exit_code = execute_robocopy(L"invalid_folder robocopy_destination"); + todo_wine ok(exit_code == 16, "unexpected exit code %d\n", exit_code); + winetest_pop_context(); +}