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 */
323 /* this crashes on win9x */
326 shfo
.fFlags
&= ~FOF_FILESONLY
;
327 shfo
.fAnyOperationsAborted
= FALSE
;
328 ret
= SHFileOperation(&shfo
);
329 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
330 ok(!shfo
.fAnyOperationsAborted
, "Expected no aborted operations\n");
331 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
334 /* try an invalid function */
336 shfo
.pFrom
= "test1.txt\0";
338 ret
= SHFileOperation(&shfo
);
339 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
340 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
342 /* try an invalid list, only one null terminator */
344 /* this crashes on win9x */
347 shfo
.wFunc
= FO_DELETE
;
348 ret
= SHFileOperation(&shfo
);
349 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
350 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
353 /* delete a dir, and then a file inside the dir, same as
354 * deleting a nonexistent file
357 shfo
.pFrom
= "testdir2\0testdir2\\one.txt\0";
358 shfo
.wFunc
= FO_DELETE
;
359 ret
= SHFileOperation(&shfo
);
360 ok(ret
== ERROR_PATH_NOT_FOUND
, "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret
);
361 ok(!file_exists("testdir2"), "Expected testdir2 to not exist\n");
362 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
364 /* try the FOF_NORECURSION flag, continues deleting subdirs */
366 shfo
.pFrom
= "testdir2\0";
367 shfo
.fFlags
|= FOF_NORECURSION
;
368 ret
= SHFileOperation(&shfo
);
369 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
370 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
371 ok(!file_exists("testdir2\\nested"), "Expected testdir2\\nested to exist\n");
374 /* tests the FO_RENAME action */
375 static void test_rename(void)
377 SHFILEOPSTRUCTA shfo
, shfo2
;
378 CHAR from
[5*MAX_PATH
];
383 shfo
.wFunc
= FO_RENAME
;
386 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
387 shfo
.hNameMappings
= NULL
;
388 shfo
.lpszProgressTitle
= NULL
;
390 set_curr_dir_path(from
, "test1.txt\0");
391 set_curr_dir_path(to
, "test4.txt\0");
392 ok(SHFileOperationA(&shfo
), "File is not renamed moving to other directory "
393 "when specifying directory name only\n");
394 ok(file_exists("test1.txt"), "The file is removed\n");
396 set_curr_dir_path(from
, "test3.txt\0");
397 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
398 ok(!SHFileOperationA(&shfo
), "File is renamed moving to other directory\n");
399 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
401 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
402 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
403 retval
= SHFileOperationA(&shfo
); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
404 ok(!retval
|| retval
== ERROR_GEN_FAILURE
|| retval
== ERROR_INVALID_TARGET_HANDLE
,
405 "Can't rename many files, retval = %d\n", retval
);
406 ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
408 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
409 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
411 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
412 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
413 retval
= SHFileOperationA(&shfo2
); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
414 ok(!retval
|| retval
== ERROR_GEN_FAILURE
|| retval
== ERROR_INVALID_TARGET_HANDLE
,
415 "Can't rename many files, retval = %d\n", retval
);
416 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
418 set_curr_dir_path(from
, "test1.txt\0");
419 set_curr_dir_path(to
, "test6.txt\0");
420 retval
= SHFileOperationA(&shfo
);
421 ok(!retval
, "Rename file failed, retval = %d\n", retval
);
422 ok(!file_exists("test1.txt"), "The file is not renamed\n");
423 ok(file_exists("test6.txt"), "The file is not renamed\n");
425 set_curr_dir_path(from
, "test6.txt\0");
426 set_curr_dir_path(to
, "test1.txt\0");
427 retval
= SHFileOperationA(&shfo
);
428 ok(!retval
, "Rename file back failed, retval = %d\n", retval
);
430 set_curr_dir_path(from
, "test4.txt\0");
431 set_curr_dir_path(to
, "test6.txt\0");
432 retval
= SHFileOperationA(&shfo
);
433 ok(!retval
, "Rename dir failed, retval = %d\n", retval
);
434 ok(!file_exists("test4.txt"), "The dir is not renamed\n");
435 ok(file_exists("test6.txt"), "The dir is not renamed\n");
437 set_curr_dir_path(from
, "test6.txt\0");
438 set_curr_dir_path(to
, "test4.txt\0");
439 retval
= SHFileOperationA(&shfo
);
440 ok(!retval
, "Rename dir back failed, retval = %d\n", retval
);
442 /* try to rename more than one file to a single file */
443 shfo
.pFrom
= "test1.txt\0test2.txt\0";
444 shfo
.pTo
= "a.txt\0";
445 retval
= SHFileOperationA(&shfo
);
446 ok(retval
== ERROR_GEN_FAILURE
, "Expected ERROR_GEN_FAILURE, got %d\n", retval
);
447 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
448 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
450 /* pFrom doesn't exist */
451 shfo
.pFrom
= "idontexist\0";
452 shfo
.pTo
= "newfile\0";
453 retval
= SHFileOperationA(&shfo
);
454 ok(retval
== 1026, "Expected 1026, got %d\n", retval
);
455 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
457 /* pTo already exist */
458 shfo
.pFrom
= "test1.txt\0";
459 shfo
.pTo
= "test2.txt\0";
460 retval
= SHFileOperationA(&shfo
);
461 ok(retval
== ERROR_ALREADY_EXISTS
, "Expected ERROR_ALREADY_EXISTS, got %d\n", retval
);
463 /* pFrom is valid, but pTo is empty */
464 shfo
.pFrom
= "test1.txt\0";
466 retval
= SHFileOperationA(&shfo
);
467 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
468 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
472 retval
= SHFileOperationA(&shfo
);
473 ok(retval
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", retval
);
475 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
478 retval
= SHFileOperationA(&shfo
);
479 ok(retval
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval
);
483 /* tests the FO_COPY action */
484 static void test_copy(void)
486 SHFILEOPSTRUCTA shfo
, shfo2
;
487 CHAR from
[5*MAX_PATH
];
489 FILEOP_FLAGS tmp_flags
;
494 shfo
.wFunc
= FO_COPY
;
497 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
498 shfo
.hNameMappings
= NULL
;
499 shfo
.lpszProgressTitle
= NULL
;
501 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
502 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
503 ok(SHFileOperationA(&shfo
), "Can't copy many files\n");
504 ok(!file_exists("test6.txt"), "The file is not copied - many files are "
505 "specified as a target\n");
507 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
508 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
510 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
511 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
512 ok(!SHFileOperationA(&shfo2
), "Can't copy many files\n");
513 ok(file_exists("test6.txt"), "The file is copied - many files are "
514 "specified as a target\n");
515 DeleteFileA("test6.txt");
516 DeleteFileA("test7.txt");
517 RemoveDirectoryA("test8.txt");
519 /* number of sources do not correspond to number of targets */
520 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
521 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
522 ok(SHFileOperationA(&shfo2
), "Can't copy many files\n");
523 ok(!file_exists("test6.txt"), "The file is not copied - many files are "
524 "specified as a target\n");
526 set_curr_dir_path(from
, "test1.txt\0");
527 set_curr_dir_path(to
, "test4.txt\0");
528 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are copied recursively\n");
529 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
531 set_curr_dir_path(from
, "test?.txt\0");
532 set_curr_dir_path(to
, "testdir2\0");
533 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
534 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
535 ok(!SHFileOperationA(&shfo
), "Files and directories are copied to directory\n");
536 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
537 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
538 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
539 clean_after_shfo_tests();
542 shfo
.fFlags
|= FOF_FILESONLY
;
543 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
544 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
545 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
546 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
547 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
548 clean_after_shfo_tests();
551 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
552 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
553 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
554 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
555 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
556 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
557 clean_after_shfo_tests();
559 /* Copying multiple files with one not existing as source, fails the
560 entire operation in Win98/ME/2K/XP, but not in 95/NT */
562 tmp_flags
= shfo
.fFlags
;
563 set_curr_dir_path(from
, "test1.txt\0test10.txt\0test2.txt\0");
564 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
565 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
566 retval
= SHFileOperationA(&shfo
);
568 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
569 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
572 /* Win 98/ME/2K/XP fail the entire operation with return code 1026 if one source file does not exist */
573 ok(retval
== 1026, "Files are copied to other directory\n");
574 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
576 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
577 shfo
.fFlags
= tmp_flags
;
579 /* copy into a nonexistent directory */
581 shfo
.fFlags
= FOF_NOCONFIRMMKDIR
;
582 set_curr_dir_path(from
, "test1.txt\0");
583 set_curr_dir_path(to
, "nonexistent\\notreal\\test2.txt\0");
584 retval
= SHFileOperation(&shfo
);
585 ok(!retval
, "Error copying into nonexistent directory\n");
586 ok(file_exists("nonexistent"), "nonexistent not created\n");
587 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
588 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
589 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
591 /* a relative dest directory is OK */
592 clean_after_shfo_tests();
594 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
595 shfo
.pTo
= "testdir2\0";
596 retval
= SHFileOperation(&shfo
);
597 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
598 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
600 /* try to copy files to a file */
601 clean_after_shfo_tests();
605 /* suppress the error-dialog in win9x here */
606 shfo
.fFlags
|= FOF_NOERRORUI
;
607 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
608 set_curr_dir_path(to
, "test3.txt\0");
609 retval
= SHFileOperation(&shfo
);
610 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
611 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
612 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
614 /* try to copy many files to nonexistent directory */
616 shfo
.fFlags
&= ~FOF_NOERRORUI
;
617 shfo
.fAnyOperationsAborted
= FALSE
;
618 retval
= SHFileOperation(&shfo
);
619 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
620 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
621 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
622 ok(RemoveDirectory(to
), "Expected test3.txt to exist\n");
624 /* send in FOF_MULTIDESTFILES with too many destination files */
626 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
627 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
628 shfo
.fFlags
|= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
629 retval
= SHFileOperation(&shfo
);
630 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
631 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
632 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
634 /* send in FOF_MULTIDESTFILES with too many destination files */
635 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
636 shfo
.pTo
= "e.txt\0f.txt\0";
637 shfo
.fAnyOperationsAborted
= FALSE
;
638 retval
= SHFileOperation(&shfo
);
639 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
640 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
641 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
643 /* use FOF_MULTIDESTFILES with files and a source directory */
644 shfo
.pFrom
= "test1.txt\0test2.txt\0test4.txt\0";
645 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
646 shfo
.fAnyOperationsAborted
= FALSE
;
647 retval
= SHFileOperation(&shfo
);
648 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
649 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
650 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
651 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
653 /* try many dest files without FOF_MULTIDESTFILES flag */
654 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
655 shfo
.pTo
= "a.txt\0b.txt\0c.txt\0";
656 shfo
.fAnyOperationsAborted
= FALSE
;
657 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
658 retval
= SHFileOperation(&shfo
);
659 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
660 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
663 shfo
.pFrom
= "test?.txt\0";
664 shfo
.pTo
= "testdir2\0";
665 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
666 retval
= SHFileOperation(&shfo
);
667 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
668 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
670 /* try a glob with FOF_FILESONLY */
671 clean_after_shfo_tests();
673 shfo
.pFrom
= "test?.txt\0";
674 shfo
.fFlags
|= FOF_FILESONLY
;
675 retval
= SHFileOperation(&shfo
);
676 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
677 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
678 ok(!file_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
680 /* try a glob with FOF_MULTIDESTFILES and the same number
681 * of dest files that we would expect
683 clean_after_shfo_tests();
685 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
686 shfo
.fFlags
&= ~FOF_FILESONLY
;
687 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
688 retval
= SHFileOperation(&shfo
);
689 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
690 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
691 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
692 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
694 /* copy one file to two others, second is ignored */
695 clean_after_shfo_tests();
697 shfo
.pFrom
= "test1.txt\0";
698 shfo
.pTo
= "b.txt\0c.txt\0";
699 shfo
.fAnyOperationsAborted
= FALSE
;
700 retval
= SHFileOperation(&shfo
);
701 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
702 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
703 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
705 /* copy two file to three others, all fail */
706 shfo
.pFrom
= "test1.txt\0test2.txt\0";
707 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
708 retval
= SHFileOperation(&shfo
);
709 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
710 ok(shfo
.fAnyOperationsAborted
, "Expected operations to be aborted\n");
711 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
713 /* copy one file and one directory to three others */
714 shfo
.pFrom
= "test1.txt\0test4.txt\0";
715 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
716 shfo
.fAnyOperationsAborted
= FALSE
;
717 retval
= SHFileOperation(&shfo
);
718 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
719 ok(shfo
.fAnyOperationsAborted
, "Expected operations to be aborted\n");
720 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
721 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
723 /* copy a directory with a file beneath it, plus some files */
724 createTestFile("test4.txt\\a.txt");
725 shfo
.pFrom
= "test4.txt\0test1.txt\0";
726 shfo
.pTo
= "testdir2\0";
727 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
728 shfo
.fAnyOperationsAborted
= FALSE
;
729 retval
= SHFileOperation(&shfo
);
730 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
731 ok(DeleteFile("testdir2\\test1.txt"), "Expected newdir\\test1.txt to exist\n");
732 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
733 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
735 /* copy one directory and a file in that dir to another dir */
736 shfo
.pFrom
= "test4.txt\0test4.txt\\a.txt\0";
737 shfo
.pTo
= "testdir2\0";
738 retval
= SHFileOperation(&shfo
);
739 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
740 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
741 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
743 /* copy a file in a directory first, and then the directory to a nonexistent dir */
744 shfo
.pFrom
= "test4.txt\\a.txt\0test4.txt\0";
745 shfo
.pTo
= "nonexistent\0";
746 retval
= SHFileOperation(&shfo
);
747 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
748 ok(shfo
.fAnyOperationsAborted
, "Expected operations to be aborted\n");
749 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
750 DeleteFile("test4.txt\\a.txt");
752 /* destination is same as source file */
753 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
754 shfo
.pTo
= "b.txt\0test2.txt\0c.txt\0";
755 shfo
.fAnyOperationsAborted
= FALSE
;
756 shfo
.fFlags
= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
757 retval
= SHFileOperation(&shfo
);
758 ok(retval
== ERROR_NO_MORE_SEARCH_HANDLES
,
759 "Expected ERROR_NO_MORE_SEARCH_HANDLES, got %d\n", retval
);
760 ok(!shfo
.fAnyOperationsAborted
, "Expected no operations to be aborted\n");
761 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
762 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
764 /* destination is same as source directory */
765 shfo
.pFrom
= "test1.txt\0test4.txt\0test3.txt\0";
766 shfo
.pTo
= "b.txt\0test4.txt\0c.txt\0";
767 shfo
.fAnyOperationsAborted
= FALSE
;
768 retval
= SHFileOperation(&shfo
);
769 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
770 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
771 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
773 /* copy a directory into itself, error displayed in UI */
774 shfo
.pFrom
= "test4.txt\0";
775 shfo
.pTo
= "test4.txt\\newdir\0";
776 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
777 shfo
.fAnyOperationsAborted
= FALSE
;
778 retval
= SHFileOperation(&shfo
);
779 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
780 ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
782 /* copy a directory to itself, error displayed in UI */
783 shfo
.pFrom
= "test4.txt\0";
784 shfo
.pTo
= "test4.txt\0";
785 shfo
.fAnyOperationsAborted
= FALSE
;
786 retval
= SHFileOperation(&shfo
);
787 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
789 /* copy a file into a directory, and the directory into itself */
790 shfo
.pFrom
= "test1.txt\0test4.txt\0";
791 shfo
.pTo
= "test4.txt\0";
792 shfo
.fAnyOperationsAborted
= FALSE
;
793 shfo
.fFlags
|= FOF_NOCONFIRMATION
;
794 retval
= SHFileOperation(&shfo
);
795 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
796 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
798 /* copy a file to a file, and the directory into itself */
799 shfo
.pFrom
= "test1.txt\0test4.txt\0";
800 shfo
.pTo
= "test4.txt\\a.txt\0";
801 shfo
.fAnyOperationsAborted
= FALSE
;
802 retval
= SHFileOperation(&shfo
);
803 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
804 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
806 /* copy a nonexistent file to a nonexistent directory */
807 shfo
.pFrom
= "e.txt\0";
808 shfo
.pTo
= "nonexistent\0";
809 shfo
.fAnyOperationsAborted
= FALSE
;
810 retval
= SHFileOperation(&shfo
);
811 ok(retval
== 1026, "Expected 1026, got %d\n", retval
);
812 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
813 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
815 /* Overwrite tests */
816 clean_after_shfo_tests();
818 shfo
.fFlags
= FOF_NOCONFIRMATION
;
819 shfo
.pFrom
= "test1.txt\0";
820 shfo
.pTo
= "test2.txt\0";
821 shfo
.fAnyOperationsAborted
= FALSE
;
822 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
823 retval
= SHFileOperation(&shfo
);
824 ok(retval
== 0, "Expected 0, got %d\n", retval
);
825 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
827 shfo
.pFrom
= "test3.txt\0test1.txt\0";
828 shfo
.pTo
= "test2.txt\0one.txt\0";
829 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_MULTIDESTFILES
;
830 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
831 retval
= SHFileOperation(&shfo
);
832 ok(retval
== 0, "Expected 0, got %d\n", retval
);
833 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
835 shfo
.pFrom
= "one.txt\0";
836 shfo
.pTo
= "testdir2\0";
837 shfo
.fFlags
= FOF_NOCONFIRMATION
;
838 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
839 retval
= SHFileOperation(&shfo
);
840 ok(retval
== 0, "Expected 0, got %d\n", retval
);
841 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
843 createTestFile("test4.txt\\test1.txt");
844 shfo
.pFrom
= "test4.txt\0";
845 shfo
.pTo
= "testdir2\0";
846 shfo
.fFlags
= FOF_NOCONFIRMATION
;
847 ok(!SHFileOperation(&shfo
), "First SHFileOperation failed\n");
848 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
849 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
850 retval
= SHFileOperation(&shfo
);
851 ok(retval
== 0, "Expected 0, got %d\n", retval
);
852 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
854 createTestFile("one.txt");
856 /* pFrom contains bogus 2nd name longer than MAX_PATH */
857 memset(from
, 'a', MAX_PATH
*2);
858 memset(from
+MAX_PATH
*2, 0, 2);
859 lstrcpyA(from
, "one.txt");
861 shfo
.pTo
= "two.txt\0";
862 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
863 retval
= SHFileOperation(&shfo
);
864 ok(retval
== 1148 || retval
== 1026, "Expected 1148 or 1026, got %d\n", retval
);
865 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
866 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
868 createTestFile("one.txt");
870 /* pTo contains bogus 2nd name longer than MAX_PATH */
871 memset(to
, 'a', MAX_PATH
*2);
872 memset(to
+MAX_PATH
*2, 0, 2);
873 lstrcpyA(to
, "two.txt");
874 shfo
.pFrom
= "one.txt\0";
876 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
877 retval
= SHFileOperation(&shfo
);
878 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
879 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
880 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
882 createTestFile("one.txt");
884 /* no FOF_MULTIDESTFILES, two files in pTo */
885 shfo
.pFrom
= "one.txt\0";
886 shfo
.pTo
= "two.txt\0three.txt\0";
887 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
888 retval
= SHFileOperation(&shfo
);
889 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
890 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
891 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
893 createTestFile("one.txt");
895 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
896 memset(from
, 'a', MAX_PATH
*2);
897 memset(from
+MAX_PATH
*2, 0, 2);
898 memset(to
, 'a', MAX_PATH
*2);
899 memset(to
+MAX_PATH
*2, 0, 2);
900 lstrcpyA(from
, "one.txt");
901 lstrcpyA(to
, "two.txt");
904 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
905 retval
= SHFileOperation(&shfo
);
906 ok(retval
== 1148 || retval
== 1026, "Expected 1148 or 1026, got %d\n", retval
);
907 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
908 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
910 createTestFile("one.txt");
912 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
913 memset(to
, 'a', MAX_PATH
*2);
914 memset(to
+MAX_PATH
*2, 0, 2);
915 lstrcpyA(to
, "two.txt");
916 shfo
.pFrom
= "one.txt\0";
918 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
919 FOF_SILENT
| FOF_NOERRORUI
;
920 retval
= SHFileOperation(&shfo
);
921 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
922 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
923 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
925 createTestFile("one.txt");
926 createTestFile("two.txt");
928 /* pTo contains bogus 2nd name longer than MAX_PATH,
929 * multiple source files,
930 * dest directory does not exist
932 memset(to
, 'a', 2 * MAX_PATH
);
933 memset(to
+MAX_PATH
*2, 0, 2);
934 lstrcpyA(to
, "threedir");
935 shfo
.pFrom
= "one.txt\0two.txt\0";
937 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
938 retval
= SHFileOperation(&shfo
);
939 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
940 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
941 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
942 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
943 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
944 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
945 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
947 createTestFile("one.txt");
948 createTestFile("two.txt");
949 CreateDirectoryA("threedir", NULL
);
951 /* pTo contains bogus 2nd name longer than MAX_PATH,
952 * multiple source files,
953 * dest directory does exist
955 memset(to
, 'a', 2 * MAX_PATH
);
956 memset(to
+MAX_PATH
*2, 0, 2);
957 lstrcpyA(to
, "threedir");
958 shfo
.pFrom
= "one.txt\0two.txt\0";
960 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
961 retval
= SHFileOperation(&shfo
);
962 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
963 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
964 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
965 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
966 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
967 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
970 /* this crashes on win9x */
971 createTestFile("one.txt");
972 createTestFile("two.txt");
974 /* pTo contains bogus 2nd name longer than MAX_PATH,
975 * multiple source files, FOF_MULTIDESTFILES
976 * dest dir does not exist
979 memset(to
, 'a', 2 * MAX_PATH
);
980 memset(to
+MAX_PATH
*2, 0, 2);
981 lstrcpyA(to
, "threedir");
982 shfo
.pFrom
= "one.txt\0two.txt\0";
984 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
985 FOF_SILENT
| FOF_NOERRORUI
;
986 retval
= SHFileOperation(&shfo
);
987 ok(retval
== ERROR_CANCELLED
||
988 retval
== ERROR_SUCCESS
, /* win2k3 */
989 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval
);
990 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
991 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
992 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
993 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
994 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
996 /* file exists in win2k */
997 DeleteFileA("threedir");
1001 createTestFile("one.txt");
1002 createTestFile("two.txt");
1003 CreateDirectoryA("threedir", NULL
);
1005 /* pTo contains bogus 2nd name longer than MAX_PATH,
1006 * multiple source files, FOF_MULTIDESTFILES
1007 * dest dir does exist
1009 memset(to
, 'a', 2 * MAX_PATH
);
1010 memset(to
+MAX_PATH
*2, 0, 2);
1011 lstrcpyA(to
, "threedir");
1012 ptr
= to
+ lstrlenA(to
) + 1;
1013 lstrcpyA(ptr
, "fourdir");
1014 shfo
.pFrom
= "one.txt\0two.txt\0";
1016 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1017 FOF_SILENT
| FOF_NOERRORUI
;
1018 retval
= SHFileOperation(&shfo
);
1019 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1020 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1021 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1022 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1023 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1024 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1025 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1026 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1028 createTestFile("one.txt");
1029 createTestFile("two.txt");
1030 CreateDirectoryA("threedir", NULL
);
1032 /* multiple source files, FOF_MULTIDESTFILES
1033 * multiple dest files, but first dest dir exists
1034 * num files in lists is equal
1036 shfo
.pFrom
= "one.txt\0two.txt\0";
1037 shfo
.pTo
= "threedir\0fourdir\0";
1038 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1039 FOF_SILENT
| FOF_NOERRORUI
;
1040 retval
= SHFileOperation(&shfo
);
1041 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1042 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1043 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1044 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1045 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1046 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1047 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1048 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1050 createTestFile("one.txt");
1051 createTestFile("two.txt");
1052 CreateDirectoryA("threedir", NULL
);
1054 /* multiple source files, FOF_MULTIDESTFILES
1055 * multiple dest files, but first dest dir exists
1056 * num files in lists is not equal
1058 shfo
.pFrom
= "one.txt\0two.txt\0";
1059 shfo
.pTo
= "threedir\0fourdir\0five\0";
1060 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1061 FOF_SILENT
| FOF_NOERRORUI
;
1062 retval
= SHFileOperation(&shfo
);
1063 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1064 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1065 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1066 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1067 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1068 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1069 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1070 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1071 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1072 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1074 createTestFile("aa.txt");
1075 createTestFile("ab.txt");
1076 CreateDirectoryA("one", NULL
);
1077 CreateDirectoryA("two", NULL
);
1079 /* pFrom has a glob, pTo has more than one dest */
1080 shfo
.pFrom
= "a*.txt\0";
1081 shfo
.pTo
= "one\0two\0";
1082 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1083 retval
= SHFileOperation(&shfo
);
1084 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1085 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1086 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1087 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1088 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1089 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1090 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1091 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1092 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1095 /* tests the FO_MOVE action */
1096 static void test_move(void)
1098 SHFILEOPSTRUCTA shfo
, shfo2
;
1099 CHAR from
[5*MAX_PATH
];
1100 CHAR to
[5*MAX_PATH
];
1104 shfo
.wFunc
= FO_MOVE
;
1107 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1108 shfo
.hNameMappings
= NULL
;
1109 shfo
.lpszProgressTitle
= NULL
;
1111 set_curr_dir_path(from
, "test1.txt\0");
1112 set_curr_dir_path(to
, "test4.txt\0");
1113 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are moved recursively\n");
1114 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1115 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1117 set_curr_dir_path(from
, "test?.txt\0");
1118 set_curr_dir_path(to
, "testdir2\0");
1119 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1120 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1121 ok(!SHFileOperationA(&shfo
), "Files and directories are moved to directory\n");
1122 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1123 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1124 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1126 clean_after_shfo_tests();
1129 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
1130 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
1132 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1133 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1134 ok(!SHFileOperationA(&shfo2
), "Move many files\n");
1135 ok(file_exists("test6.txt"), "The file is moved - many files are "
1136 "specified as a target\n");
1137 DeleteFileA("test6.txt");
1138 DeleteFileA("test7.txt");
1139 RemoveDirectoryA("test8.txt");
1143 /* number of sources do not correspond to number of targets */
1144 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1145 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1146 ok(SHFileOperationA(&shfo2
), "Can't move many files\n");
1147 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1148 "specified as a target\n");
1152 set_curr_dir_path(from
, "test3.txt\0");
1153 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
1154 ok(!SHFileOperationA(&shfo
), "File is moved moving to other directory\n");
1155 ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
1157 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1158 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1159 ok(SHFileOperationA(&shfo
), "Cannot move many files\n");
1160 ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
1161 ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
1163 set_curr_dir_path(from
, "test1.txt\0");
1164 set_curr_dir_path(to
, "test6.txt\0");
1165 ok(!SHFileOperationA(&shfo
), "Move file\n");
1166 ok(!file_exists("test1.txt"), "The file is moved\n");
1167 ok(file_exists("test6.txt"), "The file is moved\n");
1168 set_curr_dir_path(from
, "test6.txt\0");
1169 set_curr_dir_path(to
, "test1.txt\0");
1170 ok(!SHFileOperationA(&shfo
), "Move file back\n");
1172 set_curr_dir_path(from
, "test4.txt\0");
1173 set_curr_dir_path(to
, "test6.txt\0");
1174 ok(!SHFileOperationA(&shfo
), "Move dir\n");
1175 ok(!file_exists("test4.txt"), "The dir is moved\n");
1176 ok(file_exists("test6.txt"), "The dir is moved\n");
1177 set_curr_dir_path(from
, "test6.txt\0");
1178 set_curr_dir_path(to
, "test4.txt\0");
1179 ok(!SHFileOperationA(&shfo
), "Move dir back\n");
1181 /* move one file to two others */
1183 shfo
.pFrom
= "test1.txt\0";
1184 shfo
.pTo
= "a.txt\0b.txt\0";
1185 retval
= SHFileOperationA(&shfo
);
1186 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1187 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1188 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1189 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1191 /* move two files to one other */
1192 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1193 shfo
.pTo
= "test1.txt\0";
1194 retval
= SHFileOperationA(&shfo
);
1195 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1196 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1197 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1198 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1200 /* move a directory into itself */
1201 shfo
.pFrom
= "test4.txt\0";
1202 shfo
.pTo
= "test4.txt\\b.txt\0";
1203 retval
= SHFileOperationA(&shfo
);
1204 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1205 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1206 ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
1208 /* move many files without FOF_MULTIDESTFILES */
1209 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1210 shfo
.pTo
= "d.txt\0e.txt\0";
1211 retval
= SHFileOperationA(&shfo
);
1212 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1213 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1214 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1216 /* number of sources != number of targets */
1217 shfo
.pTo
= "d.txt\0";
1218 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1219 retval
= SHFileOperationA(&shfo
);
1220 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1221 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1223 /* FO_MOVE does not create dest directories */
1224 shfo
.pFrom
= "test2.txt\0";
1225 shfo
.pTo
= "dir1\\dir2\\test2.txt\0";
1226 retval
= SHFileOperationA(&shfo
);
1227 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1228 ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
1230 /* try to overwrite an existing file */
1231 shfo
.pTo
= "test3.txt\0";
1232 retval
= SHFileOperationA(&shfo
);
1233 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1234 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1235 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1238 static void test_sh_create_dir(void)
1240 CHAR path
[MAX_PATH
];
1243 if(!pSHCreateDirectoryExA
)
1245 trace("skipping SHCreateDirectoryExA tests\n");
1249 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1250 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1251 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret
);
1252 ok(file_exists("testdir2"), "The first directory is not created\n");
1253 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
1255 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1256 ok(ERROR_ALREADY_EXISTS
== ret
, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret
);
1258 ret
= pSHCreateDirectoryExA(NULL
, "c:\\testdir3", NULL
);
1259 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
1262 static void test_sh_path_prepare(void)
1265 CHAR path
[MAX_PATH
];
1267 if(!pSHPathPrepareForWriteA
)
1269 trace("skipping SHPathPrepareForWriteA tests\n");
1273 /* directory exists, SHPPFW_NONE */
1274 set_curr_dir_path(path
, "testdir2\0");
1275 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1276 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1278 /* directory exists, SHPPFW_IGNOREFILENAME */
1279 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1280 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
1281 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1283 /* directory exists, SHPPFW_DIRCREATE */
1284 set_curr_dir_path(path
, "testdir2\0");
1285 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1286 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1288 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1289 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1290 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
1291 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1292 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1294 /* file exists, SHPPFW_NONE */
1295 set_curr_dir_path(path
, "test1.txt\0");
1296 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1297 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1299 /* file exists, SHPPFW_DIRCREATE */
1300 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1301 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1303 /* file exists, SHPPFW_NONE, trailing \ */
1304 set_curr_dir_path(path
, "test1.txt\\\0");
1305 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1306 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1308 /* relative path exists, SHPPFW_DIRCREATE */
1309 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE
);
1310 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1312 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
1313 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE
);
1314 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1315 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
1317 /* directory doesn't exist, SHPPFW_NONE */
1318 set_curr_dir_path(path
, "nonexistent\0");
1319 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1320 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1322 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
1323 set_curr_dir_path(path
, "nonexistent\\notreal\0");
1324 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
1325 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1326 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
1327 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1329 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1330 set_curr_dir_path(path
, "testdir2\\test4.txt\\\0");
1331 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
1332 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1333 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
1335 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
1336 set_curr_dir_path(path
, "nonexistent\\notreal\0");
1337 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1338 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1339 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
1341 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
1343 if(!pSHPathPrepareForWriteW
)
1345 skip("Skipping SHPathPrepareForWriteW tests\n");
1348 /* unicode directory doesn't exist, SHPPFW_NONE */
1349 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
1350 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1351 ok(!file_existsW(UNICODE_PATH
), "unicode path was created but shouldn't be\n");
1352 RemoveDirectoryW(UNICODE_PATH
);
1354 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
1355 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
1356 ok(res
== S_OK
, "res == %08x, expected S_OK\n", res
);
1357 ok(file_existsW(UNICODE_PATH
), "unicode path should've been created\n");
1359 /* unicode directory exists, SHPPFW_NONE */
1360 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
1361 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
1363 /* unicode directory exists, SHPPFW_DIRCREATE */
1364 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
1365 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
1366 RemoveDirectoryW(UNICODE_PATH
);
1369 static void test_unicode(void)
1371 SHFILEOPSTRUCTW shfoW
;
1375 if (!pSHFileOperationW
)
1377 skip("SHFileOperationW() is missing\n");
1382 shfoW
.wFunc
= FO_DELETE
;
1383 shfoW
.pFrom
= UNICODE_PATH
;
1385 shfoW
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1386 shfoW
.hNameMappings
= NULL
;
1387 shfoW
.lpszProgressTitle
= NULL
;
1389 /* Clean up before start test */
1390 DeleteFileW(UNICODE_PATH
);
1391 RemoveDirectoryW(UNICODE_PATH
);
1393 /* Make sure we are on a system that supports unicode */
1394 SetLastError(0xdeadbeef);
1395 file
= CreateFileW(UNICODE_PATH
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1396 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
1398 skip("Unicode tests skipped on non-unicode system\n");
1403 /* Try to delete a file with unicode filename */
1404 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
1405 ret
= pSHFileOperationW(&shfoW
);
1406 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
1407 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
1409 /* Try to trash a file with unicode filename */
1410 createTestFileW(UNICODE_PATH
);
1411 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
1412 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
1413 ret
= pSHFileOperationW(&shfoW
);
1414 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
1415 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
1417 if(!pSHCreateDirectoryExW
)
1419 skip("Skipping SHCreateDirectoryExW tests\n");
1423 /* Try to delete a directory with unicode filename */
1424 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
1425 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
1426 ok(file_existsW(UNICODE_PATH
), "The directory is not created\n");
1427 shfoW
.fFlags
&= ~FOF_ALLOWUNDO
;
1428 ret
= pSHFileOperationW(&shfoW
);
1429 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
1430 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
1432 /* Try to trash a directory with unicode filename */
1433 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
1434 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
1435 ok(file_existsW(UNICODE_PATH
), "The directory was not created\n");
1436 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
1437 ret
= pSHFileOperationW(&shfoW
);
1438 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
1439 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
1442 START_TEST(shlfileop
)
1444 InitFunctionPointers();
1446 clean_after_shfo_tests();
1449 test_get_file_info();
1450 clean_after_shfo_tests();
1454 clean_after_shfo_tests();
1458 clean_after_shfo_tests();
1462 clean_after_shfo_tests();
1466 clean_after_shfo_tests();
1468 test_sh_create_dir();
1469 clean_after_shfo_tests();
1472 test_sh_path_prepare();
1473 clean_after_shfo_tests();