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
;
826 win_skip("Too many differences for old shell32\n");
831 shfo
.wFunc
= FO_COPY
;
834 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
835 shfo
.hNameMappings
= NULL
;
836 shfo
.lpszProgressTitle
= NULL
;
838 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
839 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
840 retval
= SHFileOperationA(&shfo
);
841 if (dir_exists("test6.txt"))
843 /* Vista and W2K8 (broken or new behavior ?) */
844 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
845 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
846 "are specified as a target\n");
847 DeleteFileA("test6.txt\\test2.txt");
848 RemoveDirectoryA("test6.txt\\test4.txt");
849 RemoveDirectoryA("test6.txt");
853 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
854 ok(!file_exists("test6.txt"), "The file is copied - many files are "
855 "specified as a target\n");
858 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
859 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
861 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
862 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
863 ok(!SHFileOperationA(&shfo2
), "Can't copy many files\n");
864 ok(file_exists("test6.txt"), "The file is not copied - many files are "
865 "specified as a target\n");
866 DeleteFileA("test6.txt");
867 DeleteFileA("test7.txt");
868 RemoveDirectoryA("test8.txt");
870 /* number of sources do not correspond to number of targets */
871 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
872 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
873 retval
= SHFileOperationA(&shfo2
);
874 if (dir_exists("test6.txt"))
876 /* Vista and W2K8 (broken or new behavior ?) */
877 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
878 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
879 "are specified as a target\n");
880 RemoveDirectoryA("test6.txt");
881 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not copied - many files "
882 "are specified as a target\n");
883 RemoveDirectoryA("test7.txt");
887 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
888 ok(!file_exists("test6.txt"), "The file is copied - many files are "
889 "specified as a target\n");
892 set_curr_dir_path(from
, "test1.txt\0");
893 set_curr_dir_path(to
, "test4.txt\0");
894 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are copied recursively\n");
895 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
897 set_curr_dir_path(from
, "test?.txt\0");
898 set_curr_dir_path(to
, "testdir2\0");
899 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
900 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
901 ok(!SHFileOperationA(&shfo
), "Files and directories are copied to directory\n");
902 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
903 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
904 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
905 clean_after_shfo_tests();
908 shfo
.fFlags
|= FOF_FILESONLY
;
909 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
910 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
911 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
912 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
913 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
914 clean_after_shfo_tests();
917 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
918 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
919 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
920 ok(!SHFileOperationA(&shfo
), "Files are copied to other directory\n");
921 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
922 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
923 clean_after_shfo_tests();
925 /* Copying multiple files with one not existing as source, fails the
926 entire operation in Win98/ME/2K/XP, but not in 95/NT */
928 tmp_flags
= shfo
.fFlags
;
929 set_curr_dir_path(from
, "test1.txt\0test10.txt\0test2.txt\0");
930 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
931 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
932 retval
= SHFileOperationA(&shfo
);
933 if (retval
== ERROR_SUCCESS
)
934 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
935 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
938 /* Failure if one source file does not exist */
939 ok(retval
== 1026 || /* Win 98/ME/2K/XP */
940 retval
== ERROR_FILE_NOT_FOUND
, /* Vista and W2K8 */
941 "Files are copied to other directory\n");
942 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
944 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
945 shfo
.fFlags
= tmp_flags
;
947 /* copy into a nonexistent directory */
949 shfo
.fFlags
= FOF_NOCONFIRMMKDIR
;
950 set_curr_dir_path(from
, "test1.txt\0");
951 set_curr_dir_path(to
, "nonexistent\\notreal\\test2.txt\0");
952 retval
= SHFileOperation(&shfo
);
953 ok(!retval
, "Error copying into nonexistent directory\n");
954 ok(file_exists("nonexistent"), "nonexistent not created\n");
955 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
956 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
957 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
959 /* a relative dest directory is OK */
960 clean_after_shfo_tests();
962 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
963 shfo
.pTo
= "testdir2\0";
964 retval
= SHFileOperation(&shfo
);
965 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
966 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
968 /* try to copy files to a file */
969 clean_after_shfo_tests();
973 /* suppress the error-dialog in win9x here */
974 shfo
.fFlags
|= FOF_NOERRORUI
;
975 set_curr_dir_path(from
, "test1.txt\0test2.txt\0");
976 set_curr_dir_path(to
, "test3.txt\0");
977 retval
= SHFileOperation(&shfo
);
978 if (retval
== DE_FLDDESTISFILE
|| /* Vista and W2K8 */
979 retval
== DE_INVALIDFILES
) /* Win7 */
981 /* Most likely new behavior */
982 ok(!shfo
.fAnyOperationsAborted
, "Didn't expect aborted operations\n");
986 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
987 ok(shfo
.fAnyOperationsAborted
, "Expected aborted operations\n");
989 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
991 /* try to copy many files to nonexistent directory */
993 shfo
.fFlags
&= ~FOF_NOERRORUI
;
994 shfo
.fAnyOperationsAborted
= FALSE
;
995 retval
= SHFileOperation(&shfo
);
996 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
997 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
998 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
999 ok(RemoveDirectory(to
), "Expected test3.txt to exist\n");
1001 /* send in FOF_MULTIDESTFILES with too many destination files */
1003 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1004 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1005 shfo
.fFlags
|= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
1006 retval
= SHFileOperation(&shfo
);
1007 if (dir_exists("testdir2\\a.txt"))
1009 /* Vista and W2K8 (broken or new behavior ?) */
1010 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1011 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1012 RemoveDirectory("testdir2\\a.txt");
1013 ok(DeleteFile("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
1014 RemoveDirectory("testdir2\\b.txt");
1015 ok(DeleteFile("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
1016 RemoveDirectory("testdir2\\c.txt");
1017 ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
1021 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1022 ok(shfo
.fAnyOperationsAborted
||
1023 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1024 "Expected aborted operations\n");
1025 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
1028 /* send in FOF_MULTIDESTFILES with too many destination files */
1029 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1030 shfo
.pTo
= "e.txt\0f.txt\0";
1031 shfo
.fAnyOperationsAborted
= FALSE
;
1032 retval
= SHFileOperation(&shfo
);
1033 if (dir_exists("e.txt"))
1035 /* Vista and W2K8 (broken or new behavior ?) */
1036 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1037 ok(DeleteFile("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
1038 RemoveDirectory("e.txt");
1039 ok(DeleteFile("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
1040 RemoveDirectory("f.txt");
1044 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1045 ok(shfo
.fAnyOperationsAborted
||
1046 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1047 "Expected aborted operations\n");
1048 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
1051 /* use FOF_MULTIDESTFILES with files and a source directory */
1052 shfo
.pFrom
= "test1.txt\0test2.txt\0test4.txt\0";
1053 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
1054 shfo
.fAnyOperationsAborted
= FALSE
;
1055 retval
= SHFileOperation(&shfo
);
1056 ok(retval
== ERROR_SUCCESS
||
1057 broken(retval
== 0x100a1), /* WinMe */
1058 "Expected ERROR_SUCCESS, got %d\n", retval
);
1059 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1060 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
1061 if (retval
== ERROR_SUCCESS
)
1062 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
1064 /* try many dest files without FOF_MULTIDESTFILES flag */
1065 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1066 shfo
.pTo
= "a.txt\0b.txt\0c.txt\0";
1067 shfo
.fAnyOperationsAborted
= FALSE
;
1068 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1069 retval
= SHFileOperation(&shfo
);
1070 if (dir_exists("a.txt"))
1072 /* Vista and W2K8 (broken or new behavior ?) */
1073 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1074 ok(DeleteFile("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
1075 ok(DeleteFile("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
1076 ok(DeleteFile("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
1077 RemoveDirectory("a.txt");
1081 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1082 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1086 shfo
.pFrom
= "test?.txt\0";
1087 shfo
.pTo
= "testdir2\0";
1088 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1089 retval
= SHFileOperation(&shfo
);
1090 ok(retval
== ERROR_SUCCESS
||
1091 broken(retval
== 0x100a1), /* WinMe */
1092 "Expected ERROR_SUCCESS, got %d\n", retval
);
1093 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1095 /* try a glob with FOF_FILESONLY */
1096 clean_after_shfo_tests();
1098 shfo
.pFrom
= "test?.txt\0";
1099 shfo
.fFlags
|= FOF_FILESONLY
;
1100 retval
= SHFileOperation(&shfo
);
1101 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1102 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1103 ok(!dir_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
1105 /* try a glob with FOF_MULTIDESTFILES and the same number
1106 * of dest files that we would expect
1108 clean_after_shfo_tests();
1110 shfo
.pTo
= "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1111 shfo
.fFlags
&= ~FOF_FILESONLY
;
1112 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1113 retval
= SHFileOperation(&shfo
);
1114 if (dir_exists("testdir2\\a.txt"))
1116 /* Vista and W2K8 (broken or new behavior ?) */
1117 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1118 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1119 ok(DeleteFile("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
1120 ok(DeleteFile("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
1121 ok(RemoveDirectory("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
1122 RemoveDirectory("testdir2\\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("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
1132 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
1134 /* copy one file to two others, second is ignored */
1135 clean_after_shfo_tests();
1137 shfo
.pFrom
= "test1.txt\0";
1138 shfo
.pTo
= "b.txt\0c.txt\0";
1139 shfo
.fAnyOperationsAborted
= FALSE
;
1140 retval
= SHFileOperation(&shfo
);
1141 if (retval
== DE_OPCANCELLED
)
1143 /* NT4 fails and doesn't copy any files */
1144 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1145 /* Needed to skip some tests */
1146 win_skip("Skipping some tests on NT4\n");
1151 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1152 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1154 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1156 /* copy two file to three others, all fail */
1157 shfo
.pFrom
= "test1.txt\0test2.txt\0";
1158 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1159 retval
= SHFileOperation(&shfo
);
1160 if (dir_exists("b.txt"))
1162 /* Vista and W2K8 (broken or new behavior ?) */
1163 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1164 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1165 RemoveDirectory("b.txt");
1166 ok(DeleteFile("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1167 RemoveDirectory("c.txt");
1171 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1172 ok(shfo
.fAnyOperationsAborted
||
1173 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1174 "Expected aborted operations\n");
1175 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1178 /* copy one file and one directory to three others */
1179 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1180 shfo
.pTo
= "b.txt\0c.txt\0d.txt\0";
1181 shfo
.fAnyOperationsAborted
= FALSE
;
1182 retval
= SHFileOperation(&shfo
);
1183 if (dir_exists("b.txt"))
1185 /* Vista and W2K8 (broken or new behavior ?) */
1186 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1187 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1188 RemoveDirectory("b.txt");
1189 ok(RemoveDirectory("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1190 RemoveDirectory("c.txt");
1194 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1195 ok(shfo
.fAnyOperationsAborted
||
1196 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1197 "Expected aborted operations\n");
1198 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1199 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1202 /* copy a directory with a file beneath it, plus some files */
1203 createTestFile("test4.txt\\a.txt");
1204 shfo
.pFrom
= "test4.txt\0test1.txt\0";
1205 shfo
.pTo
= "testdir2\0";
1206 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1207 shfo
.fAnyOperationsAborted
= FALSE
;
1208 retval
= SHFileOperation(&shfo
);
1209 ok(retval
== ERROR_SUCCESS
||
1210 broken(retval
== 0x100a1), /* WinMe */
1211 "Expected ERROR_SUCCESS, got %d\n", retval
);
1212 if (retval
== ERROR_SUCCESS
)
1214 ok(DeleteFile("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1215 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1216 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1219 /* copy one directory and a file in that dir to another dir */
1220 shfo
.pFrom
= "test4.txt\0test4.txt\\a.txt\0";
1221 shfo
.pTo
= "testdir2\0";
1222 retval
= SHFileOperation(&shfo
);
1223 ok(retval
== ERROR_SUCCESS
||
1224 broken(retval
== 0x100a1), /* WinMe */
1225 "Expected ERROR_SUCCESS, got %d\n", retval
);
1226 if (retval
== ERROR_SUCCESS
)
1228 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1229 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1232 /* copy a file in a directory first, and then the directory to a nonexistent dir */
1233 shfo
.pFrom
= "test4.txt\\a.txt\0test4.txt\0";
1234 shfo
.pTo
= "nonexistent\0";
1235 retval
= SHFileOperation(&shfo
);
1236 if (dir_exists("nonexistent"))
1238 /* Vista and W2K8 (broken or new behavior ?) */
1239 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1240 ok(DeleteFile("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1241 RemoveDirectory("nonexistent\\test4.txt");
1242 ok(DeleteFile("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1243 RemoveDirectory("nonexistent");
1247 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1248 ok(shfo
.fAnyOperationsAborted
||
1249 broken(!shfo
.fAnyOperationsAborted
), /* NT4 */
1250 "Expected aborted operations\n");
1251 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1253 DeleteFile("test4.txt\\a.txt");
1255 /* destination is same as source file */
1256 shfo
.pFrom
= "test1.txt\0test2.txt\0test3.txt\0";
1257 shfo
.pTo
= "b.txt\0test2.txt\0c.txt\0";
1258 shfo
.fAnyOperationsAborted
= FALSE
;
1259 shfo
.fFlags
= FOF_NOERRORUI
| FOF_MULTIDESTFILES
;
1260 retval
= SHFileOperation(&shfo
);
1261 if (retval
== DE_OPCANCELLED
)
1263 /* NT4 fails and doesn't copy any files */
1264 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1268 ok(retval
== DE_SAMEFILE
, "Expected DE_SAMEFILE, got %d\n", retval
);
1269 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1271 ok(!shfo
.fAnyOperationsAborted
, "Expected no operations to be aborted\n");
1272 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1274 /* destination is same as source directory */
1275 shfo
.pFrom
= "test1.txt\0test4.txt\0test3.txt\0";
1276 shfo
.pTo
= "b.txt\0test4.txt\0c.txt\0";
1277 shfo
.fAnyOperationsAborted
= FALSE
;
1278 retval
= SHFileOperation(&shfo
);
1279 if (retval
== DE_OPCANCELLED
)
1281 /* NT4 fails and doesn't copy any files */
1282 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1286 ok(retval
== ERROR_SUCCESS
||
1287 retval
== DE_DESTSAMETREE
, /* Vista */
1288 "Expected ERROR_SUCCESS or DE_DESTSAMETREE, got %d\n", retval
);
1289 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1291 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1293 /* copy a directory into itself, error displayed in UI */
1294 shfo
.pFrom
= "test4.txt\0";
1295 shfo
.pTo
= "test4.txt\\newdir\0";
1296 shfo
.fFlags
&= ~FOF_MULTIDESTFILES
;
1297 shfo
.fAnyOperationsAborted
= FALSE
;
1298 retval
= SHFileOperation(&shfo
);
1299 ok(retval
== ERROR_SUCCESS
||
1300 retval
== DE_DESTSUBTREE
, /* Vista */
1301 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1302 ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1304 /* copy a directory to itself, error displayed in UI */
1305 shfo
.pFrom
= "test4.txt\0";
1306 shfo
.pTo
= "test4.txt\0";
1307 shfo
.fAnyOperationsAborted
= FALSE
;
1308 retval
= SHFileOperation(&shfo
);
1309 ok(retval
== ERROR_SUCCESS
||
1310 retval
== DE_DESTSUBTREE
, /* Vista */
1311 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1313 /* copy a file into a directory, and the directory into itself */
1314 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1315 shfo
.pTo
= "test4.txt\0";
1316 shfo
.fAnyOperationsAborted
= FALSE
;
1317 shfo
.fFlags
|= FOF_NOCONFIRMATION
;
1318 retval
= SHFileOperation(&shfo
);
1319 ok(retval
== ERROR_SUCCESS
||
1320 retval
== DE_DESTSUBTREE
, /* Vista */
1321 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1322 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1324 /* copy a file to a file, and the directory into itself */
1325 shfo
.pFrom
= "test1.txt\0test4.txt\0";
1326 shfo
.pTo
= "test4.txt\\a.txt\0";
1327 shfo
.fAnyOperationsAborted
= FALSE
;
1328 retval
= SHFileOperation(&shfo
);
1329 if (dir_exists("test4.txt\\a.txt"))
1331 /* Vista and W2K8 (broken or new behavior ?) */
1332 ok(retval
== DE_DESTSUBTREE
, "Expected DE_DESTSUBTREE, got %d\n", retval
);
1333 ok(DeleteFile("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1334 RemoveDirectory("test4.txt\\a.txt");
1338 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1339 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1342 /* copy a nonexistent file to a nonexistent directory */
1343 shfo
.pFrom
= "e.txt\0";
1344 shfo
.pTo
= "nonexistent\0";
1345 shfo
.fAnyOperationsAborted
= FALSE
;
1346 retval
= SHFileOperation(&shfo
);
1347 ok(retval
== 1026 ||
1348 retval
== ERROR_FILE_NOT_FOUND
|| /* Vista */
1349 broken(retval
== ERROR_SUCCESS
), /* NT4 */
1350 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval
);
1351 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1352 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1354 /* Overwrite tests */
1355 clean_after_shfo_tests();
1359 /* NT4 would throw up some dialog boxes and doesn't copy files that are needed
1360 * in subsequent tests.
1362 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1363 shfo
.pFrom
= "test1.txt\0";
1364 shfo
.pTo
= "test2.txt\0";
1365 shfo
.fAnyOperationsAborted
= FALSE
;
1366 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1367 retval
= SHFileOperation(&shfo
);
1368 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1369 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1371 shfo
.pFrom
= "test3.txt\0test1.txt\0";
1372 shfo
.pTo
= "test2.txt\0one.txt\0";
1373 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_MULTIDESTFILES
;
1374 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1375 retval
= SHFileOperation(&shfo
);
1376 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1377 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1379 shfo
.pFrom
= "one.txt\0";
1380 shfo
.pTo
= "testdir2\0";
1381 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1382 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1383 retval
= SHFileOperation(&shfo
);
1384 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1385 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1388 createTestFile("test4.txt\\test1.txt");
1389 shfo
.pFrom
= "test4.txt\0";
1390 shfo
.pTo
= "testdir2\0";
1391 /* WinMe needs FOF_NOERRORUI */
1392 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_NOERRORUI
;
1393 retval
= SHFileOperation(&shfo
);
1394 ok(retval
== ERROR_SUCCESS
||
1395 broken(retval
== 0x100a1), /* WinMe */
1396 "Expected ERROR_SUCCESS, got %d\n", retval
);
1397 shfo
.fFlags
= FOF_NOCONFIRMATION
;
1400 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1401 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1402 retval
= SHFileOperation(&shfo
);
1403 ok(retval
== 0, "Expected 0, got %d\n", retval
);
1404 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1407 createTestFile("one.txt");
1409 /* pFrom contains bogus 2nd name longer than MAX_PATH */
1410 memset(from
, 'a', MAX_PATH
*2);
1411 memset(from
+MAX_PATH
*2, 0, 2);
1412 lstrcpyA(from
, "one.txt");
1414 shfo
.pTo
= "two.txt\0";
1415 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1416 retval
= SHFileOperation(&shfo
);
1417 ok(retval
== 1148 || retval
== 1026 ||
1418 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1419 retval
== DE_INVALIDFILES
, /* Vista */
1420 "Unexpected return value, got %d\n", retval
);
1421 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1422 if (dir_exists("two.txt"))
1423 /* Vista and W2K8 (broken or new behavior ?) */
1424 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1426 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1428 createTestFile("one.txt");
1430 /* pTo contains bogus 2nd name longer than MAX_PATH */
1431 memset(to
, 'a', MAX_PATH
*2);
1432 memset(to
+MAX_PATH
*2, 0, 2);
1433 lstrcpyA(to
, "two.txt");
1434 shfo
.pFrom
= "one.txt\0";
1436 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1437 retval
= SHFileOperation(&shfo
);
1438 if (retval
== DE_OPCANCELLED
)
1440 /* NT4 fails and doesn't copy any files */
1441 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1445 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1446 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1448 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1450 createTestFile("one.txt");
1452 /* no FOF_MULTIDESTFILES, two files in pTo */
1453 shfo
.pFrom
= "one.txt\0";
1454 shfo
.pTo
= "two.txt\0three.txt\0";
1455 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1456 retval
= SHFileOperation(&shfo
);
1457 if (retval
== DE_OPCANCELLED
)
1459 /* NT4 fails and doesn't copy any files */
1460 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1464 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1465 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1467 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1469 createTestFile("one.txt");
1471 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1472 memset(from
, 'a', MAX_PATH
*2);
1473 memset(from
+MAX_PATH
*2, 0, 2);
1474 memset(to
, 'a', MAX_PATH
*2);
1475 memset(to
+MAX_PATH
*2, 0, 2);
1476 lstrcpyA(from
, "one.txt");
1477 lstrcpyA(to
, "two.txt");
1480 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1481 retval
= SHFileOperation(&shfo
);
1482 ok(retval
== 1148 || retval
== 1026 ||
1483 retval
== ERROR_ACCESS_DENIED
|| /* win2k */
1484 retval
== DE_INVALIDFILES
, /* Vista */
1485 "Unexpected return value, got %d\n", retval
);
1486 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1487 if (dir_exists("two.txt"))
1488 /* Vista and W2K8 (broken or new behavior ?) */
1489 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1491 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1493 createTestFile("one.txt");
1495 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1496 memset(to
, 'a', MAX_PATH
*2);
1497 memset(to
+MAX_PATH
*2, 0, 2);
1498 lstrcpyA(to
, "two.txt");
1499 shfo
.pFrom
= "one.txt\0";
1501 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1502 FOF_SILENT
| FOF_NOERRORUI
;
1503 retval
= SHFileOperation(&shfo
);
1504 if (retval
== DE_OPCANCELLED
)
1506 /* NT4 fails and doesn't copy any files */
1507 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1511 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1512 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1514 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1516 createTestFile("one.txt");
1517 createTestFile("two.txt");
1519 /* pTo contains bogus 2nd name longer than MAX_PATH,
1520 * multiple source files,
1521 * dest directory does not exist
1523 memset(to
, 'a', 2 * MAX_PATH
);
1524 memset(to
+MAX_PATH
*2, 0, 2);
1525 lstrcpyA(to
, "threedir");
1526 shfo
.pFrom
= "one.txt\0two.txt\0";
1528 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1529 retval
= SHFileOperation(&shfo
);
1530 if (dir_exists("threedir"))
1532 /* Vista and W2K8 (broken or new behavior ?) */
1533 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1534 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1535 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1536 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1540 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1541 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1542 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1543 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1544 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1546 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1547 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1549 createTestFile("one.txt");
1550 createTestFile("two.txt");
1551 CreateDirectoryA("threedir", NULL
);
1553 /* pTo contains bogus 2nd name longer than MAX_PATH,
1554 * multiple source files,
1555 * dest directory does exist
1557 memset(to
, 'a', 2 * MAX_PATH
);
1558 memset(to
+MAX_PATH
*2, 0, 2);
1559 lstrcpyA(to
, "threedir");
1560 shfo
.pFrom
= "one.txt\0two.txt\0";
1562 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1563 retval
= SHFileOperation(&shfo
);
1564 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1565 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1566 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1567 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1568 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1569 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1572 /* this crashes on win9x */
1573 createTestFile("one.txt");
1574 createTestFile("two.txt");
1576 /* pTo contains bogus 2nd name longer than MAX_PATH,
1577 * multiple source files, FOF_MULTIDESTFILES
1578 * dest dir does not exist
1581 memset(to
, 'a', 2 * MAX_PATH
);
1582 memset(to
+MAX_PATH
*2, 0, 2);
1583 lstrcpyA(to
, "threedir");
1584 shfo
.pFrom
= "one.txt\0two.txt\0";
1586 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1587 FOF_SILENT
| FOF_NOERRORUI
;
1588 retval
= SHFileOperation(&shfo
);
1589 ok(retval
== ERROR_CANCELLED
||
1590 retval
== ERROR_SUCCESS
, /* win2k3 */
1591 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval
);
1592 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1593 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1594 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1595 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1596 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1598 /* file exists in win2k */
1599 DeleteFileA("threedir");
1603 createTestFile("one.txt");
1604 createTestFile("two.txt");
1605 CreateDirectoryA("threedir", NULL
);
1607 /* pTo contains bogus 2nd name longer than MAX_PATH,
1608 * multiple source files, FOF_MULTIDESTFILES
1609 * dest dir does exist
1611 memset(to
, 'a', 2 * MAX_PATH
);
1612 memset(to
+MAX_PATH
*2, 0, 2);
1613 lstrcpyA(to
, "threedir");
1614 ptr
= to
+ lstrlenA(to
) + 1;
1615 lstrcpyA(ptr
, "fourdir");
1616 shfo
.pFrom
= "one.txt\0two.txt\0";
1618 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1619 FOF_SILENT
| FOF_NOERRORUI
;
1620 retval
= SHFileOperation(&shfo
);
1621 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1622 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1623 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1624 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1625 if (dir_exists("fourdir"))
1627 /* Vista and W2K8 (broken or new behavior ?) */
1628 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1629 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1630 RemoveDirectoryA("fourdir");
1634 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1635 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1636 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1638 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1640 createTestFile("one.txt");
1641 createTestFile("two.txt");
1642 CreateDirectoryA("threedir", NULL
);
1644 /* multiple source files, FOF_MULTIDESTFILES
1645 * multiple dest files, but first dest dir exists
1646 * num files in lists is equal
1648 shfo
.pFrom
= "one.txt\0two.txt\0";
1649 shfo
.pTo
= "threedir\0fourdir\0";
1650 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1651 FOF_SILENT
| FOF_NOERRORUI
;
1652 retval
= SHFileOperation(&shfo
);
1653 ok(retval
== ERROR_CANCELLED
||
1654 retval
== DE_FILEDESTISFLD
|| /* Vista */
1655 broken(retval
== DE_OPCANCELLED
), /* Win9x, NT4 */
1656 "Expected ERROR_CANCELLED or DE_FILEDESTISFLD. got %d\n", retval
);
1657 if (file_exists("threedir\\threedir"))
1660 ok(DeleteFileA("threedir\\threedir"), "Expected file to exist\n");
1662 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1663 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1664 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1665 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1666 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1667 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1668 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1670 createTestFile("one.txt");
1671 createTestFile("two.txt");
1672 CreateDirectoryA("threedir", NULL
);
1674 /* multiple source files, FOF_MULTIDESTFILES
1675 * multiple dest files, but first dest dir exists
1676 * num files in lists is not equal
1678 shfo
.pFrom
= "one.txt\0two.txt\0";
1679 shfo
.pTo
= "threedir\0fourdir\0five\0";
1680 shfo
.fFlags
= FOF_MULTIDESTFILES
| FOF_NOCONFIRMATION
|
1681 FOF_SILENT
| FOF_NOERRORUI
;
1682 retval
= SHFileOperation(&shfo
);
1683 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1684 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1685 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1686 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1687 if (dir_exists("fourdir"))
1689 /* Vista and W2K8 (broken or new behavior ?) */
1690 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1691 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1692 RemoveDirectoryA("fourdir");
1696 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1697 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1698 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1700 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1701 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1702 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1704 createTestFile("aa.txt");
1705 createTestFile("ab.txt");
1706 CreateDirectoryA("one", NULL
);
1707 CreateDirectoryA("two", NULL
);
1709 /* pFrom has a glob, pTo has more than one dest */
1710 shfo
.pFrom
= "a*.txt\0";
1711 shfo
.pTo
= "one\0two\0";
1712 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1713 retval
= SHFileOperation(&shfo
);
1714 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1715 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1716 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1717 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1718 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1719 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1720 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1721 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1722 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1724 /* pTo is an empty string */
1725 CreateDirectoryA("dir", NULL
);
1726 createTestFile("dir\\abcdefgh.abc");
1727 shfo
.pFrom
= "dir\\abcdefgh.abc\0";
1729 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1730 retval
= SHFileOperation(&shfo
);
1731 ok(retval
== ERROR_SUCCESS
||
1732 broken(retval
== DE_OPCANCELLED
), /* NT4 */
1733 "Expected ERROR_SUCCESS, got %d\n", retval
);
1734 if (retval
== ERROR_SUCCESS
)
1735 ok(DeleteFileA("abcdefgh.abc"), "Expected file to exist\n");
1736 ok(DeleteFileA("dir\\abcdefgh.abc"), "Expected file to exist\n");
1737 ok(RemoveDirectoryA("dir"), "Expected dir to exist\n");
1740 /* tests the FO_MOVE action */
1741 static void test_move(void)
1743 SHFILEOPSTRUCTA shfo
, shfo2
;
1744 CHAR from
[5*MAX_PATH
];
1745 CHAR to
[5*MAX_PATH
];
1749 shfo
.wFunc
= FO_MOVE
;
1752 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
1753 shfo
.hNameMappings
= NULL
;
1754 shfo
.lpszProgressTitle
= NULL
;
1756 set_curr_dir_path(from
, "test1.txt\0");
1757 set_curr_dir_path(to
, "test4.txt\0");
1758 ok(!SHFileOperationA(&shfo
), "Prepare test to check how directories are moved recursively\n");
1759 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1760 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1762 set_curr_dir_path(from
, "test?.txt\0");
1763 set_curr_dir_path(to
, "testdir2\0");
1764 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1765 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1766 ok(!SHFileOperationA(&shfo
), "Files and directories are moved to directory\n");
1767 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1768 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1769 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1771 clean_after_shfo_tests();
1774 memcpy(&shfo2
, &shfo
, sizeof(SHFILEOPSTRUCTA
));
1775 shfo2
.fFlags
|= FOF_MULTIDESTFILES
;
1777 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1778 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1780 shfo2
.fFlags
|= FOF_NOCONFIRMMKDIR
;
1781 ok(!SHFileOperationA(&shfo2
), "Move many files\n");
1782 ok(DeleteFileA("test6.txt"), "The file is not moved - many files are "
1783 "specified as a target\n");
1784 ok(DeleteFileA("test7.txt"), "The file is not moved\n");
1785 ok(RemoveDirectoryA("test8.txt"), "The directory is not moved\n");
1789 /* number of sources do not correspond to number of targets */
1790 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1791 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
1792 retval
= SHFileOperationA(&shfo2
);
1793 if (dir_exists("test6.txt"))
1795 if (retval
== ERROR_SUCCESS
)
1798 DeleteFileA("test6.txt\\test1.txt");
1799 DeleteFileA("test6.txt\\test2.txt");
1800 RemoveDirectoryA("test6.txt\\test4.txt");
1801 RemoveDirectoryA("test6.txt");
1805 /* Vista and W2K8 (broken or new behavior ?) */
1806 ok(retval
== DE_DESTSAMETREE
, "Expected DE_DESTSAMETREE, got %d\n", retval
);
1807 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1808 RemoveDirectoryA("test6.txt");
1809 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1810 RemoveDirectoryA("test7.txt");
1815 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1816 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1817 "specified as a target\n");
1822 set_curr_dir_path(from
, "test3.txt\0");
1823 set_curr_dir_path(to
, "test4.txt\\test1.txt\0");
1824 ok(!SHFileOperationA(&shfo
), "Can't move file to other directory\n");
1825 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1827 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test4.txt\0");
1828 set_curr_dir_path(to
, "test6.txt\0test7.txt\0test8.txt\0");
1830 shfo
.fFlags
|= FOF_NOCONFIRMMKDIR
;
1831 retval
= SHFileOperationA(&shfo
);
1832 if (dir_exists("test6.txt"))
1835 /* Vista and W2K8 (broken or new behavior ?) */
1836 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1837 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1838 ok(DeleteFileA("test6.txt\\test2.txt"), "The file is not moved. Many files are specified\n");
1839 ok(DeleteFileA("test6.txt\\test4.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1840 ok(RemoveDirectoryA("test6.txt\\test4.txt"), "The directory is not moved. Many files are specified\n");
1841 RemoveDirectoryA("test6.txt");
1846 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1847 ok(file_exists("test1.txt"), "The file is moved. Many files are specified\n");
1848 ok(dir_exists("test4.txt"), "The directory is moved. Many files are specified\n");
1851 set_curr_dir_path(from
, "test1.txt\0");
1852 set_curr_dir_path(to
, "test6.txt\0");
1853 ok(!SHFileOperationA(&shfo
), "Move file failed\n");
1854 ok(!file_exists("test1.txt"), "The file is not moved\n");
1855 ok(file_exists("test6.txt"), "The file is not moved\n");
1856 set_curr_dir_path(from
, "test6.txt\0");
1857 set_curr_dir_path(to
, "test1.txt\0");
1858 ok(!SHFileOperationA(&shfo
), "Move file back failed\n");
1860 set_curr_dir_path(from
, "test4.txt\0");
1861 set_curr_dir_path(to
, "test6.txt\0");
1862 ok(!SHFileOperationA(&shfo
), "Move dir failed\n");
1863 ok(!dir_exists("test4.txt"), "The dir is not moved\n");
1864 ok(dir_exists("test6.txt"), "The dir is moved\n");
1865 set_curr_dir_path(from
, "test6.txt\0");
1866 set_curr_dir_path(to
, "test4.txt\0");
1867 ok(!SHFileOperationA(&shfo
), "Move dir back failed\n");
1869 /* move one file to two others */
1871 shfo
.pFrom
= "test1.txt\0";
1872 shfo
.pTo
= "a.txt\0b.txt\0";
1873 retval
= SHFileOperationA(&shfo
);
1874 if (retval
== DE_OPCANCELLED
)
1876 /* NT4 fails and doesn't move any files */
1877 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1878 DeleteFileA("test1.txt");
1882 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1885 DeleteFile("a.txt\\a.txt");
1886 RemoveDirectoryA("a.txt");
1889 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1890 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1892 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1894 /* move two files to one other */
1895 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1896 shfo
.pTo
= "test1.txt\0";
1897 retval
= SHFileOperationA(&shfo
);
1898 if (dir_exists("test1.txt"))
1901 /* Vista and W2K8 (broken or new behavior ?) */
1902 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1903 ok(DeleteFileA("test1.txt\\test2.txt"), "Expected test1.txt\\test2.txt to exist\n");
1904 ok(DeleteFileA("test1.txt\\test3.txt"), "Expected test1.txt\\test3.txt to exist\n");
1905 RemoveDirectoryA("test1.txt");
1906 createTestFile("test2.txt");
1907 createTestFile("test3.txt");
1911 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1912 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1913 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1914 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1917 /* move a directory into itself */
1918 shfo
.pFrom
= "test4.txt\0";
1919 shfo
.pTo
= "test4.txt\\b.txt\0";
1920 retval
= SHFileOperationA(&shfo
);
1921 ok(retval
== ERROR_SUCCESS
||
1922 retval
== DE_DESTSUBTREE
, /* Vista */
1923 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval
);
1924 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1925 ok(dir_exists("test4.txt"), "Expected test4.txt to exist\n");
1927 /* move many files without FOF_MULTIDESTFILES */
1928 shfo
.pFrom
= "test2.txt\0test3.txt\0";
1929 shfo
.pTo
= "d.txt\0e.txt\0";
1930 retval
= SHFileOperationA(&shfo
);
1931 if (dir_exists("d.txt"))
1934 /* Vista and W2K8 (broken or new behavior ?) */
1935 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1936 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1937 ok(DeleteFileA("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to exist\n");
1938 RemoveDirectoryA("d.txt");
1939 createTestFile("test2.txt");
1940 createTestFile("test3.txt");
1944 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1945 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1946 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1949 /* number of sources != number of targets */
1950 shfo
.pTo
= "d.txt\0";
1951 shfo
.fFlags
|= FOF_MULTIDESTFILES
;
1952 retval
= SHFileOperationA(&shfo
);
1953 if (dir_exists("d.txt"))
1957 DeleteFileA("d.txt\\test2.txt");
1958 DeleteFileA("d.txt\\test3.txt");
1959 RemoveDirectoryA("d.txt");
1960 createTestFile("test2.txt");
1964 /* Vista and W2K8 (broken or new behavior ?) */
1965 ok(retval
== DE_SAMEFILE
,
1966 "Expected DE_SAMEFILE, got %d\n", retval
);
1967 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1968 ok(!file_exists("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to not exist\n");
1969 RemoveDirectoryA("d.txt");
1970 createTestFile("test2.txt");
1975 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1976 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1979 /* FO_MOVE does not create dest directories */
1980 shfo
.pFrom
= "test2.txt\0";
1981 shfo
.pTo
= "dir1\\dir2\\test2.txt\0";
1982 retval
= SHFileOperationA(&shfo
);
1983 if (dir_exists("dir1"))
1985 /* Vista and W2K8 (broken or new behavior ?) */
1986 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
1987 ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n");
1988 RemoveDirectoryA("dir1\\dir2");
1989 RemoveDirectoryA("dir1");
1990 createTestFile("test2.txt");
1994 expect_retval(ERROR_CANCELLED
, DE_OPCANCELLED
/* Win9x, NT4 */);
1997 /* try to overwrite an existing file */
1998 shfo
.pTo
= "test3.txt\0";
1999 retval
= SHFileOperationA(&shfo
);
2000 if (retval
== DE_OPCANCELLED
)
2002 /* NT4 fails and doesn't move any files */
2003 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
2007 ok(retval
== ERROR_SUCCESS
, "Expected ERROR_SUCCESS, got %d\n", retval
);
2008 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
2011 DeleteFileA("test3.txt\\test3.txt");
2012 RemoveDirectoryA("test3.txt");
2015 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2019 static void test_sh_create_dir(void)
2021 CHAR path
[MAX_PATH
];
2024 if(!pSHCreateDirectoryExA
)
2026 win_skip("skipping SHCreateDirectoryExA tests\n");
2030 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2031 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
2032 ok(ERROR_SUCCESS
== ret
, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret
);
2033 ok(file_exists("testdir2"), "The first directory is not created\n");
2034 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
2036 ret
= pSHCreateDirectoryExA(NULL
, path
, NULL
);
2037 ok(ERROR_ALREADY_EXISTS
== ret
, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret
);
2039 ret
= pSHCreateDirectoryExA(NULL
, "c:\\testdir3", NULL
);
2040 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
2043 static void test_sh_path_prepare(void)
2046 CHAR path
[MAX_PATH
];
2047 CHAR UNICODE_PATH_A
[MAX_PATH
];
2049 if(!pSHPathPrepareForWriteA
)
2051 win_skip("skipping SHPathPrepareForWriteA tests\n");
2055 /* directory exists, SHPPFW_NONE */
2056 set_curr_dir_path(path
, "testdir2\0");
2057 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2058 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2060 /* directory exists, SHPPFW_IGNOREFILENAME */
2061 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2062 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
2063 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2065 /* directory exists, SHPPFW_DIRCREATE */
2066 set_curr_dir_path(path
, "testdir2\0");
2067 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2068 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2070 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2071 set_curr_dir_path(path
, "testdir2\\test4.txt\0");
2072 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
2073 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2074 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2076 /* file exists, SHPPFW_NONE */
2077 set_curr_dir_path(path
, "test1.txt\0");
2078 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2079 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2080 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2081 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2082 "Unexpected result : 0x%08x\n", res
);
2084 /* file exists, SHPPFW_DIRCREATE */
2085 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2086 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2087 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2088 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2089 "Unexpected result : 0x%08x\n", res
);
2091 /* file exists, SHPPFW_NONE, trailing \ */
2092 set_curr_dir_path(path
, "test1.txt\\\0");
2093 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2094 ok(res
== HRESULT_FROM_WIN32(ERROR_DIRECTORY
) ||
2095 res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
) || /* WinMe */
2096 res
== HRESULT_FROM_WIN32(ERROR_INVALID_NAME
), /* Vista */
2097 "Unexpected result : 0x%08x\n", res
);
2099 /* relative path exists, SHPPFW_DIRCREATE */
2100 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE
);
2101 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2103 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
2104 res
= pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE
);
2105 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2106 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
2108 /* directory doesn't exist, SHPPFW_NONE */
2109 set_curr_dir_path(path
, "nonexistent\0");
2110 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_NONE
);
2111 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2113 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
2114 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2115 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
);
2116 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2117 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
2118 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2120 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2121 set_curr_dir_path(path
, "testdir2\\test4.txt\\\0");
2122 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_IGNOREFILENAME
|SHPPFW_DIRCREATE
);
2123 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2124 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
2126 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
2127 set_curr_dir_path(path
, "nonexistent\\notreal\0");
2128 res
= pSHPathPrepareForWriteA(0, 0, path
, SHPPFW_DIRCREATE
);
2129 ok(res
== S_OK
, "res == 0x%08x, expected S_OK\n", res
);
2130 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
2132 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
2134 if(!pSHPathPrepareForWriteW
)
2136 win_skip("Skipping SHPathPrepareForWriteW tests\n");
2139 WideCharToMultiByte(CP_ACP
, 0, UNICODE_PATH
, -1, UNICODE_PATH_A
, sizeof(UNICODE_PATH_A
), NULL
, NULL
);
2141 /* unicode directory doesn't exist, SHPPFW_NONE */
2142 RemoveDirectoryA(UNICODE_PATH_A
);
2143 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2144 ok(res
== HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND
), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res
);
2145 ok(!file_exists(UNICODE_PATH_A
), "unicode path was created but shouldn't be\n");
2146 RemoveDirectoryA(UNICODE_PATH_A
);
2148 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
2149 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2150 ok(res
== S_OK
, "res == %08x, expected S_OK\n", res
);
2151 ok(file_exists(UNICODE_PATH_A
), "unicode path should've been created\n");
2153 /* unicode directory exists, SHPPFW_NONE */
2154 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_NONE
);
2155 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2157 /* unicode directory exists, SHPPFW_DIRCREATE */
2158 res
= pSHPathPrepareForWriteW(0, 0, UNICODE_PATH
, SHPPFW_DIRCREATE
);
2159 ok(res
== S_OK
, "ret == %08x, expected S_OK\n", res
);
2160 RemoveDirectoryA(UNICODE_PATH_A
);
2163 static void test_sh_new_link_info(void)
2165 BOOL ret
, mustcopy
=TRUE
;
2166 CHAR linkto
[MAX_PATH
];
2167 CHAR destdir
[MAX_PATH
];
2168 CHAR result
[MAX_PATH
];
2169 CHAR result2
[MAX_PATH
];
2171 /* source file does not exist */
2172 set_curr_dir_path(linkto
, "nosuchfile.txt\0");
2173 set_curr_dir_path(destdir
, "testdir2\0");
2174 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2176 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2177 "SHGetNewLinkInfoA succeeded\n");
2178 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2180 /* dest dir does not exist */
2181 set_curr_dir_path(linkto
, "test1.txt\0");
2182 set_curr_dir_path(destdir
, "nosuchdir\0");
2183 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2185 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2186 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2187 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2189 /* source file exists */
2190 set_curr_dir_path(linkto
, "test1.txt\0");
2191 set_curr_dir_path(destdir
, "testdir2\0");
2192 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result
, &mustcopy
, 0);
2194 broken(ret
== lstrlenA(result
) + 1), /* NT4 */
2195 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2196 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2197 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, destdir
,
2198 lstrlenA(destdir
), result
, lstrlenA(destdir
)) == CSTR_EQUAL
,
2199 "%s does not start with %s\n", result
, destdir
);
2200 ok(lstrlenA(result
) > 4 && lstrcmpiA(result
+lstrlenA(result
)-4, ".lnk") == 0,
2201 "%s does not end with .lnk\n", result
);
2203 /* preferred target name already exists */
2204 createTestFile(result
);
2205 ret
= SHGetNewLinkInfoA(linkto
, destdir
, result2
, &mustcopy
, 0);
2207 broken(ret
== lstrlenA(result2
) + 1), /* NT4 */
2208 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2209 ok(mustcopy
== FALSE
, "mustcopy should be FALSE\n");
2210 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT
, NORM_IGNORECASE
, destdir
,
2211 lstrlenA(destdir
), result2
, lstrlenA(destdir
)) == CSTR_EQUAL
,
2212 "%s does not start with %s\n", result2
, destdir
);
2213 ok(lstrlenA(result2
) > 4 && lstrcmpiA(result2
+lstrlenA(result2
)-4, ".lnk") == 0,
2214 "%s does not end with .lnk\n", result2
);
2215 ok(lstrcmpiA(result
, result2
) != 0, "%s and %s are the same\n", result
, result2
);
2216 DeleteFileA(result
);
2219 static void test_unicode(void)
2221 SHFILEOPSTRUCTW shfoW
;
2225 if (!pSHFileOperationW
)
2227 skip("SHFileOperationW() is missing\n");
2232 shfoW
.wFunc
= FO_DELETE
;
2233 shfoW
.pFrom
= UNICODE_PATH
;
2235 shfoW
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
;
2236 shfoW
.hNameMappings
= NULL
;
2237 shfoW
.lpszProgressTitle
= NULL
;
2239 /* Clean up before start test */
2240 DeleteFileW(UNICODE_PATH
);
2241 RemoveDirectoryW(UNICODE_PATH
);
2243 /* Make sure we are on a system that supports unicode */
2244 SetLastError(0xdeadbeef);
2245 file
= CreateFileW(UNICODE_PATH
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
2246 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
2248 skip("Unicode tests skipped on non-unicode system\n");
2253 /* Try to delete a file with unicode filename */
2254 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2255 ret
= pSHFileOperationW(&shfoW
);
2256 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2257 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2259 /* Try to trash a file with unicode filename */
2260 createTestFileW(UNICODE_PATH
);
2261 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2262 ok(file_existsW(UNICODE_PATH
), "The file does not exist\n");
2263 ret
= pSHFileOperationW(&shfoW
);
2264 ok(!ret
, "File is not removed, ErrorCode: %d\n", ret
);
2265 ok(!file_existsW(UNICODE_PATH
), "The file should have been removed\n");
2267 if(!pSHCreateDirectoryExW
)
2269 skip("Skipping SHCreateDirectoryExW tests\n");
2273 /* Try to delete a directory with unicode filename */
2274 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2275 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2276 ok(file_existsW(UNICODE_PATH
), "The directory is not created\n");
2277 shfoW
.fFlags
&= ~FOF_ALLOWUNDO
;
2278 ret
= pSHFileOperationW(&shfoW
);
2279 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2280 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2282 /* Try to trash a directory with unicode filename */
2283 ret
= pSHCreateDirectoryExW(NULL
, UNICODE_PATH
, NULL
);
2284 ok(!ret
, "SHCreateDirectoryExW returned %d\n", ret
);
2285 ok(file_existsW(UNICODE_PATH
), "The directory was not created\n");
2286 shfoW
.fFlags
|= FOF_ALLOWUNDO
;
2287 ret
= pSHFileOperationW(&shfoW
);
2288 ok(!ret
, "Directory is not removed, ErrorCode: %d\n", ret
);
2289 ok(!file_existsW(UNICODE_PATH
), "The directory should have been removed\n");
2292 extern HRESULT WINAPI
Shell_MergeMenus (HMENU hmDst
, HMENU hmSrc
, UINT uInsert
, UINT uIDAdjust
, UINT uIDAdjustMax
, ULONG uFlags
);
2295 test_shlmenu(void) {
2297 hres
= Shell_MergeMenus (0, 0, 0x42, 0x4242, 0x424242, 0);
2298 ok (hres
== 0x4242, "expected 0x4242 but got %x\n", hres
);
2299 hres
= Shell_MergeMenus ((HMENU
)42, 0, 0x42, 0x4242, 0x424242, 0);
2300 ok (hres
== 0x4242, "expected 0x4242 but got %x\n", hres
);
2303 /* Check for old shell32 (4.0.x) */
2304 static BOOL
is_old_shell32(void)
2306 SHFILEOPSTRUCTA shfo
;
2307 CHAR from
[5*MAX_PATH
];
2308 CHAR to
[5*MAX_PATH
];
2312 shfo
.wFunc
= FO_COPY
;
2315 /* FOF_NOCONFIRMMKDIR is needed for old shell32 */
2316 shfo
.fFlags
= FOF_NOCONFIRMATION
| FOF_SILENT
| FOF_NOERRORUI
| FOF_MULTIDESTFILES
| FOF_NOCONFIRMMKDIR
;
2317 shfo
.hNameMappings
= NULL
;
2318 shfo
.lpszProgressTitle
= NULL
;
2320 set_curr_dir_path(from
, "test1.txt\0test2.txt\0test3.txt\0");
2321 set_curr_dir_path(to
, "test6.txt\0test7.txt\0");
2322 retval
= SHFileOperationA(&shfo
);
2324 /* Delete extra files on old shell32 and Vista+*/
2325 DeleteFileA("test6.txt\\test1.txt");
2326 /* Delete extra files on old shell32 */
2327 DeleteFileA("test6.txt\\test2.txt");
2328 DeleteFileA("test6.txt\\test3.txt");
2329 /* Delete extra directory on old shell32 and Vista+ */
2330 RemoveDirectoryA("test6.txt");
2331 /* Delete extra files/directories on Vista+*/
2332 DeleteFileA("test7.txt\\test2.txt");
2333 RemoveDirectoryA("test7.txt");
2335 if (retval
== ERROR_SUCCESS
)
2341 START_TEST(shlfileop
)
2343 InitFunctionPointers();
2345 clean_after_shfo_tests();
2348 old_shell32
= is_old_shell32();
2350 win_skip("Need to cater for old shell32 (4.0.x) on Win95\n");
2351 clean_after_shfo_tests();
2354 test_get_file_info();
2355 test_get_file_info_iconlist();
2356 clean_after_shfo_tests();
2360 clean_after_shfo_tests();
2364 clean_after_shfo_tests();
2368 clean_after_shfo_tests();
2372 clean_after_shfo_tests();
2374 test_sh_create_dir();
2375 clean_after_shfo_tests();
2378 test_sh_path_prepare();
2379 clean_after_shfo_tests();
2382 test_sh_new_link_info();
2383 clean_after_shfo_tests();