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 overwrite an existing write protected file */
969 clean_after_shfo_tests();
971 tmp_flags = shfo.fFlags;
972 shfo.pFrom = "test1.txt\0";
973 shfo.pTo = "test2.txt\0";
974 /* suppress the error-dialog in win9x here */
975 shfo.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT;
976 ok(SetFileAttributesA(shfo.pTo, FILE_ATTRIBUTE_READONLY),
977 "Failure to set file attributes (error %x)\n", GetLastError());
978 retval = CopyFileA(shfo.pFrom, shfo.pTo, FALSE);
979 ok(!retval && GetLastError() == ERROR_ACCESS_DENIED, "CopyFileA should have fail with ERROR_ACCESS_DENIED\n");
980 retval = SHFileOperationA(&shfo);
981 /* Does not work on Win95, Win95B, NT4WS and NT4SRV */
982 ok(!retval || broken(retval == DE_OPCANCELLED), "SHFileOperationA failed to copy (error %x)\n", retval);
983 /* Set back normal attributes to make the file deletion succeed */
984 ok(SetFileAttributesA(shfo.pTo, FILE_ATTRIBUTE_NORMAL),
985 "Failure to set file attributes (error %x)\n", GetLastError());
986 shfo.fFlags = tmp_flags;
988 /* try to copy files to a file */
989 clean_after_shfo_tests();
993 /* suppress the error-dialog in win9x here */
994 shfo.fFlags |= FOF_NOERRORUI;
995 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
996 set_curr_dir_path(to, "test3.txt\0");
997 retval = SHFileOperation(&shfo);
998 if (retval == DE_FLDDESTISFILE || /* Vista and W2K8 */
999 retval == DE_INVALIDFILES) /* Win7 */
1001 /* Most likely new behavior */
1002 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1006 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1007 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
1009 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
1011 /* try to copy many files to nonexistent directory */
1013 shfo.fFlags &= ~FOF_NOERRORUI;
1014 shfo.fAnyOperationsAborted = FALSE;
1015 retval = SHFileOperation(&shfo);
1016 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1017 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
1018 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
1019 ok(RemoveDirectory(to), "Expected test3.txt to exist\n");
1021 /* send in FOF_MULTIDESTFILES with too many destination files */
1023 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1024 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1025 shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
1026 retval = SHFileOperation(&shfo);
1027 if (dir_exists("testdir2\\a.txt"))
1029 /* Vista and W2K8 (broken or new behavior ?) */
1030 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1031 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1032 RemoveDirectory("testdir2\\a.txt");
1033 ok(DeleteFile("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
1034 RemoveDirectory("testdir2\\b.txt");
1035 ok(DeleteFile("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
1036 RemoveDirectory("testdir2\\c.txt");
1037 ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
1041 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1042 ok(shfo.fAnyOperationsAborted ||
1043 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1044 "Expected aborted operations\n");
1045 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
1048 /* send in FOF_MULTIDESTFILES with too many destination files */
1049 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1050 shfo.pTo = "e.txt\0f.txt\0";
1051 shfo.fAnyOperationsAborted = FALSE;
1052 retval = SHFileOperation(&shfo);
1053 if (dir_exists("e.txt"))
1055 /* Vista and W2K8 (broken or new behavior ?) */
1056 ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
1057 ok(DeleteFile("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
1058 RemoveDirectory("e.txt");
1059 ok(DeleteFile("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
1060 RemoveDirectory("f.txt");
1064 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1065 ok(shfo.fAnyOperationsAborted ||
1066 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1067 "Expected aborted operations\n");
1068 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
1071 /* use FOF_MULTIDESTFILES with files and a source directory */
1072 shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
1073 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
1074 shfo.fAnyOperationsAborted = FALSE;
1075 retval = SHFileOperation(&shfo);
1076 ok(retval == ERROR_SUCCESS ||
1077 broken(retval == 0x100a1), /* WinMe */
1078 "Expected ERROR_SUCCESS, got %d\n", retval);
1079 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1080 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
1081 if (retval == ERROR_SUCCESS)
1082 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
1084 /* try many dest files without FOF_MULTIDESTFILES flag */
1085 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1086 shfo.pTo = "a.txt\0b.txt\0c.txt\0";
1087 shfo.fAnyOperationsAborted = FALSE;
1088 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1089 retval = SHFileOperation(&shfo);
1090 if (dir_exists("a.txt"))
1092 /* Vista and W2K8 (broken or new behavior ?) */
1093 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1094 ok(DeleteFile("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
1095 ok(DeleteFile("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
1096 ok(DeleteFile("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
1097 RemoveDirectory("a.txt");
1101 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1102 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1106 shfo.pFrom = "test?.txt\0";
1107 shfo.pTo = "testdir2\0";
1108 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1109 retval = SHFileOperation(&shfo);
1110 ok(retval == ERROR_SUCCESS ||
1111 broken(retval == 0x100a1), /* WinMe */
1112 "Expected ERROR_SUCCESS, got %d\n", retval);
1113 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1115 /* try a glob with FOF_FILESONLY */
1116 clean_after_shfo_tests();
1118 shfo.pFrom = "test?.txt\0";
1119 shfo.fFlags |= FOF_FILESONLY;
1120 retval = SHFileOperation(&shfo);
1121 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1122 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1123 ok(!dir_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
1125 /* try a glob with FOF_MULTIDESTFILES and the same number
1126 * of dest files that we would expect
1128 clean_after_shfo_tests();
1130 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1131 shfo.fFlags &= ~FOF_FILESONLY;
1132 shfo.fFlags |= FOF_MULTIDESTFILES;
1133 retval = SHFileOperation(&shfo);
1134 if (dir_exists("testdir2\\a.txt"))
1136 /* Vista and W2K8 (broken or new behavior ?) */
1137 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1138 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1139 ok(DeleteFile("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
1140 ok(DeleteFile("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
1141 ok(RemoveDirectory("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
1142 RemoveDirectory("testdir2\\a.txt");
1146 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1147 ok(shfo.fAnyOperationsAborted ||
1148 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1149 "Expected aborted operations\n");
1150 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
1152 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
1154 /* copy one file to two others, second is ignored */
1155 clean_after_shfo_tests();
1157 shfo.pFrom = "test1.txt\0";
1158 shfo.pTo = "b.txt\0c.txt\0";
1159 shfo.fAnyOperationsAborted = FALSE;
1160 retval = SHFileOperation(&shfo);
1161 if (retval == DE_OPCANCELLED)
1163 /* NT4 fails and doesn't copy any files */
1164 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1165 /* Needed to skip some tests */
1166 win_skip("Skipping some tests on NT4\n");
1171 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1172 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1174 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1176 /* copy two file to three others, all fail */
1177 shfo.pFrom = "test1.txt\0test2.txt\0";
1178 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1179 retval = SHFileOperation(&shfo);
1180 if (dir_exists("b.txt"))
1182 /* Vista and W2K8 (broken or new behavior ?) */
1183 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1184 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1185 RemoveDirectory("b.txt");
1186 ok(DeleteFile("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1187 RemoveDirectory("c.txt");
1191 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1192 ok(shfo.fAnyOperationsAborted ||
1193 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1194 "Expected aborted operations\n");
1195 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1198 /* copy one file and one directory to three others */
1199 shfo.pFrom = "test1.txt\0test4.txt\0";
1200 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1201 shfo.fAnyOperationsAborted = FALSE;
1202 retval = SHFileOperation(&shfo);
1203 if (dir_exists("b.txt"))
1205 /* Vista and W2K8 (broken or new behavior ?) */
1206 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1207 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1208 RemoveDirectory("b.txt");
1209 ok(RemoveDirectory("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1210 RemoveDirectory("c.txt");
1214 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1215 ok(shfo.fAnyOperationsAborted ||
1216 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1217 "Expected aborted operations\n");
1218 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1219 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1222 /* copy a directory with a file beneath it, plus some files */
1223 createTestFile("test4.txt\\a.txt");
1224 shfo.pFrom = "test4.txt\0test1.txt\0";
1225 shfo.pTo = "testdir2\0";
1226 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1227 shfo.fAnyOperationsAborted = FALSE;
1228 retval = SHFileOperation(&shfo);
1229 ok(retval == ERROR_SUCCESS ||
1230 broken(retval == 0x100a1), /* WinMe */
1231 "Expected ERROR_SUCCESS, got %d\n", retval);
1232 if (retval == ERROR_SUCCESS)
1234 ok(DeleteFile("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1235 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1236 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1239 /* copy one directory and a file in that dir to another dir */
1240 shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
1241 shfo.pTo = "testdir2\0";
1242 retval = SHFileOperation(&shfo);
1243 ok(retval == ERROR_SUCCESS ||
1244 broken(retval == 0x100a1), /* WinMe */
1245 "Expected ERROR_SUCCESS, got %d\n", retval);
1246 if (retval == ERROR_SUCCESS)
1248 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1249 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1252 /* copy a file in a directory first, and then the directory to a nonexistent dir */
1253 shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
1254 shfo.pTo = "nonexistent\0";
1255 retval = SHFileOperation(&shfo);
1256 if (dir_exists("nonexistent"))
1258 /* Vista and W2K8 (broken or new behavior ?) */
1259 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1260 ok(DeleteFile("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1261 RemoveDirectory("nonexistent\\test4.txt");
1262 ok(DeleteFile("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1263 RemoveDirectory("nonexistent");
1267 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1268 ok(shfo.fAnyOperationsAborted ||
1269 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1270 "Expected aborted operations\n");
1271 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1273 DeleteFile("test4.txt\\a.txt");
1275 /* destination is same as source file */
1276 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1277 shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
1278 shfo.fAnyOperationsAborted = FALSE;
1279 shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
1280 retval = SHFileOperation(&shfo);
1281 if (retval == DE_OPCANCELLED)
1283 /* NT4 fails and doesn't copy any files */
1284 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1288 ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
1289 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1291 ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
1292 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1294 /* destination is same as source directory */
1295 shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
1296 shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
1297 shfo.fAnyOperationsAborted = FALSE;
1298 retval = SHFileOperation(&shfo);
1299 if (retval == DE_OPCANCELLED)
1301 /* NT4 fails and doesn't copy any files */
1302 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1306 ok(retval == ERROR_SUCCESS ||
1307 retval == DE_DESTSAMETREE, /* Vista */
1308 "Expected ERROR_SUCCESS or DE_DESTSAMETREE, got %d\n", retval);
1309 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1311 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1313 /* copy a directory into itself, error displayed in UI */
1314 shfo.pFrom = "test4.txt\0";
1315 shfo.pTo = "test4.txt\\newdir\0";
1316 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1317 shfo.fAnyOperationsAborted = FALSE;
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(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1324 /* copy a directory to itself, error displayed in UI */
1325 shfo.pFrom = "test4.txt\0";
1326 shfo.pTo = "test4.txt\0";
1327 shfo.fAnyOperationsAborted = FALSE;
1328 retval = SHFileOperation(&shfo);
1329 ok(retval == ERROR_SUCCESS ||
1330 retval == DE_DESTSUBTREE, /* Vista */
1331 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1333 /* copy a file into a directory, and the directory into itself */
1334 shfo.pFrom = "test1.txt\0test4.txt\0";
1335 shfo.pTo = "test4.txt\0";
1336 shfo.fAnyOperationsAborted = FALSE;
1337 shfo.fFlags |= FOF_NOCONFIRMATION;
1338 retval = SHFileOperation(&shfo);
1339 ok(retval == ERROR_SUCCESS ||
1340 retval == DE_DESTSUBTREE, /* Vista */
1341 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1342 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1344 /* copy a file to a file, and the directory into itself */
1345 shfo.pFrom = "test1.txt\0test4.txt\0";
1346 shfo.pTo = "test4.txt\\a.txt\0";
1347 shfo.fAnyOperationsAborted = FALSE;
1348 retval = SHFileOperation(&shfo);
1349 if (dir_exists("test4.txt\\a.txt"))
1351 /* Vista and W2K8 (broken or new behavior ?) */
1352 ok(retval == DE_DESTSUBTREE, "Expected DE_DESTSUBTREE, got %d\n", retval);
1353 ok(DeleteFile("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1354 RemoveDirectory("test4.txt\\a.txt");
1358 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1359 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1362 /* copy a nonexistent file to a nonexistent directory */
1363 shfo.pFrom = "e.txt\0";
1364 shfo.pTo = "nonexistent\0";
1365 shfo.fAnyOperationsAborted = FALSE;
1366 retval = SHFileOperation(&shfo);
1367 ok(retval == 1026 ||
1368 retval == ERROR_FILE_NOT_FOUND || /* Vista */
1369 broken(retval == ERROR_SUCCESS), /* NT4 */
1370 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval);
1371 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1372 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1374 /* Overwrite tests */
1375 clean_after_shfo_tests();
1379 /* NT4 would throw up some dialog boxes and doesn't copy files that are needed
1380 * in subsequent tests.
1382 shfo.fFlags = FOF_NOCONFIRMATION;
1383 shfo.pFrom = "test1.txt\0";
1384 shfo.pTo = "test2.txt\0";
1385 shfo.fAnyOperationsAborted = FALSE;
1386 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1387 retval = SHFileOperation(&shfo);
1388 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1389 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1391 shfo.pFrom = "test3.txt\0test1.txt\0";
1392 shfo.pTo = "test2.txt\0one.txt\0";
1393 shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
1394 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1395 retval = SHFileOperation(&shfo);
1396 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1397 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1399 shfo.pFrom = "one.txt\0";
1400 shfo.pTo = "testdir2\0";
1401 shfo.fFlags = FOF_NOCONFIRMATION;
1402 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1403 retval = SHFileOperation(&shfo);
1404 ok(retval == 0, "Expected 0, got %d\n", retval);
1405 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1408 createTestFile("test4.txt\\test1.txt");
1409 shfo.pFrom = "test4.txt\0";
1410 shfo.pTo = "testdir2\0";
1411 /* WinMe needs FOF_NOERRORUI */
1412 shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
1413 retval = SHFileOperation(&shfo);
1414 ok(retval == ERROR_SUCCESS ||
1415 broken(retval == 0x100a1), /* WinMe */
1416 "Expected ERROR_SUCCESS, got %d\n", retval);
1417 shfo.fFlags = FOF_NOCONFIRMATION;
1420 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1421 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1422 retval = SHFileOperation(&shfo);
1423 ok(retval == 0, "Expected 0, got %d\n", retval);
1424 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1427 createTestFile("one.txt");
1429 /* pFrom contains bogus 2nd name longer than MAX_PATH */
1430 memset(from, 'a', MAX_PATH*2);
1431 memset(from+MAX_PATH*2, 0, 2);
1432 lstrcpyA(from, "one.txt");
1434 shfo.pTo = "two.txt\0";
1435 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1436 retval = SHFileOperation(&shfo);
1437 ok(retval == 1148 || retval == 1026 ||
1438 retval == ERROR_ACCESS_DENIED || /* win2k */
1439 retval == DE_INVALIDFILES, /* Vista */
1440 "Unexpected return value, got %d\n", retval);
1441 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1442 if (dir_exists("two.txt"))
1443 /* Vista and W2K8 (broken or new behavior ?) */
1444 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1446 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1448 createTestFile("one.txt");
1450 /* pTo contains bogus 2nd name longer than MAX_PATH */
1451 memset(to, 'a', MAX_PATH*2);
1452 memset(to+MAX_PATH*2, 0, 2);
1453 lstrcpyA(to, "two.txt");
1454 shfo.pFrom = "one.txt\0";
1456 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1457 retval = SHFileOperation(&shfo);
1458 if (retval == DE_OPCANCELLED)
1460 /* NT4 fails and doesn't copy any files */
1461 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1465 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1466 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1468 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1470 createTestFile("one.txt");
1472 /* no FOF_MULTIDESTFILES, two files in pTo */
1473 shfo.pFrom = "one.txt\0";
1474 shfo.pTo = "two.txt\0three.txt\0";
1475 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1476 retval = SHFileOperation(&shfo);
1477 if (retval == DE_OPCANCELLED)
1479 /* NT4 fails and doesn't copy any files */
1480 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1484 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1485 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1487 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1489 createTestFile("one.txt");
1491 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1492 memset(from, 'a', MAX_PATH*2);
1493 memset(from+MAX_PATH*2, 0, 2);
1494 memset(to, 'a', MAX_PATH*2);
1495 memset(to+MAX_PATH*2, 0, 2);
1496 lstrcpyA(from, "one.txt");
1497 lstrcpyA(to, "two.txt");
1500 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1501 retval = SHFileOperation(&shfo);
1502 ok(retval == 1148 || retval == 1026 ||
1503 retval == ERROR_ACCESS_DENIED || /* win2k */
1504 retval == DE_INVALIDFILES, /* Vista */
1505 "Unexpected return value, got %d\n", retval);
1506 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1507 if (dir_exists("two.txt"))
1508 /* Vista and W2K8 (broken or new behavior ?) */
1509 ok(RemoveDirectory("two.txt"), "Expected two.txt to exist\n");
1511 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1513 createTestFile("one.txt");
1515 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1516 memset(to, 'a', MAX_PATH*2);
1517 memset(to+MAX_PATH*2, 0, 2);
1518 lstrcpyA(to, "two.txt");
1519 shfo.pFrom = "one.txt\0";
1521 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1522 FOF_SILENT | FOF_NOERRORUI;
1523 retval = SHFileOperation(&shfo);
1524 if (retval == DE_OPCANCELLED)
1526 /* NT4 fails and doesn't copy any files */
1527 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1531 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1532 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1534 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1536 createTestFile("one.txt");
1537 createTestFile("two.txt");
1539 /* pTo contains bogus 2nd name longer than MAX_PATH,
1540 * multiple source files,
1541 * dest directory does not exist
1543 memset(to, 'a', 2 * MAX_PATH);
1544 memset(to+MAX_PATH*2, 0, 2);
1545 lstrcpyA(to, "threedir");
1546 shfo.pFrom = "one.txt\0two.txt\0";
1548 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1549 retval = SHFileOperation(&shfo);
1550 if (dir_exists("threedir"))
1552 /* Vista and W2K8 (broken or new behavior ?) */
1553 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1554 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1555 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1556 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1560 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1561 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1562 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1563 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1564 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1566 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1567 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1569 createTestFile("one.txt");
1570 createTestFile("two.txt");
1571 CreateDirectoryA("threedir", NULL);
1573 /* pTo contains bogus 2nd name longer than MAX_PATH,
1574 * multiple source files,
1575 * dest directory does exist
1577 memset(to, 'a', 2 * MAX_PATH);
1578 memset(to+MAX_PATH*2, 0, 2);
1579 lstrcpyA(to, "threedir");
1580 shfo.pFrom = "one.txt\0two.txt\0";
1582 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1583 retval = SHFileOperation(&shfo);
1584 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1585 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1586 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1587 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1588 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1589 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1592 /* this crashes on win9x */
1593 createTestFile("one.txt");
1594 createTestFile("two.txt");
1596 /* pTo contains bogus 2nd name longer than MAX_PATH,
1597 * multiple source files, FOF_MULTIDESTFILES
1598 * dest dir does not exist
1601 memset(to, 'a', 2 * MAX_PATH);
1602 memset(to+MAX_PATH*2, 0, 2);
1603 lstrcpyA(to, "threedir");
1604 shfo.pFrom = "one.txt\0two.txt\0";
1606 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1607 FOF_SILENT | FOF_NOERRORUI;
1608 retval = SHFileOperation(&shfo);
1609 ok(retval == ERROR_CANCELLED ||
1610 retval == ERROR_SUCCESS, /* win2k3 */
1611 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval);
1612 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1613 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1614 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1615 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1616 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1618 /* file exists in win2k */
1619 DeleteFileA("threedir");
1623 createTestFile("one.txt");
1624 createTestFile("two.txt");
1625 CreateDirectoryA("threedir", NULL);
1627 /* pTo contains bogus 2nd name longer than MAX_PATH,
1628 * multiple source files, FOF_MULTIDESTFILES
1629 * dest dir does exist
1631 memset(to, 'a', 2 * MAX_PATH);
1632 memset(to+MAX_PATH*2, 0, 2);
1633 lstrcpyA(to, "threedir");
1634 ptr = to + lstrlenA(to) + 1;
1635 lstrcpyA(ptr, "fourdir");
1636 shfo.pFrom = "one.txt\0two.txt\0";
1638 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1639 FOF_SILENT | FOF_NOERRORUI;
1640 retval = SHFileOperation(&shfo);
1641 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1642 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1643 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1644 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1645 if (dir_exists("fourdir"))
1647 /* Vista and W2K8 (broken or new behavior ?) */
1648 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1649 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1650 RemoveDirectoryA("fourdir");
1654 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1655 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1656 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1658 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1660 createTestFile("one.txt");
1661 createTestFile("two.txt");
1662 CreateDirectoryA("threedir", NULL);
1664 /* multiple source files, FOF_MULTIDESTFILES
1665 * multiple dest files, but first dest dir exists
1666 * num files in lists is equal
1668 shfo.pFrom = "one.txt\0two.txt\0";
1669 shfo.pTo = "threedir\0fourdir\0";
1670 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1671 FOF_SILENT | FOF_NOERRORUI;
1672 retval = SHFileOperation(&shfo);
1673 ok(retval == ERROR_CANCELLED ||
1674 retval == DE_FILEDESTISFLD || /* Vista */
1675 broken(retval == DE_OPCANCELLED), /* Win9x, NT4 */
1676 "Expected ERROR_CANCELLED or DE_FILEDESTISFLD. got %d\n", retval);
1677 if (file_exists("threedir\\threedir"))
1680 ok(DeleteFileA("threedir\\threedir"), "Expected file to exist\n");
1682 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1683 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1684 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1685 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1686 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1687 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1688 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1690 createTestFile("one.txt");
1691 createTestFile("two.txt");
1692 CreateDirectoryA("threedir", NULL);
1694 /* multiple source files, FOF_MULTIDESTFILES
1695 * multiple dest files, but first dest dir exists
1696 * num files in lists is not equal
1698 shfo.pFrom = "one.txt\0two.txt\0";
1699 shfo.pTo = "threedir\0fourdir\0five\0";
1700 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1701 FOF_SILENT | FOF_NOERRORUI;
1702 retval = SHFileOperation(&shfo);
1703 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1704 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1705 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1706 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1707 if (dir_exists("fourdir"))
1709 /* Vista and W2K8 (broken or new behavior ?) */
1710 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1711 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1712 RemoveDirectoryA("fourdir");
1716 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1717 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1718 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1720 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1721 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1722 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1724 createTestFile("aa.txt");
1725 createTestFile("ab.txt");
1726 CreateDirectoryA("one", NULL);
1727 CreateDirectoryA("two", NULL);
1729 /* pFrom has a glob, pTo has more than one dest */
1730 shfo.pFrom = "a*.txt\0";
1731 shfo.pTo = "one\0two\0";
1732 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1733 retval = SHFileOperation(&shfo);
1734 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1735 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1736 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1737 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1738 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1739 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1740 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1741 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1742 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1744 /* pTo is an empty string */
1745 CreateDirectoryA("dir", NULL);
1746 createTestFile("dir\\abcdefgh.abc");
1747 shfo.pFrom = "dir\\abcdefgh.abc\0";
1749 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1750 retval = SHFileOperation(&shfo);
1751 ok(retval == ERROR_SUCCESS ||
1752 broken(retval == DE_OPCANCELLED), /* NT4 */
1753 "Expected ERROR_SUCCESS, got %d\n", retval);
1754 if (retval == ERROR_SUCCESS)
1755 ok(DeleteFileA("abcdefgh.abc"), "Expected file to exist\n");
1756 ok(DeleteFileA("dir\\abcdefgh.abc"), "Expected file to exist\n");
1757 ok(RemoveDirectoryA("dir"), "Expected dir to exist\n");
1760 /* tests the FO_MOVE action */
1761 static void test_move(void)
1763 SHFILEOPSTRUCTA shfo, shfo2;
1764 CHAR from[5*MAX_PATH];
1765 CHAR to[5*MAX_PATH];
1769 shfo.wFunc = FO_MOVE;
1772 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1773 shfo.hNameMappings = NULL;
1774 shfo.lpszProgressTitle = NULL;
1776 set_curr_dir_path(from, "test1.txt\0");
1777 set_curr_dir_path(to, "test4.txt\0");
1778 ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
1779 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1780 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1782 set_curr_dir_path(from, "test?.txt\0");
1783 set_curr_dir_path(to, "testdir2\0");
1784 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1785 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1786 ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
1787 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1788 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1789 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1791 clean_after_shfo_tests();
1794 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
1795 shfo2.fFlags |= FOF_MULTIDESTFILES;
1797 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1798 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1800 shfo2.fFlags |= FOF_NOCONFIRMMKDIR;
1801 ok(!SHFileOperationA(&shfo2), "Move many files\n");
1802 ok(DeleteFileA("test6.txt"), "The file is not moved - many files are "
1803 "specified as a target\n");
1804 ok(DeleteFileA("test7.txt"), "The file is not moved\n");
1805 ok(RemoveDirectoryA("test8.txt"), "The directory is not moved\n");
1809 /* number of sources do not correspond to number of targets */
1810 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1811 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
1812 retval = SHFileOperationA(&shfo2);
1813 if (dir_exists("test6.txt"))
1815 if (retval == ERROR_SUCCESS)
1818 DeleteFileA("test6.txt\\test1.txt");
1819 DeleteFileA("test6.txt\\test2.txt");
1820 RemoveDirectoryA("test6.txt\\test4.txt");
1821 RemoveDirectoryA("test6.txt");
1825 /* Vista and W2K8 (broken or new behavior ?) */
1826 ok(retval == DE_DESTSAMETREE, "Expected DE_DESTSAMETREE, got %d\n", retval);
1827 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1828 RemoveDirectoryA("test6.txt");
1829 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1830 RemoveDirectoryA("test7.txt");
1835 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1836 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1837 "specified as a target\n");
1842 set_curr_dir_path(from, "test3.txt\0");
1843 set_curr_dir_path(to, "test4.txt\\test1.txt\0");
1844 ok(!SHFileOperationA(&shfo), "Can't move file to other directory\n");
1845 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1847 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1848 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1850 shfo.fFlags |= FOF_NOCONFIRMMKDIR;
1851 retval = SHFileOperationA(&shfo);
1852 if (dir_exists("test6.txt"))
1855 /* Vista and W2K8 (broken or new behavior ?) */
1856 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1857 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1858 ok(DeleteFileA("test6.txt\\test2.txt"), "The file is not moved. Many files are specified\n");
1859 ok(DeleteFileA("test6.txt\\test4.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
1860 ok(RemoveDirectoryA("test6.txt\\test4.txt"), "The directory is not moved. Many files are specified\n");
1861 RemoveDirectoryA("test6.txt");
1866 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1867 ok(file_exists("test1.txt"), "The file is moved. Many files are specified\n");
1868 ok(dir_exists("test4.txt"), "The directory is moved. Many files are specified\n");
1871 set_curr_dir_path(from, "test1.txt\0");
1872 set_curr_dir_path(to, "test6.txt\0");
1873 ok(!SHFileOperationA(&shfo), "Move file failed\n");
1874 ok(!file_exists("test1.txt"), "The file is not moved\n");
1875 ok(file_exists("test6.txt"), "The file is not moved\n");
1876 set_curr_dir_path(from, "test6.txt\0");
1877 set_curr_dir_path(to, "test1.txt\0");
1878 ok(!SHFileOperationA(&shfo), "Move file back failed\n");
1880 set_curr_dir_path(from, "test4.txt\0");
1881 set_curr_dir_path(to, "test6.txt\0");
1882 ok(!SHFileOperationA(&shfo), "Move dir failed\n");
1883 ok(!dir_exists("test4.txt"), "The dir is not moved\n");
1884 ok(dir_exists("test6.txt"), "The dir is moved\n");
1885 set_curr_dir_path(from, "test6.txt\0");
1886 set_curr_dir_path(to, "test4.txt\0");
1887 ok(!SHFileOperationA(&shfo), "Move dir back failed\n");
1889 /* move one file to two others */
1891 shfo.pFrom = "test1.txt\0";
1892 shfo.pTo = "a.txt\0b.txt\0";
1893 retval = SHFileOperationA(&shfo);
1894 if (retval == DE_OPCANCELLED)
1896 /* NT4 fails and doesn't move any files */
1897 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1898 DeleteFileA("test1.txt");
1902 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1905 DeleteFile("a.txt\\a.txt");
1906 RemoveDirectoryA("a.txt");
1909 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1910 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1912 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1914 /* move two files to one other */
1915 shfo.pFrom = "test2.txt\0test3.txt\0";
1916 shfo.pTo = "test1.txt\0";
1917 retval = SHFileOperationA(&shfo);
1918 if (dir_exists("test1.txt"))
1921 /* Vista and W2K8 (broken or new behavior ?) */
1922 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1923 ok(DeleteFileA("test1.txt\\test2.txt"), "Expected test1.txt\\test2.txt to exist\n");
1924 ok(DeleteFileA("test1.txt\\test3.txt"), "Expected test1.txt\\test3.txt to exist\n");
1925 RemoveDirectoryA("test1.txt");
1926 createTestFile("test2.txt");
1927 createTestFile("test3.txt");
1931 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1932 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1933 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1934 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1937 /* move a directory into itself */
1938 shfo.pFrom = "test4.txt\0";
1939 shfo.pTo = "test4.txt\\b.txt\0";
1940 retval = SHFileOperationA(&shfo);
1941 ok(retval == ERROR_SUCCESS ||
1942 retval == DE_DESTSUBTREE, /* Vista */
1943 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1944 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1945 ok(dir_exists("test4.txt"), "Expected test4.txt to exist\n");
1947 /* move many files without FOF_MULTIDESTFILES */
1948 shfo.pFrom = "test2.txt\0test3.txt\0";
1949 shfo.pTo = "d.txt\0e.txt\0";
1950 retval = SHFileOperationA(&shfo);
1951 if (dir_exists("d.txt"))
1954 /* Vista and W2K8 (broken or new behavior ?) */
1955 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1956 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1957 ok(DeleteFileA("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to exist\n");
1958 RemoveDirectoryA("d.txt");
1959 createTestFile("test2.txt");
1960 createTestFile("test3.txt");
1964 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1965 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1966 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1969 /* number of sources != number of targets */
1970 shfo.pTo = "d.txt\0";
1971 shfo.fFlags |= FOF_MULTIDESTFILES;
1972 retval = SHFileOperationA(&shfo);
1973 if (dir_exists("d.txt"))
1977 DeleteFileA("d.txt\\test2.txt");
1978 DeleteFileA("d.txt\\test3.txt");
1979 RemoveDirectoryA("d.txt");
1980 createTestFile("test2.txt");
1984 /* Vista and W2K8 (broken or new behavior ?) */
1985 ok(retval == DE_SAMEFILE,
1986 "Expected DE_SAMEFILE, got %d\n", retval);
1987 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
1988 ok(!file_exists("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to not exist\n");
1989 RemoveDirectoryA("d.txt");
1990 createTestFile("test2.txt");
1995 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1996 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1999 /* FO_MOVE does not create dest directories */
2000 shfo.pFrom = "test2.txt\0";
2001 shfo.pTo = "dir1\\dir2\\test2.txt\0";
2002 retval = SHFileOperationA(&shfo);
2003 if (dir_exists("dir1"))
2005 /* Vista and W2K8 (broken or new behavior ?) */
2006 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2007 ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n");
2008 RemoveDirectoryA("dir1\\dir2");
2009 RemoveDirectoryA("dir1");
2010 createTestFile("test2.txt");
2014 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
2017 /* try to overwrite an existing file */
2018 shfo.pTo = "test3.txt\0";
2019 retval = SHFileOperationA(&shfo);
2020 if (retval == DE_OPCANCELLED)
2022 /* NT4 fails and doesn't move any files */
2023 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
2027 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2028 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
2031 DeleteFileA("test3.txt\\test3.txt");
2032 RemoveDirectoryA("test3.txt");
2035 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2039 static void test_sh_create_dir(void)
2041 CHAR path[MAX_PATH];
2044 if(!pSHCreateDirectoryExA)
2046 win_skip("skipping SHCreateDirectoryExA tests\n");
2050 set_curr_dir_path(path, "testdir2\\test4.txt\0");
2051 ret = pSHCreateDirectoryExA(NULL, path, NULL);
2052 ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
2053 ok(file_exists("testdir2"), "The first directory is not created\n");
2054 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
2056 ret = pSHCreateDirectoryExA(NULL, path, NULL);
2057 ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
2059 ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
2060 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
2063 static void test_sh_path_prepare(void)
2066 CHAR path[MAX_PATH];
2067 CHAR UNICODE_PATH_A[MAX_PATH];
2069 if(!pSHPathPrepareForWriteA)
2071 win_skip("skipping SHPathPrepareForWriteA tests\n");
2075 /* directory exists, SHPPFW_NONE */
2076 set_curr_dir_path(path, "testdir2\0");
2077 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2078 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2080 /* directory exists, SHPPFW_IGNOREFILENAME */
2081 set_curr_dir_path(path, "testdir2\\test4.txt\0");
2082 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
2083 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2085 /* directory exists, SHPPFW_DIRCREATE */
2086 set_curr_dir_path(path, "testdir2\0");
2087 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2088 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2090 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2091 set_curr_dir_path(path, "testdir2\\test4.txt\0");
2092 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
2093 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2094 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2096 /* file exists, SHPPFW_NONE */
2097 set_curr_dir_path(path, "test1.txt\0");
2098 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2099 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2100 res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2101 res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2102 "Unexpected result : 0x%08x\n", res);
2104 /* file exists, SHPPFW_DIRCREATE */
2105 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2106 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2107 res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2108 res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2109 "Unexpected result : 0x%08x\n", res);
2111 /* file exists, SHPPFW_NONE, trailing \ */
2112 set_curr_dir_path(path, "test1.txt\\\0");
2113 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2114 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2115 res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2116 res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2117 "Unexpected result : 0x%08x\n", res);
2119 /* relative path exists, SHPPFW_DIRCREATE */
2120 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE);
2121 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2123 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
2124 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE);
2125 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2126 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
2128 /* directory doesn't exist, SHPPFW_NONE */
2129 set_curr_dir_path(path, "nonexistent\0");
2130 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2131 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2133 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
2134 set_curr_dir_path(path, "nonexistent\\notreal\0");
2135 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
2136 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2137 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
2138 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2140 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2141 set_curr_dir_path(path, "testdir2\\test4.txt\\\0");
2142 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
2143 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2144 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
2146 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
2147 set_curr_dir_path(path, "nonexistent\\notreal\0");
2148 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2149 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2150 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
2152 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
2154 if(!pSHPathPrepareForWriteW)
2156 win_skip("Skipping SHPathPrepareForWriteW tests\n");
2159 WideCharToMultiByte(CP_ACP, 0, UNICODE_PATH, -1, UNICODE_PATH_A, sizeof(UNICODE_PATH_A), NULL, NULL);
2161 /* unicode directory doesn't exist, SHPPFW_NONE */
2162 RemoveDirectoryA(UNICODE_PATH_A);
2163 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
2164 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2165 ok(!file_exists(UNICODE_PATH_A), "unicode path was created but shouldn't be\n");
2166 RemoveDirectoryA(UNICODE_PATH_A);
2168 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
2169 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
2170 ok(res == S_OK, "res == %08x, expected S_OK\n", res);
2171 ok(file_exists(UNICODE_PATH_A), "unicode path should've been created\n");
2173 /* unicode directory exists, SHPPFW_NONE */
2174 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
2175 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
2177 /* unicode directory exists, SHPPFW_DIRCREATE */
2178 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
2179 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
2180 RemoveDirectoryA(UNICODE_PATH_A);
2183 static void test_sh_new_link_info(void)
2185 BOOL ret, mustcopy=TRUE;
2186 CHAR linkto[MAX_PATH];
2187 CHAR destdir[MAX_PATH];
2188 CHAR result[MAX_PATH];
2189 CHAR result2[MAX_PATH];
2191 /* source file does not exist */
2192 set_curr_dir_path(linkto, "nosuchfile.txt\0");
2193 set_curr_dir_path(destdir, "testdir2\0");
2194 ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2196 broken(ret == lstrlenA(result) + 1), /* NT4 */
2197 "SHGetNewLinkInfoA succeeded\n");
2198 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2200 /* dest dir does not exist */
2201 set_curr_dir_path(linkto, "test1.txt\0");
2202 set_curr_dir_path(destdir, "nosuchdir\0");
2203 ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2205 broken(ret == lstrlenA(result) + 1), /* NT4 */
2206 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2207 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2209 /* source file exists */
2210 set_curr_dir_path(linkto, "test1.txt\0");
2211 set_curr_dir_path(destdir, "testdir2\0");
2212 ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2214 broken(ret == lstrlenA(result) + 1), /* NT4 */
2215 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2216 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2217 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, destdir,
2218 lstrlenA(destdir), result, lstrlenA(destdir)) == CSTR_EQUAL,
2219 "%s does not start with %s\n", result, destdir);
2220 ok(lstrlenA(result) > 4 && lstrcmpiA(result+lstrlenA(result)-4, ".lnk") == 0,
2221 "%s does not end with .lnk\n", result);
2223 /* preferred target name already exists */
2224 createTestFile(result);
2225 ret = SHGetNewLinkInfoA(linkto, destdir, result2, &mustcopy, 0);
2227 broken(ret == lstrlenA(result2) + 1), /* NT4 */
2228 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2229 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2230 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, destdir,
2231 lstrlenA(destdir), result2, lstrlenA(destdir)) == CSTR_EQUAL,
2232 "%s does not start with %s\n", result2, destdir);
2233 ok(lstrlenA(result2) > 4 && lstrcmpiA(result2+lstrlenA(result2)-4, ".lnk") == 0,
2234 "%s does not end with .lnk\n", result2);
2235 ok(lstrcmpiA(result, result2) != 0, "%s and %s are the same\n", result, result2);
2236 DeleteFileA(result);
2239 static void test_unicode(void)
2241 SHFILEOPSTRUCTW shfoW;
2245 if (!pSHFileOperationW)
2247 skip("SHFileOperationW() is missing\n");
2252 shfoW.wFunc = FO_DELETE;
2253 shfoW.pFrom = UNICODE_PATH;
2255 shfoW.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
2256 shfoW.hNameMappings = NULL;
2257 shfoW.lpszProgressTitle = NULL;
2259 /* Clean up before start test */
2260 DeleteFileW(UNICODE_PATH);
2261 RemoveDirectoryW(UNICODE_PATH);
2263 /* Make sure we are on a system that supports unicode */
2264 SetLastError(0xdeadbeef);
2265 file = CreateFileW(UNICODE_PATH, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
2266 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
2268 skip("Unicode tests skipped on non-unicode system\n");
2273 /* Try to delete a file with unicode filename */
2274 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
2275 ret = pSHFileOperationW(&shfoW);
2276 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
2277 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
2279 /* Try to trash a file with unicode filename */
2280 createTestFileW(UNICODE_PATH);
2281 shfoW.fFlags |= FOF_ALLOWUNDO;
2282 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
2283 ret = pSHFileOperationW(&shfoW);
2284 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
2285 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
2287 if(!pSHCreateDirectoryExW)
2289 skip("Skipping SHCreateDirectoryExW tests\n");
2293 /* Try to delete a directory with unicode filename */
2294 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
2295 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
2296 ok(file_existsW(UNICODE_PATH), "The directory is not created\n");
2297 shfoW.fFlags &= ~FOF_ALLOWUNDO;
2298 ret = pSHFileOperationW(&shfoW);
2299 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
2300 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
2302 /* Try to trash a directory with unicode filename */
2303 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
2304 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
2305 ok(file_existsW(UNICODE_PATH), "The directory was not created\n");
2306 shfoW.fFlags |= FOF_ALLOWUNDO;
2307 ret = pSHFileOperationW(&shfoW);
2308 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
2309 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
2312 extern HRESULT WINAPI Shell_MergeMenus (HMENU hmDst, HMENU hmSrc, UINT uInsert, UINT uIDAdjust, UINT uIDAdjustMax, ULONG uFlags);
2315 test_shlmenu(void) {
2317 hres = Shell_MergeMenus (0, 0, 0x42, 0x4242, 0x424242, 0);
2318 ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
2319 hres = Shell_MergeMenus ((HMENU)42, 0, 0x42, 0x4242, 0x424242, 0);
2320 ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
2323 /* Check for old shell32 (4.0.x) */
2324 static BOOL is_old_shell32(void)
2326 SHFILEOPSTRUCTA shfo;
2327 CHAR from[5*MAX_PATH];
2328 CHAR to[5*MAX_PATH];
2332 shfo.wFunc = FO_COPY;
2335 /* FOF_NOCONFIRMMKDIR is needed for old shell32 */
2336 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI | FOF_MULTIDESTFILES | FOF_NOCONFIRMMKDIR;
2337 shfo.hNameMappings = NULL;
2338 shfo.lpszProgressTitle = NULL;
2340 set_curr_dir_path(from, "test1.txt\0test2.txt\0test3.txt\0");
2341 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
2342 retval = SHFileOperationA(&shfo);
2344 /* Delete extra files on old shell32 and Vista+*/
2345 DeleteFileA("test6.txt\\test1.txt");
2346 /* Delete extra files on old shell32 */
2347 DeleteFileA("test6.txt\\test2.txt");
2348 DeleteFileA("test6.txt\\test3.txt");
2349 /* Delete extra directory on old shell32 and Vista+ */
2350 RemoveDirectoryA("test6.txt");
2351 /* Delete extra files/directories on Vista+*/
2352 DeleteFileA("test7.txt\\test2.txt");
2353 RemoveDirectoryA("test7.txt");
2355 if (retval == ERROR_SUCCESS)
2361 START_TEST(shlfileop)
2363 InitFunctionPointers();
2365 clean_after_shfo_tests();
2368 old_shell32 = is_old_shell32();
2370 win_skip("Need to cater for old shell32 (4.0.x) on Win95\n");
2371 clean_after_shfo_tests();
2374 test_get_file_info();
2375 test_get_file_info_iconlist();
2376 clean_after_shfo_tests();
2380 clean_after_shfo_tests();
2384 clean_after_shfo_tests();
2388 clean_after_shfo_tests();
2392 clean_after_shfo_tests();
2394 test_sh_create_dir();
2395 clean_after_shfo_tests();
2398 test_sh_path_prepare();
2399 clean_after_shfo_tests();
2402 test_sh_new_link_info();
2403 clean_after_shfo_tests();