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 DWORD_PTR (WINAPI
*pSHGetFileInfoW
)(LPCWSTR
, DWORD
, SHFILEINFOW
*, UINT
, UINT
);
45 static int (WINAPI
*pSHPathPrepareForWriteA
)(HWND
, IUnknown
*, LPCSTR
, DWORD
);
46 static int (WINAPI
*pSHPathPrepareForWriteW
)(HWND
, IUnknown
*, LPCWSTR
, DWORD
);
48 static void InitFunctionPointers(void)
50 hshell32
= GetModuleHandleA("shell32.dll");
51 pSHCreateDirectoryExA
= (void*)GetProcAddress(hshell32
, "SHCreateDirectoryExA");
52 pSHCreateDirectoryExW
= (void*)GetProcAddress(hshell32
, "SHCreateDirectoryExW");
53 pSHFileOperationW
= (void*)GetProcAddress(hshell32
, "SHFileOperationW");
54 pSHGetFileInfoW
= (void*)GetProcAddress(hshell32
, "SHGetFileInfoW");
55 pSHPathPrepareForWriteA
= (void*)GetProcAddress(hshell32
, "SHPathPrepareForWriteA");
56 pSHPathPrepareForWriteW
= (void*)GetProcAddress(hshell32
, "SHPathPrepareForWriteW");
59 /* creates a file with the specified name for tests */
60 static void createTestFile(const CHAR
*name
)
65 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
66 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
67 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
68 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
72 static void createTestFileW(const WCHAR
*name
)
76 file
= CreateFileW(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
77 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file\n");
81 static BOOL
file_exists(const CHAR
*name
)
83 return GetFileAttributesA(name
) != INVALID_FILE_ATTRIBUTES
;
86 static BOOL
file_existsW(LPCWSTR name
)
88 return GetFileAttributesW(name
) != INVALID_FILE_ATTRIBUTES
;
91 static BOOL
file_has_content(const CHAR
*name
, const CHAR
*content
)
97 file
= CreateFileA(name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
98 if (file
== INVALID_HANDLE_VALUE
)
100 ReadFile(file
, buf
, MAX_PATH
- 1, &read
, NULL
);
103 return strcmp(buf
, content
)==0;
106 /* initializes the tests */
107 static void init_shfo_tests(void)
111 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
112 len
= lstrlenA(CURR_DIR
);
114 if(len
&& (CURR_DIR
[len
-1] == '\\'))
117 createTestFile("test1.txt");
118 createTestFile("test2.txt");
119 createTestFile("test3.txt");
120 createTestFile("test_5.txt");
121 CreateDirectoryA("test4.txt", NULL
);
122 CreateDirectoryA("testdir2", NULL
);
123 CreateDirectoryA("testdir2\\nested", NULL
);
124 createTestFile("testdir2\\one.txt");
125 createTestFile("testdir2\\nested\\two.txt");
128 /* cleans after tests */
129 static void clean_after_shfo_tests(void)
131 DeleteFileA("test1.txt");
132 DeleteFileA("test2.txt");
133 DeleteFileA("test3.txt");
134 DeleteFileA("test_5.txt");
135 DeleteFileA("one.txt");
136 DeleteFileA("test4.txt\\test1.txt");
137 DeleteFileA("test4.txt\\test2.txt");
138 DeleteFileA("test4.txt\\test3.txt");
139 RemoveDirectoryA("test4.txt");
140 DeleteFileA("testdir2\\one.txt");
141 DeleteFileA("testdir2\\test1.txt");
142 DeleteFileA("testdir2\\test2.txt");
143 DeleteFileA("testdir2\\test3.txt");
144 DeleteFileA("testdir2\\test4.txt\\test1.txt");
145 DeleteFileA("testdir2\\nested\\two.txt");
146 RemoveDirectoryA("testdir2\\test4.txt");
147 RemoveDirectoryA("testdir2\\nested");
148 RemoveDirectoryA("testdir2");
149 RemoveDirectoryA("c:\\testdir3");
150 DeleteFileA("nonexistent\\notreal\\test2.txt");
151 RemoveDirectoryA("nonexistent\\notreal");
152 RemoveDirectoryA("nonexistent");
156 static void test_get_file_info(void)
159 SHFILEINFOA shfi
, shfi2
;
161 char notepad
[MAX_PATH
];
163 /* Test whether fields of SHFILEINFOA are always cleared */
164 memset(&shfi
, 0xcf, sizeof(shfi
));
165 rc
=SHGetFileInfoA("", 0, &shfi
, sizeof(shfi
), 0);
166 ok(rc
, "SHGetFileInfoA('' | 0) should not fail\n");
167 todo_wine
ok(shfi
.hIcon
== 0, "SHGetFileInfoA('' | 0) did not clear hIcon\n");
168 todo_wine
ok(shfi
.szDisplayName
[0] == 0, "SHGetFileInfoA('' | 0) did not clear szDisplayName[0]\n");
169 todo_wine
ok(shfi
.szTypeName
[0] == 0, "SHGetFileInfoA('' | 0) did not clear szTypeName[0]\n");
170 ok(shfi
.iIcon
== 0xcfcfcfcf, "SHGetFileInfoA('' | 0) should not clear iIcon\n");
171 ok(shfi
.dwAttributes
== 0xcfcfcfcf, "SHGetFileInfoA('' | 0) should not clear dwAttributes\n");
175 /* Test whether fields of SHFILEINFOW are always cleared */
176 memset(&shfiw
, 0xcf, sizeof(shfiw
));
177 rc
=pSHGetFileInfoW(NULL
, 0, &shfiw
, sizeof(shfiw
), 0);
178 todo_wine
ok(!rc
, "SHGetFileInfoW(NULL | 0) should fail\n");
179 ok(shfiw
.hIcon
== (HANDLE
) 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear hIcon\n");
180 todo_wine
ok(shfiw
.szDisplayName
[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szDisplayName[0]\n");
181 todo_wine
ok(shfiw
.szTypeName
[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szTypeName[0]\n");
182 todo_wine
ok(shfiw
.iIcon
== 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear iIcon\n");
183 ok(shfiw
.dwAttributes
== 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear dwAttributes\n");
186 win_skip("SHGetFileInfoW is not available\n");
189 /* Test some flag combinations that MSDN claims are not allowed,
190 * but which work anyway
192 memset(&shfi
, 0xcf, sizeof(shfi
));
193 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
195 SHGFI_ATTRIBUTES
| SHGFI_USEFILEATTRIBUTES
);
196 todo_wine
ok(rc
, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) failed\n");
198 ok(shfi
.dwAttributes
!= 0xcfcfcfcf, "dwFileAttributes is not set\n");
199 todo_wine
ok(shfi
.hIcon
== 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear hIcon\n");
200 todo_wine
ok(shfi
.szDisplayName
[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szDisplayName[0]\n");
201 todo_wine
ok(shfi
.szTypeName
[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szTypeName[0]\n");
202 ok(shfi
.iIcon
== 0xcfcfcfcf, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should not clear iIcon\n");
204 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
206 SHGFI_EXETYPE
| SHGFI_USEFILEATTRIBUTES
);
207 todo_wine
ok(rc
== 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) returned %d\n", rc
);
209 /* Test SHGFI_USEFILEATTRIBUTES support */
210 strcpy(shfi
.szDisplayName
, "dummy");
211 shfi
.iIcon
=0xdeadbeef;
212 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
214 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
215 ok(rc
, "SHGetFileInfoA(c:\\nonexistent) failed\n");
218 ok(strcpy(shfi
.szDisplayName
, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
219 ok(shfi
.iIcon
!= 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
222 /* Wine does not have a default icon for text files, and Windows 98 fails
223 * if we give it an empty executable. So use notepad.exe as the test
225 if (SearchPath(NULL
, "notepad.exe", NULL
, sizeof(notepad
), notepad
, NULL
))
227 strcpy(shfi
.szDisplayName
, "dummy");
228 shfi
.iIcon
=0xdeadbeef;
229 rc
=SHGetFileInfoA(notepad
, GetFileAttributes(notepad
),
231 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
232 ok(rc
, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) failed\n", notepad
);
233 strcpy(shfi2
.szDisplayName
, "dummy");
234 shfi2
.iIcon
=0xdeadbeef;
235 rc2
=SHGetFileInfoA(notepad
, 0,
236 &shfi2
, sizeof(shfi2
),
238 ok(rc2
, "SHGetFileInfoA(%s) failed\n", notepad
);
241 ok(lstrcmpi(shfi2
.szDisplayName
, shfi
.szDisplayName
) == 0, "wrong display name %s != %s\n", shfi
.szDisplayName
, shfi2
.szDisplayName
);
242 ok(shfi2
.iIcon
== shfi
.iIcon
, "wrong icon index %d != %d\n", shfi
.iIcon
, shfi2
.iIcon
);
246 /* with a directory now */
247 strcpy(shfi
.szDisplayName
, "dummy");
248 shfi
.iIcon
=0xdeadbeef;
249 rc
=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
251 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
252 ok(rc
, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) failed\n");
253 strcpy(shfi2
.szDisplayName
, "dummy");
254 shfi2
.iIcon
=0xdeadbeef;
255 rc2
=SHGetFileInfoA("test4.txt", 0,
256 &shfi2
, sizeof(shfi2
),
258 ok(rc2
, "SHGetFileInfoA(test4.txt/) failed\n");
261 ok(lstrcmpi(shfi2
.szDisplayName
, shfi
.szDisplayName
) == 0, "wrong display name %s != %s\n", shfi
.szDisplayName
, shfi2
.szDisplayName
);
262 ok(shfi2
.iIcon
== shfi
.iIcon
, "wrong icon index %d != %d\n", shfi
.iIcon
, shfi2
.iIcon
);
266 static void test_get_file_info_iconlist(void)
268 /* Test retrieving a handle to the system image list, and
269 * what that returns for hIcon
272 HIMAGELIST hSysImageList
;
273 LPITEMIDLIST pidList
;
277 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_DESKTOP
, &pidList
);
278 if (!SUCCEEDED(hr
)) {
279 skip("can't get desktop pidl\n");
283 memset(&shInfoa
, 0xcf, sizeof(shInfoa
));
284 hSysImageList
= (HIMAGELIST
) SHGetFileInfoA((const char *)pidList
, 0,
285 &shInfoa
, sizeof(shInfoa
),
286 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_PIDL
);
287 ok(hSysImageList
!= INVALID_HANDLE_VALUE
, "Can't get handle for CSIDL_DESKTOP imagelist\n");
288 todo_wine
ok(shInfoa
.hIcon
== 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
289 todo_wine
ok(shInfoa
.szTypeName
[0] == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
290 ok(shInfoa
.iIcon
!= 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
291 ok(shInfoa
.dwAttributes
== 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should not change dwAttributes\n");
292 CloseHandle(hSysImageList
);
294 if (!pSHGetFileInfoW
)
296 win_skip("SHGetFileInfoW is not available\n");
300 memset(&shInfow
, 0xcf, sizeof(shInfow
));
301 hSysImageList
= (HIMAGELIST
) pSHGetFileInfoW((const WCHAR
*)pidList
, 0,
302 &shInfow
, sizeof(shInfow
),
303 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_PIDL
);
304 ok(hSysImageList
!= INVALID_HANDLE_VALUE
, "Can't get handle for CSIDL_DESKTOP imagelist\n");
305 todo_wine
ok(shInfow
.hIcon
== 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
306 ok(shInfow
.szTypeName
[0] == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
307 ok(shInfow
.iIcon
!= 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
308 ok(shInfow
.dwAttributes
== 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should not change dwAttributes\n");
309 CloseHandle(hSysImageList
);
316 puts into the specified buffer file names with current directory.
317 files - string with file names, separated by null characters. Ends on a double
320 static void set_curr_dir_path(CHAR
*buf
, const CHAR
* files
)
325 strcpy(buf
, CURR_DIR
);
330 buf
+= strlen(buf
) + 1;
331 files
+= strlen(files
) + 1;
337 /* tests the FO_DELETE action */
338 static void test_delete(void)
340 SHFILEOPSTRUCTA shfo
;
342 CHAR buf
[sizeof(CURR_DIR
)+sizeof("/test?.txt")+1];
344 sprintf(buf
, "%s\\%s", CURR_DIR
, "test?.txt");
345 buf
[strlen(buf
) + 1] = '\0';
348 shfo
.wFunc
= FO_DELETE
;
351 shfo
.fFlags
= FOF_FILESONLY
| FOF_NOCONFIRMATION
| FOF_SILENT
;
352 shfo
.hNameMappings
= NULL
;
353 shfo
.lpszProgressTitle
= NULL
;
355 ok(!SHFileOperationA(&shfo
), "Deletion was not successful\n");
356 ok(file_exists("test4.txt"), "Directory should not have been removed\n");
357 ok(!file_exists("test1.txt"), "File should have been removed\n");
359 ret
= SHFileOperationA(&shfo
);
360 ok(!ret
, "Directory exists, but is not removed, ret=%d\n", ret
);
361 ok(file_exists("test4.txt"), "Directory should not have been removed\n");
363 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
365 ok(!SHFileOperationA(&shfo
), "Directory is not removed\n");
366 ok(!file_exists("test4.txt"), "Directory should have been removed\n");
368 ret
= SHFileOperationA(&shfo
);
369 ok(!ret
, "The requested file does not exist, ret=%d\n", ret
);
372 sprintf(buf
, "%s\\%s", CURR_DIR
, "test4.txt");
373 buf
[strlen(buf
) + 1] = '\0';
374 ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
375 ok(!SHFileOperationA(&shfo
), "Directory is not removed\n");
376 ok(!file_exists("test4.txt"), "Directory is not removed\n");
379 shfo
.pFrom
= "test1.txt\0test4.txt\0";
380 ok(!SHFileOperationA(&shfo
), "Directory and a file are not removed\n");
381 ok(!file_exists("test1.txt"), "The file should have been removed\n");
382 ok(!file_exists("test4.txt"), "Directory should have been removed\n");
383 ok(file_exists("test2.txt"), "This file should not have been removed\n");
385 /* FOF_FILESONLY does not delete a dir matching a wildcard */
387 shfo
.fFlags
|= FOF_FILESONLY
;
388 shfo
.pFrom
= "*.txt\0";
389 ok(!SHFileOperation(&shfo
), "Failed to delete files\n");
390 ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
391 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
392 ok(file_exists("test4.txt"), "test4.txt should not have been removed\n");
394 /* FOF_FILESONLY only deletes a dir if explicitly specified */
396 shfo
.pFrom
= "test_?.txt\0test4.txt\0";
397 ok(!SHFileOperation(&shfo
), "Failed to delete files and directory\n");
398 ok(!file_exists("test4.txt"), "test4.txt should have been removed\n");
399 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
400 ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
402 /* try to delete an invalid filename */
404 /* this crashes on win9x */
407 shfo
.fFlags
&= ~FOF_FILESONLY
;
408 shfo
.fAnyOperationsAborted
= FALSE
;
409 ret
= SHFileOperation(&shfo
);
410 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
411 ok(!shfo
.fAnyOperationsAborted
, "Expected no aborted operations\n");
412 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
415 /* try an invalid function */
417 shfo
.pFrom
= "test1.txt\0";
419 ret
= SHFileOperation(&shfo
);
420 ok(ret
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
421 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
423 /* try an invalid list, only one null terminator */
425 /* this crashes on win9x */
428 shfo
.wFunc
= FO_DELETE
;
429 ret
= SHFileOperation(&shfo
);
430 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
431 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
434 /* delete a dir, and then a file inside the dir, same as
435 * deleting a nonexistent file
438 shfo
.pFrom
= "testdir2\0testdir2\\one.txt\0";
439 shfo
.wFunc
= FO_DELETE
;
440 ret
= SHFileOperation(&shfo
);
441 ok(ret
== ERROR_PATH_NOT_FOUND
, "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret
);
442 ok(!file_exists("testdir2"), "Expected testdir2 to not exist\n");
443 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
445 /* try the FOF_NORECURSION flag, continues deleting subdirs */
447 shfo
.pFrom
= "testdir2\0";
448 shfo
.fFlags
|= FOF_NORECURSION
;
449 ret
= SHFileOperation(&shfo
);
450 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
451 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
452 ok(!file_exists("testdir2\\nested"), "Expected testdir2\\nested to exist\n");
455 /* tests the FO_RENAME action */
456 static void test_rename(void)
458 SHFILEOPSTRUCTA shfo
, shfo2
;
459 CHAR from
[5*MAX_PATH
];
464 shfo
.wFunc
= FO_RENAME
;
467 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
468 shfo
.hNameMappings
= NULL
;
469 shfo
.lpszProgressTitle
= NULL
;
471 set_curr_dir_path(from
, "test1.txt\0");
472 set_curr_dir_path(to
, "test4.txt\0");
473 ok(SHFileOperationA(&shfo
), "File is not renamed moving to other directory "
474 "when specifying directory name only\n");
475 ok(file_exists("test1.txt"), "The file is removed\n");
477 set_curr_dir_path(from
, "test3.txt\0");
478 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
479 ok(!SHFileOperationA(&shfo
), "File is renamed moving to other directory\n");
480 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
482 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
483 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
484 retval
= SHFileOperationA(&shfo
); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
485 ok(!retval
|| retval
== ERROR_GEN_FAILURE
|| retval
== ERROR_INVALID_TARGET_HANDLE
,
486 "Can't rename many files, retval = %d\n", retval
);
487 ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
489 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
490 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
492 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
493 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
494 retval
= SHFileOperationA(&shfo2
); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
495 ok(!retval
|| retval
== ERROR_GEN_FAILURE
|| retval
== ERROR_INVALID_TARGET_HANDLE
,
496 "Can't rename many files, retval = %d\n", retval
);
497 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
499 set_curr_dir_path(from
, "test1.txt\0");
500 set_curr_dir_path(to
, "test6.txt\0");
501 retval
= SHFileOperationA(&shfo
);
502 ok(!retval
, "Rename file failed, retval = %d\n", retval
);
503 ok(!file_exists("test1.txt"), "The file is not renamed\n");
504 ok(file_exists("test6.txt"), "The file is not renamed\n");
506 set_curr_dir_path(from
, "test6.txt\0");
507 set_curr_dir_path(to
, "test1.txt\0");
508 retval
= SHFileOperationA(&shfo
);
509 ok(!retval
, "Rename file back failed, retval = %d\n", retval
);
511 set_curr_dir_path(from
, "test4.txt\0");
512 set_curr_dir_path(to
, "test6.txt\0");
513 retval
= SHFileOperationA(&shfo
);
514 ok(!retval
, "Rename dir failed, retval = %d\n", retval
);
515 ok(!file_exists("test4.txt"), "The dir is not renamed\n");
516 ok(file_exists("test6.txt"), "The dir is not renamed\n");
518 set_curr_dir_path(from
, "test6.txt\0");
519 set_curr_dir_path(to
, "test4.txt\0");
520 retval
= SHFileOperationA(&shfo
);
521 ok(!retval
, "Rename dir back failed, retval = %d\n", retval
);
523 /* try to rename more than one file to a single file */
524 shfo
.pFrom
= "test1.txt\0test2.txt\0";
525 shfo
.pTo
= "a.txt\0";
526 retval
= SHFileOperationA(&shfo
);
527 ok(retval
== ERROR_GEN_FAILURE
, "Expected ERROR_GEN_FAILURE, got %d\n", retval
);
528 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
529 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
531 /* pFrom doesn't exist */
532 shfo
.pFrom
= "idontexist\0";
533 shfo
.pTo
= "newfile\0";
534 retval
= SHFileOperationA(&shfo
);
535 ok(retval
== 1026, "Expected 1026, got %d\n", retval
);
536 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
538 /* pTo already exist */
539 shfo
.pFrom
= "test1.txt\0";
540 shfo
.pTo
= "test2.txt\0";
541 retval
= SHFileOperationA(&shfo
);
542 ok(retval
== ERROR_ALREADY_EXISTS
, "Expected ERROR_ALREADY_EXISTS, got %d\n", retval
);
544 /* pFrom is valid, but pTo is empty */
545 shfo
.pFrom
= "test1.txt\0";
547 retval
= SHFileOperationA(&shfo
);
548 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
549 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
553 retval
= SHFileOperationA(&shfo
);
554 ok(retval
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", retval
);
556 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
559 retval
= SHFileOperationA(&shfo
);
560 ok(retval
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval
);
564 /* tests the FO_COPY action */
565 static void test_copy(void)
567 SHFILEOPSTRUCTA shfo
, shfo2
;
568 CHAR from
[5*MAX_PATH
];
570 FILEOP_FLAGS tmp_flags
;
575 shfo
.wFunc
= FO_COPY
;
578 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
579 shfo
.hNameMappings
= NULL
;
580 shfo
.lpszProgressTitle
= NULL
;
582 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
583 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
584 ok(SHFileOperationA(&shfo
), "Can't copy many files\n");
585 ok(!file_exists("test6.txt"), "The file is not copied - many files are "
586 "specified as a target\n");
588 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
589 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
591 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
592 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
593 ok(!SHFileOperationA(&shfo2
), "Can't copy many files\n");
594 ok(file_exists("test6.txt"), "The file is copied - many files are "
595 "specified as a target\n");
596 DeleteFileA("test6.txt");
597 DeleteFileA("test7.txt");
598 RemoveDirectoryA("test8.txt");
600 /* number of sources do not correspond to number of targets */
601 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
602 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
603 ok(SHFileOperationA(&shfo2
), "Can't copy many files\n");
604 ok(!file_exists("test6.txt"), "The file is not copied - many files are "
605 "specified as a target\n");
607 set_curr_dir_path(from
, "test1.txt\0");
608 set_curr_dir_path(to
, "test4.txt\0");
609 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are copied recursively\n");
610 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
612 set_curr_dir_path(from
, "test?.txt\0");
613 set_curr_dir_path(to
, "testdir2\0");
614 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
615 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
616 ok(!SHFileOperationA(&shfo
), "Files and directories are copied to directory\n");
617 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
618 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
619 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
620 clean_after_shfo_tests();
623 shfo
.fFlags
|= FOF_FILESONLY
;
624 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
625 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
626 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
627 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
628 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
629 clean_after_shfo_tests();
632 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
633 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
634 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
635 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
636 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
637 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
638 clean_after_shfo_tests();
640 /* Copying multiple files with one not existing as source, fails the
641 entire operation in Win98/ME/2K/XP, but not in 95/NT */
643 tmp_flags
= shfo
.fFlags
;
644 set_curr_dir_path(from
, "test1.txt\0test10.txt\0test2.txt\0");
645 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
646 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
647 retval
= SHFileOperationA(&shfo
);
649 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
650 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
653 /* Win 98/ME/2K/XP fail the entire operation with return code 1026 if one source file does not exist */
654 ok(retval
== 1026, "Files are copied to other directory\n");
655 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
657 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
658 shfo
.fFlags
= tmp_flags
;
660 /* copy into a nonexistent directory */
662 shfo
.fFlags
= FOF_NOCONFIRMMKDIR
;
663 set_curr_dir_path(from
, "test1.txt\0");
664 set_curr_dir_path(to
, "nonexistent\\notreal\\test2.txt\0");
665 retval
= SHFileOperation(&shfo
);
666 ok(!retval
, "Error copying into nonexistent directory\n");
667 ok(file_exists("nonexistent"), "nonexistent not created\n");
668 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
669 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
670 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
672 /* a relative dest directory is OK */
673 clean_after_shfo_tests();
675 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
676 shfo
.pTo
= "testdir2\0";
677 retval
= SHFileOperation(&shfo
);
678 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
679 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
681 /* try to copy files to a file */
682 clean_after_shfo_tests();
686 /* suppress the error-dialog in win9x here */
687 shfo
.fFlags
|= FOF_NOERRORUI
;
688 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
689 set_curr_dir_path(to
, "test3.txt\0");
690 retval
= SHFileOperation(&shfo
);
691 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
692 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
693 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
695 /* try to copy many files to nonexistent directory */
697 shfo
.fFlags
&= ~FOF_NOERRORUI
;
698 shfo
.fAnyOperationsAborted
= FALSE
;
699 retval
= SHFileOperation(&shfo
);
700 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
701 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
702 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
703 ok(RemoveDirectory(to
), "Expected test3.txt to exist\n");
705 /* send in FOF_MULTIDESTFILES with too many destination files */
707 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
708 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
709 shfo
.fFlags
|= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
710 retval
= SHFileOperation(&shfo
);
711 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
712 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
713 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
715 /* send in FOF_MULTIDESTFILES with too many destination files */
716 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
717 shfo
.pTo
= "e.txt\0f.txt\0";
718 shfo
.fAnyOperationsAborted
= FALSE
;
719 retval
= SHFileOperation(&shfo
);
720 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
721 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
722 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
724 /* use FOF_MULTIDESTFILES with files and a source directory */
725 shfo
.pFrom
= "test1.txt\0test2.txt\0test4.txt\0";
726 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
727 shfo
.fAnyOperationsAborted
= FALSE
;
728 retval
= SHFileOperation(&shfo
);
729 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
730 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
731 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
732 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
734 /* try many dest files without FOF_MULTIDESTFILES flag */
735 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
736 shfo
.pTo
= "a.txt\0b.txt\0c.txt\0";
737 shfo
.fAnyOperationsAborted
= FALSE
;
738 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
739 retval
= SHFileOperation(&shfo
);
740 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
741 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
744 shfo
.pFrom
= "test?.txt\0";
745 shfo
.pTo
= "testdir2\0";
746 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
747 retval
= SHFileOperation(&shfo
);
748 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
749 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
751 /* try a glob with FOF_FILESONLY */
752 clean_after_shfo_tests();
754 shfo
.pFrom
= "test?.txt\0";
755 shfo
.fFlags
|= FOF_FILESONLY
;
756 retval
= SHFileOperation(&shfo
);
757 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
758 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
759 ok(!file_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
761 /* try a glob with FOF_MULTIDESTFILES and the same number
762 * of dest files that we would expect
764 clean_after_shfo_tests();
766 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
767 shfo
.fFlags
&= ~FOF_FILESONLY
;
768 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
769 retval
= SHFileOperation(&shfo
);
770 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
771 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
772 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
773 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
775 /* copy one file to two others, second is ignored */
776 clean_after_shfo_tests();
778 shfo
.pFrom
= "test1.txt\0";
779 shfo
.pTo
= "b.txt\0c.txt\0";
780 shfo
.fAnyOperationsAborted
= FALSE
;
781 retval
= SHFileOperation(&shfo
);
782 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
783 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
784 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
786 /* copy two file to three others, all fail */
787 shfo
.pFrom
= "test1.txt\0test2.txt\0";
788 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
789 retval
= SHFileOperation(&shfo
);
790 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
791 ok(shfo
.fAnyOperationsAborted
, "Expected operations to be aborted\n");
792 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
794 /* copy one file and one directory to three others */
795 shfo
.pFrom
= "test1.txt\0test4.txt\0";
796 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
797 shfo
.fAnyOperationsAborted
= FALSE
;
798 retval
= SHFileOperation(&shfo
);
799 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
800 ok(shfo
.fAnyOperationsAborted
, "Expected operations to be aborted\n");
801 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
802 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
804 /* copy a directory with a file beneath it, plus some files */
805 createTestFile("test4.txt\\a.txt");
806 shfo
.pFrom
= "test4.txt\0test1.txt\0";
807 shfo
.pTo
= "testdir2\0";
808 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
809 shfo
.fAnyOperationsAborted
= FALSE
;
810 retval
= SHFileOperation(&shfo
);
811 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
812 ok(DeleteFile("testdir2\\test1.txt"), "Expected newdir\\test1.txt to exist\n");
813 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
814 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
816 /* copy one directory and a file in that dir to another dir */
817 shfo
.pFrom
= "test4.txt\0test4.txt\\a.txt\0";
818 shfo
.pTo
= "testdir2\0";
819 retval
= SHFileOperation(&shfo
);
820 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
821 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
822 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
824 /* copy a file in a directory first, and then the directory to a nonexistent dir */
825 shfo
.pFrom
= "test4.txt\\a.txt\0test4.txt\0";
826 shfo
.pTo
= "nonexistent\0";
827 retval
= SHFileOperation(&shfo
);
828 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
829 ok(shfo
.fAnyOperationsAborted
, "Expected operations to be aborted\n");
830 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
831 DeleteFile("test4.txt\\a.txt");
833 /* destination is same as source file */
834 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
835 shfo
.pTo
= "b.txt\0test2.txt\0c.txt\0";
836 shfo
.fAnyOperationsAborted
= FALSE
;
837 shfo
.fFlags
= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
838 retval
= SHFileOperation(&shfo
);
839 ok(retval
== ERROR_NO_MORE_SEARCH_HANDLES
,
840 "Expected ERROR_NO_MORE_SEARCH_HANDLES, got %d\n", retval
);
841 ok(!shfo
.fAnyOperationsAborted
, "Expected no operations to be aborted\n");
842 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
843 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
845 /* destination is same as source directory */
846 shfo
.pFrom
= "test1.txt\0test4.txt\0test3.txt\0";
847 shfo
.pTo
= "b.txt\0test4.txt\0c.txt\0";
848 shfo
.fAnyOperationsAborted
= FALSE
;
849 retval
= SHFileOperation(&shfo
);
850 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
851 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
852 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
854 /* copy a directory into itself, error displayed in UI */
855 shfo
.pFrom
= "test4.txt\0";
856 shfo
.pTo
= "test4.txt\\newdir\0";
857 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
858 shfo
.fAnyOperationsAborted
= FALSE
;
859 retval
= SHFileOperation(&shfo
);
860 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
861 ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
863 /* copy a directory to itself, error displayed in UI */
864 shfo
.pFrom
= "test4.txt\0";
865 shfo
.pTo
= "test4.txt\0";
866 shfo
.fAnyOperationsAborted
= FALSE
;
867 retval
= SHFileOperation(&shfo
);
868 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
870 /* copy a file into a directory, and the directory into itself */
871 shfo
.pFrom
= "test1.txt\0test4.txt\0";
872 shfo
.pTo
= "test4.txt\0";
873 shfo
.fAnyOperationsAborted
= FALSE
;
874 shfo
.fFlags
|= FOF_NOCONFIRMATION
;
875 retval
= SHFileOperation(&shfo
);
876 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
877 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
879 /* copy a file to a file, and the directory into itself */
880 shfo
.pFrom
= "test1.txt\0test4.txt\0";
881 shfo
.pTo
= "test4.txt\\a.txt\0";
882 shfo
.fAnyOperationsAborted
= FALSE
;
883 retval
= SHFileOperation(&shfo
);
884 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
885 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
887 /* copy a nonexistent file to a nonexistent directory */
888 shfo
.pFrom
= "e.txt\0";
889 shfo
.pTo
= "nonexistent\0";
890 shfo
.fAnyOperationsAborted
= FALSE
;
891 retval
= SHFileOperation(&shfo
);
892 ok(retval
== 1026, "Expected 1026, got %d\n", retval
);
893 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
894 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
896 /* Overwrite tests */
897 clean_after_shfo_tests();
899 shfo
.fFlags
= FOF_NOCONFIRMATION
;
900 shfo
.pFrom
= "test1.txt\0";
901 shfo
.pTo
= "test2.txt\0";
902 shfo
.fAnyOperationsAborted
= FALSE
;
903 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
904 retval
= SHFileOperation(&shfo
);
905 ok(retval
== 0, "Expected 0, got %d\n", retval
);
906 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
908 shfo
.pFrom
= "test3.txt\0test1.txt\0";
909 shfo
.pTo
= "test2.txt\0one.txt\0";
910 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_MULTIDESTFILES
;
911 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
912 retval
= SHFileOperation(&shfo
);
913 ok(retval
== 0, "Expected 0, got %d\n", retval
);
914 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
916 shfo
.pFrom
= "one.txt\0";
917 shfo
.pTo
= "testdir2\0";
918 shfo
.fFlags
= FOF_NOCONFIRMATION
;
919 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
920 retval
= SHFileOperation(&shfo
);
921 ok(retval
== 0, "Expected 0, got %d\n", retval
);
922 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
924 createTestFile("test4.txt\\test1.txt");
925 shfo
.pFrom
= "test4.txt\0";
926 shfo
.pTo
= "testdir2\0";
927 shfo
.fFlags
= FOF_NOCONFIRMATION
;
928 ok(!SHFileOperation(&shfo
), "First SHFileOperation failed\n");
929 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
930 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
931 retval
= SHFileOperation(&shfo
);
932 ok(retval
== 0, "Expected 0, got %d\n", retval
);
933 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
935 createTestFile("one.txt");
937 /* pFrom contains bogus 2nd name longer than MAX_PATH */
938 memset(from
, 'a', MAX_PATH
*2);
939 memset(from
+MAX_PATH
*2, 0, 2);
940 lstrcpyA(from
, "one.txt");
942 shfo
.pTo
= "two.txt\0";
943 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
944 retval
= SHFileOperation(&shfo
);
945 ok(retval
== 1148 || retval
== 1026, "Expected 1148 or 1026, got %d\n", retval
);
946 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
947 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
949 createTestFile("one.txt");
951 /* pTo contains bogus 2nd name longer than MAX_PATH */
952 memset(to
, 'a', MAX_PATH
*2);
953 memset(to
+MAX_PATH
*2, 0, 2);
954 lstrcpyA(to
, "two.txt");
955 shfo
.pFrom
= "one.txt\0";
957 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
958 retval
= SHFileOperation(&shfo
);
959 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
960 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
961 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
963 createTestFile("one.txt");
965 /* no FOF_MULTIDESTFILES, two files in pTo */
966 shfo
.pFrom
= "one.txt\0";
967 shfo
.pTo
= "two.txt\0three.txt\0";
968 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
969 retval
= SHFileOperation(&shfo
);
970 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
971 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
972 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
974 createTestFile("one.txt");
976 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
977 memset(from
, 'a', MAX_PATH
*2);
978 memset(from
+MAX_PATH
*2, 0, 2);
979 memset(to
, 'a', MAX_PATH
*2);
980 memset(to
+MAX_PATH
*2, 0, 2);
981 lstrcpyA(from
, "one.txt");
982 lstrcpyA(to
, "two.txt");
985 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
986 retval
= SHFileOperation(&shfo
);
987 ok(retval
== 1148 || retval
== 1026, "Expected 1148 or 1026, got %d\n", retval
);
988 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
989 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
991 createTestFile("one.txt");
993 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
994 memset(to
, 'a', MAX_PATH
*2);
995 memset(to
+MAX_PATH
*2, 0, 2);
996 lstrcpyA(to
, "two.txt");
997 shfo
.pFrom
= "one.txt\0";
999 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1000 FOF_SILENT
| FOF_NOERRORUI
;
1001 retval
= SHFileOperation(&shfo
);
1002 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1003 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1004 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1006 createTestFile("one.txt");
1007 createTestFile("two.txt");
1009 /* pTo contains bogus 2nd name longer than MAX_PATH,
1010 * multiple source files,
1011 * dest directory does not exist
1013 memset(to
, 'a', 2 * MAX_PATH
);
1014 memset(to
+MAX_PATH
*2, 0, 2);
1015 lstrcpyA(to
, "threedir");
1016 shfo
.pFrom
= "one.txt\0two.txt\0";
1018 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1019 retval
= SHFileOperation(&shfo
);
1020 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1021 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1022 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1023 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1024 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1025 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1026 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1028 createTestFile("one.txt");
1029 createTestFile("two.txt");
1030 CreateDirectoryA("threedir", NULL
);
1032 /* pTo contains bogus 2nd name longer than MAX_PATH,
1033 * multiple source files,
1034 * dest directory does exist
1036 memset(to
, 'a', 2 * MAX_PATH
);
1037 memset(to
+MAX_PATH
*2, 0, 2);
1038 lstrcpyA(to
, "threedir");
1039 shfo
.pFrom
= "one.txt\0two.txt\0";
1041 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1042 retval
= SHFileOperation(&shfo
);
1043 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1044 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1045 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1046 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1047 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1048 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1051 /* this crashes on win9x */
1052 createTestFile("one.txt");
1053 createTestFile("two.txt");
1055 /* pTo contains bogus 2nd name longer than MAX_PATH,
1056 * multiple source files, FOF_MULTIDESTFILES
1057 * dest dir does not exist
1060 memset(to
, 'a', 2 * MAX_PATH
);
1061 memset(to
+MAX_PATH
*2, 0, 2);
1062 lstrcpyA(to
, "threedir");
1063 shfo
.pFrom
= "one.txt\0two.txt\0";
1065 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1066 FOF_SILENT
| FOF_NOERRORUI
;
1067 retval
= SHFileOperation(&shfo
);
1068 ok(retval
== ERROR_CANCELLED
||
1069 retval
== ERROR_SUCCESS
, /* win2k3 */
1070 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval
);
1071 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1072 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1073 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1074 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1075 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1077 /* file exists in win2k */
1078 DeleteFileA("threedir");
1082 createTestFile("one.txt");
1083 createTestFile("two.txt");
1084 CreateDirectoryA("threedir", NULL
);
1086 /* pTo contains bogus 2nd name longer than MAX_PATH,
1087 * multiple source files, FOF_MULTIDESTFILES
1088 * dest dir does exist
1090 memset(to
, 'a', 2 * MAX_PATH
);
1091 memset(to
+MAX_PATH
*2, 0, 2);
1092 lstrcpyA(to
, "threedir");
1093 ptr
= to
+ lstrlenA(to
) + 1;
1094 lstrcpyA(ptr
, "fourdir");
1095 shfo
.pFrom
= "one.txt\0two.txt\0";
1097 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1098 FOF_SILENT
| FOF_NOERRORUI
;
1099 retval
= SHFileOperation(&shfo
);
1100 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1101 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1102 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1103 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1104 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1105 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1106 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1107 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1109 createTestFile("one.txt");
1110 createTestFile("two.txt");
1111 CreateDirectoryA("threedir", NULL
);
1113 /* multiple source files, FOF_MULTIDESTFILES
1114 * multiple dest files, but first dest dir exists
1115 * num files in lists is equal
1117 shfo
.pFrom
= "one.txt\0two.txt\0";
1118 shfo
.pTo
= "threedir\0fourdir\0";
1119 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1120 FOF_SILENT
| FOF_NOERRORUI
;
1121 retval
= SHFileOperation(&shfo
);
1122 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1123 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1124 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1125 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1126 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1127 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1128 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1129 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1131 createTestFile("one.txt");
1132 createTestFile("two.txt");
1133 CreateDirectoryA("threedir", NULL
);
1135 /* multiple source files, FOF_MULTIDESTFILES
1136 * multiple dest files, but first dest dir exists
1137 * num files in lists is not equal
1139 shfo
.pFrom
= "one.txt\0two.txt\0";
1140 shfo
.pTo
= "threedir\0fourdir\0five\0";
1141 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1142 FOF_SILENT
| FOF_NOERRORUI
;
1143 retval
= SHFileOperation(&shfo
);
1144 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1145 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1146 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1147 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1148 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1149 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1150 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1151 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1152 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1153 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1155 createTestFile("aa.txt");
1156 createTestFile("ab.txt");
1157 CreateDirectoryA("one", NULL
);
1158 CreateDirectoryA("two", NULL
);
1160 /* pFrom has a glob, pTo has more than one dest */
1161 shfo
.pFrom
= "a*.txt\0";
1162 shfo
.pTo
= "one\0two\0";
1163 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1164 retval
= SHFileOperation(&shfo
);
1165 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1166 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1167 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1168 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1169 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1170 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1171 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1172 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1173 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1176 /* tests the FO_MOVE action */
1177 static void test_move(void)
1179 SHFILEOPSTRUCTA shfo
, shfo2
;
1180 CHAR from
[5*MAX_PATH
];
1181 CHAR to
[5*MAX_PATH
];
1185 shfo
.wFunc
= FO_MOVE
;
1188 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1189 shfo
.hNameMappings
= NULL
;
1190 shfo
.lpszProgressTitle
= NULL
;
1192 set_curr_dir_path(from
, "test1.txt\0");
1193 set_curr_dir_path(to
, "test4.txt\0");
1194 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are moved recursively\n");
1195 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1196 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1198 set_curr_dir_path(from
, "test?.txt\0");
1199 set_curr_dir_path(to
, "testdir2\0");
1200 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1201 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1202 ok(!SHFileOperationA(&shfo
), "Files and directories are moved to directory\n");
1203 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1204 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1205 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1207 clean_after_shfo_tests();
1210 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
1211 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
1213 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1214 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1215 ok(!SHFileOperationA(&shfo2
), "Move many files\n");
1216 ok(file_exists("test6.txt"), "The file is moved - many files are "
1217 "specified as a target\n");
1218 DeleteFileA("test6.txt");
1219 DeleteFileA("test7.txt");
1220 RemoveDirectoryA("test8.txt");
1224 /* number of sources do not correspond to number of targets */
1225 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1226 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1227 ok(SHFileOperationA(&shfo2
), "Can't move many files\n");
1228 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1229 "specified as a target\n");
1233 set_curr_dir_path(from
, "test3.txt\0");
1234 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
1235 ok(!SHFileOperationA(&shfo
), "File is moved moving to other directory\n");
1236 ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
1238 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1239 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1240 ok(SHFileOperationA(&shfo
), "Cannot move many files\n");
1241 ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
1242 ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
1244 set_curr_dir_path(from
, "test1.txt\0");
1245 set_curr_dir_path(to
, "test6.txt\0");
1246 ok(!SHFileOperationA(&shfo
), "Move file\n");
1247 ok(!file_exists("test1.txt"), "The file is moved\n");
1248 ok(file_exists("test6.txt"), "The file is moved\n");
1249 set_curr_dir_path(from
, "test6.txt\0");
1250 set_curr_dir_path(to
, "test1.txt\0");
1251 ok(!SHFileOperationA(&shfo
), "Move file back\n");
1253 set_curr_dir_path(from
, "test4.txt\0");
1254 set_curr_dir_path(to
, "test6.txt\0");
1255 ok(!SHFileOperationA(&shfo
), "Move dir\n");
1256 ok(!file_exists("test4.txt"), "The dir is moved\n");
1257 ok(file_exists("test6.txt"), "The dir is moved\n");
1258 set_curr_dir_path(from
, "test6.txt\0");
1259 set_curr_dir_path(to
, "test4.txt\0");
1260 ok(!SHFileOperationA(&shfo
), "Move dir back\n");
1262 /* move one file to two others */
1264 shfo
.pFrom
= "test1.txt\0";
1265 shfo
.pTo
= "a.txt\0b.txt\0";
1266 retval
= SHFileOperationA(&shfo
);
1267 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1268 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1269 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1270 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1272 /* move two files to one other */
1273 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1274 shfo
.pTo
= "test1.txt\0";
1275 retval
= SHFileOperationA(&shfo
);
1276 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1277 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1278 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1279 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1281 /* move a directory into itself */
1282 shfo
.pFrom
= "test4.txt\0";
1283 shfo
.pTo
= "test4.txt\\b.txt\0";
1284 retval
= SHFileOperationA(&shfo
);
1285 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1286 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1287 ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
1289 /* move many files without FOF_MULTIDESTFILES */
1290 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1291 shfo
.pTo
= "d.txt\0e.txt\0";
1292 retval
= SHFileOperationA(&shfo
);
1293 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1294 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1295 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1297 /* number of sources != number of targets */
1298 shfo
.pTo
= "d.txt\0";
1299 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1300 retval
= SHFileOperationA(&shfo
);
1301 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1302 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1304 /* FO_MOVE does not create dest directories */
1305 shfo
.pFrom
= "test2.txt\0";
1306 shfo
.pTo
= "dir1\\dir2\\test2.txt\0";
1307 retval
= SHFileOperationA(&shfo
);
1308 ok(retval
== ERROR_CANCELLED
, "Expected ERROR_CANCELLED, got %d\n", retval
);
1309 ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
1311 /* try to overwrite an existing file */
1312 shfo
.pTo
= "test3.txt\0";
1313 retval
= SHFileOperationA(&shfo
);
1314 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1315 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1316 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1319 static void test_sh_create_dir(void)
1321 CHAR path
[MAX_PATH
];
1324 if(!pSHCreateDirectoryExA
)
1326 trace("skipping SHCreateDirectoryExA tests\n");
1330 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1331 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1332 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret
);
1333 ok(file_exists("testdir2"), "The first directory is not created\n");
1334 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
1336 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1337 ok(ERROR_ALREADY_EXISTS
== ret
, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret
);
1339 ret
= pSHCreateDirectoryExA(NULL
, "c:\\testdir3", NULL
);
1340 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
1343 static void test_sh_path_prepare(void)
1346 CHAR path
[MAX_PATH
];
1348 if(!pSHPathPrepareForWriteA
)
1350 trace("skipping SHPathPrepareForWriteA tests\n");
1354 /* directory exists, SHPPFW_NONE */
1355 set_curr_dir_path(path
, "testdir2\0");
1356 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1357 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1359 /* directory exists, SHPPFW_IGNOREFILENAME */
1360 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1361 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
1362 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1364 /* directory exists, SHPPFW_DIRCREATE */
1365 set_curr_dir_path(path
, "testdir2\0");
1366 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1367 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1369 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1370 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1371 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
1372 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1373 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1375 /* file exists, SHPPFW_NONE */
1376 set_curr_dir_path(path
, "test1.txt\0");
1377 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1378 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1380 /* file exists, SHPPFW_DIRCREATE */
1381 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1382 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1384 /* file exists, SHPPFW_NONE, trailing \ */
1385 set_curr_dir_path(path
, "test1.txt\\\0");
1386 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1387 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res
);
1389 /* relative path exists, SHPPFW_DIRCREATE */
1390 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE
);
1391 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1393 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
1394 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE
);
1395 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1396 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
1398 /* directory doesn't exist, SHPPFW_NONE */
1399 set_curr_dir_path(path
, "nonexistent\0");
1400 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1401 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1403 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
1404 set_curr_dir_path(path
, "nonexistent\\notreal\0");
1405 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
1406 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1407 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
1408 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1410 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1411 set_curr_dir_path(path
, "testdir2\\test4.txt\\\0");
1412 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
1413 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1414 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
1416 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
1417 set_curr_dir_path(path
, "nonexistent\\notreal\0");
1418 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1419 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1420 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
1422 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
1424 if(!pSHPathPrepareForWriteW
)
1426 skip("Skipping SHPathPrepareForWriteW tests\n");
1429 /* unicode directory doesn't exist, SHPPFW_NONE */
1430 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
1431 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1432 ok(!file_existsW(UNICODE_PATH
), "unicode path was created but shouldn't be\n");
1433 RemoveDirectoryW(UNICODE_PATH
);
1435 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
1436 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
1437 ok(res
== S_OK
, "res == %08x, expected S_OK\n", res
);
1438 ok(file_existsW(UNICODE_PATH
), "unicode path should've been created\n");
1440 /* unicode directory exists, SHPPFW_NONE */
1441 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
1442 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
1444 /* unicode directory exists, SHPPFW_DIRCREATE */
1445 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
1446 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
1447 RemoveDirectoryW(UNICODE_PATH
);
1450 static void test_unicode(void)
1452 SHFILEOPSTRUCTW shfoW
;
1456 if (!pSHFileOperationW
)
1458 skip("SHFileOperationW() is missing\n");
1463 shfoW
.wFunc
= FO_DELETE
;
1464 shfoW
.pFrom
= UNICODE_PATH
;
1466 shfoW
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1467 shfoW
.hNameMappings
= NULL
;
1468 shfoW
.lpszProgressTitle
= NULL
;
1470 /* Clean up before start test */
1471 DeleteFileW(UNICODE_PATH
);
1472 RemoveDirectoryW(UNICODE_PATH
);
1474 /* Make sure we are on a system that supports unicode */
1475 SetLastError(0xdeadbeef);
1476 file
= CreateFileW(UNICODE_PATH
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
1477 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
1479 skip("Unicode tests skipped on non-unicode system\n");
1484 /* Try to delete a file with unicode filename */
1485 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
1486 ret
= pSHFileOperationW(&shfoW
);
1487 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
1488 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
1490 /* Try to trash a file with unicode filename */
1491 createTestFileW(UNICODE_PATH
);
1492 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
1493 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
1494 ret
= pSHFileOperationW(&shfoW
);
1495 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
1496 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
1498 if(!pSHCreateDirectoryExW
)
1500 skip("Skipping SHCreateDirectoryExW tests\n");
1504 /* Try to delete a directory with unicode filename */
1505 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
1506 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
1507 ok(file_existsW(UNICODE_PATH
), "The directory is not created\n");
1508 shfoW
.fFlags
&= ~FOF_ALLOWUNDO
;
1509 ret
= pSHFileOperationW(&shfoW
);
1510 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
1511 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
1513 /* Try to trash a directory with unicode filename */
1514 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
1515 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
1516 ok(file_existsW(UNICODE_PATH
), "The directory was not created\n");
1517 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
1518 ret
= pSHFileOperationW(&shfoW
);
1519 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
1520 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
1523 START_TEST(shlfileop
)
1525 InitFunctionPointers();
1527 clean_after_shfo_tests();
1530 test_get_file_info();
1531 test_get_file_info_iconlist();
1532 clean_after_shfo_tests();
1536 clean_after_shfo_tests();
1540 clean_after_shfo_tests();
1544 clean_after_shfo_tests();
1548 clean_after_shfo_tests();
1550 test_sh_create_dir();
1551 clean_after_shfo_tests();
1554 test_sh_path_prepare();
1555 clean_after_shfo_tests();