mcicda: Exclude unused headers.
[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 static CHAR CURR_DIR[MAX_PATH];
36
37 static HMODULE hshell32;
38 static int (WINAPI *pSHCreateDirectoryExA)(HWND, LPCSTR, LPSECURITY_ATTRIBUTES);
39
40 static void InitFunctionPointers(void)
41 {
42     hshell32 = GetModuleHandleA("shell32.dll");
43     pSHCreateDirectoryExA = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExA");
44 }
45
46 /* creates a file with the specified name for tests */
47 static void createTestFile(const CHAR *name)
48 {
49     HANDLE file;
50     DWORD written;
51
52     file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
53     ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
54     WriteFile(file, name, strlen(name), &written, NULL);
55     WriteFile(file, "\n", strlen("\n"), &written, NULL);
56     CloseHandle(file);
57 }
58
59 static BOOL file_exists(const CHAR *name)
60 {
61     return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
62 }
63
64 static BOOL file_has_content(const CHAR *name, const CHAR *content)
65 {
66     CHAR buf[MAX_PATH];
67     HANDLE file;
68     DWORD read;
69
70     file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
71     if (file == INVALID_HANDLE_VALUE)
72         return FALSE;
73     ReadFile(file, buf, MAX_PATH - 1, &read, NULL);
74     buf[read] = 0;
75     CloseHandle(file);
76     return strcmp(buf, content)==0;
77 }
78
79 /* initializes the tests */
80 static void init_shfo_tests(void)
81 {
82     int len;
83
84     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
85     len = lstrlenA(CURR_DIR);
86
87     if(len && (CURR_DIR[len-1] == '\\'))
88         CURR_DIR[len-1] = 0;
89
90     createTestFile("test1.txt");
91     createTestFile("test2.txt");
92     createTestFile("test3.txt");
93     createTestFile("test_5.txt");
94     CreateDirectoryA("test4.txt", NULL);
95     CreateDirectoryA("testdir2", NULL);
96     CreateDirectoryA("testdir2\\nested", NULL);
97     createTestFile("testdir2\\one.txt");
98     createTestFile("testdir2\\nested\\two.txt");
99 }
100
101 /* cleans after tests */
102 static void clean_after_shfo_tests(void)
103 {
104     DeleteFileA("test1.txt");
105     DeleteFileA("test2.txt");
106     DeleteFileA("test3.txt");
107     DeleteFileA("test_5.txt");
108     DeleteFileA("one.txt");
109     DeleteFileA("test4.txt\\test1.txt");
110     DeleteFileA("test4.txt\\test2.txt");
111     DeleteFileA("test4.txt\\test3.txt");
112     RemoveDirectoryA("test4.txt");
113     DeleteFileA("testdir2\\one.txt");
114     DeleteFileA("testdir2\\test1.txt");
115     DeleteFileA("testdir2\\test2.txt");
116     DeleteFileA("testdir2\\test3.txt");
117     DeleteFileA("testdir2\\test4.txt\\test1.txt");
118     DeleteFileA("testdir2\\nested\\two.txt");
119     RemoveDirectoryA("testdir2\\test4.txt");
120     RemoveDirectoryA("testdir2\\nested");
121     RemoveDirectoryA("testdir2");
122     RemoveDirectoryA("c:\\testdir3");
123     DeleteFileA("nonexistent\\notreal\\test2.txt");
124     RemoveDirectoryA("nonexistent\\notreal");
125     RemoveDirectoryA("nonexistent");
126 }
127
128
129 static void test_get_file_info(void)
130 {
131     DWORD rc, rc2;
132     SHFILEINFO shfi, shfi2;
133     char notepad[MAX_PATH];
134
135     /* Test some flag combinations that MSDN claims are not allowed,
136      * but which work anyway
137      */
138     shfi.dwAttributes=0xdeadbeef;
139     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
140                       &shfi, sizeof(shfi),
141                       SHGFI_ATTRIBUTES | SHGFI_USEFILEATTRIBUTES);
142     todo_wine ok(rc, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) failed\n");
143     if (rc)
144         ok(shfi.dwAttributes != 0xdeadbeef, "dwFileAttributes is not set\n");
145
146     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
147                       &shfi, sizeof(shfi),
148                       SHGFI_EXETYPE | SHGFI_USEFILEATTRIBUTES);
149     todo_wine ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) returned %d\n", rc);
150
151     /* Test SHGFI_USEFILEATTRIBUTES support */
152     strcpy(shfi.szDisplayName, "dummy");
153     shfi.iIcon=0xdeadbeef;
154     rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
155                       &shfi, sizeof(shfi),
156                       SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
157     ok(rc, "SHGetFileInfoA(c:\\nonexistent) failed\n");
158     if (rc)
159     {
160         ok(strcpy(shfi.szDisplayName, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
161         ok(shfi.iIcon != 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
162     }
163
164     /* Wine does not have a default icon for text files, and Windows 98 fails
165      * if we give it an empty executable. So use notepad.exe as the test
166      */
167     if (SearchPath(NULL, "notepad.exe", NULL, sizeof(notepad), notepad, NULL))
168     {
169         strcpy(shfi.szDisplayName, "dummy");
170         shfi.iIcon=0xdeadbeef;
171         rc=SHGetFileInfoA(notepad, GetFileAttributes(notepad),
172                           &shfi, sizeof(shfi),
173                           SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
174         ok(rc, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) failed\n", notepad);
175         strcpy(shfi2.szDisplayName, "dummy");
176         shfi2.iIcon=0xdeadbeef;
177         rc2=SHGetFileInfoA(notepad, 0,
178                            &shfi2, sizeof(shfi2),
179                            SHGFI_ICONLOCATION);
180         ok(rc2, "SHGetFileInfoA(%s) failed\n", notepad);
181         if (rc && rc2)
182         {
183             ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
184             ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
185         }
186     }
187
188     /* with a directory now */
189     strcpy(shfi.szDisplayName, "dummy");
190     shfi.iIcon=0xdeadbeef;
191     rc=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
192                       &shfi, sizeof(shfi),
193                       SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
194     ok(rc, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) failed\n");
195     strcpy(shfi2.szDisplayName, "dummy");
196     shfi2.iIcon=0xdeadbeef;
197     rc2=SHGetFileInfoA("test4.txt", 0,
198                       &shfi2, sizeof(shfi2),
199                       SHGFI_ICONLOCATION);
200     ok(rc2, "SHGetFileInfoA(test4.txt/) failed\n");
201     if (rc && rc2)
202     {
203         ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
204         ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
205     }
206 }
207
208
209 /*
210  puts into the specified buffer file names with current directory.
211  files - string with file names, separated by null characters. Ends on a double
212  null characters
213 */
214 static void set_curr_dir_path(CHAR *buf, const CHAR* files)
215 {
216     buf[0] = 0;
217     while (files[0])
218     {
219         strcpy(buf, CURR_DIR);
220         buf += strlen(buf);
221         buf[0] = '\\';
222         buf++;
223         strcpy(buf, files);
224         buf += strlen(buf) + 1;
225         files += strlen(files) + 1;
226     }
227     buf[0] = 0;
228 }
229
230
231 /* tests the FO_DELETE action */
232 static void test_delete(void)
233 {
234     SHFILEOPSTRUCTA shfo;
235     DWORD ret;
236     CHAR buf[sizeof(CURR_DIR)+sizeof("/test?.txt")+1];
237
238     sprintf(buf, "%s\\%s", CURR_DIR, "test?.txt");
239     buf[strlen(buf) + 1] = '\0';
240
241     shfo.hwnd = NULL;
242     shfo.wFunc = FO_DELETE;
243     shfo.pFrom = buf;
244     shfo.pTo = "\0";
245     shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
246     shfo.hNameMappings = NULL;
247     shfo.lpszProgressTitle = NULL;
248
249     ok(!SHFileOperationA(&shfo), "Deletion was not successful\n");
250     ok(file_exists("test4.txt"), "Directory should not have been removed\n");
251     ok(!file_exists("test1.txt"), "File should have been removed\n");
252
253     ret = SHFileOperationA(&shfo);
254     ok(!ret, "Directory exists, but is not removed, ret=%d\n", ret);
255     ok(file_exists("test4.txt"), "Directory should not have been removed\n");
256
257     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
258
259     ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
260     ok(!file_exists("test4.txt"), "Directory should have been removed\n");
261
262     ret = SHFileOperationA(&shfo);
263     ok(!ret, "The requested file does not exist, ret=%d\n", ret);
264
265     init_shfo_tests();
266     sprintf(buf, "%s\\%s", CURR_DIR, "test4.txt");
267     buf[strlen(buf) + 1] = '\0';
268     ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
269     ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
270     ok(!file_exists("test4.txt"), "Directory is not removed\n");
271
272     init_shfo_tests();
273     shfo.pFrom = "test1.txt\0test4.txt\0";
274     ok(!SHFileOperationA(&shfo), "Directory and a file are not removed\n");
275     ok(!file_exists("test1.txt"), "The file should have been removed\n");
276     ok(!file_exists("test4.txt"), "Directory should have been removed\n");
277     ok(file_exists("test2.txt"), "This file should not have been removed\n");
278
279     /* FOF_FILESONLY does not delete a dir matching a wildcard */
280     init_shfo_tests();
281     shfo.fFlags |= FOF_FILESONLY;
282     shfo.pFrom = "*.txt\0";
283     ok(!SHFileOperation(&shfo), "Failed to delete files\n");
284     ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
285     ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
286     ok(file_exists("test4.txt"), "test4.txt should not have been removed\n");
287
288     /* FOF_FILESONLY only deletes a dir if explicitly specified */
289     init_shfo_tests();
290     shfo.pFrom = "test_?.txt\0test4.txt\0";
291     ok(!SHFileOperation(&shfo), "Failed to delete files and directory\n");
292     ok(!file_exists("test4.txt"), "test4.txt should have been removed\n");
293     ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
294     ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
295
296     /* try to delete an invalid filename */
297     init_shfo_tests();
298     shfo.pFrom = "\0";
299     shfo.fFlags &= ~FOF_FILESONLY;
300     shfo.fAnyOperationsAborted = FALSE;
301     ret = SHFileOperation(&shfo);
302     ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
303     ok(!shfo.fAnyOperationsAborted, "Expected no aborted operations\n");
304     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
305
306     /* try an invalid function */
307     init_shfo_tests();
308     shfo.pFrom = "test1.txt\0";
309     shfo.wFunc = 0;
310     ret = SHFileOperation(&shfo);
311     ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
312     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
313
314     /* try an invalid list, only one null terminator */
315     init_shfo_tests();
316     shfo.pFrom = "";
317     shfo.wFunc = FO_DELETE;
318     ret = SHFileOperation(&shfo);
319     ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
320     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
321
322     /* delete a dir, and then a file inside the dir, same as
323     * deleting a nonexistent file
324     */
325     init_shfo_tests();
326     shfo.pFrom = "testdir2\0testdir2\\one.txt\0";
327     ret = SHFileOperation(&shfo);
328     ok(ret == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret);
329     ok(!file_exists("testdir2"), "Expected testdir2 to not exist\n");
330     ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
331
332     /* try the FOF_NORECURSION flag, continues deleting subdirs */
333     init_shfo_tests();
334     shfo.pFrom = "testdir2\0";
335     shfo.fFlags |= FOF_NORECURSION;
336     ret = SHFileOperation(&shfo);
337     ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
338     ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
339     ok(!file_exists("testdir2\\nested"), "Expected testdir2\\nested to exist\n");
340 }
341
342 /* tests the FO_RENAME action */
343 static void test_rename(void)
344 {
345     SHFILEOPSTRUCTA shfo, shfo2;
346     CHAR from[5*MAX_PATH];
347     CHAR to[5*MAX_PATH];
348     DWORD retval;
349
350     shfo.hwnd = NULL;
351     shfo.wFunc = FO_RENAME;
352     shfo.pFrom = from;
353     shfo.pTo = to;
354     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
355     shfo.hNameMappings = NULL;
356     shfo.lpszProgressTitle = NULL;
357
358     set_curr_dir_path(from, "test1.txt\0");
359     set_curr_dir_path(to, "test4.txt\0");
360     ok(SHFileOperationA(&shfo), "File is not renamed moving to other directory "
361        "when specifying directory name only\n");
362     ok(file_exists("test1.txt"), "The file is removed\n");
363
364     set_curr_dir_path(from, "test3.txt\0");
365     set_curr_dir_path(to, "test4.txt\\test1.txt\0");
366     ok(!SHFileOperationA(&shfo), "File is renamed moving to other directory\n");
367     ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
368
369     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
370     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
371     retval = SHFileOperationA(&shfo); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
372     ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
373        "Can't rename many files, retval = %d\n", retval);
374     ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
375
376     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
377     shfo2.fFlags |= FOF_MULTIDESTFILES;
378
379     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
380     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
381     retval = SHFileOperationA(&shfo2); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
382     ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
383        "Can't rename many files, retval = %d\n", retval);
384     ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
385
386     set_curr_dir_path(from, "test1.txt\0");
387     set_curr_dir_path(to, "test6.txt\0");
388     retval = SHFileOperationA(&shfo);
389     ok(!retval, "Rename file failed, retval = %d\n", retval);
390     ok(!file_exists("test1.txt"), "The file is not renamed\n");
391     ok(file_exists("test6.txt"), "The file is not renamed\n");
392
393     set_curr_dir_path(from, "test6.txt\0");
394     set_curr_dir_path(to, "test1.txt\0");
395     retval = SHFileOperationA(&shfo);
396     ok(!retval, "Rename file back failed, retval = %d\n", retval);
397
398     set_curr_dir_path(from, "test4.txt\0");
399     set_curr_dir_path(to, "test6.txt\0");
400     retval = SHFileOperationA(&shfo);
401     ok(!retval, "Rename dir failed, retval = %d\n", retval);
402     ok(!file_exists("test4.txt"), "The dir is not renamed\n");
403     ok(file_exists("test6.txt"), "The dir is not renamed\n");
404
405     set_curr_dir_path(from, "test6.txt\0");
406     set_curr_dir_path(to, "test4.txt\0");
407     retval = SHFileOperationA(&shfo);
408     ok(!retval, "Rename dir back failed, retval = %d\n", retval);
409
410     /* try to rename more than one file to a single file */
411     shfo.pFrom = "test1.txt\0test2.txt\0";
412     shfo.pTo = "a.txt\0";
413     retval = SHFileOperationA(&shfo);
414     ok(retval == ERROR_GEN_FAILURE, "Expected ERROR_GEN_FAILURE, got %d\n", retval);
415     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
416     ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
417
418     /* pFrom doesn't exist */
419     shfo.pFrom = "idontexist\0";
420     shfo.pTo = "newfile\0";
421     retval = SHFileOperationA(&shfo);
422     ok(retval == 1026, "Expected 1026, got %d\n", retval);
423     ok(!file_exists("newfile"), "Expected newfile to not exist\n");
424
425     /* pTo already exist */
426     shfo.pFrom = "test1.txt\0";
427     shfo.pTo = "test2.txt\0";
428     retval = SHFileOperationA(&shfo);
429         ok(retval == ERROR_ALREADY_EXISTS, "Expected ERROR_ALREADY_EXISTS, got %d\n", retval);
430
431     /* pFrom is valid, but pTo is empty */
432     shfo.pFrom = "test1.txt\0";
433     shfo.pTo = "\0";
434     retval = SHFileOperationA(&shfo);
435         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
436     ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
437
438     /* pFrom is empty */
439     shfo.pFrom = "\0";
440     retval = SHFileOperationA(&shfo);
441         ok(retval == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", retval);
442
443     /* pFrom is NULL, commented out because it crashes on nt 4.0 */
444 #if 0
445     shfo.pFrom = NULL;
446     retval = SHFileOperationA(&shfo);
447     ok(retval == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval);
448 #endif
449 }
450
451 /* tests the FO_COPY action */
452 static void test_copy(void)
453 {
454     SHFILEOPSTRUCTA shfo, shfo2;
455     CHAR from[5*MAX_PATH];
456     CHAR to[5*MAX_PATH];
457     FILEOP_FLAGS tmp_flags;
458     DWORD retval;
459
460     shfo.hwnd = NULL;
461     shfo.wFunc = FO_COPY;
462     shfo.pFrom = from;
463     shfo.pTo = to;
464     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
465     shfo.hNameMappings = NULL;
466     shfo.lpszProgressTitle = NULL;
467
468     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
469     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
470     ok(SHFileOperationA(&shfo), "Can't copy many files\n");
471     ok(!file_exists("test6.txt"), "The file is not copied - many files are "
472        "specified as a target\n");
473
474     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
475     shfo2.fFlags |= FOF_MULTIDESTFILES;
476
477     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
478     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
479     ok(!SHFileOperationA(&shfo2), "Can't copy many files\n");
480     ok(file_exists("test6.txt"), "The file is copied - many files are "
481        "specified as a target\n");
482     DeleteFileA("test6.txt");
483     DeleteFileA("test7.txt");
484     RemoveDirectoryA("test8.txt");
485
486     /* number of sources do not correspond to number of targets */
487     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
488     set_curr_dir_path(to, "test6.txt\0test7.txt\0");
489     ok(SHFileOperationA(&shfo2), "Can't copy many files\n");
490     ok(!file_exists("test6.txt"), "The file is not copied - many files are "
491        "specified as a target\n");
492
493     set_curr_dir_path(from, "test1.txt\0");
494     set_curr_dir_path(to, "test4.txt\0");
495     ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively\n");
496     ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
497
498     set_curr_dir_path(from, "test?.txt\0");
499     set_curr_dir_path(to, "testdir2\0");
500     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
501     ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
502     ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory\n");
503     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
504     ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
505     ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
506     clean_after_shfo_tests();
507
508     init_shfo_tests();
509     shfo.fFlags |= FOF_FILESONLY;
510     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
511     ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
512     ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
513     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
514     ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
515     clean_after_shfo_tests();
516
517     init_shfo_tests();
518     set_curr_dir_path(from, "test1.txt\0test2.txt\0");
519     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
520     ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
521     ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
522     ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
523     ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
524     clean_after_shfo_tests();
525
526     /* Copying multiple files with one not existing as source, fails the
527        entire operation in Win98/ME/2K/XP, but not in 95/NT */
528     init_shfo_tests();
529     tmp_flags = shfo.fFlags;
530     set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0");
531     ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
532     ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
533     retval = SHFileOperationA(&shfo);
534     if (!retval)
535         /* Win 95/NT returns success but copies only the files up to the nonexistent source */
536         ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
537     else
538     {
539         /* Win 98/ME/2K/XP fail the entire operation with return code 1026 if one source file does not exist */
540         ok(retval == 1026, "Files are copied to other directory\n");
541         ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
542     }
543     ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
544     shfo.fFlags = tmp_flags;
545
546     /* copy into a nonexistent directory */
547     init_shfo_tests();
548     shfo.fFlags = FOF_NOCONFIRMMKDIR;
549     set_curr_dir_path(from, "test1.txt\0");
550     set_curr_dir_path(to, "nonexistent\\notreal\\test2.txt\0");
551     retval= SHFileOperation(&shfo);
552         ok(!retval, "Error copying into nonexistent directory\n");
553         ok(file_exists("nonexistent"), "nonexistent not created\n");
554         ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
555         ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
556     ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
557
558     /* a relative dest directory is OK */
559     clean_after_shfo_tests();
560     init_shfo_tests();
561     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
562     shfo.pTo = "testdir2\0";
563     retval = SHFileOperation(&shfo);
564     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
565     ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
566
567     /* try to copy files to a file */
568     clean_after_shfo_tests();
569     init_shfo_tests();
570     shfo.pFrom = from;
571     shfo.pTo = to;
572     set_curr_dir_path(from, "test1.txt\0test2.txt\0");
573     set_curr_dir_path(to, "test3.txt\0");
574     retval = SHFileOperation(&shfo);
575         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
576     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
577     ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
578
579     /* try to copy many files to nonexistent directory */
580     DeleteFile(to);
581     shfo.fAnyOperationsAborted = FALSE;
582     retval = SHFileOperation(&shfo);
583         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
584         ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
585         ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
586         ok(RemoveDirectory(to), "Expected test3.txt to exist\n");
587
588     /* send in FOF_MULTIDESTFILES with too many destination files */
589     init_shfo_tests();
590     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
591     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
592     shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
593     retval = SHFileOperation(&shfo);
594         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
595     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
596     ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
597
598     /* send in FOF_MULTIDESTFILES with too many destination files */
599     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
600     shfo.pTo = "e.txt\0f.txt\0";
601     shfo.fAnyOperationsAborted = FALSE;
602     retval = SHFileOperation(&shfo);
603         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
604     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
605     ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
606
607     /* use FOF_MULTIDESTFILES with files and a source directory */
608     shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
609     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
610     shfo.fAnyOperationsAborted = FALSE;
611     retval = SHFileOperation(&shfo);
612     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
613     ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
614     ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
615     ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
616
617     /* try many dest files without FOF_MULTIDESTFILES flag */
618     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
619     shfo.pTo = "a.txt\0b.txt\0c.txt\0";
620     shfo.fAnyOperationsAborted = FALSE;
621     shfo.fFlags &= ~FOF_MULTIDESTFILES;
622     retval = SHFileOperation(&shfo);
623         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
624     ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
625
626     /* try a glob */
627     shfo.pFrom = "test?.txt\0";
628     shfo.pTo = "testdir2\0";
629     shfo.fFlags &= ~FOF_MULTIDESTFILES;
630     retval = SHFileOperation(&shfo);
631         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
632         ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
633
634     /* try a glob with FOF_FILESONLY */
635     clean_after_shfo_tests();
636     init_shfo_tests();
637     shfo.pFrom = "test?.txt\0";
638     shfo.fFlags |= FOF_FILESONLY;
639     retval = SHFileOperation(&shfo);
640         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
641         ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
642     ok(!file_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
643
644     /* try a glob with FOF_MULTIDESTFILES and the same number
645     * of dest files that we would expect
646     */
647     clean_after_shfo_tests();
648     init_shfo_tests();
649     shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
650     shfo.fFlags &= ~FOF_FILESONLY;
651     shfo.fFlags |= FOF_MULTIDESTFILES;
652     retval = SHFileOperation(&shfo);
653         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
654     ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
655     ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
656     ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
657
658     /* copy one file to two others, second is ignored */
659     clean_after_shfo_tests();
660     init_shfo_tests();
661     shfo.pFrom = "test1.txt\0";
662     shfo.pTo = "b.txt\0c.txt\0";
663     shfo.fAnyOperationsAborted = FALSE;
664     retval = SHFileOperation(&shfo);
665         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
666         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
667     ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
668
669     /* copy two file to three others, all fail */
670     shfo.pFrom = "test1.txt\0test2.txt\0";
671     shfo.pTo = "b.txt\0c.txt\0d.txt\0";
672     retval = SHFileOperation(&shfo);
673         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
674     ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
675     ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
676
677     /* copy one file and one directory to three others */
678     shfo.pFrom = "test1.txt\0test4.txt\0";
679     shfo.pTo = "b.txt\0c.txt\0d.txt\0";
680     shfo.fAnyOperationsAborted = FALSE;
681     retval = SHFileOperation(&shfo);
682         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
683     ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
684     ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
685     ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
686
687     /* copy a directory with a file beneath it, plus some files */
688     createTestFile("test4.txt\\a.txt");
689     shfo.pFrom = "test4.txt\0test1.txt\0";
690     shfo.pTo = "testdir2\0";
691     shfo.fFlags &= ~FOF_MULTIDESTFILES;
692     shfo.fAnyOperationsAborted = FALSE;
693     retval = SHFileOperation(&shfo);
694     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
695     ok(DeleteFile("testdir2\\test1.txt"), "Expected newdir\\test1.txt to exist\n");
696     ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
697     ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
698
699     /* copy one directory and a file in that dir to another dir */
700     shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
701     shfo.pTo = "testdir2\0";
702     retval = SHFileOperation(&shfo);
703     ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
704     ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
705     ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
706
707     /* copy a file in a directory first, and then the directory to a nonexistent dir */
708     shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
709     shfo.pTo = "nonexistent\0";
710     retval = SHFileOperation(&shfo);
711         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
712     ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
713     ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
714     DeleteFile("test4.txt\\a.txt");
715
716     /* destination is same as source file */
717     shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
718     shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
719     shfo.fAnyOperationsAborted = FALSE;
720     shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
721     retval = SHFileOperation(&shfo);
722         ok(retval == ERROR_NO_MORE_SEARCH_HANDLES,
723            "Expected ERROR_NO_MORE_SEARCH_HANDLES, got %d\n", retval);
724         ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
725         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
726     ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
727
728     /* destination is same as source directory */
729     shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
730     shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
731     shfo.fAnyOperationsAborted = FALSE;
732     retval = SHFileOperation(&shfo);
733         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
734         ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
735     ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
736
737     /* copy a directory into itself, error displayed in UI */
738     shfo.pFrom = "test4.txt\0";
739     shfo.pTo = "test4.txt\\newdir\0";
740     shfo.fFlags &= ~FOF_MULTIDESTFILES;
741     shfo.fAnyOperationsAborted = FALSE;
742     retval = SHFileOperation(&shfo);
743         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
744     ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
745
746     /* copy a directory to itself, error displayed in UI */
747     shfo.pFrom = "test4.txt\0";
748     shfo.pTo = "test4.txt\0";
749     shfo.fAnyOperationsAborted = FALSE;
750     retval = SHFileOperation(&shfo);
751         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
752
753     /* copy a file into a directory, and the directory into itself */
754     shfo.pFrom = "test1.txt\0test4.txt\0";
755     shfo.pTo = "test4.txt\0";
756     shfo.fAnyOperationsAborted = FALSE;
757     shfo.fFlags |= FOF_NOCONFIRMATION;
758     retval = SHFileOperation(&shfo);
759         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
760     ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
761
762     /* copy a file to a file, and the directory into itself */
763     shfo.pFrom = "test1.txt\0test4.txt\0";
764     shfo.pTo = "test4.txt\\a.txt\0";
765     shfo.fAnyOperationsAborted = FALSE;
766     retval = SHFileOperation(&shfo);
767         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
768     ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
769
770     /* copy a nonexistent file to a nonexistent directory */
771     shfo.pFrom = "e.txt\0";
772     shfo.pTo = "nonexistent\0";
773     shfo.fAnyOperationsAborted = FALSE;
774     retval = SHFileOperation(&shfo);
775     ok(retval == 1026, "Expected 1026, got %d\n", retval);
776     ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
777     ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
778
779     /* Overwrite tests */
780     clean_after_shfo_tests();
781     init_shfo_tests();
782     shfo.fFlags = FOF_NOCONFIRMATION;
783     shfo.pFrom = "test1.txt\0";
784     shfo.pTo = "test2.txt\0";
785     shfo.fAnyOperationsAborted = FALSE;
786     /* without FOF_NOCOFIRMATION the confirmation is Yes/No */
787     retval = SHFileOperation(&shfo);
788     ok(retval == 0, "Expected 0, got %d\n", retval);
789     ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
790
791     shfo.pFrom = "test3.txt\0test1.txt\0";
792     shfo.pTo = "test2.txt\0one.txt\0";
793     shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
794     /* without FOF_NOCOFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
795     retval = SHFileOperation(&shfo);
796     ok(retval == 0, "Expected 0, got %d\n", retval);
797     ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
798
799     shfo.pFrom = "one.txt\0";
800     shfo.pTo = "testdir2\0";
801     shfo.fFlags = FOF_NOCONFIRMATION;
802     /* without FOF_NOCOFIRMATION the confirmation is Yes/No */
803     retval = SHFileOperation(&shfo);
804     ok(retval == 0, "Expected 0, got %d\n", retval);
805     ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
806
807     createTestFile("test4.txt\\test1.txt");
808     shfo.pFrom = "test4.txt\0";
809     shfo.pTo = "testdir2\0";
810     shfo.fFlags = FOF_NOCONFIRMATION;
811     ok(!SHFileOperation(&shfo), "First SHFileOperation failed\n");
812     createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
813     /* without FOF_NOCOFIRMATION the confirmation is "This folder already contains a folder named ..." */
814     retval = SHFileOperation(&shfo);
815     ok(retval == 0, "Expected 0, got %d\n", retval);
816     ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
817 }
818
819 /* tests the FO_MOVE action */
820 static void test_move(void)
821 {
822     SHFILEOPSTRUCTA shfo, shfo2;
823     CHAR from[5*MAX_PATH];
824     CHAR to[5*MAX_PATH];
825     DWORD retval;
826
827     shfo.hwnd = NULL;
828     shfo.wFunc = FO_MOVE;
829     shfo.pFrom = from;
830     shfo.pTo = to;
831     shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
832     shfo.hNameMappings = NULL;
833     shfo.lpszProgressTitle = NULL;
834
835     set_curr_dir_path(from, "test1.txt\0");
836     set_curr_dir_path(to, "test4.txt\0");
837     ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
838     ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
839     ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
840
841     set_curr_dir_path(from, "test?.txt\0");
842     set_curr_dir_path(to, "testdir2\0");
843     ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
844     ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
845     ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
846     ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
847     ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
848     ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
849
850     clean_after_shfo_tests();
851     init_shfo_tests();
852
853     memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
854     shfo2.fFlags |= FOF_MULTIDESTFILES;
855
856     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
857     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
858     ok(!SHFileOperationA(&shfo2), "Move many files\n");
859     ok(file_exists("test6.txt"), "The file is moved - many files are "
860        "specified as a target\n");
861     DeleteFileA("test6.txt");
862     DeleteFileA("test7.txt");
863     RemoveDirectoryA("test8.txt");
864
865     init_shfo_tests();
866
867     /* number of sources do not correspond to number of targets */
868     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
869     set_curr_dir_path(to, "test6.txt\0test7.txt\0");
870     ok(SHFileOperationA(&shfo2), "Can't move many files\n");
871     ok(!file_exists("test6.txt"), "The file is not moved - many files are "
872        "specified as a target\n");
873
874     init_shfo_tests();
875
876     set_curr_dir_path(from, "test3.txt\0");
877     set_curr_dir_path(to, "test4.txt\\test1.txt\0");
878     ok(!SHFileOperationA(&shfo), "File is moved moving to other directory\n");
879     ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
880
881     set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
882     set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
883     ok(SHFileOperationA(&shfo), "Cannot move many files\n");
884     ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
885     ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
886
887     set_curr_dir_path(from, "test1.txt\0");
888     set_curr_dir_path(to, "test6.txt\0");
889     ok(!SHFileOperationA(&shfo), "Move file\n");
890     ok(!file_exists("test1.txt"), "The file is moved\n");
891     ok(file_exists("test6.txt"), "The file is moved\n");
892     set_curr_dir_path(from, "test6.txt\0");
893     set_curr_dir_path(to, "test1.txt\0");
894     ok(!SHFileOperationA(&shfo), "Move file back\n");
895
896     set_curr_dir_path(from, "test4.txt\0");
897     set_curr_dir_path(to, "test6.txt\0");
898     ok(!SHFileOperationA(&shfo), "Move dir\n");
899     ok(!file_exists("test4.txt"), "The dir is moved\n");
900     ok(file_exists("test6.txt"), "The dir is moved\n");
901     set_curr_dir_path(from, "test6.txt\0");
902     set_curr_dir_path(to, "test4.txt\0");
903     ok(!SHFileOperationA(&shfo), "Move dir back\n");
904
905     /* move one file to two others */
906     init_shfo_tests();
907     shfo.pFrom = "test1.txt\0";
908     shfo.pTo = "a.txt\0b.txt\0";
909     retval = SHFileOperationA(&shfo);
910         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
911         ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
912         ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
913     ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
914
915     /* move two files to one other */
916     shfo.pFrom = "test2.txt\0test3.txt\0";
917     shfo.pTo = "test1.txt\0";
918     retval = SHFileOperationA(&shfo);
919         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
920         ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
921     ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
922     ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
923
924     /* move a directory into itself */
925     shfo.pFrom = "test4.txt\0";
926     shfo.pTo = "test4.txt\\b.txt\0";
927     retval = SHFileOperationA(&shfo);
928         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
929     ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
930     ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
931
932     /* move many files without FOF_MULTIDESTFILES */
933     shfo.pFrom = "test2.txt\0test3.txt\0";
934     shfo.pTo = "d.txt\0e.txt\0";
935     retval = SHFileOperationA(&shfo);
936         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
937     ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
938     ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
939
940     /* number of sources != number of targets */
941     shfo.pTo = "d.txt\0";
942     shfo.fFlags |= FOF_MULTIDESTFILES;
943     retval = SHFileOperationA(&shfo);
944         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
945     ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
946
947     /* FO_MOVE does not create dest directories */
948     shfo.pFrom = "test2.txt\0";
949     shfo.pTo = "dir1\\dir2\\test2.txt\0";
950     retval = SHFileOperationA(&shfo);
951         ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
952     ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
953
954     /* try to overwrite an existing file */
955     shfo.pTo = "test3.txt\0";
956     retval = SHFileOperationA(&shfo);
957         ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
958         ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
959     ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
960 }
961
962 static void test_sh_create_dir(void)
963 {
964     CHAR path[MAX_PATH];
965     int ret;
966
967     if(!pSHCreateDirectoryExA)
968     {
969         trace("skipping SHCreateDirectoryExA tests\n");
970         return;
971     }
972
973     set_curr_dir_path(path, "testdir2\\test4.txt\0");
974     ret = pSHCreateDirectoryExA(NULL, path, NULL);
975     ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
976     ok(file_exists("testdir2"), "The first directory is not created\n");
977     ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
978
979     ret = pSHCreateDirectoryExA(NULL, path, NULL);
980     ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
981
982     ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
983     ok(file_exists("c:\\testdir3"), "The directory is not created\n");
984 }
985
986 START_TEST(shlfileop)
987 {
988     InitFunctionPointers();
989
990     clean_after_shfo_tests();
991
992     init_shfo_tests();
993     test_get_file_info();
994     clean_after_shfo_tests();
995
996     init_shfo_tests();
997     test_delete();
998     clean_after_shfo_tests();
999
1000     init_shfo_tests();
1001     test_rename();
1002     clean_after_shfo_tests();
1003
1004     init_shfo_tests();
1005     test_copy();
1006     clean_after_shfo_tests();
1007
1008     init_shfo_tests();
1009     test_move();
1010     clean_after_shfo_tests();
1011
1012     test_sh_create_dir();
1013     clean_after_shfo_tests();
1014 }