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 BOOL old_shell32
= FALSE
;
52 static CHAR CURR_DIR
[MAX_PATH
];
53 static const WCHAR UNICODE_PATH
[] = {'c',':','\\',0x00ae,'\0','\0'};
54 /* "c:\®" can be used in all codepages */
55 /* Double-null termination needed for pFrom field of SHFILEOPSTRUCT */
57 static HMODULE hshell32
;
58 static int (WINAPI
*pSHCreateDirectoryExA
)(HWND
, LPCSTR
, LPSECURITY_ATTRIBUTES
);
59 static int (WINAPI
*pSHCreateDirectoryExW
)(HWND
, LPCWSTR
, LPSECURITY_ATTRIBUTES
);
60 static int (WINAPI
*pSHFileOperationW
)(LPSHFILEOPSTRUCTW
);
61 static DWORD_PTR (WINAPI
*pSHGetFileInfoW
)(LPCWSTR
, DWORD
, SHFILEINFOW
*, UINT
, UINT
);
62 static int (WINAPI
*pSHPathPrepareForWriteA
)(HWND
, IUnknown
*, LPCSTR
, DWORD
);
63 static int (WINAPI
*pSHPathPrepareForWriteW
)(HWND
, IUnknown
*, LPCWSTR
, DWORD
);
65 static void InitFunctionPointers(void)
67 hshell32
= GetModuleHandleA("shell32.dll");
68 pSHCreateDirectoryExA
= (void*)GetProcAddress(hshell32
, "SHCreateDirectoryExA");
69 pSHCreateDirectoryExW
= (void*)GetProcAddress(hshell32
, "SHCreateDirectoryExW");
70 pSHFileOperationW
= (void*)GetProcAddress(hshell32
, "SHFileOperationW");
71 pSHGetFileInfoW
= (void*)GetProcAddress(hshell32
, "SHGetFileInfoW");
72 pSHPathPrepareForWriteA
= (void*)GetProcAddress(hshell32
, "SHPathPrepareForWriteA");
73 pSHPathPrepareForWriteW
= (void*)GetProcAddress(hshell32
, "SHPathPrepareForWriteW");
76 /* creates a file with the specified name for tests */
77 static void createTestFile(const CHAR
*name
)
82 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
83 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
84 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
85 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
89 static void createTestFileW(const WCHAR
*name
)
93 file
= CreateFileW(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
94 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file\n");
98 static BOOL
file_exists(const CHAR
*name
)
100 return GetFileAttributesA(name
) != INVALID_FILE_ATTRIBUTES
;
103 static BOOL
dir_exists(const CHAR
*name
)
108 attr
= GetFileAttributesA(name
);
109 dir
= ((attr
& FILE_ATTRIBUTE_DIRECTORY
) == FILE_ATTRIBUTE_DIRECTORY
);
111 return ((attr
!= INVALID_FILE_ATTRIBUTES
) && dir
);
114 static BOOL
file_existsW(LPCWSTR name
)
116 return GetFileAttributesW(name
) != INVALID_FILE_ATTRIBUTES
;
119 static BOOL
file_has_content(const CHAR
*name
, const CHAR
*content
)
125 file
= CreateFileA(name
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, NULL
);
126 if (file
== INVALID_HANDLE_VALUE
)
128 ReadFile(file
, buf
, MAX_PATH
- 1, &read
, NULL
);
131 return strcmp(buf
, content
)==0;
134 /* initializes the tests */
135 static void init_shfo_tests(void)
139 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
140 len
= lstrlenA(CURR_DIR
);
142 if(len
&& (CURR_DIR
[len
-1] == '\\'))
145 createTestFile("test1.txt");
146 createTestFile("test2.txt");
147 createTestFile("test3.txt");
148 createTestFile("test_5.txt");
149 CreateDirectoryA("test4.txt", NULL
);
150 CreateDirectoryA("testdir2", NULL
);
151 CreateDirectoryA("testdir2\\nested", NULL
);
152 createTestFile("testdir2\\one.txt");
153 createTestFile("testdir2\\nested\\two.txt");
156 /* cleans after tests */
157 static void clean_after_shfo_tests(void)
159 DeleteFileA("test1.txt");
160 DeleteFileA("test2.txt");
161 DeleteFileA("test3.txt");
162 DeleteFileA("test_5.txt");
163 DeleteFileA("one.txt");
164 DeleteFileA("test4.txt\\test1.txt");
165 DeleteFileA("test4.txt\\test2.txt");
166 DeleteFileA("test4.txt\\test3.txt");
167 RemoveDirectoryA("test4.txt");
168 DeleteFileA("testdir2\\one.txt");
169 DeleteFileA("testdir2\\test1.txt");
170 DeleteFileA("testdir2\\test2.txt");
171 DeleteFileA("testdir2\\test3.txt");
172 DeleteFileA("testdir2\\test4.txt\\test1.txt");
173 DeleteFileA("testdir2\\nested\\two.txt");
174 RemoveDirectoryA("testdir2\\test4.txt");
175 RemoveDirectoryA("testdir2\\nested");
176 RemoveDirectoryA("testdir2");
177 RemoveDirectoryA("c:\\testdir3");
178 DeleteFileA("nonexistent\\notreal\\test2.txt");
179 RemoveDirectoryA("nonexistent\\notreal");
180 RemoveDirectoryA("nonexistent");
184 static void test_get_file_info(void)
187 SHFILEINFOA shfi
, shfi2
;
189 char notepad
[MAX_PATH
];
191 /* Test whether fields of SHFILEINFOA are always cleared */
192 memset(&shfi
, 0xcf, sizeof(shfi
));
193 rc
=SHGetFileInfoA("", 0, &shfi
, sizeof(shfi
), 0);
194 ok(rc
== 1, "SHGetFileInfoA('' | 0) should return 1, got 0x%x\n", rc
);
195 todo_wine
ok(shfi
.hIcon
== 0, "SHGetFileInfoA('' | 0) did not clear hIcon\n");
196 todo_wine
ok(shfi
.szDisplayName
[0] == 0, "SHGetFileInfoA('' | 0) did not clear szDisplayName[0]\n");
197 todo_wine
ok(shfi
.szTypeName
[0] == 0, "SHGetFileInfoA('' | 0) did not clear szTypeName[0]\n");
198 ok(shfi
.iIcon
== 0xcfcfcfcf ||
199 broken(shfi
.iIcon
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
200 "SHGetFileInfoA('' | 0) should not clear iIcon\n");
201 ok(shfi
.dwAttributes
== 0xcfcfcfcf ||
202 broken(shfi
.dwAttributes
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
203 "SHGetFileInfoA('' | 0) should not clear dwAttributes\n");
208 /* Test whether fields of SHFILEINFOW are always cleared */
209 memset(&shfiw
, 0xcf, sizeof(shfiw
));
210 memset(&unset_icon
, 0xcf, sizeof(unset_icon
));
211 rc
=pSHGetFileInfoW(NULL
, 0, &shfiw
, sizeof(shfiw
), 0);
212 ok(!rc
, "SHGetFileInfoW(NULL | 0) should fail\n");
213 ok(shfiw
.hIcon
== unset_icon
, "SHGetFileInfoW(NULL | 0) should not clear hIcon\n");
214 ok(shfiw
.szDisplayName
[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szDisplayName[0]\n");
215 ok(shfiw
.szTypeName
[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szTypeName[0]\n");
216 ok(shfiw
.iIcon
== 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear iIcon\n");
217 ok(shfiw
.dwAttributes
== 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear dwAttributes\n");
220 win_skip("SHGetFileInfoW is not available\n");
223 /* Test some flag combinations that MSDN claims are not allowed,
224 * but which work anyway
226 memset(&shfi
, 0xcf, sizeof(shfi
));
227 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
229 SHGFI_ATTRIBUTES
| SHGFI_USEFILEATTRIBUTES
);
230 ok(rc
== 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should return 1, got 0x%x\n", rc
);
232 ok(shfi
.dwAttributes
!= 0xcfcfcfcf, "dwFileAttributes is not set\n");
233 todo_wine
ok(shfi
.hIcon
== 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear hIcon\n");
234 todo_wine
ok(shfi
.szDisplayName
[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szDisplayName[0]\n");
235 todo_wine
ok(shfi
.szTypeName
[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szTypeName[0]\n");
236 ok(shfi
.iIcon
== 0xcfcfcfcf ||
237 broken(shfi
.iIcon
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
238 "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should not clear iIcon\n");
240 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
242 SHGFI_EXETYPE
| SHGFI_USEFILEATTRIBUTES
);
243 todo_wine
ok(rc
== 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) should return 1, got 0x%x\n", rc
);
245 /* Test SHGFI_USEFILEATTRIBUTES support */
246 strcpy(shfi
.szDisplayName
, "dummy");
247 shfi
.iIcon
=0xdeadbeef;
248 rc
=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY
,
250 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
251 ok(rc
== 1, "SHGetFileInfoA(c:\\nonexistent) should return 1, got 0x%x\n", rc
);
254 ok(strcpy(shfi
.szDisplayName
, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
255 ok(shfi
.iIcon
!= 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
258 /* Wine does not have a default icon for text files, and Windows 98 fails
259 * if we give it an empty executable. So use notepad.exe as the test
261 if (SearchPathA(NULL
, "notepad.exe", NULL
, sizeof(notepad
), notepad
, NULL
))
263 strcpy(shfi
.szDisplayName
, "dummy");
264 shfi
.iIcon
=0xdeadbeef;
265 rc
=SHGetFileInfoA(notepad
, GetFileAttributesA(notepad
),
267 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
268 ok(rc
== 1, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) should return 1, got 0x%x\n", notepad
, rc
);
269 strcpy(shfi2
.szDisplayName
, "dummy");
270 shfi2
.iIcon
=0xdeadbeef;
271 rc2
=SHGetFileInfoA(notepad
, 0,
272 &shfi2
, sizeof(shfi2
),
274 ok(rc2
== 1, "SHGetFileInfoA(%s) failed %x\n", notepad
, rc2
);
277 ok(lstrcmpiA(shfi2
.szDisplayName
, shfi
.szDisplayName
) == 0, "wrong display name %s != %s\n", shfi
.szDisplayName
, shfi2
.szDisplayName
);
278 ok(shfi2
.iIcon
== shfi
.iIcon
, "wrong icon index %d != %d\n", shfi
.iIcon
, shfi2
.iIcon
);
282 /* with a directory now */
283 strcpy(shfi
.szDisplayName
, "dummy");
284 shfi
.iIcon
=0xdeadbeef;
285 rc
=SHGetFileInfoA("test4.txt", GetFileAttributesA("test4.txt"),
287 SHGFI_ICONLOCATION
| SHGFI_USEFILEATTRIBUTES
);
288 ok(rc
== 1, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) should return 1, got 0x%x\n", rc
);
289 strcpy(shfi2
.szDisplayName
, "dummy");
290 shfi2
.iIcon
=0xdeadbeef;
291 rc2
=SHGetFileInfoA("test4.txt", 0,
292 &shfi2
, sizeof(shfi2
),
294 ok(rc2
== 1, "SHGetFileInfoA(test4.txt/) should return 1, got 0x%x\n", rc2
);
297 ok(lstrcmpiA(shfi2
.szDisplayName
, shfi
.szDisplayName
) == 0, "wrong display name %s != %s\n", shfi
.szDisplayName
, shfi2
.szDisplayName
);
298 ok(shfi2
.iIcon
== shfi
.iIcon
, "wrong icon index %d != %d\n", shfi
.iIcon
, shfi2
.iIcon
);
300 /* with drive root directory */
301 strcpy(shfi
.szDisplayName
, "dummy");
302 strcpy(shfi
.szTypeName
, "dummy");
303 shfi
.hIcon
=(HICON
) 0xdeadbeef;
304 shfi
.iIcon
=0xdeadbeef;
305 shfi
.dwAttributes
=0xdeadbeef;
306 rc
=SHGetFileInfoA("c:\\", 0, &shfi
, sizeof(shfi
),
307 SHGFI_TYPENAME
| SHGFI_DISPLAYNAME
| SHGFI_ICON
| SHGFI_SMALLICON
);
308 ok(rc
== 1, "SHGetFileInfoA(c:\\) should return 1, got 0x%x\n", rc
);
309 ok(strcmp(shfi
.szDisplayName
, "dummy") != 0, "display name was expected to change\n");
310 ok(strcmp(shfi
.szTypeName
, "dummy") != 0, "type name was expected to change\n");
311 ok(shfi
.hIcon
!= (HICON
) 0xdeadbeef, "hIcon was expected to change\n");
312 ok(shfi
.iIcon
!= 0xdeadbeef, "iIcon was expected to change\n");
315 static void test_get_file_info_iconlist(void)
317 /* Test retrieving a handle to the system image list, and
318 * what that returns for hIcon
321 HIMAGELIST hSysImageList
;
322 LPITEMIDLIST pidList
;
326 hr
= SHGetSpecialFolderLocation(NULL
, CSIDL_DESKTOP
, &pidList
);
328 skip("can't get desktop pidl\n");
332 memset(&shInfoa
, 0xcf, sizeof(shInfoa
));
333 hSysImageList
= (HIMAGELIST
) SHGetFileInfoA((const char *)pidList
, 0,
334 &shInfoa
, sizeof(shInfoa
),
335 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_PIDL
);
336 ok((hSysImageList
!= INVALID_HANDLE_VALUE
) && (hSysImageList
> (HIMAGELIST
) 0xffff), "Can't get handle for CSIDL_DESKTOP imagelist\n");
337 todo_wine
ok(shInfoa
.hIcon
== 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
338 todo_wine
ok(shInfoa
.szTypeName
[0] == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
339 ok(shInfoa
.iIcon
!= 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
340 ok(shInfoa
.dwAttributes
== 0xcfcfcfcf ||
341 shInfoa
.dwAttributes
== 0 || /* Vista */
342 broken(shInfoa
.dwAttributes
!= 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
343 "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL), unexpected dwAttributes\n");
344 CloseHandle(hSysImageList
);
346 if (!pSHGetFileInfoW
)
348 win_skip("SHGetFileInfoW is not available\n");
353 memset(&shInfow
, 0xcf, sizeof(shInfow
));
354 hSysImageList
= (HIMAGELIST
) pSHGetFileInfoW((const WCHAR
*)pidList
, 0,
355 &shInfow
, sizeof(shInfow
),
356 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_PIDL
);
359 win_skip("SHGetFileInfoW is not implemented\n");
362 ok((hSysImageList
!= INVALID_HANDLE_VALUE
) && (hSysImageList
> (HIMAGELIST
) 0xffff), "Can't get handle for CSIDL_DESKTOP imagelist\n");
363 todo_wine
ok(shInfow
.hIcon
== 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
364 ok(shInfow
.szTypeName
[0] == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
365 ok(shInfow
.iIcon
!= 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
366 ok(shInfow
.dwAttributes
== 0xcfcfcfcf ||
367 shInfoa
.dwAttributes
== 0, /* Vista */
368 "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) unexpected dwAttributes\n");
369 CloseHandle(hSysImageList
);
371 /* Various suposidly invalid flag testing */
372 memset(&shInfow
, 0xcf, sizeof(shInfow
));
373 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
374 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
375 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
376 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
377 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
378 shInfoa
.dwAttributes
==0, /* Vista */
379 "unexpected dwAttributes\n");
381 memset(&shInfow
, 0xcf, sizeof(shInfow
));
382 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
383 SHGFI_ICON
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
384 ok(hr
!= 0, " SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
385 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
386 ok(shInfow
.hIcon
!=(HICON
)0xcfcfcfcf && shInfow
.hIcon
!=0,"hIcon invalid\n");
387 if (shInfow
.hIcon
!=(HICON
)0xcfcfcfcf) DestroyIcon(shInfow
.hIcon
);
388 todo_wine
ok(shInfow
.dwAttributes
==0,"dwAttributes not set\n");
390 memset(&shInfow
, 0xcf, sizeof(shInfow
));
391 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
392 SHGFI_ICON
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_LARGEICON
);
393 ok(hr
!= 0, "SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
394 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
395 ok(shInfow
.hIcon
!=(HICON
)0xcfcfcfcf && shInfow
.hIcon
!=0,"hIcon invalid\n");
396 if (shInfow
.hIcon
!= (HICON
)0xcfcfcfcf) DestroyIcon(shInfow
.hIcon
);
397 todo_wine
ok(shInfow
.dwAttributes
==0,"dwAttributes not set\n");
399 memset(&shInfow
, 0xcf, sizeof(shInfow
));
400 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
401 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_LARGEICON
);
402 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
403 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
404 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
405 shInfoa
.dwAttributes
==0, /* Vista */
406 "unexpected dwAttributes\n");
408 memset(&shInfow
, 0xcf, sizeof(shInfow
));
409 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
410 SHGFI_OPENICON
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
411 ok(hr
!= 0, "SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
412 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
413 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
415 memset(&shInfow
, 0xcf, sizeof(shInfow
));
416 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
417 SHGFI_SHELLICONSIZE
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
418 ok(hr
!= 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
419 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
420 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
422 memset(&shInfow
, 0xcf, sizeof(shInfow
));
423 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
424 SHGFI_SHELLICONSIZE
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
);
425 ok(hr
!= 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
426 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
427 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
429 memset(&shInfow
, 0xcf, sizeof(shInfow
));
430 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
431 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|
433 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
434 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
435 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
437 memset(&shInfow
, 0xcf, sizeof(shInfow
));
438 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
439 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|
441 todo_wine
ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
442 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
443 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
444 shInfoa
.dwAttributes
==0, /* Vista */
445 "unexpected dwAttributes\n");
447 memset(&shInfow
, 0xcf, sizeof(shInfow
));
448 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
449 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|SHGFI_EXETYPE
);
450 todo_wine
ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
451 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
452 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
454 memset(&shInfow
, 0xcf, sizeof(shInfow
));
455 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
456 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_SMALLICON
|SHGFI_ATTRIBUTES
);
457 ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
458 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
459 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
461 memset(&shInfow
, 0xcf, sizeof(shInfow
));
462 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
463 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|
465 ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
466 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
467 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
469 memset(&shInfow
, 0xcf, sizeof(shInfow
));
470 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
471 SHGFI_SYSICONINDEX
|SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_EXETYPE
);
472 todo_wine
ok(hr
!= 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
473 ok(shInfow
.iIcon
!=0xcfcfcfcf, "Icon Index Missing\n");
474 ok(shInfow
.dwAttributes
==0xcfcfcfcf ||
475 shInfoa
.dwAttributes
==0, /* Vista */
476 "unexpected dwAttributes\n");
478 memset(&shInfow
, 0xcf, sizeof(shInfow
));
479 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
480 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_EXETYPE
);
481 todo_wine
ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
482 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
483 ok(shInfow
.dwAttributes
==0xcfcfcfcf,"dwAttributes modified\n");
485 memset(&shInfow
, 0xcf, sizeof(shInfow
));
486 hr
= pSHGetFileInfoW((const WCHAR
*)pidList
, 0, &shInfow
, sizeof(shInfow
),
487 SHGFI_USEFILEATTRIBUTES
|SHGFI_PIDL
|SHGFI_ATTRIBUTES
);
488 ok(hr
!= 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
489 todo_wine
ok(shInfow
.iIcon
==0xcfcfcfcf, "Icon Index Modified\n");
490 ok(shInfow
.dwAttributes
!=0xcfcfcfcf,"dwAttributes not set\n");
497 puts into the specified buffer file names with current directory.
498 files - string with file names, separated by null characters. Ends on a double
501 static void set_curr_dir_path(CHAR
*buf
, const CHAR
* files
)
506 strcpy(buf
, CURR_DIR
);
511 buf
+= strlen(buf
) + 1;
512 files
+= strlen(files
) + 1;
518 /* tests the FO_DELETE action */
519 static void test_delete(void)
521 SHFILEOPSTRUCTA shfo
;
523 CHAR buf
[sizeof(CURR_DIR
)+sizeof("/test?.txt")+1];
525 sprintf(buf
, "%s\\%s", CURR_DIR
, "test?.txt");
526 buf
[strlen(buf
) + 1] = '\0';
529 shfo
.wFunc
= FO_DELETE
;
532 shfo
.fFlags
= FOF_FILESONLY
| FOF_NOCONFIRMATION
| FOF_SILENT
;
533 shfo
.hNameMappings
= NULL
;
534 shfo
.lpszProgressTitle
= NULL
;
536 ok(!SHFileOperationA(&shfo
), "Deletion was not successful\n");
537 ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
538 ok(!file_exists("test1.txt"), "File should have been removed\n");
539 ok(!file_exists("test2.txt"), "File should have been removed\n");
540 ok(!file_exists("test3.txt"), "File should have been removed\n");
542 ret
= SHFileOperationA(&shfo
);
543 ok(ret
== ERROR_SUCCESS
, "Directory exists, but is not removed, ret=%d\n", ret
);
544 ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
546 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
548 ok(!SHFileOperationA(&shfo
), "Directory is not removed\n");
549 ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
551 ret
= SHFileOperationA(&shfo
);
552 ok(!ret
, "The requested file does not exist, ret=%d\n", ret
);
555 sprintf(buf
, "%s\\%s", CURR_DIR
, "test4.txt");
556 buf
[strlen(buf
) + 1] = '\0';
557 ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
558 ok(!SHFileOperationA(&shfo
), "Directory is not removed\n");
559 ok(!dir_exists("test4.txt"), "Directory is not removed\n");
562 shfo
.pFrom
= "test1.txt\0test4.txt\0";
563 ok(!SHFileOperationA(&shfo
), "Directory and a file are not removed\n");
564 ok(!file_exists("test1.txt"), "The file should have been removed\n");
565 ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
566 ok(file_exists("test2.txt"), "This file should not have been removed\n");
568 /* FOF_FILESONLY does not delete a dir matching a wildcard */
570 shfo
.fFlags
|= FOF_FILESONLY
;
571 shfo
.pFrom
= "*.txt\0";
572 ok(!SHFileOperationA(&shfo
), "Failed to delete files\n");
573 ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
574 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
575 ok(dir_exists("test4.txt"), "test4.txt should not have been removed\n");
577 /* FOF_FILESONLY only deletes a dir if explicitly specified */
579 shfo
.pFrom
= "test_?.txt\0test4.txt\0";
580 ok(!SHFileOperationA(&shfo
), "Failed to delete files and directory\n");
581 ok(!dir_exists("test4.txt") ||
582 broken(dir_exists("test4.txt")), /* NT4 */
583 "test4.txt should have been removed\n");
584 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
585 ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
587 /* try to delete an invalid filename */
589 /* this crashes on win9x */
592 shfo
.fFlags
&= ~FOF_FILESONLY
;
593 shfo
.fAnyOperationsAborted
= FALSE
;
594 ret
= SHFileOperationA(&shfo
);
595 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
596 ok(!shfo
.fAnyOperationsAborted
, "Expected no aborted operations\n");
597 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
600 /* try an invalid function */
602 shfo
.pFrom
= "test1.txt\0";
604 ret
= SHFileOperationA(&shfo
);
605 ok(ret
== ERROR_INVALID_PARAMETER
||
606 broken(ret
== ERROR_SUCCESS
), /* Win9x, NT4 */
607 "Expected ERROR_INVALID_PARAMETER, got %d\n", ret
);
608 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
610 /* try an invalid list, only one null terminator */
612 /* this crashes on win9x */
615 shfo
.wFunc
= FO_DELETE
;
616 ret
= SHFileOperationA(&shfo
);
617 ok(ret
== ERROR_ACCESS_DENIED
, "Expected ERROR_ACCESS_DENIED, got %d\n", ret
);
618 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
621 /* delete a nonexistent file */
622 shfo
.pFrom
= "nonexistent.txt\0";
623 shfo
.wFunc
= FO_DELETE
;
624 ret
= SHFileOperationA(&shfo
);
627 ret
== ERROR_FILE_NOT_FOUND
|| /* Vista */
628 broken(ret
== ERROR_SUCCESS
), /* NT4 */
629 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
631 /* delete a dir, and then a file inside the dir, same as
632 * deleting a nonexistent file
634 if (ret
!= ERROR_FILE_NOT_FOUND
)
636 /* Vista would throw up a dialog box that we can't suppress */
638 shfo
.pFrom
= "testdir2\0testdir2\\one.txt\0";
639 ret
= SHFileOperationA(&shfo
);
640 ok(ret
== ERROR_PATH_NOT_FOUND
||
641 broken(ret
== ERROR_SUCCESS
), /* NT4 */
642 "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret
);
643 ok(!dir_exists("testdir2"), "Expected testdir2 to not exist\n");
644 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
647 skip("Test would show a dialog box\n");
649 /* delete an existent file and a nonexistent file */
651 shfo
.pFrom
= "test1.txt\0nonexistent.txt\0test2.txt\0";
652 shfo
.wFunc
= FO_DELETE
;
653 ret
= SHFileOperationA(&shfo
);
656 ret
== ERROR_FILE_NOT_FOUND
|| /* Vista */
657 broken(ret
== ERROR_SUCCESS
), /* NT4 */
658 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", ret
);
660 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
661 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
663 /* delete a nonexistent file in an existent dir or a nonexistent dir */
665 shfo
.pFrom
= "testdir2\\nonexistent.txt\0";
666 ret
= SHFileOperationA(&shfo
);
668 ok(ret
== ERROR_FILE_NOT_FOUND
|| /* Vista */
669 broken(ret
== 0x402) || /* XP */
670 broken(ret
== ERROR_SUCCESS
), /* NT4 */
671 "Expected 0x402 or ERROR_FILE_NOT_FOUND, got %x\n", ret
);
672 shfo
.pFrom
= "nonexistent\\one.txt\0";
673 ret
= SHFileOperationA(&shfo
);
675 ok(ret
== DE_INVALIDFILES
|| /* Vista or later */
676 broken(ret
== 0x402), /* XP */
677 "Expected 0x402 or DE_INVALIDFILES, got %x\n", ret
);
679 /* try the FOF_NORECURSION flag, continues deleting subdirs */
681 shfo
.pFrom
= "testdir2\0";
682 shfo
.fFlags
|= FOF_NORECURSION
;
683 ret
= SHFileOperationA(&shfo
);
684 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
685 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
686 ok(!dir_exists("testdir2\\nested"), "Expected testdir2\\nested to not exist\n");
689 /* tests the FO_RENAME action */
690 static void test_rename(void)
692 SHFILEOPSTRUCTA shfo
, shfo2
;
693 CHAR from
[5*MAX_PATH
];
698 shfo
.wFunc
= FO_RENAME
;
701 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
702 shfo
.hNameMappings
= NULL
;
703 shfo
.lpszProgressTitle
= NULL
;
705 set_curr_dir_path(from
, "test1.txt\0");
706 set_curr_dir_path(to
, "test4.txt\0");
707 retval
= SHFileOperationA(&shfo
);
708 ok(retval
== ERROR_ALREADY_EXISTS
||
709 retval
== DE_FILEDESTISFLD
|| /* Vista */
710 broken(retval
== ERROR_INVALID_NAME
), /* Win9x, NT4 */
711 "Expected ERROR_ALREADY_EXISTS or DE_FILEDESTISFLD, got %d\n", retval
);
712 ok(file_exists("test1.txt"), "The file is renamed\n");
714 set_curr_dir_path(from
, "test3.txt\0");
715 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
716 retval
= SHFileOperationA(&shfo
);
717 if (retval
== DE_DIFFDIR
)
719 /* Vista and W2K8 (broken or new behavior ?) */
720 ok(!file_exists("test4.txt\\test1.txt"), "The file is renamed\n");
724 ok(retval
== ERROR_SUCCESS
, "File is renamed moving to other directory\n");
725 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
728 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
729 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.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"), "The file is renamed - many files are specified\n");
737 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
738 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
740 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
741 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
742 retval
= SHFileOperationA(&shfo2
);
743 ok(retval
== ERROR_GEN_FAILURE
||
744 retval
== DE_MANYSRC1DEST
|| /* Vista */
745 broken(retval
== ERROR_SUCCESS
), /* Win9x */
746 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST files, got %d\n", retval
);
747 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
749 set_curr_dir_path(from
, "test1.txt\0");
750 set_curr_dir_path(to
, "test6.txt\0");
751 retval
= SHFileOperationA(&shfo
);
752 ok(retval
== ERROR_SUCCESS
, "Rename file failed, retval = %d\n", retval
);
753 ok(!file_exists("test1.txt"), "The file is not renamed\n");
754 ok(file_exists("test6.txt"), "The file is not renamed\n");
756 set_curr_dir_path(from
, "test6.txt\0");
757 set_curr_dir_path(to
, "test1.txt\0");
758 retval
= SHFileOperationA(&shfo
);
759 ok(retval
== ERROR_SUCCESS
, "Rename file back failed, retval = %d\n", retval
);
761 set_curr_dir_path(from
, "test4.txt\0");
762 set_curr_dir_path(to
, "test6.txt\0");
763 retval
= SHFileOperationA(&shfo
);
764 ok(retval
== ERROR_SUCCESS
, "Rename dir failed, retval = %d\n", retval
);
765 ok(!dir_exists("test4.txt"), "The dir is not renamed\n");
766 ok(dir_exists("test6.txt"), "The dir is not renamed\n");
768 set_curr_dir_path(from
, "test6.txt\0");
769 set_curr_dir_path(to
, "test4.txt\0");
770 retval
= SHFileOperationA(&shfo
);
771 ok(retval
== ERROR_SUCCESS
, "Rename dir back failed, retval = %d\n", retval
);
772 ok(dir_exists("test4.txt"), "The dir is not renamed\n");
774 /* try to rename more than one file to a single file */
775 shfo
.pFrom
= "test1.txt\0test2.txt\0";
776 shfo
.pTo
= "a.txt\0";
777 retval
= SHFileOperationA(&shfo
);
778 ok(retval
== ERROR_GEN_FAILURE
||
779 retval
== DE_MANYSRC1DEST
|| /* Vista */
780 broken(retval
== ERROR_SUCCESS
), /* Win9x */
781 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST, got %d\n", retval
);
782 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
783 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
784 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
786 /* pFrom doesn't exist */
787 shfo
.pFrom
= "idontexist\0";
788 shfo
.pTo
= "newfile\0";
789 retval
= SHFileOperationA(&shfo
);
791 retval
== ERROR_FILE_NOT_FOUND
|| /* Vista */
792 broken(retval
== ERROR_SUCCESS
), /* NT4 */
793 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval
);
794 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
796 /* pTo already exist */
797 shfo
.pFrom
= "test1.txt\0";
798 shfo
.pTo
= "test2.txt\0";
800 shfo
.fFlags
|= FOF_NOCONFIRMMKDIR
;
801 retval
= SHFileOperationA(&shfo
);
802 if (retval
== ERROR_SUCCESS
)
804 /* Vista and W2K8 (broken or new behavior ?) */
805 createTestFile("test1.txt");
809 ok(retval
== ERROR_ALREADY_EXISTS
||
810 broken(retval
== DE_OPCANCELLED
) || /* NT4 */
811 broken(retval
== ERROR_INVALID_NAME
), /* Win9x */
812 "Expected ERROR_ALREADY_EXISTS, got %d\n", retval
);
815 /* pFrom is valid, but pTo is empty */
816 shfo
.pFrom
= "test1.txt\0";
818 retval
= SHFileOperationA(&shfo
);
819 ok(retval
== ERROR_CANCELLED
||
820 retval
== DE_DIFFDIR
|| /* Vista */
821 broken(retval
== DE_OPCANCELLED
) || /* Win9x */
822 broken(retval
== 65652), /* NT4 */
823 "Expected ERROR_CANCELLED or DE_DIFFDIR\n");
824 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
828 retval
= SHFileOperationA(&shfo
);
829 ok(retval
== ERROR_ACCESS_DENIED
||
830 retval
== DE_MANYSRC1DEST
|| /* Vista */
831 broken(retval
== ERROR_SUCCESS
), /* Win9x */
832 "Expected ERROR_ACCESS_DENIED or DE_MANYSRC1DEST, got %d\n", retval
);
834 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
838 retval
= SHFileOperationA(&shfo
);
839 ok(retval
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval
);
843 /* tests the FO_COPY action */
844 static void test_copy(void)
846 SHFILEOPSTRUCTA shfo
, shfo2
;
847 CHAR from
[5*MAX_PATH
];
849 FILEOP_FLAGS tmp_flags
;
857 win_skip("Too many differences for old shell32\n");
862 shfo
.wFunc
= FO_COPY
;
865 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
866 shfo
.hNameMappings
= NULL
;
867 shfo
.lpszProgressTitle
= NULL
;
869 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
870 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
871 retval
= SHFileOperationA(&shfo
);
872 if (dir_exists("test6.txt"))
874 /* Vista and W2K8 (broken or new behavior ?) */
875 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
876 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
877 "are specified as a target\n");
878 DeleteFileA("test6.txt\\test2.txt");
879 RemoveDirectoryA("test6.txt\\test4.txt");
880 RemoveDirectoryA("test6.txt");
884 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
885 ok(!file_exists("test6.txt"), "The file is copied - many files are "
886 "specified as a target\n");
889 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
890 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
892 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
893 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
894 ok(!SHFileOperationA(&shfo2
), "Can't copy many files\n");
895 ok(file_exists("test6.txt"), "The file is not copied - many files are "
896 "specified as a target\n");
897 DeleteFileA("test6.txt");
898 DeleteFileA("test7.txt");
899 RemoveDirectoryA("test8.txt");
901 /* number of sources do not correspond to number of targets */
902 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
903 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
904 retval
= SHFileOperationA(&shfo2
);
905 if (dir_exists("test6.txt"))
907 /* Vista and W2K8 (broken or new behavior ?) */
908 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
909 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
910 "are specified as a target\n");
911 RemoveDirectoryA("test6.txt");
912 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not copied - many files "
913 "are specified as a target\n");
914 RemoveDirectoryA("test7.txt");
918 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
919 ok(!file_exists("test6.txt"), "The file is copied - many files are "
920 "specified as a target\n");
923 set_curr_dir_path(from
, "test1.txt\0");
924 set_curr_dir_path(to
, "test4.txt\0");
925 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are copied recursively\n");
926 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
928 set_curr_dir_path(from
, "test?.txt\0");
929 set_curr_dir_path(to
, "testdir2\0");
930 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
931 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
932 ok(!SHFileOperationA(&shfo
), "Files and directories are copied to directory\n");
933 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
934 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
935 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
936 clean_after_shfo_tests();
939 shfo
.fFlags
|= FOF_FILESONLY
;
940 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
941 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
942 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
943 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
944 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
945 clean_after_shfo_tests();
948 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
949 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
950 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
951 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
952 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
953 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
954 clean_after_shfo_tests();
956 /* Copying multiple files with one not existing as source, fails the
957 entire operation in Win98/ME/2K/XP, but not in 95/NT */
959 tmp_flags
= shfo
.fFlags
;
960 set_curr_dir_path(from
, "test1.txt\0test10.txt\0test2.txt\0");
961 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
962 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
963 retval
= SHFileOperationA(&shfo
);
964 if (retval
== ERROR_SUCCESS
)
965 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
966 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
969 /* Failure if one source file does not exist */
970 ok(retval
== 1026 || /* Win 98/ME/2K/XP */
971 retval
== ERROR_FILE_NOT_FOUND
, /* Vista and W2K8 */
972 "Files are copied to other directory\n");
973 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
975 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
976 shfo
.fFlags
= tmp_flags
;
978 /* copy into a nonexistent directory */
980 shfo
.fFlags
= FOF_NOCONFIRMMKDIR
;
981 set_curr_dir_path(from
, "test1.txt\0");
982 set_curr_dir_path(to
, "nonexistent\\notreal\\test2.txt\0");
983 retval
= SHFileOperationA(&shfo
);
984 ok(!retval
, "Error copying into nonexistent directory\n");
985 ok(file_exists("nonexistent"), "nonexistent not created\n");
986 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
987 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
988 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
990 /* a relative dest directory is OK */
991 clean_after_shfo_tests();
993 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
994 shfo
.pTo
= "testdir2\0";
995 retval
= SHFileOperationA(&shfo
);
996 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
997 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
999 /* try to overwrite an existing write protected file */
1000 clean_after_shfo_tests();
1002 tmp_flags
= shfo
.fFlags
;
1003 shfo
.pFrom
= "test1.txt\0";
1004 shfo
.pTo
= "test2.txt\0";
1005 /* suppress the error-dialog in win9x here */
1006 shfo
.fFlags
= FOF_NOERRORUI
| FOF_NOCONFIRMATION
| FOF_SILENT
;
1007 ret
= SetFileAttributesA(shfo
.pTo
, FILE_ATTRIBUTE_READONLY
);
1008 ok(ret
, "Failure to set file attributes (error %x)\n", GetLastError());
1009 retval
= CopyFileA(shfo
.pFrom
, shfo
.pTo
, FALSE
);
1010 ok(!retval
&& GetLastError() == ERROR_ACCESS_DENIED
, "CopyFileA should have fail with ERROR_ACCESS_DENIED\n");
1011 retval
= SHFileOperationA(&shfo
);
1012 /* Does not work on Win95, Win95B, NT4WS and NT4SRV */
1013 ok(!retval
|| broken(retval
== DE_OPCANCELLED
), "SHFileOperationA failed to copy (error %x)\n", retval
);
1014 /* Set back normal attributes to make the file deletion succeed */
1015 ret
= SetFileAttributesA(shfo
.pTo
, FILE_ATTRIBUTE_NORMAL
);
1016 ok(ret
, "Failure to set file attributes (error %x)\n", GetLastError());
1017 shfo
.fFlags
= tmp_flags
;
1019 /* try to copy files to a file */
1020 clean_after_shfo_tests();
1024 /* suppress the error-dialog in win9x here */
1025 shfo
.fFlags
|= FOF_NOERRORUI
;
1026 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
1027 set_curr_dir_path(to
, "test3.txt\0");
1028 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1029 retval
= SHFileOperationA(&shfo
);
1030 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1031 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1032 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1033 if (retval
== DE_FLDDESTISFILE
|| /* Vista and W2K8 */
1034 retval
== DE_INVALIDFILES
) /* Win7 */
1036 /* Most likely new behavior */
1037 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1041 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1042 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
1044 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
1046 /* try to copy many files to nonexistent directory */
1048 shfo
.fFlags
&= ~FOF_NOERRORUI
;
1049 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1050 retval
= SHFileOperationA(&shfo
);
1051 ok(!shfo
.fAnyOperationsAborted
||
1052 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1053 "Didn't expect aborted operations\n");
1054 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1055 ok(DeleteFileA("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
1056 ok(DeleteFileA("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
1057 ok(RemoveDirectoryA(to
), "Expected test3.txt to exist\n");
1059 /* send in FOF_MULTIDESTFILES with too many destination files */
1061 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1062 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1063 shfo
.fFlags
|= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
1064 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1065 retval
= SHFileOperationA(&shfo
);
1066 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1067 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1068 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1069 if (dir_exists("testdir2\\a.txt"))
1071 /* Vista and W2K8 (broken or new behavior ?) */
1072 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1073 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1074 ok(DeleteFileA("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1075 RemoveDirectoryA("testdir2\\a.txt");
1076 ok(DeleteFileA("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
1077 RemoveDirectoryA("testdir2\\b.txt");
1078 ok(DeleteFileA("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
1079 RemoveDirectoryA("testdir2\\c.txt");
1080 ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
1084 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1085 ok(shfo
.fAnyOperationsAborted
||
1086 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1087 "Expected aborted operations\n");
1088 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
1091 /* send in FOF_MULTIDESTFILES with too many destination files */
1092 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1093 shfo
.pTo
= "e.txt\0f.txt\0";
1094 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1095 retval
= SHFileOperationA(&shfo
);
1096 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1097 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1098 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1099 if (dir_exists("e.txt"))
1101 /* Vista and W2K8 (broken or new behavior ?) */
1102 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1103 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1104 ok(DeleteFileA("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
1105 RemoveDirectoryA("e.txt");
1106 ok(DeleteFileA("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
1107 RemoveDirectoryA("f.txt");
1111 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1112 ok(shfo
.fAnyOperationsAborted
||
1113 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1114 "Expected aborted operations\n");
1115 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
1118 /* use FOF_MULTIDESTFILES with files and a source directory */
1119 shfo
.pFrom
= "test1.txt\0test2.txt\0test4.txt\0";
1120 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
1121 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1122 retval
= SHFileOperationA(&shfo
);
1123 ok(!shfo
.fAnyOperationsAborted
||
1124 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1125 "Didn't expect aborted operations\n");
1126 ok(retval
== ERROR_SUCCESS
||
1127 broken(retval
== 0x100a1), /* WinMe */
1128 "Expected ERROR_SUCCESS, got %d\n", retval
);
1129 ok(DeleteFileA("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1130 ok(DeleteFileA("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
1131 if (retval
== ERROR_SUCCESS
)
1132 ok(RemoveDirectoryA("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
1134 /* try many dest files without FOF_MULTIDESTFILES flag */
1135 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1136 shfo
.pTo
= "a.txt\0b.txt\0c.txt\0";
1137 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1138 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1139 retval
= SHFileOperationA(&shfo
);
1140 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1141 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1142 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1143 if (dir_exists("a.txt"))
1145 /* Vista and W2K8 (broken or new behavior ?) */
1146 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1147 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1148 ok(DeleteFileA("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
1149 ok(DeleteFileA("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
1150 ok(DeleteFileA("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
1151 RemoveDirectoryA("a.txt");
1156 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1157 ok(shfo
.fAnyOperationsAborted
||
1158 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1159 "Expected aborted operations\n");
1160 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1164 shfo
.pFrom
= "test?.txt\0";
1165 shfo
.pTo
= "testdir2\0";
1166 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1167 retval
= SHFileOperationA(&shfo
);
1168 ok(retval
== ERROR_SUCCESS
||
1169 broken(retval
== 0x100a1), /* WinMe */
1170 "Expected ERROR_SUCCESS, got %d\n", retval
);
1171 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1173 /* try a glob with FOF_FILESONLY */
1174 clean_after_shfo_tests();
1176 shfo
.pFrom
= "test?.txt\0";
1177 shfo
.fFlags
|= FOF_FILESONLY
;
1178 retval
= SHFileOperationA(&shfo
);
1179 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1180 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1181 ok(!dir_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
1183 /* try a glob with FOF_MULTIDESTFILES and the same number
1184 * of dest files that we would expect
1186 clean_after_shfo_tests();
1188 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1189 shfo
.fFlags
&= ~FOF_FILESONLY
;
1190 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1191 retval
= SHFileOperationA(&shfo
);
1192 if (dir_exists("testdir2\\a.txt"))
1194 /* Vista and W2K8 (broken or new behavior ?) */
1195 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1196 ok(DeleteFileA("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1197 ok(DeleteFileA("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
1198 ok(DeleteFileA("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
1199 ok(RemoveDirectoryA("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
1200 RemoveDirectoryA("testdir2\\a.txt");
1204 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1205 ok(shfo
.fAnyOperationsAborted
||
1206 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1207 "Expected aborted operations\n");
1208 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
1210 ok(!RemoveDirectoryA("b.txt"), "b.txt should not exist\n");
1212 /* copy one file to two others, second is ignored */
1213 clean_after_shfo_tests();
1215 shfo
.pFrom
= "test1.txt\0";
1216 shfo
.pTo
= "b.txt\0c.txt\0";
1217 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1218 retval
= SHFileOperationA(&shfo
);
1219 ok(!shfo
.fAnyOperationsAborted
||
1220 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1221 "Didn't expect aborted operations\n");
1222 if (retval
== DE_OPCANCELLED
)
1224 /* NT4 fails and doesn't copy any files */
1225 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1226 /* Needed to skip some tests */
1227 win_skip("Skipping some tests on NT4\n");
1232 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1233 ok(DeleteFileA("b.txt"), "Expected b.txt to exist\n");
1235 ok(!DeleteFileA("c.txt"), "Expected c.txt to not exist\n");
1237 /* copy two file to three others, all fail */
1238 shfo
.pFrom
= "test1.txt\0test2.txt\0";
1239 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1240 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1241 retval
= SHFileOperationA(&shfo
);
1242 if (dir_exists("b.txt"))
1244 /* Vista and W2K8 (broken or new behavior ?) */
1245 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1246 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1247 ok(DeleteFileA("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1248 RemoveDirectoryA("b.txt");
1249 ok(DeleteFileA("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1250 RemoveDirectoryA("c.txt");
1254 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1255 ok(shfo
.fAnyOperationsAborted
||
1256 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1257 "Expected aborted operations\n");
1258 ok(!DeleteFileA("b.txt"), "Expected b.txt to not exist\n");
1261 /* copy one file and one directory to three others */
1262 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1263 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1264 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1265 retval
= SHFileOperationA(&shfo
);
1266 if (dir_exists("b.txt"))
1268 /* Vista and W2K8 (broken or new behavior ?) */
1269 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1270 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1271 ok(DeleteFileA("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1272 RemoveDirectoryA("b.txt");
1273 ok(RemoveDirectoryA("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1274 RemoveDirectoryA("c.txt");
1278 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1279 ok(shfo
.fAnyOperationsAborted
||
1280 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1281 "Expected aborted operations\n");
1282 ok(!DeleteFileA("b.txt"), "Expected b.txt to not exist\n");
1283 ok(!DeleteFileA("c.txt"), "Expected c.txt to not exist\n");
1286 /* copy a directory with a file beneath it, plus some files */
1287 createTestFile("test4.txt\\a.txt");
1288 shfo
.pFrom
= "test4.txt\0test1.txt\0";
1289 shfo
.pTo
= "testdir2\0";
1290 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1291 shfo
.fAnyOperationsAborted
= FALSE
;
1292 retval
= SHFileOperationA(&shfo
);
1293 ok(retval
== ERROR_SUCCESS
||
1294 broken(retval
== 0x100a1), /* WinMe */
1295 "Expected ERROR_SUCCESS, got %d\n", retval
);
1296 if (retval
== ERROR_SUCCESS
)
1298 ok(DeleteFileA("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1299 ok(DeleteFileA("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1300 ok(RemoveDirectoryA("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1303 /* copy one directory and a file in that dir to another dir */
1304 shfo
.pFrom
= "test4.txt\0test4.txt\\a.txt\0";
1305 shfo
.pTo
= "testdir2\0";
1306 retval
= SHFileOperationA(&shfo
);
1307 ok(retval
== ERROR_SUCCESS
||
1308 broken(retval
== 0x100a1), /* WinMe */
1309 "Expected ERROR_SUCCESS, got %d\n", retval
);
1310 if (retval
== ERROR_SUCCESS
)
1312 ok(DeleteFileA("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1313 ok(DeleteFileA("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1316 /* copy a file in a directory first, and then the directory to a nonexistent dir */
1317 shfo
.pFrom
= "test4.txt\\a.txt\0test4.txt\0";
1318 shfo
.pTo
= "nonexistent\0";
1319 retval
= SHFileOperationA(&shfo
);
1320 if (dir_exists("nonexistent"))
1322 /* Vista and W2K8 (broken or new behavior ?) */
1323 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1324 ok(DeleteFileA("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1325 RemoveDirectoryA("nonexistent\\test4.txt");
1326 ok(DeleteFileA("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1327 RemoveDirectoryA("nonexistent");
1331 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1332 ok(shfo
.fAnyOperationsAborted
||
1333 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1334 "Expected aborted operations\n");
1335 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1337 DeleteFileA("test4.txt\\a.txt");
1339 /* destination is same as source file */
1340 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1341 shfo
.pTo
= "b.txt\0test2.txt\0c.txt\0";
1342 shfo
.fAnyOperationsAborted
= FALSE
;
1343 shfo
.fFlags
= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
1344 retval
= SHFileOperationA(&shfo
);
1345 if (retval
== DE_OPCANCELLED
)
1347 /* NT4 fails and doesn't copy any files */
1348 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1352 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1353 ok(DeleteFileA("b.txt"), "Expected b.txt to exist\n");
1355 ok(!shfo
.fAnyOperationsAborted
, "Expected no operations to be aborted\n");
1356 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1358 /* destination is same as source directory */
1359 shfo
.pFrom
= "test1.txt\0test4.txt\0test3.txt\0";
1360 shfo
.pTo
= "b.txt\0test4.txt\0c.txt\0";
1361 shfo
.fAnyOperationsAborted
= FALSE
;
1362 retval
= SHFileOperationA(&shfo
);
1363 if (retval
== DE_OPCANCELLED
)
1365 /* NT4 fails and doesn't copy any files */
1366 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1370 ok(retval
== ERROR_SUCCESS
||
1371 retval
== DE_DESTSAMETREE
, /* Vista */
1372 "Expected ERROR_SUCCESS or DE_DESTSAMETREE, got %d\n", retval
);
1373 ok(DeleteFileA("b.txt"), "Expected b.txt to exist\n");
1375 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1377 /* copy a directory into itself, error displayed in UI */
1378 shfo
.pFrom
= "test4.txt\0";
1379 shfo
.pTo
= "test4.txt\\newdir\0";
1380 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1381 shfo
.fAnyOperationsAborted
= FALSE
;
1382 retval
= SHFileOperationA(&shfo
);
1383 ok(retval
== ERROR_SUCCESS
||
1384 retval
== DE_DESTSUBTREE
, /* Vista */
1385 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1386 ok(!RemoveDirectoryA("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1388 /* copy a directory to itself, error displayed in UI */
1389 shfo
.pFrom
= "test4.txt\0";
1390 shfo
.pTo
= "test4.txt\0";
1391 shfo
.fAnyOperationsAborted
= FALSE
;
1392 retval
= SHFileOperationA(&shfo
);
1393 ok(retval
== ERROR_SUCCESS
||
1394 retval
== DE_DESTSUBTREE
, /* Vista */
1395 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1397 /* copy a file into a directory, and the directory into itself */
1398 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1399 shfo
.pTo
= "test4.txt\0";
1400 shfo
.fAnyOperationsAborted
= FALSE
;
1401 shfo
.fFlags
|= FOF_NOCONFIRMATION
;
1402 retval
= SHFileOperationA(&shfo
);
1403 ok(retval
== ERROR_SUCCESS
||
1404 retval
== DE_DESTSUBTREE
, /* Vista */
1405 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1406 ok(DeleteFileA("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1408 /* copy a file to a file, and the directory into itself */
1409 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1410 shfo
.pTo
= "test4.txt\\a.txt\0";
1411 shfo
.fAnyOperationsAborted
= FALSE
;
1412 retval
= SHFileOperationA(&shfo
);
1413 if (dir_exists("test4.txt\\a.txt"))
1415 /* Vista and W2K8 (broken or new behavior ?) */
1416 ok(retval
== DE_DESTSUBTREE
, "Expected DE_DESTSUBTREE, got %d\n", retval
);
1417 ok(DeleteFileA("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1418 RemoveDirectoryA("test4.txt\\a.txt");
1422 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1423 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1426 /* copy a nonexistent file to a nonexistent directory */
1427 shfo
.pFrom
= "e.txt\0";
1428 shfo
.pTo
= "nonexistent\0";
1429 shfo
.fAnyOperationsAborted
= FALSE
;
1430 retval
= SHFileOperationA(&shfo
);
1431 ok(retval
== 1026 ||
1432 retval
== ERROR_FILE_NOT_FOUND
|| /* Vista */
1433 broken(retval
== ERROR_SUCCESS
), /* NT4 */
1434 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval
);
1435 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1436 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1438 /* Overwrite tests */
1439 clean_after_shfo_tests();
1443 /* NT4 would throw up some dialog boxes and doesn't copy files that are needed
1444 * in subsequent tests.
1446 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1447 shfo
.pFrom
= "test1.txt\0";
1448 shfo
.pTo
= "test2.txt\0";
1449 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1450 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1451 retval
= SHFileOperationA(&shfo
);
1452 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1453 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1454 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1456 shfo
.pFrom
= "test3.txt\0test1.txt\0";
1457 shfo
.pTo
= "test2.txt\0one.txt\0";
1458 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_MULTIDESTFILES
;
1459 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1460 retval
= SHFileOperationA(&shfo
);
1461 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1462 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1464 shfo
.pFrom
= "one.txt\0";
1465 shfo
.pTo
= "testdir2\0";
1466 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1467 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1468 retval
= SHFileOperationA(&shfo
);
1469 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1470 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1473 createTestFile("test4.txt\\test1.txt");
1474 shfo
.pFrom
= "test4.txt\0";
1475 shfo
.pTo
= "testdir2\0";
1476 /* WinMe needs FOF_NOERRORUI */
1477 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_NOERRORUI
;
1478 retval
= SHFileOperationA(&shfo
);
1479 ok(retval
== ERROR_SUCCESS
||
1480 broken(retval
== 0x100a1), /* WinMe */
1481 "Expected ERROR_SUCCESS, got %d\n", retval
);
1482 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1485 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1486 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1487 retval
= SHFileOperationA(&shfo
);
1488 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1489 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1492 createTestFile("one.txt");
1494 /* pFrom contains bogus 2nd name longer than MAX_PATH */
1495 memset(from
, 'a', MAX_PATH
*2);
1496 memset(from
+MAX_PATH
*2, 0, 2);
1497 lstrcpyA(from
, "one.txt");
1499 shfo
.pTo
= "two.txt\0";
1500 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1501 retval
= SHFileOperationA(&shfo
);
1502 ok(retval
== 1148 || retval
== 1026 ||
1503 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1504 retval
== DE_INVALIDFILES
, /* Vista */
1505 "Unexpected return value, got %d\n", retval
);
1506 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1507 if (dir_exists("two.txt"))
1508 /* Vista and W2K8 (broken or new behavior ?) */
1509 ok(RemoveDirectoryA("two.txt"), "Expected two.txt to exist\n");
1511 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1513 createTestFile("one.txt");
1515 /* pTo contains bogus 2nd name longer than MAX_PATH */
1516 memset(to
, 'a', MAX_PATH
*2);
1517 memset(to
+MAX_PATH
*2, 0, 2);
1518 lstrcpyA(to
, "two.txt");
1519 shfo
.pFrom
= "one.txt\0";
1521 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1522 retval
= SHFileOperationA(&shfo
);
1523 if (retval
== DE_OPCANCELLED
)
1525 /* NT4 fails and doesn't copy any files */
1526 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1530 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1531 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1533 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1535 createTestFile("one.txt");
1537 /* no FOF_MULTIDESTFILES, two files in pTo */
1538 shfo
.pFrom
= "one.txt\0";
1539 shfo
.pTo
= "two.txt\0three.txt\0";
1540 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1541 retval
= SHFileOperationA(&shfo
);
1542 if (retval
== DE_OPCANCELLED
)
1544 /* NT4 fails and doesn't copy any files */
1545 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1549 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1550 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1552 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1554 createTestFile("one.txt");
1556 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1557 memset(from
, 'a', MAX_PATH
*2);
1558 memset(from
+MAX_PATH
*2, 0, 2);
1559 memset(to
, 'a', MAX_PATH
*2);
1560 memset(to
+MAX_PATH
*2, 0, 2);
1561 lstrcpyA(from
, "one.txt");
1562 lstrcpyA(to
, "two.txt");
1565 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1566 retval
= SHFileOperationA(&shfo
);
1567 ok(retval
== 1148 || retval
== 1026 ||
1568 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1569 retval
== DE_INVALIDFILES
, /* Vista */
1570 "Unexpected return value, got %d\n", retval
);
1571 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1572 if (dir_exists("two.txt"))
1573 /* Vista and W2K8 (broken or new behavior ?) */
1574 ok(RemoveDirectoryA("two.txt"), "Expected two.txt to exist\n");
1576 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1578 createTestFile("one.txt");
1580 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1581 memset(to
, 'a', MAX_PATH
*2);
1582 memset(to
+MAX_PATH
*2, 0, 2);
1583 lstrcpyA(to
, "two.txt");
1584 shfo
.pFrom
= "one.txt\0";
1586 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1587 FOF_SILENT
| FOF_NOERRORUI
;
1588 retval
= SHFileOperationA(&shfo
);
1589 if (retval
== DE_OPCANCELLED
)
1591 /* NT4 fails and doesn't copy any files */
1592 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1596 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1597 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1599 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1601 createTestFile("one.txt");
1602 createTestFile("two.txt");
1604 /* pTo contains bogus 2nd name longer than MAX_PATH,
1605 * multiple source files,
1606 * dest directory does not exist
1608 memset(to
, 'a', 2 * MAX_PATH
);
1609 memset(to
+MAX_PATH
*2, 0, 2);
1610 lstrcpyA(to
, "threedir");
1611 shfo
.pFrom
= "one.txt\0two.txt\0";
1613 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1614 retval
= SHFileOperationA(&shfo
);
1615 if (dir_exists("threedir"))
1617 /* Vista and W2K8 (broken or new behavior ?) */
1618 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1619 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1620 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1621 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1625 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1626 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1627 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1628 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1629 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1631 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1632 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1634 createTestFile("one.txt");
1635 createTestFile("two.txt");
1636 CreateDirectoryA("threedir", NULL
);
1638 /* pTo contains bogus 2nd name longer than MAX_PATH,
1639 * multiple source files,
1640 * dest directory does exist
1642 memset(to
, 'a', 2 * MAX_PATH
);
1643 memset(to
+MAX_PATH
*2, 0, 2);
1644 lstrcpyA(to
, "threedir");
1645 shfo
.pFrom
= "one.txt\0two.txt\0";
1647 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1648 retval
= SHFileOperationA(&shfo
);
1649 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1650 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1651 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1652 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1653 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1654 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1657 /* this crashes on win9x */
1658 createTestFile("one.txt");
1659 createTestFile("two.txt");
1661 /* pTo contains bogus 2nd name longer than MAX_PATH,
1662 * multiple source files, FOF_MULTIDESTFILES
1663 * dest dir does not exist
1666 memset(to
, 'a', 2 * MAX_PATH
);
1667 memset(to
+MAX_PATH
*2, 0, 2);
1668 lstrcpyA(to
, "threedir");
1669 shfo
.pFrom
= "one.txt\0two.txt\0";
1671 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1672 FOF_SILENT
| FOF_NOERRORUI
;
1673 retval
= SHFileOperationA(&shfo
);
1674 ok(retval
== ERROR_CANCELLED
||
1675 retval
== ERROR_SUCCESS
, /* win2k3 */
1676 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval
);
1677 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1678 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1679 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1680 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1681 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1683 /* file exists in win2k */
1684 DeleteFileA("threedir");
1688 createTestFile("one.txt");
1689 createTestFile("two.txt");
1690 CreateDirectoryA("threedir", NULL
);
1692 /* pTo contains bogus 2nd name longer than MAX_PATH,
1693 * multiple source files, FOF_MULTIDESTFILES
1694 * dest dir does exist
1696 memset(to
, 'a', 2 * MAX_PATH
);
1697 memset(to
+MAX_PATH
*2, 0, 2);
1698 lstrcpyA(to
, "threedir");
1699 ptr
= to
+ lstrlenA(to
) + 1;
1700 lstrcpyA(ptr
, "fourdir");
1701 shfo
.pFrom
= "one.txt\0two.txt\0";
1703 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1704 FOF_SILENT
| FOF_NOERRORUI
;
1705 retval
= SHFileOperationA(&shfo
);
1706 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1707 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1708 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1709 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1710 if (dir_exists("fourdir"))
1712 /* Vista and W2K8 (broken or new behavior ?) */
1713 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1714 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1715 RemoveDirectoryA("fourdir");
1719 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1720 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1721 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1723 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1725 createTestFile("one.txt");
1726 createTestFile("two.txt");
1727 CreateDirectoryA("threedir", NULL
);
1729 /* multiple source files, FOF_MULTIDESTFILES
1730 * multiple dest files, but first dest dir exists
1731 * num files in lists is equal
1733 shfo
.pFrom
= "one.txt\0two.txt\0";
1734 shfo
.pTo
= "threedir\0fourdir\0";
1735 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1736 FOF_SILENT
| FOF_NOERRORUI
;
1737 retval
= SHFileOperationA(&shfo
);
1738 ok(retval
== ERROR_CANCELLED
||
1739 retval
== DE_FILEDESTISFLD
|| /* Vista */
1740 broken(retval
== DE_OPCANCELLED
), /* Win9x, NT4 */
1741 "Expected ERROR_CANCELLED or DE_FILEDESTISFLD. got %d\n", retval
);
1742 if (file_exists("threedir\\threedir"))
1745 ok(DeleteFileA("threedir\\threedir"), "Expected file to exist\n");
1747 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1748 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1749 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1750 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1751 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1752 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1753 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1755 createTestFile("one.txt");
1756 createTestFile("two.txt");
1757 CreateDirectoryA("threedir", NULL
);
1759 /* multiple source files, FOF_MULTIDESTFILES
1760 * multiple dest files, but first dest dir exists
1761 * num files in lists is not equal
1763 shfo
.pFrom
= "one.txt\0two.txt\0";
1764 shfo
.pTo
= "threedir\0fourdir\0five\0";
1765 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1766 FOF_SILENT
| FOF_NOERRORUI
;
1767 retval
= SHFileOperationA(&shfo
);
1768 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1769 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1770 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1771 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1772 if (dir_exists("fourdir"))
1774 /* Vista and W2K8 (broken or new behavior ?) */
1775 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1776 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1777 RemoveDirectoryA("fourdir");
1781 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1782 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1783 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1785 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1786 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1787 ok(!RemoveDirectoryA("five"), "Expected dir to not exist\n");
1789 createTestFile("aa.txt");
1790 createTestFile("ab.txt");
1791 CreateDirectoryA("one", NULL
);
1792 CreateDirectoryA("two", NULL
);
1794 /* pFrom has a glob, pTo has more than one dest */
1795 shfo
.pFrom
= "a*.txt\0";
1796 shfo
.pTo
= "one\0two\0";
1797 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1798 retval
= SHFileOperationA(&shfo
);
1799 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1800 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1801 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1802 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1803 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1804 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1805 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1806 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1807 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1809 /* pTo is an empty string */
1810 CreateDirectoryA("dir", NULL
);
1811 createTestFile("dir\\abcdefgh.abc");
1812 shfo
.pFrom
= "dir\\abcdefgh.abc\0";
1814 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1815 retval
= SHFileOperationA(&shfo
);
1816 ok(retval
== ERROR_SUCCESS
||
1817 broken(retval
== DE_OPCANCELLED
), /* NT4 */
1818 "Expected ERROR_SUCCESS, got %d\n", retval
);
1819 if (retval
== ERROR_SUCCESS
)
1820 ok(DeleteFileA("abcdefgh.abc"), "Expected file to exist\n");
1821 ok(DeleteFileA("dir\\abcdefgh.abc"), "Expected file to exist\n");
1822 ok(RemoveDirectoryA("dir"), "Expected dir to exist\n");
1825 /* tests the FO_MOVE action */
1826 static void test_move(void)
1828 SHFILEOPSTRUCTA shfo
, shfo2
;
1829 CHAR from
[5*MAX_PATH
];
1830 CHAR to
[5*MAX_PATH
];
1834 shfo
.wFunc
= FO_MOVE
;
1837 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1838 shfo
.hNameMappings
= NULL
;
1839 shfo
.lpszProgressTitle
= NULL
;
1841 set_curr_dir_path(from
, "test1.txt\0");
1842 set_curr_dir_path(to
, "test4.txt\0");
1843 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are moved recursively\n");
1844 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1845 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1847 set_curr_dir_path(from
, "test?.txt\0");
1848 set_curr_dir_path(to
, "testdir2\0");
1849 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1850 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1851 ok(!SHFileOperationA(&shfo
), "Files and directories are moved to directory\n");
1852 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1853 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1854 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1856 clean_after_shfo_tests();
1859 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
1860 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
1862 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1863 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1865 shfo2
.fFlags
|= FOF_NOCONFIRMMKDIR
;
1866 ok(!SHFileOperationA(&shfo2
), "Move many files\n");
1867 ok(DeleteFileA("test6.txt"), "The file is not moved - many files are "
1868 "specified as a target\n");
1869 ok(DeleteFileA("test7.txt"), "The file is not moved\n");
1870 ok(RemoveDirectoryA("test8.txt"), "The directory is not moved\n");
1874 /* number of sources do not correspond to number of targets,
1875 include directories */
1876 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1877 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1878 retval
= SHFileOperationA(&shfo2
);
1879 if (dir_exists("test6.txt"))
1881 if (retval
== ERROR_SUCCESS
)
1884 DeleteFileA("test6.txt\\test1.txt");
1885 DeleteFileA("test6.txt\\test2.txt");
1886 RemoveDirectoryA("test6.txt\\test4.txt");
1887 RemoveDirectoryA("test6.txt");
1891 /* Vista and W2K8 (broken or new behavior ?) */
1892 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
1893 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1894 RemoveDirectoryA("test6.txt");
1895 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1896 RemoveDirectoryA("test7.txt");
1901 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1902 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1903 "specified as a target\n");
1907 /* number of sources do not correspond to number of targets,
1910 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test3.txt\0");
1911 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1912 retval
= SHFileOperationA(&shfo2
);
1913 if (dir_exists("test6.txt"))
1915 if (retval
== ERROR_SUCCESS
)
1918 DeleteFileA("test6.txt\\test1.txt");
1919 DeleteFileA("test6.txt\\test2.txt");
1920 RemoveDirectoryA("test6.txt\\test4.txt");
1921 RemoveDirectoryA("test6.txt");
1925 /* Vista and W2K8 (broken or new behavior ?) */
1926 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1927 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1928 RemoveDirectoryA("test6.txt");
1929 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1930 RemoveDirectoryA("test7.txt");
1931 ok(file_exists("test3.txt"), "File should not be moved\n");
1936 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1937 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1938 "specified as a target\n");
1942 /* number of sources do not correspond to number of targets,
1945 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
1946 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1947 retval
= SHFileOperationA(&shfo2
);
1948 if (dir_exists("test6.txt"))
1950 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1951 ok(DeleteFileA("test6.txt\\test1.txt"),"The file is not moved\n");
1952 ok(DeleteFileA("test7.txt\\test2.txt"),"The file is not moved\n");
1953 ok(!dir_exists("test8.txt") && !file_exists("test8.txt"),
1954 "Directory should not be created\n");
1955 RemoveDirectoryA("test6.txt");
1956 RemoveDirectoryA("test7.txt");
1960 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* WinXp, Win2k */);
1961 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1962 "specified as a target\n");
1966 /* number of sources do not correspond to number of targets,
1967 target directories */
1968 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test3.txt\0");
1969 set_curr_dir_path(to
, "test4.txt\0test5.txt\0");
1970 retval
= SHFileOperationA(&shfo2
);
1971 if (dir_exists("test5.txt"))
1973 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1974 ok(DeleteFileA("test4.txt\\test1.txt"),"The file is not moved\n");
1975 ok(DeleteFileA("test5.txt\\test2.txt"),"The file is not moved\n");
1976 ok(file_exists("test3.txt"), "The file is not moved\n");
1977 RemoveDirectoryA("test4.txt");
1978 RemoveDirectoryA("test5.txt");
1982 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1983 ok(DeleteFileA("test4.txt\\test1.txt"),"The file is not moved\n");
1984 ok(DeleteFileA("test4.txt\\test2.txt"),"The file is not moved\n");
1985 ok(DeleteFileA("test4.txt\\test3.txt"),"The file is not moved\n");
1990 /* 0 incomming files */
1991 set_curr_dir_path(from
, "\0\0");
1992 set_curr_dir_path(to
, "test6.txt\0\0");
1993 retval
= SHFileOperationA(&shfo2
);
1994 ok(retval
== ERROR_SUCCESS
|| retval
== ERROR_ACCESS_DENIED
1995 , "Expected ERROR_SUCCESS || ERROR_ACCESS_DENIED, got %d\n", retval
);
1996 ok(!file_exists("test6.txt"), "The file should not exist\n");
1999 /* 0 outgoing files */
2000 set_curr_dir_path(from
, "test1\0\0");
2001 set_curr_dir_path(to
, "\0\0");
2002 retval
= SHFileOperationA(&shfo2
);
2003 ok(retval
== ERROR_FILE_NOT_FOUND
||
2004 broken(retval
== 1026)
2005 , "Expected ERROR_FILE_NOT_FOUND, got %d\n", retval
);
2006 ok(!file_exists("test6.txt"), "The file should not exist\n");
2010 set_curr_dir_path(from
, "test3.txt\0");
2011 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
2012 ok(!SHFileOperationA(&shfo
), "Can't move file to other directory\n");
2013 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
2015 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
2016 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
2018 shfo
.fFlags
|= FOF_NOCONFIRMMKDIR
;
2019 retval
= SHFileOperationA(&shfo
);
2020 if (dir_exists("test6.txt"))
2023 /* Vista and W2K8 (broken or new behavior ?) */
2024 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2025 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
2026 ok(DeleteFileA("test6.txt\\test2.txt"), "The file is not moved. Many files are specified\n");
2027 ok(DeleteFileA("test6.txt\\test4.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
2028 ok(RemoveDirectoryA("test6.txt\\test4.txt"), "The directory is not moved. Many files are specified\n");
2029 RemoveDirectoryA("test6.txt");
2034 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2035 ok(file_exists("test1.txt"), "The file is moved. Many files are specified\n");
2036 ok(dir_exists("test4.txt"), "The directory is moved. Many files are specified\n");
2039 set_curr_dir_path(from
, "test1.txt\0");
2040 set_curr_dir_path(to
, "test6.txt\0");
2041 ok(!SHFileOperationA(&shfo
), "Move file failed\n");
2042 ok(!file_exists("test1.txt"), "The file is not moved\n");
2043 ok(file_exists("test6.txt"), "The file is not moved\n");
2044 set_curr_dir_path(from
, "test6.txt\0");
2045 set_curr_dir_path(to
, "test1.txt\0");
2046 ok(!SHFileOperationA(&shfo
), "Move file back failed\n");
2048 set_curr_dir_path(from
, "test4.txt\0");
2049 set_curr_dir_path(to
, "test6.txt\0");
2050 ok(!SHFileOperationA(&shfo
), "Move dir failed\n");
2051 ok(!dir_exists("test4.txt"), "The dir is not moved\n");
2052 ok(dir_exists("test6.txt"), "The dir is moved\n");
2053 set_curr_dir_path(from
, "test6.txt\0");
2054 set_curr_dir_path(to
, "test4.txt\0");
2055 ok(!SHFileOperationA(&shfo
), "Move dir back failed\n");
2057 /* move one file to two others */
2059 shfo
.pFrom
= "test1.txt\0";
2060 shfo
.pTo
= "a.txt\0b.txt\0";
2061 retval
= SHFileOperationA(&shfo
);
2062 if (retval
== DE_OPCANCELLED
)
2064 /* NT4 fails and doesn't move any files */
2065 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
2066 DeleteFileA("test1.txt");
2070 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2073 DeleteFileA("a.txt\\a.txt");
2074 RemoveDirectoryA("a.txt");
2077 ok(DeleteFileA("a.txt"), "Expected a.txt to exist\n");
2078 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
2080 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
2082 /* move two files to one other */
2083 shfo
.pFrom
= "test2.txt\0test3.txt\0";
2084 shfo
.pTo
= "test1.txt\0";
2085 retval
= SHFileOperationA(&shfo
);
2086 if (dir_exists("test1.txt"))
2089 /* Vista and W2K8 (broken or new behavior ?) */
2090 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2091 ok(DeleteFileA("test1.txt\\test2.txt"), "Expected test1.txt\\test2.txt to exist\n");
2092 ok(DeleteFileA("test1.txt\\test3.txt"), "Expected test1.txt\\test3.txt to exist\n");
2093 RemoveDirectoryA("test1.txt");
2094 createTestFile("test2.txt");
2095 createTestFile("test3.txt");
2099 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2100 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
2101 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
2102 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2105 /* move a directory into itself */
2106 shfo
.pFrom
= "test4.txt\0";
2107 shfo
.pTo
= "test4.txt\\b.txt\0";
2108 retval
= SHFileOperationA(&shfo
);
2109 ok(retval
== ERROR_SUCCESS
||
2110 retval
== DE_DESTSUBTREE
, /* Vista */
2111 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
2112 ok(!RemoveDirectoryA("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
2113 ok(dir_exists("test4.txt"), "Expected test4.txt to exist\n");
2115 /* move many files without FOF_MULTIDESTFILES */
2116 shfo
.pFrom
= "test2.txt\0test3.txt\0";
2117 shfo
.pTo
= "d.txt\0e.txt\0";
2118 retval
= SHFileOperationA(&shfo
);
2119 if (dir_exists("d.txt"))
2122 /* Vista and W2K8 (broken or new behavior ?) */
2123 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2124 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
2125 ok(DeleteFileA("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to exist\n");
2126 RemoveDirectoryA("d.txt");
2127 createTestFile("test2.txt");
2128 createTestFile("test3.txt");
2132 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2133 ok(!DeleteFileA("d.txt"), "Expected d.txt to not exist\n");
2134 ok(!DeleteFileA("e.txt"), "Expected e.txt to not exist\n");
2137 /* number of sources != number of targets */
2138 shfo
.pTo
= "d.txt\0";
2139 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
2140 retval
= SHFileOperationA(&shfo
);
2141 if (dir_exists("d.txt"))
2145 DeleteFileA("d.txt\\test2.txt");
2146 DeleteFileA("d.txt\\test3.txt");
2147 RemoveDirectoryA("d.txt");
2148 createTestFile("test2.txt");
2152 /* Vista and W2K8 (broken or new behavior ?) */
2153 ok(retval
== DE_SAMEFILE
,
2154 "Expected DE_SAMEFILE, got %d\n", retval
);
2155 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
2156 ok(!file_exists("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to not exist\n");
2157 RemoveDirectoryA("d.txt");
2158 createTestFile("test2.txt");
2163 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2164 ok(!DeleteFileA("d.txt"), "Expected d.txt to not exist\n");
2167 /* FO_MOVE does not create dest directories */
2168 shfo
.pFrom
= "test2.txt\0";
2169 shfo
.pTo
= "dir1\\dir2\\test2.txt\0";
2170 retval
= SHFileOperationA(&shfo
);
2171 if (dir_exists("dir1"))
2173 /* Vista and W2K8 (broken or new behavior ?) */
2174 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2175 ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n");
2176 RemoveDirectoryA("dir1\\dir2");
2177 RemoveDirectoryA("dir1");
2178 createTestFile("test2.txt");
2182 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2185 /* try to overwrite an existing file */
2186 shfo
.pTo
= "test3.txt\0";
2187 retval
= SHFileOperationA(&shfo
);
2188 if (retval
== DE_OPCANCELLED
)
2190 /* NT4 fails and doesn't move any files */
2191 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
2195 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2196 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
2199 DeleteFileA("test3.txt\\test3.txt");
2200 RemoveDirectoryA("test3.txt");
2203 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2207 static void test_sh_create_dir(void)
2209 CHAR path
[MAX_PATH
];
2212 if(!pSHCreateDirectoryExA
)
2214 win_skip("skipping SHCreateDirectoryExA tests\n");
2218 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2219 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
2220 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret
);
2221 ok(file_exists("testdir2"), "The first directory is not created\n");
2222 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
2224 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
2225 ok(ERROR_ALREADY_EXISTS
== ret
, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret
);
2227 ret
= pSHCreateDirectoryExA(NULL
, "c:\\testdir3", NULL
);
2228 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory, ret = %d\n", ret
);
2229 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
2232 static void test_sh_path_prepare(void)
2235 CHAR path
[MAX_PATH
];
2236 CHAR UNICODE_PATH_A
[MAX_PATH
];
2237 BOOL UsedDefaultChar
;
2239 if(!pSHPathPrepareForWriteA
)
2241 win_skip("skipping SHPathPrepareForWriteA tests\n");
2245 /* directory exists, SHPPFW_NONE */
2246 set_curr_dir_path(path
, "testdir2\0");
2247 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2248 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2250 /* directory exists, SHPPFW_IGNOREFILENAME */
2251 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2252 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
2253 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2255 /* directory exists, SHPPFW_DIRCREATE */
2256 set_curr_dir_path(path
, "testdir2\0");
2257 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2258 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2260 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2261 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2262 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
2263 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2264 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2266 /* file exists, SHPPFW_NONE */
2267 set_curr_dir_path(path
, "test1.txt\0");
2268 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2269 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2270 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2271 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2272 "Unexpected result : 0x%08x\n", res
);
2274 /* file exists, SHPPFW_DIRCREATE */
2275 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2276 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2277 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2278 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2279 "Unexpected result : 0x%08x\n", res
);
2281 /* file exists, SHPPFW_NONE, trailing \ */
2282 set_curr_dir_path(path
, "test1.txt\\\0");
2283 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2284 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2285 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2286 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2287 "Unexpected result : 0x%08x\n", res
);
2289 /* relative path exists, SHPPFW_DIRCREATE */
2290 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE
);
2291 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2293 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
2294 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE
);
2295 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2296 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
2298 /* directory doesn't exist, SHPPFW_NONE */
2299 set_curr_dir_path(path
, "nonexistent\0");
2300 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2301 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2303 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
2304 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2305 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
2306 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2307 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
2308 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2310 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2311 set_curr_dir_path(path
, "testdir2\\test4.txt\\\0");
2312 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
2313 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2314 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
2316 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
2317 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2318 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2319 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2320 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
2322 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
2324 if(!pSHPathPrepareForWriteW
)
2326 win_skip("Skipping SHPathPrepareForWriteW tests\n");
2330 SetLastError(0xdeadbeef);
2331 UsedDefaultChar
= FALSE
;
2332 if (WideCharToMultiByte(CP_ACP
, WC_NO_BEST_FIT_CHARS
, UNICODE_PATH
, -1, UNICODE_PATH_A
, sizeof(UNICODE_PATH_A
), NULL
, &UsedDefaultChar
) == 0)
2334 win_skip("Could not convert Unicode path name to multibyte (%d)\n", GetLastError());
2337 if (UsedDefaultChar
)
2339 win_skip("Could not find unique multibyte representation for directory name using default codepage\n");
2343 /* unicode directory doesn't exist, SHPPFW_NONE */
2344 RemoveDirectoryA(UNICODE_PATH_A
);
2345 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2346 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2347 ok(!file_exists(UNICODE_PATH_A
), "unicode path was created but shouldn't be\n");
2348 RemoveDirectoryA(UNICODE_PATH_A
);
2350 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
2351 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2352 ok(res
== S_OK
, "res == %08x, expected S_OK\n", res
);
2353 ok(file_exists(UNICODE_PATH_A
), "unicode path should've been created\n");
2355 /* unicode directory exists, SHPPFW_NONE */
2356 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2357 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2359 /* unicode directory exists, SHPPFW_DIRCREATE */
2360 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2361 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2362 RemoveDirectoryA(UNICODE_PATH_A
);
2365 static void test_sh_new_link_info(void)
2367 BOOL ret
, mustcopy
=TRUE
;
2368 CHAR linkto
[MAX_PATH
];
2369 CHAR destdir
[MAX_PATH
];
2370 CHAR result
[MAX_PATH
];
2371 CHAR result2
[MAX_PATH
];
2373 /* source file does not exist */
2374 set_curr_dir_path(linkto
, "nosuchfile.txt\0");
2375 set_curr_dir_path(destdir
, "testdir2\0");
2376 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2378 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2379 "SHGetNewLinkInfoA succeeded\n");
2380 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2382 /* dest dir does not exist */
2383 set_curr_dir_path(linkto
, "test1.txt\0");
2384 set_curr_dir_path(destdir
, "nosuchdir\0");
2385 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2387 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2388 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2389 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2391 /* source file exists */
2392 set_curr_dir_path(linkto
, "test1.txt\0");
2393 set_curr_dir_path(destdir
, "testdir2\0");
2394 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2396 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2397 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2398 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2399 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, destdir
,
2400 lstrlenA(destdir
), result
, lstrlenA(destdir
)) == CSTR_EQUAL
,
2401 "%s does not start with %s\n", result
, destdir
);
2402 ok(lstrlenA(result
) > 4 && lstrcmpiA(result
+lstrlenA(result
)-4, ".lnk") == 0,
2403 "%s does not end with .lnk\n", result
);
2405 /* preferred target name already exists */
2406 createTestFile(result
);
2407 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result2
, &mustcopy
, 0);
2409 broken(ret
== lstrlenA(result2
) + 1), /* NT4 */
2410 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2411 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2412 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, destdir
,
2413 lstrlenA(destdir
), result2
, lstrlenA(destdir
)) == CSTR_EQUAL
,
2414 "%s does not start with %s\n", result2
, destdir
);
2415 ok(lstrlenA(result2
) > 4 && lstrcmpiA(result2
+lstrlenA(result2
)-4, ".lnk") == 0,
2416 "%s does not end with .lnk\n", result2
);
2417 ok(lstrcmpiA(result
, result2
) != 0, "%s and %s are the same\n", result
, result2
);
2418 DeleteFileA(result
);
2421 static void test_unicode(void)
2423 SHFILEOPSTRUCTW shfoW
;
2427 if (!pSHFileOperationW
)
2429 skip("SHFileOperationW() is missing\n");
2434 shfoW
.wFunc
= FO_DELETE
;
2435 shfoW
.pFrom
= UNICODE_PATH
;
2437 shfoW
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
2438 shfoW
.hNameMappings
= NULL
;
2439 shfoW
.lpszProgressTitle
= NULL
;
2441 /* Clean up before start test */
2442 DeleteFileW(UNICODE_PATH
);
2443 RemoveDirectoryW(UNICODE_PATH
);
2445 /* Make sure we are on a system that supports unicode */
2446 SetLastError(0xdeadbeef);
2447 file
= CreateFileW(UNICODE_PATH
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
2448 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
2450 skip("Unicode tests skipped on non-unicode system\n");
2455 /* Try to delete a file with unicode filename */
2456 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2457 ret
= pSHFileOperationW(&shfoW
);
2458 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2459 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2461 /* Try to trash a file with unicode filename */
2462 createTestFileW(UNICODE_PATH
);
2463 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2464 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2465 ret
= pSHFileOperationW(&shfoW
);
2466 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2467 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2469 if(!pSHCreateDirectoryExW
)
2471 skip("Skipping SHCreateDirectoryExW tests\n");
2475 /* Try to delete a directory with unicode filename */
2476 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2477 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2478 ok(file_existsW(UNICODE_PATH
), "The directory is not created\n");
2479 shfoW
.fFlags
&= ~FOF_ALLOWUNDO
;
2480 ret
= pSHFileOperationW(&shfoW
);
2481 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2482 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2484 /* Try to trash a directory with unicode filename */
2485 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2486 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2487 ok(file_existsW(UNICODE_PATH
), "The directory was not created\n");
2488 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2489 ret
= pSHFileOperationW(&shfoW
);
2490 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2491 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2495 test_shlmenu(void) {
2497 hres
= Shell_MergeMenus (0, 0, 0x42, 0x4242, 0x424242, 0);
2498 ok (hres
== 0x4242, "expected 0x4242 but got %x\n", hres
);
2499 hres
= Shell_MergeMenus ((HMENU
)42, 0, 0x42, 0x4242, 0x424242, 0);
2500 ok (hres
== 0x4242, "expected 0x4242 but got %x\n", hres
);
2503 /* Check for old shell32 (4.0.x) */
2504 static BOOL
is_old_shell32(void)
2506 SHFILEOPSTRUCTA shfo
;
2507 CHAR from
[5*MAX_PATH
];
2508 CHAR to
[5*MAX_PATH
];
2512 shfo
.wFunc
= FO_COPY
;
2515 /* FOF_NOCONFIRMMKDIR is needed for old shell32 */
2516 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
| FOF_MULTIDESTFILES
| FOF_NOCONFIRMMKDIR
;
2517 shfo
.hNameMappings
= NULL
;
2518 shfo
.lpszProgressTitle
= NULL
;
2520 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test3.txt\0");
2521 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
2522 retval
= SHFileOperationA(&shfo
);
2524 /* Delete extra files on old shell32 and Vista+*/
2525 DeleteFileA("test6.txt\\test1.txt");
2526 /* Delete extra files on old shell32 */
2527 DeleteFileA("test6.txt\\test2.txt");
2528 DeleteFileA("test6.txt\\test3.txt");
2529 /* Delete extra directory on old shell32 and Vista+ */
2530 RemoveDirectoryA("test6.txt");
2531 /* Delete extra files/directories on Vista+*/
2532 DeleteFileA("test7.txt\\test2.txt");
2533 RemoveDirectoryA("test7.txt");
2535 if (retval
== ERROR_SUCCESS
)
2541 START_TEST(shlfileop
)
2543 InitFunctionPointers();
2545 clean_after_shfo_tests();
2548 old_shell32
= is_old_shell32();
2550 win_skip("Need to cater for old shell32 (4.0.x) on Win95\n");
2551 clean_after_shfo_tests();
2554 test_get_file_info();
2555 test_get_file_info_iconlist();
2556 clean_after_shfo_tests();
2560 clean_after_shfo_tests();
2564 clean_after_shfo_tests();
2568 clean_after_shfo_tests();
2572 clean_after_shfo_tests();
2574 test_sh_create_dir();
2575 clean_after_shfo_tests();
2578 test_sh_path_prepare();
2579 clean_after_shfo_tests();
2582 test_sh_new_link_info();
2583 clean_after_shfo_tests();