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 (SearchPath(NULL
, "notepad.exe", NULL
, sizeof(notepad
), notepad
, NULL
))
263 strcpy(shfi
.szDisplayName
, "dummy");
264 shfi
.iIcon
=0xdeadbeef;
265 rc
=SHGetFileInfoA(notepad
, GetFileAttributes(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(lstrcmpi(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", GetFileAttributes("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(lstrcmpi(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(lstrcmp(shfi
.szDisplayName
, "dummy") != 0, "display name was expected to change\n");
310 ok(lstrcmp(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(!SHFileOperation(&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(!SHFileOperation(&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
= SHFileOperation(&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
= SHFileOperation(&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
= SHFileOperation(&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
= SHFileOperation(&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
= SHFileOperation(&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 /* try the FOF_NORECURSION flag, continues deleting subdirs */
651 shfo
.pFrom
= "testdir2\0";
652 shfo
.fFlags
|= FOF_NORECURSION
;
653 ret
= SHFileOperation(&shfo
);
654 ok(ret
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", ret
);
655 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
656 ok(!dir_exists("testdir2\\nested"), "Expected testdir2\\nested to not exist\n");
659 /* tests the FO_RENAME action */
660 static void test_rename(void)
662 SHFILEOPSTRUCTA shfo
, shfo2
;
663 CHAR from
[5*MAX_PATH
];
668 shfo
.wFunc
= FO_RENAME
;
671 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
672 shfo
.hNameMappings
= NULL
;
673 shfo
.lpszProgressTitle
= NULL
;
675 set_curr_dir_path(from
, "test1.txt\0");
676 set_curr_dir_path(to
, "test4.txt\0");
677 retval
= SHFileOperationA(&shfo
);
678 ok(retval
== ERROR_ALREADY_EXISTS
||
679 retval
== DE_FILEDESTISFLD
|| /* Vista */
680 broken(retval
== ERROR_INVALID_NAME
), /* Win9x, NT4 */
681 "Expected ERROR_ALREADY_EXISTS or DE_FILEDESTISFLD, got %d\n", retval
);
682 ok(file_exists("test1.txt"), "The file is renamed\n");
684 set_curr_dir_path(from
, "test3.txt\0");
685 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
686 retval
= SHFileOperationA(&shfo
);
687 if (retval
== DE_DIFFDIR
)
689 /* Vista and W2K8 (broken or new behavior ?) */
690 ok(!file_exists("test4.txt\\test1.txt"), "The file is renamed\n");
694 ok(retval
== ERROR_SUCCESS
, "File is renamed moving to other directory\n");
695 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
698 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
699 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
700 retval
= SHFileOperationA(&shfo
);
701 ok(retval
== ERROR_GEN_FAILURE
||
702 retval
== DE_MANYSRC1DEST
|| /* Vista */
703 broken(retval
== ERROR_SUCCESS
), /* Win9x */
704 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST , got %d\n", retval
);
705 ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
707 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
708 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
710 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
711 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
712 retval
= SHFileOperationA(&shfo2
);
713 ok(retval
== ERROR_GEN_FAILURE
||
714 retval
== DE_MANYSRC1DEST
|| /* Vista */
715 broken(retval
== ERROR_SUCCESS
), /* Win9x */
716 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST files, got %d\n", retval
);
717 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
719 set_curr_dir_path(from
, "test1.txt\0");
720 set_curr_dir_path(to
, "test6.txt\0");
721 retval
= SHFileOperationA(&shfo
);
722 ok(retval
== ERROR_SUCCESS
, "Rename file failed, retval = %d\n", retval
);
723 ok(!file_exists("test1.txt"), "The file is not renamed\n");
724 ok(file_exists("test6.txt"), "The file is not renamed\n");
726 set_curr_dir_path(from
, "test6.txt\0");
727 set_curr_dir_path(to
, "test1.txt\0");
728 retval
= SHFileOperationA(&shfo
);
729 ok(retval
== ERROR_SUCCESS
, "Rename file back failed, retval = %d\n", retval
);
731 set_curr_dir_path(from
, "test4.txt\0");
732 set_curr_dir_path(to
, "test6.txt\0");
733 retval
= SHFileOperationA(&shfo
);
734 ok(retval
== ERROR_SUCCESS
, "Rename dir failed, retval = %d\n", retval
);
735 ok(!dir_exists("test4.txt"), "The dir is not renamed\n");
736 ok(dir_exists("test6.txt"), "The dir is not renamed\n");
738 set_curr_dir_path(from
, "test6.txt\0");
739 set_curr_dir_path(to
, "test4.txt\0");
740 retval
= SHFileOperationA(&shfo
);
741 ok(retval
== ERROR_SUCCESS
, "Rename dir back failed, retval = %d\n", retval
);
742 ok(dir_exists("test4.txt"), "The dir is not renamed\n");
744 /* try to rename more than one file to a single file */
745 shfo
.pFrom
= "test1.txt\0test2.txt\0";
746 shfo
.pTo
= "a.txt\0";
747 retval
= SHFileOperationA(&shfo
);
748 ok(retval
== ERROR_GEN_FAILURE
||
749 retval
== DE_MANYSRC1DEST
|| /* Vista */
750 broken(retval
== ERROR_SUCCESS
), /* Win9x */
751 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST, got %d\n", retval
);
752 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
753 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
754 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
756 /* pFrom doesn't exist */
757 shfo
.pFrom
= "idontexist\0";
758 shfo
.pTo
= "newfile\0";
759 retval
= SHFileOperationA(&shfo
);
761 retval
== ERROR_FILE_NOT_FOUND
|| /* Vista */
762 broken(retval
== ERROR_SUCCESS
), /* NT4 */
763 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval
);
764 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
766 /* pTo already exist */
767 shfo
.pFrom
= "test1.txt\0";
768 shfo
.pTo
= "test2.txt\0";
770 shfo
.fFlags
|= FOF_NOCONFIRMMKDIR
;
771 retval
= SHFileOperationA(&shfo
);
772 if (retval
== ERROR_SUCCESS
)
774 /* Vista and W2K8 (broken or new behavior ?) */
775 createTestFile("test1.txt");
779 ok(retval
== ERROR_ALREADY_EXISTS
||
780 broken(retval
== DE_OPCANCELLED
) || /* NT4 */
781 broken(retval
== ERROR_INVALID_NAME
), /* Win9x */
782 "Expected ERROR_ALREADY_EXISTS, got %d\n", retval
);
785 /* pFrom is valid, but pTo is empty */
786 shfo
.pFrom
= "test1.txt\0";
788 retval
= SHFileOperationA(&shfo
);
789 ok(retval
== ERROR_CANCELLED
||
790 retval
== DE_DIFFDIR
|| /* Vista */
791 broken(retval
== DE_OPCANCELLED
) || /* Win9x */
792 broken(retval
== 65652), /* NT4 */
793 "Expected ERROR_CANCELLED or DE_DIFFDIR\n");
794 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
798 retval
= SHFileOperationA(&shfo
);
799 ok(retval
== ERROR_ACCESS_DENIED
||
800 retval
== DE_MANYSRC1DEST
|| /* Vista */
801 broken(retval
== ERROR_SUCCESS
), /* Win9x */
802 "Expected ERROR_ACCESS_DENIED or DE_MANYSRC1DEST, got %d\n", retval
);
804 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
808 retval
= SHFileOperationA(&shfo
);
809 ok(retval
== ERROR_INVALID_PARAMETER
, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval
);
813 /* tests the FO_COPY action */
814 static void test_copy(void)
816 SHFILEOPSTRUCTA shfo
, shfo2
;
817 CHAR from
[5*MAX_PATH
];
819 FILEOP_FLAGS tmp_flags
;
827 win_skip("Too many differences for old shell32\n");
832 shfo
.wFunc
= FO_COPY
;
835 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
836 shfo
.hNameMappings
= NULL
;
837 shfo
.lpszProgressTitle
= NULL
;
839 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
840 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
841 retval
= SHFileOperationA(&shfo
);
842 if (dir_exists("test6.txt"))
844 /* Vista and W2K8 (broken or new behavior ?) */
845 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
846 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
847 "are specified as a target\n");
848 DeleteFileA("test6.txt\\test2.txt");
849 RemoveDirectoryA("test6.txt\\test4.txt");
850 RemoveDirectoryA("test6.txt");
854 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
855 ok(!file_exists("test6.txt"), "The file is copied - many files are "
856 "specified as a target\n");
859 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
860 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
862 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
863 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
864 ok(!SHFileOperationA(&shfo2
), "Can't copy many files\n");
865 ok(file_exists("test6.txt"), "The file is not copied - many files are "
866 "specified as a target\n");
867 DeleteFileA("test6.txt");
868 DeleteFileA("test7.txt");
869 RemoveDirectoryA("test8.txt");
871 /* number of sources do not correspond to number of targets */
872 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
873 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
874 retval
= SHFileOperationA(&shfo2
);
875 if (dir_exists("test6.txt"))
877 /* Vista and W2K8 (broken or new behavior ?) */
878 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
879 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
880 "are specified as a target\n");
881 RemoveDirectoryA("test6.txt");
882 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not copied - many files "
883 "are specified as a target\n");
884 RemoveDirectoryA("test7.txt");
888 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
889 ok(!file_exists("test6.txt"), "The file is copied - many files are "
890 "specified as a target\n");
893 set_curr_dir_path(from
, "test1.txt\0");
894 set_curr_dir_path(to
, "test4.txt\0");
895 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are copied recursively\n");
896 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
898 set_curr_dir_path(from
, "test?.txt\0");
899 set_curr_dir_path(to
, "testdir2\0");
900 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
901 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
902 ok(!SHFileOperationA(&shfo
), "Files and directories are copied to directory\n");
903 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
904 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
905 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
906 clean_after_shfo_tests();
909 shfo
.fFlags
|= FOF_FILESONLY
;
910 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
911 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
912 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
913 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
914 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
915 clean_after_shfo_tests();
918 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
919 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
920 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
921 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
922 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
923 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
924 clean_after_shfo_tests();
926 /* Copying multiple files with one not existing as source, fails the
927 entire operation in Win98/ME/2K/XP, but not in 95/NT */
929 tmp_flags
= shfo
.fFlags
;
930 set_curr_dir_path(from
, "test1.txt\0test10.txt\0test2.txt\0");
931 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
932 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
933 retval
= SHFileOperationA(&shfo
);
934 if (retval
== ERROR_SUCCESS
)
935 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
936 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
939 /* Failure if one source file does not exist */
940 ok(retval
== 1026 || /* Win 98/ME/2K/XP */
941 retval
== ERROR_FILE_NOT_FOUND
, /* Vista and W2K8 */
942 "Files are copied to other directory\n");
943 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
945 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
946 shfo
.fFlags
= tmp_flags
;
948 /* copy into a nonexistent directory */
950 shfo
.fFlags
= FOF_NOCONFIRMMKDIR
;
951 set_curr_dir_path(from
, "test1.txt\0");
952 set_curr_dir_path(to
, "nonexistent\\notreal\\test2.txt\0");
953 retval
= SHFileOperation(&shfo
);
954 ok(!retval
, "Error copying into nonexistent directory\n");
955 ok(file_exists("nonexistent"), "nonexistent not created\n");
956 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
957 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
958 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
960 /* a relative dest directory is OK */
961 clean_after_shfo_tests();
963 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
964 shfo
.pTo
= "testdir2\0";
965 retval
= SHFileOperation(&shfo
);
966 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
967 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
969 /* try to overwrite an existing write protected file */
970 clean_after_shfo_tests();
972 tmp_flags
= shfo
.fFlags
;
973 shfo
.pFrom
= "test1.txt\0";
974 shfo
.pTo
= "test2.txt\0";
975 /* suppress the error-dialog in win9x here */
976 shfo
.fFlags
= FOF_NOERRORUI
| FOF_NOCONFIRMATION
| FOF_SILENT
;
977 ret
= SetFileAttributesA(shfo
.pTo
, FILE_ATTRIBUTE_READONLY
);
978 ok(ret
, "Failure to set file attributes (error %x)\n", GetLastError());
979 retval
= CopyFileA(shfo
.pFrom
, shfo
.pTo
, FALSE
);
980 ok(!retval
&& GetLastError() == ERROR_ACCESS_DENIED
, "CopyFileA should have fail with ERROR_ACCESS_DENIED\n");
981 retval
= SHFileOperationA(&shfo
);
982 /* Does not work on Win95, Win95B, NT4WS and NT4SRV */
983 ok(!retval
|| broken(retval
== DE_OPCANCELLED
), "SHFileOperationA failed to copy (error %x)\n", retval
);
984 /* Set back normal attributes to make the file deletion succeed */
985 ret
= SetFileAttributesA(shfo
.pTo
, FILE_ATTRIBUTE_NORMAL
);
986 ok(ret
, "Failure to set file attributes (error %x)\n", GetLastError());
987 shfo
.fFlags
= tmp_flags
;
989 /* try to copy files to a file */
990 clean_after_shfo_tests();
994 /* suppress the error-dialog in win9x here */
995 shfo
.fFlags
|= FOF_NOERRORUI
;
996 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
997 set_curr_dir_path(to
, "test3.txt\0");
998 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
999 retval
= SHFileOperation(&shfo
);
1000 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1001 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1002 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1003 if (retval
== DE_FLDDESTISFILE
|| /* Vista and W2K8 */
1004 retval
== DE_INVALIDFILES
) /* Win7 */
1006 /* Most likely new behavior */
1007 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1011 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1012 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
1014 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
1016 /* try to copy many files to nonexistent directory */
1018 shfo
.fFlags
&= ~FOF_NOERRORUI
;
1019 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1020 retval
= SHFileOperation(&shfo
);
1021 ok(!shfo
.fAnyOperationsAborted
||
1022 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1023 "Didn't expect aborted operations\n");
1024 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1025 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
1026 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
1027 ok(RemoveDirectory(to
), "Expected test3.txt to exist\n");
1029 /* send in FOF_MULTIDESTFILES with too many destination files */
1031 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1032 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1033 shfo
.fFlags
|= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
1034 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1035 retval
= SHFileOperation(&shfo
);
1036 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1037 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1038 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1039 if (dir_exists("testdir2\\a.txt"))
1041 /* Vista and W2K8 (broken or new behavior ?) */
1042 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1043 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1044 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1045 RemoveDirectory("testdir2\\a.txt");
1046 ok(DeleteFile("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
1047 RemoveDirectory("testdir2\\b.txt");
1048 ok(DeleteFile("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
1049 RemoveDirectory("testdir2\\c.txt");
1050 ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
1054 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1055 ok(shfo
.fAnyOperationsAborted
||
1056 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1057 "Expected aborted operations\n");
1058 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
1061 /* send in FOF_MULTIDESTFILES with too many destination files */
1062 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1063 shfo
.pTo
= "e.txt\0f.txt\0";
1064 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1065 retval
= SHFileOperation(&shfo
);
1066 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1067 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1068 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1069 if (dir_exists("e.txt"))
1071 /* Vista and W2K8 (broken or new behavior ?) */
1072 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1073 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1074 ok(DeleteFile("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
1075 RemoveDirectory("e.txt");
1076 ok(DeleteFile("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
1077 RemoveDirectory("f.txt");
1081 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1082 ok(shfo
.fAnyOperationsAborted
||
1083 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1084 "Expected aborted operations\n");
1085 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
1088 /* use FOF_MULTIDESTFILES with files and a source directory */
1089 shfo
.pFrom
= "test1.txt\0test2.txt\0test4.txt\0";
1090 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
1091 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1092 retval
= SHFileOperation(&shfo
);
1093 ok(!shfo
.fAnyOperationsAborted
||
1094 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1095 "Didn't expect aborted operations\n");
1096 ok(retval
== ERROR_SUCCESS
||
1097 broken(retval
== 0x100a1), /* WinMe */
1098 "Expected ERROR_SUCCESS, got %d\n", retval
);
1099 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1100 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
1101 if (retval
== ERROR_SUCCESS
)
1102 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
1104 /* try many dest files without FOF_MULTIDESTFILES flag */
1105 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1106 shfo
.pTo
= "a.txt\0b.txt\0c.txt\0";
1107 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1108 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1109 retval
= SHFileOperation(&shfo
);
1110 ok(shfo
.fAnyOperationsAborted
!= 0xdeadbeef ||
1111 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1112 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1113 if (dir_exists("a.txt"))
1115 /* Vista and W2K8 (broken or new behavior ?) */
1116 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1117 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1118 ok(DeleteFile("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
1119 ok(DeleteFile("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
1120 ok(DeleteFile("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
1121 RemoveDirectory("a.txt");
1126 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1127 ok(shfo
.fAnyOperationsAborted
||
1128 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1129 "Expected aborted operations\n");
1130 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1134 shfo
.pFrom
= "test?.txt\0";
1135 shfo
.pTo
= "testdir2\0";
1136 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1137 retval
= SHFileOperation(&shfo
);
1138 ok(retval
== ERROR_SUCCESS
||
1139 broken(retval
== 0x100a1), /* WinMe */
1140 "Expected ERROR_SUCCESS, got %d\n", retval
);
1141 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1143 /* try a glob with FOF_FILESONLY */
1144 clean_after_shfo_tests();
1146 shfo
.pFrom
= "test?.txt\0";
1147 shfo
.fFlags
|= FOF_FILESONLY
;
1148 retval
= SHFileOperation(&shfo
);
1149 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1150 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1151 ok(!dir_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
1153 /* try a glob with FOF_MULTIDESTFILES and the same number
1154 * of dest files that we would expect
1156 clean_after_shfo_tests();
1158 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1159 shfo
.fFlags
&= ~FOF_FILESONLY
;
1160 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1161 retval
= SHFileOperation(&shfo
);
1162 if (dir_exists("testdir2\\a.txt"))
1164 /* Vista and W2K8 (broken or new behavior ?) */
1165 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1166 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1167 ok(DeleteFile("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
1168 ok(DeleteFile("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
1169 ok(RemoveDirectory("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
1170 RemoveDirectory("testdir2\\a.txt");
1174 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1175 ok(shfo
.fAnyOperationsAborted
||
1176 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1177 "Expected aborted operations\n");
1178 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
1180 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
1182 /* copy one file to two others, second is ignored */
1183 clean_after_shfo_tests();
1185 shfo
.pFrom
= "test1.txt\0";
1186 shfo
.pTo
= "b.txt\0c.txt\0";
1187 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1188 retval
= SHFileOperation(&shfo
);
1189 ok(!shfo
.fAnyOperationsAborted
||
1190 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1191 "Didn't expect aborted operations\n");
1192 if (retval
== DE_OPCANCELLED
)
1194 /* NT4 fails and doesn't copy any files */
1195 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1196 /* Needed to skip some tests */
1197 win_skip("Skipping some tests on NT4\n");
1202 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1203 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1205 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1207 /* copy two file to three others, all fail */
1208 shfo
.pFrom
= "test1.txt\0test2.txt\0";
1209 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1210 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1211 retval
= SHFileOperation(&shfo
);
1212 if (dir_exists("b.txt"))
1214 /* Vista and W2K8 (broken or new behavior ?) */
1215 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1216 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1217 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1218 RemoveDirectory("b.txt");
1219 ok(DeleteFile("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1220 RemoveDirectory("c.txt");
1224 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1225 ok(shfo
.fAnyOperationsAborted
||
1226 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1227 "Expected aborted operations\n");
1228 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1231 /* copy one file and one directory to three others */
1232 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1233 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1234 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1235 retval
= SHFileOperation(&shfo
);
1236 if (dir_exists("b.txt"))
1238 /* Vista and W2K8 (broken or new behavior ?) */
1239 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1240 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1241 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1242 RemoveDirectory("b.txt");
1243 ok(RemoveDirectory("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1244 RemoveDirectory("c.txt");
1248 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1249 ok(shfo
.fAnyOperationsAborted
||
1250 broken(shfo
.fAnyOperationsAborted
== 0xdeadbeef), /* NT4 */
1251 "Expected aborted operations\n");
1252 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1253 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1256 /* copy a directory with a file beneath it, plus some files */
1257 createTestFile("test4.txt\\a.txt");
1258 shfo
.pFrom
= "test4.txt\0test1.txt\0";
1259 shfo
.pTo
= "testdir2\0";
1260 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1261 shfo
.fAnyOperationsAborted
= FALSE
;
1262 retval
= SHFileOperation(&shfo
);
1263 ok(retval
== ERROR_SUCCESS
||
1264 broken(retval
== 0x100a1), /* WinMe */
1265 "Expected ERROR_SUCCESS, got %d\n", retval
);
1266 if (retval
== ERROR_SUCCESS
)
1268 ok(DeleteFile("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1269 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1270 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1273 /* copy one directory and a file in that dir to another dir */
1274 shfo
.pFrom
= "test4.txt\0test4.txt\\a.txt\0";
1275 shfo
.pTo
= "testdir2\0";
1276 retval
= SHFileOperation(&shfo
);
1277 ok(retval
== ERROR_SUCCESS
||
1278 broken(retval
== 0x100a1), /* WinMe */
1279 "Expected ERROR_SUCCESS, got %d\n", retval
);
1280 if (retval
== ERROR_SUCCESS
)
1282 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1283 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1286 /* copy a file in a directory first, and then the directory to a nonexistent dir */
1287 shfo
.pFrom
= "test4.txt\\a.txt\0test4.txt\0";
1288 shfo
.pTo
= "nonexistent\0";
1289 retval
= SHFileOperation(&shfo
);
1290 if (dir_exists("nonexistent"))
1292 /* Vista and W2K8 (broken or new behavior ?) */
1293 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1294 ok(DeleteFile("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1295 RemoveDirectory("nonexistent\\test4.txt");
1296 ok(DeleteFile("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1297 RemoveDirectory("nonexistent");
1301 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1302 ok(shfo
.fAnyOperationsAborted
||
1303 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1304 "Expected aborted operations\n");
1305 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1307 DeleteFile("test4.txt\\a.txt");
1309 /* destination is same as source file */
1310 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1311 shfo
.pTo
= "b.txt\0test2.txt\0c.txt\0";
1312 shfo
.fAnyOperationsAborted
= FALSE
;
1313 shfo
.fFlags
= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
1314 retval
= SHFileOperation(&shfo
);
1315 if (retval
== DE_OPCANCELLED
)
1317 /* NT4 fails and doesn't copy any files */
1318 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1322 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1323 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1325 ok(!shfo
.fAnyOperationsAborted
, "Expected no operations to be aborted\n");
1326 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1328 /* destination is same as source directory */
1329 shfo
.pFrom
= "test1.txt\0test4.txt\0test3.txt\0";
1330 shfo
.pTo
= "b.txt\0test4.txt\0c.txt\0";
1331 shfo
.fAnyOperationsAborted
= FALSE
;
1332 retval
= SHFileOperation(&shfo
);
1333 if (retval
== DE_OPCANCELLED
)
1335 /* NT4 fails and doesn't copy any files */
1336 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1340 ok(retval
== ERROR_SUCCESS
||
1341 retval
== DE_DESTSAMETREE
, /* Vista */
1342 "Expected ERROR_SUCCESS or DE_DESTSAMETREE, got %d\n", retval
);
1343 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1345 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1347 /* copy a directory into itself, error displayed in UI */
1348 shfo
.pFrom
= "test4.txt\0";
1349 shfo
.pTo
= "test4.txt\\newdir\0";
1350 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1351 shfo
.fAnyOperationsAborted
= FALSE
;
1352 retval
= SHFileOperation(&shfo
);
1353 ok(retval
== ERROR_SUCCESS
||
1354 retval
== DE_DESTSUBTREE
, /* Vista */
1355 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1356 ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1358 /* copy a directory to itself, error displayed in UI */
1359 shfo
.pFrom
= "test4.txt\0";
1360 shfo
.pTo
= "test4.txt\0";
1361 shfo
.fAnyOperationsAborted
= FALSE
;
1362 retval
= SHFileOperation(&shfo
);
1363 ok(retval
== ERROR_SUCCESS
||
1364 retval
== DE_DESTSUBTREE
, /* Vista */
1365 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1367 /* copy a file into a directory, and the directory into itself */
1368 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1369 shfo
.pTo
= "test4.txt\0";
1370 shfo
.fAnyOperationsAborted
= FALSE
;
1371 shfo
.fFlags
|= FOF_NOCONFIRMATION
;
1372 retval
= SHFileOperation(&shfo
);
1373 ok(retval
== ERROR_SUCCESS
||
1374 retval
== DE_DESTSUBTREE
, /* Vista */
1375 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1376 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1378 /* copy a file to a file, and the directory into itself */
1379 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1380 shfo
.pTo
= "test4.txt\\a.txt\0";
1381 shfo
.fAnyOperationsAborted
= FALSE
;
1382 retval
= SHFileOperation(&shfo
);
1383 if (dir_exists("test4.txt\\a.txt"))
1385 /* Vista and W2K8 (broken or new behavior ?) */
1386 ok(retval
== DE_DESTSUBTREE
, "Expected DE_DESTSUBTREE, got %d\n", retval
);
1387 ok(DeleteFile("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1388 RemoveDirectory("test4.txt\\a.txt");
1392 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1393 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1396 /* copy a nonexistent file to a nonexistent directory */
1397 shfo
.pFrom
= "e.txt\0";
1398 shfo
.pTo
= "nonexistent\0";
1399 shfo
.fAnyOperationsAborted
= FALSE
;
1400 retval
= SHFileOperation(&shfo
);
1401 ok(retval
== 1026 ||
1402 retval
== ERROR_FILE_NOT_FOUND
|| /* Vista */
1403 broken(retval
== ERROR_SUCCESS
), /* NT4 */
1404 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval
);
1405 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1406 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1408 /* Overwrite tests */
1409 clean_after_shfo_tests();
1413 /* NT4 would throw up some dialog boxes and doesn't copy files that are needed
1414 * in subsequent tests.
1416 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1417 shfo
.pFrom
= "test1.txt\0";
1418 shfo
.pTo
= "test2.txt\0";
1419 shfo
.fAnyOperationsAborted
= 0xdeadbeef;
1420 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1421 retval
= SHFileOperation(&shfo
);
1422 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1423 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
1424 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1426 shfo
.pFrom
= "test3.txt\0test1.txt\0";
1427 shfo
.pTo
= "test2.txt\0one.txt\0";
1428 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_MULTIDESTFILES
;
1429 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1430 retval
= SHFileOperation(&shfo
);
1431 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1432 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1434 shfo
.pFrom
= "one.txt\0";
1435 shfo
.pTo
= "testdir2\0";
1436 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1437 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1438 retval
= SHFileOperation(&shfo
);
1439 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1440 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1443 createTestFile("test4.txt\\test1.txt");
1444 shfo
.pFrom
= "test4.txt\0";
1445 shfo
.pTo
= "testdir2\0";
1446 /* WinMe needs FOF_NOERRORUI */
1447 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_NOERRORUI
;
1448 retval
= SHFileOperation(&shfo
);
1449 ok(retval
== ERROR_SUCCESS
||
1450 broken(retval
== 0x100a1), /* WinMe */
1451 "Expected ERROR_SUCCESS, got %d\n", retval
);
1452 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1455 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1456 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1457 retval
= SHFileOperation(&shfo
);
1458 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1459 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1462 createTestFile("one.txt");
1464 /* pFrom contains bogus 2nd name longer than MAX_PATH */
1465 memset(from
, 'a', MAX_PATH
*2);
1466 memset(from
+MAX_PATH
*2, 0, 2);
1467 lstrcpyA(from
, "one.txt");
1469 shfo
.pTo
= "two.txt\0";
1470 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1471 retval
= SHFileOperation(&shfo
);
1472 ok(retval
== 1148 || retval
== 1026 ||
1473 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1474 retval
== DE_INVALIDFILES
, /* Vista */
1475 "Unexpected return value, got %d\n", retval
);
1476 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1477 if (dir_exists("two.txt"))
1478 /* Vista and W2K8 (broken or new behavior ?) */
1479 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1481 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1483 createTestFile("one.txt");
1485 /* pTo contains bogus 2nd name longer than MAX_PATH */
1486 memset(to
, 'a', MAX_PATH
*2);
1487 memset(to
+MAX_PATH
*2, 0, 2);
1488 lstrcpyA(to
, "two.txt");
1489 shfo
.pFrom
= "one.txt\0";
1491 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1492 retval
= SHFileOperation(&shfo
);
1493 if (retval
== DE_OPCANCELLED
)
1495 /* NT4 fails and doesn't copy any files */
1496 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1500 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1501 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1503 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1505 createTestFile("one.txt");
1507 /* no FOF_MULTIDESTFILES, two files in pTo */
1508 shfo
.pFrom
= "one.txt\0";
1509 shfo
.pTo
= "two.txt\0three.txt\0";
1510 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1511 retval
= SHFileOperation(&shfo
);
1512 if (retval
== DE_OPCANCELLED
)
1514 /* NT4 fails and doesn't copy any files */
1515 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1519 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1520 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1522 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1524 createTestFile("one.txt");
1526 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1527 memset(from
, 'a', MAX_PATH
*2);
1528 memset(from
+MAX_PATH
*2, 0, 2);
1529 memset(to
, 'a', MAX_PATH
*2);
1530 memset(to
+MAX_PATH
*2, 0, 2);
1531 lstrcpyA(from
, "one.txt");
1532 lstrcpyA(to
, "two.txt");
1535 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1536 retval
= SHFileOperation(&shfo
);
1537 ok(retval
== 1148 || retval
== 1026 ||
1538 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1539 retval
== DE_INVALIDFILES
, /* Vista */
1540 "Unexpected return value, got %d\n", retval
);
1541 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1542 if (dir_exists("two.txt"))
1543 /* Vista and W2K8 (broken or new behavior ?) */
1544 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1546 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1548 createTestFile("one.txt");
1550 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1551 memset(to
, 'a', MAX_PATH
*2);
1552 memset(to
+MAX_PATH
*2, 0, 2);
1553 lstrcpyA(to
, "two.txt");
1554 shfo
.pFrom
= "one.txt\0";
1556 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1557 FOF_SILENT
| FOF_NOERRORUI
;
1558 retval
= SHFileOperation(&shfo
);
1559 if (retval
== DE_OPCANCELLED
)
1561 /* NT4 fails and doesn't copy any files */
1562 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1566 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1567 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1569 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1571 createTestFile("one.txt");
1572 createTestFile("two.txt");
1574 /* pTo contains bogus 2nd name longer than MAX_PATH,
1575 * multiple source files,
1576 * dest directory does not exist
1578 memset(to
, 'a', 2 * MAX_PATH
);
1579 memset(to
+MAX_PATH
*2, 0, 2);
1580 lstrcpyA(to
, "threedir");
1581 shfo
.pFrom
= "one.txt\0two.txt\0";
1583 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1584 retval
= SHFileOperation(&shfo
);
1585 if (dir_exists("threedir"))
1587 /* Vista and W2K8 (broken or new behavior ?) */
1588 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1589 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1590 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1591 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1595 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1596 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1597 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1598 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1599 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1601 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1602 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1604 createTestFile("one.txt");
1605 createTestFile("two.txt");
1606 CreateDirectoryA("threedir", NULL
);
1608 /* pTo contains bogus 2nd name longer than MAX_PATH,
1609 * multiple source files,
1610 * dest directory does exist
1612 memset(to
, 'a', 2 * MAX_PATH
);
1613 memset(to
+MAX_PATH
*2, 0, 2);
1614 lstrcpyA(to
, "threedir");
1615 shfo
.pFrom
= "one.txt\0two.txt\0";
1617 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1618 retval
= SHFileOperation(&shfo
);
1619 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1620 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1621 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1622 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1623 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1624 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1627 /* this crashes on win9x */
1628 createTestFile("one.txt");
1629 createTestFile("two.txt");
1631 /* pTo contains bogus 2nd name longer than MAX_PATH,
1632 * multiple source files, FOF_MULTIDESTFILES
1633 * dest dir does not exist
1636 memset(to
, 'a', 2 * MAX_PATH
);
1637 memset(to
+MAX_PATH
*2, 0, 2);
1638 lstrcpyA(to
, "threedir");
1639 shfo
.pFrom
= "one.txt\0two.txt\0";
1641 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1642 FOF_SILENT
| FOF_NOERRORUI
;
1643 retval
= SHFileOperation(&shfo
);
1644 ok(retval
== ERROR_CANCELLED
||
1645 retval
== ERROR_SUCCESS
, /* win2k3 */
1646 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval
);
1647 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1648 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1649 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1650 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1651 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1653 /* file exists in win2k */
1654 DeleteFileA("threedir");
1658 createTestFile("one.txt");
1659 createTestFile("two.txt");
1660 CreateDirectoryA("threedir", NULL
);
1662 /* pTo contains bogus 2nd name longer than MAX_PATH,
1663 * multiple source files, FOF_MULTIDESTFILES
1664 * dest dir does exist
1666 memset(to
, 'a', 2 * MAX_PATH
);
1667 memset(to
+MAX_PATH
*2, 0, 2);
1668 lstrcpyA(to
, "threedir");
1669 ptr
= to
+ lstrlenA(to
) + 1;
1670 lstrcpyA(ptr
, "fourdir");
1671 shfo
.pFrom
= "one.txt\0two.txt\0";
1673 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1674 FOF_SILENT
| FOF_NOERRORUI
;
1675 retval
= SHFileOperation(&shfo
);
1676 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1677 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1678 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1679 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1680 if (dir_exists("fourdir"))
1682 /* Vista and W2K8 (broken or new behavior ?) */
1683 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1684 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1685 RemoveDirectoryA("fourdir");
1689 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1690 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1691 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1693 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1695 createTestFile("one.txt");
1696 createTestFile("two.txt");
1697 CreateDirectoryA("threedir", NULL
);
1699 /* multiple source files, FOF_MULTIDESTFILES
1700 * multiple dest files, but first dest dir exists
1701 * num files in lists is equal
1703 shfo
.pFrom
= "one.txt\0two.txt\0";
1704 shfo
.pTo
= "threedir\0fourdir\0";
1705 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1706 FOF_SILENT
| FOF_NOERRORUI
;
1707 retval
= SHFileOperation(&shfo
);
1708 ok(retval
== ERROR_CANCELLED
||
1709 retval
== DE_FILEDESTISFLD
|| /* Vista */
1710 broken(retval
== DE_OPCANCELLED
), /* Win9x, NT4 */
1711 "Expected ERROR_CANCELLED or DE_FILEDESTISFLD. got %d\n", retval
);
1712 if (file_exists("threedir\\threedir"))
1715 ok(DeleteFileA("threedir\\threedir"), "Expected file to exist\n");
1717 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1718 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1719 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1720 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1721 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1722 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1723 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not 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 not equal
1733 shfo
.pFrom
= "one.txt\0two.txt\0";
1734 shfo
.pTo
= "threedir\0fourdir\0five\0";
1735 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1736 FOF_SILENT
| FOF_NOERRORUI
;
1737 retval
= SHFileOperation(&shfo
);
1738 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1739 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1740 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1741 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1742 if (dir_exists("fourdir"))
1744 /* Vista and W2K8 (broken or new behavior ?) */
1745 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1746 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1747 RemoveDirectoryA("fourdir");
1751 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1752 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1753 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1755 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1756 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1757 ok(!RemoveDirectoryA("five"), "Expected dir to not exist\n");
1759 createTestFile("aa.txt");
1760 createTestFile("ab.txt");
1761 CreateDirectoryA("one", NULL
);
1762 CreateDirectoryA("two", NULL
);
1764 /* pFrom has a glob, pTo has more than one dest */
1765 shfo
.pFrom
= "a*.txt\0";
1766 shfo
.pTo
= "one\0two\0";
1767 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1768 retval
= SHFileOperation(&shfo
);
1769 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1770 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1771 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1772 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1773 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1774 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1775 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1776 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1777 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1779 /* pTo is an empty string */
1780 CreateDirectoryA("dir", NULL
);
1781 createTestFile("dir\\abcdefgh.abc");
1782 shfo
.pFrom
= "dir\\abcdefgh.abc\0";
1784 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1785 retval
= SHFileOperation(&shfo
);
1786 ok(retval
== ERROR_SUCCESS
||
1787 broken(retval
== DE_OPCANCELLED
), /* NT4 */
1788 "Expected ERROR_SUCCESS, got %d\n", retval
);
1789 if (retval
== ERROR_SUCCESS
)
1790 ok(DeleteFileA("abcdefgh.abc"), "Expected file to exist\n");
1791 ok(DeleteFileA("dir\\abcdefgh.abc"), "Expected file to exist\n");
1792 ok(RemoveDirectoryA("dir"), "Expected dir to exist\n");
1795 /* tests the FO_MOVE action */
1796 static void test_move(void)
1798 SHFILEOPSTRUCTA shfo
, shfo2
;
1799 CHAR from
[5*MAX_PATH
];
1800 CHAR to
[5*MAX_PATH
];
1804 shfo
.wFunc
= FO_MOVE
;
1807 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1808 shfo
.hNameMappings
= NULL
;
1809 shfo
.lpszProgressTitle
= NULL
;
1811 set_curr_dir_path(from
, "test1.txt\0");
1812 set_curr_dir_path(to
, "test4.txt\0");
1813 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are moved recursively\n");
1814 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1815 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1817 set_curr_dir_path(from
, "test?.txt\0");
1818 set_curr_dir_path(to
, "testdir2\0");
1819 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1820 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1821 ok(!SHFileOperationA(&shfo
), "Files and directories are moved to directory\n");
1822 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1823 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1824 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1826 clean_after_shfo_tests();
1829 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
1830 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
1832 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1833 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1835 shfo2
.fFlags
|= FOF_NOCONFIRMMKDIR
;
1836 ok(!SHFileOperationA(&shfo2
), "Move many files\n");
1837 ok(DeleteFileA("test6.txt"), "The file is not moved - many files are "
1838 "specified as a target\n");
1839 ok(DeleteFileA("test7.txt"), "The file is not moved\n");
1840 ok(RemoveDirectoryA("test8.txt"), "The directory is not moved\n");
1844 /* number of sources do not correspond to number of targets */
1845 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1846 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1847 retval
= SHFileOperationA(&shfo2
);
1848 if (dir_exists("test6.txt"))
1850 if (retval
== ERROR_SUCCESS
)
1853 DeleteFileA("test6.txt\\test1.txt");
1854 DeleteFileA("test6.txt\\test2.txt");
1855 RemoveDirectoryA("test6.txt\\test4.txt");
1856 RemoveDirectoryA("test6.txt");
1860 /* Vista and W2K8 (broken or new behavior ?) */
1861 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
1862 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1863 RemoveDirectoryA("test6.txt");
1864 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1865 RemoveDirectoryA("test7.txt");
1870 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1871 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1872 "specified as a target\n");
1877 set_curr_dir_path(from
, "test3.txt\0");
1878 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
1879 ok(!SHFileOperationA(&shfo
), "Can't move file to other directory\n");
1880 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1882 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1883 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1885 shfo
.fFlags
|= FOF_NOCONFIRMMKDIR
;
1886 retval
= SHFileOperationA(&shfo
);
1887 if (dir_exists("test6.txt"))
1890 /* Vista and W2K8 (broken or new behavior ?) */
1891 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1892 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1893 ok(DeleteFileA("test6.txt\\test2.txt"), "The file is not moved. Many files are specified\n");
1894 ok(DeleteFileA("test6.txt\\test4.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1895 ok(RemoveDirectoryA("test6.txt\\test4.txt"), "The directory is not moved. Many files are specified\n");
1896 RemoveDirectoryA("test6.txt");
1901 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1902 ok(file_exists("test1.txt"), "The file is moved. Many files are specified\n");
1903 ok(dir_exists("test4.txt"), "The directory is moved. Many files are specified\n");
1906 set_curr_dir_path(from
, "test1.txt\0");
1907 set_curr_dir_path(to
, "test6.txt\0");
1908 ok(!SHFileOperationA(&shfo
), "Move file failed\n");
1909 ok(!file_exists("test1.txt"), "The file is not moved\n");
1910 ok(file_exists("test6.txt"), "The file is not moved\n");
1911 set_curr_dir_path(from
, "test6.txt\0");
1912 set_curr_dir_path(to
, "test1.txt\0");
1913 ok(!SHFileOperationA(&shfo
), "Move file back failed\n");
1915 set_curr_dir_path(from
, "test4.txt\0");
1916 set_curr_dir_path(to
, "test6.txt\0");
1917 ok(!SHFileOperationA(&shfo
), "Move dir failed\n");
1918 ok(!dir_exists("test4.txt"), "The dir is not moved\n");
1919 ok(dir_exists("test6.txt"), "The dir is moved\n");
1920 set_curr_dir_path(from
, "test6.txt\0");
1921 set_curr_dir_path(to
, "test4.txt\0");
1922 ok(!SHFileOperationA(&shfo
), "Move dir back failed\n");
1924 /* move one file to two others */
1926 shfo
.pFrom
= "test1.txt\0";
1927 shfo
.pTo
= "a.txt\0b.txt\0";
1928 retval
= SHFileOperationA(&shfo
);
1929 if (retval
== DE_OPCANCELLED
)
1931 /* NT4 fails and doesn't move any files */
1932 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1933 DeleteFileA("test1.txt");
1937 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1940 DeleteFile("a.txt\\a.txt");
1941 RemoveDirectoryA("a.txt");
1944 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1945 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1947 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1949 /* move two files to one other */
1950 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1951 shfo
.pTo
= "test1.txt\0";
1952 retval
= SHFileOperationA(&shfo
);
1953 if (dir_exists("test1.txt"))
1956 /* Vista and W2K8 (broken or new behavior ?) */
1957 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1958 ok(DeleteFileA("test1.txt\\test2.txt"), "Expected test1.txt\\test2.txt to exist\n");
1959 ok(DeleteFileA("test1.txt\\test3.txt"), "Expected test1.txt\\test3.txt to exist\n");
1960 RemoveDirectoryA("test1.txt");
1961 createTestFile("test2.txt");
1962 createTestFile("test3.txt");
1966 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1967 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1968 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1969 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1972 /* move a directory into itself */
1973 shfo
.pFrom
= "test4.txt\0";
1974 shfo
.pTo
= "test4.txt\\b.txt\0";
1975 retval
= SHFileOperationA(&shfo
);
1976 ok(retval
== ERROR_SUCCESS
||
1977 retval
== DE_DESTSUBTREE
, /* Vista */
1978 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1979 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1980 ok(dir_exists("test4.txt"), "Expected test4.txt to exist\n");
1982 /* move many files without FOF_MULTIDESTFILES */
1983 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1984 shfo
.pTo
= "d.txt\0e.txt\0";
1985 retval
= SHFileOperationA(&shfo
);
1986 if (dir_exists("d.txt"))
1989 /* Vista and W2K8 (broken or new behavior ?) */
1990 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1991 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1992 ok(DeleteFileA("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to exist\n");
1993 RemoveDirectoryA("d.txt");
1994 createTestFile("test2.txt");
1995 createTestFile("test3.txt");
1999 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2000 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
2001 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
2004 /* number of sources != number of targets */
2005 shfo
.pTo
= "d.txt\0";
2006 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
2007 retval
= SHFileOperationA(&shfo
);
2008 if (dir_exists("d.txt"))
2012 DeleteFileA("d.txt\\test2.txt");
2013 DeleteFileA("d.txt\\test3.txt");
2014 RemoveDirectoryA("d.txt");
2015 createTestFile("test2.txt");
2019 /* Vista and W2K8 (broken or new behavior ?) */
2020 ok(retval
== DE_SAMEFILE
,
2021 "Expected DE_SAMEFILE, got %d\n", retval
);
2022 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
2023 ok(!file_exists("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to not exist\n");
2024 RemoveDirectoryA("d.txt");
2025 createTestFile("test2.txt");
2030 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2031 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
2034 /* FO_MOVE does not create dest directories */
2035 shfo
.pFrom
= "test2.txt\0";
2036 shfo
.pTo
= "dir1\\dir2\\test2.txt\0";
2037 retval
= SHFileOperationA(&shfo
);
2038 if (dir_exists("dir1"))
2040 /* Vista and W2K8 (broken or new behavior ?) */
2041 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2042 ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n");
2043 RemoveDirectoryA("dir1\\dir2");
2044 RemoveDirectoryA("dir1");
2045 createTestFile("test2.txt");
2049 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
2052 /* try to overwrite an existing file */
2053 shfo
.pTo
= "test3.txt\0";
2054 retval
= SHFileOperationA(&shfo
);
2055 if (retval
== DE_OPCANCELLED
)
2057 /* NT4 fails and doesn't move any files */
2058 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
2062 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2063 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
2066 DeleteFileA("test3.txt\\test3.txt");
2067 RemoveDirectoryA("test3.txt");
2070 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2074 static void test_sh_create_dir(void)
2076 CHAR path
[MAX_PATH
];
2079 if(!pSHCreateDirectoryExA
)
2081 win_skip("skipping SHCreateDirectoryExA tests\n");
2085 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2086 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
2087 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret
);
2088 ok(file_exists("testdir2"), "The first directory is not created\n");
2089 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
2091 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
2092 ok(ERROR_ALREADY_EXISTS
== ret
, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret
);
2094 ret
= pSHCreateDirectoryExA(NULL
, "c:\\testdir3", NULL
);
2095 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory, ret = %d\n", ret
);
2096 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
2099 static void test_sh_path_prepare(void)
2102 CHAR path
[MAX_PATH
];
2103 CHAR UNICODE_PATH_A
[MAX_PATH
];
2104 BOOL UsedDefaultChar
;
2106 if(!pSHPathPrepareForWriteA
)
2108 win_skip("skipping SHPathPrepareForWriteA tests\n");
2112 /* directory exists, SHPPFW_NONE */
2113 set_curr_dir_path(path
, "testdir2\0");
2114 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2115 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2117 /* directory exists, SHPPFW_IGNOREFILENAME */
2118 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2119 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
2120 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2122 /* directory exists, SHPPFW_DIRCREATE */
2123 set_curr_dir_path(path
, "testdir2\0");
2124 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2125 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2127 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2128 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2129 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
2130 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2131 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2133 /* file exists, SHPPFW_NONE */
2134 set_curr_dir_path(path
, "test1.txt\0");
2135 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2136 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2137 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2138 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2139 "Unexpected result : 0x%08x\n", res
);
2141 /* file exists, SHPPFW_DIRCREATE */
2142 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2143 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2144 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2145 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2146 "Unexpected result : 0x%08x\n", res
);
2148 /* file exists, SHPPFW_NONE, trailing \ */
2149 set_curr_dir_path(path
, "test1.txt\\\0");
2150 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2151 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2152 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2153 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2154 "Unexpected result : 0x%08x\n", res
);
2156 /* relative path exists, SHPPFW_DIRCREATE */
2157 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE
);
2158 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2160 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
2161 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE
);
2162 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2163 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
2165 /* directory doesn't exist, SHPPFW_NONE */
2166 set_curr_dir_path(path
, "nonexistent\0");
2167 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2168 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2170 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
2171 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2172 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
2173 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2174 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
2175 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2177 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2178 set_curr_dir_path(path
, "testdir2\\test4.txt\\\0");
2179 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
2180 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2181 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
2183 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
2184 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2185 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2186 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2187 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
2189 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
2191 if(!pSHPathPrepareForWriteW
)
2193 win_skip("Skipping SHPathPrepareForWriteW tests\n");
2197 SetLastError(0xdeadbeef);
2198 UsedDefaultChar
= FALSE
;
2199 if (WideCharToMultiByte(CP_ACP
, WC_NO_BEST_FIT_CHARS
, UNICODE_PATH
, -1, UNICODE_PATH_A
, sizeof(UNICODE_PATH_A
), NULL
, &UsedDefaultChar
) == 0)
2201 win_skip("Could not convert Unicode path name to multibyte (%d)\n", GetLastError());
2204 if (UsedDefaultChar
)
2206 win_skip("Could not find unique multibyte representation for directory name using default codepage\n");
2210 /* unicode directory doesn't exist, SHPPFW_NONE */
2211 RemoveDirectoryA(UNICODE_PATH_A
);
2212 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2213 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2214 ok(!file_exists(UNICODE_PATH_A
), "unicode path was created but shouldn't be\n");
2215 RemoveDirectoryA(UNICODE_PATH_A
);
2217 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
2218 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2219 ok(res
== S_OK
, "res == %08x, expected S_OK\n", res
);
2220 ok(file_exists(UNICODE_PATH_A
), "unicode path should've been created\n");
2222 /* unicode directory exists, SHPPFW_NONE */
2223 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2224 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2226 /* unicode directory exists, SHPPFW_DIRCREATE */
2227 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2228 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2229 RemoveDirectoryA(UNICODE_PATH_A
);
2232 static void test_sh_new_link_info(void)
2234 BOOL ret
, mustcopy
=TRUE
;
2235 CHAR linkto
[MAX_PATH
];
2236 CHAR destdir
[MAX_PATH
];
2237 CHAR result
[MAX_PATH
];
2238 CHAR result2
[MAX_PATH
];
2240 /* source file does not exist */
2241 set_curr_dir_path(linkto
, "nosuchfile.txt\0");
2242 set_curr_dir_path(destdir
, "testdir2\0");
2243 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2245 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2246 "SHGetNewLinkInfoA succeeded\n");
2247 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2249 /* dest dir does not exist */
2250 set_curr_dir_path(linkto
, "test1.txt\0");
2251 set_curr_dir_path(destdir
, "nosuchdir\0");
2252 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2254 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2255 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2256 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2258 /* source file exists */
2259 set_curr_dir_path(linkto
, "test1.txt\0");
2260 set_curr_dir_path(destdir
, "testdir2\0");
2261 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2263 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2264 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2265 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2266 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, destdir
,
2267 lstrlenA(destdir
), result
, lstrlenA(destdir
)) == CSTR_EQUAL
,
2268 "%s does not start with %s\n", result
, destdir
);
2269 ok(lstrlenA(result
) > 4 && lstrcmpiA(result
+lstrlenA(result
)-4, ".lnk") == 0,
2270 "%s does not end with .lnk\n", result
);
2272 /* preferred target name already exists */
2273 createTestFile(result
);
2274 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result2
, &mustcopy
, 0);
2276 broken(ret
== lstrlenA(result2
) + 1), /* NT4 */
2277 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2278 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2279 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, destdir
,
2280 lstrlenA(destdir
), result2
, lstrlenA(destdir
)) == CSTR_EQUAL
,
2281 "%s does not start with %s\n", result2
, destdir
);
2282 ok(lstrlenA(result2
) > 4 && lstrcmpiA(result2
+lstrlenA(result2
)-4, ".lnk") == 0,
2283 "%s does not end with .lnk\n", result2
);
2284 ok(lstrcmpiA(result
, result2
) != 0, "%s and %s are the same\n", result
, result2
);
2285 DeleteFileA(result
);
2288 static void test_unicode(void)
2290 SHFILEOPSTRUCTW shfoW
;
2294 if (!pSHFileOperationW
)
2296 skip("SHFileOperationW() is missing\n");
2301 shfoW
.wFunc
= FO_DELETE
;
2302 shfoW
.pFrom
= UNICODE_PATH
;
2304 shfoW
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
2305 shfoW
.hNameMappings
= NULL
;
2306 shfoW
.lpszProgressTitle
= NULL
;
2308 /* Clean up before start test */
2309 DeleteFileW(UNICODE_PATH
);
2310 RemoveDirectoryW(UNICODE_PATH
);
2312 /* Make sure we are on a system that supports unicode */
2313 SetLastError(0xdeadbeef);
2314 file
= CreateFileW(UNICODE_PATH
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
2315 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
2317 skip("Unicode tests skipped on non-unicode system\n");
2322 /* Try to delete a file with unicode filename */
2323 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2324 ret
= pSHFileOperationW(&shfoW
);
2325 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2326 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2328 /* Try to trash a file with unicode filename */
2329 createTestFileW(UNICODE_PATH
);
2330 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2331 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2332 ret
= pSHFileOperationW(&shfoW
);
2333 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2334 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2336 if(!pSHCreateDirectoryExW
)
2338 skip("Skipping SHCreateDirectoryExW tests\n");
2342 /* Try to delete a directory with unicode filename */
2343 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2344 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2345 ok(file_existsW(UNICODE_PATH
), "The directory is not created\n");
2346 shfoW
.fFlags
&= ~FOF_ALLOWUNDO
;
2347 ret
= pSHFileOperationW(&shfoW
);
2348 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2349 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2351 /* Try to trash a directory with unicode filename */
2352 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2353 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2354 ok(file_existsW(UNICODE_PATH
), "The directory was not created\n");
2355 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2356 ret
= pSHFileOperationW(&shfoW
);
2357 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2358 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2362 test_shlmenu(void) {
2364 hres
= Shell_MergeMenus (0, 0, 0x42, 0x4242, 0x424242, 0);
2365 ok (hres
== 0x4242, "expected 0x4242 but got %x\n", hres
);
2366 hres
= Shell_MergeMenus ((HMENU
)42, 0, 0x42, 0x4242, 0x424242, 0);
2367 ok (hres
== 0x4242, "expected 0x4242 but got %x\n", hres
);
2370 /* Check for old shell32 (4.0.x) */
2371 static BOOL
is_old_shell32(void)
2373 SHFILEOPSTRUCTA shfo
;
2374 CHAR from
[5*MAX_PATH
];
2375 CHAR to
[5*MAX_PATH
];
2379 shfo
.wFunc
= FO_COPY
;
2382 /* FOF_NOCONFIRMMKDIR is needed for old shell32 */
2383 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
| FOF_MULTIDESTFILES
| FOF_NOCONFIRMMKDIR
;
2384 shfo
.hNameMappings
= NULL
;
2385 shfo
.lpszProgressTitle
= NULL
;
2387 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test3.txt\0");
2388 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
2389 retval
= SHFileOperationA(&shfo
);
2391 /* Delete extra files on old shell32 and Vista+*/
2392 DeleteFileA("test6.txt\\test1.txt");
2393 /* Delete extra files on old shell32 */
2394 DeleteFileA("test6.txt\\test2.txt");
2395 DeleteFileA("test6.txt\\test3.txt");
2396 /* Delete extra directory on old shell32 and Vista+ */
2397 RemoveDirectoryA("test6.txt");
2398 /* Delete extra files/directories on Vista+*/
2399 DeleteFileA("test7.txt\\test2.txt");
2400 RemoveDirectoryA("test7.txt");
2402 if (retval
== ERROR_SUCCESS
)
2408 START_TEST(shlfileop
)
2410 InitFunctionPointers();
2412 clean_after_shfo_tests();
2415 old_shell32
= is_old_shell32();
2417 win_skip("Need to cater for old shell32 (4.0.x) on Win95\n");
2418 clean_after_shfo_tests();
2421 test_get_file_info();
2422 test_get_file_info_iconlist();
2423 clean_after_shfo_tests();
2427 clean_after_shfo_tests();
2431 clean_after_shfo_tests();
2435 clean_after_shfo_tests();
2439 clean_after_shfo_tests();
2441 test_sh_create_dir();
2442 clean_after_shfo_tests();
2445 test_sh_path_prepare();
2446 clean_after_shfo_tests();
2449 test_sh_new_link_info();
2450 clean_after_shfo_tests();