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