oleaut32: Rewrite RollUdate to be easier to change and to support more conversions.
[wine] / dlls / shell32 / tests / shlfileop.c
1 /*
2  * Unit test of the SHFileOperation function.
3  *
4  * Copyright 2002 Andriy Palamarchuk
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define WINE_NOWINSOCK
25 #include <windows.h>
26 #include "shellapi.h"
27 #include "shlobj.h"
28
29 #include "wine/test.h"
30
31 #ifndef FOF_NORECURSION
32 #define FOF_NORECURSION 0x1000
33 #endif
34
35 /* Error codes could be pre-Win32 */
36 #define DE_SAMEFILE      0x71
37 #define DE_MANYSRC1DEST  0x72
38 #define DE_DIFFDIR       0x73
39 #define DE_OPCANCELLED   0x75
40 #define DE_DESTSUBTREE   0x76
41 #define DE_INVALIDFILES  0x7C
42 #define DE_DESTSAMETREE  0x7D
43 #define DE_FLDDESTISFILE 0x7E
44 #define DE_FILEDESTISFLD 0x80
45 #define expect_retval(ret, ret_prewin32)\
46     ok(retval == ret ||\
47        broken(retval == ret_prewin32),\
48        "Expected %d, got %d\n", ret, retval)
49
50 static BOOL old_shell32 = FALSE;
51
52 static CHAR CURR_DIR[MAX_PATH];
53 static const WCHAR UNICODE_PATH[] = {'c',':','\\',0x00ae,'\0','\0'};
54     /* "c:\®" can be used in all codepages */
55     /* Double-null termination needed for pFrom field of SHFILEOPSTRUCT */
56
57 static HMODULE hshell32;
58 static int (WINAPI *pSHCreateDirectoryExA)(HWND, LPCSTR, LPSECURITY_ATTRIBUTES);
59 static int (WINAPI *pSHCreateDirectoryExW)(HWND, LPCWSTR, LPSECURITY_ATTRIBUTES);
60 static int (WINAPI *pSHFileOperationW)(LPSHFILEOPSTRUCTW);
61 static DWORD_PTR (WINAPI *pSHGetFileInfoW)(LPCWSTR, DWORD , SHFILEINFOW*, UINT, UINT);
62 static int (WINAPI *pSHPathPrepareForWriteA)(HWND, IUnknown*, LPCSTR, DWORD);
63 static int (WINAPI *pSHPathPrepareForWriteW)(HWND, IUnknown*, LPCWSTR, DWORD);
64
65 static void InitFunctionPointers(void)
66 {
67     hshell32 = GetModuleHandleA("shell32.dll");
68     pSHCreateDirectoryExA = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExA");
69     pSHCreateDirectoryExW = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExW");
70     pSHFileOperationW = (void*)GetProcAddress(hshell32, "SHFileOperationW");
71     pSHGetFileInfoW = (void*)GetProcAddress(hshell32, "SHGetFileInfoW");
72     pSHPathPrepareForWriteA = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteA");
73     pSHPathPrepareForWriteW = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteW");
74 }
75
76 /* creates a file with the specified name for tests */
77 static void createTestFile(const CHAR *name)
78 {
79     HANDLE file;
80     DWORD written;
81
82     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
83     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
84     WriteFile(file, name, strlen(name), &written, NULL);
85     WriteFile(file, "\n", strlen("\n"), &written, NULL);
86     CloseHandle(file);
87 }
88
89 static void createTestFileW(const WCHAR *name)
90 {
91     HANDLE file;
92
93     file = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
94     ok(file != INVALID_HANDLE_VALUE, "Failure to open file\n");
95     CloseHandle(file);
96 }
97
98 static BOOL file_exists(const CHAR *name)
99 {
100     return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
101 }
102
103 static BOOL dir_exists(const CHAR *name)
104 {
105     DWORD attr;
106     BOOL dir;
107
108     attr = GetFileAttributesA(name);
109     dir = ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
110
111     return ((attr != INVALID_FILE_ATTRIBUTES) && dir);
112 }
113
114 static BOOL file_existsW(LPCWSTR name)
115 {
116   return GetFileAttributesW(name) != INVALID_FILE_ATTRIBUTES;
117 }
118
119 static BOOL file_has_content(const CHAR *name, const CHAR *content)
120 {
121     CHAR buf[MAX_PATH];
122     HANDLE file;
123     DWORD read;
124
125     file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
126     if (file == INVALID_HANDLE_VALUE)
127         return FALSE;
128     ReadFile(file, buf, MAX_PATH - 1, &read, NULL);
129     buf[read] = 0;
130     CloseHandle(file);
131     return strcmp(buf, content)==0;
132 }
133
134 /* initializes the tests */
135 static void init_shfo_tests(void)
136 {
137     int len;
138
139     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
140     len = lstrlenA(CURR_DIR);
141
142     if(len && (CURR_DIR[len-1] == '\\'))
143         CURR_DIR[len-1] = 0;
144
145     createTestFile("test1.txt");
146     createTestFile("test2.txt");
147     createTestFile("test3.txt");
148     createTestFile("test_5.txt");
149     CreateDirectoryA("test4.txt", NULL);
150     CreateDirectoryA("testdir2", NULL);
151     CreateDirectoryA("testdir2\\nested", NULL);
152     createTestFile("testdir2\\one.txt");
153     createTestFile("testdir2\\nested\\two.txt");
154 }
155
156 /* cleans after tests */
157 static void clean_after_shfo_tests(void)
158 {
159     DeleteFileA("test1.txt");
160     DeleteFileA("test2.txt");
161     DeleteFileA("test3.txt");
162     DeleteFileA("test_5.txt");
163     DeleteFileA("one.txt");
164     DeleteFileA("test4.txt\\test1.txt");
165     DeleteFileA("test4.txt\\test2.txt");
166     DeleteFileA("test4.txt\\test3.txt");
167     RemoveDirectoryA("test4.txt");
168     DeleteFileA("testdir2\\one.txt");
169     DeleteFileA("testdir2\\test1.txt");
170     DeleteFileA("testdir2\\test2.txt");
171     DeleteFileA("testdir2\\test3.txt");
172     DeleteFileA("testdir2\\test4.txt\\test1.txt");
173     DeleteFileA("testdir2\\nested\\two.txt");
174     RemoveDirectoryA("testdir2\\test4.txt");
175     RemoveDirectoryA("testdir2\\nested");
176     RemoveDirectoryA("testdir2");
177     RemoveDirectoryA("c:\\testdir3");
178     DeleteFileA("nonexistent\\notreal\\test2.txt");
179     RemoveDirectoryA("nonexistent\\notreal");
180     RemoveDirectoryA("nonexistent");
181 }
182
183
184 static void test_get_file_info(void)
185 {
186     DWORD rc, rc2;
187     SHFILEINFOA shfi, shfi2;
188     SHFILEINFOW shfiw;
189     char notepad[MAX_PATH];
190
191     /* Test whether fields of SHFILEINFOA are always cleared */
192     memset(&shfi, 0xcf, sizeof(shfi));
193     rc=SHGetFileInfoA("", 0, &shfi, sizeof(shfi), 0);
194     ok(rc == 1, "SHGetFileInfoA('' | 0) should return 1, got 0x%x\n", rc);
195     todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA('' | 0) did not clear hIcon\n");
196     todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szDisplayName[0]\n");
197     todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szTypeName[0]\n");
198     ok(shfi.iIcon == 0xcfcfcfcf ||
199        broken(shfi.iIcon != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
200        "SHGetFileInfoA('' | 0) should not clear iIcon\n");
201     ok(shfi.dwAttributes == 0xcfcfcfcf ||
202        broken(shfi.dwAttributes != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
203        "SHGetFileInfoA('' | 0) should not clear dwAttributes\n");
204
205     if (pSHGetFileInfoW)
206     {
207         HANDLE unset_icon;
208         /* Test whether fields of SHFILEINFOW are always cleared */
209         memset(&shfiw, 0xcf, sizeof(shfiw));
210         memset(&unset_icon, 0xcf, sizeof(unset_icon));
211         rc=pSHGetFileInfoW(NULL, 0, &shfiw, sizeof(shfiw), 0);
212         ok(!rc, "SHGetFileInfoW(NULL | 0) should fail\n");
213         ok(shfiw.hIcon == unset_icon, "SHGetFileInfoW(NULL | 0) should not clear hIcon\n");
214         ok(shfiw.szDisplayName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szDisplayName[0]\n");
215         ok(shfiw.szTypeName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szTypeName[0]\n");
216         ok(shfiw.iIcon == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear iIcon\n");
217         ok(shfiw.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear dwAttributes\n");
218     }
219     else
220         win_skip("SHGetFileInfoW is not available\n");
221
222
223     /* Test some flag combinations that MSDN claims are not allowed,
224      * but which work anyway
225      */
226     memset(&shfi, 0xcf, sizeof(shfi));
227     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
228                       &shfi, sizeof(shfi),
229                       SHGFI_ATTRIBUTES | SHGFI_USEFILEATTRIBUTES);
230     ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should return 1, got 0x%x\n", rc);
231     if (rc)
232         ok(shfi.dwAttributes != 0xcfcfcfcf, "dwFileAttributes is not set\n");
233     todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear hIcon\n");
234     todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szDisplayName[0]\n");
235     todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szTypeName[0]\n");
236     ok(shfi.iIcon == 0xcfcfcfcf ||
237        broken(shfi.iIcon != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
238        "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should not clear iIcon\n");
239
240     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
241                       &shfi, sizeof(shfi),
242                       SHGFI_EXETYPE | SHGFI_USEFILEATTRIBUTES);
243     todo_wine ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) should return 1, got 0x%x\n", rc);
244
245     /* Test SHGFI_USEFILEATTRIBUTES support */
246     strcpy(shfi.szDisplayName, "dummy");
247     shfi.iIcon=0xdeadbeef;
248     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
249                       &shfi, sizeof(shfi),
250                       SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
251     ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent) should return 1, got 0x%x\n", rc);
252     if (rc)
253     {
254         ok(strcpy(shfi.szDisplayName, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
255         ok(shfi.iIcon != 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
256     }
257
258     /* Wine does not have a default icon for text files, and Windows 98 fails
259      * if we give it an empty executable. So use notepad.exe as the test
260      */
261     if (SearchPath(NULL, "notepad.exe", NULL, sizeof(notepad), notepad, NULL))
262     {
263         strcpy(shfi.szDisplayName, "dummy");
264         shfi.iIcon=0xdeadbeef;
265         rc=SHGetFileInfoA(notepad, GetFileAttributes(notepad),
266                           &shfi, sizeof(shfi),
267                           SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
268         ok(rc == 1, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) should return 1, got 0x%x\n", notepad, rc);
269         strcpy(shfi2.szDisplayName, "dummy");
270         shfi2.iIcon=0xdeadbeef;
271         rc2=SHGetFileInfoA(notepad, 0,
272                            &shfi2, sizeof(shfi2),
273                            SHGFI_ICONLOCATION);
274         ok(rc2 == 1, "SHGetFileInfoA(%s) failed %x\n", notepad, rc2);
275         if (rc && rc2)
276         {
277             ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
278             ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
279         }
280     }
281
282     /* with a directory now */
283     strcpy(shfi.szDisplayName, "dummy");
284     shfi.iIcon=0xdeadbeef;
285     rc=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
286                       &shfi, sizeof(shfi),
287                       SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
288     ok(rc == 1, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) should return 1, got 0x%x\n", rc);
289     strcpy(shfi2.szDisplayName, "dummy");
290     shfi2.iIcon=0xdeadbeef;
291     rc2=SHGetFileInfoA("test4.txt", 0,
292                       &shfi2, sizeof(shfi2),
293                       SHGFI_ICONLOCATION);
294     ok(rc2 == 1, "SHGetFileInfoA(test4.txt/) should return 1, got 0x%x\n", rc2);
295     if (rc && rc2)
296     {
297         ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
298         ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
299     }
300     /* with drive root directory */
301     strcpy(shfi.szDisplayName, "dummy");
302     strcpy(shfi.szTypeName, "dummy");
303     shfi.hIcon=(HICON) 0xdeadbeef;
304     shfi.iIcon=0xdeadbeef;
305     shfi.dwAttributes=0xdeadbeef;
306     rc=SHGetFileInfoA("c:\\", 0, &shfi, sizeof(shfi),
307                       SHGFI_TYPENAME | SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON);
308     ok(rc == 1, "SHGetFileInfoA(c:\\) should return 1, got 0x%x\n", rc);
309     ok(lstrcmp(shfi.szDisplayName, "dummy") != 0, "display name was expected to change\n");
310     ok(lstrcmp(shfi.szTypeName, "dummy") != 0, "type name was expected to change\n");
311     ok(shfi.hIcon != (HICON) 0xdeadbeef, "hIcon was expected to change\n");
312     ok(shfi.iIcon != 0xdeadbeef, "iIcon was expected to change\n");
313 }
314
315 static void test_get_file_info_iconlist(void)
316 {
317     /* Test retrieving a handle to the system image list, and
318      * what that returns for hIcon
319      */
320     HRESULT hr;
321     HIMAGELIST hSysImageList;
322     LPITEMIDLIST pidList;
323     SHFILEINFOA shInfoa;
324     SHFILEINFOW shInfow;
325
326     hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidList);
327     if (FAILED(hr)) {
328          skip("can't get desktop pidl\n");
329          return;
330     }
331
332     memset(&shInfoa, 0xcf, sizeof(shInfoa));
333     hSysImageList = (HIMAGELIST) SHGetFileInfoA((const char *)pidList, 0,
334             &shInfoa, sizeof(shInfoa),
335             SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
336     ok((hSysImageList != INVALID_HANDLE_VALUE) && (hSysImageList > (HIMAGELIST) 0xffff), "Can't get handle for CSIDL_DESKTOP imagelist\n");
337     todo_wine ok(shInfoa.hIcon == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
338     todo_wine ok(shInfoa.szTypeName[0] == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
339     ok(shInfoa.iIcon != 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
340     ok(shInfoa.dwAttributes == 0xcfcfcfcf ||
341        shInfoa.dwAttributes ==  0 || /* Vista */
342        broken(shInfoa.dwAttributes != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
343        "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL), unexpected dwAttributes\n");
344     CloseHandle(hSysImageList);
345
346     if (!pSHGetFileInfoW)
347     {
348         win_skip("SHGetFileInfoW is not available\n");
349         ILFree(pidList);
350         return;
351     }
352
353     memset(&shInfow, 0xcf, sizeof(shInfow));
354     hSysImageList = (HIMAGELIST) pSHGetFileInfoW((const WCHAR *)pidList, 0,
355             &shInfow, sizeof(shInfow),
356             SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
357     if (!hSysImageList)
358     {
359         win_skip("SHGetFileInfoW is not implemented\n");
360         return;
361     }
362     ok((hSysImageList != INVALID_HANDLE_VALUE) && (hSysImageList > (HIMAGELIST) 0xffff), "Can't get handle for CSIDL_DESKTOP imagelist\n");
363     todo_wine ok(shInfow.hIcon == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
364     ok(shInfow.szTypeName[0] == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
365     ok(shInfow.iIcon != 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
366     ok(shInfow.dwAttributes == 0xcfcfcfcf ||
367        shInfoa.dwAttributes ==  0, /* Vista */
368        "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) unexpected dwAttributes\n");
369     CloseHandle(hSysImageList);
370
371     /* Various suposidly invalid flag testing */
372     memset(&shInfow, 0xcf, sizeof(shInfow));
373     hr =  pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
374             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
375     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
376     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
377     ok(shInfow.dwAttributes==0xcfcfcfcf ||
378        shInfoa.dwAttributes==0, /* Vista */
379        "unexpected dwAttributes\n");
380
381     memset(&shInfow, 0xcf, sizeof(shInfow));
382     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
383             SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
384     ok(hr != 0, " SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
385     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
386     ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
387     if (shInfow.hIcon!=(HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
388     todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
389
390     memset(&shInfow, 0xcf, sizeof(shInfow));
391     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
392             SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
393     ok(hr != 0, "SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
394     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
395     ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
396     if (shInfow.hIcon != (HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
397     todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
398
399     memset(&shInfow, 0xcf, sizeof(shInfow));
400     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
401             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
402     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
403     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
404     ok(shInfow.dwAttributes==0xcfcfcfcf ||
405        shInfoa.dwAttributes==0, /* Vista */
406        "unexpected dwAttributes\n");
407
408     memset(&shInfow, 0xcf, sizeof(shInfow));
409     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
410             SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
411     ok(hr != 0, "SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
412     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
413     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
414
415     memset(&shInfow, 0xcf, sizeof(shInfow));
416     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
417             SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
418     ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
419     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
420     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
421
422     memset(&shInfow, 0xcf, sizeof(shInfow));
423     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
424             SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
425     ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
426     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
427     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
428
429     memset(&shInfow, 0xcf, sizeof(shInfow));
430     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
431             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
432         SHGFI_ATTRIBUTES);
433     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
434     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
435     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
436
437     memset(&shInfow, 0xcf, sizeof(shInfow));
438     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
439             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
440         SHGFI_EXETYPE);
441     todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
442     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
443     ok(shInfow.dwAttributes==0xcfcfcfcf ||
444        shInfoa.dwAttributes==0, /* Vista */
445        "unexpected dwAttributes\n");
446
447     memset(&shInfow, 0xcf, sizeof(shInfow));
448     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
449         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE);
450     todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
451     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
452     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
453
454     memset(&shInfow, 0xcf, sizeof(shInfow));
455     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
456         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES);
457     ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
458     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
459     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
460
461     memset(&shInfow, 0xcf, sizeof(shInfow));
462     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
463             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|
464         SHGFI_ATTRIBUTES);
465     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
466     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
467     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
468
469     memset(&shInfow, 0xcf, sizeof(shInfow));
470     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
471         SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
472     todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
473     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
474     ok(shInfow.dwAttributes==0xcfcfcfcf ||
475        shInfoa.dwAttributes==0, /* Vista */
476        "unexpected dwAttributes\n");
477
478     memset(&shInfow, 0xcf, sizeof(shInfow));
479     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
480         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
481     todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
482     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
483     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
484
485     memset(&shInfow, 0xcf, sizeof(shInfow));
486     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
487         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES);
488     ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
489     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
490     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
491
492     ILFree(pidList);
493 }
494
495
496 /*
497  puts into the specified buffer file names with current directory.
498  files - string with file names, separated by null characters. Ends on a double
499  null characters
500 */
501 static void set_curr_dir_path(CHAR *buf, const CHAR* files)
502 {
503     buf[0] = 0;
504     while (files[0])
505     {
506         strcpy(buf, CURR_DIR);
507         buf += strlen(buf);
508         buf[0] = '\\';
509         buf++;
510         strcpy(buf, files);
511         buf += strlen(buf) + 1;
512         files += strlen(files) + 1;
513     }
514     buf[0] = 0;
515 }
516
517
518 /* tests the FO_DELETE action */
519 static void test_delete(void)
520 {
521     SHFILEOPSTRUCTA shfo;
522     DWORD ret;
523     CHAR buf[sizeof(CURR_DIR)+sizeof("/test?.txt")+1];
524
525     sprintf(buf, "%s\\%s", CURR_DIR, "test?.txt");
526     buf[strlen(buf) + 1] = '\0';
527
528     shfo.hwnd = NULL;
529     shfo.wFunc = FO_DELETE;
530     shfo.pFrom = buf;
531     shfo.pTo = NULL;
532     shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
533     shfo.hNameMappings = NULL;
534     shfo.lpszProgressTitle = NULL;
535
536     ok(!SHFileOperationA(&shfo), "Deletion was not successful\n");
537     ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
538     ok(!file_exists("test1.txt"), "File should have been removed\n");
539     ok(!file_exists("test2.txt"), "File should have been removed\n");
540     ok(!file_exists("test3.txt"), "File should have been removed\n");
541
542     ret = SHFileOperationA(&shfo);
543     ok(ret == ERROR_SUCCESS, "Directory exists, but is not removed, ret=%d\n", ret);
544     ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
545
546     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
547
548     ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
549     ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
550
551     ret = SHFileOperationA(&shfo);
552     ok(!ret, "The requested file does not exist, ret=%d\n", ret);
553
554     init_shfo_tests();
555     sprintf(buf, "%s\\%s", CURR_DIR, "test4.txt");
556     buf[strlen(buf) + 1] = '\0';
557     ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
558     ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
559     ok(!dir_exists("test4.txt"), "Directory is not removed\n");
560
561     init_shfo_tests();
562     shfo.pFrom = "test1.txt\0test4.txt\0";
563     ok(!SHFileOperationA(&shfo), "Directory and a file are not removed\n");
564     ok(!file_exists("test1.txt"), "The file should have been removed\n");
565     ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
566     ok(file_exists("test2.txt"), "This file should not have been removed\n");
567
568     /* FOF_FILESONLY does not delete a dir matching a wildcard */
569     init_shfo_tests();
570     shfo.fFlags |= FOF_FILESONLY;
571     shfo.pFrom = "*.txt\0";
572     ok(!SHFileOperation(&shfo), "Failed to delete files\n");
573     ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
574     ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
575     ok(dir_exists("test4.txt"), "test4.txt should not have been removed\n");
576
577     /* FOF_FILESONLY only deletes a dir if explicitly specified */
578     init_shfo_tests();
579     shfo.pFrom = "test_?.txt\0test4.txt\0";
580     ok(!SHFileOperation(&shfo), "Failed to delete files and directory\n");
581     ok(!dir_exists("test4.txt") ||
582        broken(dir_exists("test4.txt")), /* NT4 */
583       "test4.txt should have been removed\n");
584     ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
585     ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
586
587     /* try to delete an invalid filename */
588     if (0) {
589         /* this crashes on win9x */
590         init_shfo_tests();
591         shfo.pFrom = "\0";
592         shfo.fFlags &= ~FOF_FILESONLY;
593         shfo.fAnyOperationsAborted = FALSE;
594         ret = SHFileOperation(&shfo);
595         ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
596         ok(!shfo.fAnyOperationsAborted, "Expected no aborted operations\n");
597         ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
598     }
599
600     /* try an invalid function */
601     init_shfo_tests();
602     shfo.pFrom = "test1.txt\0";
603     shfo.wFunc = 0;
604     ret = SHFileOperation(&shfo);
605     ok(ret == ERROR_INVALID_PARAMETER ||
606        broken(ret == ERROR_SUCCESS), /* Win9x, NT4 */
607        "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
608     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
609
610     /* try an invalid list, only one null terminator */
611     if (0) {
612         /* this crashes on win9x */
613         init_shfo_tests();
614         shfo.pFrom = "";
615         shfo.wFunc = FO_DELETE;
616         ret = SHFileOperation(&shfo);
617         ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
618         ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
619     }
620
621     /* delete a nonexistent file */
622     shfo.pFrom = "nonexistent.txt\0";
623     shfo.wFunc = FO_DELETE;
624     ret = SHFileOperation(&shfo);
625     todo_wine
626     ok(ret == 1026 ||
627        ret == ERROR_FILE_NOT_FOUND || /* Vista */
628        broken(ret == ERROR_SUCCESS), /* NT4 */
629        "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", ret);
630
631     /* delete a dir, and then a file inside the dir, same as
632     * deleting a nonexistent file
633     */
634     if (ret != ERROR_FILE_NOT_FOUND)
635     {
636         /* Vista would throw up a dialog box that we can't suppress */
637         init_shfo_tests();
638         shfo.pFrom = "testdir2\0testdir2\\one.txt\0";
639         ret = SHFileOperation(&shfo);
640         ok(ret == ERROR_PATH_NOT_FOUND ||
641            broken(ret == ERROR_SUCCESS), /* NT4 */
642            "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret);
643         ok(!dir_exists("testdir2"), "Expected testdir2 to not exist\n");
644         ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
645     }
646     else
647         skip("Test would show a dialog box\n");
648
649     /* try the FOF_NORECURSION flag, continues deleting subdirs */
650     init_shfo_tests();
651     shfo.pFrom = "testdir2\0";
652     shfo.fFlags |= FOF_NORECURSION;
653     ret = SHFileOperation(&shfo);
654     ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
655     ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
656     ok(!dir_exists("testdir2\\nested"), "Expected testdir2\\nested to not exist\n");
657 }
658
659 /* tests the FO_RENAME action */
660 static void test_rename(void)
661 {
662     SHFILEOPSTRUCTA shfo, shfo2;
663     CHAR from[5*MAX_PATH];
664     CHAR to[5*MAX_PATH];
665     DWORD retval;
666
667     shfo.hwnd = NULL;
668     shfo.wFunc = FO_RENAME;
669     shfo.pFrom = from;
670     shfo.pTo = to;
671     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
672     shfo.hNameMappings = NULL;
673     shfo.lpszProgressTitle = NULL;
674
675     set_curr_dir_path(from, "test1.txt\0");
676     set_curr_dir_path(to, "test4.txt\0");
677     retval = SHFileOperationA(&shfo);
678     ok(retval == ERROR_ALREADY_EXISTS ||
679        retval == DE_FILEDESTISFLD || /* Vista */
680        broken(retval == ERROR_INVALID_NAME), /* Win9x, NT4 */
681        "Expected ERROR_ALREADY_EXISTS or DE_FILEDESTISFLD, got %d\n", retval);
682     ok(file_exists("test1.txt"), "The file is renamed\n");
683
684     set_curr_dir_path(from, "test3.txt\0");
685     set_curr_dir_path(to, "test4.txt\\test1.txt\0");
686     retval = SHFileOperationA(&shfo);
687     if (retval == DE_DIFFDIR)
688     {
689         /* Vista and W2K8 (broken or new behavior ?) */
690         ok(!file_exists("test4.txt\\test1.txt"), "The file is renamed\n");
691     }
692     else
693     {
694         ok(retval == ERROR_SUCCESS, "File is renamed moving to other directory\n");
695         ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
696     }
697
698     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
699     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
700     retval = SHFileOperationA(&shfo);
701     ok(retval == ERROR_GEN_FAILURE ||
702        retval == DE_MANYSRC1DEST || /* Vista */
703        broken(retval == ERROR_SUCCESS), /* Win9x */
704        "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST , got %d\n", retval);
705     ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
706
707     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
708     shfo2.fFlags |= FOF_MULTIDESTFILES;
709
710     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
711     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
712     retval = SHFileOperationA(&shfo2);
713     ok(retval == ERROR_GEN_FAILURE ||
714        retval == DE_MANYSRC1DEST || /* Vista */
715        broken(retval == ERROR_SUCCESS), /* Win9x */
716        "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST files, got %d\n", retval);
717     ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
718
719     set_curr_dir_path(from, "test1.txt\0");
720     set_curr_dir_path(to, "test6.txt\0");
721     retval = SHFileOperationA(&shfo);
722     ok(retval == ERROR_SUCCESS, "Rename file failed, retval = %d\n", retval);
723     ok(!file_exists("test1.txt"), "The file is not renamed\n");
724     ok(file_exists("test6.txt"), "The file is not renamed\n");
725
726     set_curr_dir_path(from, "test6.txt\0");
727     set_curr_dir_path(to, "test1.txt\0");
728     retval = SHFileOperationA(&shfo);
729     ok(retval == ERROR_SUCCESS, "Rename file back failed, retval = %d\n", retval);
730
731     set_curr_dir_path(from, "test4.txt\0");
732     set_curr_dir_path(to, "test6.txt\0");
733     retval = SHFileOperationA(&shfo);
734     ok(retval == ERROR_SUCCESS, "Rename dir failed, retval = %d\n", retval);
735     ok(!dir_exists("test4.txt"), "The dir is not renamed\n");
736     ok(dir_exists("test6.txt"), "The dir is not renamed\n");
737
738     set_curr_dir_path(from, "test6.txt\0");
739     set_curr_dir_path(to, "test4.txt\0");
740     retval = SHFileOperationA(&shfo);
741     ok(retval == ERROR_SUCCESS, "Rename dir back failed, retval = %d\n", retval);
742     ok(dir_exists("test4.txt"), "The dir is not renamed\n");
743
744     /* try to rename more than one file to a single file */
745     shfo.pFrom = "test1.txt\0test2.txt\0";
746     shfo.pTo = "a.txt\0";
747     retval = SHFileOperationA(&shfo);
748     ok(retval == ERROR_GEN_FAILURE ||
749        retval == DE_MANYSRC1DEST || /* Vista */
750        broken(retval == ERROR_SUCCESS), /* Win9x */
751        "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST, got %d\n", retval);
752     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
753     ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
754     ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
755
756     /* pFrom doesn't exist */
757     shfo.pFrom = "idontexist\0";
758     shfo.pTo = "newfile\0";
759     retval = SHFileOperationA(&shfo);
760     ok(retval == 1026 ||
761        retval == ERROR_FILE_NOT_FOUND || /* Vista */
762        broken(retval == ERROR_SUCCESS), /* NT4 */
763        "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval);
764     ok(!file_exists("newfile"), "Expected newfile to not exist\n");
765
766     /* pTo already exist */
767     shfo.pFrom = "test1.txt\0";
768     shfo.pTo = "test2.txt\0";
769     if (old_shell32)
770         shfo.fFlags |= FOF_NOCONFIRMMKDIR;
771     retval = SHFileOperationA(&shfo);
772     if (retval == ERROR_SUCCESS)
773     {
774         /* Vista and W2K8 (broken or new behavior ?) */
775         createTestFile("test1.txt");
776     }
777     else
778     {
779         ok(retval == ERROR_ALREADY_EXISTS ||
780            broken(retval == DE_OPCANCELLED) || /* NT4 */
781            broken(retval == ERROR_INVALID_NAME), /* Win9x */
782            "Expected ERROR_ALREADY_EXISTS, got %d\n", retval);
783     }
784
785     /* pFrom is valid, but pTo is empty */
786     shfo.pFrom = "test1.txt\0";
787     shfo.pTo = "\0";
788     retval = SHFileOperationA(&shfo);
789     ok(retval == ERROR_CANCELLED ||
790        retval == DE_DIFFDIR || /* Vista */
791        broken(retval == DE_OPCANCELLED) || /* Win9x */
792        broken(retval == 65652), /* NT4 */
793        "Expected ERROR_CANCELLED or DE_DIFFDIR\n");
794     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
795
796     /* pFrom is empty */
797     shfo.pFrom = "\0";
798     retval = SHFileOperationA(&shfo);
799     ok(retval == ERROR_ACCESS_DENIED ||
800        retval == DE_MANYSRC1DEST || /* Vista */
801        broken(retval == ERROR_SUCCESS), /* Win9x */
802        "Expected ERROR_ACCESS_DENIED or DE_MANYSRC1DEST, got %d\n", retval);
803
804     /* pFrom is NULL, commented out because it crashes on nt 4.0 */
805     if (0)
806     {
807         shfo.pFrom = NULL;
808         retval = SHFileOperationA(&shfo);
809         ok(retval == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval);
810     }
811 }
812
813 /* tests the FO_COPY action */
814 static void test_copy(void)
815 {
816     SHFILEOPSTRUCTA shfo, shfo2;
817     CHAR from[5*MAX_PATH];
818     CHAR to[5*MAX_PATH];
819     FILEOP_FLAGS tmp_flags;
820     DWORD retval;
821     LPSTR ptr;
822     BOOL on_nt4 = FALSE;
823
824     if (old_shell32)
825     {
826         win_skip("Too many differences for old shell32\n");
827         return;
828     }
829
830     shfo.hwnd = NULL;
831     shfo.wFunc = FO_COPY;
832     shfo.pFrom = from;
833     shfo.pTo = to;
834     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
835     shfo.hNameMappings = NULL;
836     shfo.lpszProgressTitle = NULL;
837
838     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
839     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
840     retval = SHFileOperationA(&shfo);
841     if (dir_exists("test6.txt"))
842     {
843         /* Vista and W2K8 (broken or new behavior ?) */
844         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
845         ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
846            "are specified as a target\n");
847         DeleteFileA("test6.txt\\test2.txt");
848         RemoveDirectoryA("test6.txt\\test4.txt");
849         RemoveDirectoryA("test6.txt");
850     }
851     else
852     {
853         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
854         ok(!file_exists("test6.txt"), "The file is copied - many files are "
855            "specified as a target\n");
856     }
857
858     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
859     shfo2.fFlags |= FOF_MULTIDESTFILES;
860
861     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
862     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
863     ok(!SHFileOperationA(&shfo2), "Can't copy many files\n");
864     ok(file_exists("test6.txt"), "The file is not copied - many files are "
865        "specified as a target\n");
866     DeleteFileA("test6.txt");
867     DeleteFileA("test7.txt");
868     RemoveDirectoryA("test8.txt");
869
870     /* number of sources do not correspond to number of targets */
871     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
872     set_curr_dir_path(to, "test6.txt\0test7.txt\0");
873     retval = SHFileOperationA(&shfo2);
874     if (dir_exists("test6.txt"))
875     {
876         /* Vista and W2K8 (broken or new behavior ?) */
877         ok(retval == DE_DESTSAMETREE, "Expected DE_DESTSAMETREE, got %d\n", retval);
878         ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
879            "are specified as a target\n");
880         RemoveDirectoryA("test6.txt");
881         ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not copied - many files "
882            "are specified as a target\n");
883         RemoveDirectoryA("test7.txt");
884     }
885     else
886     {
887         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
888         ok(!file_exists("test6.txt"), "The file is copied - many files are "
889            "specified as a target\n");
890     }
891
892     set_curr_dir_path(from, "test1.txt\0");
893     set_curr_dir_path(to, "test4.txt\0");
894     ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively\n");
895     ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
896
897     set_curr_dir_path(from, "test?.txt\0");
898     set_curr_dir_path(to, "testdir2\0");
899     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
900     ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
901     ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory\n");
902     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
903     ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
904     ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
905     clean_after_shfo_tests();
906
907     init_shfo_tests();
908     shfo.fFlags |= FOF_FILESONLY;
909     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
910     ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
911     ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
912     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
913     ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
914     clean_after_shfo_tests();
915
916     init_shfo_tests();
917     set_curr_dir_path(from, "test1.txt\0test2.txt\0");
918     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
919     ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
920     ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
921     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
922     ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
923     clean_after_shfo_tests();
924
925     /* Copying multiple files with one not existing as source, fails the
926        entire operation in Win98/ME/2K/XP, but not in 95/NT */
927     init_shfo_tests();
928     tmp_flags = shfo.fFlags;
929     set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0");
930     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
931     ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
932     retval = SHFileOperationA(&shfo);
933     if (retval == ERROR_SUCCESS)
934         /* Win 95/NT returns success but copies only the files up to the nonexistent source */
935         ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
936     else
937     {
938         /* Failure if one source file does not exist */
939         ok(retval == 1026 || /* Win 98/ME/2K/XP */
940            retval == ERROR_FILE_NOT_FOUND, /* Vista and W2K8 */
941            "Files are copied to other directory\n");
942         ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
943     }
944     ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
945     shfo.fFlags = tmp_flags;
946
947     /* copy into a nonexistent directory */
948     init_shfo_tests();
949     shfo.fFlags = FOF_NOCONFIRMMKDIR;
950     set_curr_dir_path(from, "test1.txt\0");
951     set_curr_dir_path(to, "nonexistent\\notreal\\test2.txt\0");
952     retval= SHFileOperation(&shfo);
953     ok(!retval, "Error copying into nonexistent directory\n");
954     ok(file_exists("nonexistent"), "nonexistent not created\n");
955     ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
956     ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
957     ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
958
959     /* a relative dest directory is OK */
960     clean_after_shfo_tests();
961     init_shfo_tests();
962     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
963     shfo.pTo = "testdir2\0";
964     retval = SHFileOperation(&shfo);
965     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
966     ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
967
968     /* try to copy files to a file */
969     clean_after_shfo_tests();
970     init_shfo_tests();
971     shfo.pFrom = from;
972     shfo.pTo = to;
973     /* suppress the error-dialog in win9x here */
974     shfo.fFlags |= FOF_NOERRORUI;
975     set_curr_dir_path(from, "test1.txt\0test2.txt\0");
976     set_curr_dir_path(to, "test3.txt\0");
977     retval = SHFileOperation(&shfo);
978     if (retval == DE_FLDDESTISFILE || /* Vista and W2K8 */
979         retval == DE_INVALIDFILES)    /* Win7 */
980     {
981         /* Most likely new behavior */
982         ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
983     }
984     else
985     {
986         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
987         ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
988     }
989     ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
990
991     /* try to copy many files to nonexistent directory */
992     DeleteFile(to);
993     shfo.fFlags &= ~FOF_NOERRORUI;
994     shfo.fAnyOperationsAborted = FALSE;
995     retval = SHFileOperation(&shfo);
996     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
997     ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
998     ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
999     ok(RemoveDirectory(to), "Expected test3.txt to exist\n");
1000
1001     /* send in FOF_MULTIDESTFILES with too many destination files */
1002     init_shfo_tests();
1003     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1004     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1005     shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
1006     retval = SHFileOperation(&shfo);
1007     if (dir_exists("testdir2\\a.txt"))
1008     {
1009         /* Vista and W2K8 (broken or new behavior ?) */
1010         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1011         ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1012         RemoveDirectory("testdir2\\a.txt");
1013         ok(DeleteFile("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
1014         RemoveDirectory("testdir2\\b.txt");
1015         ok(DeleteFile("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
1016         RemoveDirectory("testdir2\\c.txt");
1017         ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
1018     }
1019     else
1020     {
1021         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1022         ok(shfo.fAnyOperationsAborted ||
1023            broken(!shfo.fAnyOperationsAborted), /* NT4 */
1024            "Expected aborted operations\n");
1025         ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
1026     }
1027
1028     /* send in FOF_MULTIDESTFILES with too many destination files */
1029     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1030     shfo.pTo = "e.txt\0f.txt\0";
1031     shfo.fAnyOperationsAborted = FALSE;
1032     retval = SHFileOperation(&shfo);
1033     if (dir_exists("e.txt"))
1034     {
1035         /* Vista and W2K8 (broken or new behavior ?) */
1036         ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
1037         ok(DeleteFile("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
1038         RemoveDirectory("e.txt");
1039         ok(DeleteFile("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
1040         RemoveDirectory("f.txt");
1041     }
1042     else
1043     {
1044         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1045         ok(shfo.fAnyOperationsAborted ||
1046            broken(!shfo.fAnyOperationsAborted), /* NT4 */
1047            "Expected aborted operations\n");
1048         ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
1049     }
1050
1051     /* use FOF_MULTIDESTFILES with files and a source directory */
1052     shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
1053     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
1054     shfo.fAnyOperationsAborted = FALSE;
1055     retval = SHFileOperation(&shfo);
1056     ok(retval == ERROR_SUCCESS ||
1057        broken(retval == 0x100a1), /* WinMe */
1058        "Expected ERROR_SUCCESS, got %d\n", retval);
1059     ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1060     ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
1061     if (retval == ERROR_SUCCESS)
1062         ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
1063
1064     /* try many dest files without FOF_MULTIDESTFILES flag */
1065     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1066     shfo.pTo = "a.txt\0b.txt\0c.txt\0";
1067     shfo.fAnyOperationsAborted = FALSE;
1068     shfo.fFlags &= ~FOF_MULTIDESTFILES;
1069     retval = SHFileOperation(&shfo);
1070     if (dir_exists("a.txt"))
1071     {
1072         /* Vista and W2K8 (broken or new behavior ?) */
1073         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1074         ok(DeleteFile("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
1075         ok(DeleteFile("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
1076         ok(DeleteFile("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
1077         RemoveDirectory("a.txt");
1078     }
1079     else
1080     {
1081         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1082         ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1083     }
1084
1085     /* try a glob */
1086     shfo.pFrom = "test?.txt\0";
1087     shfo.pTo = "testdir2\0";
1088     shfo.fFlags &= ~FOF_MULTIDESTFILES;
1089     retval = SHFileOperation(&shfo);
1090     ok(retval == ERROR_SUCCESS ||
1091        broken(retval == 0x100a1), /* WinMe */
1092        "Expected ERROR_SUCCESS, got %d\n", retval);
1093     ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1094
1095     /* try a glob with FOF_FILESONLY */
1096     clean_after_shfo_tests();
1097     init_shfo_tests();
1098     shfo.pFrom = "test?.txt\0";
1099     shfo.fFlags |= FOF_FILESONLY;
1100     retval = SHFileOperation(&shfo);
1101     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1102     ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1103     ok(!dir_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
1104
1105     /* try a glob with FOF_MULTIDESTFILES and the same number
1106     * of dest files that we would expect
1107     */
1108     clean_after_shfo_tests();
1109     init_shfo_tests();
1110     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1111     shfo.fFlags &= ~FOF_FILESONLY;
1112     shfo.fFlags |= FOF_MULTIDESTFILES;
1113     retval = SHFileOperation(&shfo);
1114     if (dir_exists("testdir2\\a.txt"))
1115     {
1116         /* Vista and W2K8 (broken or new behavior ?) */
1117         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1118         ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1119         ok(DeleteFile("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
1120         ok(DeleteFile("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
1121         ok(RemoveDirectory("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
1122         RemoveDirectory("testdir2\\a.txt");
1123     }
1124     else
1125     {
1126         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1127         ok(shfo.fAnyOperationsAborted ||
1128            broken(!shfo.fAnyOperationsAborted), /* NT4 */
1129            "Expected aborted operations\n");
1130         ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
1131     }
1132     ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
1133
1134     /* copy one file to two others, second is ignored */
1135     clean_after_shfo_tests();
1136     init_shfo_tests();
1137     shfo.pFrom = "test1.txt\0";
1138     shfo.pTo = "b.txt\0c.txt\0";
1139     shfo.fAnyOperationsAborted = FALSE;
1140     retval = SHFileOperation(&shfo);
1141     if (retval == DE_OPCANCELLED)
1142     {
1143         /* NT4 fails and doesn't copy any files */
1144         ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1145         /* Needed to skip some tests */
1146         win_skip("Skipping some tests on NT4\n");
1147         on_nt4 = TRUE;
1148     }
1149     else
1150     {
1151         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1152         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1153     }
1154     ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1155
1156     /* copy two file to three others, all fail */
1157     shfo.pFrom = "test1.txt\0test2.txt\0";
1158     shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1159     retval = SHFileOperation(&shfo);
1160     if (dir_exists("b.txt"))
1161     {
1162         /* Vista and W2K8 (broken or new behavior ?) */
1163         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1164         ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1165         RemoveDirectory("b.txt");
1166         ok(DeleteFile("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1167         RemoveDirectory("c.txt");
1168     }
1169     else
1170     {
1171         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1172         ok(shfo.fAnyOperationsAborted ||
1173            broken(!shfo.fAnyOperationsAborted), /* NT4 */
1174            "Expected aborted operations\n");
1175         ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1176     }
1177
1178     /* copy one file and one directory to three others */
1179     shfo.pFrom = "test1.txt\0test4.txt\0";
1180     shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1181     shfo.fAnyOperationsAborted = FALSE;
1182     retval = SHFileOperation(&shfo);
1183     if (dir_exists("b.txt"))
1184     {
1185         /* Vista and W2K8 (broken or new behavior ?) */
1186         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1187         ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1188         RemoveDirectory("b.txt");
1189         ok(RemoveDirectory("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1190         RemoveDirectory("c.txt");
1191     }
1192     else
1193     {
1194         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1195         ok(shfo.fAnyOperationsAborted ||
1196            broken(!shfo.fAnyOperationsAborted), /* NT4 */
1197            "Expected aborted operations\n");
1198         ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1199         ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1200     }
1201
1202     /* copy a directory with a file beneath it, plus some files */
1203     createTestFile("test4.txt\\a.txt");
1204     shfo.pFrom = "test4.txt\0test1.txt\0";
1205     shfo.pTo = "testdir2\0";
1206     shfo.fFlags &= ~FOF_MULTIDESTFILES;
1207     shfo.fAnyOperationsAborted = FALSE;
1208     retval = SHFileOperation(&shfo);
1209     ok(retval == ERROR_SUCCESS ||
1210        broken(retval == 0x100a1), /* WinMe */
1211        "Expected ERROR_SUCCESS, got %d\n", retval);
1212     if (retval == ERROR_SUCCESS)
1213     {
1214         ok(DeleteFile("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1215         ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1216         ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1217     }
1218
1219     /* copy one directory and a file in that dir to another dir */
1220     shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
1221     shfo.pTo = "testdir2\0";
1222     retval = SHFileOperation(&shfo);
1223     ok(retval == ERROR_SUCCESS ||
1224        broken(retval == 0x100a1), /* WinMe */
1225        "Expected ERROR_SUCCESS, got %d\n", retval);
1226     if (retval == ERROR_SUCCESS)
1227     {
1228         ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1229         ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1230     }
1231
1232     /* copy a file in a directory first, and then the directory to a nonexistent dir */
1233     shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
1234     shfo.pTo = "nonexistent\0";
1235     retval = SHFileOperation(&shfo);
1236     if (dir_exists("nonexistent"))
1237     {
1238         /* Vista and W2K8 (broken or new behavior ?) */
1239         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1240         ok(DeleteFile("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1241         RemoveDirectory("nonexistent\\test4.txt");
1242         ok(DeleteFile("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1243         RemoveDirectory("nonexistent");
1244     }
1245     else
1246     {
1247         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1248         ok(shfo.fAnyOperationsAborted ||
1249            broken(!shfo.fAnyOperationsAborted), /* NT4 */
1250            "Expected aborted operations\n");
1251         ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1252     }
1253     DeleteFile("test4.txt\\a.txt");
1254
1255     /* destination is same as source file */
1256     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1257     shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
1258     shfo.fAnyOperationsAborted = FALSE;
1259     shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
1260     retval = SHFileOperation(&shfo);
1261     if (retval == DE_OPCANCELLED)
1262     {
1263         /* NT4 fails and doesn't copy any files */
1264         ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1265     }
1266     else
1267     {
1268         ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
1269         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1270     }
1271     ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
1272     ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1273
1274     /* destination is same as source directory */
1275     shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
1276     shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
1277     shfo.fAnyOperationsAborted = FALSE;
1278     retval = SHFileOperation(&shfo);
1279     if (retval == DE_OPCANCELLED)
1280     {
1281         /* NT4 fails and doesn't copy any files */
1282         ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1283     }
1284     else
1285     {
1286         ok(retval == ERROR_SUCCESS ||
1287            retval == DE_DESTSAMETREE, /* Vista */
1288            "Expected ERROR_SUCCESS or DE_DESTSAMETREE, got %d\n", retval);
1289         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1290     }
1291     ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1292
1293     /* copy a directory into itself, error displayed in UI */
1294     shfo.pFrom = "test4.txt\0";
1295     shfo.pTo = "test4.txt\\newdir\0";
1296     shfo.fFlags &= ~FOF_MULTIDESTFILES;
1297     shfo.fAnyOperationsAborted = FALSE;
1298     retval = SHFileOperation(&shfo);
1299     ok(retval == ERROR_SUCCESS ||
1300        retval == DE_DESTSUBTREE, /* Vista */
1301        "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1302     ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1303
1304     /* copy a directory to itself, error displayed in UI */
1305     shfo.pFrom = "test4.txt\0";
1306     shfo.pTo = "test4.txt\0";
1307     shfo.fAnyOperationsAborted = FALSE;
1308     retval = SHFileOperation(&shfo);
1309     ok(retval == ERROR_SUCCESS ||
1310        retval == DE_DESTSUBTREE, /* Vista */
1311        "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1312
1313     /* copy a file into a directory, and the directory into itself */
1314     shfo.pFrom = "test1.txt\0test4.txt\0";
1315     shfo.pTo = "test4.txt\0";
1316     shfo.fAnyOperationsAborted = FALSE;
1317     shfo.fFlags |= FOF_NOCONFIRMATION;
1318     retval = SHFileOperation(&shfo);
1319     ok(retval == ERROR_SUCCESS ||
1320        retval == DE_DESTSUBTREE, /* Vista */
1321        "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1322     ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1323
1324     /* copy a file to a file, and the directory into itself */
1325     shfo.pFrom = "test1.txt\0test4.txt\0";
1326     shfo.pTo = "test4.txt\\a.txt\0";
1327     shfo.fAnyOperationsAborted = FALSE;
1328     retval = SHFileOperation(&shfo);
1329     if (dir_exists("test4.txt\\a.txt"))
1330     {
1331         /* Vista and W2K8 (broken or new behavior ?) */
1332         ok(retval == DE_DESTSUBTREE, "Expected DE_DESTSUBTREE, got %d\n", retval);
1333         ok(DeleteFile("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1334         RemoveDirectory("test4.txt\\a.txt");
1335     }
1336     else
1337     {
1338         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1339         ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1340     }
1341
1342     /* copy a nonexistent file to a nonexistent directory */
1343     shfo.pFrom = "e.txt\0";
1344     shfo.pTo = "nonexistent\0";
1345     shfo.fAnyOperationsAborted = FALSE;
1346     retval = SHFileOperation(&shfo);
1347     ok(retval == 1026 ||
1348        retval == ERROR_FILE_NOT_FOUND || /* Vista */
1349        broken(retval == ERROR_SUCCESS), /* NT4 */
1350        "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval);
1351     ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1352     ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1353
1354     /* Overwrite tests */
1355     clean_after_shfo_tests();
1356     init_shfo_tests();
1357     if (!on_nt4)
1358     {
1359         /* NT4 would throw up some dialog boxes and doesn't copy files that are needed
1360          * in subsequent tests.
1361          */
1362         shfo.fFlags = FOF_NOCONFIRMATION;
1363         shfo.pFrom = "test1.txt\0";
1364         shfo.pTo = "test2.txt\0";
1365         shfo.fAnyOperationsAborted = FALSE;
1366         /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1367         retval = SHFileOperation(&shfo);
1368         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1369         ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1370
1371         shfo.pFrom = "test3.txt\0test1.txt\0";
1372         shfo.pTo = "test2.txt\0one.txt\0";
1373         shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
1374         /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1375         retval = SHFileOperation(&shfo);
1376         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1377         ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1378
1379         shfo.pFrom = "one.txt\0";
1380         shfo.pTo = "testdir2\0";
1381         shfo.fFlags = FOF_NOCONFIRMATION;
1382         /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1383         retval = SHFileOperation(&shfo);
1384         ok(retval == 0, "Expected 0, got %d\n", retval);
1385         ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1386     }
1387
1388     createTestFile("test4.txt\\test1.txt");
1389     shfo.pFrom = "test4.txt\0";
1390     shfo.pTo = "testdir2\0";
1391     /* WinMe needs FOF_NOERRORUI */
1392     shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
1393     retval = SHFileOperation(&shfo);
1394     ok(retval == ERROR_SUCCESS ||
1395        broken(retval == 0x100a1), /* WinMe */
1396        "Expected ERROR_SUCCESS, got %d\n", retval);
1397     shfo.fFlags = FOF_NOCONFIRMATION;
1398     if (ERROR_SUCCESS)
1399     {
1400         createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1401         /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1402         retval = SHFileOperation(&shfo);
1403         ok(retval == 0, "Expected 0, got %d\n", retval);
1404         ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1405     }
1406
1407     createTestFile("one.txt");
1408
1409     /* pFrom contains bogus 2nd name longer than MAX_PATH */
1410     memset(from, 'a', MAX_PATH*2);
1411     memset(from+MAX_PATH*2, 0, 2);
1412     lstrcpyA(from, "one.txt");
1413     shfo.pFrom = from;
1414     shfo.pTo = "two.txt\0";
1415     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1416     retval = SHFileOperation(&shfo);
1417     ok(retval == 1148 || retval == 1026 ||
1418        retval == ERROR_ACCESS_DENIED || /* win2k */
1419        retval == DE_INVALIDFILES, /* Vista */
1420        "Unexpected return value, got %d\n", retval);
1421     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1422     if (dir_exists("two.txt"))
1423         /* Vista and W2K8 (broken or new behavior ?) */
1424         ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1425     else
1426         ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1427
1428     createTestFile("one.txt");
1429
1430     /* pTo contains bogus 2nd name longer than MAX_PATH */
1431     memset(to, 'a', MAX_PATH*2);
1432     memset(to+MAX_PATH*2, 0, 2);
1433     lstrcpyA(to, "two.txt");
1434     shfo.pFrom = "one.txt\0";
1435     shfo.pTo = to;
1436     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1437     retval = SHFileOperation(&shfo);
1438     if (retval == DE_OPCANCELLED)
1439     {
1440         /* NT4 fails and doesn't copy any files */
1441         ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1442     }
1443     else
1444     {
1445         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1446         ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1447     }
1448     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1449
1450     createTestFile("one.txt");
1451
1452     /* no FOF_MULTIDESTFILES, two files in pTo */
1453     shfo.pFrom = "one.txt\0";
1454     shfo.pTo = "two.txt\0three.txt\0";
1455     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1456     retval = SHFileOperation(&shfo);
1457     if (retval == DE_OPCANCELLED)
1458     {
1459         /* NT4 fails and doesn't copy any files */
1460         ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1461     }
1462     else
1463     {
1464         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1465         ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1466     }
1467     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1468
1469     createTestFile("one.txt");
1470
1471     /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1472     memset(from, 'a', MAX_PATH*2);
1473     memset(from+MAX_PATH*2, 0, 2);
1474     memset(to, 'a', MAX_PATH*2);
1475     memset(to+MAX_PATH*2, 0, 2);
1476     lstrcpyA(from, "one.txt");
1477     lstrcpyA(to, "two.txt");
1478     shfo.pFrom = from;
1479     shfo.pTo = to;
1480     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1481     retval = SHFileOperation(&shfo);
1482     ok(retval == 1148 || retval == 1026 ||
1483        retval == ERROR_ACCESS_DENIED ||  /* win2k */
1484        retval == DE_INVALIDFILES, /* Vista */
1485        "Unexpected return value, got %d\n", retval);
1486     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1487     if (dir_exists("two.txt"))
1488         /* Vista and W2K8 (broken or new behavior ?) */
1489         ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1490     else
1491         ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1492
1493     createTestFile("one.txt");
1494
1495     /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1496     memset(to, 'a', MAX_PATH*2);
1497     memset(to+MAX_PATH*2, 0, 2);
1498     lstrcpyA(to, "two.txt");
1499     shfo.pFrom = "one.txt\0";
1500     shfo.pTo = to;
1501     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1502                   FOF_SILENT | FOF_NOERRORUI;
1503     retval = SHFileOperation(&shfo);
1504     if (retval == DE_OPCANCELLED)
1505     {
1506         /* NT4 fails and doesn't copy any files */
1507         ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1508     }
1509     else
1510     {
1511         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1512         ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1513     }
1514     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1515
1516     createTestFile("one.txt");
1517     createTestFile("two.txt");
1518
1519     /* pTo contains bogus 2nd name longer than MAX_PATH,
1520      * multiple source files,
1521      * dest directory does not exist
1522      */
1523     memset(to, 'a', 2 * MAX_PATH);
1524     memset(to+MAX_PATH*2, 0, 2);
1525     lstrcpyA(to, "threedir");
1526     shfo.pFrom = "one.txt\0two.txt\0";
1527     shfo.pTo = to;
1528     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1529     retval = SHFileOperation(&shfo);
1530     if (dir_exists("threedir"))
1531     {
1532         /* Vista and W2K8 (broken or new behavior ?) */
1533         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1534         ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1535         ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1536         ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1537     }
1538     else
1539     {
1540         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1541         ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1542         ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1543         ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1544         ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1545     }
1546     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1547     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1548
1549     createTestFile("one.txt");
1550     createTestFile("two.txt");
1551     CreateDirectoryA("threedir", NULL);
1552
1553     /* pTo contains bogus 2nd name longer than MAX_PATH,
1554      * multiple source files,
1555      * dest directory does exist
1556      */
1557     memset(to, 'a', 2 * MAX_PATH);
1558     memset(to+MAX_PATH*2, 0, 2);
1559     lstrcpyA(to, "threedir");
1560     shfo.pFrom = "one.txt\0two.txt\0";
1561     shfo.pTo = to;
1562     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1563     retval = SHFileOperation(&shfo);
1564     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1565     ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1566     ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1567     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1568     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1569     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1570
1571     if (0) {
1572         /* this crashes on win9x */
1573         createTestFile("one.txt");
1574         createTestFile("two.txt");
1575
1576         /* pTo contains bogus 2nd name longer than MAX_PATH,
1577          * multiple source files, FOF_MULTIDESTFILES
1578          * dest dir does not exist
1579          */
1580
1581         memset(to, 'a', 2 * MAX_PATH);
1582         memset(to+MAX_PATH*2, 0, 2);
1583         lstrcpyA(to, "threedir");
1584         shfo.pFrom = "one.txt\0two.txt\0";
1585         shfo.pTo = to;
1586         shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1587                       FOF_SILENT | FOF_NOERRORUI;
1588         retval = SHFileOperation(&shfo);
1589         ok(retval == ERROR_CANCELLED ||
1590            retval == ERROR_SUCCESS, /* win2k3 */
1591            "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval);
1592         ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1593         ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1594         ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1595         ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1596         ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1597
1598         /* file exists in win2k */
1599         DeleteFileA("threedir");
1600     }
1601
1602
1603     createTestFile("one.txt");
1604     createTestFile("two.txt");
1605     CreateDirectoryA("threedir", NULL);
1606
1607     /* pTo contains bogus 2nd name longer than MAX_PATH,
1608      * multiple source files, FOF_MULTIDESTFILES
1609      * dest dir does exist
1610      */
1611     memset(to, 'a', 2 * MAX_PATH);
1612     memset(to+MAX_PATH*2, 0, 2);
1613     lstrcpyA(to, "threedir");
1614     ptr = to + lstrlenA(to) + 1;
1615     lstrcpyA(ptr, "fourdir");
1616     shfo.pFrom = "one.txt\0two.txt\0";
1617     shfo.pTo = to;
1618     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1619                   FOF_SILENT | FOF_NOERRORUI;
1620     retval = SHFileOperation(&shfo);
1621     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1622     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1623     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1624     ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1625     if (dir_exists("fourdir"))
1626     {
1627         /* Vista and W2K8 (broken or new behavior ?) */
1628         ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1629         ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1630         RemoveDirectoryA("fourdir");
1631     }
1632     else
1633     {
1634         ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1635         ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1636         ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1637     }
1638     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1639
1640     createTestFile("one.txt");
1641     createTestFile("two.txt");
1642     CreateDirectoryA("threedir", NULL);
1643
1644     /* multiple source files, FOF_MULTIDESTFILES
1645      * multiple dest files, but first dest dir exists
1646      * num files in lists is equal
1647      */
1648     shfo.pFrom = "one.txt\0two.txt\0";
1649     shfo.pTo = "threedir\0fourdir\0";
1650     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1651                   FOF_SILENT | FOF_NOERRORUI;
1652     retval = SHFileOperation(&shfo);
1653     ok(retval == ERROR_CANCELLED ||
1654        retval == DE_FILEDESTISFLD || /* Vista */
1655        broken(retval == DE_OPCANCELLED), /* Win9x, NT4 */
1656        "Expected ERROR_CANCELLED or DE_FILEDESTISFLD. got %d\n", retval);
1657     if (file_exists("threedir\\threedir"))
1658     {
1659         /* NT4 */
1660         ok(DeleteFileA("threedir\\threedir"), "Expected file to exist\n");
1661     }
1662     ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1663     ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1664     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1665     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1666     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1667     ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1668     ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1669
1670     createTestFile("one.txt");
1671     createTestFile("two.txt");
1672     CreateDirectoryA("threedir", NULL);
1673
1674     /* multiple source files, FOF_MULTIDESTFILES
1675      * multiple dest files, but first dest dir exists
1676      * num files in lists is not equal
1677      */
1678     shfo.pFrom = "one.txt\0two.txt\0";
1679     shfo.pTo = "threedir\0fourdir\0five\0";
1680     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1681                   FOF_SILENT | FOF_NOERRORUI;
1682     retval = SHFileOperation(&shfo);
1683     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1684     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1685     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1686     ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1687     if (dir_exists("fourdir"))
1688     {
1689         /* Vista and W2K8 (broken or new behavior ?) */
1690         ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1691         ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1692         RemoveDirectoryA("fourdir");
1693     }
1694     else
1695     {
1696         ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1697         ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1698         ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1699     }
1700     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1701     ok(!DeleteFileA("five"), "Expected file to not exist\n");
1702     ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1703
1704     createTestFile("aa.txt");
1705     createTestFile("ab.txt");
1706     CreateDirectoryA("one", NULL);
1707     CreateDirectoryA("two", NULL);
1708
1709     /* pFrom has a glob, pTo has more than one dest */
1710     shfo.pFrom = "a*.txt\0";
1711     shfo.pTo = "one\0two\0";
1712     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1713     retval = SHFileOperation(&shfo);
1714     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1715     ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1716     ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1717     ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1718     ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1719     ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1720     ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1721     ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1722     ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1723 }
1724
1725 /* tests the FO_MOVE action */
1726 static void test_move(void)
1727 {
1728     SHFILEOPSTRUCTA shfo, shfo2;
1729     CHAR from[5*MAX_PATH];
1730     CHAR to[5*MAX_PATH];
1731     DWORD retval;
1732
1733     shfo.hwnd = NULL;
1734     shfo.wFunc = FO_MOVE;
1735     shfo.pFrom = from;
1736     shfo.pTo = to;
1737     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1738     shfo.hNameMappings = NULL;
1739     shfo.lpszProgressTitle = NULL;
1740
1741     set_curr_dir_path(from, "test1.txt\0");
1742     set_curr_dir_path(to, "test4.txt\0");
1743     ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
1744     ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1745     ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1746
1747     set_curr_dir_path(from, "test?.txt\0");
1748     set_curr_dir_path(to, "testdir2\0");
1749     ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1750     ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1751     ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
1752     ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1753     ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1754     ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1755
1756     clean_after_shfo_tests();
1757     init_shfo_tests();
1758
1759     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
1760     shfo2.fFlags |= FOF_MULTIDESTFILES;
1761
1762     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1763     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1764     if (old_shell32)
1765         shfo2.fFlags |= FOF_NOCONFIRMMKDIR;
1766     ok(!SHFileOperationA(&shfo2), "Move many files\n");
1767     ok(DeleteFileA("test6.txt"), "The file is not moved - many files are "
1768        "specified as a target\n");
1769     ok(DeleteFileA("test7.txt"), "The file is not moved\n");
1770     ok(RemoveDirectoryA("test8.txt"), "The directory is not moved\n");
1771
1772     init_shfo_tests();
1773
1774     /* number of sources do not correspond to number of targets */
1775     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1776     set_curr_dir_path(to, "test6.txt\0test7.txt\0");
1777     retval = SHFileOperationA(&shfo2);
1778     if (dir_exists("test6.txt"))
1779     {
1780         if (retval == ERROR_SUCCESS)
1781         {
1782             /* Old shell32 */
1783             DeleteFileA("test6.txt\\test1.txt");
1784             DeleteFileA("test6.txt\\test2.txt");
1785             RemoveDirectoryA("test6.txt\\test4.txt");
1786             RemoveDirectoryA("test6.txt");
1787         }
1788         else
1789         {
1790             /* Vista and W2K8 (broken or new behavior ?) */
1791             ok(retval == DE_DESTSAMETREE, "Expected DE_DESTSAMETREE, got %d\n", retval);
1792             ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1793             RemoveDirectoryA("test6.txt");
1794             ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1795             RemoveDirectoryA("test7.txt");
1796         }
1797     }
1798     else
1799     {
1800         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1801         ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1802            "specified as a target\n");
1803     }
1804
1805     init_shfo_tests();
1806
1807     set_curr_dir_path(from, "test3.txt\0");
1808     set_curr_dir_path(to, "test4.txt\\test1.txt\0");
1809     ok(!SHFileOperationA(&shfo), "Can't move file to other directory\n");
1810     ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1811
1812     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1813     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1814     if (old_shell32)
1815         shfo.fFlags |= FOF_NOCONFIRMMKDIR;
1816     retval = SHFileOperationA(&shfo);
1817     if (dir_exists("test6.txt"))
1818     {
1819         /* Old shell32 */
1820         /* Vista and W2K8 (broken or new behavior ?) */
1821         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1822         ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1823         ok(DeleteFileA("test6.txt\\test2.txt"), "The file is not moved. Many files are specified\n");
1824         ok(DeleteFileA("test6.txt\\test4.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1825         ok(RemoveDirectoryA("test6.txt\\test4.txt"), "The directory is not moved. Many files are specified\n");
1826         RemoveDirectoryA("test6.txt");
1827         init_shfo_tests();
1828     }
1829     else
1830     {
1831         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1832         ok(file_exists("test1.txt"), "The file is moved. Many files are specified\n");
1833         ok(dir_exists("test4.txt"), "The directory is moved. Many files are specified\n");
1834     }
1835
1836     set_curr_dir_path(from, "test1.txt\0");
1837     set_curr_dir_path(to, "test6.txt\0");
1838     ok(!SHFileOperationA(&shfo), "Move file failed\n");
1839     ok(!file_exists("test1.txt"), "The file is not moved\n");
1840     ok(file_exists("test6.txt"), "The file is not moved\n");
1841     set_curr_dir_path(from, "test6.txt\0");
1842     set_curr_dir_path(to, "test1.txt\0");
1843     ok(!SHFileOperationA(&shfo), "Move file back failed\n");
1844
1845     set_curr_dir_path(from, "test4.txt\0");
1846     set_curr_dir_path(to, "test6.txt\0");
1847     ok(!SHFileOperationA(&shfo), "Move dir failed\n");
1848     ok(!dir_exists("test4.txt"), "The dir is not moved\n");
1849     ok(dir_exists("test6.txt"), "The dir is moved\n");
1850     set_curr_dir_path(from, "test6.txt\0");
1851     set_curr_dir_path(to, "test4.txt\0");
1852     ok(!SHFileOperationA(&shfo), "Move dir back failed\n");
1853
1854     /* move one file to two others */
1855     init_shfo_tests();
1856     shfo.pFrom = "test1.txt\0";
1857     shfo.pTo = "a.txt\0b.txt\0";
1858     retval = SHFileOperationA(&shfo);
1859     if (retval == DE_OPCANCELLED)
1860     {
1861         /* NT4 fails and doesn't move any files */
1862         ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1863         DeleteFileA("test1.txt");
1864     }
1865     else
1866     {
1867         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1868         if (old_shell32)
1869         {
1870             DeleteFile("a.txt\\a.txt");
1871             RemoveDirectoryA("a.txt");
1872         }
1873         else
1874             ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1875         ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1876     }
1877     ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1878
1879     /* move two files to one other */
1880     shfo.pFrom = "test2.txt\0test3.txt\0";
1881     shfo.pTo = "test1.txt\0";
1882     retval = SHFileOperationA(&shfo);
1883     if (dir_exists("test1.txt"))
1884     {
1885         /* Old shell32 */
1886         /* Vista and W2K8 (broken or new behavior ?) */
1887         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1888         ok(DeleteFileA("test1.txt\\test2.txt"), "Expected test1.txt\\test2.txt to exist\n");
1889         ok(DeleteFileA("test1.txt\\test3.txt"), "Expected test1.txt\\test3.txt to exist\n");
1890         RemoveDirectoryA("test1.txt");
1891         createTestFile("test2.txt");
1892         createTestFile("test3.txt");
1893     }
1894     else
1895     {
1896         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1897         ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1898         ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1899         ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1900     }
1901
1902     /* move a directory into itself */
1903     shfo.pFrom = "test4.txt\0";
1904     shfo.pTo = "test4.txt\\b.txt\0";
1905     retval = SHFileOperationA(&shfo);
1906     ok(retval == ERROR_SUCCESS ||
1907        retval == DE_DESTSUBTREE, /* Vista */
1908        "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1909     ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1910     ok(dir_exists("test4.txt"), "Expected test4.txt to exist\n");
1911
1912     /* move many files without FOF_MULTIDESTFILES */
1913     shfo.pFrom = "test2.txt\0test3.txt\0";
1914     shfo.pTo = "d.txt\0e.txt\0";
1915     retval = SHFileOperationA(&shfo);
1916     if (dir_exists("d.txt"))
1917     {
1918         /* Old shell32 */
1919         /* Vista and W2K8 (broken or new behavior ?) */
1920         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1921         ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1922         ok(DeleteFileA("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to exist\n");
1923         RemoveDirectoryA("d.txt");
1924         createTestFile("test2.txt");
1925         createTestFile("test3.txt");
1926     }
1927     else
1928     {
1929         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1930         ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1931         ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1932     }
1933
1934     /* number of sources != number of targets */
1935     shfo.pTo = "d.txt\0";
1936     shfo.fFlags |= FOF_MULTIDESTFILES;
1937     retval = SHFileOperationA(&shfo);
1938     if (dir_exists("d.txt"))
1939     {
1940         if (old_shell32)
1941         {
1942             DeleteFileA("d.txt\\test2.txt");
1943             DeleteFileA("d.txt\\test3.txt");
1944             RemoveDirectoryA("d.txt");
1945             createTestFile("test2.txt");
1946         }
1947         else
1948         {
1949             /* Vista and W2K8 (broken or new behavior ?) */
1950             ok(retval == DE_SAMEFILE,
1951                "Expected DE_SAMEFILE, got %d\n", retval);
1952             ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1953             ok(!file_exists("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to not exist\n");
1954             RemoveDirectoryA("d.txt");
1955             createTestFile("test2.txt");
1956         }
1957     }
1958     else
1959     {
1960         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1961         ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1962     }
1963
1964     /* FO_MOVE does not create dest directories */
1965     shfo.pFrom = "test2.txt\0";
1966     shfo.pTo = "dir1\\dir2\\test2.txt\0";
1967     retval = SHFileOperationA(&shfo);
1968     if (dir_exists("dir1"))
1969     {
1970         /* Vista and W2K8 (broken or new behavior ?) */
1971         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1972         ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n");
1973         RemoveDirectoryA("dir1\\dir2");
1974         RemoveDirectoryA("dir1");
1975         createTestFile("test2.txt");
1976     }
1977     else
1978     {
1979         expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1980     }
1981
1982     /* try to overwrite an existing file */
1983     shfo.pTo = "test3.txt\0";
1984     retval = SHFileOperationA(&shfo);
1985     if (retval == DE_OPCANCELLED)
1986     {
1987         /* NT4 fails and doesn't move any files */
1988         ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1989     }
1990     else
1991     {
1992         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1993         ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1994         if (old_shell32)
1995         {
1996             DeleteFileA("test3.txt\\test3.txt");
1997             RemoveDirectoryA("test3.txt");
1998         }
1999         else
2000             ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2001     }
2002 }
2003
2004 static void test_sh_create_dir(void)
2005 {
2006     CHAR path[MAX_PATH];
2007     int ret;
2008
2009     if(!pSHCreateDirectoryExA)
2010     {
2011         win_skip("skipping SHCreateDirectoryExA tests\n");
2012         return;
2013     }
2014
2015     set_curr_dir_path(path, "testdir2\\test4.txt\0");
2016     ret = pSHCreateDirectoryExA(NULL, path, NULL);
2017     ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
2018     ok(file_exists("testdir2"), "The first directory is not created\n");
2019     ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
2020
2021     ret = pSHCreateDirectoryExA(NULL, path, NULL);
2022     ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
2023
2024     ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
2025     ok(file_exists("c:\\testdir3"), "The directory is not created\n");
2026 }
2027
2028 static void test_sh_path_prepare(void)
2029 {
2030     HRESULT res;
2031     CHAR path[MAX_PATH];
2032     CHAR UNICODE_PATH_A[MAX_PATH];
2033
2034     if(!pSHPathPrepareForWriteA)
2035     {
2036         win_skip("skipping SHPathPrepareForWriteA tests\n");
2037         return;
2038     }
2039
2040     /* directory exists, SHPPFW_NONE */
2041     set_curr_dir_path(path, "testdir2\0");
2042     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2043     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2044
2045     /* directory exists, SHPPFW_IGNOREFILENAME */
2046     set_curr_dir_path(path, "testdir2\\test4.txt\0");
2047     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
2048     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2049
2050     /* directory exists, SHPPFW_DIRCREATE */
2051     set_curr_dir_path(path, "testdir2\0");
2052     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2053     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2054
2055     /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2056     set_curr_dir_path(path, "testdir2\\test4.txt\0");
2057     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
2058     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2059     ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2060
2061     /* file exists, SHPPFW_NONE */
2062     set_curr_dir_path(path, "test1.txt\0");
2063     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2064     ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2065        res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2066        res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2067        "Unexpected result : 0x%08x\n", res);
2068
2069     /* file exists, SHPPFW_DIRCREATE */
2070     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2071     ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2072        res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2073        res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2074        "Unexpected result : 0x%08x\n", res);
2075
2076     /* file exists, SHPPFW_NONE, trailing \ */
2077     set_curr_dir_path(path, "test1.txt\\\0");
2078     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2079     ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2080        res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2081        res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2082        "Unexpected result : 0x%08x\n", res);
2083
2084     /* relative path exists, SHPPFW_DIRCREATE */
2085     res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE);
2086     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2087
2088     /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
2089     res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE);
2090     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2091     ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
2092
2093     /* directory doesn't exist, SHPPFW_NONE */
2094     set_curr_dir_path(path, "nonexistent\0");
2095     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2096     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2097
2098     /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
2099     set_curr_dir_path(path, "nonexistent\\notreal\0");
2100     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
2101     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2102     ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
2103     ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2104
2105     /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2106     set_curr_dir_path(path, "testdir2\\test4.txt\\\0");
2107     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
2108     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2109     ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
2110
2111     /* nested directory doesn't exist, SHPPFW_DIRCREATE */
2112     set_curr_dir_path(path, "nonexistent\\notreal\0");
2113     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2114     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2115     ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
2116
2117     /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
2118
2119     if(!pSHPathPrepareForWriteW)
2120     {
2121         win_skip("Skipping SHPathPrepareForWriteW tests\n");
2122         return;
2123     }
2124     WideCharToMultiByte(CP_ACP, 0, UNICODE_PATH, -1, UNICODE_PATH_A, sizeof(UNICODE_PATH_A), NULL, NULL);
2125
2126     /* unicode directory doesn't exist, SHPPFW_NONE */
2127     RemoveDirectoryA(UNICODE_PATH_A);
2128     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
2129     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2130     ok(!file_exists(UNICODE_PATH_A), "unicode path was created but shouldn't be\n");
2131     RemoveDirectoryA(UNICODE_PATH_A);
2132
2133     /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
2134     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
2135     ok(res == S_OK, "res == %08x, expected S_OK\n", res);
2136     ok(file_exists(UNICODE_PATH_A), "unicode path should've been created\n");
2137
2138     /* unicode directory exists, SHPPFW_NONE */
2139     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
2140     ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
2141
2142     /* unicode directory exists, SHPPFW_DIRCREATE */
2143     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
2144     ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
2145     RemoveDirectoryA(UNICODE_PATH_A);
2146 }
2147
2148 static void test_sh_new_link_info(void)
2149 {
2150     BOOL ret, mustcopy=TRUE;
2151     CHAR linkto[MAX_PATH];
2152     CHAR destdir[MAX_PATH];
2153     CHAR result[MAX_PATH];
2154     CHAR result2[MAX_PATH];
2155
2156     /* source file does not exist */
2157     set_curr_dir_path(linkto, "nosuchfile.txt\0");
2158     set_curr_dir_path(destdir, "testdir2\0");
2159     ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2160     ok(ret == FALSE ||
2161        broken(ret == lstrlenA(result) + 1), /* NT4 */
2162        "SHGetNewLinkInfoA succeeded\n");
2163     ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2164
2165     /* dest dir does not exist */
2166     set_curr_dir_path(linkto, "test1.txt\0");
2167     set_curr_dir_path(destdir, "nosuchdir\0");
2168     ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2169     ok(ret == TRUE ||
2170        broken(ret == lstrlenA(result) + 1), /* NT4 */
2171        "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2172     ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2173
2174     /* source file exists */
2175     set_curr_dir_path(linkto, "test1.txt\0");
2176     set_curr_dir_path(destdir, "testdir2\0");
2177     ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2178     ok(ret == TRUE ||
2179        broken(ret == lstrlenA(result) + 1), /* NT4 */
2180        "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2181     ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2182     ok(CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, destdir,
2183                       lstrlenA(destdir), result, lstrlenA(destdir)) == CSTR_EQUAL,
2184        "%s does not start with %s\n", result, destdir);
2185     ok(lstrlenA(result) > 4 && lstrcmpiA(result+lstrlenA(result)-4, ".lnk") == 0,
2186        "%s does not end with .lnk\n", result);
2187
2188     /* preferred target name already exists */
2189     createTestFile(result);
2190     ret = SHGetNewLinkInfoA(linkto, destdir, result2, &mustcopy, 0);
2191     ok(ret == TRUE ||
2192        broken(ret == lstrlenA(result2) + 1), /* NT4 */
2193        "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2194     ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2195     ok(CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, destdir,
2196                       lstrlenA(destdir), result2, lstrlenA(destdir)) == CSTR_EQUAL,
2197        "%s does not start with %s\n", result2, destdir);
2198     ok(lstrlenA(result2) > 4 && lstrcmpiA(result2+lstrlenA(result2)-4, ".lnk") == 0,
2199        "%s does not end with .lnk\n", result2);
2200     ok(lstrcmpiA(result, result2) != 0, "%s and %s are the same\n", result, result2);
2201     DeleteFileA(result);
2202 }
2203
2204 static void test_unicode(void)
2205 {
2206     SHFILEOPSTRUCTW shfoW;
2207     int ret;
2208     HANDLE file;
2209
2210     if (!pSHFileOperationW)
2211     {
2212         skip("SHFileOperationW() is missing\n");
2213         return;
2214     }
2215
2216     shfoW.hwnd = NULL;
2217     shfoW.wFunc = FO_DELETE;
2218     shfoW.pFrom = UNICODE_PATH;
2219     shfoW.pTo = '\0';
2220     shfoW.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
2221     shfoW.hNameMappings = NULL;
2222     shfoW.lpszProgressTitle = NULL;
2223
2224     /* Clean up before start test */
2225     DeleteFileW(UNICODE_PATH);
2226     RemoveDirectoryW(UNICODE_PATH);
2227
2228     /* Make sure we are on a system that supports unicode */
2229     SetLastError(0xdeadbeef);
2230     file = CreateFileW(UNICODE_PATH, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
2231     if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
2232     {
2233         skip("Unicode tests skipped on non-unicode system\n");
2234         return;
2235     }
2236     CloseHandle(file);
2237
2238     /* Try to delete a file with unicode filename */
2239     ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
2240     ret = pSHFileOperationW(&shfoW);
2241     ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
2242     ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
2243
2244     /* Try to trash a file with unicode filename */
2245     createTestFileW(UNICODE_PATH);
2246     shfoW.fFlags |= FOF_ALLOWUNDO;
2247     ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
2248     ret = pSHFileOperationW(&shfoW);
2249     ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
2250     ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
2251
2252     if(!pSHCreateDirectoryExW)
2253     {
2254         skip("Skipping SHCreateDirectoryExW tests\n");
2255         return;
2256     }
2257
2258     /* Try to delete a directory with unicode filename */
2259     ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
2260     ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
2261     ok(file_existsW(UNICODE_PATH), "The directory is not created\n");
2262     shfoW.fFlags &= ~FOF_ALLOWUNDO;
2263     ret = pSHFileOperationW(&shfoW);
2264     ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
2265     ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
2266
2267     /* Try to trash a directory with unicode filename */
2268     ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
2269     ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
2270     ok(file_existsW(UNICODE_PATH), "The directory was not created\n");
2271     shfoW.fFlags |= FOF_ALLOWUNDO;
2272     ret = pSHFileOperationW(&shfoW);
2273     ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
2274     ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
2275 }
2276
2277 extern HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags);
2278
2279 static void
2280 test_shlmenu(void) {
2281         HRESULT hres;
2282         hres = Shell_MergeMenus (0, 0, 0x42, 0x4242, 0x424242, 0);
2283         ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
2284         hres = Shell_MergeMenus ((HMENU)42, 0, 0x42, 0x4242, 0x424242, 0);
2285         ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
2286 }
2287
2288 /* Check for old shell32 (4.0.x) */
2289 static BOOL is_old_shell32(void)
2290 {
2291     SHFILEOPSTRUCTA shfo;
2292     CHAR from[5*MAX_PATH];
2293     CHAR to[5*MAX_PATH];
2294     DWORD retval;
2295
2296     shfo.hwnd = NULL;
2297     shfo.wFunc = FO_COPY;
2298     shfo.pFrom = from;
2299     shfo.pTo = to;
2300     /* FOF_NOCONFIRMMKDIR is needed for old shell32 */
2301     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI | FOF_MULTIDESTFILES | FOF_NOCONFIRMMKDIR;
2302     shfo.hNameMappings = NULL;
2303     shfo.lpszProgressTitle = NULL;
2304
2305     set_curr_dir_path(from, "test1.txt\0test2.txt\0test3.txt\0");
2306     set_curr_dir_path(to, "test6.txt\0test7.txt\0");
2307     retval = SHFileOperationA(&shfo);
2308
2309     /* Delete extra files on old shell32 and Vista+*/
2310     DeleteFileA("test6.txt\\test1.txt");
2311     /* Delete extra files on old shell32 */
2312     DeleteFileA("test6.txt\\test2.txt");
2313     DeleteFileA("test6.txt\\test3.txt");
2314     /* Delete extra directory on old shell32 and Vista+ */
2315     RemoveDirectoryA("test6.txt");
2316     /* Delete extra files/directories on Vista+*/
2317     DeleteFileA("test7.txt\\test2.txt");
2318     RemoveDirectoryA("test7.txt");
2319
2320     if (retval == ERROR_SUCCESS)
2321         return TRUE;
2322
2323     return FALSE;
2324 }
2325
2326 START_TEST(shlfileop)
2327 {
2328     InitFunctionPointers();
2329
2330     clean_after_shfo_tests();
2331
2332     init_shfo_tests();
2333     old_shell32 = is_old_shell32();
2334     if (old_shell32)
2335         win_skip("Need to cater for old shell32 (4.0.x) on Win95\n");
2336     clean_after_shfo_tests();
2337
2338     init_shfo_tests();
2339     test_get_file_info();
2340     test_get_file_info_iconlist();
2341     clean_after_shfo_tests();
2342
2343     init_shfo_tests();
2344     test_delete();
2345     clean_after_shfo_tests();
2346
2347     init_shfo_tests();
2348     test_rename();
2349     clean_after_shfo_tests();
2350
2351     init_shfo_tests();
2352     test_copy();
2353     clean_after_shfo_tests();
2354
2355     init_shfo_tests();
2356     test_move();
2357     clean_after_shfo_tests();
2358
2359     test_sh_create_dir();
2360     clean_after_shfo_tests();
2361
2362     init_shfo_tests();
2363     test_sh_path_prepare();
2364     clean_after_shfo_tests();
2365
2366     init_shfo_tests();
2367     test_sh_new_link_info();
2368     clean_after_shfo_tests();
2369
2370     test_unicode();
2371
2372     test_shlmenu();
2373 }