xcopy: Add tests to show that the /D option only accepts dates in the m-d-y format.
Francois Gouget
fgouget at free.fr
Thu Nov 21 09:00:39 CST 2013
---
This will be particularly interesting when run in a French locale.
Note that configure.ac & co need to be regenerated.
programs/xcopy/tests/Makefile.in | 7 +++
programs/xcopy/tests/xcopy.c | 92 ++++++++++++++++++++++++++++++++++++++++
programs/xcopy/xcopy.c | 7 +--
3 files changed, 103 insertions(+), 3 deletions(-)
create mode 100644 programs/xcopy/tests/Makefile.in
create mode 100644 programs/xcopy/tests/xcopy.c
diff --git a/programs/xcopy/tests/Makefile.in b/programs/xcopy/tests/Makefile.in
new file mode 100644
index 0000000..b024602
--- /dev/null
+++ b/programs/xcopy/tests/Makefile.in
@@ -0,0 +1,7 @@
+TESTDLL = xcopy.exe
+IMPORTS =
+
+C_SRCS = \
+ xcopy.c
+
+ at MAKE_TEST_RULES@
diff --git a/programs/xcopy/tests/xcopy.c b/programs/xcopy/tests/xcopy.c
new file mode 100644
index 0000000..df3ad17
--- /dev/null
+++ b/programs/xcopy/tests/xcopy.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2013 Francois Gouget
+ *
+ * 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
+ */
+
+#include <windows.h>
+
+#include "wine/test.h"
+
+
+static DWORD runcmd(const char* cmd)
+{
+ STARTUPINFOA si = {sizeof(STARTUPINFOA)};
+ PROCESS_INFORMATION pi;
+ char* wcmd;
+ DWORD rc;
+
+ wcmd = strdup(cmd); // FIXME
+ if (!CreateProcessA(NULL, wcmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi))
+ return 260;
+
+ rc = WaitForSingleObject(pi.hProcess, 5000);
+ if (rc == WAIT_OBJECT_0)
+ GetExitCodeProcess(pi.hProcess, &rc);
+ else
+ TerminateProcess(pi.hProcess, 1);
+ CloseHandle(pi.hThread);
+ CloseHandle(pi.hProcess);
+
+ return rc;
+}
+
+static void test_date_format(void)
+{
+ DWORD rc;
+
+ rc = runcmd("xcopy /D:20-01-2000 xcopy1 xcopytest");
+ ok(rc == 4, "xcopy /D:d-m-y test returned rc=%u\n", rc);
+ ok(GetFileAttributesA("xcopytest\\xcopy1") == INVALID_FILE_ATTRIBUTES,
+ "xcopy should not have created xcopytest\\xcopy1\n");
+
+ rc = runcmd("xcopy /D:01-20-2000 xcopy1 xcopytest");
+ ok(rc == 0, "xcopy /D:m-d-y test failed rc=%u\n", rc);
+ ok(GetFileAttributesA("xcopytest\\xcopy1") != INVALID_FILE_ATTRIBUTES,
+ "xcopy did not create xcopytest\\xcopy1\n");
+ DeleteFileA("xcopytest\\xcopy1");
+
+ rc = runcmd("xcopy /D:1-20-2000 xcopy1 xcopytest");
+ ok(rc == 0, "xcopy /D:m-d-y test failed rc=%u\n", rc);
+ ok(GetFileAttributesA("xcopytest\\xcopy1") != INVALID_FILE_ATTRIBUTES,
+ "xcopy did not create xcopytest\\xcopy1\n");
+ DeleteFileA("xcopytest\\xcopy1");
+}
+
+START_TEST(xcopy)
+{
+ char tmpdir[MAX_PATH];
+ HANDLE hfile;
+
+ GetTempPathA(MAX_PATH, tmpdir);
+ SetCurrentDirectoryA(tmpdir);
+ trace("%s\n", tmpdir);
+
+ CreateDirectoryA("xcopytest", NULL);
+ hfile = CreateFileA("xcopy1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ ok(hfile != INVALID_HANDLE_VALUE, "Failed to create xcopy1 file\n");
+ if (hfile == INVALID_HANDLE_VALUE)
+ {
+ skip("skipping xcopy tests");
+ return;
+ }
+ CloseHandle(hfile);
+
+ test_date_format();
+
+ DeleteFileA("xcopy1");
+ RemoveDirectoryA("xcopytest");
+}
diff --git a/programs/xcopy/xcopy.c b/programs/xcopy/xcopy.c
index 3967b18..e424eea 100644
--- a/programs/xcopy/xcopy.c
+++ b/programs/xcopy/xcopy.c
@@ -778,19 +778,20 @@ static int XCOPY_ParseCommandLine(WCHAR *suppliedsource,
BOOL isError = FALSE;
memset(&st, 0x00, sizeof(st));
- /* Parse the arg : Month */
+ /* Microsoft's xcopy's usage implies that the date
+ * format depends on the locale but that false.
+ * It is hardcoded to month-day-year
+ */
st.wMonth = _wtol(pos);
while (*pos && isdigit(*pos)) pos++;
if (*pos++ != '-') isError = TRUE;
- /* Parse the arg : Day */
if (!isError) {
st.wDay = _wtol(pos);
while (*pos && isdigit(*pos)) pos++;
if (*pos++ != '-') isError = TRUE;
}
- /* Parse the arg : Year */
if (!isError) {
st.wYear = _wtol(pos);
while (*pos && isdigit(*pos)) pos++;
--
1.8.4.2
More information about the wine-patches
mailing list