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 /* Error codes could be pre-Win32 */
36 #define DE_SAMEFILE 0x71
37 #define DE_MANYSRC1DEST 0x72
38 #define DE_DIFFDIR 0x73
39 #define DE_OPCANCELLED 0x75
40 #define DE_DESTSUBTREE 0x76
41 #define DE_INVALIDFILES 0x7C
42 #define DE_DESTSAMETREE 0x7D
43 #define DE_FLDDESTISFILE 0x7E
44 #define DE_FILEDESTISFLD 0x80
45 #define expect_retval(ret, ret_prewin32)\
47 broken(retval == ret_prewin32),\
48 "Expected %d, got %d\n", ret, retval)
50 static CHAR CURR_DIR
[MAX_PATH
];
51 static const WCHAR UNICODE_PATH
[] = {'c',':','\\',0x00c4,'\0','\0'};
52 /* "c:\Ä", or "c:\A" with diaeresis */
53 /* Double-null termination needed for pFrom field of SHFILEOPSTRUCT */
55 static HMODULE hshell32
;
56 static int (WINAPI
*pSHCreateDirectoryExA
)(HWND
, LPCSTR
, LPSECURITY_ATTRIBUTES
);
57 static int (WINAPI
*pSHCreateDirectoryExW
)(HWND
, LPCWSTR
, LPSECURITY_ATTRIBUTES
);
58 static int (WINAPI
*pSHFileOperationW
)(LPSHFILEOPSTRUCTW
);
59 static DWORD_PTR (WINAPI
*pSHGetFileInfoW
)(LPCWSTR
, DWORD
, SHFILEINFOW
*, UINT
, UINT
);
60 static int (WINAPI
*pSHPathPrepareForWriteA
)(HWND
, IUnknown
*, LPCSTR
, DWORD
);
61 static int (WINAPI
*pSHPathPrepareForWriteW
)(HWND
, IUnknown
*, LPCWSTR
, DWORD
);
63 static void InitFunctionPointers(void)
65 hshell32
= GetModuleHandleA("shell32.dll");
66 pSHCreateDirectoryExA
= (void*)GetProcAddress(hshell32
, "SHCreateDirectoryExA");
67 pSHCreateDirectoryExW
= (void*)GetProcAddress(hshell32
, "SHCreateDirectoryExW");
68 pSHFileOperationW
= (void*)GetProcAddress(hshell32
, "SHFileOperationW");
69 pSHGetFileInfoW
= (void*)GetProcAddress(hshell32
, "SHGetFileInfoW");
70 pSHPathPrepareForWriteA
= (void*)GetProcAddress(hshell32
, "SHPathPrepareForWriteA");
71 pSHPathPrepareForWriteW
= (void*)GetProcAddress(hshell32
, "SHPathPrepareForWriteW");
74 /* creates a file with the specified name for tests */
75 static void createTestFile(const CHAR
*name
)
80 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
81 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
82 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
83 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
87 static void createTestFileW(const WCHAR
*name
)
91 file
= CreateFileW(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
92 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file\n");
96 static BOOL
file_exists(const CHAR
*name
)
98 return GetFileAttributesA(name
) != INVALID_FILE_ATTRIBUTES
;
101 static BOOL
dir_exists(const CHAR
*name
)
106 attr
= GetFileAttributesA(name
);
107 dir
= ((attr
& FILE_ATTRIBUTE_DIRECTORY
) == FILE_ATTRIBUTE_DIRECTORY
);
109 return ((attr
!= INVALID_FILE_ATTRIBUTES
) && dir
);
112 static BOOL
file_existsW(LPCWSTR name
)
114 return GetFileAttributesW(name
) != INVALID_FILE_ATTRIBUTES
;
117 static BOOL
file_has_content(const CHAR
*name
, const CHAR
*content
)
123 file
= CreateFileA(name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
124 if (file
== INVALID_HANDLE_VALUE
)
126 ReadFile(file
, buf
, MAX_PATH
- 1, &read
, NULL
);
129 return strcmp(buf
, content
)==0;
132 /* initializes the tests */
133 static void init_shfo_tests(void)
137 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
138 len
= lstrlenA(CURR_DIR
);
140 if(len
&& (CURR_DIR
[len
-1] == '\\'))
143 createTestFile("test1.txt");
144 createTestFile("test2.txt");
145 createTestFile("test3.txt");
146 createTestFile("test_5.txt");
147 CreateDirectoryA("test4.txt", NULL
);
148 CreateDirectoryA("testdir2", NULL
);
149 CreateDirectoryA("testdir2\\nested", NULL
);
150 createTestFile("testdir2\\one.txt");
151 createTestFile("testdir2\\nested\\two.txt");
154 /* cleans after tests */
155 static void clean_after_shfo_tests(void)
157 DeleteFileA("test1.txt");
158 DeleteFileA("test2.txt");
159 DeleteFileA("test3.txt");
160 DeleteFileA("test_5.txt");
161 DeleteFileA("one.txt");
162 DeleteFileA("test4.txt\\test1.txt");
163 DeleteFileA("test4.txt\\test2.txt");
164 DeleteFileA("test4.txt\\test3.txt");
165 RemoveDirectoryA("test4.txt");
166 DeleteFileA("testdir2\\one.txt");
167 DeleteFileA("testdir2\\test1.txt");
168 DeleteFileA("testdir2\\test2.txt");
169 DeleteFileA("testdir2\\test3.txt");
170 DeleteFileA("testdir2\\test4.txt\\test1.txt");
171 DeleteFileA("testdir2\\nested\\two.txt");
172 RemoveDirectoryA("testdir2\\test4.txt");
173 RemoveDirectoryA("testdir2\\nested");
174 RemoveDirectoryA("testdir2");
175 RemoveDirectoryA("c:\\testdir3");
176 DeleteFileA("nonexistent\\notreal\\test2.txt");
177 RemoveDirectoryA("nonexistent\\notreal");
178 RemoveDirectoryA("nonexistent");
182 static void test_get_file_info(void)
185 SHFILEINFOA shfi
, shfi2
;
187 char notepad
[MAX_PATH
];
189 /* Test whether fields of SHFILEINFOA are always cleared */
190 memset(&shfi
, 0xcf, sizeof(shfi
));
191 rc
=SHGetFileInfoA("", 0, &shfi
, sizeof(shfi
), 0);
192 ok(rc
, "SHGetFileInfoA('' | 0) should not fail\n");
193 todo_wine
ok(shfi
.hIcon
== 0, "SHGetFileInfoA('' | 0) did not clear hIcon\n");
194 todo_wine
ok(shfi
.szDisplayName
[0] == 0, "SHGetFileInfoA('' | 0) did not clear szDisplayName[0]\n");
195 todo_wine
ok(shfi
.szTypeName
[0] == 0, "SHGetFileInfoA('' | 0) did not clear szTypeName[0]\n");
196 ok(shfi
.iIcon
== 0xcfcfcfcf ||
197 broken(shfi
.iIcon
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
198 "SHGetFileInfoA('' | 0) should not clear iIcon\n");
199 ok(shfi
.dwAttributes
== 0xcfcfcfcf ||
200 broken(shfi
.dwAttributes
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
201 "SHGetFileInfoA('' | 0) should not clear dwAttributes\n");
205 /* Test whether fields of SHFILEINFOW are always cleared */
206 memset(&shfiw
, 0xcf, sizeof(shfiw
));
207 rc
=pSHGetFileInfoW(NULL
, 0, &shfiw
, sizeof(shfiw
), 0);
208 todo_wine
ok(!rc
, "SHGetFileInfoW(NULL | 0) should fail\n");
209 ok(shfiw
.hIcon
== (HANDLE
) 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear hIcon\n");
210 todo_wine
ok(shfiw
.szDisplayName
[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szDisplayName[0]\n");
211 todo_wine
ok(shfiw
.szTypeName
[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szTypeName[0]\n");
212 todo_wine
ok(shfiw
.iIcon
== 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear iIcon\n");
213 ok(shfiw
.dwAttributes
== 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear dwAttributes\n");
216 win_skip("SHGetFileInfoW is not available\n");
219 /* Test some flag combinations that MSDN claims are not allowed,
220 * but which work anyway
222 memset(&shfi
, 0xcf, sizeof(shfi
));
223 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
225 SHGFI_ATTRIBUTES
| SHGFI_USEFILEATTRIBUTES
);
226 ok(rc
, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) failed\n");
228 ok(shfi
.dwAttributes
!= 0xcfcfcfcf, "dwFileAttributes is not set\n");
229 todo_wine
ok(shfi
.hIcon
== 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear hIcon\n");
230 todo_wine
ok(shfi
.szDisplayName
[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szDisplayName[0]\n");
231 todo_wine
ok(shfi
.szTypeName
[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szTypeName[0]\n");
232 ok(shfi
.iIcon
== 0xcfcfcfcf ||
233 broken(shfi
.iIcon
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
234 "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should not clear iIcon\n");
236 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
238 SHGFI_EXETYPE
| SHGFI_USEFILEATTRIBUTES
);
239 todo_wine
ok(rc
== 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) returned %d\n", rc
);
241 /* Test SHGFI_USEFILEATTRIBUTES support */
242 strcpy(shfi
.szDisplayName
, "dummy");
243 shfi
.iIcon
=0xdeadbeef;
244 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
246 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
247 ok(rc
, "SHGetFileInfoA(c:\\nonexistent) failed\n");
250 ok(strcpy(shfi
.szDisplayName
, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
251 ok(shfi
.iIcon
!= 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
254 /* Wine does not have a default icon for text files, and Windows 98 fails
255 * if we give it an empty executable. So use notepad.exe as the test
257 if (SearchPath(NULL
, "notepad.exe", NULL
, sizeof(notepad
), notepad
, NULL
))
259 strcpy(shfi
.szDisplayName
, "dummy");
260 shfi
.iIcon
=0xdeadbeef;
261 rc
=SHGetFileInfoA(notepad
, GetFileAttributes(notepad
),
263 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
264 ok(rc
, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) failed\n", notepad
);
265 strcpy(shfi2
.szDisplayName
, "dummy");
266 shfi2
.iIcon
=0xdeadbeef;
267 rc2
=SHGetFileInfoA(notepad
, 0,
268 &shfi2
, sizeof(shfi2
),
270 ok(rc2
, "SHGetFileInfoA(%s) failed\n", notepad
);
273 ok(lstrcmpi(shfi2
.szDisplayName
, shfi
.szDisplayName
) == 0, "wrong display name %s != %s\n", shfi
.szDisplayName
, shfi2
.szDisplayName
);
274 ok(shfi2
.iIcon
== shfi
.iIcon
, "wrong icon index %d != %d\n", shfi
.iIcon
, shfi2
.iIcon
);
278 /* with a directory now */
279 strcpy(shfi
.szDisplayName
, "dummy");
280 shfi
.iIcon
=0xdeadbeef;
281 rc
=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
283 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
284 ok(rc
, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) failed\n");
285 strcpy(shfi2
.szDisplayName
, "dummy");
286 shfi2
.iIcon
=0xdeadbeef;
287 rc2
=SHGetFileInfoA("test4.txt", 0,
288 &shfi2
, sizeof(shfi2
),
290 ok(rc2
, "SHGetFileInfoA(test4.txt/) failed\n");
293 ok(lstrcmpi(shfi2
.szDisplayName
, shfi
.szDisplayName
) == 0, "wrong display name %s != %s\n", shfi
.szDisplayName
, shfi2
.szDisplayName
);
294 ok(shfi2
.iIcon
== shfi
.iIcon
, "wrong icon index %d != %d\n", shfi
.iIcon
, shfi2
.iIcon
);
298 static void test_get_file_info_iconlist(void)
300 /* Test retrieving a handle to the system image list, and
301 * what that returns for hIcon
304 HIMAGELIST hSysImageList
;
305 LPITEMIDLIST pidList
;
309 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_DESKTOP
, &pidList
);
311 skip("can't get desktop pidl\n");
315 memset(&shInfoa
, 0xcf, sizeof(shInfoa
));
316 hSysImageList
= (HIMAGELIST
) SHGetFileInfoA((const char *)pidList
, 0,
317 &shInfoa
, sizeof(shInfoa
),
318 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_PIDL
);
319 ok(hSysImageList
!= INVALID_HANDLE_VALUE
, "Can't get handle for CSIDL_DESKTOP imagelist\n");
320 todo_wine
ok(shInfoa
.hIcon
== 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
321 todo_wine
ok(shInfoa
.szTypeName
[0] == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
322 ok(shInfoa
.iIcon
!= 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
323 ok(shInfoa
.dwAttributes
== 0xcfcfcfcf ||
324 shInfoa
.dwAttributes
== 0 || /* Vista */
325 broken(shInfoa
.dwAttributes
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
326 "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL), unexpected dwAttributes\n");
327 CloseHandle(hSysImageList
);
329 if (!pSHGetFileInfoW
)
331 win_skip("SHGetFileInfoW is not available\n");
336 memset(&shInfow
, 0xcf, sizeof(shInfow
));
337 hSysImageList
= (HIMAGELIST
) pSHGetFileInfoW((const WCHAR
*)pidList
, 0,
338 &shInfow
, sizeof(shInfow
),
339 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_PIDL
);
342 win_skip("SHGetFileInfoW is not implemented\n");
345 ok(hSysImageList
!= INVALID_HANDLE_VALUE
, "Can't get handle for CSIDL_DESKTOP imagelist\n");
346 todo_wine
ok(shInfow
.hIcon
== 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
347 ok(shInfow
.szTypeName
[0] == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
348 ok(shInfow
.iIcon
!= 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
349 ok(shInfow
.dwAttributes
== 0xcfcfcfcf ||
350 shInfoa
.dwAttributes
== 0, /* Vista */
351 "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) unexpected dwAttributes\n");
352 CloseHandle(hSysImageList
);
354 /* Various suposidly invalid flag testing */
355 memset(&shInfow
, 0xcf, sizeof(shInfow
));
356 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
357 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
358 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
359 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
360 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
361 shInfoa
.dwAttributes
==0, /* Vista */
362 "unexpected dwAttributes\n");
364 memset(&shInfow
, 0xcf, sizeof(shInfow
));
365 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
366 SHGFI_ICON
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
367 ok(hr
!= 0, " SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
368 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
369 ok(shInfow
.hIcon
!=(HICON
)0xcfcfcfcf && shInfow
.hIcon
!=0,"hIcon invalid\n");
370 if (shInfow
.hIcon
!=(HICON
)0xcfcfcfcf) DestroyIcon(shInfow
.hIcon
);
371 todo_wine
ok(shInfow
.dwAttributes
==0,"dwAttributes not set\n");
373 memset(&shInfow
, 0xcf, sizeof(shInfow
));
374 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
375 SHGFI_ICON
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_LARGEICON
);
376 ok(hr
!= 0, "SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
377 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
378 ok(shInfow
.hIcon
!=(HICON
)0xcfcfcfcf && shInfow
.hIcon
!=0,"hIcon invalid\n");
379 if (shInfow
.hIcon
!= (HICON
)0xcfcfcfcf) DestroyIcon(shInfow
.hIcon
);
380 todo_wine
ok(shInfow
.dwAttributes
==0,"dwAttributes not set\n");
382 memset(&shInfow
, 0xcf, sizeof(shInfow
));
383 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
384 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_LARGEICON
);
385 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
386 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
387 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
388 shInfoa
.dwAttributes
==0, /* Vista */
389 "unexpected dwAttributes\n");
391 memset(&shInfow
, 0xcf, sizeof(shInfow
));
392 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
393 SHGFI_OPENICON
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
394 ok(hr
!= 0, "SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
395 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
396 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
398 memset(&shInfow
, 0xcf, sizeof(shInfow
));
399 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
400 SHGFI_SHELLICONSIZE
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
401 ok(hr
!= 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
402 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
403 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
405 memset(&shInfow
, 0xcf, sizeof(shInfow
));
406 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
407 SHGFI_SHELLICONSIZE
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
408 ok(hr
!= 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
409 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
410 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
412 memset(&shInfow
, 0xcf, sizeof(shInfow
));
413 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
414 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|
416 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
417 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
418 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
420 memset(&shInfow
, 0xcf, sizeof(shInfow
));
421 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
422 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|
424 todo_wine
ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
425 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
426 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
427 shInfoa
.dwAttributes
==0, /* Vista */
428 "unexpected dwAttributes\n");
430 memset(&shInfow
, 0xcf, sizeof(shInfow
));
431 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
432 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|SHGFI_EXETYPE
);
433 todo_wine
ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
434 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
435 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
437 memset(&shInfow
, 0xcf, sizeof(shInfow
));
438 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
439 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|SHGFI_ATTRIBUTES
);
440 ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
441 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
442 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
444 memset(&shInfow
, 0xcf, sizeof(shInfow
));
445 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
446 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|
448 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
449 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
450 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
452 memset(&shInfow
, 0xcf, sizeof(shInfow
));
453 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
454 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_EXETYPE
);
455 todo_wine
ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
456 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
457 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
458 shInfoa
.dwAttributes
==0, /* Vista */
459 "unexpected dwAttributes\n");
461 memset(&shInfow
, 0xcf, sizeof(shInfow
));
462 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
463 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_EXETYPE
);
464 todo_wine
ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
465 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
466 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
468 memset(&shInfow
, 0xcf, sizeof(shInfow
));
469 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
470 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_ATTRIBUTES
);
471 ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
472 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
473 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
480 puts into the specified buffer file names with current directory.
481 files - string with file names, separated by null characters. Ends on a double
484 static void set_curr_dir_path(CHAR
*buf
, const CHAR
* files
)
489 strcpy(buf
, CURR_DIR
);
494 buf
+= strlen(buf
) + 1;
495 files
+= strlen(files
) + 1;
501 /* tests the FO_DELETE action */
502 static void test_delete(void)
504 SHFILEOPSTRUCTA shfo
;
506 CHAR buf
[sizeof(CURR_DIR
)+sizeof("/test?.txt")+1];
508 sprintf(buf
, "%s\\%s", CURR_DIR
, "test?.txt");
509 buf
[strlen(buf
) + 1] = '\0';
512 shfo
.wFunc
= FO_DELETE
;
515 shfo
.fFlags
= FOF_FILESONLY
| FOF_NOCONFIRMATION
| FOF_SILENT
;
516 shfo
.hNameMappings
= NULL
;
517 shfo
.lpszProgressTitle
= NULL
;
519 ok(!SHFileOperationA(&shfo
), "Deletion was not successful\n");
520 ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
521 ok(!file_exists("test1.txt"), "File should have been removed\n");
522 ok(!file_exists("test2.txt"), "File should have been removed\n");
523 ok(!file_exists("test3.txt"), "File should have been removed\n");
525 ret
= SHFileOperationA(&shfo
);
526 ok(ret
== ERROR_SUCCESS
, "Directory exists, but is not removed, ret=%d\n", ret
);
527 ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
529 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
531 ok(!SHFileOperationA(&shfo
), "Directory is not removed\n");
532 ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
534 ret
= SHFileOperationA(&shfo
);
535 ok(!ret
, "The requested file does not exist, ret=%d\n", ret
);
538 sprintf(buf
, "%s\\%s", CURR_DIR
, "test4.txt");
539 buf
[strlen(buf
) + 1] = '\0';
540 ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
541 ok(!SHFileOperationA(&shfo
), "Directory is not removed\n");
542 ok(!dir_exists("test4.txt"), "Directory is not removed\n");
545 shfo
.pFrom
= "test1.txt\0test4.txt\0";
546 ok(!SHFileOperationA(&shfo
), "Directory and a file are not removed\n");
547 ok(!file_exists("test1.txt"), "The file should have been removed\n");
548 ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
549 ok(file_exists("test2.txt"), "This file should not have been removed\n");
551 /* FOF_FILESONLY does not delete a dir matching a wildcard */
553 shfo
.fFlags
|= FOF_FILESONLY
;
554 shfo
.pFrom
= "*.txt\0";
555 ok(!SHFileOperation(&shfo
), "Failed to delete files\n");
556 ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
557 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
558 ok(dir_exists("test4.txt"), "test4.txt should not have been removed\n");
560 /* FOF_FILESONLY only deletes a dir if explicitly specified */
562 shfo
.pFrom
= "test_?.txt\0test4.txt\0";
563 ok(!SHFileOperation(&shfo
), "Failed to delete files and directory\n");
564 ok(!dir_exists("test4.txt") ||
565 broken(dir_exists("test4.txt")), /* NT4 */
566 "test4.txt should have been removed\n");
567 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
568 ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
570 /* try to delete an invalid filename */
572 /* this crashes on win9x */
575 shfo
.fFlags
&= ~FOF_FILESONLY
;
576 shfo
.fAnyOperationsAborted
= FALSE
;
577 ret
= SHFileOperation(&shfo
);
578 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
579 ok(!shfo
.fAnyOperationsAborted
, "Expected no aborted operations\n");
580 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
583 /* try an invalid function */
585 shfo
.pFrom
= "test1.txt\0";
587 ret
= SHFileOperation(&shfo
);
588 ok(ret
== ERROR_INVALID_PARAMETER
||
589 broken(ret
== ERROR_SUCCESS
), /* Win9x, NT4 */
590 "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
591 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
593 /* try an invalid list, only one null terminator */
595 /* this crashes on win9x */
598 shfo
.wFunc
= FO_DELETE
;
599 ret
= SHFileOperation(&shfo
);
600 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
601 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
604 /* delete a nonexistent file */
605 shfo
.pFrom
= "nonexistent.txt\0";
606 shfo
.wFunc
= FO_DELETE
;
607 ret
= SHFileOperation(&shfo
);
610 ret
== ERROR_FILE_NOT_FOUND
|| /* Vista */
611 broken(ret
== ERROR_SUCCESS
), /* NT4 */
612 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
614 /* delete a dir, and then a file inside the dir, same as
615 * deleting a nonexistent file
617 if (ret
!= ERROR_FILE_NOT_FOUND
)
619 /* Vista would throw up a dialog box that we can't suppress */
621 shfo
.pFrom
= "testdir2\0testdir2\\one.txt\0";
622 ret
= SHFileOperation(&shfo
);
623 ok(ret
== ERROR_PATH_NOT_FOUND
||
624 broken(ret
== ERROR_SUCCESS
), /* NT4 */
625 "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret
);
626 ok(!dir_exists("testdir2"), "Expected testdir2 to not exist\n");
627 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
630 skip("Test would show a dialog box\n");
632 /* try the FOF_NORECURSION flag, continues deleting subdirs */
634 shfo
.pFrom
= "testdir2\0";
635 shfo
.fFlags
|= FOF_NORECURSION
;
636 ret
= SHFileOperation(&shfo
);
637 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
638 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
639 ok(!dir_exists("testdir2\\nested"), "Expected testdir2\\nested to not exist\n");
642 /* tests the FO_RENAME action */
643 static void test_rename(void)
645 SHFILEOPSTRUCTA shfo
, shfo2
;
646 CHAR from
[5*MAX_PATH
];
651 shfo
.wFunc
= FO_RENAME
;
654 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
655 shfo
.hNameMappings
= NULL
;
656 shfo
.lpszProgressTitle
= NULL
;
658 set_curr_dir_path(from
, "test1.txt\0");
659 set_curr_dir_path(to
, "test4.txt\0");
660 retval
= SHFileOperationA(&shfo
);
661 ok(retval
== ERROR_ALREADY_EXISTS
||
662 retval
== DE_FILEDESTISFLD
|| /* Vista */
663 broken(retval
== ERROR_INVALID_NAME
), /* Win9x, NT4 */
664 "Expected ERROR_ALREADY_EXISTS or DE_FILEDESTISFLD, got %d\n", retval
);
665 ok(file_exists("test1.txt"), "The file is renamed\n");
667 set_curr_dir_path(from
, "test3.txt\0");
668 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
669 retval
= SHFileOperationA(&shfo
);
670 if (retval
== DE_DIFFDIR
)
672 /* Vista and W2K8 (broken or new behavior ?) */
673 ok(!file_exists("test4.txt\\test1.txt"), "The file is renamed\n");
677 ok(retval
== ERROR_SUCCESS
, "File is renamed moving to other directory\n");
678 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
681 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
682 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
683 retval
= SHFileOperationA(&shfo
);
684 ok(retval
== ERROR_GEN_FAILURE
||
685 retval
== DE_MANYSRC1DEST
|| /* Vista */
686 broken(retval
== ERROR_SUCCESS
), /* Win9x */
687 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST , got %d\n", retval
);
688 ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
690 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
691 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
693 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
694 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
695 retval
= SHFileOperationA(&shfo2
);
696 ok(retval
== ERROR_GEN_FAILURE
||
697 retval
== DE_MANYSRC1DEST
|| /* Vista */
698 broken(retval
== ERROR_SUCCESS
), /* Win9x */
699 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST files, got %d\n", retval
);
700 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
702 set_curr_dir_path(from
, "test1.txt\0");
703 set_curr_dir_path(to
, "test6.txt\0");
704 retval
= SHFileOperationA(&shfo
);
705 ok(retval
== ERROR_SUCCESS
, "Rename file failed, retval = %d\n", retval
);
706 ok(!file_exists("test1.txt"), "The file is not renamed\n");
707 ok(file_exists("test6.txt"), "The file is not renamed\n");
709 set_curr_dir_path(from
, "test6.txt\0");
710 set_curr_dir_path(to
, "test1.txt\0");
711 retval
= SHFileOperationA(&shfo
);
712 ok(retval
== ERROR_SUCCESS
, "Rename file back failed, retval = %d\n", retval
);
714 set_curr_dir_path(from
, "test4.txt\0");
715 set_curr_dir_path(to
, "test6.txt\0");
716 retval
= SHFileOperationA(&shfo
);
717 ok(retval
== ERROR_SUCCESS
, "Rename dir failed, retval = %d\n", retval
);
718 ok(!dir_exists("test4.txt"), "The dir is not renamed\n");
719 ok(dir_exists("test6.txt"), "The dir is not renamed\n");
721 set_curr_dir_path(from
, "test6.txt\0");
722 set_curr_dir_path(to
, "test4.txt\0");
723 retval
= SHFileOperationA(&shfo
);
724 ok(retval
== ERROR_SUCCESS
, "Rename dir back failed, retval = %d\n", retval
);
725 ok(dir_exists("test4.txt"), "The dir is not renamed\n");
727 /* try to rename more than one file to a single file */
728 shfo
.pFrom
= "test1.txt\0test2.txt\0";
729 shfo
.pTo
= "a.txt\0";
730 retval
= SHFileOperationA(&shfo
);
731 ok(retval
== ERROR_GEN_FAILURE
||
732 retval
== DE_MANYSRC1DEST
|| /* Vista */
733 broken(retval
== ERROR_SUCCESS
), /* Win9x */
734 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST, got %d\n", retval
);
735 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
736 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
737 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
739 /* pFrom doesn't exist */
740 shfo
.pFrom
= "idontexist\0";
741 shfo
.pTo
= "newfile\0";
742 retval
= SHFileOperationA(&shfo
);
744 retval
== ERROR_FILE_NOT_FOUND
|| /* Vista */
745 broken(retval
== ERROR_SUCCESS
), /* NT4 */
746 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval
);
747 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
749 /* pTo already exist */
750 shfo
.pFrom
= "test1.txt\0";
751 shfo
.pTo
= "test2.txt\0";
752 retval
= SHFileOperationA(&shfo
);
753 if (retval
== ERROR_SUCCESS
)
755 /* Vista and W2K8 (broken or new behavior ?) */
756 createTestFile("test1.txt");
760 ok(retval
== ERROR_ALREADY_EXISTS
||
761 broken(retval
== DE_OPCANCELLED
) || /* NT4 */
762 broken(retval
== ERROR_INVALID_NAME
), /* Win9x */
763 "Expected ERROR_ALREADY_EXISTS, got %d\n", retval
);
766 /* pFrom is valid, but pTo is empty */
767 shfo
.pFrom
= "test1.txt\0";
769 retval
= SHFileOperationA(&shfo
);
770 ok(retval
== ERROR_CANCELLED
||
771 retval
== DE_DIFFDIR
|| /* Vista */
772 broken(retval
== DE_OPCANCELLED
) || /* Win9x */
773 broken(retval
== 65652), /* NT4 */
774 "Expected ERROR_CANCELLED or DE_DIFFDIR\n");
775 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
779 retval
= SHFileOperationA(&shfo
);
780 ok(retval
== ERROR_ACCESS_DENIED
||
781 retval
== DE_MANYSRC1DEST
|| /* Vista */
782 broken(retval
== ERROR_SUCCESS
), /* Win9x */
783 "Expected ERROR_ACCESS_DENIED or DE_MANYSRC1DEST, got %d\n", retval
);
785 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
789 retval
= SHFileOperationA(&shfo
);
790 ok(retval
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval
);
794 /* tests the FO_COPY action */
795 static void test_copy(void)
797 SHFILEOPSTRUCTA shfo
, shfo2
;
798 CHAR from
[5*MAX_PATH
];
800 FILEOP_FLAGS tmp_flags
;
806 shfo
.wFunc
= FO_COPY
;
809 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
810 shfo
.hNameMappings
= NULL
;
811 shfo
.lpszProgressTitle
= NULL
;
813 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
814 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
815 retval
= SHFileOperationA(&shfo
);
816 if (dir_exists("test6.txt"))
818 /* Vista and W2K8 (broken or new behavior ?) */
819 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
820 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
821 "are specified as a target\n");
822 DeleteFileA("test6.txt\\test2.txt");
823 RemoveDirectoryA("test6.txt\\test4.txt");
824 RemoveDirectoryA("test6.txt");
828 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
829 ok(!file_exists("test6.txt"), "The file is copied - many files are "
830 "specified as a target\n");
833 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
834 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
836 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
837 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
838 ok(!SHFileOperationA(&shfo2
), "Can't copy many files\n");
839 ok(file_exists("test6.txt"), "The file is not copied - many files are "
840 "specified as a target\n");
841 DeleteFileA("test6.txt");
842 DeleteFileA("test7.txt");
843 RemoveDirectoryA("test8.txt");
845 /* number of sources do not correspond to number of targets */
846 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
847 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
848 retval
= SHFileOperationA(&shfo2
);
849 if (dir_exists("test6.txt"))
851 /* Vista and W2K8 (broken or new behavior ?) */
852 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
853 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
854 "are specified as a target\n");
855 RemoveDirectoryA("test6.txt");
856 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not copied - many files "
857 "are specified as a target\n");
858 RemoveDirectoryA("test7.txt");
862 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
863 ok(!file_exists("test6.txt"), "The file is copied - many files are "
864 "specified as a target\n");
867 set_curr_dir_path(from
, "test1.txt\0");
868 set_curr_dir_path(to
, "test4.txt\0");
869 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are copied recursively\n");
870 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
872 set_curr_dir_path(from
, "test?.txt\0");
873 set_curr_dir_path(to
, "testdir2\0");
874 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
875 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
876 ok(!SHFileOperationA(&shfo
), "Files and directories are copied to directory\n");
877 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
878 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
879 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
880 clean_after_shfo_tests();
883 shfo
.fFlags
|= FOF_FILESONLY
;
884 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
885 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
886 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
887 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
888 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
889 clean_after_shfo_tests();
892 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
893 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
894 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
895 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
896 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
897 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
898 clean_after_shfo_tests();
900 /* Copying multiple files with one not existing as source, fails the
901 entire operation in Win98/ME/2K/XP, but not in 95/NT */
903 tmp_flags
= shfo
.fFlags
;
904 set_curr_dir_path(from
, "test1.txt\0test10.txt\0test2.txt\0");
905 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
906 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
907 retval
= SHFileOperationA(&shfo
);
908 if (retval
== ERROR_SUCCESS
)
909 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
910 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
913 /* Failure if one source file does not exist */
914 ok(retval
== 1026 || /* Win 98/ME/2K/XP */
915 retval
== ERROR_FILE_NOT_FOUND
, /* Vista and W2K8 */
916 "Files are copied to other directory\n");
917 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
919 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
920 shfo
.fFlags
= tmp_flags
;
922 /* copy into a nonexistent directory */
924 shfo
.fFlags
= FOF_NOCONFIRMMKDIR
;
925 set_curr_dir_path(from
, "test1.txt\0");
926 set_curr_dir_path(to
, "nonexistent\\notreal\\test2.txt\0");
927 retval
= SHFileOperation(&shfo
);
928 ok(!retval
, "Error copying into nonexistent directory\n");
929 ok(file_exists("nonexistent"), "nonexistent not created\n");
930 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
931 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
932 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
934 /* a relative dest directory is OK */
935 clean_after_shfo_tests();
937 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
938 shfo
.pTo
= "testdir2\0";
939 retval
= SHFileOperation(&shfo
);
940 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
941 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
943 /* try to copy files to a file */
944 clean_after_shfo_tests();
948 /* suppress the error-dialog in win9x here */
949 shfo
.fFlags
|= FOF_NOERRORUI
;
950 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
951 set_curr_dir_path(to
, "test3.txt\0");
952 retval
= SHFileOperation(&shfo
);
953 if (retval
== DE_FLDDESTISFILE
)
955 /* Vista and W2K8 (broken or new behavior ?) */
956 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
960 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
961 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
963 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
965 /* try to copy many files to nonexistent directory */
967 shfo
.fFlags
&= ~FOF_NOERRORUI
;
968 shfo
.fAnyOperationsAborted
= FALSE
;
969 retval
= SHFileOperation(&shfo
);
970 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
971 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
972 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
973 ok(RemoveDirectory(to
), "Expected test3.txt to exist\n");
975 /* send in FOF_MULTIDESTFILES with too many destination files */
977 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
978 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
979 shfo
.fFlags
|= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
980 retval
= SHFileOperation(&shfo
);
981 if (dir_exists("testdir2\\a.txt"))
983 /* Vista and W2K8 (broken or new behavior ?) */
984 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
985 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
986 RemoveDirectory("testdir2\\a.txt");
987 ok(DeleteFile("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
988 RemoveDirectory("testdir2\\b.txt");
989 ok(DeleteFile("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
990 RemoveDirectory("testdir2\\c.txt");
991 ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
995 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
996 ok(shfo
.fAnyOperationsAborted
||
997 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
998 "Expected aborted operations\n");
999 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
1002 /* send in FOF_MULTIDESTFILES with too many destination files */
1003 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1004 shfo
.pTo
= "e.txt\0f.txt\0";
1005 shfo
.fAnyOperationsAborted
= FALSE
;
1006 retval
= SHFileOperation(&shfo
);
1007 if (dir_exists("e.txt"))
1009 /* Vista and W2K8 (broken or new behavior ?) */
1010 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1011 ok(DeleteFile("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
1012 RemoveDirectory("e.txt");
1013 ok(DeleteFile("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
1014 RemoveDirectory("f.txt");
1018 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1019 ok(shfo
.fAnyOperationsAborted
||
1020 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1021 "Expected aborted operations\n");
1022 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
1025 /* use FOF_MULTIDESTFILES with files and a source directory */
1026 shfo
.pFrom
= "test1.txt\0test2.txt\0test4.txt\0";
1027 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
1028 shfo
.fAnyOperationsAborted
= FALSE
;
1029 retval
= SHFileOperation(&shfo
);
1030 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1031 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1032 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
1033 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
1035 /* try many dest files without FOF_MULTIDESTFILES flag */
1036 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1037 shfo
.pTo
= "a.txt\0b.txt\0c.txt\0";
1038 shfo
.fAnyOperationsAborted
= FALSE
;
1039 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1040 retval
= SHFileOperation(&shfo
);
1041 if (dir_exists("a.txt"))
1043 /* Vista and W2K8 (broken or new behavior ?) */
1044 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1045 ok(DeleteFile("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
1046 ok(DeleteFile("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
1047 ok(DeleteFile("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
1048 RemoveDirectory("a.txt");
1052 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1053 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1057 shfo
.pFrom
= "test?.txt\0";
1058 shfo
.pTo
= "testdir2\0";
1059 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1060 retval
= SHFileOperation(&shfo
);
1061 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1062 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1064 /* try a glob with FOF_FILESONLY */
1065 clean_after_shfo_tests();
1067 shfo
.pFrom
= "test?.txt\0";
1068 shfo
.fFlags
|= FOF_FILESONLY
;
1069 retval
= SHFileOperation(&shfo
);
1070 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1071 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1072 ok(!dir_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
1074 /* try a glob with FOF_MULTIDESTFILES and the same number
1075 * of dest files that we would expect
1077 clean_after_shfo_tests();
1079 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1080 shfo
.fFlags
&= ~FOF_FILESONLY
;
1081 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1082 retval
= SHFileOperation(&shfo
);
1083 if (dir_exists("testdir2\\a.txt"))
1085 /* Vista and W2K8 (broken or new behavior ?) */
1086 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1087 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1088 ok(DeleteFile("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
1089 ok(DeleteFile("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
1090 ok(RemoveDirectory("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
1091 RemoveDirectory("testdir2\\a.txt");
1095 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1096 ok(shfo
.fAnyOperationsAborted
||
1097 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1098 "Expected aborted operations\n");
1099 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
1101 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
1103 /* copy one file to two others, second is ignored */
1104 clean_after_shfo_tests();
1106 shfo
.pFrom
= "test1.txt\0";
1107 shfo
.pTo
= "b.txt\0c.txt\0";
1108 shfo
.fAnyOperationsAborted
= FALSE
;
1109 retval
= SHFileOperation(&shfo
);
1110 if (retval
== DE_OPCANCELLED
)
1112 /* NT4 fails and doesn't copy any files */
1113 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1114 /* Needed to skip some tests */
1115 win_skip("Skipping some tests on NT4\n");
1120 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1121 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1123 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1125 /* copy two file to three others, all fail */
1126 shfo
.pFrom
= "test1.txt\0test2.txt\0";
1127 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1128 retval
= SHFileOperation(&shfo
);
1129 if (dir_exists("b.txt"))
1131 /* Vista and W2K8 (broken or new behavior ?) */
1132 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1133 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1134 RemoveDirectory("b.txt");
1135 ok(DeleteFile("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1136 RemoveDirectory("c.txt");
1140 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1141 ok(shfo
.fAnyOperationsAborted
||
1142 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1143 "Expected aborted operations\n");
1144 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1147 /* copy one file and one directory to three others */
1148 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1149 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1150 shfo
.fAnyOperationsAborted
= FALSE
;
1151 retval
= SHFileOperation(&shfo
);
1152 if (dir_exists("b.txt"))
1154 /* Vista and W2K8 (broken or new behavior ?) */
1155 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1156 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1157 RemoveDirectory("b.txt");
1158 ok(RemoveDirectory("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1159 RemoveDirectory("c.txt");
1163 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1164 ok(shfo
.fAnyOperationsAborted
||
1165 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1166 "Expected aborted operations\n");
1167 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1168 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1171 /* copy a directory with a file beneath it, plus some files */
1172 createTestFile("test4.txt\\a.txt");
1173 shfo
.pFrom
= "test4.txt\0test1.txt\0";
1174 shfo
.pTo
= "testdir2\0";
1175 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1176 shfo
.fAnyOperationsAborted
= FALSE
;
1177 retval
= SHFileOperation(&shfo
);
1178 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1179 ok(DeleteFile("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1180 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1181 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1183 /* copy one directory and a file in that dir to another dir */
1184 shfo
.pFrom
= "test4.txt\0test4.txt\\a.txt\0";
1185 shfo
.pTo
= "testdir2\0";
1186 retval
= SHFileOperation(&shfo
);
1187 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1188 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1189 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1191 /* copy a file in a directory first, and then the directory to a nonexistent dir */
1192 shfo
.pFrom
= "test4.txt\\a.txt\0test4.txt\0";
1193 shfo
.pTo
= "nonexistent\0";
1194 retval
= SHFileOperation(&shfo
);
1195 if (dir_exists("nonexistent"))
1197 /* Vista and W2K8 (broken or new behavior ?) */
1198 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1199 ok(DeleteFile("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1200 RemoveDirectory("nonexistent\\test4.txt");
1201 ok(DeleteFile("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1202 RemoveDirectory("nonexistent");
1206 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1207 ok(shfo
.fAnyOperationsAborted
||
1208 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1209 "Expected aborted operations\n");
1210 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1212 DeleteFile("test4.txt\\a.txt");
1214 /* destination is same as source file */
1215 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1216 shfo
.pTo
= "b.txt\0test2.txt\0c.txt\0";
1217 shfo
.fAnyOperationsAborted
= FALSE
;
1218 shfo
.fFlags
= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
1219 retval
= SHFileOperation(&shfo
);
1220 if (retval
== DE_OPCANCELLED
)
1222 /* NT4 fails and doesn't copy any files */
1223 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1227 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1228 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1230 ok(!shfo
.fAnyOperationsAborted
, "Expected no operations to be aborted\n");
1231 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1233 /* destination is same as source directory */
1234 shfo
.pFrom
= "test1.txt\0test4.txt\0test3.txt\0";
1235 shfo
.pTo
= "b.txt\0test4.txt\0c.txt\0";
1236 shfo
.fAnyOperationsAborted
= FALSE
;
1237 retval
= SHFileOperation(&shfo
);
1238 if (retval
== DE_OPCANCELLED
)
1240 /* NT4 fails and doesn't copy any files */
1241 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1245 ok(retval
== ERROR_SUCCESS
||
1246 retval
== DE_DESTSAMETREE
, /* Vista */
1247 "Expected ERROR_SUCCESS or DE_DESTSAMETREE, got %d\n", retval
);
1248 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1250 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1252 /* copy a directory into itself, error displayed in UI */
1253 shfo
.pFrom
= "test4.txt\0";
1254 shfo
.pTo
= "test4.txt\\newdir\0";
1255 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1256 shfo
.fAnyOperationsAborted
= FALSE
;
1257 retval
= SHFileOperation(&shfo
);
1258 ok(retval
== ERROR_SUCCESS
||
1259 retval
== DE_DESTSUBTREE
, /* Vista */
1260 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1261 ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1263 /* copy a directory to itself, error displayed in UI */
1264 shfo
.pFrom
= "test4.txt\0";
1265 shfo
.pTo
= "test4.txt\0";
1266 shfo
.fAnyOperationsAborted
= FALSE
;
1267 retval
= SHFileOperation(&shfo
);
1268 ok(retval
== ERROR_SUCCESS
||
1269 retval
== DE_DESTSUBTREE
, /* Vista */
1270 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1272 /* copy a file into a directory, and the directory into itself */
1273 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1274 shfo
.pTo
= "test4.txt\0";
1275 shfo
.fAnyOperationsAborted
= FALSE
;
1276 shfo
.fFlags
|= FOF_NOCONFIRMATION
;
1277 retval
= SHFileOperation(&shfo
);
1278 ok(retval
== ERROR_SUCCESS
||
1279 retval
== DE_DESTSUBTREE
, /* Vista */
1280 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1281 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1283 /* copy a file to a file, and the directory into itself */
1284 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1285 shfo
.pTo
= "test4.txt\\a.txt\0";
1286 shfo
.fAnyOperationsAborted
= FALSE
;
1287 retval
= SHFileOperation(&shfo
);
1288 if (dir_exists("test4.txt\\a.txt"))
1290 /* Vista and W2K8 (broken or new behavior ?) */
1291 ok(retval
== DE_DESTSUBTREE
, "Expected DE_DESTSUBTREE, got %d\n", retval
);
1292 ok(DeleteFile("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1293 RemoveDirectory("test4.txt\\a.txt");
1297 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1298 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1301 /* copy a nonexistent file to a nonexistent directory */
1302 shfo
.pFrom
= "e.txt\0";
1303 shfo
.pTo
= "nonexistent\0";
1304 shfo
.fAnyOperationsAborted
= FALSE
;
1305 retval
= SHFileOperation(&shfo
);
1306 ok(retval
== 1026 ||
1307 retval
== ERROR_FILE_NOT_FOUND
|| /* Vista */
1308 broken(retval
== ERROR_SUCCESS
), /* NT4 */
1309 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval
);
1310 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1311 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1313 /* Overwrite tests */
1314 clean_after_shfo_tests();
1318 /* NT4 would throw up some dialog boxes and doesn't copy files that are needed
1319 * in subsequent tests.
1321 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1322 shfo
.pFrom
= "test1.txt\0";
1323 shfo
.pTo
= "test2.txt\0";
1324 shfo
.fAnyOperationsAborted
= FALSE
;
1325 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1326 retval
= SHFileOperation(&shfo
);
1327 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1328 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1330 shfo
.pFrom
= "test3.txt\0test1.txt\0";
1331 shfo
.pTo
= "test2.txt\0one.txt\0";
1332 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_MULTIDESTFILES
;
1333 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1334 retval
= SHFileOperation(&shfo
);
1335 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1336 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1338 shfo
.pFrom
= "one.txt\0";
1339 shfo
.pTo
= "testdir2\0";
1340 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1341 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1342 retval
= SHFileOperation(&shfo
);
1343 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1344 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1347 createTestFile("test4.txt\\test1.txt");
1348 shfo
.pFrom
= "test4.txt\0";
1349 shfo
.pTo
= "testdir2\0";
1350 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1351 ok(!SHFileOperation(&shfo
), "First SHFileOperation failed\n");
1352 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1353 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1354 retval
= SHFileOperation(&shfo
);
1355 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1356 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1358 createTestFile("one.txt");
1360 /* pFrom contains bogus 2nd name longer than MAX_PATH */
1361 memset(from
, 'a', MAX_PATH
*2);
1362 memset(from
+MAX_PATH
*2, 0, 2);
1363 lstrcpyA(from
, "one.txt");
1365 shfo
.pTo
= "two.txt\0";
1366 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1367 retval
= SHFileOperation(&shfo
);
1368 ok(retval
== 1148 || retval
== 1026 ||
1369 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1370 retval
== DE_INVALIDFILES
, /* Vista */
1371 "Unexpected return value, got %d\n", retval
);
1372 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1373 if (dir_exists("two.txt"))
1374 /* Vista and W2K8 (broken or new behavior ?) */
1375 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1377 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1379 createTestFile("one.txt");
1381 /* pTo contains bogus 2nd name longer than MAX_PATH */
1382 memset(to
, 'a', MAX_PATH
*2);
1383 memset(to
+MAX_PATH
*2, 0, 2);
1384 lstrcpyA(to
, "two.txt");
1385 shfo
.pFrom
= "one.txt\0";
1387 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1388 retval
= SHFileOperation(&shfo
);
1389 if (retval
== DE_OPCANCELLED
)
1391 /* NT4 fails and doesn't copy any files */
1392 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1396 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1397 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1399 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1401 createTestFile("one.txt");
1403 /* no FOF_MULTIDESTFILES, two files in pTo */
1404 shfo
.pFrom
= "one.txt\0";
1405 shfo
.pTo
= "two.txt\0three.txt\0";
1406 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1407 retval
= SHFileOperation(&shfo
);
1408 if (retval
== DE_OPCANCELLED
)
1410 /* NT4 fails and doesn't copy any files */
1411 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1415 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1416 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1418 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1420 createTestFile("one.txt");
1422 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1423 memset(from
, 'a', MAX_PATH
*2);
1424 memset(from
+MAX_PATH
*2, 0, 2);
1425 memset(to
, 'a', MAX_PATH
*2);
1426 memset(to
+MAX_PATH
*2, 0, 2);
1427 lstrcpyA(from
, "one.txt");
1428 lstrcpyA(to
, "two.txt");
1431 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1432 retval
= SHFileOperation(&shfo
);
1433 ok(retval
== 1148 || retval
== 1026 ||
1434 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1435 retval
== DE_INVALIDFILES
, /* Vista */
1436 "Unexpected return value, got %d\n", retval
);
1437 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1438 if (dir_exists("two.txt"))
1439 /* Vista and W2K8 (broken or new behavior ?) */
1440 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1442 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1444 createTestFile("one.txt");
1446 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1447 memset(to
, 'a', MAX_PATH
*2);
1448 memset(to
+MAX_PATH
*2, 0, 2);
1449 lstrcpyA(to
, "two.txt");
1450 shfo
.pFrom
= "one.txt\0";
1452 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1453 FOF_SILENT
| FOF_NOERRORUI
;
1454 retval
= SHFileOperation(&shfo
);
1455 if (retval
== DE_OPCANCELLED
)
1457 /* NT4 fails and doesn't copy any files */
1458 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1462 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1463 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1465 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1467 createTestFile("one.txt");
1468 createTestFile("two.txt");
1470 /* pTo contains bogus 2nd name longer than MAX_PATH,
1471 * multiple source files,
1472 * dest directory does not exist
1474 memset(to
, 'a', 2 * MAX_PATH
);
1475 memset(to
+MAX_PATH
*2, 0, 2);
1476 lstrcpyA(to
, "threedir");
1477 shfo
.pFrom
= "one.txt\0two.txt\0";
1479 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1480 retval
= SHFileOperation(&shfo
);
1481 if (dir_exists("threedir"))
1483 /* Vista and W2K8 (broken or new behavior ?) */
1484 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1485 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1486 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1487 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1491 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1492 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1493 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1494 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1495 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1497 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1498 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1500 createTestFile("one.txt");
1501 createTestFile("two.txt");
1502 CreateDirectoryA("threedir", NULL
);
1504 /* pTo contains bogus 2nd name longer than MAX_PATH,
1505 * multiple source files,
1506 * dest directory does exist
1508 memset(to
, 'a', 2 * MAX_PATH
);
1509 memset(to
+MAX_PATH
*2, 0, 2);
1510 lstrcpyA(to
, "threedir");
1511 shfo
.pFrom
= "one.txt\0two.txt\0";
1513 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1514 retval
= SHFileOperation(&shfo
);
1515 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1516 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1517 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1518 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1519 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1520 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1523 /* this crashes on win9x */
1524 createTestFile("one.txt");
1525 createTestFile("two.txt");
1527 /* pTo contains bogus 2nd name longer than MAX_PATH,
1528 * multiple source files, FOF_MULTIDESTFILES
1529 * dest dir does not exist
1532 memset(to
, 'a', 2 * MAX_PATH
);
1533 memset(to
+MAX_PATH
*2, 0, 2);
1534 lstrcpyA(to
, "threedir");
1535 shfo
.pFrom
= "one.txt\0two.txt\0";
1537 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1538 FOF_SILENT
| FOF_NOERRORUI
;
1539 retval
= SHFileOperation(&shfo
);
1540 ok(retval
== ERROR_CANCELLED
||
1541 retval
== ERROR_SUCCESS
, /* win2k3 */
1542 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval
);
1543 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1544 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1545 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1546 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1547 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1549 /* file exists in win2k */
1550 DeleteFileA("threedir");
1554 createTestFile("one.txt");
1555 createTestFile("two.txt");
1556 CreateDirectoryA("threedir", NULL
);
1558 /* pTo contains bogus 2nd name longer than MAX_PATH,
1559 * multiple source files, FOF_MULTIDESTFILES
1560 * dest dir does exist
1562 memset(to
, 'a', 2 * MAX_PATH
);
1563 memset(to
+MAX_PATH
*2, 0, 2);
1564 lstrcpyA(to
, "threedir");
1565 ptr
= to
+ lstrlenA(to
) + 1;
1566 lstrcpyA(ptr
, "fourdir");
1567 shfo
.pFrom
= "one.txt\0two.txt\0";
1569 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1570 FOF_SILENT
| FOF_NOERRORUI
;
1571 retval
= SHFileOperation(&shfo
);
1572 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1573 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1574 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1575 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1576 if (dir_exists("fourdir"))
1578 /* Vista and W2K8 (broken or new behavior ?) */
1579 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1580 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1581 RemoveDirectoryA("fourdir");
1585 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1586 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1587 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1589 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1591 createTestFile("one.txt");
1592 createTestFile("two.txt");
1593 CreateDirectoryA("threedir", NULL
);
1595 /* multiple source files, FOF_MULTIDESTFILES
1596 * multiple dest files, but first dest dir exists
1597 * num files in lists is equal
1599 shfo
.pFrom
= "one.txt\0two.txt\0";
1600 shfo
.pTo
= "threedir\0fourdir\0";
1601 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1602 FOF_SILENT
| FOF_NOERRORUI
;
1603 retval
= SHFileOperation(&shfo
);
1604 ok(retval
== ERROR_CANCELLED
||
1605 retval
== DE_FILEDESTISFLD
|| /* Vista */
1606 broken(retval
== DE_OPCANCELLED
), /* Win9x, NT4 */
1607 "Expected ERROR_CANCELLED or DE_FILEDESTISFLD. got %d\n", retval
);
1608 if (file_exists("threedir\\threedir"))
1611 ok(DeleteFileA("threedir\\threedir"), "Expected file to exist\n");
1613 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1614 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1615 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1616 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1617 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1618 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1619 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1621 createTestFile("one.txt");
1622 createTestFile("two.txt");
1623 CreateDirectoryA("threedir", NULL
);
1625 /* multiple source files, FOF_MULTIDESTFILES
1626 * multiple dest files, but first dest dir exists
1627 * num files in lists is not equal
1629 shfo
.pFrom
= "one.txt\0two.txt\0";
1630 shfo
.pTo
= "threedir\0fourdir\0five\0";
1631 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1632 FOF_SILENT
| FOF_NOERRORUI
;
1633 retval
= SHFileOperation(&shfo
);
1634 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1635 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1636 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1637 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1638 if (dir_exists("fourdir"))
1640 /* Vista and W2K8 (broken or new behavior ?) */
1641 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1642 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1643 RemoveDirectoryA("fourdir");
1647 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1648 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1649 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1651 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1652 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1653 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1655 createTestFile("aa.txt");
1656 createTestFile("ab.txt");
1657 CreateDirectoryA("one", NULL
);
1658 CreateDirectoryA("two", NULL
);
1660 /* pFrom has a glob, pTo has more than one dest */
1661 shfo
.pFrom
= "a*.txt\0";
1662 shfo
.pTo
= "one\0two\0";
1663 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1664 retval
= SHFileOperation(&shfo
);
1665 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1666 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1667 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1668 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1669 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1670 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1671 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1672 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1673 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1676 /* tests the FO_MOVE action */
1677 static void test_move(void)
1679 SHFILEOPSTRUCTA shfo
, shfo2
;
1680 CHAR from
[5*MAX_PATH
];
1681 CHAR to
[5*MAX_PATH
];
1685 shfo
.wFunc
= FO_MOVE
;
1688 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1689 shfo
.hNameMappings
= NULL
;
1690 shfo
.lpszProgressTitle
= NULL
;
1692 set_curr_dir_path(from
, "test1.txt\0");
1693 set_curr_dir_path(to
, "test4.txt\0");
1694 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are moved recursively\n");
1695 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1696 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1698 set_curr_dir_path(from
, "test?.txt\0");
1699 set_curr_dir_path(to
, "testdir2\0");
1700 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1701 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1702 ok(!SHFileOperationA(&shfo
), "Files and directories are moved to directory\n");
1703 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1704 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1705 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1707 clean_after_shfo_tests();
1710 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
1711 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
1713 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1714 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1715 ok(!SHFileOperationA(&shfo2
), "Move many files\n");
1716 ok(DeleteFileA("test6.txt"), "The file is not moved - many files are "
1717 "specified as a target\n");
1718 ok(DeleteFileA("test7.txt"), "The file is not moved\n");
1719 ok(RemoveDirectoryA("test8.txt"), "The directory is not moved\n");
1723 /* number of sources do not correspond to number of targets */
1724 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1725 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1726 retval
= SHFileOperationA(&shfo2
);
1727 if (dir_exists("test6.txt"))
1729 /* Vista and W2K8 (broken or new behavior ?) */
1730 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
1731 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1732 RemoveDirectoryA("test6.txt");
1733 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1734 RemoveDirectoryA("test7.txt");
1738 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1739 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1740 "specified as a target\n");
1745 set_curr_dir_path(from
, "test3.txt\0");
1746 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
1747 ok(!SHFileOperationA(&shfo
), "Can't move file to other directory\n");
1748 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1750 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1751 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1752 retval
= SHFileOperationA(&shfo
);
1753 if (dir_exists("test6.txt"))
1755 /* Vista and W2K8 (broken or new behavior ?) */
1756 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1757 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1758 ok(DeleteFileA("test6.txt\\test2.txt"), "The file is not moved. Many files are specified\n");
1759 ok(DeleteFileA("test6.txt\\test4.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1760 ok(RemoveDirectoryA("test6.txt\\test4.txt"), "The directory is not moved. Many files are specified\n");
1761 RemoveDirectoryA("test6.txt");
1766 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1767 ok(file_exists("test1.txt"), "The file is moved. Many files are specified\n");
1768 ok(dir_exists("test4.txt"), "The directory is moved. Many files are specified\n");
1771 set_curr_dir_path(from
, "test1.txt\0");
1772 set_curr_dir_path(to
, "test6.txt\0");
1773 ok(!SHFileOperationA(&shfo
), "Move file failed\n");
1774 ok(!file_exists("test1.txt"), "The file is not moved\n");
1775 ok(file_exists("test6.txt"), "The file is not moved\n");
1776 set_curr_dir_path(from
, "test6.txt\0");
1777 set_curr_dir_path(to
, "test1.txt\0");
1778 ok(!SHFileOperationA(&shfo
), "Move file back failed\n");
1780 set_curr_dir_path(from
, "test4.txt\0");
1781 set_curr_dir_path(to
, "test6.txt\0");
1782 ok(!SHFileOperationA(&shfo
), "Move dir failed\n");
1783 ok(!dir_exists("test4.txt"), "The dir is not moved\n");
1784 ok(dir_exists("test6.txt"), "The dir is moved\n");
1785 set_curr_dir_path(from
, "test6.txt\0");
1786 set_curr_dir_path(to
, "test4.txt\0");
1787 ok(!SHFileOperationA(&shfo
), "Move dir back failed\n");
1789 /* move one file to two others */
1791 shfo
.pFrom
= "test1.txt\0";
1792 shfo
.pTo
= "a.txt\0b.txt\0";
1793 retval
= SHFileOperationA(&shfo
);
1794 if (retval
== DE_OPCANCELLED
)
1796 /* NT4 fails and doesn't move any files */
1797 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1798 DeleteFileA("test1.txt");
1802 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1803 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1804 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1806 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1808 /* move two files to one other */
1809 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1810 shfo
.pTo
= "test1.txt\0";
1811 retval
= SHFileOperationA(&shfo
);
1812 if (dir_exists("test1.txt"))
1814 /* Vista and W2K8 (broken or new behavior ?) */
1815 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1816 ok(DeleteFileA("test1.txt\\test2.txt"), "Expected test1.txt\\test2.txt to exist\n");
1817 ok(DeleteFileA("test1.txt\\test3.txt"), "Expected test1.txt\\test3.txt to exist\n");
1818 RemoveDirectoryA("test1.txt");
1819 createTestFile("test2.txt");
1820 createTestFile("test3.txt");
1824 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1825 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1826 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1827 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1830 /* move a directory into itself */
1831 shfo
.pFrom
= "test4.txt\0";
1832 shfo
.pTo
= "test4.txt\\b.txt\0";
1833 retval
= SHFileOperationA(&shfo
);
1834 ok(retval
== ERROR_SUCCESS
||
1835 retval
== DE_DESTSUBTREE
, /* Vista */
1836 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1837 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1838 ok(dir_exists("test4.txt"), "Expected test4.txt to exist\n");
1840 /* move many files without FOF_MULTIDESTFILES */
1841 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1842 shfo
.pTo
= "d.txt\0e.txt\0";
1843 retval
= SHFileOperationA(&shfo
);
1844 if (dir_exists("d.txt"))
1846 /* Vista and W2K8 (broken or new behavior ?) */
1847 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1848 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1849 ok(DeleteFileA("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to exist\n");
1850 RemoveDirectoryA("d.txt");
1851 createTestFile("test2.txt");
1852 createTestFile("test3.txt");
1856 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1857 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1858 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1861 /* number of sources != number of targets */
1862 shfo
.pTo
= "d.txt\0";
1863 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1864 retval
= SHFileOperationA(&shfo
);
1865 if (dir_exists("d.txt"))
1867 /* Vista and W2K8 (broken or new behavior ?) */
1868 ok(retval
== DE_SAMEFILE
,
1869 "Expected DE_SAMEFILE, got %d\n", retval
);
1870 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1871 ok(!file_exists("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to not exist\n");
1872 RemoveDirectoryA("d.txt");
1873 createTestFile("test2.txt");
1877 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1878 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1881 /* FO_MOVE does not create dest directories */
1882 shfo
.pFrom
= "test2.txt\0";
1883 shfo
.pTo
= "dir1\\dir2\\test2.txt\0";
1884 retval
= SHFileOperationA(&shfo
);
1885 if (dir_exists("dir1"))
1887 /* Vista and W2K8 (broken or new behavior ?) */
1888 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1889 ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n");
1890 RemoveDirectoryA("dir1\\dir2");
1891 RemoveDirectoryA("dir1");
1892 createTestFile("test2.txt");
1896 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1899 /* try to overwrite an existing file */
1900 shfo
.pTo
= "test3.txt\0";
1901 retval
= SHFileOperationA(&shfo
);
1902 if (retval
== DE_OPCANCELLED
)
1904 /* NT4 fails and doesn't move any files */
1905 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1909 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1910 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1911 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1915 static void test_sh_create_dir(void)
1917 CHAR path
[MAX_PATH
];
1920 if(!pSHCreateDirectoryExA
)
1922 win_skip("skipping SHCreateDirectoryExA tests\n");
1926 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1927 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1928 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret
);
1929 ok(file_exists("testdir2"), "The first directory is not created\n");
1930 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
1932 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
1933 ok(ERROR_ALREADY_EXISTS
== ret
, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret
);
1935 ret
= pSHCreateDirectoryExA(NULL
, "c:\\testdir3", NULL
);
1936 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
1939 static void test_sh_path_prepare(void)
1942 CHAR path
[MAX_PATH
];
1944 if(!pSHPathPrepareForWriteA
)
1946 win_skip("skipping SHPathPrepareForWriteA tests\n");
1950 /* directory exists, SHPPFW_NONE */
1951 set_curr_dir_path(path
, "testdir2\0");
1952 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1953 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1955 /* directory exists, SHPPFW_IGNOREFILENAME */
1956 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1957 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
1958 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1960 /* directory exists, SHPPFW_DIRCREATE */
1961 set_curr_dir_path(path
, "testdir2\0");
1962 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1963 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1965 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1966 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
1967 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
1968 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1969 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1971 /* file exists, SHPPFW_NONE */
1972 set_curr_dir_path(path
, "test1.txt\0");
1973 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1974 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
1975 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
1976 "Unexpected result : 0x%08x\n", res
);
1978 /* file exists, SHPPFW_DIRCREATE */
1979 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
1980 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
1981 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
1982 "Unexpected result : 0x%08x\n", res
);
1984 /* file exists, SHPPFW_NONE, trailing \ */
1985 set_curr_dir_path(path
, "test1.txt\\\0");
1986 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
1987 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
1988 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
1989 "Unexpected result : 0x%08x\n", res
);
1991 /* relative path exists, SHPPFW_DIRCREATE */
1992 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE
);
1993 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
1995 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
1996 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE
);
1997 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
1998 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
2000 /* directory doesn't exist, SHPPFW_NONE */
2001 set_curr_dir_path(path
, "nonexistent\0");
2002 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2003 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2005 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
2006 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2007 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
2008 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2009 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
2010 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2012 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2013 set_curr_dir_path(path
, "testdir2\\test4.txt\\\0");
2014 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
2015 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2016 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
2018 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
2019 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2020 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2021 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2022 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
2024 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
2026 if(!pSHPathPrepareForWriteW
)
2028 skip("Skipping SHPathPrepareForWriteW tests\n");
2031 /* unicode directory doesn't exist, SHPPFW_NONE */
2032 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2033 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2034 ok(!file_existsW(UNICODE_PATH
), "unicode path was created but shouldn't be\n");
2035 RemoveDirectoryW(UNICODE_PATH
);
2037 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
2038 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2039 ok(res
== S_OK
, "res == %08x, expected S_OK\n", res
);
2040 ok(file_existsW(UNICODE_PATH
), "unicode path should've been created\n");
2042 /* unicode directory exists, SHPPFW_NONE */
2043 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2044 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2046 /* unicode directory exists, SHPPFW_DIRCREATE */
2047 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2048 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2049 RemoveDirectoryW(UNICODE_PATH
);
2052 static void test_unicode(void)
2054 SHFILEOPSTRUCTW shfoW
;
2058 if (!pSHFileOperationW
)
2060 skip("SHFileOperationW() is missing\n");
2065 shfoW
.wFunc
= FO_DELETE
;
2066 shfoW
.pFrom
= UNICODE_PATH
;
2068 shfoW
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
2069 shfoW
.hNameMappings
= NULL
;
2070 shfoW
.lpszProgressTitle
= NULL
;
2072 /* Clean up before start test */
2073 DeleteFileW(UNICODE_PATH
);
2074 RemoveDirectoryW(UNICODE_PATH
);
2076 /* Make sure we are on a system that supports unicode */
2077 SetLastError(0xdeadbeef);
2078 file
= CreateFileW(UNICODE_PATH
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
2079 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
2081 skip("Unicode tests skipped on non-unicode system\n");
2086 /* Try to delete a file with unicode filename */
2087 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2088 ret
= pSHFileOperationW(&shfoW
);
2089 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2090 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2092 /* Try to trash a file with unicode filename */
2093 createTestFileW(UNICODE_PATH
);
2094 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2095 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2096 ret
= pSHFileOperationW(&shfoW
);
2097 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2098 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2100 if(!pSHCreateDirectoryExW
)
2102 skip("Skipping SHCreateDirectoryExW tests\n");
2106 /* Try to delete a directory with unicode filename */
2107 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2108 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2109 ok(file_existsW(UNICODE_PATH
), "The directory is not created\n");
2110 shfoW
.fFlags
&= ~FOF_ALLOWUNDO
;
2111 ret
= pSHFileOperationW(&shfoW
);
2112 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2113 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2115 /* Try to trash a directory with unicode filename */
2116 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2117 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2118 ok(file_existsW(UNICODE_PATH
), "The directory was not created\n");
2119 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2120 ret
= pSHFileOperationW(&shfoW
);
2121 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2122 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2125 START_TEST(shlfileop
)
2127 InitFunctionPointers();
2129 clean_after_shfo_tests();
2132 test_get_file_info();
2133 test_get_file_info_iconlist();
2134 clean_after_shfo_tests();
2138 clean_after_shfo_tests();
2142 clean_after_shfo_tests();
2146 clean_after_shfo_tests();
2150 clean_after_shfo_tests();
2152 test_sh_create_dir();
2153 clean_after_shfo_tests();
2156 test_sh_path_prepare();
2157 clean_after_shfo_tests();