[XCOPY_WINETEST]
[reactos.git] / rostests / winetests / xcopy / xcopy.c
1 /*
2 * Copyright 2013 Francois Gouget
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #include <wine/test.h>
20
21 static DWORD runcmd(const char* cmd)
22 {
23 STARTUPINFOA si = {sizeof(STARTUPINFOA)};
24 PROCESS_INFORMATION pi;
25 char* wcmd;
26 DWORD rc;
27
28 /* Create a writable copy for CreateProcessA() */
29 wcmd = HeapAlloc(GetProcessHeap(), 0, strlen(cmd) + 1);
30 strcpy(wcmd, cmd);
31
32 /* On Windows 2003 and older, xcopy.exe fails if stdin is not a console
33 * handle, even with '/I /Y' options.
34 */
35 rc = CreateProcessA(NULL, wcmd, NULL, NULL, FALSE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi);
36 HeapFree(GetProcessHeap(), 0, wcmd);
37 if (!rc)
38 return 260;
39
40 rc = WaitForSingleObject(pi.hProcess, 5000);
41 if (rc == WAIT_OBJECT_0)
42 GetExitCodeProcess(pi.hProcess, &rc);
43 else
44 TerminateProcess(pi.hProcess, 1);
45 CloseHandle(pi.hThread);
46 CloseHandle(pi.hProcess);
47
48 return rc;
49 }
50
51 static void test_date_format(void)
52 {
53 DWORD rc;
54
55 rc = runcmd("xcopy /D:20-01-2000 xcopy1 xcopytest");
56 ok(rc == 4, "xcopy /D:d-m-y test returned rc=%u\n", rc);
57 ok(GetFileAttributesA("xcopytest\\xcopy1") == INVALID_FILE_ATTRIBUTES,
58 "xcopy should not have created xcopytest\\xcopy1\n");
59
60 rc = runcmd("xcopy /D:01-20-2000 xcopy1 xcopytest");
61 ok(rc == 0, "xcopy /D:m-d-y test failed rc=%u\n", rc);
62 ok(GetFileAttributesA("xcopytest\\xcopy1") != INVALID_FILE_ATTRIBUTES,
63 "xcopy did not create xcopytest\\xcopy1\n");
64 DeleteFileA("xcopytest\\xcopy1");
65
66 rc = runcmd("xcopy /D:1-20-2000 xcopy1 xcopytest");
67 ok(rc == 0, "xcopy /D:m-d-y test failed rc=%u\n", rc);
68 ok(GetFileAttributesA("xcopytest\\xcopy1") != INVALID_FILE_ATTRIBUTES,
69 "xcopy did not create xcopytest\\xcopy1\n");
70 DeleteFileA("xcopytest\\xcopy1");
71 }
72
73 START_TEST(xcopy)
74 {
75 char tmpdir[MAX_PATH];
76 HANDLE hfile;
77
78 GetTempPathA(MAX_PATH, tmpdir);
79 SetCurrentDirectoryA(tmpdir);
80 trace("%s\n", tmpdir);
81
82 CreateDirectoryA("xcopytest", NULL);
83 hfile = CreateFileA("xcopy1", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
84 FILE_ATTRIBUTE_NORMAL, NULL);
85 ok(hfile != INVALID_HANDLE_VALUE, "Failed to create xcopy1 file\n");
86 if (hfile == INVALID_HANDLE_VALUE)
87 {
88 skip("skipping xcopy tests\n");
89 return;
90 }
91 CloseHandle(hfile);
92
93 test_date_format();
94
95 DeleteFileA("xcopy1");
96 RemoveDirectoryA("xcopytest");
97 }