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 /* no double-NULL terminator for pFrom */
847 memset(from
, 'a', MAX_PATH
);
848 lstrcpyA(from
, "one.txt");
850 shfo
.pTo
= "two.txt\0";
851 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
852 retval
= SHFileOperation(&shfo
);
853 ok(retval
== 1148 || retval
== 1026, "Expected 1148 or 1026, got %d\n", retval
);
854 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
855 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
857 createTestFile("one.txt");
859 /* no double-NULL terminator for pTo */
860 memset(to
, 'a', MAX_PATH
);
861 lstrcpyA(to
, "two.txt");
862 shfo
.pFrom
= "one.txt\0";
864 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
865 retval
= SHFileOperation(&shfo
);
866 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
867 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
868 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
870 createTestFile("one.txt");
872 /* no FOF_MULTIDESTFILES, two files in pTo */
873 shfo
.pFrom
= "one.txt\0";
874 shfo
.pTo
= "two.txt\0three.txt\0";
875 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
876 retval
= SHFileOperation(&shfo
);
877 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
878 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
879 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
881 createTestFile("one.txt");
883 /* no double-NULL terminator for pFrom and pTo */
884 memset(from
, 'a', MAX_PATH
);
885 memset(to
, 'a', MAX_PATH
);
886 lstrcpyA(from
, "one.txt");
887 lstrcpyA(to
, "two.txt");
890 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
891 retval
= SHFileOperation(&shfo
);
892 ok(retval
== 1148 || retval
== 1026, "Expected 1148 or 1026, got %d\n", retval
);
893 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
894 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
896 createTestFile("one.txt");
898 /* no double-NULL terminator for pTo, FOF_MULTIDESTFILES */
899 memset(to
, 'a', MAX_PATH
);
900 lstrcpyA(to
, "two.txt");
901 shfo
.pFrom
= "one.txt\0";
903 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
904 FOF_SILENT
| FOF_NOERRORUI
;
905 retval
= SHFileOperation(&shfo
);
906 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
907 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
908 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
910 createTestFile("one.txt");
911 createTestFile("two.txt");
913 /* no double-NULL terminator for pTo,
914 * multiple source files,
915 * dest directory does not exist
917 memset(to
, 'a', 2 * MAX_PATH
);
918 lstrcpyA(to
, "threedir");
919 shfo
.pFrom
= "one.txt\0two.txt\0";
921 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
922 retval
= SHFileOperation(&shfo
);
923 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
924 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
925 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
926 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
927 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
928 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
929 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
931 createTestFile("one.txt");
932 createTestFile("two.txt");
933 CreateDirectoryA("threedir", NULL
);
935 /* no double-NULL terminator for pTo,
936 * multiple source files,
937 * dest directory does exist
939 memset(to
, 'a', 2 * MAX_PATH
);
940 lstrcpyA(to
, "threedir");
941 shfo
.pFrom
= "one.txt\0two.txt\0";
943 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
944 retval
= SHFileOperation(&shfo
);
945 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
946 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
947 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
948 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
949 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
950 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
952 createTestFile("one.txt");
953 createTestFile("two.txt");
955 /* no double-NULL terminator for pTo,
956 * multiple source files, FOF_MULTIDESTFILES
957 * dest dir does not exist
959 memset(to
, 'a', 2 * MAX_PATH
);
960 lstrcpyA(to
, "threedir");
961 shfo
.pFrom
= "one.txt\0two.txt\0";
963 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
964 FOF_SILENT
| FOF_NOERRORUI
;
965 retval
= SHFileOperation(&shfo
);
966 ok(retval
== ERROR_CANCELLED
||
967 retval
== ERROR_SUCCESS
, /* win2k3 */
968 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval
);
969 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
970 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
971 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
972 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
973 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
975 /* file exists in win2k */
976 DeleteFileA("threedir");
978 createTestFile("one.txt");
979 createTestFile("two.txt");
980 CreateDirectoryA("threedir", NULL
);
982 /* no double-NULL terminator for pTo,
983 * multiple source files, FOF_MULTIDESTFILES
984 * dest dir does exist
986 memset(to
, 'a', 2 * MAX_PATH
);
987 lstrcpyA(to
, "threedir");
988 ptr
= to
+ lstrlenA(to
) + 1;
989 lstrcpyA(ptr
, "fourdir");
990 shfo
.pFrom
= "one.txt\0two.txt\0";
992 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
993 FOF_SILENT
| FOF_NOERRORUI
;
994 retval
= SHFileOperation(&shfo
);
995 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
996 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
997 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
998 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
999 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1000 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1001 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1002 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1004 createTestFile("one.txt");
1005 createTestFile("two.txt");
1006 CreateDirectoryA("threedir", NULL
);
1008 /* multiple source files, FOF_MULTIDESTFILES
1009 * multiple dest files, but first dest dir exists
1010 * num files in lists is equal
1012 shfo
.pFrom
= "one.txt\0two.txt\0";
1013 shfo
.pTo
= "threedir\0fourdir\0";
1014 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1015 FOF_SILENT
| FOF_NOERRORUI
;
1016 retval
= SHFileOperation(&shfo
);
1017 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1018 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1019 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1020 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1021 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1022 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1023 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1024 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1026 createTestFile("one.txt");
1027 createTestFile("two.txt");
1028 CreateDirectoryA("threedir", NULL
);
1030 /* multiple source files, FOF_MULTIDESTFILES
1031 * multiple dest files, but first dest dir exists
1032 * num files in lists is not equal
1034 shfo
.pFrom
= "one.txt\0two.txt\0";
1035 shfo
.pTo
= "threedir\0fourdir\0five\0";
1036 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1037 FOF_SILENT
| FOF_NOERRORUI
;
1038 retval
= SHFileOperation(&shfo
);
1039 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1040 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1041 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1042 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1043 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1044 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1045 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1046 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1047 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1048 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1050 createTestFile("aa.txt");
1051 createTestFile("ab.txt");
1052 CreateDirectoryA("one", NULL
);
1053 CreateDirectoryA("two", NULL
);
1055 /* pFrom has a glob, pTo has more than one dest */
1056 shfo
.pFrom
= "a*.txt\0";
1057 shfo
.pTo
= "one\0two\0";
1058 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1059 retval
= SHFileOperation(&shfo
);
1060 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1061 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1062 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1063 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1064 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1065 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1066 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1067 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1068 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1071 /* tests the FO_MOVE action */
1072 static void test_move(void)
1074 SHFILEOPSTRUCTA shfo
, shfo2
;
1075 CHAR from
[5*MAX_PATH
];
1076 CHAR to
[5*MAX_PATH
];
1080 shfo
.wFunc
= FO_MOVE
;
1083 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1084 shfo
.hNameMappings
= NULL
;
1085 shfo
.lpszProgressTitle
= NULL
;
1087 set_curr_dir_path(from
, "test1.txt\0");
1088 set_curr_dir_path(to
, "test4.txt\0");
1089 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are moved recursively\n");
1090 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1091 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1093 set_curr_dir_path(from
, "test?.txt\0");
1094 set_curr_dir_path(to
, "testdir2\0");
1095 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1096 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1097 ok(!SHFileOperationA(&shfo
), "Files and directories are moved to directory\n");
1098 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1099 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1100 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1102 clean_after_shfo_tests();
1105 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
1106 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
1108 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1109 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1110 ok(!SHFileOperationA(&shfo2
), "Move many files\n");
1111 ok(file_exists("test6.txt"), "The file is moved - many files are "
1112 "specified as a target\n");
1113 DeleteFileA("test6.txt");
1114 DeleteFileA("test7.txt");
1115 RemoveDirectoryA("test8.txt");
1119 /* number of sources do not correspond to number of targets */
1120 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1121 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1122 ok(SHFileOperationA(&shfo2
), "Can't move many files\n");
1123 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1124 "specified as a target\n");
1128 set_curr_dir_path(from
, "test3.txt\0");
1129 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
1130 ok(!SHFileOperationA(&shfo
), "File is moved moving to other directory\n");
1131 ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
1133 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1134 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1135 ok(SHFileOperationA(&shfo
), "Cannot move many files\n");
1136 ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
1137 ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
1139 set_curr_dir_path(from
, "test1.txt\0");
1140 set_curr_dir_path(to
, "test6.txt\0");
1141 ok(!SHFileOperationA(&shfo
), "Move file\n");
1142 ok(!file_exists("test1.txt"), "The file is moved\n");
1143 ok(file_exists("test6.txt"), "The file is moved\n");
1144 set_curr_dir_path(from
, "test6.txt\0");
1145 set_curr_dir_path(to
, "test1.txt\0");
1146 ok(!SHFileOperationA(&shfo
), "Move file back\n");
1148 set_curr_dir_path(from
, "test4.txt\0");
1149 set_curr_dir_path(to
, "test6.txt\0");
1150 ok(!SHFileOperationA(&shfo
), "Move dir\n");
1151 ok(!file_exists("test4.txt"), "The dir is moved\n");
1152 ok(file_exists("test6.txt"), "The dir is moved\n");
1153 set_curr_dir_path(from
, "test6.txt\0");
1154 set_curr_dir_path(to
, "test4.txt\0");
1155 ok(!SHFileOperationA(&shfo
), "Move dir back\n");
1157 /* move one file to two others */
1159 shfo
.pFrom
= "test1.txt\0";
1160 shfo
.pTo
= "a.txt\0b.txt\0";
1161 retval
= SHFileOperationA(&shfo
);
1162 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1163 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1164 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1165 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1167 /* move two files to one other */
1168 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1169 shfo
.pTo
= "test1.txt\0";
1170 retval
= SHFileOperationA(&shfo
);
1171 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1172 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1173 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1174 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1176 /* move a directory into itself */
1177 shfo
.pFrom
= "test4.txt\0";
1178 shfo
.pTo
= "test4.txt\\b.txt\0";
1179 retval
= SHFileOperationA(&shfo
);
1180 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1181 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1182 ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
1184 /* move many files without FOF_MULTIDESTFILES */
1185 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1186 shfo
.pTo
= "d.txt\0e.txt\0";
1187 retval
= SHFileOperationA(&shfo
);
1188 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1189 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1190 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1192 /* number of sources != number of targets */
1193 shfo
.pTo
= "d.txt\0";
1194 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1195 retval
= SHFileOperationA(&shfo
);
1196 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1197 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1199 /* FO_MOVE does not create dest directories */
1200 shfo
.pFrom
= "test2.txt\0";
1201 shfo
.pTo
= "dir1\\dir2\\test2.txt\0";
1202 retval
= SHFileOperationA(&shfo
);
1203 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1204 ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
1206 /* try to overwrite an existing file */
1207 shfo
.pTo
= "test3.txt\0";
1208 retval
= SHFileOperationA(&shfo
);
1209 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1210 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1211 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1214 static void test_sh_create_dir(void)
1216 CHAR path
[MAX_PATH
];
1219 if(!pSHCreateDirectoryExA
)
1221 trace("skipping SHCreateDirectoryExA tests\n");
1225 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1226 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1227 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret
);
1228 ok(file_exists("testdir2"), "The first directory is not created\n");
1229 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
1231 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1232 ok(ERROR_ALREADY_EXISTS
== ret
, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret
);
1234 ret
= pSHCreateDirectoryExA(NULL
, "c:\\testdir3", NULL
);
1235 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
1238 static void test_sh_path_prepare(void)
1241 CHAR path
[MAX_PATH
];
1243 if(!pSHPathPrepareForWriteA
)
1245 trace("skipping SHPathPrepareForWriteA tests\n");
1249 /* directory exists, SHPPFW_NONE */
1250 set_curr_dir_path(path
, "testdir2\0");
1251 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1252 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1254 /* directory exists, SHPPFW_IGNOREFILENAME */
1255 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1256 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
1257 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1259 /* directory exists, SHPPFW_DIRCREATE */
1260 set_curr_dir_path(path
, "testdir2\0");
1261 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1262 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1264 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1265 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1266 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
1267 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1268 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1270 /* file exists, SHPPFW_NONE */
1271 set_curr_dir_path(path
, "test1.txt\0");
1272 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1273 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1275 /* file exists, SHPPFW_DIRCREATE */
1276 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1277 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1279 /* file exists, SHPPFW_NONE, trailing \ */
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 /* relative path exists, SHPPFW_DIRCREATE */
1285 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE
);
1286 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1288 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
1289 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE
);
1290 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1291 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
1293 /* directory doesn't exist, SHPPFW_NONE */
1294 set_curr_dir_path(path
, "nonexistent\0");
1295 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1296 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1298 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
1299 set_curr_dir_path(path
, "nonexistent\\notreal\0");
1300 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
1301 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1302 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
1303 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1305 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1306 set_curr_dir_path(path
, "testdir2\\test4.txt\\\0");
1307 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
1308 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1309 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
1311 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
1312 set_curr_dir_path(path
, "nonexistent\\notreal\0");
1313 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1314 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1315 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
1317 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
1319 if(!pSHPathPrepareForWriteW
)
1321 skip("Skipping SHPathPrepareForWriteW tests\n");
1324 /* unicode directory doesn't exist, SHPPFW_NONE */
1325 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
1326 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1327 ok(!file_existsW(UNICODE_PATH
), "unicode path was created but shouldn't be\n");
1328 RemoveDirectoryW(UNICODE_PATH
);
1330 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
1331 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
1332 ok(res
== S_OK
, "res == %08x, expected S_OK\n", res
);
1333 ok(file_existsW(UNICODE_PATH
), "unicode path should've been created\n");
1335 /* unicode directory exists, SHPPFW_NONE */
1336 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
1337 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
1339 /* unicode directory exists, SHPPFW_DIRCREATE */
1340 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
1341 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
1342 RemoveDirectoryW(UNICODE_PATH
);
1345 static void test_unicode(void)
1347 SHFILEOPSTRUCTW shfoW
;
1351 if (!pSHFileOperationW
)
1353 skip("SHFileOperationW() is missing\n");
1358 shfoW
.wFunc
= FO_DELETE
;
1359 shfoW
.pFrom
= UNICODE_PATH
;
1361 shfoW
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1362 shfoW
.hNameMappings
= NULL
;
1363 shfoW
.lpszProgressTitle
= NULL
;
1365 /* Clean up before start test */
1366 DeleteFileW(UNICODE_PATH
);
1367 RemoveDirectoryW(UNICODE_PATH
);
1369 /* Make sure we are on a system that supports unicode */
1370 SetLastError(0xdeadbeef);
1371 file
= CreateFileW(UNICODE_PATH
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1372 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
1374 skip("Unicode tests skipped on non-unicode system\n");
1379 /* Try to delete a file with unicode filename */
1380 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
1381 ret
= pSHFileOperationW(&shfoW
);
1382 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
1383 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
1385 /* Try to trash a file with unicode filename */
1386 createTestFileW(UNICODE_PATH
);
1387 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
1388 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
1389 ret
= pSHFileOperationW(&shfoW
);
1390 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
1391 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
1393 if(!pSHCreateDirectoryExW
)
1395 skip("Skipping SHCreateDirectoryExW tests\n");
1399 /* Try to delete a directory with unicode filename */
1400 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
1401 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
1402 ok(file_existsW(UNICODE_PATH
), "The directory is not created\n");
1403 shfoW
.fFlags
&= ~FOF_ALLOWUNDO
;
1404 ret
= pSHFileOperationW(&shfoW
);
1405 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
1406 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
1408 /* Try to trash 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 was 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");
1418 START_TEST(shlfileop
)
1420 InitFunctionPointers();
1422 clean_after_shfo_tests();
1425 test_get_file_info();
1426 clean_after_shfo_tests();
1430 clean_after_shfo_tests();
1434 clean_after_shfo_tests();
1438 clean_after_shfo_tests();
1442 clean_after_shfo_tests();
1444 test_sh_create_dir();
1445 clean_after_shfo_tests();
1448 test_sh_path_prepare();
1449 clean_after_shfo_tests();