[SHELL32_WINETEST] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / rostests / winetests / shell32 / shlfileop.c
1 /*
2 * Unit test of the SHFileOperation function.
3 *
4 * Copyright 2002 Andriy Palamarchuk
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #define WINE_NOWINSOCK
25 #include <windows.h>
26 #include "shellapi.h"
27 #include "shlobj.h"
28
29 #include "wine/test.h"
30
31 #ifndef FOF_NORECURSION
32 #define FOF_NORECURSION 0x1000
33 #endif
34
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)\
46 ok(retval == ret ||\
47 broken(retval == ret_prewin32),\
48 "Expected %d, got %d\n", ret, retval)
49
50 static BOOL old_shell32 = FALSE;
51
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 */
56
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);
64
65 static void InitFunctionPointers(void)
66 {
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");
74 }
75
76 /* creates a file with the specified name for tests */
77 static void createTestFile(const CHAR *name)
78 {
79 HANDLE file;
80 DWORD written;
81
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);
86 CloseHandle(file);
87 }
88
89 static void createTestFileW(const WCHAR *name)
90 {
91 HANDLE file;
92
93 file = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
94 ok(file != INVALID_HANDLE_VALUE, "Failure to open file\n");
95 CloseHandle(file);
96 }
97
98 static BOOL file_exists(const CHAR *name)
99 {
100 return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
101 }
102
103 static BOOL dir_exists(const CHAR *name)
104 {
105 DWORD attr;
106 BOOL dir;
107
108 attr = GetFileAttributesA(name);
109 dir = ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
110
111 return ((attr != INVALID_FILE_ATTRIBUTES) && dir);
112 }
113
114 static BOOL file_existsW(LPCWSTR name)
115 {
116 return GetFileAttributesW(name) != INVALID_FILE_ATTRIBUTES;
117 }
118
119 static BOOL file_has_content(const CHAR *name, const CHAR *content)
120 {
121 CHAR buf[MAX_PATH];
122 HANDLE file;
123 DWORD read;
124
125 file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
126 if (file == INVALID_HANDLE_VALUE)
127 return FALSE;
128 ReadFile(file, buf, MAX_PATH - 1, &read, NULL);
129 buf[read] = 0;
130 CloseHandle(file);
131 return strcmp(buf, content)==0;
132 }
133
134 /* initializes the tests */
135 static void init_shfo_tests(void)
136 {
137 int len;
138
139 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
140 len = lstrlenA(CURR_DIR);
141
142 if(len && (CURR_DIR[len-1] == '\\'))
143 CURR_DIR[len-1] = 0;
144
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");
154 }
155
156 /* cleans after tests */
157 static void clean_after_shfo_tests(void)
158 {
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 DeleteFileA("test4.txt\\one.txt");
168 DeleteFileA("test4.txt\\nested\\two.txt");
169 RemoveDirectoryA("test4.txt\\nested");
170 RemoveDirectoryA("test4.txt");
171 DeleteFileA("testdir2\\one.txt");
172 DeleteFileA("testdir2\\test1.txt");
173 DeleteFileA("testdir2\\test2.txt");
174 DeleteFileA("testdir2\\test3.txt");
175 DeleteFileA("testdir2\\test4.txt\\test1.txt");
176 DeleteFileA("testdir2\\nested\\two.txt");
177 RemoveDirectoryA("testdir2\\test4.txt");
178 RemoveDirectoryA("testdir2\\nested");
179 RemoveDirectoryA("testdir2");
180 RemoveDirectoryA("c:\\testdir3");
181 DeleteFileA("nonexistent\\notreal\\test2.txt");
182 RemoveDirectoryA("nonexistent\\notreal");
183 RemoveDirectoryA("nonexistent");
184 }
185
186
187 static void test_get_file_info(void)
188 {
189 DWORD rc, rc2;
190 SHFILEINFOA shfi, shfi2;
191 SHFILEINFOW shfiw;
192 char notepad[MAX_PATH];
193
194 /* Test whether fields of SHFILEINFOA are always cleared */
195 memset(&shfi, 0xcf, sizeof(shfi));
196 rc=SHGetFileInfoA("", 0, &shfi, sizeof(shfi), 0);
197 ok(rc == 1, "SHGetFileInfoA('' | 0) should return 1, got 0x%x\n", rc);
198 todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA('' | 0) did not clear hIcon\n");
199 todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szDisplayName[0]\n");
200 todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szTypeName[0]\n");
201 ok(shfi.iIcon == 0xcfcfcfcf ||
202 broken(shfi.iIcon != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
203 "SHGetFileInfoA('' | 0) should not clear iIcon\n");
204 ok(shfi.dwAttributes == 0xcfcfcfcf ||
205 broken(shfi.dwAttributes != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
206 "SHGetFileInfoA('' | 0) should not clear dwAttributes\n");
207
208 if (pSHGetFileInfoW)
209 {
210 HANDLE unset_icon;
211 /* Test whether fields of SHFILEINFOW are always cleared */
212 memset(&shfiw, 0xcf, sizeof(shfiw));
213 memset(&unset_icon, 0xcf, sizeof(unset_icon));
214 rc=pSHGetFileInfoW(NULL, 0, &shfiw, sizeof(shfiw), 0);
215 ok(!rc, "SHGetFileInfoW(NULL | 0) should fail\n");
216 ok(shfiw.hIcon == unset_icon, "SHGetFileInfoW(NULL | 0) should not clear hIcon\n");
217 ok(shfiw.szDisplayName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szDisplayName[0]\n");
218 ok(shfiw.szTypeName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szTypeName[0]\n");
219 ok(shfiw.iIcon == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear iIcon\n");
220 ok(shfiw.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear dwAttributes\n");
221 }
222 else
223 win_skip("SHGetFileInfoW is not available\n");
224
225
226 /* Test some flag combinations that MSDN claims are not allowed,
227 * but which work anyway
228 */
229 memset(&shfi, 0xcf, sizeof(shfi));
230 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
231 &shfi, sizeof(shfi),
232 SHGFI_ATTRIBUTES | SHGFI_USEFILEATTRIBUTES);
233 ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should return 1, got 0x%x\n", rc);
234 if (rc)
235 ok(shfi.dwAttributes != 0xcfcfcfcf, "dwFileAttributes is not set\n");
236 todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear hIcon\n");
237 todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szDisplayName[0]\n");
238 todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szTypeName[0]\n");
239 ok(shfi.iIcon == 0xcfcfcfcf ||
240 broken(shfi.iIcon != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
241 "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should not clear iIcon\n");
242
243 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
244 &shfi, sizeof(shfi),
245 SHGFI_EXETYPE | SHGFI_USEFILEATTRIBUTES);
246 todo_wine ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) should return 1, got 0x%x\n", rc);
247
248 /* Test SHGFI_USEFILEATTRIBUTES support */
249 strcpy(shfi.szDisplayName, "dummy");
250 shfi.iIcon=0xdeadbeef;
251 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
252 &shfi, sizeof(shfi),
253 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
254 ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent) should return 1, got 0x%x\n", rc);
255 if (rc)
256 {
257 ok(strcmp(shfi.szDisplayName, "dummy"), "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
258 ok(shfi.iIcon != 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
259 }
260
261 /* Wine does not have a default icon for text files, and Windows 98 fails
262 * if we give it an empty executable. So use notepad.exe as the test
263 */
264 if (SearchPathA(NULL, "notepad.exe", NULL, sizeof(notepad), notepad, NULL))
265 {
266 strcpy(shfi.szDisplayName, "dummy");
267 shfi.iIcon=0xdeadbeef;
268 rc=SHGetFileInfoA(notepad, GetFileAttributesA(notepad),
269 &shfi, sizeof(shfi),
270 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
271 ok(rc == 1, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) should return 1, got 0x%x\n", notepad, rc);
272 strcpy(shfi2.szDisplayName, "dummy");
273 shfi2.iIcon=0xdeadbeef;
274 rc2=SHGetFileInfoA(notepad, 0,
275 &shfi2, sizeof(shfi2),
276 SHGFI_ICONLOCATION);
277 ok(rc2 == 1, "SHGetFileInfoA(%s) failed %x\n", notepad, rc2);
278 if (rc && rc2)
279 {
280 ok(lstrcmpiA(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
281 ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
282 }
283 }
284
285 /* with a directory now */
286 strcpy(shfi.szDisplayName, "dummy");
287 shfi.iIcon=0xdeadbeef;
288 rc=SHGetFileInfoA("test4.txt", GetFileAttributesA("test4.txt"),
289 &shfi, sizeof(shfi),
290 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
291 ok(rc == 1, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) should return 1, got 0x%x\n", rc);
292 strcpy(shfi2.szDisplayName, "dummy");
293 shfi2.iIcon=0xdeadbeef;
294 rc2=SHGetFileInfoA("test4.txt", 0,
295 &shfi2, sizeof(shfi2),
296 SHGFI_ICONLOCATION);
297 ok(rc2 == 1, "SHGetFileInfoA(test4.txt/) should return 1, got 0x%x\n", rc2);
298 if (rc && rc2)
299 {
300 ok(lstrcmpiA(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
301 ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
302 }
303 /* with drive root directory */
304 strcpy(shfi.szDisplayName, "dummy");
305 strcpy(shfi.szTypeName, "dummy");
306 shfi.hIcon=(HICON) 0xdeadbeef;
307 shfi.iIcon=0xdeadbeef;
308 shfi.dwAttributes=0xdeadbeef;
309 rc=SHGetFileInfoA("c:\\", 0, &shfi, sizeof(shfi),
310 SHGFI_TYPENAME | SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON);
311 ok(rc == 1, "SHGetFileInfoA(c:\\) should return 1, got 0x%x\n", rc);
312 ok(strcmp(shfi.szDisplayName, "dummy") != 0, "display name was expected to change\n");
313 ok(strcmp(shfi.szTypeName, "dummy") != 0, "type name was expected to change\n");
314 ok(shfi.hIcon != (HICON) 0xdeadbeef, "hIcon was expected to change\n");
315 ok(shfi.iIcon != 0xdeadbeef, "iIcon was expected to change\n");
316 }
317
318 static void test_get_file_info_iconlist(void)
319 {
320 /* Test retrieving a handle to the system image list, and
321 * what that returns for hIcon
322 */
323 HRESULT hr;
324 HIMAGELIST hSysImageList;
325 LPITEMIDLIST pidList;
326 SHFILEINFOA shInfoa;
327 SHFILEINFOW shInfow;
328
329 hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidList);
330 if (FAILED(hr)) {
331 skip("can't get desktop pidl\n");
332 return;
333 }
334
335 memset(&shInfoa, 0xcf, sizeof(shInfoa));
336 hSysImageList = (HIMAGELIST) SHGetFileInfoA((const char *)pidList, 0,
337 &shInfoa, sizeof(shInfoa),
338 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
339 ok((hSysImageList != INVALID_HANDLE_VALUE) && (hSysImageList > (HIMAGELIST) 0xffff), "Can't get handle for CSIDL_DESKTOP imagelist\n");
340 todo_wine ok(shInfoa.hIcon == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
341 todo_wine ok(shInfoa.szTypeName[0] == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
342 ok(shInfoa.iIcon != 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
343 ok(shInfoa.dwAttributes == 0xcfcfcfcf ||
344 shInfoa.dwAttributes == 0 || /* Vista */
345 broken(shInfoa.dwAttributes != 0xcfcfcfcf), /* NT4 doesn't clear but sets this field */
346 "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL), unexpected dwAttributes\n");
347 CloseHandle(hSysImageList);
348
349 if (!pSHGetFileInfoW)
350 {
351 win_skip("SHGetFileInfoW is not available\n");
352 ILFree(pidList);
353 return;
354 }
355
356 memset(&shInfow, 0xcf, sizeof(shInfow));
357 hSysImageList = (HIMAGELIST) pSHGetFileInfoW((const WCHAR *)pidList, 0,
358 &shInfow, sizeof(shInfow),
359 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
360 if (!hSysImageList)
361 {
362 win_skip("SHGetFileInfoW is not implemented\n");
363 return;
364 }
365 ok((hSysImageList != INVALID_HANDLE_VALUE) && (hSysImageList > (HIMAGELIST) 0xffff), "Can't get handle for CSIDL_DESKTOP imagelist\n");
366 todo_wine ok(shInfow.hIcon == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
367 ok(shInfow.szTypeName[0] == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
368 ok(shInfow.iIcon != 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
369 ok(shInfow.dwAttributes == 0xcfcfcfcf ||
370 shInfoa.dwAttributes == 0, /* Vista */
371 "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) unexpected dwAttributes\n");
372 CloseHandle(hSysImageList);
373
374 /* Various suposidly invalid flag testing */
375 memset(&shInfow, 0xcf, sizeof(shInfow));
376 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
377 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
378 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
379 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
380 ok(shInfow.dwAttributes==0xcfcfcfcf ||
381 shInfoa.dwAttributes==0, /* Vista */
382 "unexpected dwAttributes\n");
383
384 memset(&shInfow, 0xcf, sizeof(shInfow));
385 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
386 SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
387 ok(hr != 0, " SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
388 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
389 ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
390 if (shInfow.hIcon!=(HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
391 todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
392
393 memset(&shInfow, 0xcf, sizeof(shInfow));
394 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
395 SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
396 ok(hr != 0, "SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
397 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
398 ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
399 if (shInfow.hIcon != (HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
400 todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
401
402 memset(&shInfow, 0xcf, sizeof(shInfow));
403 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
404 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
405 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
406 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
407 ok(shInfow.dwAttributes==0xcfcfcfcf ||
408 shInfoa.dwAttributes==0, /* Vista */
409 "unexpected dwAttributes\n");
410
411 memset(&shInfow, 0xcf, sizeof(shInfow));
412 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
413 SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
414 ok(hr != 0, "SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
415 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
416 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
417
418 memset(&shInfow, 0xcf, sizeof(shInfow));
419 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
420 SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
421 ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
422 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
423 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
424
425 memset(&shInfow, 0xcf, sizeof(shInfow));
426 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
427 SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
428 ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
429 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
430 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
431
432 memset(&shInfow, 0xcf, sizeof(shInfow));
433 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
434 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
435 SHGFI_ATTRIBUTES);
436 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
437 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
438 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
439
440 memset(&shInfow, 0xcf, sizeof(shInfow));
441 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
442 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
443 SHGFI_EXETYPE);
444 todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
445 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
446 ok(shInfow.dwAttributes==0xcfcfcfcf ||
447 shInfoa.dwAttributes==0, /* Vista */
448 "unexpected dwAttributes\n");
449
450 memset(&shInfow, 0xcf, sizeof(shInfow));
451 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
452 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE);
453 todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
454 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
455 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
456
457 memset(&shInfow, 0xcf, sizeof(shInfow));
458 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
459 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES);
460 ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
461 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
462 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
463
464 memset(&shInfow, 0xcf, sizeof(shInfow));
465 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
466 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|
467 SHGFI_ATTRIBUTES);
468 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
469 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
470 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
471
472 memset(&shInfow, 0xcf, sizeof(shInfow));
473 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
474 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
475 todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
476 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
477 ok(shInfow.dwAttributes==0xcfcfcfcf ||
478 shInfoa.dwAttributes==0, /* Vista */
479 "unexpected dwAttributes\n");
480
481 memset(&shInfow, 0xcf, sizeof(shInfow));
482 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
483 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
484 todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
485 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
486 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
487
488 memset(&shInfow, 0xcf, sizeof(shInfow));
489 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
490 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES);
491 ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
492 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
493 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
494
495 ILFree(pidList);
496 }
497
498
499 /*
500 puts into the specified buffer file names with current directory.
501 files - string with file names, separated by null characters. Ends on a double
502 null characters
503 */
504 static void set_curr_dir_path(CHAR *buf, const CHAR* files)
505 {
506 buf[0] = 0;
507 while (files[0])
508 {
509 strcpy(buf, CURR_DIR);
510 buf += strlen(buf);
511 buf[0] = '\\';
512 buf++;
513 strcpy(buf, files);
514 buf += strlen(buf) + 1;
515 files += strlen(files) + 1;
516 }
517 buf[0] = 0;
518 }
519
520
521 /* tests the FO_DELETE action */
522 static void test_delete(void)
523 {
524 SHFILEOPSTRUCTA shfo;
525 DWORD ret;
526 CHAR buf[sizeof(CURR_DIR)+sizeof("/test?.txt")+1];
527
528 sprintf(buf, "%s\\%s", CURR_DIR, "test?.txt");
529 buf[strlen(buf) + 1] = '\0';
530
531 shfo.hwnd = NULL;
532 shfo.wFunc = FO_DELETE;
533 shfo.pFrom = buf;
534 shfo.pTo = NULL;
535 shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
536 shfo.hNameMappings = NULL;
537 shfo.lpszProgressTitle = NULL;
538
539 ok(!SHFileOperationA(&shfo), "Deletion was not successful\n");
540 ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
541 ok(!file_exists("test1.txt"), "File should have been removed\n");
542 ok(!file_exists("test2.txt"), "File should have been removed\n");
543 ok(!file_exists("test3.txt"), "File should have been removed\n");
544
545 ret = SHFileOperationA(&shfo);
546 ok(ret == ERROR_SUCCESS, "Directory exists, but is not removed, ret=%d\n", ret);
547 ok(dir_exists("test4.txt"), "Directory should not have been removed\n");
548
549 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
550
551 ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
552 ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
553
554 ret = SHFileOperationA(&shfo);
555 ok(!ret, "The requested file does not exist, ret=%d\n", ret);
556
557 init_shfo_tests();
558 sprintf(buf, "%s\\%s", CURR_DIR, "test4.txt");
559 buf[strlen(buf) + 1] = '\0';
560 ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
561 ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
562 ok(!dir_exists("test4.txt"), "Directory is not removed\n");
563
564 init_shfo_tests();
565 shfo.pFrom = "test1.txt\0test4.txt\0";
566 ok(!SHFileOperationA(&shfo), "Directory and a file are not removed\n");
567 ok(!file_exists("test1.txt"), "The file should have been removed\n");
568 ok(!dir_exists("test4.txt"), "Directory should have been removed\n");
569 ok(file_exists("test2.txt"), "This file should not have been removed\n");
570
571 /* FOF_FILESONLY does not delete a dir matching a wildcard */
572 init_shfo_tests();
573 shfo.fFlags |= FOF_FILESONLY;
574 shfo.pFrom = "*.txt\0";
575 ok(!SHFileOperationA(&shfo), "Failed to delete files\n");
576 ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
577 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
578 ok(dir_exists("test4.txt"), "test4.txt should not have been removed\n");
579
580 /* FOF_FILESONLY only deletes a dir if explicitly specified */
581 init_shfo_tests();
582 shfo.pFrom = "test_?.txt\0test4.txt\0";
583 ok(!SHFileOperationA(&shfo), "Failed to delete files and directory\n");
584 ok(!dir_exists("test4.txt") ||
585 broken(dir_exists("test4.txt")), /* NT4 */
586 "test4.txt should have been removed\n");
587 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
588 ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
589
590 /* try to delete an invalid filename */
591 if (0) {
592 /* this crashes on win9x */
593 init_shfo_tests();
594 shfo.pFrom = "\0";
595 shfo.fFlags &= ~FOF_FILESONLY;
596 shfo.fAnyOperationsAborted = FALSE;
597 ret = SHFileOperationA(&shfo);
598 ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
599 ok(!shfo.fAnyOperationsAborted, "Expected no aborted operations\n");
600 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
601 }
602
603 /* try an invalid function */
604 init_shfo_tests();
605 shfo.pFrom = "test1.txt\0";
606 shfo.wFunc = 0;
607 ret = SHFileOperationA(&shfo);
608 ok(ret == ERROR_INVALID_PARAMETER ||
609 broken(ret == ERROR_SUCCESS), /* Win9x, NT4 */
610 "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
611 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
612
613 /* try an invalid list, only one null terminator */
614 if (0) {
615 /* this crashes on win9x */
616 init_shfo_tests();
617 shfo.pFrom = "";
618 shfo.wFunc = FO_DELETE;
619 ret = SHFileOperationA(&shfo);
620 ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
621 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
622 }
623
624 /* delete a nonexistent file */
625 shfo.pFrom = "nonexistent.txt\0";
626 shfo.wFunc = FO_DELETE;
627 ret = SHFileOperationA(&shfo);
628 ok(ret == 1026 ||
629 ret == ERROR_FILE_NOT_FOUND || /* Vista */
630 broken(ret == ERROR_SUCCESS), /* NT4 */
631 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", ret);
632
633 /* delete a dir, and then a file inside the dir, same as
634 * deleting a nonexistent file
635 */
636 if (ret != ERROR_FILE_NOT_FOUND)
637 {
638 /* Vista would throw up a dialog box that we can't suppress */
639 init_shfo_tests();
640 shfo.pFrom = "testdir2\0testdir2\\one.txt\0";
641 ret = SHFileOperationA(&shfo);
642 ok(ret == ERROR_PATH_NOT_FOUND ||
643 broken(ret == ERROR_SUCCESS), /* NT4 */
644 "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret);
645 ok(!dir_exists("testdir2"), "Expected testdir2 to not exist\n");
646 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
647 }
648 else
649 skip("Test would show a dialog box\n");
650
651 /* delete an existent file and a nonexistent file */
652 init_shfo_tests();
653 shfo.pFrom = "test1.txt\0nonexistent.txt\0test2.txt\0";
654 shfo.wFunc = FO_DELETE;
655 ret = SHFileOperationA(&shfo);
656 ok(ret == 1026 ||
657 ret == ERROR_FILE_NOT_FOUND || /* Vista */
658 broken(ret == ERROR_SUCCESS), /* NT4 */
659 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", ret);
660 todo_wine
661 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
662 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
663
664 /* delete a nonexistent file in an existent dir or a nonexistent dir */
665 init_shfo_tests();
666 shfo.pFrom = "testdir2\\nonexistent.txt\0";
667 ret = SHFileOperationA(&shfo);
668 ok(ret == ERROR_FILE_NOT_FOUND || /* Vista */
669 broken(ret == 0x402) || /* XP */
670 broken(ret == ERROR_SUCCESS), /* NT4 */
671 "Expected 0x402 or ERROR_FILE_NOT_FOUND, got %x\n", ret);
672 shfo.pFrom = "nonexistent\\one.txt\0";
673 ret = SHFileOperationA(&shfo);
674 ok(ret == DE_INVALIDFILES || /* Vista or later */
675 broken(ret == 0x402), /* XP */
676 "Expected 0x402 or DE_INVALIDFILES, got %x\n", ret);
677
678 /* try the FOF_NORECURSION flag, continues deleting subdirs */
679 init_shfo_tests();
680 shfo.pFrom = "testdir2\0";
681 shfo.fFlags |= FOF_NORECURSION;
682 ret = SHFileOperationA(&shfo);
683 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
684 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
685 ok(!dir_exists("testdir2\\nested"), "Expected testdir2\\nested to not exist\n");
686 }
687
688 /* tests the FO_RENAME action */
689 static void test_rename(void)
690 {
691 SHFILEOPSTRUCTA shfo, shfo2;
692 CHAR from[5*MAX_PATH];
693 CHAR to[5*MAX_PATH];
694 DWORD retval;
695
696 shfo.hwnd = NULL;
697 shfo.wFunc = FO_RENAME;
698 shfo.pFrom = from;
699 shfo.pTo = to;
700 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
701 shfo.hNameMappings = NULL;
702 shfo.lpszProgressTitle = NULL;
703
704 set_curr_dir_path(from, "test1.txt\0");
705 set_curr_dir_path(to, "test4.txt\0");
706 retval = SHFileOperationA(&shfo);
707 ok(retval == ERROR_ALREADY_EXISTS ||
708 retval == DE_FILEDESTISFLD || /* Vista */
709 broken(retval == ERROR_INVALID_NAME), /* Win9x, NT4 */
710 "Expected ERROR_ALREADY_EXISTS or DE_FILEDESTISFLD, got %d\n", retval);
711 ok(file_exists("test1.txt"), "The file is renamed\n");
712
713 set_curr_dir_path(from, "test3.txt\0");
714 set_curr_dir_path(to, "test4.txt\\test1.txt\0");
715 retval = SHFileOperationA(&shfo);
716 if (retval == DE_DIFFDIR)
717 {
718 /* Vista and W2K8 (broken or new behavior ?) */
719 ok(!file_exists("test4.txt\\test1.txt"), "The file is renamed\n");
720 }
721 else
722 {
723 ok(retval == ERROR_SUCCESS, "File is renamed moving to other directory\n");
724 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
725 }
726
727 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
728 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
729 retval = SHFileOperationA(&shfo);
730 ok(retval == ERROR_GEN_FAILURE ||
731 retval == DE_MANYSRC1DEST || /* Vista */
732 broken(retval == ERROR_SUCCESS), /* Win9x */
733 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST , got %d\n", retval);
734 ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
735
736 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
737 shfo2.fFlags |= FOF_MULTIDESTFILES;
738
739 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
740 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
741 retval = SHFileOperationA(&shfo2);
742 ok(retval == ERROR_GEN_FAILURE ||
743 retval == DE_MANYSRC1DEST || /* Vista */
744 broken(retval == ERROR_SUCCESS), /* Win9x */
745 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST files, got %d\n", retval);
746 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
747
748 set_curr_dir_path(from, "test1.txt\0");
749 set_curr_dir_path(to, "test6.txt\0");
750 retval = SHFileOperationA(&shfo);
751 ok(retval == ERROR_SUCCESS, "Rename file failed, retval = %d\n", retval);
752 ok(!file_exists("test1.txt"), "The file is not renamed\n");
753 ok(file_exists("test6.txt"), "The file is not renamed\n");
754
755 set_curr_dir_path(from, "test6.txt\0");
756 set_curr_dir_path(to, "test1.txt\0");
757 retval = SHFileOperationA(&shfo);
758 ok(retval == ERROR_SUCCESS, "Rename file back failed, retval = %d\n", retval);
759
760 set_curr_dir_path(from, "test4.txt\0");
761 set_curr_dir_path(to, "test6.txt\0");
762 retval = SHFileOperationA(&shfo);
763 ok(retval == ERROR_SUCCESS, "Rename dir failed, retval = %d\n", retval);
764 ok(!dir_exists("test4.txt"), "The dir is not renamed\n");
765 ok(dir_exists("test6.txt"), "The dir is not renamed\n");
766
767 set_curr_dir_path(from, "test6.txt\0");
768 set_curr_dir_path(to, "test4.txt\0");
769 retval = SHFileOperationA(&shfo);
770 ok(retval == ERROR_SUCCESS, "Rename dir back failed, retval = %d\n", retval);
771 ok(dir_exists("test4.txt"), "The dir is not renamed\n");
772
773 /* try to rename more than one file to a single file */
774 shfo.pFrom = "test1.txt\0test2.txt\0";
775 shfo.pTo = "a.txt\0";
776 retval = SHFileOperationA(&shfo);
777 ok(retval == ERROR_GEN_FAILURE ||
778 retval == DE_MANYSRC1DEST || /* Vista */
779 broken(retval == ERROR_SUCCESS), /* Win9x */
780 "Expected ERROR_GEN_FAILURE or DE_MANYSRC1DEST, got %d\n", retval);
781 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
782 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
783 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
784
785 /* pFrom doesn't exist */
786 shfo.pFrom = "idontexist\0";
787 shfo.pTo = "newfile\0";
788 retval = SHFileOperationA(&shfo);
789 ok(retval == 1026 ||
790 retval == ERROR_FILE_NOT_FOUND || /* Vista */
791 broken(retval == ERROR_SUCCESS), /* NT4 */
792 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval);
793 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
794
795 /* pTo already exist */
796 shfo.pFrom = "test1.txt\0";
797 shfo.pTo = "test2.txt\0";
798 if (old_shell32)
799 shfo.fFlags |= FOF_NOCONFIRMMKDIR;
800 retval = SHFileOperationA(&shfo);
801 if (retval == ERROR_SUCCESS)
802 {
803 /* Vista and W2K8 (broken or new behavior ?) */
804 createTestFile("test1.txt");
805 }
806 else
807 {
808 ok(retval == ERROR_ALREADY_EXISTS ||
809 broken(retval == DE_OPCANCELLED) || /* NT4 */
810 broken(retval == ERROR_INVALID_NAME), /* Win9x */
811 "Expected ERROR_ALREADY_EXISTS, got %d\n", retval);
812 }
813
814 /* pFrom is valid, but pTo is empty */
815 shfo.pFrom = "test1.txt\0";
816 shfo.pTo = "\0";
817 retval = SHFileOperationA(&shfo);
818 ok(retval == ERROR_CANCELLED ||
819 retval == DE_DIFFDIR || /* Vista */
820 broken(retval == DE_OPCANCELLED) || /* Win9x */
821 broken(retval == 65652), /* NT4 */
822 "Expected ERROR_CANCELLED or DE_DIFFDIR\n");
823 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
824
825 /* pFrom is empty */
826 shfo.pFrom = "\0";
827 retval = SHFileOperationA(&shfo);
828 ok(retval == ERROR_ACCESS_DENIED ||
829 retval == DE_MANYSRC1DEST || /* Vista */
830 broken(retval == ERROR_SUCCESS), /* Win9x */
831 "Expected ERROR_ACCESS_DENIED or DE_MANYSRC1DEST, got %d\n", retval);
832
833 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
834 if (0)
835 {
836 shfo.pFrom = NULL;
837 retval = SHFileOperationA(&shfo);
838 ok(retval == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval);
839 }
840 }
841
842 /* tests the FO_COPY action */
843 static void test_copy(void)
844 {
845 SHFILEOPSTRUCTA shfo, shfo2;
846 CHAR from[5*MAX_PATH];
847 CHAR to[5*MAX_PATH];
848 FILEOP_FLAGS tmp_flags;
849 DWORD retval;
850 LPSTR ptr;
851 BOOL on_nt4 = FALSE;
852 BOOL ret;
853
854 if (old_shell32)
855 {
856 win_skip("Too many differences for old shell32\n");
857 return;
858 }
859
860 shfo.hwnd = NULL;
861 shfo.wFunc = FO_COPY;
862 shfo.pFrom = from;
863 shfo.pTo = to;
864 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
865 shfo.hNameMappings = NULL;
866 shfo.lpszProgressTitle = NULL;
867
868 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
869 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
870 retval = SHFileOperationA(&shfo);
871 if (dir_exists("test6.txt"))
872 {
873 /* Vista and W2K8 (broken or new behavior ?) */
874 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
875 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
876 "are specified as a target\n");
877 DeleteFileA("test6.txt\\test2.txt");
878 RemoveDirectoryA("test6.txt\\test4.txt");
879 RemoveDirectoryA("test6.txt");
880 }
881 else
882 {
883 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
884 ok(!file_exists("test6.txt"), "The file is copied - many files are "
885 "specified as a target\n");
886 }
887
888 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
889 shfo2.fFlags |= FOF_MULTIDESTFILES;
890
891 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
892 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
893 ok(!SHFileOperationA(&shfo2), "Can't copy many files\n");
894 ok(file_exists("test6.txt"), "The file is not copied - many files are "
895 "specified as a target\n");
896 DeleteFileA("test6.txt");
897 DeleteFileA("test7.txt");
898 RemoveDirectoryA("test8.txt");
899
900 /* number of sources does not correspond to number of targets */
901 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
902 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
903 retval = SHFileOperationA(&shfo2);
904 if (dir_exists("test6.txt"))
905 {
906 /* Vista and W2K8 (broken or new behavior?) */
907 ok(retval == DE_DESTSAMETREE, "Expected DE_DESTSAMETREE, got %d\n", retval);
908 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not copied - many files "
909 "are specified as a target\n");
910 RemoveDirectoryA("test6.txt");
911 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not copied - many files "
912 "are specified as a target\n");
913 RemoveDirectoryA("test7.txt");
914 }
915 else
916 {
917 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
918 ok(!file_exists("test6.txt"), "The file is copied - many files are "
919 "specified as a target\n");
920 }
921
922 set_curr_dir_path(from, "test1.txt\0");
923 set_curr_dir_path(to, "test4.txt\0");
924 ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively\n");
925 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
926
927 set_curr_dir_path(from, "test?.txt\0");
928 set_curr_dir_path(to, "testdir2\0");
929 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
930 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
931 ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory\n");
932 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
933 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
934 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
935 clean_after_shfo_tests();
936
937 init_shfo_tests();
938 shfo.fFlags |= FOF_FILESONLY;
939 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
940 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
941 ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
942 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
943 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
944 clean_after_shfo_tests();
945
946 init_shfo_tests();
947 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
948 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
949 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
950 ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
951 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
952 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
953 clean_after_shfo_tests();
954
955 /* Copying multiple files with one not existing as source, fails the
956 entire operation in Win98/ME/2K/XP, but not in 95/NT */
957 init_shfo_tests();
958 tmp_flags = shfo.fFlags;
959 set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0");
960 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
961 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
962 retval = SHFileOperationA(&shfo);
963 if (retval == ERROR_SUCCESS)
964 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
965 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
966 else
967 {
968 /* Failure if one source file does not exist */
969 ok(retval == 1026 || /* Win 98/ME/2K/XP */
970 retval == ERROR_FILE_NOT_FOUND, /* Vista and W2K8 */
971 "Files are copied to other directory\n");
972 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
973 }
974 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
975 shfo.fFlags = tmp_flags;
976
977 /* copy into a nonexistent directory */
978 init_shfo_tests();
979 shfo.fFlags = FOF_NOCONFIRMMKDIR;
980 set_curr_dir_path(from, "test1.txt\0");
981 set_curr_dir_path(to, "nonexistent\\notreal\\test2.txt\0");
982 retval= SHFileOperationA(&shfo);
983 ok(!retval, "Error copying into nonexistent directory\n");
984 ok(file_exists("nonexistent"), "nonexistent not created\n");
985 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
986 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
987 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
988
989 /* a relative dest directory is OK */
990 clean_after_shfo_tests();
991 init_shfo_tests();
992 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
993 shfo.pTo = "testdir2\0";
994 retval = SHFileOperationA(&shfo);
995 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
996 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
997
998 /* try to overwrite an existing write protected file */
999 clean_after_shfo_tests();
1000 init_shfo_tests();
1001 tmp_flags = shfo.fFlags;
1002 shfo.pFrom = "test1.txt\0";
1003 shfo.pTo = "test2.txt\0";
1004 /* suppress the error-dialog in win9x here */
1005 shfo.fFlags = FOF_NOERRORUI | FOF_NOCONFIRMATION | FOF_SILENT;
1006 ret = SetFileAttributesA(shfo.pTo, FILE_ATTRIBUTE_READONLY);
1007 ok(ret, "Failure to set file attributes (error %x)\n", GetLastError());
1008 retval = CopyFileA(shfo.pFrom, shfo.pTo, FALSE);
1009 ok(!retval && GetLastError() == ERROR_ACCESS_DENIED, "CopyFileA should have fail with ERROR_ACCESS_DENIED\n");
1010 retval = SHFileOperationA(&shfo);
1011 /* Does not work on Win95, Win95B, NT4WS and NT4SRV */
1012 ok(!retval || broken(retval == DE_OPCANCELLED), "SHFileOperationA failed to copy (error %x)\n", retval);
1013 /* Set back normal attributes to make the file deletion succeed */
1014 ret = SetFileAttributesA(shfo.pTo, FILE_ATTRIBUTE_NORMAL);
1015 ok(ret, "Failure to set file attributes (error %x)\n", GetLastError());
1016 shfo.fFlags = tmp_flags;
1017
1018 /* try to copy files to a file */
1019 clean_after_shfo_tests();
1020 init_shfo_tests();
1021 shfo.pFrom = from;
1022 shfo.pTo = to;
1023 /* suppress the error-dialog in win9x here */
1024 shfo.fFlags |= FOF_NOERRORUI;
1025 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
1026 set_curr_dir_path(to, "test3.txt\0");
1027 shfo.fAnyOperationsAborted = 0xdeadbeef;
1028 retval = SHFileOperationA(&shfo);
1029 ok(shfo.fAnyOperationsAborted != 0xdeadbeef ||
1030 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1031 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1032 if (retval == DE_FLDDESTISFILE || /* Vista and W2K8 */
1033 retval == DE_INVALIDFILES) /* Win7 */
1034 {
1035 /* Most likely new behavior */
1036 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1037 }
1038 else
1039 {
1040 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1041 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
1042 }
1043 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
1044
1045 /* try to copy many files to nonexistent directory */
1046 DeleteFileA(to);
1047 shfo.fFlags &= ~FOF_NOERRORUI;
1048 shfo.fAnyOperationsAborted = 0xdeadbeef;
1049 retval = SHFileOperationA(&shfo);
1050 ok(!shfo.fAnyOperationsAborted ||
1051 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1052 "Didn't expect aborted operations\n");
1053 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1054 ok(DeleteFileA("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
1055 ok(DeleteFileA("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
1056 ok(RemoveDirectoryA(to), "Expected test3.txt to exist\n");
1057
1058 /* send in FOF_MULTIDESTFILES with too many destination files */
1059 init_shfo_tests();
1060 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1061 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1062 shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
1063 shfo.fAnyOperationsAborted = 0xdeadbeef;
1064 retval = SHFileOperationA(&shfo);
1065 ok(shfo.fAnyOperationsAborted != 0xdeadbeef ||
1066 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1067 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1068 if (dir_exists("testdir2\\a.txt"))
1069 {
1070 /* Vista and W2K8 (broken or new behavior ?) */
1071 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1072 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1073 ok(DeleteFileA("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1074 RemoveDirectoryA("testdir2\\a.txt");
1075 ok(DeleteFileA("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
1076 RemoveDirectoryA("testdir2\\b.txt");
1077 ok(DeleteFileA("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
1078 RemoveDirectoryA("testdir2\\c.txt");
1079 ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
1080 }
1081 else
1082 {
1083 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1084 ok(shfo.fAnyOperationsAborted ||
1085 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1086 "Expected aborted operations\n");
1087 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
1088 }
1089
1090 /* send in FOF_MULTIDESTFILES with too many destination files */
1091 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1092 shfo.pTo = "e.txt\0f.txt\0";
1093 shfo.fAnyOperationsAborted = 0xdeadbeef;
1094 retval = SHFileOperationA(&shfo);
1095 ok(shfo.fAnyOperationsAborted != 0xdeadbeef ||
1096 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1097 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1098 if (dir_exists("e.txt"))
1099 {
1100 /* Vista and W2K8 (broken or new behavior ?) */
1101 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1102 ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
1103 ok(DeleteFileA("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
1104 RemoveDirectoryA("e.txt");
1105 ok(DeleteFileA("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
1106 RemoveDirectoryA("f.txt");
1107 }
1108 else
1109 {
1110 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1111 ok(shfo.fAnyOperationsAborted ||
1112 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1113 "Expected aborted operations\n");
1114 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
1115 }
1116
1117 /* use FOF_MULTIDESTFILES with files and a source directory */
1118 shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
1119 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
1120 shfo.fAnyOperationsAborted = 0xdeadbeef;
1121 retval = SHFileOperationA(&shfo);
1122 ok(!shfo.fAnyOperationsAborted ||
1123 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1124 "Didn't expect aborted operations\n");
1125 ok(retval == ERROR_SUCCESS ||
1126 broken(retval == 0x100a1), /* WinMe */
1127 "Expected ERROR_SUCCESS, got %d\n", retval);
1128 ok(DeleteFileA("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1129 ok(DeleteFileA("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
1130 if (retval == ERROR_SUCCESS)
1131 ok(RemoveDirectoryA("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
1132
1133 /* try many dest files without FOF_MULTIDESTFILES flag */
1134 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1135 shfo.pTo = "a.txt\0b.txt\0c.txt\0";
1136 shfo.fAnyOperationsAborted = 0xdeadbeef;
1137 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1138 retval = SHFileOperationA(&shfo);
1139 ok(shfo.fAnyOperationsAborted != 0xdeadbeef ||
1140 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1141 "Expected TRUE/FALSE fAnyOperationsAborted not 0xdeadbeef\n");
1142 if (dir_exists("a.txt"))
1143 {
1144 /* Vista and W2K8 (broken or new behavior ?) */
1145 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1146 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1147 ok(DeleteFileA("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
1148 ok(DeleteFileA("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
1149 ok(DeleteFileA("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
1150 RemoveDirectoryA("a.txt");
1151 }
1152 else
1153 {
1154
1155 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1156 ok(shfo.fAnyOperationsAborted ||
1157 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1158 "Expected aborted operations\n");
1159 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
1160 }
1161
1162 /* try a glob */
1163 shfo.pFrom = "test?.txt\0";
1164 shfo.pTo = "testdir2\0";
1165 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1166 retval = SHFileOperationA(&shfo);
1167 ok(retval == ERROR_SUCCESS ||
1168 broken(retval == 0x100a1), /* WinMe */
1169 "Expected ERROR_SUCCESS, got %d\n", retval);
1170 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1171
1172 /* try a glob with FOF_FILESONLY */
1173 clean_after_shfo_tests();
1174 init_shfo_tests();
1175 shfo.pFrom = "test?.txt\0";
1176 shfo.fFlags |= FOF_FILESONLY;
1177 retval = SHFileOperationA(&shfo);
1178 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1179 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1180 ok(!dir_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
1181
1182 /* try a glob with FOF_MULTIDESTFILES and the same number
1183 * of dest files that we would expect
1184 */
1185 clean_after_shfo_tests();
1186 init_shfo_tests();
1187 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
1188 shfo.fFlags &= ~FOF_FILESONLY;
1189 shfo.fFlags |= FOF_MULTIDESTFILES;
1190 retval = SHFileOperationA(&shfo);
1191 if (dir_exists("testdir2\\a.txt"))
1192 {
1193 /* Vista and W2K8 (broken or new behavior ?) */
1194 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1195 ok(DeleteFileA("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
1196 ok(DeleteFileA("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
1197 ok(DeleteFileA("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
1198 ok(RemoveDirectoryA("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
1199 RemoveDirectoryA("testdir2\\a.txt");
1200 }
1201 else
1202 {
1203 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1204 ok(shfo.fAnyOperationsAborted ||
1205 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1206 "Expected aborted operations\n");
1207 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
1208 }
1209 ok(!RemoveDirectoryA("b.txt"), "b.txt should not exist\n");
1210
1211 /* copy one file to two others, second is ignored */
1212 clean_after_shfo_tests();
1213 init_shfo_tests();
1214 shfo.pFrom = "test1.txt\0";
1215 shfo.pTo = "b.txt\0c.txt\0";
1216 shfo.fAnyOperationsAborted = 0xdeadbeef;
1217 retval = SHFileOperationA(&shfo);
1218 ok(!shfo.fAnyOperationsAborted ||
1219 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1220 "Didn't expect aborted operations\n");
1221 if (retval == DE_OPCANCELLED)
1222 {
1223 /* NT4 fails and doesn't copy any files */
1224 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1225 /* Needed to skip some tests */
1226 win_skip("Skipping some tests on NT4\n");
1227 on_nt4 = TRUE;
1228 }
1229 else
1230 {
1231 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1232 ok(DeleteFileA("b.txt"), "Expected b.txt to exist\n");
1233 }
1234 ok(!DeleteFileA("c.txt"), "Expected c.txt to not exist\n");
1235
1236 /* copy two file to three others, all fail */
1237 shfo.pFrom = "test1.txt\0test2.txt\0";
1238 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1239 shfo.fAnyOperationsAborted = 0xdeadbeef;
1240 retval = SHFileOperationA(&shfo);
1241 if (dir_exists("b.txt"))
1242 {
1243 /* Vista and W2K8 (broken or new behavior ?) */
1244 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1245 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1246 ok(DeleteFileA("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1247 RemoveDirectoryA("b.txt");
1248 ok(DeleteFileA("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1249 RemoveDirectoryA("c.txt");
1250 }
1251 else
1252 {
1253 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1254 ok(shfo.fAnyOperationsAborted ||
1255 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1256 "Expected aborted operations\n");
1257 ok(!DeleteFileA("b.txt"), "Expected b.txt to not exist\n");
1258 }
1259
1260 /* copy one file and one directory to three others */
1261 shfo.pFrom = "test1.txt\0test4.txt\0";
1262 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1263 shfo.fAnyOperationsAborted = 0xdeadbeef;
1264 retval = SHFileOperationA(&shfo);
1265 if (dir_exists("b.txt"))
1266 {
1267 /* Vista and W2K8 (broken or new behavior ?) */
1268 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1269 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1270 ok(DeleteFileA("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1271 RemoveDirectoryA("b.txt");
1272 ok(RemoveDirectoryA("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1273 RemoveDirectoryA("c.txt");
1274 }
1275 else
1276 {
1277 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1278 ok(shfo.fAnyOperationsAborted ||
1279 broken(shfo.fAnyOperationsAborted == 0xdeadbeef), /* NT4 */
1280 "Expected aborted operations\n");
1281 ok(!DeleteFileA("b.txt"), "Expected b.txt to not exist\n");
1282 ok(!DeleteFileA("c.txt"), "Expected c.txt to not exist\n");
1283 }
1284
1285 /* copy a directory with a file beneath it, plus some files */
1286 createTestFile("test4.txt\\a.txt");
1287 shfo.pFrom = "test4.txt\0test1.txt\0";
1288 shfo.pTo = "testdir2\0";
1289 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1290 shfo.fAnyOperationsAborted = FALSE;
1291 retval = SHFileOperationA(&shfo);
1292 ok(retval == ERROR_SUCCESS ||
1293 broken(retval == 0x100a1), /* WinMe */
1294 "Expected ERROR_SUCCESS, got %d\n", retval);
1295 if (retval == ERROR_SUCCESS)
1296 {
1297 ok(DeleteFileA("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
1298 ok(DeleteFileA("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1299 ok(RemoveDirectoryA("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1300 }
1301
1302 /* copy one directory and a file in that dir to another dir */
1303 shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
1304 shfo.pTo = "testdir2\0";
1305 retval = SHFileOperationA(&shfo);
1306 ok(retval == ERROR_SUCCESS ||
1307 broken(retval == 0x100a1), /* WinMe */
1308 "Expected ERROR_SUCCESS, got %d\n", retval);
1309 if (retval == ERROR_SUCCESS)
1310 {
1311 ok(DeleteFileA("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1312 ok(DeleteFileA("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1313 }
1314
1315 /* copy a file in a directory first, and then the directory to a nonexistent dir */
1316 shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
1317 shfo.pTo = "nonexistent\0";
1318 retval = SHFileOperationA(&shfo);
1319 if (dir_exists("nonexistent"))
1320 {
1321 /* Vista and W2K8 (broken or new behavior ?) */
1322 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1323 ok(DeleteFileA("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1324 RemoveDirectoryA("nonexistent\\test4.txt");
1325 ok(DeleteFileA("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1326 RemoveDirectoryA("nonexistent");
1327 }
1328 else
1329 {
1330 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1331 ok(shfo.fAnyOperationsAborted ||
1332 broken(!shfo.fAnyOperationsAborted), /* NT4 */
1333 "Expected aborted operations\n");
1334 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1335 }
1336 DeleteFileA("test4.txt\\a.txt");
1337
1338 /* destination is same as source file */
1339 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1340 shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
1341 shfo.fAnyOperationsAborted = FALSE;
1342 shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
1343 retval = SHFileOperationA(&shfo);
1344 if (retval == DE_OPCANCELLED)
1345 {
1346 /* NT4 fails and doesn't copy any files */
1347 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1348 }
1349 else
1350 {
1351 ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
1352 ok(DeleteFileA("b.txt"), "Expected b.txt to exist\n");
1353 }
1354 ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
1355 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1356
1357 /* destination is same as source directory */
1358 shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
1359 shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
1360 shfo.fAnyOperationsAborted = FALSE;
1361 retval = SHFileOperationA(&shfo);
1362 if (retval == DE_OPCANCELLED)
1363 {
1364 /* NT4 fails and doesn't copy any files */
1365 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1366 }
1367 else
1368 {
1369 ok(retval == ERROR_SUCCESS ||
1370 retval == DE_DESTSAMETREE, /* Vista */
1371 "Expected ERROR_SUCCESS or DE_DESTSAMETREE, got %d\n", retval);
1372 ok(DeleteFileA("b.txt"), "Expected b.txt to exist\n");
1373 }
1374 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1375
1376 /* copy a directory into itself, error displayed in UI */
1377 shfo.pFrom = "test4.txt\0";
1378 shfo.pTo = "test4.txt\\newdir\0";
1379 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1380 shfo.fAnyOperationsAborted = FALSE;
1381 retval = SHFileOperationA(&shfo);
1382 ok(retval == ERROR_SUCCESS ||
1383 retval == DE_DESTSUBTREE, /* Vista */
1384 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1385 ok(!RemoveDirectoryA("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1386
1387 /* copy a directory to itself, error displayed in UI */
1388 shfo.pFrom = "test4.txt\0";
1389 shfo.pTo = "test4.txt\0";
1390 shfo.fAnyOperationsAborted = FALSE;
1391 retval = SHFileOperationA(&shfo);
1392 ok(retval == ERROR_SUCCESS ||
1393 retval == DE_DESTSUBTREE, /* Vista */
1394 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1395
1396 /* copy a file into a directory, and the directory into itself */
1397 shfo.pFrom = "test1.txt\0test4.txt\0";
1398 shfo.pTo = "test4.txt\0";
1399 shfo.fAnyOperationsAborted = FALSE;
1400 shfo.fFlags |= FOF_NOCONFIRMATION;
1401 retval = SHFileOperationA(&shfo);
1402 ok(retval == ERROR_SUCCESS ||
1403 retval == DE_DESTSUBTREE, /* Vista */
1404 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
1405 ok(DeleteFileA("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1406
1407 /* copy a file to a file, and the directory into itself */
1408 shfo.pFrom = "test1.txt\0test4.txt\0";
1409 shfo.pTo = "test4.txt\\a.txt\0";
1410 shfo.fAnyOperationsAborted = FALSE;
1411 retval = SHFileOperationA(&shfo);
1412 if (dir_exists("test4.txt\\a.txt"))
1413 {
1414 /* Vista and W2K8 (broken or new behavior ?) */
1415 ok(retval == DE_DESTSUBTREE, "Expected DE_DESTSUBTREE, got %d\n", retval);
1416 ok(DeleteFileA("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1417 RemoveDirectoryA("test4.txt\\a.txt");
1418 }
1419 else
1420 {
1421 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1422 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1423 }
1424
1425 /* copy a nonexistent file to a nonexistent directory */
1426 shfo.pFrom = "e.txt\0";
1427 shfo.pTo = "nonexistent\0";
1428 shfo.fAnyOperationsAborted = FALSE;
1429 retval = SHFileOperationA(&shfo);
1430 ok(retval == 1026 ||
1431 retval == ERROR_FILE_NOT_FOUND || /* Vista */
1432 broken(retval == ERROR_SUCCESS), /* NT4 */
1433 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval);
1434 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1435 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1436
1437 /* Overwrite tests */
1438 clean_after_shfo_tests();
1439 init_shfo_tests();
1440 if (!on_nt4)
1441 {
1442 /* NT4 would throw up some dialog boxes and doesn't copy files that are needed
1443 * in subsequent tests.
1444 */
1445 shfo.fFlags = FOF_NOCONFIRMATION;
1446 shfo.pFrom = "test1.txt\0";
1447 shfo.pTo = "test2.txt\0";
1448 shfo.fAnyOperationsAborted = 0xdeadbeef;
1449 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1450 retval = SHFileOperationA(&shfo);
1451 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1452 ok(!shfo.fAnyOperationsAborted, "Didn't expect aborted operations\n");
1453 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1454
1455 shfo.pFrom = "test3.txt\0test1.txt\0";
1456 shfo.pTo = "test2.txt\0one.txt\0";
1457 shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
1458 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1459 retval = SHFileOperationA(&shfo);
1460 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1461 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1462
1463 shfo.pFrom = "one.txt\0";
1464 shfo.pTo = "testdir2\0";
1465 shfo.fFlags = FOF_NOCONFIRMATION;
1466 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1467 retval = SHFileOperationA(&shfo);
1468 ok(retval == 0, "Expected 0, got %d\n", retval);
1469 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1470 }
1471
1472 createTestFile("test4.txt\\test1.txt");
1473 shfo.pFrom = "test4.txt\0";
1474 shfo.pTo = "testdir2\0";
1475 /* WinMe needs FOF_NOERRORUI */
1476 shfo.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI;
1477 retval = SHFileOperationA(&shfo);
1478 ok(retval == ERROR_SUCCESS ||
1479 broken(retval == 0x100a1), /* WinMe */
1480 "Expected ERROR_SUCCESS, got %d\n", retval);
1481 shfo.fFlags = FOF_NOCONFIRMATION;
1482 if (ERROR_SUCCESS)
1483 {
1484 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1485 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1486 retval = SHFileOperationA(&shfo);
1487 ok(retval == 0, "Expected 0, got %d\n", retval);
1488 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1489 }
1490
1491 createTestFile("one.txt");
1492
1493 /* pFrom contains bogus 2nd name longer than MAX_PATH */
1494 memset(from, 'a', MAX_PATH*2);
1495 memset(from+MAX_PATH*2, 0, 2);
1496 lstrcpyA(from, "one.txt");
1497 shfo.pFrom = from;
1498 shfo.pTo = "two.txt\0";
1499 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1500 retval = SHFileOperationA(&shfo);
1501 ok(retval == 1148 || retval == 1026 ||
1502 retval == ERROR_ACCESS_DENIED || /* win2k */
1503 retval == DE_INVALIDFILES, /* Vista */
1504 "Unexpected return value, got %d\n", retval);
1505 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1506 if (dir_exists("two.txt"))
1507 /* Vista and W2K8 (broken or new behavior ?) */
1508 ok(RemoveDirectoryA("two.txt"), "Expected two.txt to exist\n");
1509 else
1510 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1511
1512 createTestFile("one.txt");
1513
1514 /* pTo contains bogus 2nd name longer than MAX_PATH */
1515 memset(to, 'a', MAX_PATH*2);
1516 memset(to+MAX_PATH*2, 0, 2);
1517 lstrcpyA(to, "two.txt");
1518 shfo.pFrom = "one.txt\0";
1519 shfo.pTo = to;
1520 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1521 retval = SHFileOperationA(&shfo);
1522 if (retval == DE_OPCANCELLED)
1523 {
1524 /* NT4 fails and doesn't copy any files */
1525 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1526 }
1527 else
1528 {
1529 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1530 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1531 }
1532 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1533
1534 createTestFile("one.txt");
1535
1536 /* no FOF_MULTIDESTFILES, two files in pTo */
1537 shfo.pFrom = "one.txt\0";
1538 shfo.pTo = "two.txt\0three.txt\0";
1539 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1540 retval = SHFileOperationA(&shfo);
1541 if (retval == DE_OPCANCELLED)
1542 {
1543 /* NT4 fails and doesn't copy any files */
1544 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1545 }
1546 else
1547 {
1548 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1549 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1550 }
1551 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1552
1553 createTestFile("one.txt");
1554
1555 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1556 memset(from, 'a', MAX_PATH*2);
1557 memset(from+MAX_PATH*2, 0, 2);
1558 memset(to, 'a', MAX_PATH*2);
1559 memset(to+MAX_PATH*2, 0, 2);
1560 lstrcpyA(from, "one.txt");
1561 lstrcpyA(to, "two.txt");
1562 shfo.pFrom = from;
1563 shfo.pTo = to;
1564 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1565 retval = SHFileOperationA(&shfo);
1566 ok(retval == 1148 || retval == 1026 ||
1567 retval == ERROR_ACCESS_DENIED || /* win2k */
1568 retval == DE_INVALIDFILES, /* Vista */
1569 "Unexpected return value, got %d\n", retval);
1570 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1571 if (dir_exists("two.txt"))
1572 /* Vista and W2K8 (broken or new behavior ?) */
1573 ok(RemoveDirectoryA("two.txt"), "Expected two.txt to exist\n");
1574 else
1575 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1576
1577 createTestFile("one.txt");
1578
1579 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1580 memset(to, 'a', MAX_PATH*2);
1581 memset(to+MAX_PATH*2, 0, 2);
1582 lstrcpyA(to, "two.txt");
1583 shfo.pFrom = "one.txt\0";
1584 shfo.pTo = to;
1585 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1586 FOF_SILENT | FOF_NOERRORUI;
1587 retval = SHFileOperationA(&shfo);
1588 if (retval == DE_OPCANCELLED)
1589 {
1590 /* NT4 fails and doesn't copy any files */
1591 ok(!file_exists("two.txt"), "Expected two.txt to not exist\n");
1592 }
1593 else
1594 {
1595 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1596 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1597 }
1598 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1599
1600 createTestFile("one.txt");
1601 createTestFile("two.txt");
1602
1603 /* pTo contains bogus 2nd name longer than MAX_PATH,
1604 * multiple source files,
1605 * dest directory does not exist
1606 */
1607 memset(to, 'a', 2 * MAX_PATH);
1608 memset(to+MAX_PATH*2, 0, 2);
1609 lstrcpyA(to, "threedir");
1610 shfo.pFrom = "one.txt\0two.txt\0";
1611 shfo.pTo = to;
1612 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1613 retval = SHFileOperationA(&shfo);
1614 if (dir_exists("threedir"))
1615 {
1616 /* Vista and W2K8 (broken or new behavior ?) */
1617 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1618 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1619 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1620 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1621 }
1622 else
1623 {
1624 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1625 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1626 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1627 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1628 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1629 }
1630 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1631 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1632
1633 createTestFile("one.txt");
1634 createTestFile("two.txt");
1635 CreateDirectoryA("threedir", NULL);
1636
1637 /* pTo contains bogus 2nd name longer than MAX_PATH,
1638 * multiple source files,
1639 * dest directory does exist
1640 */
1641 memset(to, 'a', 2 * MAX_PATH);
1642 memset(to+MAX_PATH*2, 0, 2);
1643 lstrcpyA(to, "threedir");
1644 shfo.pFrom = "one.txt\0two.txt\0";
1645 shfo.pTo = to;
1646 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1647 retval = SHFileOperationA(&shfo);
1648 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1649 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1650 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1651 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1652 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1653 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1654
1655 if (0) {
1656 /* this crashes on win9x */
1657 createTestFile("one.txt");
1658 createTestFile("two.txt");
1659
1660 /* pTo contains bogus 2nd name longer than MAX_PATH,
1661 * multiple source files, FOF_MULTIDESTFILES
1662 * dest dir does not exist
1663 */
1664
1665 memset(to, 'a', 2 * MAX_PATH);
1666 memset(to+MAX_PATH*2, 0, 2);
1667 lstrcpyA(to, "threedir");
1668 shfo.pFrom = "one.txt\0two.txt\0";
1669 shfo.pTo = to;
1670 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1671 FOF_SILENT | FOF_NOERRORUI;
1672 retval = SHFileOperationA(&shfo);
1673 ok(retval == ERROR_CANCELLED ||
1674 retval == ERROR_SUCCESS, /* win2k3 */
1675 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval);
1676 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1677 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1678 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1679 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1680 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1681
1682 /* file exists in win2k */
1683 DeleteFileA("threedir");
1684 }
1685
1686
1687 createTestFile("one.txt");
1688 createTestFile("two.txt");
1689 CreateDirectoryA("threedir", NULL);
1690
1691 /* pTo contains bogus 2nd name longer than MAX_PATH,
1692 * multiple source files, FOF_MULTIDESTFILES
1693 * dest dir does exist
1694 */
1695 memset(to, 'a', 2 * MAX_PATH);
1696 memset(to+MAX_PATH*2, 0, 2);
1697 lstrcpyA(to, "threedir");
1698 ptr = to + lstrlenA(to) + 1;
1699 lstrcpyA(ptr, "fourdir");
1700 shfo.pFrom = "one.txt\0two.txt\0";
1701 shfo.pTo = to;
1702 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1703 FOF_SILENT | FOF_NOERRORUI;
1704 retval = SHFileOperationA(&shfo);
1705 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1706 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1707 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1708 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1709 if (dir_exists("fourdir"))
1710 {
1711 /* Vista and W2K8 (broken or new behavior ?) */
1712 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1713 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1714 RemoveDirectoryA("fourdir");
1715 }
1716 else
1717 {
1718 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1719 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1720 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1721 }
1722 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1723
1724 createTestFile("one.txt");
1725 createTestFile("two.txt");
1726 CreateDirectoryA("threedir", NULL);
1727
1728 /* multiple source files, FOF_MULTIDESTFILES
1729 * multiple dest files, but first dest dir exists
1730 * num files in lists is equal
1731 */
1732 shfo.pFrom = "one.txt\0two.txt\0";
1733 shfo.pTo = "threedir\0fourdir\0";
1734 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1735 FOF_SILENT | FOF_NOERRORUI;
1736 retval = SHFileOperationA(&shfo);
1737 ok(retval == ERROR_CANCELLED ||
1738 retval == DE_FILEDESTISFLD || /* Vista */
1739 broken(retval == DE_OPCANCELLED), /* Win9x, NT4 */
1740 "Expected ERROR_CANCELLED or DE_FILEDESTISFLD. got %d\n", retval);
1741 if (file_exists("threedir\\threedir"))
1742 {
1743 /* NT4 */
1744 ok(DeleteFileA("threedir\\threedir"), "Expected file to exist\n");
1745 }
1746 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1747 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1748 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1749 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1750 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1751 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1752 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1753
1754 createTestFile("one.txt");
1755 createTestFile("two.txt");
1756 CreateDirectoryA("threedir", NULL);
1757
1758 /* multiple source files, FOF_MULTIDESTFILES
1759 * multiple dest files, but first dest dir exists
1760 * num files in lists is not equal
1761 */
1762 shfo.pFrom = "one.txt\0two.txt\0";
1763 shfo.pTo = "threedir\0fourdir\0five\0";
1764 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1765 FOF_SILENT | FOF_NOERRORUI;
1766 retval = SHFileOperationA(&shfo);
1767 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1768 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1769 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1770 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1771 if (dir_exists("fourdir"))
1772 {
1773 /* Vista and W2K8 (broken or new behavior ?) */
1774 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1775 ok(DeleteFileA("fourdir\\two.txt"), "Expected file to exist\n");
1776 RemoveDirectoryA("fourdir");
1777 }
1778 else
1779 {
1780 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1781 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1782 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1783 }
1784 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1785 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1786 ok(!RemoveDirectoryA("five"), "Expected dir to not exist\n");
1787
1788 createTestFile("aa.txt");
1789 createTestFile("ab.txt");
1790 CreateDirectoryA("one", NULL);
1791 CreateDirectoryA("two", NULL);
1792
1793 /* pFrom has a glob, pTo has more than one dest */
1794 shfo.pFrom = "a*.txt\0";
1795 shfo.pTo = "one\0two\0";
1796 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1797 retval = SHFileOperationA(&shfo);
1798 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1799 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1800 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1801 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1802 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1803 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1804 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1805 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1806 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1807
1808 /* pTo is an empty string */
1809 CreateDirectoryA("dir", NULL);
1810 createTestFile("dir\\abcdefgh.abc");
1811 shfo.pFrom = "dir\\abcdefgh.abc\0";
1812 shfo.pTo = "\0";
1813 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1814 retval = SHFileOperationA(&shfo);
1815 ok(retval == ERROR_SUCCESS ||
1816 broken(retval == DE_OPCANCELLED), /* NT4 */
1817 "Expected ERROR_SUCCESS, got %d\n", retval);
1818 if (retval == ERROR_SUCCESS)
1819 ok(DeleteFileA("abcdefgh.abc"), "Expected file to exist\n");
1820 ok(DeleteFileA("dir\\abcdefgh.abc"), "Expected file to exist\n");
1821 ok(RemoveDirectoryA("dir"), "Expected dir to exist\n");
1822 }
1823
1824 /* tests the FO_MOVE action */
1825 static void test_move(void)
1826 {
1827 SHFILEOPSTRUCTA shfo, shfo2;
1828 CHAR from[5*MAX_PATH];
1829 CHAR to[5*MAX_PATH];
1830 DWORD retval;
1831
1832 clean_after_shfo_tests();
1833 init_shfo_tests();
1834
1835 shfo.hwnd = NULL;
1836 shfo.wFunc = FO_MOVE;
1837 shfo.pFrom = from;
1838 shfo.pTo = to;
1839 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR;
1840 shfo.hNameMappings = NULL;
1841 shfo.lpszProgressTitle = NULL;
1842 shfo.fAnyOperationsAborted = FALSE;
1843
1844 set_curr_dir_path(from, "testdir2\\*.*\0");
1845 set_curr_dir_path(to, "test4.txt\\*.*\0");
1846 retval = SHFileOperationA(&shfo);
1847 ok(retval != 0, "SHFileOperation should fail\n");
1848 ok(!shfo.fAnyOperationsAborted, "fAnyOperationsAborted %d\n", shfo.fAnyOperationsAborted);
1849
1850 ok(file_exists("testdir2"), "dir should not be moved\n");
1851 ok(file_exists("testdir2\\one.txt"), "file should not be moved\n");
1852 ok(file_exists("testdir2\\nested"), "dir should not be moved\n");
1853 ok(file_exists("testdir2\\nested\\two.txt"), "file should not be moved\n");
1854
1855 set_curr_dir_path(from, "testdir2\\*.*\0");
1856 set_curr_dir_path(to, "test4.txt\0");
1857 retval = SHFileOperationA(&shfo);
1858 ok(!retval, "SHFileOperation error %#x\n", retval);
1859 ok(!shfo.fAnyOperationsAborted, "fAnyOperationsAborted %d\n", shfo.fAnyOperationsAborted);
1860
1861 ok(file_exists("testdir2"), "dir should not be moved\n");
1862 ok(!file_exists("testdir2\\one.txt"), "file should be moved\n");
1863 ok(!file_exists("testdir2\\nested"), "dir should be moved\n");
1864 ok(!file_exists("testdir2\\nested\\two.txt"), "file should be moved\n");
1865
1866 ok(file_exists("test4.txt"), "dir should exist\n");
1867 ok(file_exists("test4.txt\\one.txt"), "file should exist\n");
1868 ok(file_exists("test4.txt\\nested"), "dir should exist\n");
1869 ok(file_exists("test4.txt\\nested\\two.txt"), "file should exist\n");
1870
1871 clean_after_shfo_tests();
1872 init_shfo_tests();
1873
1874 shfo.hwnd = NULL;
1875 shfo.wFunc = FO_MOVE;
1876 shfo.pFrom = from;
1877 shfo.pTo = to;
1878 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1879 shfo.hNameMappings = NULL;
1880 shfo.lpszProgressTitle = NULL;
1881
1882 set_curr_dir_path(from, "test1.txt\0");
1883 set_curr_dir_path(to, "test4.txt\0");
1884 ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
1885 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1886 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1887
1888 set_curr_dir_path(from, "test?.txt\0");
1889 set_curr_dir_path(to, "testdir2\0");
1890 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1891 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1892 ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
1893 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1894 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1895 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1896
1897 clean_after_shfo_tests();
1898 init_shfo_tests();
1899
1900 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
1901 shfo2.fFlags |= FOF_MULTIDESTFILES;
1902
1903 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1904 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1905 if (old_shell32)
1906 shfo2.fFlags |= FOF_NOCONFIRMMKDIR;
1907 ok(!SHFileOperationA(&shfo2), "Move many files\n");
1908 ok(DeleteFileA("test6.txt"), "The file is not moved - many files are "
1909 "specified as a target\n");
1910 ok(DeleteFileA("test7.txt"), "The file is not moved\n");
1911 ok(RemoveDirectoryA("test8.txt"), "The directory is not moved\n");
1912
1913 init_shfo_tests();
1914
1915 /* number of sources does not correspond to number of targets,
1916 include directories */
1917 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1918 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
1919 retval = SHFileOperationA(&shfo2);
1920 if (dir_exists("test6.txt"))
1921 {
1922 if (retval == ERROR_SUCCESS)
1923 {
1924 /* Old shell32 */
1925 DeleteFileA("test6.txt\\test1.txt");
1926 DeleteFileA("test6.txt\\test2.txt");
1927 RemoveDirectoryA("test6.txt\\test4.txt");
1928 RemoveDirectoryA("test6.txt");
1929 }
1930 else
1931 {
1932 /* Vista and W2K8 (broken or new behavior ?) */
1933 ok(retval == DE_DESTSAMETREE, "Expected DE_DESTSAMETREE, got %d\n", retval);
1934 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1935 RemoveDirectoryA("test6.txt");
1936 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1937 RemoveDirectoryA("test7.txt");
1938 }
1939 }
1940 else
1941 {
1942 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1943 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1944 "specified as a target\n");
1945 }
1946
1947 init_shfo_tests();
1948 /* number of sources does not correspond to number of targets,
1949 files only,
1950 from exceeds to */
1951 set_curr_dir_path(from, "test1.txt\0test2.txt\0test3.txt\0");
1952 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
1953 retval = SHFileOperationA(&shfo2);
1954 if (dir_exists("test6.txt"))
1955 {
1956 if (retval == ERROR_SUCCESS)
1957 {
1958 /* Old shell32 */
1959 DeleteFileA("test6.txt\\test1.txt");
1960 DeleteFileA("test6.txt\\test2.txt");
1961 RemoveDirectoryA("test6.txt\\test4.txt");
1962 RemoveDirectoryA("test6.txt");
1963 }
1964 else
1965 {
1966 /* Vista and W2K8 (broken or new behavior ?) */
1967 ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
1968 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved\n");
1969 RemoveDirectoryA("test6.txt");
1970 ok(DeleteFileA("test7.txt\\test2.txt"), "The file is not moved\n");
1971 RemoveDirectoryA("test7.txt");
1972 ok(file_exists("test3.txt"), "File should not be moved\n");
1973 }
1974 }
1975 else
1976 {
1977 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1978 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1979 "specified as a target\n");
1980 }
1981
1982 init_shfo_tests();
1983 /* number of sources does not correspond to number of targets,
1984 files only,
1985 too exceeds from */
1986 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
1987 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1988 retval = SHFileOperationA(&shfo2);
1989 if (dir_exists("test6.txt"))
1990 {
1991 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1992 ok(DeleteFileA("test6.txt\\test1.txt"),"The file is not moved\n");
1993 ok(DeleteFileA("test7.txt\\test2.txt"),"The file is not moved\n");
1994 ok(!dir_exists("test8.txt") && !file_exists("test8.txt"),
1995 "Directory should not be created\n");
1996 RemoveDirectoryA("test6.txt");
1997 RemoveDirectoryA("test7.txt");
1998 }
1999 else
2000 {
2001 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* WinXp, Win2k */);
2002 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
2003 "specified as a target\n");
2004 }
2005
2006 init_shfo_tests();
2007 /* number of sources does not correspond to number of targets,
2008 target directories */
2009 set_curr_dir_path(from, "test1.txt\0test2.txt\0test3.txt\0");
2010 set_curr_dir_path(to, "test4.txt\0test5.txt\0");
2011 retval = SHFileOperationA(&shfo2);
2012 if (dir_exists("test5.txt"))
2013 {
2014 ok(retval == DE_SAMEFILE, "Expected DE_SAMEFILE, got %d\n", retval);
2015 ok(DeleteFileA("test4.txt\\test1.txt"),"The file is not moved\n");
2016 ok(DeleteFileA("test5.txt\\test2.txt"),"The file is not moved\n");
2017 ok(file_exists("test3.txt"), "The file is not moved\n");
2018 RemoveDirectoryA("test4.txt");
2019 RemoveDirectoryA("test5.txt");
2020 }
2021 else
2022 {
2023 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2024 ok(DeleteFileA("test4.txt\\test1.txt"),"The file is not moved\n");
2025 ok(DeleteFileA("test4.txt\\test2.txt"),"The file is not moved\n");
2026 ok(DeleteFileA("test4.txt\\test3.txt"),"The file is not moved\n");
2027 }
2028
2029
2030 init_shfo_tests();
2031 /* 0 incoming files */
2032 set_curr_dir_path(from, "\0\0");
2033 set_curr_dir_path(to, "test6.txt\0\0");
2034 retval = SHFileOperationA(&shfo2);
2035 ok(retval == ERROR_SUCCESS || retval == ERROR_ACCESS_DENIED
2036 , "Expected ERROR_SUCCESS || ERROR_ACCESS_DENIED, got %d\n", retval);
2037 ok(!file_exists("test6.txt"), "The file should not exist\n");
2038
2039 init_shfo_tests();
2040 /* 0 outgoing files */
2041 set_curr_dir_path(from, "test1\0\0");
2042 set_curr_dir_path(to, "\0\0");
2043 retval = SHFileOperationA(&shfo2);
2044 ok(retval == ERROR_FILE_NOT_FOUND ||
2045 broken(retval == 1026)
2046 , "Expected ERROR_FILE_NOT_FOUND, got %d\n", retval);
2047 ok(!file_exists("test6.txt"), "The file should not exist\n");
2048
2049 init_shfo_tests();
2050
2051 set_curr_dir_path(from, "test3.txt\0");
2052 set_curr_dir_path(to, "test4.txt\\test1.txt\0");
2053 ok(!SHFileOperationA(&shfo), "Can't move file to other directory\n");
2054 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
2055
2056 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
2057 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
2058 if (old_shell32)
2059 shfo.fFlags |= FOF_NOCONFIRMMKDIR;
2060 retval = SHFileOperationA(&shfo);
2061 if (dir_exists("test6.txt"))
2062 {
2063 /* Old shell32 */
2064 /* Vista and W2K8 (broken or new behavior ?) */
2065 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2066 ok(DeleteFileA("test6.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
2067 ok(DeleteFileA("test6.txt\\test2.txt"), "The file is not moved. Many files are specified\n");
2068 ok(DeleteFileA("test6.txt\\test4.txt\\test1.txt"), "The file is not moved. Many files are specified\n");
2069 ok(RemoveDirectoryA("test6.txt\\test4.txt"), "The directory is not moved. Many files are specified\n");
2070 RemoveDirectoryA("test6.txt");
2071 init_shfo_tests();
2072 }
2073 else
2074 {
2075 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
2076 ok(file_exists("test1.txt"), "The file is moved. Many files are specified\n");
2077 ok(dir_exists("test4.txt"), "The directory is moved. Many files are specified\n");
2078 }
2079
2080 set_curr_dir_path(from, "test1.txt\0");
2081 set_curr_dir_path(to, "test6.txt\0");
2082 ok(!SHFileOperationA(&shfo), "Move file failed\n");
2083 ok(!file_exists("test1.txt"), "The file is not moved\n");
2084 ok(file_exists("test6.txt"), "The file is not moved\n");
2085 set_curr_dir_path(from, "test6.txt\0");
2086 set_curr_dir_path(to, "test1.txt\0");
2087 ok(!SHFileOperationA(&shfo), "Move file back failed\n");
2088
2089 set_curr_dir_path(from, "test4.txt\0");
2090 set_curr_dir_path(to, "test6.txt\0");
2091 ok(!SHFileOperationA(&shfo), "Move dir failed\n");
2092 ok(!dir_exists("test4.txt"), "The dir is not moved\n");
2093 ok(dir_exists("test6.txt"), "The dir is moved\n");
2094 set_curr_dir_path(from, "test6.txt\0");
2095 set_curr_dir_path(to, "test4.txt\0");
2096 ok(!SHFileOperationA(&shfo), "Move dir back failed\n");
2097
2098 /* move one file to two others */
2099 init_shfo_tests();
2100 shfo.pFrom = "test1.txt\0";
2101 shfo.pTo = "a.txt\0b.txt\0";
2102 retval = SHFileOperationA(&shfo);
2103 if (retval == DE_OPCANCELLED)
2104 {
2105 /* NT4 fails and doesn't move any files */
2106 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
2107 DeleteFileA("test1.txt");
2108 }
2109 else
2110 {
2111 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2112 if (old_shell32)
2113 {
2114 DeleteFileA("a.txt\\a.txt");
2115 RemoveDirectoryA("a.txt");
2116 }
2117 else
2118 ok(DeleteFileA("a.txt"), "Expected a.txt to exist\n");
2119 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
2120 }
2121 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
2122
2123 /* move two files to one other */
2124 shfo.pFrom = "test2.txt\0test3.txt\0";
2125 shfo.pTo = "test1.txt\0";
2126 retval = SHFileOperationA(&shfo);
2127 if (dir_exists("test1.txt"))
2128 {
2129 /* Old shell32 */
2130 /* Vista and W2K8 (broken or new behavior ?) */
2131 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2132 ok(DeleteFileA("test1.txt\\test2.txt"), "Expected test1.txt\\test2.txt to exist\n");
2133 ok(DeleteFileA("test1.txt\\test3.txt"), "Expected test1.txt\\test3.txt to exist\n");
2134 RemoveDirectoryA("test1.txt");
2135 createTestFile("test2.txt");
2136 createTestFile("test3.txt");
2137 }
2138 else
2139 {
2140 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
2141 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
2142 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
2143 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2144 }
2145
2146 /* move a directory into itself */
2147 shfo.pFrom = "test4.txt\0";
2148 shfo.pTo = "test4.txt\\b.txt\0";
2149 retval = SHFileOperationA(&shfo);
2150 ok(retval == ERROR_SUCCESS ||
2151 retval == DE_DESTSUBTREE, /* Vista */
2152 "Expected ERROR_SUCCESS or DE_DESTSUBTREE, got %d\n", retval);
2153 ok(!RemoveDirectoryA("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
2154 ok(dir_exists("test4.txt"), "Expected test4.txt to exist\n");
2155
2156 /* move many files without FOF_MULTIDESTFILES */
2157 shfo.pFrom = "test2.txt\0test3.txt\0";
2158 shfo.pTo = "d.txt\0e.txt\0";
2159 retval = SHFileOperationA(&shfo);
2160 if (dir_exists("d.txt"))
2161 {
2162 /* Old shell32 */
2163 /* Vista and W2K8 (broken or new behavior ?) */
2164 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2165 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
2166 ok(DeleteFileA("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to exist\n");
2167 RemoveDirectoryA("d.txt");
2168 createTestFile("test2.txt");
2169 createTestFile("test3.txt");
2170 }
2171 else
2172 {
2173 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
2174 ok(!DeleteFileA("d.txt"), "Expected d.txt to not exist\n");
2175 ok(!DeleteFileA("e.txt"), "Expected e.txt to not exist\n");
2176 }
2177
2178 /* number of sources != number of targets */
2179 shfo.pTo = "d.txt\0";
2180 shfo.fFlags |= FOF_MULTIDESTFILES;
2181 retval = SHFileOperationA(&shfo);
2182 if (dir_exists("d.txt"))
2183 {
2184 if (old_shell32)
2185 {
2186 DeleteFileA("d.txt\\test2.txt");
2187 DeleteFileA("d.txt\\test3.txt");
2188 RemoveDirectoryA("d.txt");
2189 createTestFile("test2.txt");
2190 }
2191 else
2192 {
2193 /* Vista and W2K8 (broken or new behavior ?) */
2194 ok(retval == DE_SAMEFILE,
2195 "Expected DE_SAMEFILE, got %d\n", retval);
2196 ok(DeleteFileA("d.txt\\test2.txt"), "Expected d.txt\\test2.txt to exist\n");
2197 ok(!file_exists("d.txt\\test3.txt"), "Expected d.txt\\test3.txt to not exist\n");
2198 RemoveDirectoryA("d.txt");
2199 createTestFile("test2.txt");
2200 }
2201 }
2202 else
2203 {
2204 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
2205 ok(!DeleteFileA("d.txt"), "Expected d.txt to not exist\n");
2206 }
2207
2208 /* FO_MOVE should create dest directories */
2209 shfo.pFrom = "test2.txt\0";
2210 shfo.pTo = "dir1\\dir2\\test2.txt\0";
2211 retval = SHFileOperationA(&shfo);
2212 if (dir_exists("dir1"))
2213 {
2214 /* New behavior on Vista or later */
2215 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2216 ok(DeleteFileA("dir1\\dir2\\test2.txt"), "Expected dir1\\dir2\\test2.txt to exist\n");
2217 RemoveDirectoryA("dir1\\dir2");
2218 RemoveDirectoryA("dir1");
2219 createTestFile("test2.txt");
2220 }
2221 else
2222 {
2223 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
2224 }
2225
2226 /* try to overwrite an existing file */
2227 shfo.pTo = "test3.txt\0";
2228 retval = SHFileOperationA(&shfo);
2229 if (retval == DE_OPCANCELLED)
2230 {
2231 /* NT4 fails and doesn't move any files */
2232 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
2233 }
2234 else
2235 {
2236 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
2237 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
2238 if (old_shell32)
2239 {
2240 DeleteFileA("test3.txt\\test3.txt");
2241 RemoveDirectoryA("test3.txt");
2242 }
2243 else
2244 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
2245 }
2246 }
2247
2248 static void test_sh_create_dir(void)
2249 {
2250 CHAR path[MAX_PATH];
2251 int ret;
2252
2253 if(!pSHCreateDirectoryExA)
2254 {
2255 win_skip("skipping SHCreateDirectoryExA tests\n");
2256 return;
2257 }
2258
2259 set_curr_dir_path(path, "testdir2\\test4.txt\0");
2260 ret = pSHCreateDirectoryExA(NULL, path, NULL);
2261 ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
2262 ok(file_exists("testdir2"), "The first directory is not created\n");
2263 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
2264
2265 ret = pSHCreateDirectoryExA(NULL, path, NULL);
2266 ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
2267
2268 ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
2269 ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory, ret = %d\n", ret);
2270 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
2271 }
2272
2273 static void test_sh_path_prepare(void)
2274 {
2275 HRESULT res;
2276 CHAR path[MAX_PATH];
2277 CHAR UNICODE_PATH_A[MAX_PATH];
2278 BOOL UsedDefaultChar;
2279
2280 if(!pSHPathPrepareForWriteA)
2281 {
2282 win_skip("skipping SHPathPrepareForWriteA tests\n");
2283 return;
2284 }
2285
2286 /* directory exists, SHPPFW_NONE */
2287 set_curr_dir_path(path, "testdir2\0");
2288 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2289 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2290
2291 /* directory exists, SHPPFW_IGNOREFILENAME */
2292 set_curr_dir_path(path, "testdir2\\test4.txt\0");
2293 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
2294 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2295
2296 /* directory exists, SHPPFW_DIRCREATE */
2297 set_curr_dir_path(path, "testdir2\0");
2298 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2299 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2300
2301 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2302 set_curr_dir_path(path, "testdir2\\test4.txt\0");
2303 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
2304 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2305 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2306
2307 /* file exists, SHPPFW_NONE */
2308 set_curr_dir_path(path, "test1.txt\0");
2309 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2310 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2311 res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2312 res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2313 "Unexpected result : 0x%08x\n", res);
2314
2315 /* file exists, SHPPFW_DIRCREATE */
2316 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2317 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2318 res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2319 res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2320 "Unexpected result : 0x%08x\n", res);
2321
2322 /* file exists, SHPPFW_NONE, trailing \ */
2323 set_curr_dir_path(path, "test1.txt\\\0");
2324 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2325 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY) ||
2326 res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) || /* WinMe */
2327 res == HRESULT_FROM_WIN32(ERROR_INVALID_NAME), /* Vista */
2328 "Unexpected result : 0x%08x\n", res);
2329
2330 /* relative path exists, SHPPFW_DIRCREATE */
2331 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE);
2332 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2333
2334 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
2335 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE);
2336 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2337 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
2338
2339 /* directory doesn't exist, SHPPFW_NONE */
2340 set_curr_dir_path(path, "nonexistent\0");
2341 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
2342 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2343
2344 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
2345 set_curr_dir_path(path, "nonexistent\\notreal\0");
2346 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
2347 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2348 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
2349 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
2350
2351 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
2352 set_curr_dir_path(path, "testdir2\\test4.txt\\\0");
2353 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
2354 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2355 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
2356
2357 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
2358 set_curr_dir_path(path, "nonexistent\\notreal\0");
2359 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
2360 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
2361 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
2362
2363 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
2364
2365 if(!pSHPathPrepareForWriteW)
2366 {
2367 win_skip("Skipping SHPathPrepareForWriteW tests\n");
2368 return;
2369 }
2370
2371 SetLastError(0xdeadbeef);
2372 UsedDefaultChar = FALSE;
2373 if (WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, UNICODE_PATH, -1, UNICODE_PATH_A, sizeof(UNICODE_PATH_A), NULL, &UsedDefaultChar) == 0)
2374 {
2375 win_skip("Could not convert Unicode path name to multibyte (%d)\n", GetLastError());
2376 return;
2377 }
2378 if (UsedDefaultChar)
2379 {
2380 win_skip("Could not find unique multibyte representation for directory name using default codepage\n");
2381 return;
2382 }
2383
2384 /* unicode directory doesn't exist, SHPPFW_NONE */
2385 RemoveDirectoryA(UNICODE_PATH_A);
2386 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
2387 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
2388 ok(!file_exists(UNICODE_PATH_A), "unicode path was created but shouldn't be\n");
2389 RemoveDirectoryA(UNICODE_PATH_A);
2390
2391 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
2392 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
2393 ok(res == S_OK, "res == %08x, expected S_OK\n", res);
2394 ok(file_exists(UNICODE_PATH_A), "unicode path should've been created\n");
2395
2396 /* unicode directory exists, SHPPFW_NONE */
2397 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
2398 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
2399
2400 /* unicode directory exists, SHPPFW_DIRCREATE */
2401 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
2402 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
2403 RemoveDirectoryA(UNICODE_PATH_A);
2404 }
2405
2406 static void test_sh_new_link_info(void)
2407 {
2408 BOOL ret, mustcopy=TRUE;
2409 CHAR linkto[MAX_PATH];
2410 CHAR destdir[MAX_PATH];
2411 CHAR result[MAX_PATH];
2412 CHAR result2[MAX_PATH];
2413
2414 /* source file does not exist */
2415 set_curr_dir_path(linkto, "nosuchfile.txt\0");
2416 set_curr_dir_path(destdir, "testdir2\0");
2417 ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2418 ok(ret == FALSE ||
2419 broken(ret == lstrlenA(result) + 1), /* NT4 */
2420 "SHGetNewLinkInfoA succeeded\n");
2421 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2422
2423 /* dest dir does not exist */
2424 set_curr_dir_path(linkto, "test1.txt\0");
2425 set_curr_dir_path(destdir, "nosuchdir\0");
2426 ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2427 ok(ret == TRUE ||
2428 broken(ret == lstrlenA(result) + 1), /* NT4 */
2429 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2430 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2431
2432 /* source file exists */
2433 set_curr_dir_path(linkto, "test1.txt\0");
2434 set_curr_dir_path(destdir, "testdir2\0");
2435 ret = SHGetNewLinkInfoA(linkto, destdir, result, &mustcopy, 0);
2436 ok(ret == TRUE ||
2437 broken(ret == lstrlenA(result) + 1), /* NT4 */
2438 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2439 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2440 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, destdir,
2441 lstrlenA(destdir), result, lstrlenA(destdir)) == CSTR_EQUAL,
2442 "%s does not start with %s\n", result, destdir);
2443 ok(lstrlenA(result) > 4 && lstrcmpiA(result+lstrlenA(result)-4, ".lnk") == 0,
2444 "%s does not end with .lnk\n", result);
2445
2446 /* preferred target name already exists */
2447 createTestFile(result);
2448 ret = SHGetNewLinkInfoA(linkto, destdir, result2, &mustcopy, 0);
2449 ok(ret == TRUE ||
2450 broken(ret == lstrlenA(result2) + 1), /* NT4 */
2451 "SHGetNewLinkInfoA failed, err=%i\n", GetLastError());
2452 ok(mustcopy == FALSE, "mustcopy should be FALSE\n");
2453 ok(CompareStringA(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, destdir,
2454 lstrlenA(destdir), result2, lstrlenA(destdir)) == CSTR_EQUAL,
2455 "%s does not start with %s\n", result2, destdir);
2456 ok(lstrlenA(result2) > 4 && lstrcmpiA(result2+lstrlenA(result2)-4, ".lnk") == 0,
2457 "%s does not end with .lnk\n", result2);
2458 ok(lstrcmpiA(result, result2) != 0, "%s and %s are the same\n", result, result2);
2459 DeleteFileA(result);
2460 }
2461
2462 static void test_unicode(void)
2463 {
2464 SHFILEOPSTRUCTW shfoW;
2465 int ret;
2466 HANDLE file;
2467
2468 if (!pSHFileOperationW)
2469 {
2470 skip("SHFileOperationW() is missing\n");
2471 return;
2472 }
2473
2474 shfoW.hwnd = NULL;
2475 shfoW.wFunc = FO_DELETE;
2476 shfoW.pFrom = UNICODE_PATH;
2477 shfoW.pTo = NULL;
2478 shfoW.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
2479 shfoW.hNameMappings = NULL;
2480 shfoW.lpszProgressTitle = NULL;
2481
2482 /* Clean up before start test */
2483 DeleteFileW(UNICODE_PATH);
2484 RemoveDirectoryW(UNICODE_PATH);
2485
2486 /* Make sure we are on a system that supports unicode */
2487 SetLastError(0xdeadbeef);
2488 file = CreateFileW(UNICODE_PATH, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
2489 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
2490 {
2491 skip("Unicode tests skipped on non-unicode system\n");
2492 return;
2493 }
2494 CloseHandle(file);
2495
2496 /* Try to delete a file with unicode filename */
2497 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
2498 ret = pSHFileOperationW(&shfoW);
2499 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
2500 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
2501
2502 /* Try to trash a file with unicode filename */
2503 createTestFileW(UNICODE_PATH);
2504 shfoW.fFlags |= FOF_ALLOWUNDO;
2505 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
2506 ret = pSHFileOperationW(&shfoW);
2507 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
2508 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
2509
2510 if(!pSHCreateDirectoryExW)
2511 {
2512 skip("Skipping SHCreateDirectoryExW tests\n");
2513 return;
2514 }
2515
2516 /* Try to delete a directory with unicode filename */
2517 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
2518 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
2519 ok(file_existsW(UNICODE_PATH), "The directory is not created\n");
2520 shfoW.fFlags &= ~FOF_ALLOWUNDO;
2521 ret = pSHFileOperationW(&shfoW);
2522 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
2523 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
2524
2525 /* Try to trash a directory with unicode filename */
2526 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
2527 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
2528 ok(file_existsW(UNICODE_PATH), "The directory was not created\n");
2529 shfoW.fFlags |= FOF_ALLOWUNDO;
2530 ret = pSHFileOperationW(&shfoW);
2531 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
2532 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
2533 }
2534
2535 static void
2536 test_shlmenu(void) {
2537 HRESULT hres;
2538 hres = Shell_MergeMenus (0, 0, 0x42, 0x4242, 0x424242, 0);
2539 ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
2540 hres = Shell_MergeMenus ((HMENU)42, 0, 0x42, 0x4242, 0x424242, 0);
2541 ok (hres == 0x4242, "expected 0x4242 but got %x\n", hres);
2542 }
2543
2544 /* Check for old shell32 (4.0.x) */
2545 static BOOL is_old_shell32(void)
2546 {
2547 SHFILEOPSTRUCTA shfo;
2548 CHAR from[5*MAX_PATH];
2549 CHAR to[5*MAX_PATH];
2550 DWORD retval;
2551
2552 shfo.hwnd = NULL;
2553 shfo.wFunc = FO_COPY;
2554 shfo.pFrom = from;
2555 shfo.pTo = to;
2556 /* FOF_NOCONFIRMMKDIR is needed for old shell32 */
2557 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI | FOF_MULTIDESTFILES | FOF_NOCONFIRMMKDIR;
2558 shfo.hNameMappings = NULL;
2559 shfo.lpszProgressTitle = NULL;
2560
2561 set_curr_dir_path(from, "test1.txt\0test2.txt\0test3.txt\0");
2562 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
2563 retval = SHFileOperationA(&shfo);
2564
2565 /* Delete extra files on old shell32 and Vista+*/
2566 DeleteFileA("test6.txt\\test1.txt");
2567 /* Delete extra files on old shell32 */
2568 DeleteFileA("test6.txt\\test2.txt");
2569 DeleteFileA("test6.txt\\test3.txt");
2570 /* Delete extra directory on old shell32 and Vista+ */
2571 RemoveDirectoryA("test6.txt");
2572 /* Delete extra files/directories on Vista+*/
2573 DeleteFileA("test7.txt\\test2.txt");
2574 RemoveDirectoryA("test7.txt");
2575
2576 if (retval == ERROR_SUCCESS)
2577 return TRUE;
2578
2579 return FALSE;
2580 }
2581
2582 START_TEST(shlfileop)
2583 {
2584 InitFunctionPointers();
2585
2586 clean_after_shfo_tests();
2587
2588 init_shfo_tests();
2589 old_shell32 = is_old_shell32();
2590 if (old_shell32)
2591 win_skip("Need to cater for old shell32 (4.0.x) on Win95\n");
2592 clean_after_shfo_tests();
2593
2594 init_shfo_tests();
2595 test_get_file_info();
2596 test_get_file_info_iconlist();
2597 clean_after_shfo_tests();
2598
2599 init_shfo_tests();
2600 test_delete();
2601 clean_after_shfo_tests();
2602
2603 init_shfo_tests();
2604 test_rename();
2605 clean_after_shfo_tests();
2606
2607 init_shfo_tests();
2608 test_copy();
2609 clean_after_shfo_tests();
2610
2611 init_shfo_tests();
2612 test_move();
2613 clean_after_shfo_tests();
2614
2615 test_sh_create_dir();
2616 clean_after_shfo_tests();
2617
2618 init_shfo_tests();
2619 test_sh_path_prepare();
2620 clean_after_shfo_tests();
2621
2622 init_shfo_tests();
2623 test_sh_new_link_info();
2624 clean_after_shfo_tests();
2625
2626 test_unicode();
2627
2628 test_shlmenu();
2629 }