2 * Unit test of the SHFileOperation function.
4 * Copyright 2002 Andriy Palamarchuk
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.
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.
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
24 #define WINE_NOWINSOCK
29 #include "wine/test.h"
31 #ifndef FOF_NORECURSION
32 #define FOF_NORECURSION 0x1000
35 static CHAR CURR_DIR[MAX_PATH];
36 static const WCHAR UNICODE_PATH[] = {'c',':','\\',0x00c4,'\0','\0'};
37 /* "c:\Ä", or "c:\A" with diaeresis */
38 /* Double-null termination needed for pFrom field of SHFILEOPSTRUCT */
40 static HMODULE hshell32;
41 static int (WINAPI *pSHCreateDirectoryExA)(HWND, LPCSTR, LPSECURITY_ATTRIBUTES);
42 static int (WINAPI *pSHCreateDirectoryExW)(HWND, LPCWSTR, LPSECURITY_ATTRIBUTES);
43 static int (WINAPI *pSHFileOperationW)(LPSHFILEOPSTRUCTW);
44 static int (WINAPI *pSHPathPrepareForWriteA)(HWND, IUnknown*, LPCSTR, DWORD);
45 static int (WINAPI *pSHPathPrepareForWriteW)(HWND, IUnknown*, LPCWSTR, DWORD);
47 static void InitFunctionPointers(void)
49 hshell32 = GetModuleHandleA("shell32.dll");
50 pSHCreateDirectoryExA = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExA");
51 pSHCreateDirectoryExW = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExW");
52 pSHFileOperationW = (void*)GetProcAddress(hshell32, "SHFileOperationW");
53 pSHPathPrepareForWriteA = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteA");
54 pSHPathPrepareForWriteW = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteW");
57 /* creates a file with the specified name for tests */
58 static void createTestFile(const CHAR *name)
63 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
64 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
65 WriteFile(file, name, strlen(name), &written, NULL);
66 WriteFile(file, "\n", strlen("\n"), &written, NULL);
70 static void createTestFileW(const WCHAR *name)
74 file = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
75 ok(file != INVALID_HANDLE_VALUE, "Failure to open file\n");
79 static BOOL file_exists(const CHAR *name)
81 return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
84 static BOOL file_existsW(LPCWSTR name)
86 return GetFileAttributesW(name) != INVALID_FILE_ATTRIBUTES;
89 static BOOL file_has_content(const CHAR *name, const CHAR *content)
95 file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
96 if (file == INVALID_HANDLE_VALUE)
98 ReadFile(file, buf, MAX_PATH - 1, &read, NULL);
101 return strcmp(buf, content)==0;
104 /* initializes the tests */
105 static void init_shfo_tests(void)
109 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
110 len = lstrlenA(CURR_DIR);
112 if(len && (CURR_DIR[len-1] == '\\'))
115 createTestFile("test1.txt");
116 createTestFile("test2.txt");
117 createTestFile("test3.txt");
118 createTestFile("test_5.txt");
119 CreateDirectoryA("test4.txt", NULL);
120 CreateDirectoryA("testdir2", NULL);
121 CreateDirectoryA("testdir2\\nested", NULL);
122 createTestFile("testdir2\\one.txt");
123 createTestFile("testdir2\\nested\\two.txt");
126 /* cleans after tests */
127 static void clean_after_shfo_tests(void)
129 DeleteFileA("test1.txt");
130 DeleteFileA("test2.txt");
131 DeleteFileA("test3.txt");
132 DeleteFileA("test_5.txt");
133 DeleteFileA("one.txt");
134 DeleteFileA("test4.txt\\test1.txt");
135 DeleteFileA("test4.txt\\test2.txt");
136 DeleteFileA("test4.txt\\test3.txt");
137 RemoveDirectoryA("test4.txt");
138 DeleteFileA("testdir2\\one.txt");
139 DeleteFileA("testdir2\\test1.txt");
140 DeleteFileA("testdir2\\test2.txt");
141 DeleteFileA("testdir2\\test3.txt");
142 DeleteFileA("testdir2\\test4.txt\\test1.txt");
143 DeleteFileA("testdir2\\nested\\two.txt");
144 RemoveDirectoryA("testdir2\\test4.txt");
145 RemoveDirectoryA("testdir2\\nested");
146 RemoveDirectoryA("testdir2");
147 RemoveDirectoryA("c:\\testdir3");
148 DeleteFileA("nonexistent\\notreal\\test2.txt");
149 RemoveDirectoryA("nonexistent\\notreal");
150 RemoveDirectoryA("nonexistent");
154 static void test_get_file_info(void)
157 SHFILEINFO shfi, shfi2;
158 char notepad[MAX_PATH];
160 /* Test some flag combinations that MSDN claims are not allowed,
161 * but which work anyway
163 shfi.dwAttributes=0xdeadbeef;
164 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
166 SHGFI_ATTRIBUTES | SHGFI_USEFILEATTRIBUTES);
167 todo_wine ok(rc, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) failed\n");
169 ok(shfi.dwAttributes != 0xdeadbeef, "dwFileAttributes is not set\n");
171 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
173 SHGFI_EXETYPE | SHGFI_USEFILEATTRIBUTES);
174 todo_wine ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) returned %d\n", rc);
176 /* Test SHGFI_USEFILEATTRIBUTES support */
177 strcpy(shfi.szDisplayName, "dummy");
178 shfi.iIcon=0xdeadbeef;
179 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
181 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
182 ok(rc, "SHGetFileInfoA(c:\\nonexistent) failed\n");
185 ok(strcpy(shfi.szDisplayName, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
186 ok(shfi.iIcon != 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
189 /* Wine does not have a default icon for text files, and Windows 98 fails
190 * if we give it an empty executable. So use notepad.exe as the test
192 if (SearchPath(NULL, "notepad.exe", NULL, sizeof(notepad), notepad, NULL))
194 strcpy(shfi.szDisplayName, "dummy");
195 shfi.iIcon=0xdeadbeef;
196 rc=SHGetFileInfoA(notepad, GetFileAttributes(notepad),
198 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
199 ok(rc, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) failed\n", notepad);
200 strcpy(shfi2.szDisplayName, "dummy");
201 shfi2.iIcon=0xdeadbeef;
202 rc2=SHGetFileInfoA(notepad, 0,
203 &shfi2, sizeof(shfi2),
205 ok(rc2, "SHGetFileInfoA(%s) failed\n", notepad);
208 ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
209 ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
213 /* with a directory now */
214 strcpy(shfi.szDisplayName, "dummy");
215 shfi.iIcon=0xdeadbeef;
216 rc=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
218 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
219 ok(rc, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) failed\n");
220 strcpy(shfi2.szDisplayName, "dummy");
221 shfi2.iIcon=0xdeadbeef;
222 rc2=SHGetFileInfoA("test4.txt", 0,
223 &shfi2, sizeof(shfi2),
225 ok(rc2, "SHGetFileInfoA(test4.txt/) failed\n");
228 ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
229 ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
235 puts into the specified buffer file names with current directory.
236 files - string with file names, separated by null characters. Ends on a double
239 static void set_curr_dir_path(CHAR *buf, const CHAR* files)
244 strcpy(buf, CURR_DIR);
249 buf += strlen(buf) + 1;
250 files += strlen(files) + 1;
256 /* tests the FO_DELETE action */
257 static void test_delete(void)
259 SHFILEOPSTRUCTA shfo;
261 CHAR buf[sizeof(CURR_DIR)+sizeof("/test?.txt")+1];
263 sprintf(buf, "%s\\%s", CURR_DIR, "test?.txt");
264 buf[strlen(buf) + 1] = '\0';
267 shfo.wFunc = FO_DELETE;
270 shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
271 shfo.hNameMappings = NULL;
272 shfo.lpszProgressTitle = NULL;
274 ok(!SHFileOperationA(&shfo), "Deletion was not successful\n");
275 ok(file_exists("test4.txt"), "Directory should not have been removed\n");
276 ok(!file_exists("test1.txt"), "File should have been removed\n");
278 ret = SHFileOperationA(&shfo);
279 ok(!ret, "Directory exists, but is not removed, ret=%d\n", ret);
280 ok(file_exists("test4.txt"), "Directory should not have been removed\n");
282 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
284 ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
285 ok(!file_exists("test4.txt"), "Directory should have been removed\n");
287 ret = SHFileOperationA(&shfo);
288 ok(!ret, "The requested file does not exist, ret=%d\n", ret);
291 sprintf(buf, "%s\\%s", CURR_DIR, "test4.txt");
292 buf[strlen(buf) + 1] = '\0';
293 ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
294 ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
295 ok(!file_exists("test4.txt"), "Directory is not removed\n");
298 shfo.pFrom = "test1.txt\0test4.txt\0";
299 ok(!SHFileOperationA(&shfo), "Directory and a file are not removed\n");
300 ok(!file_exists("test1.txt"), "The file should have been removed\n");
301 ok(!file_exists("test4.txt"), "Directory should have been removed\n");
302 ok(file_exists("test2.txt"), "This file should not have been removed\n");
304 /* FOF_FILESONLY does not delete a dir matching a wildcard */
306 shfo.fFlags |= FOF_FILESONLY;
307 shfo.pFrom = "*.txt\0";
308 ok(!SHFileOperation(&shfo), "Failed to delete files\n");
309 ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
310 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
311 ok(file_exists("test4.txt"), "test4.txt should not have been removed\n");
313 /* FOF_FILESONLY only deletes a dir if explicitly specified */
315 shfo.pFrom = "test_?.txt\0test4.txt\0";
316 ok(!SHFileOperation(&shfo), "Failed to delete files and directory\n");
317 ok(!file_exists("test4.txt"), "test4.txt should have been removed\n");
318 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
319 ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
321 /* try to delete an invalid filename */
324 shfo.fFlags &= ~FOF_FILESONLY;
325 shfo.fAnyOperationsAborted = FALSE;
326 ret = SHFileOperation(&shfo);
327 ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
328 ok(!shfo.fAnyOperationsAborted, "Expected no aborted operations\n");
329 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
331 /* try an invalid function */
333 shfo.pFrom = "test1.txt\0";
335 ret = SHFileOperation(&shfo);
336 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
337 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
339 /* try an invalid list, only one null terminator */
342 shfo.wFunc = FO_DELETE;
343 ret = SHFileOperation(&shfo);
344 ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
345 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
347 /* delete a dir, and then a file inside the dir, same as
348 * deleting a nonexistent file
351 shfo.pFrom = "testdir2\0testdir2\\one.txt\0";
352 ret = SHFileOperation(&shfo);
353 ok(ret == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret);
354 ok(!file_exists("testdir2"), "Expected testdir2 to not exist\n");
355 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
357 /* try the FOF_NORECURSION flag, continues deleting subdirs */
359 shfo.pFrom = "testdir2\0";
360 shfo.fFlags |= FOF_NORECURSION;
361 ret = SHFileOperation(&shfo);
362 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
363 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
364 ok(!file_exists("testdir2\\nested"), "Expected testdir2\\nested to exist\n");
367 /* tests the FO_RENAME action */
368 static void test_rename(void)
370 SHFILEOPSTRUCTA shfo, shfo2;
371 CHAR from[5*MAX_PATH];
376 shfo.wFunc = FO_RENAME;
379 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
380 shfo.hNameMappings = NULL;
381 shfo.lpszProgressTitle = NULL;
383 set_curr_dir_path(from, "test1.txt\0");
384 set_curr_dir_path(to, "test4.txt\0");
385 ok(SHFileOperationA(&shfo), "File is not renamed moving to other directory "
386 "when specifying directory name only\n");
387 ok(file_exists("test1.txt"), "The file is removed\n");
389 set_curr_dir_path(from, "test3.txt\0");
390 set_curr_dir_path(to, "test4.txt\\test1.txt\0");
391 ok(!SHFileOperationA(&shfo), "File is renamed moving to other directory\n");
392 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
394 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
395 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
396 retval = SHFileOperationA(&shfo); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
397 ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
398 "Can't rename many files, retval = %d\n", retval);
399 ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
401 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
402 shfo2.fFlags |= FOF_MULTIDESTFILES;
404 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
405 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
406 retval = SHFileOperationA(&shfo2); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
407 ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
408 "Can't rename many files, retval = %d\n", retval);
409 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
411 set_curr_dir_path(from, "test1.txt\0");
412 set_curr_dir_path(to, "test6.txt\0");
413 retval = SHFileOperationA(&shfo);
414 ok(!retval, "Rename file failed, retval = %d\n", retval);
415 ok(!file_exists("test1.txt"), "The file is not renamed\n");
416 ok(file_exists("test6.txt"), "The file is not renamed\n");
418 set_curr_dir_path(from, "test6.txt\0");
419 set_curr_dir_path(to, "test1.txt\0");
420 retval = SHFileOperationA(&shfo);
421 ok(!retval, "Rename file back failed, retval = %d\n", retval);
423 set_curr_dir_path(from, "test4.txt\0");
424 set_curr_dir_path(to, "test6.txt\0");
425 retval = SHFileOperationA(&shfo);
426 ok(!retval, "Rename dir failed, retval = %d\n", retval);
427 ok(!file_exists("test4.txt"), "The dir is not renamed\n");
428 ok(file_exists("test6.txt"), "The dir is not renamed\n");
430 set_curr_dir_path(from, "test6.txt\0");
431 set_curr_dir_path(to, "test4.txt\0");
432 retval = SHFileOperationA(&shfo);
433 ok(!retval, "Rename dir back failed, retval = %d\n", retval);
435 /* try to rename more than one file to a single file */
436 shfo.pFrom = "test1.txt\0test2.txt\0";
437 shfo.pTo = "a.txt\0";
438 retval = SHFileOperationA(&shfo);
439 ok(retval == ERROR_GEN_FAILURE, "Expected ERROR_GEN_FAILURE, got %d\n", retval);
440 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
441 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
443 /* pFrom doesn't exist */
444 shfo.pFrom = "idontexist\0";
445 shfo.pTo = "newfile\0";
446 retval = SHFileOperationA(&shfo);
447 ok(retval == 1026, "Expected 1026, got %d\n", retval);
448 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
450 /* pTo already exist */
451 shfo.pFrom = "test1.txt\0";
452 shfo.pTo = "test2.txt\0";
453 retval = SHFileOperationA(&shfo);
454 ok(retval == ERROR_ALREADY_EXISTS, "Expected ERROR_ALREADY_EXISTS, got %d\n", retval);
456 /* pFrom is valid, but pTo is empty */
457 shfo.pFrom = "test1.txt\0";
459 retval = SHFileOperationA(&shfo);
460 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
461 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
465 retval = SHFileOperationA(&shfo);
466 ok(retval == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", retval);
468 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
471 retval = SHFileOperationA(&shfo);
472 ok(retval == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval);
476 /* tests the FO_COPY action */
477 static void test_copy(void)
479 SHFILEOPSTRUCTA shfo, shfo2;
480 CHAR from[5*MAX_PATH];
482 FILEOP_FLAGS tmp_flags;
487 shfo.wFunc = FO_COPY;
490 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
491 shfo.hNameMappings = NULL;
492 shfo.lpszProgressTitle = NULL;
494 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
495 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
496 ok(SHFileOperationA(&shfo), "Can't copy many files\n");
497 ok(!file_exists("test6.txt"), "The file is not copied - many files are "
498 "specified as a target\n");
500 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
501 shfo2.fFlags |= FOF_MULTIDESTFILES;
503 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
504 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
505 ok(!SHFileOperationA(&shfo2), "Can't copy many files\n");
506 ok(file_exists("test6.txt"), "The file is copied - many files are "
507 "specified as a target\n");
508 DeleteFileA("test6.txt");
509 DeleteFileA("test7.txt");
510 RemoveDirectoryA("test8.txt");
512 /* number of sources do not correspond to number of targets */
513 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
514 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
515 ok(SHFileOperationA(&shfo2), "Can't copy many files\n");
516 ok(!file_exists("test6.txt"), "The file is not copied - many files are "
517 "specified as a target\n");
519 set_curr_dir_path(from, "test1.txt\0");
520 set_curr_dir_path(to, "test4.txt\0");
521 ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively\n");
522 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
524 set_curr_dir_path(from, "test?.txt\0");
525 set_curr_dir_path(to, "testdir2\0");
526 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
527 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
528 ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory\n");
529 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
530 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
531 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
532 clean_after_shfo_tests();
535 shfo.fFlags |= FOF_FILESONLY;
536 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
537 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
538 ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
539 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
540 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
541 clean_after_shfo_tests();
544 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
545 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
546 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
547 ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
548 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
549 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
550 clean_after_shfo_tests();
552 /* Copying multiple files with one not existing as source, fails the
553 entire operation in Win98/ME/2K/XP, but not in 95/NT */
555 tmp_flags = shfo.fFlags;
556 set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0");
557 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
558 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
559 retval = SHFileOperationA(&shfo);
561 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
562 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
565 /* Win 98/ME/2K/XP fail the entire operation with return code 1026 if one source file does not exist */
566 ok(retval == 1026, "Files are copied to other directory\n");
567 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
569 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
570 shfo.fFlags = tmp_flags;
572 /* copy into a nonexistent directory */
574 shfo.fFlags = FOF_NOCONFIRMMKDIR;
575 set_curr_dir_path(from, "test1.txt\0");
576 set_curr_dir_path(to, "nonexistent\\notreal\\test2.txt\0");
577 retval= SHFileOperation(&shfo);
578 ok(!retval, "Error copying into nonexistent directory\n");
579 ok(file_exists("nonexistent"), "nonexistent not created\n");
580 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
581 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
582 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
584 /* a relative dest directory is OK */
585 clean_after_shfo_tests();
587 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
588 shfo.pTo = "testdir2\0";
589 retval = SHFileOperation(&shfo);
590 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
591 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
593 /* try to copy files to a file */
594 clean_after_shfo_tests();
598 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
599 set_curr_dir_path(to, "test3.txt\0");
600 retval = SHFileOperation(&shfo);
601 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
602 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
603 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
605 /* try to copy many files to nonexistent directory */
607 shfo.fAnyOperationsAborted = FALSE;
608 retval = SHFileOperation(&shfo);
609 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
610 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
611 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
612 ok(RemoveDirectory(to), "Expected test3.txt to exist\n");
614 /* send in FOF_MULTIDESTFILES with too many destination files */
616 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
617 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
618 shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
619 retval = SHFileOperation(&shfo);
620 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
621 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
622 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
624 /* send in FOF_MULTIDESTFILES with too many destination files */
625 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
626 shfo.pTo = "e.txt\0f.txt\0";
627 shfo.fAnyOperationsAborted = FALSE;
628 retval = SHFileOperation(&shfo);
629 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
630 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
631 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
633 /* use FOF_MULTIDESTFILES with files and a source directory */
634 shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
635 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
636 shfo.fAnyOperationsAborted = FALSE;
637 retval = SHFileOperation(&shfo);
638 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
639 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
640 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
641 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
643 /* try many dest files without FOF_MULTIDESTFILES flag */
644 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
645 shfo.pTo = "a.txt\0b.txt\0c.txt\0";
646 shfo.fAnyOperationsAborted = FALSE;
647 shfo.fFlags &= ~FOF_MULTIDESTFILES;
648 retval = SHFileOperation(&shfo);
649 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
650 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
653 shfo.pFrom = "test?.txt\0";
654 shfo.pTo = "testdir2\0";
655 shfo.fFlags &= ~FOF_MULTIDESTFILES;
656 retval = SHFileOperation(&shfo);
657 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
658 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
660 /* try a glob with FOF_FILESONLY */
661 clean_after_shfo_tests();
663 shfo.pFrom = "test?.txt\0";
664 shfo.fFlags |= FOF_FILESONLY;
665 retval = SHFileOperation(&shfo);
666 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
667 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
668 ok(!file_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
670 /* try a glob with FOF_MULTIDESTFILES and the same number
671 * of dest files that we would expect
673 clean_after_shfo_tests();
675 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
676 shfo.fFlags &= ~FOF_FILESONLY;
677 shfo.fFlags |= FOF_MULTIDESTFILES;
678 retval = SHFileOperation(&shfo);
679 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
680 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
681 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
682 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
684 /* copy one file to two others, second is ignored */
685 clean_after_shfo_tests();
687 shfo.pFrom = "test1.txt\0";
688 shfo.pTo = "b.txt\0c.txt\0";
689 shfo.fAnyOperationsAborted = FALSE;
690 retval = SHFileOperation(&shfo);
691 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
692 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
693 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
695 /* copy two file to three others, all fail */
696 shfo.pFrom = "test1.txt\0test2.txt\0";
697 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
698 retval = SHFileOperation(&shfo);
699 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
700 ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
701 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
703 /* copy one file and one directory to three others */
704 shfo.pFrom = "test1.txt\0test4.txt\0";
705 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
706 shfo.fAnyOperationsAborted = FALSE;
707 retval = SHFileOperation(&shfo);
708 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
709 ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
710 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
711 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
713 /* copy a directory with a file beneath it, plus some files */
714 createTestFile("test4.txt\\a.txt");
715 shfo.pFrom = "test4.txt\0test1.txt\0";
716 shfo.pTo = "testdir2\0";
717 shfo.fFlags &= ~FOF_MULTIDESTFILES;
718 shfo.fAnyOperationsAborted = FALSE;
719 retval = SHFileOperation(&shfo);
720 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
721 ok(DeleteFile("testdir2\\test1.txt"), "Expected newdir\\test1.txt to exist\n");
722 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
723 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
725 /* copy one directory and a file in that dir to another dir */
726 shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
727 shfo.pTo = "testdir2\0";
728 retval = SHFileOperation(&shfo);
729 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
730 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
731 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
733 /* copy a file in a directory first, and then the directory to a nonexistent dir */
734 shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
735 shfo.pTo = "nonexistent\0";
736 retval = SHFileOperation(&shfo);
737 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
738 ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
739 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
740 DeleteFile("test4.txt\\a.txt");
742 /* destination is same as source file */
743 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
744 shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
745 shfo.fAnyOperationsAborted = FALSE;
746 shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
747 retval = SHFileOperation(&shfo);
748 ok(retval == ERROR_NO_MORE_SEARCH_HANDLES,
749 "Expected ERROR_NO_MORE_SEARCH_HANDLES, got %d\n", retval);
750 ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
751 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
752 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
754 /* destination is same as source directory */
755 shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
756 shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
757 shfo.fAnyOperationsAborted = FALSE;
758 retval = SHFileOperation(&shfo);
759 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
760 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
761 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
763 /* copy a directory into itself, error displayed in UI */
764 shfo.pFrom = "test4.txt\0";
765 shfo.pTo = "test4.txt\\newdir\0";
766 shfo.fFlags &= ~FOF_MULTIDESTFILES;
767 shfo.fAnyOperationsAborted = FALSE;
768 retval = SHFileOperation(&shfo);
769 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
770 ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
772 /* copy a directory to itself, error displayed in UI */
773 shfo.pFrom = "test4.txt\0";
774 shfo.pTo = "test4.txt\0";
775 shfo.fAnyOperationsAborted = FALSE;
776 retval = SHFileOperation(&shfo);
777 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
779 /* copy a file into a directory, and the directory into itself */
780 shfo.pFrom = "test1.txt\0test4.txt\0";
781 shfo.pTo = "test4.txt\0";
782 shfo.fAnyOperationsAborted = FALSE;
783 shfo.fFlags |= FOF_NOCONFIRMATION;
784 retval = SHFileOperation(&shfo);
785 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
786 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
788 /* copy a file to a file, and the directory into itself */
789 shfo.pFrom = "test1.txt\0test4.txt\0";
790 shfo.pTo = "test4.txt\\a.txt\0";
791 shfo.fAnyOperationsAborted = FALSE;
792 retval = SHFileOperation(&shfo);
793 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
794 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
796 /* copy a nonexistent file to a nonexistent directory */
797 shfo.pFrom = "e.txt\0";
798 shfo.pTo = "nonexistent\0";
799 shfo.fAnyOperationsAborted = FALSE;
800 retval = SHFileOperation(&shfo);
801 ok(retval == 1026, "Expected 1026, got %d\n", retval);
802 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
803 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
805 /* Overwrite tests */
806 clean_after_shfo_tests();
808 shfo.fFlags = FOF_NOCONFIRMATION;
809 shfo.pFrom = "test1.txt\0";
810 shfo.pTo = "test2.txt\0";
811 shfo.fAnyOperationsAborted = FALSE;
812 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
813 retval = SHFileOperation(&shfo);
814 ok(retval == 0, "Expected 0, got %d\n", retval);
815 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
817 shfo.pFrom = "test3.txt\0test1.txt\0";
818 shfo.pTo = "test2.txt\0one.txt\0";
819 shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
820 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
821 retval = SHFileOperation(&shfo);
822 ok(retval == 0, "Expected 0, got %d\n", retval);
823 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
825 shfo.pFrom = "one.txt\0";
826 shfo.pTo = "testdir2\0";
827 shfo.fFlags = FOF_NOCONFIRMATION;
828 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
829 retval = SHFileOperation(&shfo);
830 ok(retval == 0, "Expected 0, got %d\n", retval);
831 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
833 createTestFile("test4.txt\\test1.txt");
834 shfo.pFrom = "test4.txt\0";
835 shfo.pTo = "testdir2\0";
836 shfo.fFlags = FOF_NOCONFIRMATION;
837 ok(!SHFileOperation(&shfo), "First SHFileOperation failed\n");
838 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
839 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
840 retval = SHFileOperation(&shfo);
841 ok(retval == 0, "Expected 0, got %d\n", retval);
842 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
844 createTestFile("one.txt");
846 /* pFrom contains bogus 2nd name longer than MAX_PATH */
847 memset(from, 'a', MAX_PATH*2);
848 memset(from+MAX_PATH*2, 0, 2);
849 lstrcpyA(from, "one.txt");
851 shfo.pTo = "two.txt\0";
852 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
853 retval = SHFileOperation(&shfo);
854 ok(retval == 1148 || retval == 1026, "Expected 1148 or 1026, got %d\n", retval);
855 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
856 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
858 createTestFile("one.txt");
860 /* pTo contains bogus 2nd name longer than MAX_PATH */
861 memset(to, 'a', MAX_PATH*2);
862 memset(to+MAX_PATH*2, 0, 2);
863 lstrcpyA(to, "two.txt");
864 shfo.pFrom = "one.txt\0";
866 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
867 retval = SHFileOperation(&shfo);
868 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
869 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
870 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
872 createTestFile("one.txt");
874 /* no FOF_MULTIDESTFILES, two files in pTo */
875 shfo.pFrom = "one.txt\0";
876 shfo.pTo = "two.txt\0three.txt\0";
877 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
878 retval = SHFileOperation(&shfo);
879 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
880 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
881 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
883 createTestFile("one.txt");
885 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
886 memset(from, 'a', MAX_PATH*2);
887 memset(from+MAX_PATH*2, 0, 2);
888 memset(to, 'a', MAX_PATH*2);
889 memset(to+MAX_PATH*2, 0, 2);
890 lstrcpyA(from, "one.txt");
891 lstrcpyA(to, "two.txt");
894 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
895 retval = SHFileOperation(&shfo);
896 ok(retval == 1148 || retval == 1026, "Expected 1148 or 1026, got %d\n", retval);
897 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
898 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
900 createTestFile("one.txt");
902 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
903 memset(to, 'a', MAX_PATH*2);
904 memset(to+MAX_PATH*2, 0, 2);
905 lstrcpyA(to, "two.txt");
906 shfo.pFrom = "one.txt\0";
908 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
909 FOF_SILENT | FOF_NOERRORUI;
910 retval = SHFileOperation(&shfo);
911 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
912 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
913 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
915 createTestFile("one.txt");
916 createTestFile("two.txt");
918 /* pTo contains bogus 2nd name longer than MAX_PATH,
919 * multiple source files,
920 * dest directory does not exist
922 memset(to, 'a', 2 * MAX_PATH);
923 memset(to+MAX_PATH*2, 0, 2);
924 lstrcpyA(to, "threedir");
925 shfo.pFrom = "one.txt\0two.txt\0";
927 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
928 retval = SHFileOperation(&shfo);
929 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
930 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
931 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
932 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
933 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
934 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
935 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
937 createTestFile("one.txt");
938 createTestFile("two.txt");
939 CreateDirectoryA("threedir", NULL);
941 /* pTo contains bogus 2nd name longer than MAX_PATH,
942 * multiple source files,
943 * dest directory does exist
945 memset(to, 'a', 2 * MAX_PATH);
946 memset(to+MAX_PATH*2, 0, 2);
947 lstrcpyA(to, "threedir");
948 shfo.pFrom = "one.txt\0two.txt\0";
950 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
951 retval = SHFileOperation(&shfo);
952 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
953 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
954 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
955 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
956 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
957 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
959 createTestFile("one.txt");
960 createTestFile("two.txt");
962 /* pTo contains bogus 2nd name longer than MAX_PATH,
963 * multiple source files, FOF_MULTIDESTFILES
964 * dest dir does not exist
966 memset(to, 'a', 2 * MAX_PATH);
967 memset(to+MAX_PATH*2, 0, 2);
968 lstrcpyA(to, "threedir");
969 shfo.pFrom = "one.txt\0two.txt\0";
971 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
972 FOF_SILENT | FOF_NOERRORUI;
973 retval = SHFileOperation(&shfo);
974 ok(retval == ERROR_CANCELLED ||
975 retval == ERROR_SUCCESS, /* win2k3 */
976 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval);
977 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
978 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
979 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
980 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
981 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
983 /* file exists in win2k */
984 DeleteFileA("threedir");
986 createTestFile("one.txt");
987 createTestFile("two.txt");
988 CreateDirectoryA("threedir", NULL);
990 /* pTo contains bogus 2nd name longer than MAX_PATH,
991 * multiple source files, FOF_MULTIDESTFILES
992 * dest dir does exist
994 memset(to, 'a', 2 * MAX_PATH);
995 memset(to+MAX_PATH*2, 0, 2);
996 lstrcpyA(to, "threedir");
997 ptr = to + lstrlenA(to) + 1;
998 lstrcpyA(ptr, "fourdir");
999 shfo.pFrom = "one.txt\0two.txt\0";
1001 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1002 FOF_SILENT | FOF_NOERRORUI;
1003 retval = SHFileOperation(&shfo);
1004 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1005 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1006 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1007 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1008 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1009 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1010 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1011 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1013 createTestFile("one.txt");
1014 createTestFile("two.txt");
1015 CreateDirectoryA("threedir", NULL);
1017 /* multiple source files, FOF_MULTIDESTFILES
1018 * multiple dest files, but first dest dir exists
1019 * num files in lists is equal
1021 shfo.pFrom = "one.txt\0two.txt\0";
1022 shfo.pTo = "threedir\0fourdir\0";
1023 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1024 FOF_SILENT | FOF_NOERRORUI;
1025 retval = SHFileOperation(&shfo);
1026 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
1027 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1028 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1029 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1030 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1031 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1032 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1033 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1035 createTestFile("one.txt");
1036 createTestFile("two.txt");
1037 CreateDirectoryA("threedir", NULL);
1039 /* multiple source files, FOF_MULTIDESTFILES
1040 * multiple dest files, but first dest dir exists
1041 * num files in lists is not equal
1043 shfo.pFrom = "one.txt\0two.txt\0";
1044 shfo.pTo = "threedir\0fourdir\0five\0";
1045 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1046 FOF_SILENT | FOF_NOERRORUI;
1047 retval = SHFileOperation(&shfo);
1048 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1049 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1050 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1051 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1052 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1053 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1054 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1055 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1056 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1057 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1059 createTestFile("aa.txt");
1060 createTestFile("ab.txt");
1061 CreateDirectoryA("one", NULL);
1062 CreateDirectoryA("two", NULL);
1064 /* pFrom has a glob, pTo has more than one dest */
1065 shfo.pFrom = "a*.txt\0";
1066 shfo.pTo = "one\0two\0";
1067 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1068 retval = SHFileOperation(&shfo);
1069 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1070 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1071 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1072 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1073 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1074 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1075 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1076 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1077 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1080 /* tests the FO_MOVE action */
1081 static void test_move(void)
1083 SHFILEOPSTRUCTA shfo, shfo2;
1084 CHAR from[5*MAX_PATH];
1085 CHAR to[5*MAX_PATH];
1089 shfo.wFunc = FO_MOVE;
1092 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1093 shfo.hNameMappings = NULL;
1094 shfo.lpszProgressTitle = NULL;
1096 set_curr_dir_path(from, "test1.txt\0");
1097 set_curr_dir_path(to, "test4.txt\0");
1098 ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
1099 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1100 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1102 set_curr_dir_path(from, "test?.txt\0");
1103 set_curr_dir_path(to, "testdir2\0");
1104 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1105 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1106 ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
1107 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1108 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1109 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1111 clean_after_shfo_tests();
1114 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
1115 shfo2.fFlags |= FOF_MULTIDESTFILES;
1117 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1118 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1119 ok(!SHFileOperationA(&shfo2), "Move many files\n");
1120 ok(file_exists("test6.txt"), "The file is moved - many files are "
1121 "specified as a target\n");
1122 DeleteFileA("test6.txt");
1123 DeleteFileA("test7.txt");
1124 RemoveDirectoryA("test8.txt");
1128 /* number of sources do not correspond to number of targets */
1129 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1130 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
1131 ok(SHFileOperationA(&shfo2), "Can't move many files\n");
1132 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1133 "specified as a target\n");
1137 set_curr_dir_path(from, "test3.txt\0");
1138 set_curr_dir_path(to, "test4.txt\\test1.txt\0");
1139 ok(!SHFileOperationA(&shfo), "File is moved moving to other directory\n");
1140 ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
1142 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1143 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1144 ok(SHFileOperationA(&shfo), "Cannot move many files\n");
1145 ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
1146 ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
1148 set_curr_dir_path(from, "test1.txt\0");
1149 set_curr_dir_path(to, "test6.txt\0");
1150 ok(!SHFileOperationA(&shfo), "Move file\n");
1151 ok(!file_exists("test1.txt"), "The file is moved\n");
1152 ok(file_exists("test6.txt"), "The file is moved\n");
1153 set_curr_dir_path(from, "test6.txt\0");
1154 set_curr_dir_path(to, "test1.txt\0");
1155 ok(!SHFileOperationA(&shfo), "Move file back\n");
1157 set_curr_dir_path(from, "test4.txt\0");
1158 set_curr_dir_path(to, "test6.txt\0");
1159 ok(!SHFileOperationA(&shfo), "Move dir\n");
1160 ok(!file_exists("test4.txt"), "The dir is moved\n");
1161 ok(file_exists("test6.txt"), "The dir is moved\n");
1162 set_curr_dir_path(from, "test6.txt\0");
1163 set_curr_dir_path(to, "test4.txt\0");
1164 ok(!SHFileOperationA(&shfo), "Move dir back\n");
1166 /* move one file to two others */
1168 shfo.pFrom = "test1.txt\0";
1169 shfo.pTo = "a.txt\0b.txt\0";
1170 retval = SHFileOperationA(&shfo);
1171 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1172 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1173 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1174 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1176 /* move two files to one other */
1177 shfo.pFrom = "test2.txt\0test3.txt\0";
1178 shfo.pTo = "test1.txt\0";
1179 retval = SHFileOperationA(&shfo);
1180 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
1181 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1182 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1183 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1185 /* move a directory into itself */
1186 shfo.pFrom = "test4.txt\0";
1187 shfo.pTo = "test4.txt\\b.txt\0";
1188 retval = SHFileOperationA(&shfo);
1189 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1190 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1191 ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
1193 /* move many files without FOF_MULTIDESTFILES */
1194 shfo.pFrom = "test2.txt\0test3.txt\0";
1195 shfo.pTo = "d.txt\0e.txt\0";
1196 retval = SHFileOperationA(&shfo);
1197 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
1198 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1199 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1201 /* number of sources != number of targets */
1202 shfo.pTo = "d.txt\0";
1203 shfo.fFlags |= FOF_MULTIDESTFILES;
1204 retval = SHFileOperationA(&shfo);
1205 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
1206 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1208 /* FO_MOVE does not create dest directories */
1209 shfo.pFrom = "test2.txt\0";
1210 shfo.pTo = "dir1\\dir2\\test2.txt\0";
1211 retval = SHFileOperationA(&shfo);
1212 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
1213 ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
1215 /* try to overwrite an existing file */
1216 shfo.pTo = "test3.txt\0";
1217 retval = SHFileOperationA(&shfo);
1218 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1219 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1220 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1223 static void test_sh_create_dir(void)
1225 CHAR path[MAX_PATH];
1228 if(!pSHCreateDirectoryExA)
1230 trace("skipping SHCreateDirectoryExA tests\n");
1234 set_curr_dir_path(path, "testdir2\\test4.txt\0");
1235 ret = pSHCreateDirectoryExA(NULL, path, NULL);
1236 ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
1237 ok(file_exists("testdir2"), "The first directory is not created\n");
1238 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
1240 ret = pSHCreateDirectoryExA(NULL, path, NULL);
1241 ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
1243 ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
1244 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
1247 static void test_sh_path_prepare(void)
1250 CHAR path[MAX_PATH];
1252 if(!pSHPathPrepareForWriteA)
1254 trace("skipping SHPathPrepareForWriteA tests\n");
1258 /* directory exists, SHPPFW_NONE */
1259 set_curr_dir_path(path, "testdir2\0");
1260 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1261 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1263 /* directory exists, SHPPFW_IGNOREFILENAME */
1264 set_curr_dir_path(path, "testdir2\\test4.txt\0");
1265 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
1266 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1268 /* directory exists, SHPPFW_DIRCREATE */
1269 set_curr_dir_path(path, "testdir2\0");
1270 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1271 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1273 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1274 set_curr_dir_path(path, "testdir2\\test4.txt\0");
1275 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
1276 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1277 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1279 /* file exists, SHPPFW_NONE */
1280 set_curr_dir_path(path, "test1.txt\0");
1281 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1282 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1284 /* file exists, SHPPFW_DIRCREATE */
1285 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1286 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1288 /* file exists, SHPPFW_NONE, trailing \ */
1289 set_curr_dir_path(path, "test1.txt\\\0");
1290 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1291 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1293 /* relative path exists, SHPPFW_DIRCREATE */
1294 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE);
1295 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1297 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
1298 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE);
1299 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1300 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
1302 /* directory doesn't exist, SHPPFW_NONE */
1303 set_curr_dir_path(path, "nonexistent\0");
1304 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1305 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1307 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
1308 set_curr_dir_path(path, "nonexistent\\notreal\0");
1309 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
1310 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1311 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
1312 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1314 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1315 set_curr_dir_path(path, "testdir2\\test4.txt\\\0");
1316 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
1317 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1318 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
1320 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
1321 set_curr_dir_path(path, "nonexistent\\notreal\0");
1322 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1323 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1324 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
1326 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
1328 if(!pSHPathPrepareForWriteW)
1330 skip("Skipping SHPathPrepareForWriteW tests\n");
1333 /* unicode directory doesn't exist, SHPPFW_NONE */
1334 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
1335 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1336 ok(!file_existsW(UNICODE_PATH), "unicode path was created but shouldn't be\n");
1337 RemoveDirectoryW(UNICODE_PATH);
1339 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
1340 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
1341 ok(res == S_OK, "res == %08x, expected S_OK\n", res);
1342 ok(file_existsW(UNICODE_PATH), "unicode path should've been created\n");
1344 /* unicode directory exists, SHPPFW_NONE */
1345 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
1346 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
1348 /* unicode directory exists, SHPPFW_DIRCREATE */
1349 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
1350 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
1351 RemoveDirectoryW(UNICODE_PATH);
1354 static void test_unicode(void)
1356 SHFILEOPSTRUCTW shfoW;
1360 if (!pSHFileOperationW)
1362 skip("SHFileOperationW() is missing\n");
1367 shfoW.wFunc = FO_DELETE;
1368 shfoW.pFrom = UNICODE_PATH;
1370 shfoW.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1371 shfoW.hNameMappings = NULL;
1372 shfoW.lpszProgressTitle = NULL;
1374 /* Clean up before start test */
1375 DeleteFileW(UNICODE_PATH);
1376 RemoveDirectoryW(UNICODE_PATH);
1378 /* Make sure we are on a system that supports unicode */
1379 SetLastError(0xdeadbeef);
1380 file = CreateFileW(UNICODE_PATH, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1381 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
1383 skip("Unicode tests skipped on non-unicode system\n");
1388 /* Try to delete a file with unicode filename */
1389 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
1390 ret = pSHFileOperationW(&shfoW);
1391 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
1392 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
1394 /* Try to trash a file with unicode filename */
1395 createTestFileW(UNICODE_PATH);
1396 shfoW.fFlags |= FOF_ALLOWUNDO;
1397 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
1398 ret = pSHFileOperationW(&shfoW);
1399 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
1400 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
1402 if(!pSHCreateDirectoryExW)
1404 skip("Skipping SHCreateDirectoryExW tests\n");
1408 /* Try to delete a directory with unicode filename */
1409 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
1410 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
1411 ok(file_existsW(UNICODE_PATH), "The directory is not created\n");
1412 shfoW.fFlags &= ~FOF_ALLOWUNDO;
1413 ret = pSHFileOperationW(&shfoW);
1414 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
1415 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
1417 /* Try to trash a directory with unicode filename */
1418 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
1419 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
1420 ok(file_existsW(UNICODE_PATH), "The directory was not created\n");
1421 shfoW.fFlags |= FOF_ALLOWUNDO;
1422 ret = pSHFileOperationW(&shfoW);
1423 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
1424 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
1427 START_TEST(shlfileop)
1429 InitFunctionPointers();
1431 clean_after_shfo_tests();
1434 test_get_file_info();
1435 clean_after_shfo_tests();
1439 clean_after_shfo_tests();
1443 clean_after_shfo_tests();
1447 clean_after_shfo_tests();
1451 clean_after_shfo_tests();
1453 test_sh_create_dir();
1454 clean_after_shfo_tests();
1457 test_sh_path_prepare();
1458 clean_after_shfo_tests();