wined3d: Shaders will never have a NULL function.
[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_OPCANCELLED 0x75
37 #define expect_retval(ret, ret_prewin32)\
38     ok(retval == ret ||\
39        broken(retval == ret_prewin32),\
40        "Expected %d, got %d\n", ret, retval)
41
42 static CHAR CURR_DIR[MAX_PATH];
43 static const WCHAR UNICODE_PATH[] = {'c',':','\\',0x00c4,'\0','\0'};
44     /* "c:\Ä", or "c:\A" with diaeresis */
45     /* Double-null termination needed for pFrom field of SHFILEOPSTRUCT */
46
47 static HMODULE hshell32;
48 static int (WINAPI *pSHCreateDirectoryExA)(HWND, LPCSTR, LPSECURITY_ATTRIBUTES);
49 static int (WINAPI *pSHCreateDirectoryExW)(HWND, LPCWSTR, LPSECURITY_ATTRIBUTES);
50 static int (WINAPI *pSHFileOperationW)(LPSHFILEOPSTRUCTW);
51 static DWORD_PTR (WINAPI *pSHGetFileInfoW)(LPCWSTR, DWORD , SHFILEINFOW*, UINT, UINT);
52 static int (WINAPI *pSHPathPrepareForWriteA)(HWND, IUnknown*, LPCSTR, DWORD);
53 static int (WINAPI *pSHPathPrepareForWriteW)(HWND, IUnknown*, LPCWSTR, DWORD);
54
55 static void InitFunctionPointers(void)
56 {
57     hshell32 = GetModuleHandleA("shell32.dll");
58     pSHCreateDirectoryExA = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExA");
59     pSHCreateDirectoryExW = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExW");
60     pSHFileOperationW = (void*)GetProcAddress(hshell32, "SHFileOperationW");
61     pSHGetFileInfoW = (void*)GetProcAddress(hshell32, "SHGetFileInfoW");
62     pSHPathPrepareForWriteA = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteA");
63     pSHPathPrepareForWriteW = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteW");
64 }
65
66 /* creates a file with the specified name for tests */
67 static void createTestFile(const CHAR *name)
68 {
69     HANDLE file;
70     DWORD written;
71
72     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
73     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
74     WriteFile(file, name, strlen(name), &written, NULL);
75     WriteFile(file, "\n", strlen("\n"), &written, NULL);
76     CloseHandle(file);
77 }
78
79 static void createTestFileW(const WCHAR *name)
80 {
81     HANDLE file;
82
83     file = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
84     ok(file != INVALID_HANDLE_VALUE, "Failure to open file\n");
85     CloseHandle(file);
86 }
87
88 static BOOL file_exists(const CHAR *name)
89 {
90     return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
91 }
92
93 static BOOL file_existsW(LPCWSTR name)
94 {
95   return GetFileAttributesW(name) != INVALID_FILE_ATTRIBUTES;
96 }
97
98 static BOOL file_has_content(const CHAR *name, const CHAR *content)
99 {
100     CHAR buf[MAX_PATH];
101     HANDLE file;
102     DWORD read;
103
104     file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
105     if (file == INVALID_HANDLE_VALUE)
106         return FALSE;
107     ReadFile(file, buf, MAX_PATH - 1, &read, NULL);
108     buf[read] = 0;
109     CloseHandle(file);
110     return strcmp(buf, content)==0;
111 }
112
113 /* initializes the tests */
114 static void init_shfo_tests(void)
115 {
116     int len;
117
118     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
119     len = lstrlenA(CURR_DIR);
120
121     if(len && (CURR_DIR[len-1] == '\\'))
122         CURR_DIR[len-1] = 0;
123
124     createTestFile("test1.txt");
125     createTestFile("test2.txt");
126     createTestFile("test3.txt");
127     createTestFile("test_5.txt");
128     CreateDirectoryA("test4.txt", NULL);
129     CreateDirectoryA("testdir2", NULL);
130     CreateDirectoryA("testdir2\\nested", NULL);
131     createTestFile("testdir2\\one.txt");
132     createTestFile("testdir2\\nested\\two.txt");
133 }
134
135 /* cleans after tests */
136 static void clean_after_shfo_tests(void)
137 {
138     DeleteFileA("test1.txt");
139     DeleteFileA("test2.txt");
140     DeleteFileA("test3.txt");
141     DeleteFileA("test_5.txt");
142     DeleteFileA("one.txt");
143     DeleteFileA("test4.txt\\test1.txt");
144     DeleteFileA("test4.txt\\test2.txt");
145     DeleteFileA("test4.txt\\test3.txt");
146     RemoveDirectoryA("test4.txt");
147     DeleteFileA("testdir2\\one.txt");
148     DeleteFileA("testdir2\\test1.txt");
149     DeleteFileA("testdir2\\test2.txt");
150     DeleteFileA("testdir2\\test3.txt");
151     DeleteFileA("testdir2\\test4.txt\\test1.txt");
152     DeleteFileA("testdir2\\nested\\two.txt");
153     RemoveDirectoryA("testdir2\\test4.txt");
154     RemoveDirectoryA("testdir2\\nested");
155     RemoveDirectoryA("testdir2");
156     RemoveDirectoryA("c:\\testdir3");
157     DeleteFileA("nonexistent\\notreal\\test2.txt");
158     RemoveDirectoryA("nonexistent\\notreal");
159     RemoveDirectoryA("nonexistent");
160 }
161
162
163 static void test_get_file_info(void)
164 {
165     DWORD rc, rc2;
166     SHFILEINFOA shfi, shfi2;
167     SHFILEINFOW shfiw;
168     char notepad[MAX_PATH];
169
170     /* Test whether fields of SHFILEINFOA are always cleared */
171     memset(&shfi, 0xcf, sizeof(shfi));
172     rc=SHGetFileInfoA("", 0, &shfi, sizeof(shfi), 0);
173     ok(rc, "SHGetFileInfoA('' | 0) should not fail\n");
174     todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA('' | 0) did not clear hIcon\n");
175     todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szDisplayName[0]\n");
176     todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szTypeName[0]\n");
177     ok(shfi.iIcon == 0xcfcfcfcf, "SHGetFileInfoA('' | 0) should not clear iIcon\n");
178     ok(shfi.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoA('' | 0) should not clear dwAttributes\n");
179
180     if (pSHGetFileInfoW)
181     {
182         /* Test whether fields of SHFILEINFOW are always cleared */
183         memset(&shfiw, 0xcf, sizeof(shfiw));
184         rc=pSHGetFileInfoW(NULL, 0, &shfiw, sizeof(shfiw), 0);
185         todo_wine ok(!rc, "SHGetFileInfoW(NULL | 0) should fail\n");
186         ok(shfiw.hIcon == (HANDLE) 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear hIcon\n");
187         todo_wine ok(shfiw.szDisplayName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szDisplayName[0]\n");
188         todo_wine ok(shfiw.szTypeName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szTypeName[0]\n");
189         todo_wine ok(shfiw.iIcon == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear iIcon\n");
190         ok(shfiw.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear dwAttributes\n");
191     }
192     else
193         win_skip("SHGetFileInfoW is not available\n");
194
195
196     /* Test some flag combinations that MSDN claims are not allowed,
197      * but which work anyway
198      */
199     memset(&shfi, 0xcf, sizeof(shfi));
200     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
201                       &shfi, sizeof(shfi),
202                       SHGFI_ATTRIBUTES | SHGFI_USEFILEATTRIBUTES);
203     ok(rc, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) failed\n");
204     if (rc)
205         ok(shfi.dwAttributes != 0xcfcfcfcf, "dwFileAttributes is not set\n");
206     todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear hIcon\n");
207     todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szDisplayName[0]\n");
208     todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szTypeName[0]\n");
209     ok(shfi.iIcon == 0xcfcfcfcf, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should not clear iIcon\n");
210
211     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
212                       &shfi, sizeof(shfi),
213                       SHGFI_EXETYPE | SHGFI_USEFILEATTRIBUTES);
214     todo_wine ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) returned %d\n", rc);
215
216     /* Test SHGFI_USEFILEATTRIBUTES support */
217     strcpy(shfi.szDisplayName, "dummy");
218     shfi.iIcon=0xdeadbeef;
219     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
220                       &shfi, sizeof(shfi),
221                       SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
222     ok(rc, "SHGetFileInfoA(c:\\nonexistent) failed\n");
223     if (rc)
224     {
225         ok(strcpy(shfi.szDisplayName, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
226         ok(shfi.iIcon != 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
227     }
228
229     /* Wine does not have a default icon for text files, and Windows 98 fails
230      * if we give it an empty executable. So use notepad.exe as the test
231      */
232     if (SearchPath(NULL, "notepad.exe", NULL, sizeof(notepad), notepad, NULL))
233     {
234         strcpy(shfi.szDisplayName, "dummy");
235         shfi.iIcon=0xdeadbeef;
236         rc=SHGetFileInfoA(notepad, GetFileAttributes(notepad),
237                           &shfi, sizeof(shfi),
238                           SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
239         ok(rc, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) failed\n", notepad);
240         strcpy(shfi2.szDisplayName, "dummy");
241         shfi2.iIcon=0xdeadbeef;
242         rc2=SHGetFileInfoA(notepad, 0,
243                            &shfi2, sizeof(shfi2),
244                            SHGFI_ICONLOCATION);
245         ok(rc2, "SHGetFileInfoA(%s) failed\n", notepad);
246         if (rc && rc2)
247         {
248             ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
249             ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
250         }
251     }
252
253     /* with a directory now */
254     strcpy(shfi.szDisplayName, "dummy");
255     shfi.iIcon=0xdeadbeef;
256     rc=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
257                       &shfi, sizeof(shfi),
258                       SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
259     ok(rc, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) failed\n");
260     strcpy(shfi2.szDisplayName, "dummy");
261     shfi2.iIcon=0xdeadbeef;
262     rc2=SHGetFileInfoA("test4.txt", 0,
263                       &shfi2, sizeof(shfi2),
264                       SHGFI_ICONLOCATION);
265     ok(rc2, "SHGetFileInfoA(test4.txt/) failed\n");
266     if (rc && rc2)
267     {
268         ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
269         ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
270     }
271 }
272
273 static void test_get_file_info_iconlist(void)
274 {
275     /* Test retrieving a handle to the system image list, and
276      * what that returns for hIcon
277      */
278     HRESULT hr;
279     HIMAGELIST hSysImageList;
280     LPITEMIDLIST pidList;
281     SHFILEINFOA shInfoa;
282     SHFILEINFOW shInfow;
283
284     hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidList);
285     if (FAILED(hr)) {
286          skip("can't get desktop pidl\n");
287          return;
288     }
289
290     memset(&shInfoa, 0xcf, sizeof(shInfoa));
291     hSysImageList = (HIMAGELIST) SHGetFileInfoA((const char *)pidList, 0,
292             &shInfoa, sizeof(shInfoa),
293             SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
294     ok(hSysImageList != INVALID_HANDLE_VALUE, "Can't get handle for CSIDL_DESKTOP imagelist\n");
295     todo_wine ok(shInfoa.hIcon == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
296     todo_wine ok(shInfoa.szTypeName[0] == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
297     ok(shInfoa.iIcon != 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
298     ok(shInfoa.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should not change dwAttributes\n");
299     CloseHandle(hSysImageList);
300
301     if (!pSHGetFileInfoW)
302     {
303         win_skip("SHGetFileInfoW is not available\n");
304         ILFree(pidList);
305         return;
306     }
307
308     memset(&shInfow, 0xcf, sizeof(shInfow));
309     hSysImageList = (HIMAGELIST) pSHGetFileInfoW((const WCHAR *)pidList, 0,
310             &shInfow, sizeof(shInfow),
311             SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
312     if (!hSysImageList)
313     {
314         win_skip("SHGetFileInfoW is not implemented\n");
315         return;
316     }
317     ok(hSysImageList != INVALID_HANDLE_VALUE, "Can't get handle for CSIDL_DESKTOP imagelist\n");
318     todo_wine ok(shInfow.hIcon == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
319     ok(shInfow.szTypeName[0] == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
320     ok(shInfow.iIcon != 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
321     ok(shInfow.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should not change dwAttributes\n");
322     CloseHandle(hSysImageList);
323
324     /* Various suposidly invalid flag testing */
325     memset(&shInfow, 0xcf, sizeof(shInfow));
326     hr =  pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
327             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
328     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
329     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
330     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
331
332     memset(&shInfow, 0xcf, sizeof(shInfow));
333     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
334             SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
335     ok(hr != 0, " SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
336     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
337     ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
338     if (shInfow.hIcon!=(HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
339     todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
340
341     memset(&shInfow, 0xcf, sizeof(shInfow));
342     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
343             SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
344     ok(hr != 0, "SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
345     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
346     ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
347     if (shInfow.hIcon != (HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
348     todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
349
350     memset(&shInfow, 0xcf, sizeof(shInfow));
351     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
352             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
353     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
354     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
355     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
356
357     memset(&shInfow, 0xcf, sizeof(shInfow));
358     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
359             SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
360     ok(hr != 0, "SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
361     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
362     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
363
364     memset(&shInfow, 0xcf, sizeof(shInfow));
365     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
366             SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
367     ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
368     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
369     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
370
371     memset(&shInfow, 0xcf, sizeof(shInfow));
372     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
373             SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
374     ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
375     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
376     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
377
378     memset(&shInfow, 0xcf, sizeof(shInfow));
379     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
380             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
381         SHGFI_ATTRIBUTES);
382     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
383     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
384     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
385
386     memset(&shInfow, 0xcf, sizeof(shInfow));
387     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
388             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
389         SHGFI_EXETYPE);
390     todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
391     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
392     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
393
394     memset(&shInfow, 0xcf, sizeof(shInfow));
395     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
396         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE);
397     todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
398     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
399     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
400
401     memset(&shInfow, 0xcf, sizeof(shInfow));
402     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
403         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES);
404     ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
405     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
406     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
407
408     memset(&shInfow, 0xcf, sizeof(shInfow));
409     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
410             SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|
411         SHGFI_ATTRIBUTES);
412     ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
413     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
414     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
415
416     memset(&shInfow, 0xcf, sizeof(shInfow));
417     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
418         SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
419     todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
420     ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
421     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
422
423     memset(&shInfow, 0xcf, sizeof(shInfow));
424     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
425         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
426     todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
427     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
428     ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
429
430     memset(&shInfow, 0xcf, sizeof(shInfow));
431     hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
432         SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES);
433     ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
434     todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
435     ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
436
437     ILFree(pidList);
438 }
439
440
441 /*
442  puts into the specified buffer file names with current directory.
443  files - string with file names, separated by null characters. Ends on a double
444  null characters
445 */
446 static void set_curr_dir_path(CHAR *buf, const CHAR* files)
447 {
448     buf[0] = 0;
449     while (files[0])
450     {
451         strcpy(buf, CURR_DIR);
452         buf += strlen(buf);
453         buf[0] = '\\';
454         buf++;
455         strcpy(buf, files);
456         buf += strlen(buf) + 1;
457         files += strlen(files) + 1;
458     }
459     buf[0] = 0;
460 }
461
462
463 /* tests the FO_DELETE action */
464 static void test_delete(void)
465 {
466     SHFILEOPSTRUCTA shfo;
467     DWORD ret;
468     CHAR buf[sizeof(CURR_DIR)+sizeof("/test?.txt")+1];
469
470     sprintf(buf, "%s\\%s", CURR_DIR, "test?.txt");
471     buf[strlen(buf) + 1] = '\0';
472
473     shfo.hwnd = NULL;
474     shfo.wFunc = FO_DELETE;
475     shfo.pFrom = buf;
476     shfo.pTo = "\0";
477     shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
478     shfo.hNameMappings = NULL;
479     shfo.lpszProgressTitle = NULL;
480
481     ok(!SHFileOperationA(&shfo), "Deletion was not successful\n");
482     ok(file_exists("test4.txt"), "Directory should not have been removed\n");
483     ok(!file_exists("test1.txt"), "File should have been removed\n");
484
485     ret = SHFileOperationA(&shfo);
486     ok(!ret, "Directory exists, but is not removed, ret=%d\n", ret);
487     ok(file_exists("test4.txt"), "Directory should not have been removed\n");
488
489     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
490
491     ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
492     ok(!file_exists("test4.txt"), "Directory should have been removed\n");
493
494     ret = SHFileOperationA(&shfo);
495     ok(!ret, "The requested file does not exist, ret=%d\n", ret);
496
497     init_shfo_tests();
498     sprintf(buf, "%s\\%s", CURR_DIR, "test4.txt");
499     buf[strlen(buf) + 1] = '\0';
500     ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
501     ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
502     ok(!file_exists("test4.txt"), "Directory is not removed\n");
503
504     init_shfo_tests();
505     shfo.pFrom = "test1.txt\0test4.txt\0";
506     ok(!SHFileOperationA(&shfo), "Directory and a file are not removed\n");
507     ok(!file_exists("test1.txt"), "The file should have been removed\n");
508     ok(!file_exists("test4.txt"), "Directory should have been removed\n");
509     ok(file_exists("test2.txt"), "This file should not have been removed\n");
510
511     /* FOF_FILESONLY does not delete a dir matching a wildcard */
512     init_shfo_tests();
513     shfo.fFlags |= FOF_FILESONLY;
514     shfo.pFrom = "*.txt\0";
515     ok(!SHFileOperation(&shfo), "Failed to delete files\n");
516     ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
517     ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
518     ok(file_exists("test4.txt"), "test4.txt should not have been removed\n");
519
520     /* FOF_FILESONLY only deletes a dir if explicitly specified */
521     init_shfo_tests();
522     shfo.pFrom = "test_?.txt\0test4.txt\0";
523     ok(!SHFileOperation(&shfo), "Failed to delete files and directory\n");
524     ok(!file_exists("test4.txt"), "test4.txt should have been removed\n");
525     ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
526     ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
527
528     /* try to delete an invalid filename */
529     if (0) {
530         /* this crashes on win9x */
531         init_shfo_tests();
532         shfo.pFrom = "\0";
533         shfo.fFlags &= ~FOF_FILESONLY;
534         shfo.fAnyOperationsAborted = FALSE;
535         ret = SHFileOperation(&shfo);
536         ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
537         ok(!shfo.fAnyOperationsAborted, "Expected no aborted operations\n");
538         ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
539     }
540
541     /* try an invalid function */
542     init_shfo_tests();
543     shfo.pFrom = "test1.txt\0";
544     shfo.wFunc = 0;
545     ret = SHFileOperation(&shfo);
546     ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
547     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
548
549     /* try an invalid list, only one null terminator */
550     if (0) {
551         /* this crashes on win9x */
552         init_shfo_tests();
553         shfo.pFrom = "";
554         shfo.wFunc = FO_DELETE;
555         ret = SHFileOperation(&shfo);
556         ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
557         ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
558     }
559
560     /* delete a dir, and then a file inside the dir, same as
561     * deleting a nonexistent file
562     */
563     init_shfo_tests();
564     shfo.pFrom = "testdir2\0testdir2\\one.txt\0";
565     shfo.wFunc = FO_DELETE;
566     ret = SHFileOperation(&shfo);
567     ok(ret == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret);
568     ok(!file_exists("testdir2"), "Expected testdir2 to not exist\n");
569     ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
570
571     /* try the FOF_NORECURSION flag, continues deleting subdirs */
572     init_shfo_tests();
573     shfo.pFrom = "testdir2\0";
574     shfo.fFlags |= FOF_NORECURSION;
575     ret = SHFileOperation(&shfo);
576     ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
577     ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
578     ok(!file_exists("testdir2\\nested"), "Expected testdir2\\nested to exist\n");
579 }
580
581 /* tests the FO_RENAME action */
582 static void test_rename(void)
583 {
584     SHFILEOPSTRUCTA shfo, shfo2;
585     CHAR from[5*MAX_PATH];
586     CHAR to[5*MAX_PATH];
587     DWORD retval;
588
589     shfo.hwnd = NULL;
590     shfo.wFunc = FO_RENAME;
591     shfo.pFrom = from;
592     shfo.pTo = to;
593     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
594     shfo.hNameMappings = NULL;
595     shfo.lpszProgressTitle = NULL;
596
597     set_curr_dir_path(from, "test1.txt\0");
598     set_curr_dir_path(to, "test4.txt\0");
599     ok(SHFileOperationA(&shfo), "File is not renamed moving to other directory "
600        "when specifying directory name only\n");
601     ok(file_exists("test1.txt"), "The file is removed\n");
602
603     set_curr_dir_path(from, "test3.txt\0");
604     set_curr_dir_path(to, "test4.txt\\test1.txt\0");
605     ok(!SHFileOperationA(&shfo), "File is renamed moving to other directory\n");
606     ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
607
608     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
609     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
610     retval = SHFileOperationA(&shfo); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
611     ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
612        "Can't rename many files, retval = %d\n", retval);
613     ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
614
615     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
616     shfo2.fFlags |= FOF_MULTIDESTFILES;
617
618     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
619     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
620     retval = SHFileOperationA(&shfo2); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
621     ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
622        "Can't rename many files, retval = %d\n", retval);
623     ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
624
625     set_curr_dir_path(from, "test1.txt\0");
626     set_curr_dir_path(to, "test6.txt\0");
627     retval = SHFileOperationA(&shfo);
628     ok(!retval, "Rename file failed, retval = %d\n", retval);
629     ok(!file_exists("test1.txt"), "The file is not renamed\n");
630     ok(file_exists("test6.txt"), "The file is not renamed\n");
631
632     set_curr_dir_path(from, "test6.txt\0");
633     set_curr_dir_path(to, "test1.txt\0");
634     retval = SHFileOperationA(&shfo);
635     ok(!retval, "Rename file back failed, retval = %d\n", retval);
636
637     set_curr_dir_path(from, "test4.txt\0");
638     set_curr_dir_path(to, "test6.txt\0");
639     retval = SHFileOperationA(&shfo);
640     ok(!retval, "Rename dir failed, retval = %d\n", retval);
641     ok(!file_exists("test4.txt"), "The dir is not renamed\n");
642     ok(file_exists("test6.txt"), "The dir is not renamed\n");
643
644     set_curr_dir_path(from, "test6.txt\0");
645     set_curr_dir_path(to, "test4.txt\0");
646     retval = SHFileOperationA(&shfo);
647     ok(!retval, "Rename dir back failed, retval = %d\n", retval);
648
649     /* try to rename more than one file to a single file */
650     shfo.pFrom = "test1.txt\0test2.txt\0";
651     shfo.pTo = "a.txt\0";
652     retval = SHFileOperationA(&shfo);
653     ok(retval == ERROR_GEN_FAILURE ||
654        broken(!retval), /* Win9x */
655        "Expected ERROR_GEN_FAILURE, got %d\n", retval);
656     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
657     ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
658     ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
659
660     /* pFrom doesn't exist */
661     shfo.pFrom = "idontexist\0";
662     shfo.pTo = "newfile\0";
663     retval = SHFileOperationA(&shfo);
664     ok(retval == 1026, "Expected 1026, got %d\n", retval);
665     ok(!file_exists("newfile"), "Expected newfile to not exist\n");
666
667     /* pTo already exist */
668     shfo.pFrom = "test1.txt\0";
669     shfo.pTo = "test2.txt\0";
670     retval = SHFileOperationA(&shfo);
671         ok(retval == ERROR_ALREADY_EXISTS, "Expected ERROR_ALREADY_EXISTS, got %d\n", retval);
672
673     /* pFrom is valid, but pTo is empty */
674     shfo.pFrom = "test1.txt\0";
675     shfo.pTo = "\0";
676     retval = SHFileOperationA(&shfo);
677     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x */);
678     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
679
680     /* pFrom is empty */
681     shfo.pFrom = "\0";
682     retval = SHFileOperationA(&shfo);
683         ok(retval == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", retval);
684
685     /* pFrom is NULL, commented out because it crashes on nt 4.0 */
686 #if 0
687     shfo.pFrom = NULL;
688     retval = SHFileOperationA(&shfo);
689     ok(retval == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval);
690 #endif
691 }
692
693 /* tests the FO_COPY action */
694 static void test_copy(void)
695 {
696     SHFILEOPSTRUCTA shfo, shfo2;
697     CHAR from[5*MAX_PATH];
698     CHAR to[5*MAX_PATH];
699     FILEOP_FLAGS tmp_flags;
700     DWORD retval;
701     LPSTR ptr;
702
703     shfo.hwnd = NULL;
704     shfo.wFunc = FO_COPY;
705     shfo.pFrom = from;
706     shfo.pTo = to;
707     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
708     shfo.hNameMappings = NULL;
709     shfo.lpszProgressTitle = NULL;
710
711     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
712     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
713     ok(SHFileOperationA(&shfo), "Can't copy many files\n");
714     ok(!file_exists("test6.txt"), "The file is not copied - many files are "
715        "specified as a target\n");
716
717     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
718     shfo2.fFlags |= FOF_MULTIDESTFILES;
719
720     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
721     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
722     ok(!SHFileOperationA(&shfo2), "Can't copy many files\n");
723     ok(file_exists("test6.txt"), "The file is copied - many files are "
724        "specified as a target\n");
725     DeleteFileA("test6.txt");
726     DeleteFileA("test7.txt");
727     RemoveDirectoryA("test8.txt");
728
729     /* number of sources do not correspond to number of targets */
730     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
731     set_curr_dir_path(to, "test6.txt\0test7.txt\0");
732     ok(SHFileOperationA(&shfo2), "Can't copy many files\n");
733     ok(!file_exists("test6.txt"), "The file is not copied - many files are "
734        "specified as a target\n");
735
736     set_curr_dir_path(from, "test1.txt\0");
737     set_curr_dir_path(to, "test4.txt\0");
738     ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively\n");
739     ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
740
741     set_curr_dir_path(from, "test?.txt\0");
742     set_curr_dir_path(to, "testdir2\0");
743     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
744     ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
745     ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory\n");
746     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
747     ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
748     ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
749     clean_after_shfo_tests();
750
751     init_shfo_tests();
752     shfo.fFlags |= FOF_FILESONLY;
753     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
754     ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
755     ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
756     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
757     ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
758     clean_after_shfo_tests();
759
760     init_shfo_tests();
761     set_curr_dir_path(from, "test1.txt\0test2.txt\0");
762     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
763     ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
764     ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
765     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
766     ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
767     clean_after_shfo_tests();
768
769     /* Copying multiple files with one not existing as source, fails the
770        entire operation in Win98/ME/2K/XP, but not in 95/NT */
771     init_shfo_tests();
772     tmp_flags = shfo.fFlags;
773     set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0");
774     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
775     ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
776     retval = SHFileOperationA(&shfo);
777     if (!retval)
778         /* Win 95/NT returns success but copies only the files up to the nonexistent source */
779         ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
780     else
781     {
782         /* Win 98/ME/2K/XP fail the entire operation with return code 1026 if one source file does not exist */
783         ok(retval == 1026, "Files are copied to other directory\n");
784         ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
785     }
786     ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
787     shfo.fFlags = tmp_flags;
788
789     /* copy into a nonexistent directory */
790     init_shfo_tests();
791     shfo.fFlags = FOF_NOCONFIRMMKDIR;
792     set_curr_dir_path(from, "test1.txt\0");
793     set_curr_dir_path(to, "nonexistent\\notreal\\test2.txt\0");
794     retval= SHFileOperation(&shfo);
795         ok(!retval, "Error copying into nonexistent directory\n");
796         ok(file_exists("nonexistent"), "nonexistent not created\n");
797         ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
798         ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
799     ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
800
801     /* a relative dest directory is OK */
802     clean_after_shfo_tests();
803     init_shfo_tests();
804     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
805     shfo.pTo = "testdir2\0";
806     retval = SHFileOperation(&shfo);
807     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
808     ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
809
810     /* try to copy files to a file */
811     clean_after_shfo_tests();
812     init_shfo_tests();
813     shfo.pFrom = from;
814     shfo.pTo = to;
815     /* suppress the error-dialog in win9x here */
816     shfo.fFlags |= FOF_NOERRORUI;
817     set_curr_dir_path(from, "test1.txt\0test2.txt\0");
818     set_curr_dir_path(to, "test3.txt\0");
819     retval = SHFileOperation(&shfo);
820     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
821     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
822     ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
823
824     /* try to copy many files to nonexistent directory */
825     DeleteFile(to);
826     shfo.fFlags &= ~FOF_NOERRORUI;
827     shfo.fAnyOperationsAborted = FALSE;
828     retval = SHFileOperation(&shfo);
829         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
830         ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
831         ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
832         ok(RemoveDirectory(to), "Expected test3.txt to exist\n");
833
834     /* send in FOF_MULTIDESTFILES with too many destination files */
835     init_shfo_tests();
836     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
837     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
838     shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
839     retval = SHFileOperation(&shfo);
840     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
841     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
842     ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
843
844     /* send in FOF_MULTIDESTFILES with too many destination files */
845     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
846     shfo.pTo = "e.txt\0f.txt\0";
847     shfo.fAnyOperationsAborted = FALSE;
848     retval = SHFileOperation(&shfo);
849     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
850     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
851     ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
852
853     /* use FOF_MULTIDESTFILES with files and a source directory */
854     shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
855     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
856     shfo.fAnyOperationsAborted = FALSE;
857     retval = SHFileOperation(&shfo);
858     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
859     ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
860     ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
861     ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
862
863     /* try many dest files without FOF_MULTIDESTFILES flag */
864     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
865     shfo.pTo = "a.txt\0b.txt\0c.txt\0";
866     shfo.fAnyOperationsAborted = FALSE;
867     shfo.fFlags &= ~FOF_MULTIDESTFILES;
868     retval = SHFileOperation(&shfo);
869     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
870     ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
871
872     /* try a glob */
873     shfo.pFrom = "test?.txt\0";
874     shfo.pTo = "testdir2\0";
875     shfo.fFlags &= ~FOF_MULTIDESTFILES;
876     retval = SHFileOperation(&shfo);
877         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
878         ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
879
880     /* try a glob with FOF_FILESONLY */
881     clean_after_shfo_tests();
882     init_shfo_tests();
883     shfo.pFrom = "test?.txt\0";
884     shfo.fFlags |= FOF_FILESONLY;
885     retval = SHFileOperation(&shfo);
886         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
887         ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
888     ok(!file_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
889
890     /* try a glob with FOF_MULTIDESTFILES and the same number
891     * of dest files that we would expect
892     */
893     clean_after_shfo_tests();
894     init_shfo_tests();
895     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
896     shfo.fFlags &= ~FOF_FILESONLY;
897     shfo.fFlags |= FOF_MULTIDESTFILES;
898     retval = SHFileOperation(&shfo);
899     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
900     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
901     ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
902     ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
903
904     /* copy one file to two others, second is ignored */
905     clean_after_shfo_tests();
906     init_shfo_tests();
907     shfo.pFrom = "test1.txt\0";
908     shfo.pTo = "b.txt\0c.txt\0";
909     shfo.fAnyOperationsAborted = FALSE;
910     retval = SHFileOperation(&shfo);
911         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
912         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
913     ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
914
915     /* copy two file to three others, all fail */
916     shfo.pFrom = "test1.txt\0test2.txt\0";
917     shfo.pTo = "b.txt\0c.txt\0d.txt\0";
918     retval = SHFileOperation(&shfo);
919     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
920     ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
921     ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
922
923     /* copy one file and one directory to three others */
924     shfo.pFrom = "test1.txt\0test4.txt\0";
925     shfo.pTo = "b.txt\0c.txt\0d.txt\0";
926     shfo.fAnyOperationsAborted = FALSE;
927     retval = SHFileOperation(&shfo);
928     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
929     ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
930     ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
931     ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
932
933     /* copy a directory with a file beneath it, plus some files */
934     createTestFile("test4.txt\\a.txt");
935     shfo.pFrom = "test4.txt\0test1.txt\0";
936     shfo.pTo = "testdir2\0";
937     shfo.fFlags &= ~FOF_MULTIDESTFILES;
938     shfo.fAnyOperationsAborted = FALSE;
939     retval = SHFileOperation(&shfo);
940     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
941     ok(DeleteFile("testdir2\\test1.txt"), "Expected newdir\\test1.txt to exist\n");
942     ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
943     ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
944
945     /* copy one directory and a file in that dir to another dir */
946     shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
947     shfo.pTo = "testdir2\0";
948     retval = SHFileOperation(&shfo);
949     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
950     ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
951     ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
952
953     /* copy a file in a directory first, and then the directory to a nonexistent dir */
954     shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
955     shfo.pTo = "nonexistent\0";
956     retval = SHFileOperation(&shfo);
957     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
958     ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
959     ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
960     DeleteFile("test4.txt\\a.txt");
961
962     /* destination is same as source file */
963     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
964     shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
965     shfo.fAnyOperationsAborted = FALSE;
966     shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
967     retval = SHFileOperation(&shfo);
968         ok(retval == ERROR_NO_MORE_SEARCH_HANDLES,
969            "Expected ERROR_NO_MORE_SEARCH_HANDLES, got %d\n", retval);
970         ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
971         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
972     ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
973
974     /* destination is same as source directory */
975     shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
976     shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
977     shfo.fAnyOperationsAborted = FALSE;
978     retval = SHFileOperation(&shfo);
979         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
980         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
981     ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
982
983     /* copy a directory into itself, error displayed in UI */
984     shfo.pFrom = "test4.txt\0";
985     shfo.pTo = "test4.txt\\newdir\0";
986     shfo.fFlags &= ~FOF_MULTIDESTFILES;
987     shfo.fAnyOperationsAborted = FALSE;
988     retval = SHFileOperation(&shfo);
989         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
990     ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
991
992     /* copy a directory to itself, error displayed in UI */
993     shfo.pFrom = "test4.txt\0";
994     shfo.pTo = "test4.txt\0";
995     shfo.fAnyOperationsAborted = FALSE;
996     retval = SHFileOperation(&shfo);
997         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
998
999     /* copy a file into a directory, and the directory into itself */
1000     shfo.pFrom = "test1.txt\0test4.txt\0";
1001     shfo.pTo = "test4.txt\0";
1002     shfo.fAnyOperationsAborted = FALSE;
1003     shfo.fFlags |= FOF_NOCONFIRMATION;
1004     retval = SHFileOperation(&shfo);
1005         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1006     ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1007
1008     /* copy a file to a file, and the directory into itself */
1009     shfo.pFrom = "test1.txt\0test4.txt\0";
1010     shfo.pTo = "test4.txt\\a.txt\0";
1011     shfo.fAnyOperationsAborted = FALSE;
1012     retval = SHFileOperation(&shfo);
1013     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1014     ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1015
1016     /* copy a nonexistent file to a nonexistent directory */
1017     shfo.pFrom = "e.txt\0";
1018     shfo.pTo = "nonexistent\0";
1019     shfo.fAnyOperationsAborted = FALSE;
1020     retval = SHFileOperation(&shfo);
1021     ok(retval == 1026, "Expected 1026, got %d\n", retval);
1022     ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1023     ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1024
1025     /* Overwrite tests */
1026     clean_after_shfo_tests();
1027     init_shfo_tests();
1028     shfo.fFlags = FOF_NOCONFIRMATION;
1029     shfo.pFrom = "test1.txt\0";
1030     shfo.pTo = "test2.txt\0";
1031     shfo.fAnyOperationsAborted = FALSE;
1032     /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1033     retval = SHFileOperation(&shfo);
1034     ok(retval == 0, "Expected 0, got %d\n", retval);
1035     ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1036
1037     shfo.pFrom = "test3.txt\0test1.txt\0";
1038     shfo.pTo = "test2.txt\0one.txt\0";
1039     shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
1040     /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1041     retval = SHFileOperation(&shfo);
1042     ok(retval == 0, "Expected 0, got %d\n", retval);
1043     ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1044
1045     shfo.pFrom = "one.txt\0";
1046     shfo.pTo = "testdir2\0";
1047     shfo.fFlags = FOF_NOCONFIRMATION;
1048     /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1049     retval = SHFileOperation(&shfo);
1050     ok(retval == 0, "Expected 0, got %d\n", retval);
1051     ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1052
1053     createTestFile("test4.txt\\test1.txt");
1054     shfo.pFrom = "test4.txt\0";
1055     shfo.pTo = "testdir2\0";
1056     shfo.fFlags = FOF_NOCONFIRMATION;
1057     ok(!SHFileOperation(&shfo), "First SHFileOperation failed\n");
1058     createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1059     /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1060     retval = SHFileOperation(&shfo);
1061     ok(retval == 0, "Expected 0, got %d\n", retval);
1062     ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1063
1064     createTestFile("one.txt");
1065
1066     /* pFrom contains bogus 2nd name longer than MAX_PATH */
1067     memset(from, 'a', MAX_PATH*2);
1068     memset(from+MAX_PATH*2, 0, 2);
1069     lstrcpyA(from, "one.txt");
1070     shfo.pFrom = from;
1071     shfo.pTo = "two.txt\0";
1072     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1073     retval = SHFileOperation(&shfo);
1074     ok(retval == 1148 || retval == 1026 ||
1075        retval == ERROR_ACCESS_DENIED, /* win2k */
1076        "Expected 1148, 1026 or ERROR_ACCESS_DENIED, got %d\n", retval);
1077     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1078     ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1079
1080     createTestFile("one.txt");
1081
1082     /* pTo contains bogus 2nd name longer than MAX_PATH */
1083     memset(to, 'a', MAX_PATH*2);
1084     memset(to+MAX_PATH*2, 0, 2);
1085     lstrcpyA(to, "two.txt");
1086     shfo.pFrom = "one.txt\0";
1087     shfo.pTo = to;
1088     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1089     retval = SHFileOperation(&shfo);
1090     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1091     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1092     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1093
1094     createTestFile("one.txt");
1095
1096     /* no FOF_MULTIDESTFILES, two files in pTo */
1097     shfo.pFrom = "one.txt\0";
1098     shfo.pTo = "two.txt\0three.txt\0";
1099     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1100     retval = SHFileOperation(&shfo);
1101     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1102     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1103     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1104
1105     createTestFile("one.txt");
1106
1107     /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1108     memset(from, 'a', MAX_PATH*2);
1109     memset(from+MAX_PATH*2, 0, 2);
1110     memset(to, 'a', MAX_PATH*2);
1111     memset(to+MAX_PATH*2, 0, 2);
1112     lstrcpyA(from, "one.txt");
1113     lstrcpyA(to, "two.txt");
1114     shfo.pFrom = from;
1115     shfo.pTo = to;
1116     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1117     retval = SHFileOperation(&shfo);
1118     ok(retval == 1148 || retval == 1026 ||
1119        retval == ERROR_ACCESS_DENIED, /* win2k */
1120        "Expected 1148, 1026 or ERROR_ACCESS_DENIED, got %d\n", retval);
1121     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1122     ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1123
1124     createTestFile("one.txt");
1125
1126     /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1127     memset(to, 'a', MAX_PATH*2);
1128     memset(to+MAX_PATH*2, 0, 2);
1129     lstrcpyA(to, "two.txt");
1130     shfo.pFrom = "one.txt\0";
1131     shfo.pTo = to;
1132     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1133                   FOF_SILENT | FOF_NOERRORUI;
1134     retval = SHFileOperation(&shfo);
1135     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1136     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1137     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1138
1139     createTestFile("one.txt");
1140     createTestFile("two.txt");
1141
1142     /* pTo contains bogus 2nd name longer than MAX_PATH,
1143      * multiple source files,
1144      * dest directory does not exist
1145      */
1146     memset(to, 'a', 2 * MAX_PATH);
1147     memset(to+MAX_PATH*2, 0, 2);
1148     lstrcpyA(to, "threedir");
1149     shfo.pFrom = "one.txt\0two.txt\0";
1150     shfo.pTo = to;
1151     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1152     retval = SHFileOperation(&shfo);
1153     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1154     ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1155     ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1156     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1157     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1158     ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1159     ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1160
1161     createTestFile("one.txt");
1162     createTestFile("two.txt");
1163     CreateDirectoryA("threedir", NULL);
1164
1165     /* pTo contains bogus 2nd name longer than MAX_PATH,
1166      * multiple source files,
1167      * dest directory does exist
1168      */
1169     memset(to, 'a', 2 * MAX_PATH);
1170     memset(to+MAX_PATH*2, 0, 2);
1171     lstrcpyA(to, "threedir");
1172     shfo.pFrom = "one.txt\0two.txt\0";
1173     shfo.pTo = to;
1174     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1175     retval = SHFileOperation(&shfo);
1176     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1177     ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1178     ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1179     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1180     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1181     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1182
1183     if (0) {
1184         /* this crashes on win9x */
1185         createTestFile("one.txt");
1186         createTestFile("two.txt");
1187
1188         /* pTo contains bogus 2nd name longer than MAX_PATH,
1189          * multiple source files, FOF_MULTIDESTFILES
1190          * dest dir does not exist
1191          */
1192
1193         memset(to, 'a', 2 * MAX_PATH);
1194         memset(to+MAX_PATH*2, 0, 2);
1195         lstrcpyA(to, "threedir");
1196         shfo.pFrom = "one.txt\0two.txt\0";
1197         shfo.pTo = to;
1198         shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1199                       FOF_SILENT | FOF_NOERRORUI;
1200         retval = SHFileOperation(&shfo);
1201         ok(retval == ERROR_CANCELLED ||
1202            retval == ERROR_SUCCESS, /* win2k3 */
1203            "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval);
1204         ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1205         ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1206         ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1207         ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1208         ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1209
1210         /* file exists in win2k */
1211         DeleteFileA("threedir");
1212     }
1213
1214
1215     createTestFile("one.txt");
1216     createTestFile("two.txt");
1217     CreateDirectoryA("threedir", NULL);
1218
1219     /* pTo contains bogus 2nd name longer than MAX_PATH,
1220      * multiple source files, FOF_MULTIDESTFILES
1221      * dest dir does exist
1222      */
1223     memset(to, 'a', 2 * MAX_PATH);
1224     memset(to+MAX_PATH*2, 0, 2);
1225     lstrcpyA(to, "threedir");
1226     ptr = to + lstrlenA(to) + 1;
1227     lstrcpyA(ptr, "fourdir");
1228     shfo.pFrom = "one.txt\0two.txt\0";
1229     shfo.pTo = to;
1230     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1231                   FOF_SILENT | FOF_NOERRORUI;
1232     retval = SHFileOperation(&shfo);
1233     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1234     ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1235     ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1236     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1237     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1238     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1239     ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1240     ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1241
1242     createTestFile("one.txt");
1243     createTestFile("two.txt");
1244     CreateDirectoryA("threedir", NULL);
1245
1246     /* multiple source files, FOF_MULTIDESTFILES
1247      * multiple dest files, but first dest dir exists
1248      * num files in lists is equal
1249      */
1250     shfo.pFrom = "one.txt\0two.txt\0";
1251     shfo.pTo = "threedir\0fourdir\0";
1252     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1253                   FOF_SILENT | FOF_NOERRORUI;
1254     retval = SHFileOperation(&shfo);
1255     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1256     ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1257     ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1258     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1259     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1260     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1261     ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1262     ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1263
1264     createTestFile("one.txt");
1265     createTestFile("two.txt");
1266     CreateDirectoryA("threedir", NULL);
1267
1268     /* multiple source files, FOF_MULTIDESTFILES
1269      * multiple dest files, but first dest dir exists
1270      * num files in lists is not equal
1271      */
1272     shfo.pFrom = "one.txt\0two.txt\0";
1273     shfo.pTo = "threedir\0fourdir\0five\0";
1274     shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1275                   FOF_SILENT | FOF_NOERRORUI;
1276     retval = SHFileOperation(&shfo);
1277     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1278     ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1279     ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1280     ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1281     ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1282     ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1283     ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1284     ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1285     ok(!DeleteFileA("five"), "Expected file to not exist\n");
1286     ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1287
1288     createTestFile("aa.txt");
1289     createTestFile("ab.txt");
1290     CreateDirectoryA("one", NULL);
1291     CreateDirectoryA("two", NULL);
1292
1293     /* pFrom has a glob, pTo has more than one dest */
1294     shfo.pFrom = "a*.txt\0";
1295     shfo.pTo = "one\0two\0";
1296     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1297     retval = SHFileOperation(&shfo);
1298     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1299     ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1300     ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1301     ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1302     ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1303     ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1304     ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1305     ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1306     ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1307 }
1308
1309 /* tests the FO_MOVE action */
1310 static void test_move(void)
1311 {
1312     SHFILEOPSTRUCTA shfo, shfo2;
1313     CHAR from[5*MAX_PATH];
1314     CHAR to[5*MAX_PATH];
1315     DWORD retval;
1316
1317     shfo.hwnd = NULL;
1318     shfo.wFunc = FO_MOVE;
1319     shfo.pFrom = from;
1320     shfo.pTo = to;
1321     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1322     shfo.hNameMappings = NULL;
1323     shfo.lpszProgressTitle = NULL;
1324
1325     set_curr_dir_path(from, "test1.txt\0");
1326     set_curr_dir_path(to, "test4.txt\0");
1327     ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
1328     ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1329     ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1330
1331     set_curr_dir_path(from, "test?.txt\0");
1332     set_curr_dir_path(to, "testdir2\0");
1333     ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1334     ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1335     ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
1336     ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1337     ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1338     ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1339
1340     clean_after_shfo_tests();
1341     init_shfo_tests();
1342
1343     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
1344     shfo2.fFlags |= FOF_MULTIDESTFILES;
1345
1346     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1347     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1348     ok(!SHFileOperationA(&shfo2), "Move many files\n");
1349     ok(file_exists("test6.txt"), "The file is moved - many files are "
1350        "specified as a target\n");
1351     DeleteFileA("test6.txt");
1352     DeleteFileA("test7.txt");
1353     RemoveDirectoryA("test8.txt");
1354
1355     init_shfo_tests();
1356
1357     /* number of sources do not correspond to number of targets */
1358     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1359     set_curr_dir_path(to, "test6.txt\0test7.txt\0");
1360     ok(SHFileOperationA(&shfo2), "Can't move many files\n");
1361     ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1362        "specified as a target\n");
1363
1364     init_shfo_tests();
1365
1366     set_curr_dir_path(from, "test3.txt\0");
1367     set_curr_dir_path(to, "test4.txt\\test1.txt\0");
1368     ok(!SHFileOperationA(&shfo), "File is moved moving to other directory\n");
1369     ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
1370
1371     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1372     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1373     ok(SHFileOperationA(&shfo), "Cannot move many files\n");
1374     ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
1375     ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
1376
1377     set_curr_dir_path(from, "test1.txt\0");
1378     set_curr_dir_path(to, "test6.txt\0");
1379     ok(!SHFileOperationA(&shfo), "Move file\n");
1380     ok(!file_exists("test1.txt"), "The file is moved\n");
1381     ok(file_exists("test6.txt"), "The file is moved\n");
1382     set_curr_dir_path(from, "test6.txt\0");
1383     set_curr_dir_path(to, "test1.txt\0");
1384     ok(!SHFileOperationA(&shfo), "Move file back\n");
1385
1386     set_curr_dir_path(from, "test4.txt\0");
1387     set_curr_dir_path(to, "test6.txt\0");
1388     ok(!SHFileOperationA(&shfo), "Move dir\n");
1389     ok(!file_exists("test4.txt"), "The dir is moved\n");
1390     ok(file_exists("test6.txt"), "The dir is moved\n");
1391     set_curr_dir_path(from, "test6.txt\0");
1392     set_curr_dir_path(to, "test4.txt\0");
1393     ok(!SHFileOperationA(&shfo), "Move dir back\n");
1394
1395     /* move one file to two others */
1396     init_shfo_tests();
1397     shfo.pFrom = "test1.txt\0";
1398     shfo.pTo = "a.txt\0b.txt\0";
1399     retval = SHFileOperationA(&shfo);
1400         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1401         ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1402         ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1403     ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1404
1405     /* move two files to one other */
1406     shfo.pFrom = "test2.txt\0test3.txt\0";
1407     shfo.pTo = "test1.txt\0";
1408     retval = SHFileOperationA(&shfo);
1409     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1410     ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1411     ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1412     ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1413
1414     /* move a directory into itself */
1415     shfo.pFrom = "test4.txt\0";
1416     shfo.pTo = "test4.txt\\b.txt\0";
1417     retval = SHFileOperationA(&shfo);
1418         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1419     ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1420     ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
1421
1422     /* move many files without FOF_MULTIDESTFILES */
1423     shfo.pFrom = "test2.txt\0test3.txt\0";
1424     shfo.pTo = "d.txt\0e.txt\0";
1425     retval = SHFileOperationA(&shfo);
1426     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1427     ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1428     ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1429
1430     /* number of sources != number of targets */
1431     shfo.pTo = "d.txt\0";
1432     shfo.fFlags |= FOF_MULTIDESTFILES;
1433     retval = SHFileOperationA(&shfo);
1434     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1435     ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1436
1437     /* FO_MOVE does not create dest directories */
1438     shfo.pFrom = "test2.txt\0";
1439     shfo.pTo = "dir1\\dir2\\test2.txt\0";
1440     retval = SHFileOperationA(&shfo);
1441     expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1442     ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
1443
1444     /* try to overwrite an existing file */
1445     shfo.pTo = "test3.txt\0";
1446     retval = SHFileOperationA(&shfo);
1447         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1448         ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1449     ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1450 }
1451
1452 static void test_sh_create_dir(void)
1453 {
1454     CHAR path[MAX_PATH];
1455     int ret;
1456
1457     if(!pSHCreateDirectoryExA)
1458     {
1459         win_skip("skipping SHCreateDirectoryExA tests\n");
1460         return;
1461     }
1462
1463     set_curr_dir_path(path, "testdir2\\test4.txt\0");
1464     ret = pSHCreateDirectoryExA(NULL, path, NULL);
1465     ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
1466     ok(file_exists("testdir2"), "The first directory is not created\n");
1467     ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
1468
1469     ret = pSHCreateDirectoryExA(NULL, path, NULL);
1470     ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
1471
1472     ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
1473     ok(file_exists("c:\\testdir3"), "The directory is not created\n");
1474 }
1475
1476 static void test_sh_path_prepare(void)
1477 {
1478     HRESULT res;
1479     CHAR path[MAX_PATH];
1480
1481     if(!pSHPathPrepareForWriteA)
1482     {
1483         win_skip("skipping SHPathPrepareForWriteA tests\n");
1484         return;
1485     }
1486
1487     /* directory exists, SHPPFW_NONE */
1488     set_curr_dir_path(path, "testdir2\0");
1489     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1490     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1491
1492     /* directory exists, SHPPFW_IGNOREFILENAME */
1493     set_curr_dir_path(path, "testdir2\\test4.txt\0");
1494     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
1495     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1496
1497     /* directory exists, SHPPFW_DIRCREATE */
1498     set_curr_dir_path(path, "testdir2\0");
1499     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1500     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1501
1502     /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1503     set_curr_dir_path(path, "testdir2\\test4.txt\0");
1504     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
1505     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1506     ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1507
1508     /* file exists, SHPPFW_NONE */
1509     set_curr_dir_path(path, "test1.txt\0");
1510     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1511     ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1512
1513     /* file exists, SHPPFW_DIRCREATE */
1514     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1515     ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1516
1517     /* file exists, SHPPFW_NONE, trailing \ */
1518     set_curr_dir_path(path, "test1.txt\\\0");
1519     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1520     ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1521
1522     /* relative path exists, SHPPFW_DIRCREATE */
1523     res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE);
1524     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1525
1526     /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
1527     res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE);
1528     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1529     ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
1530
1531     /* directory doesn't exist, SHPPFW_NONE */
1532     set_curr_dir_path(path, "nonexistent\0");
1533     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1534     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1535
1536     /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
1537     set_curr_dir_path(path, "nonexistent\\notreal\0");
1538     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
1539     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1540     ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
1541     ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1542
1543     /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1544     set_curr_dir_path(path, "testdir2\\test4.txt\\\0");
1545     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
1546     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1547     ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
1548
1549     /* nested directory doesn't exist, SHPPFW_DIRCREATE */
1550     set_curr_dir_path(path, "nonexistent\\notreal\0");
1551     res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1552     ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1553     ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
1554
1555     /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
1556
1557     if(!pSHPathPrepareForWriteW)
1558     {
1559         skip("Skipping SHPathPrepareForWriteW tests\n");
1560         return;
1561     }
1562     /* unicode directory doesn't exist, SHPPFW_NONE */
1563     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
1564     ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1565     ok(!file_existsW(UNICODE_PATH), "unicode path was created but shouldn't be\n");
1566     RemoveDirectoryW(UNICODE_PATH);
1567
1568     /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
1569     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
1570     ok(res == S_OK, "res == %08x, expected S_OK\n", res);
1571     ok(file_existsW(UNICODE_PATH), "unicode path should've been created\n");
1572
1573     /* unicode directory exists, SHPPFW_NONE */
1574     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
1575     ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
1576
1577     /* unicode directory exists, SHPPFW_DIRCREATE */
1578     res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
1579     ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
1580     RemoveDirectoryW(UNICODE_PATH);
1581 }
1582
1583 static void test_unicode(void)
1584 {
1585     SHFILEOPSTRUCTW shfoW;
1586     int ret;
1587     HANDLE file;
1588
1589     if (!pSHFileOperationW)
1590     {
1591         skip("SHFileOperationW() is missing\n");
1592         return;
1593     }
1594
1595     shfoW.hwnd = NULL;
1596     shfoW.wFunc = FO_DELETE;
1597     shfoW.pFrom = UNICODE_PATH;
1598     shfoW.pTo = '\0';
1599     shfoW.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1600     shfoW.hNameMappings = NULL;
1601     shfoW.lpszProgressTitle = NULL;
1602
1603     /* Clean up before start test */
1604     DeleteFileW(UNICODE_PATH);
1605     RemoveDirectoryW(UNICODE_PATH);
1606
1607     /* Make sure we are on a system that supports unicode */
1608     SetLastError(0xdeadbeef);
1609     file = CreateFileW(UNICODE_PATH, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1610     if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
1611     {
1612         skip("Unicode tests skipped on non-unicode system\n");
1613         return;
1614     }
1615     CloseHandle(file);
1616
1617     /* Try to delete a file with unicode filename */
1618     ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
1619     ret = pSHFileOperationW(&shfoW);
1620     ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
1621     ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
1622
1623     /* Try to trash a file with unicode filename */
1624     createTestFileW(UNICODE_PATH);
1625     shfoW.fFlags |= FOF_ALLOWUNDO;
1626     ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
1627     ret = pSHFileOperationW(&shfoW);
1628     ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
1629     ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
1630
1631     if(!pSHCreateDirectoryExW)
1632     {
1633         skip("Skipping SHCreateDirectoryExW tests\n");
1634         return;
1635     }
1636
1637     /* Try to delete a directory with unicode filename */
1638     ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
1639     ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
1640     ok(file_existsW(UNICODE_PATH), "The directory is not created\n");
1641     shfoW.fFlags &= ~FOF_ALLOWUNDO;
1642     ret = pSHFileOperationW(&shfoW);
1643     ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
1644     ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
1645
1646     /* Try to trash a directory with unicode filename */
1647     ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
1648     ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
1649     ok(file_existsW(UNICODE_PATH), "The directory was not created\n");
1650     shfoW.fFlags |= FOF_ALLOWUNDO;
1651     ret = pSHFileOperationW(&shfoW);
1652     ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
1653     ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
1654 }
1655
1656 START_TEST(shlfileop)
1657 {
1658     InitFunctionPointers();
1659
1660     clean_after_shfo_tests();
1661
1662     init_shfo_tests();
1663     test_get_file_info();
1664     test_get_file_info_iconlist();
1665     clean_after_shfo_tests();
1666
1667     init_shfo_tests();
1668     test_delete();
1669     clean_after_shfo_tests();
1670
1671     init_shfo_tests();
1672     test_rename();
1673     clean_after_shfo_tests();
1674
1675     init_shfo_tests();
1676     test_copy();
1677     clean_after_shfo_tests();
1678
1679     init_shfo_tests();
1680     test_move();
1681     clean_after_shfo_tests();
1682
1683     test_sh_create_dir();
1684     clean_after_shfo_tests();
1685
1686     init_shfo_tests();
1687     test_sh_path_prepare();
1688     clean_after_shfo_tests();
1689
1690     test_unicode();
1691 }