[PATCH v6 2/6] robocopy/tests: Add basic syntax tests

Florian Eder others.meder at gmail.com
Tue Sep 21 09:54:46 CDT 2021


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 at gmail.com>
---
v6: Made execute_robocopy return boolean value and added a DWORD pointer as an argument to
write the exit code into, just like the tests for reg
Added syntax tests for /? and -?
---
 configure                           |   1 +
 configure.ac                        |   1 +
 programs/robocopy/tests/Makefile.in |   4 ++
 programs/robocopy/tests/robocopy.c  | 103 ++++++++++++++++++++++++++++
 4 files changed, 109 insertions(+)
 create mode 100644 programs/robocopy/tests/Makefile.in
 create mode 100644 programs/robocopy/tests/robocopy.c

diff --git a/configure b/configure
index 3a8dee81bbc..82fb0f13a43 100755
--- a/configure
+++ b/configure
@@ -21236,6 +21236,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 5bd54cfbba7..83c67911675 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3960,6 +3960,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..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)
+{
+    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");
+    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();
+}
-- 
2.32.0




More information about the wine-devel mailing list