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