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