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