shell32/tests: Cope with Vista's behavior.
[wine/wine64.git] / dlls / shell32 / tests / shlfileop.c
blobe81defb31e8d0b07833bf3e05045e6f8ece37f27
1 /*
2 * Unit test of the SHFileOperation function.
4 * Copyright 2002 Andriy Palamarchuk
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define WINE_NOWINSOCK
25 #include <windows.h>
26 #include "shellapi.h"
27 #include "shlobj.h"
29 #include "wine/test.h"
31 #ifndef FOF_NORECURSION
32 #define FOF_NORECURSION 0x1000
33 #endif
35 /* Error codes could be pre-Win32 */
36 #define DE_OPCANCELLED 0x75
37 #define expect_retval(ret, ret_prewin32)\
38 ok(retval == ret ||\
39 broken(retval == ret_prewin32),\
40 "Expected %d, got %d\n", ret, retval)
42 static CHAR CURR_DIR[MAX_PATH];
43 static const WCHAR UNICODE_PATH[] = {'c',':','\\',0x00c4,'\0','\0'};
44 /* "c:\Ä", or "c:\A" with diaeresis */
45 /* Double-null termination needed for pFrom field of SHFILEOPSTRUCT */
47 static HMODULE hshell32;
48 static int (WINAPI *pSHCreateDirectoryExA)(HWND, LPCSTR, LPSECURITY_ATTRIBUTES);
49 static int (WINAPI *pSHCreateDirectoryExW)(HWND, LPCWSTR, LPSECURITY_ATTRIBUTES);
50 static int (WINAPI *pSHFileOperationW)(LPSHFILEOPSTRUCTW);
51 static DWORD_PTR (WINAPI *pSHGetFileInfoW)(LPCWSTR, DWORD , SHFILEINFOW*, UINT, UINT);
52 static int (WINAPI *pSHPathPrepareForWriteA)(HWND, IUnknown*, LPCSTR, DWORD);
53 static int (WINAPI *pSHPathPrepareForWriteW)(HWND, IUnknown*, LPCWSTR, DWORD);
55 static void InitFunctionPointers(void)
57 hshell32 = GetModuleHandleA("shell32.dll");
58 pSHCreateDirectoryExA = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExA");
59 pSHCreateDirectoryExW = (void*)GetProcAddress(hshell32, "SHCreateDirectoryExW");
60 pSHFileOperationW = (void*)GetProcAddress(hshell32, "SHFileOperationW");
61 pSHGetFileInfoW = (void*)GetProcAddress(hshell32, "SHGetFileInfoW");
62 pSHPathPrepareForWriteA = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteA");
63 pSHPathPrepareForWriteW = (void*)GetProcAddress(hshell32, "SHPathPrepareForWriteW");
66 /* creates a file with the specified name for tests */
67 static void createTestFile(const CHAR *name)
69 HANDLE file;
70 DWORD written;
72 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
73 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
74 WriteFile(file, name, strlen(name), &written, NULL);
75 WriteFile(file, "\n", strlen("\n"), &written, NULL);
76 CloseHandle(file);
79 static void createTestFileW(const WCHAR *name)
81 HANDLE file;
83 file = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
84 ok(file != INVALID_HANDLE_VALUE, "Failure to open file\n");
85 CloseHandle(file);
88 static BOOL file_exists(const CHAR *name)
90 return GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES;
93 static BOOL file_existsW(LPCWSTR name)
95 return GetFileAttributesW(name) != INVALID_FILE_ATTRIBUTES;
98 static BOOL file_has_content(const CHAR *name, const CHAR *content)
100 CHAR buf[MAX_PATH];
101 HANDLE file;
102 DWORD read;
104 file = CreateFileA(name, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
105 if (file == INVALID_HANDLE_VALUE)
106 return FALSE;
107 ReadFile(file, buf, MAX_PATH - 1, &read, NULL);
108 buf[read] = 0;
109 CloseHandle(file);
110 return strcmp(buf, content)==0;
113 /* initializes the tests */
114 static void init_shfo_tests(void)
116 int len;
118 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
119 len = lstrlenA(CURR_DIR);
121 if(len && (CURR_DIR[len-1] == '\\'))
122 CURR_DIR[len-1] = 0;
124 createTestFile("test1.txt");
125 createTestFile("test2.txt");
126 createTestFile("test3.txt");
127 createTestFile("test_5.txt");
128 CreateDirectoryA("test4.txt", NULL);
129 CreateDirectoryA("testdir2", NULL);
130 CreateDirectoryA("testdir2\\nested", NULL);
131 createTestFile("testdir2\\one.txt");
132 createTestFile("testdir2\\nested\\two.txt");
135 /* cleans after tests */
136 static void clean_after_shfo_tests(void)
138 DeleteFileA("test1.txt");
139 DeleteFileA("test2.txt");
140 DeleteFileA("test3.txt");
141 DeleteFileA("test_5.txt");
142 DeleteFileA("one.txt");
143 DeleteFileA("test4.txt\\test1.txt");
144 DeleteFileA("test4.txt\\test2.txt");
145 DeleteFileA("test4.txt\\test3.txt");
146 RemoveDirectoryA("test4.txt");
147 DeleteFileA("testdir2\\one.txt");
148 DeleteFileA("testdir2\\test1.txt");
149 DeleteFileA("testdir2\\test2.txt");
150 DeleteFileA("testdir2\\test3.txt");
151 DeleteFileA("testdir2\\test4.txt\\test1.txt");
152 DeleteFileA("testdir2\\nested\\two.txt");
153 RemoveDirectoryA("testdir2\\test4.txt");
154 RemoveDirectoryA("testdir2\\nested");
155 RemoveDirectoryA("testdir2");
156 RemoveDirectoryA("c:\\testdir3");
157 DeleteFileA("nonexistent\\notreal\\test2.txt");
158 RemoveDirectoryA("nonexistent\\notreal");
159 RemoveDirectoryA("nonexistent");
163 static void test_get_file_info(void)
165 DWORD rc, rc2;
166 SHFILEINFOA shfi, shfi2;
167 SHFILEINFOW shfiw;
168 char notepad[MAX_PATH];
170 /* Test whether fields of SHFILEINFOA are always cleared */
171 memset(&shfi, 0xcf, sizeof(shfi));
172 rc=SHGetFileInfoA("", 0, &shfi, sizeof(shfi), 0);
173 ok(rc, "SHGetFileInfoA('' | 0) should not fail\n");
174 todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA('' | 0) did not clear hIcon\n");
175 todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szDisplayName[0]\n");
176 todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA('' | 0) did not clear szTypeName[0]\n");
177 ok(shfi.iIcon == 0xcfcfcfcf, "SHGetFileInfoA('' | 0) should not clear iIcon\n");
178 ok(shfi.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoA('' | 0) should not clear dwAttributes\n");
180 if (pSHGetFileInfoW)
182 /* Test whether fields of SHFILEINFOW are always cleared */
183 memset(&shfiw, 0xcf, sizeof(shfiw));
184 rc=pSHGetFileInfoW(NULL, 0, &shfiw, sizeof(shfiw), 0);
185 todo_wine ok(!rc, "SHGetFileInfoW(NULL | 0) should fail\n");
186 ok(shfiw.hIcon == (HANDLE) 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear hIcon\n");
187 todo_wine ok(shfiw.szDisplayName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szDisplayName[0]\n");
188 todo_wine ok(shfiw.szTypeName[0] == 0xcfcf, "SHGetFileInfoW(NULL | 0) should not clear szTypeName[0]\n");
189 todo_wine ok(shfiw.iIcon == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear iIcon\n");
190 ok(shfiw.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoW(NULL | 0) should not clear dwAttributes\n");
192 else
193 win_skip("SHGetFileInfoW is not available\n");
196 /* Test some flag combinations that MSDN claims are not allowed,
197 * but which work anyway
199 memset(&shfi, 0xcf, sizeof(shfi));
200 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
201 &shfi, sizeof(shfi),
202 SHGFI_ATTRIBUTES | SHGFI_USEFILEATTRIBUTES);
203 ok(rc, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) failed\n");
204 if (rc)
205 ok(shfi.dwAttributes != 0xcfcfcfcf, "dwFileAttributes is not set\n");
206 todo_wine ok(shfi.hIcon == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear hIcon\n");
207 todo_wine ok(shfi.szDisplayName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szDisplayName[0]\n");
208 todo_wine ok(shfi.szTypeName[0] == 0, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) did not clear szTypeName[0]\n");
209 ok(shfi.iIcon == 0xcfcfcfcf, "SHGetFileInfoA(c:\\nonexistent | SHGFI_ATTRIBUTES) should not clear iIcon\n");
211 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
212 &shfi, sizeof(shfi),
213 SHGFI_EXETYPE | SHGFI_USEFILEATTRIBUTES);
214 todo_wine ok(rc == 1, "SHGetFileInfoA(c:\\nonexistent | SHGFI_EXETYPE) returned %d\n", rc);
216 /* Test SHGFI_USEFILEATTRIBUTES support */
217 strcpy(shfi.szDisplayName, "dummy");
218 shfi.iIcon=0xdeadbeef;
219 rc=SHGetFileInfoA("c:\\nonexistent", FILE_ATTRIBUTE_DIRECTORY,
220 &shfi, sizeof(shfi),
221 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
222 ok(rc, "SHGetFileInfoA(c:\\nonexistent) failed\n");
223 if (rc)
225 ok(strcpy(shfi.szDisplayName, "dummy") != 0, "SHGetFileInfoA(c:\\nonexistent) displayname is not set\n");
226 ok(shfi.iIcon != 0xdeadbeef, "SHGetFileInfoA(c:\\nonexistent) iIcon is not set\n");
229 /* Wine does not have a default icon for text files, and Windows 98 fails
230 * if we give it an empty executable. So use notepad.exe as the test
232 if (SearchPath(NULL, "notepad.exe", NULL, sizeof(notepad), notepad, NULL))
234 strcpy(shfi.szDisplayName, "dummy");
235 shfi.iIcon=0xdeadbeef;
236 rc=SHGetFileInfoA(notepad, GetFileAttributes(notepad),
237 &shfi, sizeof(shfi),
238 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
239 ok(rc, "SHGetFileInfoA(%s, SHGFI_USEFILEATTRIBUTES) failed\n", notepad);
240 strcpy(shfi2.szDisplayName, "dummy");
241 shfi2.iIcon=0xdeadbeef;
242 rc2=SHGetFileInfoA(notepad, 0,
243 &shfi2, sizeof(shfi2),
244 SHGFI_ICONLOCATION);
245 ok(rc2, "SHGetFileInfoA(%s) failed\n", notepad);
246 if (rc && rc2)
248 ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
249 ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
253 /* with a directory now */
254 strcpy(shfi.szDisplayName, "dummy");
255 shfi.iIcon=0xdeadbeef;
256 rc=SHGetFileInfoA("test4.txt", GetFileAttributes("test4.txt"),
257 &shfi, sizeof(shfi),
258 SHGFI_ICONLOCATION | SHGFI_USEFILEATTRIBUTES);
259 ok(rc, "SHGetFileInfoA(test4.txt/, SHGFI_USEFILEATTRIBUTES) failed\n");
260 strcpy(shfi2.szDisplayName, "dummy");
261 shfi2.iIcon=0xdeadbeef;
262 rc2=SHGetFileInfoA("test4.txt", 0,
263 &shfi2, sizeof(shfi2),
264 SHGFI_ICONLOCATION);
265 ok(rc2, "SHGetFileInfoA(test4.txt/) failed\n");
266 if (rc && rc2)
268 ok(lstrcmpi(shfi2.szDisplayName, shfi.szDisplayName) == 0, "wrong display name %s != %s\n", shfi.szDisplayName, shfi2.szDisplayName);
269 ok(shfi2.iIcon == shfi.iIcon, "wrong icon index %d != %d\n", shfi.iIcon, shfi2.iIcon);
273 static void test_get_file_info_iconlist(void)
275 /* Test retrieving a handle to the system image list, and
276 * what that returns for hIcon
278 HRESULT hr;
279 HIMAGELIST hSysImageList;
280 LPITEMIDLIST pidList;
281 SHFILEINFOA shInfoa;
282 SHFILEINFOW shInfow;
284 hr = SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidList);
285 if (FAILED(hr)) {
286 skip("can't get desktop pidl\n");
287 return;
290 memset(&shInfoa, 0xcf, sizeof(shInfoa));
291 hSysImageList = (HIMAGELIST) SHGetFileInfoA((const char *)pidList, 0,
292 &shInfoa, sizeof(shInfoa),
293 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
294 ok(hSysImageList != INVALID_HANDLE_VALUE, "Can't get handle for CSIDL_DESKTOP imagelist\n");
295 todo_wine ok(shInfoa.hIcon == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
296 todo_wine ok(shInfoa.szTypeName[0] == 0, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
297 ok(shInfoa.iIcon != 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
298 ok(shInfoa.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoA(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should not change dwAttributes\n");
299 CloseHandle(hSysImageList);
301 if (!pSHGetFileInfoW)
303 win_skip("SHGetFileInfoW is not available\n");
304 ILFree(pidList);
305 return;
308 memset(&shInfow, 0xcf, sizeof(shInfow));
309 hSysImageList = (HIMAGELIST) pSHGetFileInfoW((const WCHAR *)pidList, 0,
310 &shInfow, sizeof(shInfow),
311 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_PIDL);
312 if (!hSysImageList)
314 win_skip("SHGetFileInfoW is not implemented\n");
315 return;
317 ok(hSysImageList != INVALID_HANDLE_VALUE, "Can't get handle for CSIDL_DESKTOP imagelist\n");
318 todo_wine ok(shInfow.hIcon == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear hIcon\n");
319 ok(shInfow.szTypeName[0] == 0, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) did not clear szTypeName[0]\n");
320 ok(shInfow.iIcon != 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should set iIcon\n");
321 ok(shInfow.dwAttributes == 0xcfcfcfcf, "SHGetFileInfoW(CSIDL_DESKTOP, SHGFI_SYSICONINDEX|SHGFI_SMALLICON|SHGFI_PIDL) should not change dwAttributes\n");
322 CloseHandle(hSysImageList);
324 /* Various suposidly invalid flag testing */
325 memset(&shInfow, 0xcf, sizeof(shInfow));
326 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
327 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
328 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
329 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
330 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
332 memset(&shInfow, 0xcf, sizeof(shInfow));
333 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
334 SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
335 ok(hr != 0, " SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
336 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
337 ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
338 if (shInfow.hIcon!=(HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
339 todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
341 memset(&shInfow, 0xcf, sizeof(shInfow));
342 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
343 SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
344 ok(hr != 0, "SHGFI_ICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
345 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
346 ok(shInfow.hIcon!=(HICON)0xcfcfcfcf && shInfow.hIcon!=0,"hIcon invalid\n");
347 if (shInfow.hIcon != (HICON)0xcfcfcfcf) DestroyIcon(shInfow.hIcon);
348 todo_wine ok(shInfow.dwAttributes==0,"dwAttributes not set\n");
350 memset(&shInfow, 0xcf, sizeof(shInfow));
351 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
352 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON);
353 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_LARGEICON Failed\n");
354 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
355 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
357 memset(&shInfow, 0xcf, sizeof(shInfow));
358 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
359 SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
360 ok(hr != 0, "SHGFI_OPENICON|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
361 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
362 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
364 memset(&shInfow, 0xcf, sizeof(shInfow));
365 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
366 SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
367 ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
368 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
369 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
371 memset(&shInfow, 0xcf, sizeof(shInfow));
372 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
373 SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON);
374 ok(hr != 0, "SHGFI_SHELLICONSIZE|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON Failed\n");
375 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
376 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
378 memset(&shInfow, 0xcf, sizeof(shInfow));
379 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
380 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
381 SHGFI_ATTRIBUTES);
382 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
383 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
384 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
386 memset(&shInfow, 0xcf, sizeof(shInfow));
387 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
388 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|
389 SHGFI_EXETYPE);
390 todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
391 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
392 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
394 memset(&shInfow, 0xcf, sizeof(shInfow));
395 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
396 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE);
397 todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_EXETYPE Failed\n");
398 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
399 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
401 memset(&shInfow, 0xcf, sizeof(shInfow));
402 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
403 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES);
404 ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_SMALLICON|SHGFI_ATTRIBUTES Failed\n");
405 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
406 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
408 memset(&shInfow, 0xcf, sizeof(shInfow));
409 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
410 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|
411 SHGFI_ATTRIBUTES);
412 ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
413 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
414 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
416 memset(&shInfow, 0xcf, sizeof(shInfow));
417 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
418 SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
419 todo_wine ok(hr != 0, "SHGFI_SYSICONINDEX|SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
420 ok(shInfow.iIcon!=0xcfcfcfcf, "Icon Index Missing\n");
421 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
423 memset(&shInfow, 0xcf, sizeof(shInfow));
424 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
425 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE);
426 todo_wine ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_EXETYPE Failed\n");
427 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
428 ok(shInfow.dwAttributes==0xcfcfcfcf,"dwAttributes modified\n");
430 memset(&shInfow, 0xcf, sizeof(shInfow));
431 hr = pSHGetFileInfoW((const WCHAR *)pidList, 0, &shInfow, sizeof(shInfow),
432 SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES);
433 ok(hr != 0, "SHGFI_USEFILEATTRIBUTES|SHGFI_PIDL|SHGFI_ATTRIBUTES Failed\n");
434 todo_wine ok(shInfow.iIcon==0xcfcfcfcf, "Icon Index Modified\n");
435 ok(shInfow.dwAttributes!=0xcfcfcfcf,"dwAttributes not set\n");
437 ILFree(pidList);
442 puts into the specified buffer file names with current directory.
443 files - string with file names, separated by null characters. Ends on a double
444 null characters
446 static void set_curr_dir_path(CHAR *buf, const CHAR* files)
448 buf[0] = 0;
449 while (files[0])
451 strcpy(buf, CURR_DIR);
452 buf += strlen(buf);
453 buf[0] = '\\';
454 buf++;
455 strcpy(buf, files);
456 buf += strlen(buf) + 1;
457 files += strlen(files) + 1;
459 buf[0] = 0;
463 /* tests the FO_DELETE action */
464 static void test_delete(void)
466 SHFILEOPSTRUCTA shfo;
467 DWORD ret;
468 CHAR buf[sizeof(CURR_DIR)+sizeof("/test?.txt")+1];
470 sprintf(buf, "%s\\%s", CURR_DIR, "test?.txt");
471 buf[strlen(buf) + 1] = '\0';
473 shfo.hwnd = NULL;
474 shfo.wFunc = FO_DELETE;
475 shfo.pFrom = buf;
476 shfo.pTo = "\0";
477 shfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;
478 shfo.hNameMappings = NULL;
479 shfo.lpszProgressTitle = NULL;
481 ok(!SHFileOperationA(&shfo), "Deletion was not successful\n");
482 ok(file_exists("test4.txt"), "Directory should not have been removed\n");
483 ok(!file_exists("test1.txt"), "File should have been removed\n");
485 ret = SHFileOperationA(&shfo);
486 ok(!ret, "Directory exists, but is not removed, ret=%d\n", ret);
487 ok(file_exists("test4.txt"), "Directory should not have been removed\n");
489 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
491 ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
492 ok(!file_exists("test4.txt"), "Directory should have been removed\n");
494 ret = SHFileOperationA(&shfo);
495 ok(!ret, "The requested file does not exist, ret=%d\n", ret);
497 init_shfo_tests();
498 sprintf(buf, "%s\\%s", CURR_DIR, "test4.txt");
499 buf[strlen(buf) + 1] = '\0';
500 ok(MoveFileA("test1.txt", "test4.txt\\test1.txt"), "Filling the subdirectory failed\n");
501 ok(!SHFileOperationA(&shfo), "Directory is not removed\n");
502 ok(!file_exists("test4.txt"), "Directory is not removed\n");
504 init_shfo_tests();
505 shfo.pFrom = "test1.txt\0test4.txt\0";
506 ok(!SHFileOperationA(&shfo), "Directory and a file are not removed\n");
507 ok(!file_exists("test1.txt"), "The file should have been removed\n");
508 ok(!file_exists("test4.txt"), "Directory should have been removed\n");
509 ok(file_exists("test2.txt"), "This file should not have been removed\n");
511 /* FOF_FILESONLY does not delete a dir matching a wildcard */
512 init_shfo_tests();
513 shfo.fFlags |= FOF_FILESONLY;
514 shfo.pFrom = "*.txt\0";
515 ok(!SHFileOperation(&shfo), "Failed to delete files\n");
516 ok(!file_exists("test1.txt"), "test1.txt should have been removed\n");
517 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
518 ok(file_exists("test4.txt"), "test4.txt should not have been removed\n");
520 /* FOF_FILESONLY only deletes a dir if explicitly specified */
521 init_shfo_tests();
522 shfo.pFrom = "test_?.txt\0test4.txt\0";
523 ok(!SHFileOperation(&shfo), "Failed to delete files and directory\n");
524 ok(!file_exists("test4.txt"), "test4.txt should have been removed\n");
525 ok(!file_exists("test_5.txt"), "test_5.txt should have been removed\n");
526 ok(file_exists("test1.txt"), "test1.txt should not have been removed\n");
528 /* try to delete an invalid filename */
529 if (0) {
530 /* this crashes on win9x */
531 init_shfo_tests();
532 shfo.pFrom = "\0";
533 shfo.fFlags &= ~FOF_FILESONLY;
534 shfo.fAnyOperationsAborted = FALSE;
535 ret = SHFileOperation(&shfo);
536 ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
537 ok(!shfo.fAnyOperationsAborted, "Expected no aborted operations\n");
538 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
541 /* try an invalid function */
542 init_shfo_tests();
543 shfo.pFrom = "test1.txt\0";
544 shfo.wFunc = 0;
545 ret = SHFileOperation(&shfo);
546 ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
547 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
549 /* try an invalid list, only one null terminator */
550 if (0) {
551 /* this crashes on win9x */
552 init_shfo_tests();
553 shfo.pFrom = "";
554 shfo.wFunc = FO_DELETE;
555 ret = SHFileOperation(&shfo);
556 ok(ret == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", ret);
557 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
560 /* delete a dir, and then a file inside the dir, same as
561 * deleting a nonexistent file
563 * FIXME: Vista throws up a dialog window to ask if one.txt should be created
565 init_shfo_tests();
566 shfo.pFrom = "testdir2\0testdir2\\one.txt\0";
567 shfo.wFunc = FO_DELETE;
568 ret = SHFileOperation(&shfo);
569 ok(ret == ERROR_PATH_NOT_FOUND, "Expected ERROR_PATH_NOT_FOUND, got %d\n", ret);
570 ok(!file_exists("testdir2"), "Expected testdir2 to not exist\n");
571 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
573 /* try the FOF_NORECURSION flag, continues deleting subdirs */
574 init_shfo_tests();
575 shfo.pFrom = "testdir2\0";
576 shfo.fFlags |= FOF_NORECURSION;
577 ret = SHFileOperation(&shfo);
578 ok(ret == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", ret);
579 ok(!file_exists("testdir2\\one.txt"), "Expected testdir2\\one.txt to not exist\n");
580 ok(!file_exists("testdir2\\nested"), "Expected testdir2\\nested to exist\n");
583 /* tests the FO_RENAME action */
584 static void test_rename(void)
586 SHFILEOPSTRUCTA shfo, shfo2;
587 CHAR from[5*MAX_PATH];
588 CHAR to[5*MAX_PATH];
589 DWORD retval;
591 shfo.hwnd = NULL;
592 shfo.wFunc = FO_RENAME;
593 shfo.pFrom = from;
594 shfo.pTo = to;
595 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
596 shfo.hNameMappings = NULL;
597 shfo.lpszProgressTitle = NULL;
599 set_curr_dir_path(from, "test1.txt\0");
600 set_curr_dir_path(to, "test4.txt\0");
601 ok(SHFileOperationA(&shfo), "File is not renamed moving to other directory "
602 "when specifying directory name only\n");
603 ok(file_exists("test1.txt"), "The file is removed\n");
605 set_curr_dir_path(from, "test3.txt\0");
606 set_curr_dir_path(to, "test4.txt\\test1.txt\0");
607 ok(!SHFileOperationA(&shfo), "File is renamed moving to other directory\n");
608 ok(file_exists("test4.txt\\test1.txt"), "The file is not renamed\n");
610 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
611 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
612 retval = SHFileOperationA(&shfo); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
613 ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
614 "Can't rename many files, retval = %d\n", retval);
615 ok(file_exists("test1.txt"), "The file is renamed - many files are specified\n");
617 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
618 shfo2.fFlags |= FOF_MULTIDESTFILES;
620 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
621 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
622 retval = SHFileOperationA(&shfo2); /* W98 returns 0, W2K and newer returns ERROR_GEN_FAILURE, both do nothing */
623 ok(!retval || retval == ERROR_GEN_FAILURE || retval == ERROR_INVALID_TARGET_HANDLE,
624 "Can't rename many files, retval = %d\n", retval);
625 ok(file_exists("test1.txt"), "The file is not renamed - many files are specified\n");
627 set_curr_dir_path(from, "test1.txt\0");
628 set_curr_dir_path(to, "test6.txt\0");
629 retval = SHFileOperationA(&shfo);
630 ok(!retval, "Rename file failed, retval = %d\n", retval);
631 ok(!file_exists("test1.txt"), "The file is not renamed\n");
632 ok(file_exists("test6.txt"), "The file is not renamed\n");
634 set_curr_dir_path(from, "test6.txt\0");
635 set_curr_dir_path(to, "test1.txt\0");
636 retval = SHFileOperationA(&shfo);
637 ok(!retval, "Rename file back failed, retval = %d\n", retval);
639 set_curr_dir_path(from, "test4.txt\0");
640 set_curr_dir_path(to, "test6.txt\0");
641 retval = SHFileOperationA(&shfo);
642 ok(!retval, "Rename dir failed, retval = %d\n", retval);
643 ok(!file_exists("test4.txt"), "The dir is not renamed\n");
644 ok(file_exists("test6.txt"), "The dir is not renamed\n");
646 set_curr_dir_path(from, "test6.txt\0");
647 set_curr_dir_path(to, "test4.txt\0");
648 retval = SHFileOperationA(&shfo);
649 ok(!retval, "Rename dir back failed, retval = %d\n", retval);
651 /* try to rename more than one file to a single file */
652 shfo.pFrom = "test1.txt\0test2.txt\0";
653 shfo.pTo = "a.txt\0";
654 retval = SHFileOperationA(&shfo);
655 ok(retval == ERROR_GEN_FAILURE ||
656 broken(!retval), /* Win9x */
657 "Expected ERROR_GEN_FAILURE, got %d\n", retval);
658 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
659 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
660 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
662 /* pFrom doesn't exist */
663 shfo.pFrom = "idontexist\0";
664 shfo.pTo = "newfile\0";
665 retval = SHFileOperationA(&shfo);
666 ok(retval == 1026, "Expected 1026, got %d\n", retval);
667 ok(!file_exists("newfile"), "Expected newfile to not exist\n");
669 /* pTo already exist */
670 shfo.pFrom = "test1.txt\0";
671 shfo.pTo = "test2.txt\0";
672 retval = SHFileOperationA(&shfo);
673 ok(retval == ERROR_ALREADY_EXISTS, "Expected ERROR_ALREADY_EXISTS, got %d\n", retval);
675 /* pFrom is valid, but pTo is empty */
676 shfo.pFrom = "test1.txt\0";
677 shfo.pTo = "\0";
678 retval = SHFileOperationA(&shfo);
679 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x */);
680 ok(file_exists("test1.txt"), "Expected test1.txt to exist\n");
682 /* pFrom is empty */
683 shfo.pFrom = "\0";
684 retval = SHFileOperationA(&shfo);
685 ok(retval == ERROR_ACCESS_DENIED, "Expected ERROR_ACCESS_DENIED, got %d\n", retval);
687 /* pFrom is NULL, commented out because it crashes on nt 4.0 */
688 #if 0
689 shfo.pFrom = NULL;
690 retval = SHFileOperationA(&shfo);
691 ok(retval == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", retval);
692 #endif
695 /* tests the FO_COPY action */
696 static void test_copy(void)
698 SHFILEOPSTRUCTA shfo, shfo2;
699 CHAR from[5*MAX_PATH];
700 CHAR to[5*MAX_PATH];
701 FILEOP_FLAGS tmp_flags;
702 DWORD retval;
703 LPSTR ptr;
705 shfo.hwnd = NULL;
706 shfo.wFunc = FO_COPY;
707 shfo.pFrom = from;
708 shfo.pTo = to;
709 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
710 shfo.hNameMappings = NULL;
711 shfo.lpszProgressTitle = NULL;
713 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
714 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
715 retval = SHFileOperationA(&shfo);
716 if (retval == ERROR_SUCCESS)
718 /* Vista and W2K8 (broken or new behavior ?) */
719 ok(file_exists("test6.txt\\test1.txt"), "The file is not copied - many files "
720 "are specified as a target");
721 DeleteFileA("test6.txt\\test1.txt");
722 DeleteFileA("test6.txt\\test2.txt");
723 RemoveDirectoryA("test6.txt\\test4.txt");
724 RemoveDirectoryA("test6.txt");
726 else
728 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
729 ok(!file_exists("test6.txt"), "The file is copied - many files are "
730 "specified as a target\n");
733 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
734 shfo2.fFlags |= FOF_MULTIDESTFILES;
736 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
737 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
738 ok(!SHFileOperationA(&shfo2), "Can't copy many files\n");
739 ok(file_exists("test6.txt"), "The file is not copied - many files are "
740 "specified as a target\n");
741 DeleteFileA("test6.txt");
742 DeleteFileA("test7.txt");
743 RemoveDirectoryA("test8.txt");
745 /* number of sources do not correspond to number of targets */
746 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
747 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
748 retval = SHFileOperationA(&shfo2);
749 if (retval == ERROR_NO_VOLUME_LABEL)
751 /* Vista and W2K8 (broken or new behavior ?) */
752 ok(file_exists("test6.txt\\test1.txt"), "The file is not copied - many files "
753 "are specified as a target");
754 ok(file_exists("test7.txt\\test2.txt"), "The file is not copied - many files "
755 "are specified as a target");
756 DeleteFileA("test6.txt\\test1.txt");
757 DeleteFileA("test7.txt\\test2.txt");
758 RemoveDirectoryA("test6.txt");
759 RemoveDirectoryA("test7.txt");
761 else
763 ok(retval == ERROR_CANCELLED, "Expected ERROR_CANCELLED, got %d\n", retval);
764 ok(!file_exists("test6.txt"), "The file is copied - many files are "
765 "specified as a target\n");
768 set_curr_dir_path(from, "test1.txt\0");
769 set_curr_dir_path(to, "test4.txt\0");
770 ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are copied recursively\n");
771 ok(file_exists("test4.txt\\test1.txt"), "The file is copied\n");
773 set_curr_dir_path(from, "test?.txt\0");
774 set_curr_dir_path(to, "testdir2\0");
775 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
776 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
777 ok(!SHFileOperationA(&shfo), "Files and directories are copied to directory\n");
778 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
779 ok(file_exists("testdir2\\test4.txt"), "The directory is copied\n");
780 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is copied\n");
781 clean_after_shfo_tests();
783 init_shfo_tests();
784 shfo.fFlags |= FOF_FILESONLY;
785 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
786 ok(!file_exists("testdir2\\test4.txt"), "The directory is not copied yet\n");
787 ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
788 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
789 ok(!file_exists("testdir2\\test4.txt"), "The directory is copied\n");
790 clean_after_shfo_tests();
792 init_shfo_tests();
793 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
794 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
795 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
796 ok(!SHFileOperationA(&shfo), "Files are copied to other directory\n");
797 ok(file_exists("testdir2\\test1.txt"), "The file is copied\n");
798 ok(file_exists("testdir2\\test2.txt"), "The file is copied\n");
799 clean_after_shfo_tests();
801 /* Copying multiple files with one not existing as source, fails the
802 entire operation in Win98/ME/2K/XP, but not in 95/NT */
803 init_shfo_tests();
804 tmp_flags = shfo.fFlags;
805 set_curr_dir_path(from, "test1.txt\0test10.txt\0test2.txt\0");
806 ok(!file_exists("testdir2\\test1.txt"), "The file is not copied yet\n");
807 ok(!file_exists("testdir2\\test2.txt"), "The file is not copied yet\n");
808 retval = SHFileOperationA(&shfo);
809 if (retval == ERROR_SUCCESS)
810 /* Win 95/NT returns success but copies only the files up to the nonexistent source */
811 ok(file_exists("testdir2\\test1.txt"), "The file is not copied\n");
812 else
814 /* Failure if one source file does not exist */
815 ok(retval == 1026 || /* Win 98/ME/2K/XP */
816 retval == ERROR_FILE_NOT_FOUND, /* Vista and W2K8 */
817 "Files are copied to other directory\n");
818 ok(!file_exists("testdir2\\test1.txt"), "The file is copied\n");
820 ok(!file_exists("testdir2\\test2.txt"), "The file is copied\n");
821 shfo.fFlags = tmp_flags;
823 /* copy into a nonexistent directory */
824 init_shfo_tests();
825 shfo.fFlags = FOF_NOCONFIRMMKDIR;
826 set_curr_dir_path(from, "test1.txt\0");
827 set_curr_dir_path(to, "nonexistent\\notreal\\test2.txt\0");
828 retval= SHFileOperation(&shfo);
829 ok(!retval, "Error copying into nonexistent directory\n");
830 ok(file_exists("nonexistent"), "nonexistent not created\n");
831 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal not created\n");
832 ok(file_exists("nonexistent\\notreal\\test2.txt"), "Directory not created\n");
833 ok(!file_exists("nonexistent\\notreal\\test1.txt"), "test1.txt should not exist\n");
835 /* a relative dest directory is OK */
836 clean_after_shfo_tests();
837 init_shfo_tests();
838 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
839 shfo.pTo = "testdir2\0";
840 retval = SHFileOperation(&shfo);
841 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
842 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1 to exist\n");
844 /* try to copy files to a file */
845 clean_after_shfo_tests();
846 init_shfo_tests();
847 shfo.pFrom = from;
848 shfo.pTo = to;
849 /* suppress the error-dialog in win9x here */
850 shfo.fFlags |= FOF_NOERRORUI;
851 set_curr_dir_path(from, "test1.txt\0test2.txt\0");
852 set_curr_dir_path(to, "test3.txt\0");
853 retval = SHFileOperation(&shfo);
854 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
855 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
856 ok(!file_exists("test3.txt\\test2.txt"), "Expected test3.txt\\test2.txt to not exist\n");
858 /* try to copy many files to nonexistent directory */
859 DeleteFile(to);
860 shfo.fFlags &= ~FOF_NOERRORUI;
861 shfo.fAnyOperationsAborted = FALSE;
862 retval = SHFileOperation(&shfo);
863 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
864 ok(DeleteFile("test3.txt\\test1.txt"), "Expected test3.txt\\test1.txt to exist\n");
865 ok(DeleteFile("test3.txt\\test2.txt"), "Expected test3.txt\\test1.txt to exist\n");
866 ok(RemoveDirectory(to), "Expected test3.txt to exist\n");
868 /* send in FOF_MULTIDESTFILES with too many destination files */
869 init_shfo_tests();
870 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
871 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
872 shfo.fFlags |= FOF_NOERRORUI | FOF_MULTIDESTFILES;
873 retval = SHFileOperation(&shfo);
874 if (retval == ERROR_SUCCESS)
876 /* Vista and W2K8 (broken or new behavior ?) */
877 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
878 RemoveDirectory("testdir2\\a.txt");
879 ok(DeleteFile("testdir2\\b.txt\\test2.txt"), "Expected testdir2\\b.txt\\test2.txt to exist\n");
880 RemoveDirectory("testdir2\\b.txt");
881 ok(DeleteFile("testdir2\\c.txt\\test3.txt"), "Expected testdir2\\c.txt\\test3.txt to exist\n");
882 RemoveDirectory("testdir2\\c.txt");
883 ok(!file_exists("testdir2\\d.txt"), "Expected testdir2\\d.txt to not exist\n");
885 else
887 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
888 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
889 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\a.txt to not exist\n");
892 /* send in FOF_MULTIDESTFILES with too many destination files */
893 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
894 shfo.pTo = "e.txt\0f.txt\0";
895 shfo.fAnyOperationsAborted = FALSE;
896 retval = SHFileOperation(&shfo);
897 if (retval == ERROR_NO_MORE_SEARCH_HANDLES)
899 /* Vista and W2K8 (broken or new behavior ?) */
900 ok(DeleteFile("e.txt\\test1.txt"), "Expected e.txt\\test1.txt to exist\n");
901 RemoveDirectory("e.txt");
902 ok(DeleteFile("f.txt\\test2.txt"), "Expected f.txt\\test2.txt to exist\n");
903 RemoveDirectory("f.txt");
905 else
907 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
908 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
909 ok(!file_exists("e.txt"), "Expected e.txt to not exist\n");
912 /* use FOF_MULTIDESTFILES with files and a source directory */
913 shfo.pFrom = "test1.txt\0test2.txt\0test4.txt\0";
914 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0";
915 shfo.fAnyOperationsAborted = FALSE;
916 retval = SHFileOperation(&shfo);
917 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
918 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
919 ok(DeleteFile("testdir2\\b.txt"), "Expected testdir2\\b.txt to exist\n");
920 ok(RemoveDirectory("testdir2\\c.txt"), "Expected testdir2\\c.txt to exist\n");
922 /* try many dest files without FOF_MULTIDESTFILES flag */
923 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
924 shfo.pTo = "a.txt\0b.txt\0c.txt\0";
925 shfo.fAnyOperationsAborted = FALSE;
926 shfo.fFlags &= ~FOF_MULTIDESTFILES;
927 retval = SHFileOperation(&shfo);
928 if (retval == ERROR_SUCCESS)
930 /* Vista and W2K8 (broken or new behavior ?) */
931 ok(DeleteFile("a.txt\\test1.txt"), "Expected a.txt\\test1.txt to exist\n");
932 ok(DeleteFile("a.txt\\test2.txt"), "Expected a.txt\\test2.txt to exist\n");
933 ok(DeleteFile("a.txt\\test3.txt"), "Expected a.txt\\test3.txt to exist\n");
934 RemoveDirectory("a.txt");
936 else
938 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
939 ok(!file_exists("a.txt"), "Expected a.txt to not exist\n");
942 /* try a glob */
943 shfo.pFrom = "test?.txt\0";
944 shfo.pTo = "testdir2\0";
945 shfo.fFlags &= ~FOF_MULTIDESTFILES;
946 retval = SHFileOperation(&shfo);
947 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
948 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
950 /* try a glob with FOF_FILESONLY */
951 clean_after_shfo_tests();
952 init_shfo_tests();
953 shfo.pFrom = "test?.txt\0";
954 shfo.fFlags |= FOF_FILESONLY;
955 retval = SHFileOperation(&shfo);
956 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
957 ok(file_exists("testdir2\\test1.txt"), "Expected testdir2\\test1.txt to exist\n");
958 ok(!file_exists("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to not exist\n");
960 /* try a glob with FOF_MULTIDESTFILES and the same number
961 * of dest files that we would expect
963 clean_after_shfo_tests();
964 init_shfo_tests();
965 shfo.pTo = "testdir2\\a.txt\0testdir2\\b.txt\0testdir2\\c.txt\0testdir2\\d.txt\0";
966 shfo.fFlags &= ~FOF_FILESONLY;
967 shfo.fFlags |= FOF_MULTIDESTFILES;
968 retval = SHFileOperation(&shfo);
969 if (retval == ERROR_SUCCESS)
971 /* Vista and W2K8 (broken or new behavior ?) */
972 ok(DeleteFile("testdir2\\a.txt\\test1.txt"), "Expected testdir2\\a.txt\\test1.txt to exist\n");
973 ok(DeleteFile("testdir2\\a.txt\\test2.txt"), "Expected testdir2\\a.txt\\test2.txt to exist\n");
974 ok(DeleteFile("testdir2\\a.txt\\test3.txt"), "Expected testdir2\\a.txt\\test3.txt to exist\n");
975 ok(RemoveDirectory("testdir2\\a.txt\\test4.txt"), "Expected testdir2\\a.txt\\test4.txt to exist\n");
976 RemoveDirectory("testdir2\\a.txt");
978 else
980 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
981 ok(shfo.fAnyOperationsAborted, "Expected aborted operations\n");
982 ok(!file_exists("testdir2\\a.txt"), "Expected testdir2\\test1.txt to not exist\n");
984 ok(!RemoveDirectory("b.txt"), "b.txt should not exist\n");
986 /* copy one file to two others, second is ignored */
987 clean_after_shfo_tests();
988 init_shfo_tests();
989 shfo.pFrom = "test1.txt\0";
990 shfo.pTo = "b.txt\0c.txt\0";
991 shfo.fAnyOperationsAborted = FALSE;
992 retval = SHFileOperation(&shfo);
993 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
994 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
995 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
997 /* copy two file to three others, all fail */
998 shfo.pFrom = "test1.txt\0test2.txt\0";
999 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1000 retval = SHFileOperation(&shfo);
1001 if (retval == ERROR_SUCCESS)
1003 /* Vista and W2K8 (broken or new behavior ?) */
1004 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1005 RemoveDirectory("b.txt");
1006 ok(DeleteFile("c.txt\\test2.txt"), "Expected c.txt\\test2.txt to exist\n");
1007 RemoveDirectory("c.txt");
1009 else
1011 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1012 ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
1013 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1016 /* copy one file and one directory to three others */
1017 shfo.pFrom = "test1.txt\0test4.txt\0";
1018 shfo.pTo = "b.txt\0c.txt\0d.txt\0";
1019 shfo.fAnyOperationsAborted = FALSE;
1020 retval = SHFileOperation(&shfo);
1021 if (retval == ERROR_SUCCESS)
1023 /* Vista and W2K8 (broken or new behavior ?) */
1024 ok(DeleteFile("b.txt\\test1.txt"), "Expected b.txt\\test1.txt to exist\n");
1025 RemoveDirectory("b.txt");
1026 ok(RemoveDirectory("c.txt\\test4.txt"), "Expected c.txt\\test4.txt to exist\n");
1027 RemoveDirectory("c.txt");
1029 else
1031 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1032 ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
1033 ok(!DeleteFile("b.txt"), "Expected b.txt to not exist\n");
1034 ok(!DeleteFile("c.txt"), "Expected c.txt to not exist\n");
1037 /* copy a directory with a file beneath it, plus some files */
1038 createTestFile("test4.txt\\a.txt");
1039 shfo.pFrom = "test4.txt\0test1.txt\0";
1040 shfo.pTo = "testdir2\0";
1041 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1042 shfo.fAnyOperationsAborted = FALSE;
1043 retval = SHFileOperation(&shfo);
1044 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1045 ok(DeleteFile("testdir2\\test1.txt"), "Expected newdir\\test1.txt to exist\n");
1046 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1047 ok(RemoveDirectory("testdir2\\test4.txt"), "Expected testdir2\\test4.txt to exist\n");
1049 /* copy one directory and a file in that dir to another dir */
1050 shfo.pFrom = "test4.txt\0test4.txt\\a.txt\0";
1051 shfo.pTo = "testdir2\0";
1052 retval = SHFileOperation(&shfo);
1053 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1054 ok(DeleteFile("testdir2\\test4.txt\\a.txt"), "Expected a.txt to exist\n");
1055 ok(DeleteFile("testdir2\\a.txt"), "Expected testdir2\\a.txt to exist\n");
1057 /* copy a file in a directory first, and then the directory to a nonexistent dir */
1058 shfo.pFrom = "test4.txt\\a.txt\0test4.txt\0";
1059 shfo.pTo = "nonexistent\0";
1060 retval = SHFileOperation(&shfo);
1061 if (retval == ERROR_SUCCESS)
1063 /* Vista and W2K8 (broken or new behavior ?) */
1064 ok(DeleteFile("nonexistent\\test4.txt\\a.txt"), "Expected nonexistent\\test4.txt\\a.txt to exist\n");
1065 RemoveDirectory("nonexistent\\test4.txt");
1066 ok(DeleteFile("nonexistent\\a.txt"), "Expected nonexistent\\a.txt to exist\n");
1067 RemoveDirectory("nonexistent");
1069 else
1071 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1072 ok(shfo.fAnyOperationsAborted, "Expected operations to be aborted\n");
1073 ok(!file_exists("nonexistent\\test4.txt"), "Expected nonexistent\\test4.txt to not exist\n");
1075 DeleteFile("test4.txt\\a.txt");
1077 /* destination is same as source file */
1078 shfo.pFrom = "test1.txt\0test2.txt\0test3.txt\0";
1079 shfo.pTo = "b.txt\0test2.txt\0c.txt\0";
1080 shfo.fAnyOperationsAborted = FALSE;
1081 shfo.fFlags = FOF_NOERRORUI | FOF_MULTIDESTFILES;
1082 retval = SHFileOperation(&shfo);
1083 ok(retval == ERROR_NO_MORE_SEARCH_HANDLES,
1084 "Expected ERROR_NO_MORE_SEARCH_HANDLES, got %d\n", retval);
1085 ok(!shfo.fAnyOperationsAborted, "Expected no operations to be aborted\n");
1086 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1087 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1089 /* destination is same as source directory */
1090 shfo.pFrom = "test1.txt\0test4.txt\0test3.txt\0";
1091 shfo.pTo = "b.txt\0test4.txt\0c.txt\0";
1092 shfo.fAnyOperationsAborted = FALSE;
1093 retval = SHFileOperation(&shfo);
1094 ok(retval == ERROR_SUCCESS ||
1095 retval == ERROR_NO_VOLUME_LABEL, /* Vista */
1096 "Expected ERROR_SUCCESS or ERROR_NO_VOLUME_LABEL, got %d\n", retval);
1097 ok(DeleteFile("b.txt"), "Expected b.txt to exist\n");
1098 ok(!file_exists("c.txt"), "Expected c.txt to not exist\n");
1100 /* copy a directory into itself, error displayed in UI */
1101 shfo.pFrom = "test4.txt\0";
1102 shfo.pTo = "test4.txt\\newdir\0";
1103 shfo.fFlags &= ~FOF_MULTIDESTFILES;
1104 shfo.fAnyOperationsAborted = FALSE;
1105 retval = SHFileOperation(&shfo);
1106 ok(retval == ERROR_SUCCESS ||
1107 retval == ERROR_INVALID_VERIFY_SWITCH, /* Vista */
1108 "Expected ERROR_SUCCESS or ERROR_INVALID_VERIFY_SWITCH, got %d\n", retval);
1109 ok(!RemoveDirectory("test4.txt\\newdir"), "Expected test4.txt\\newdir to not exist\n");
1111 /* copy a directory to itself, error displayed in UI */
1112 shfo.pFrom = "test4.txt\0";
1113 shfo.pTo = "test4.txt\0";
1114 shfo.fAnyOperationsAborted = FALSE;
1115 retval = SHFileOperation(&shfo);
1116 ok(retval == ERROR_SUCCESS ||
1117 retval == ERROR_INVALID_VERIFY_SWITCH, /* Vista */
1118 "Expected ERROR_SUCCESS or ERROR_INVALID_VERIFY_SWITCH, got %d\n", retval);
1120 /* copy a file into a directory, and the directory into itself */
1121 shfo.pFrom = "test1.txt\0test4.txt\0";
1122 shfo.pTo = "test4.txt\0";
1123 shfo.fAnyOperationsAborted = FALSE;
1124 shfo.fFlags |= FOF_NOCONFIRMATION;
1125 retval = SHFileOperation(&shfo);
1126 ok(retval == ERROR_SUCCESS ||
1127 retval == ERROR_INVALID_VERIFY_SWITCH, /* Vista */
1128 "Expected ERROR_SUCCESS or ERROR_INVALID_VERIFY_SWITCH, got %d\n", retval);
1129 ok(DeleteFile("test4.txt\\test1.txt"), "Expected test4.txt\\test1.txt to exist\n");
1131 /* copy a file to a file, and the directory into itself */
1132 shfo.pFrom = "test1.txt\0test4.txt\0";
1133 shfo.pTo = "test4.txt\\a.txt\0";
1134 shfo.fAnyOperationsAborted = FALSE;
1135 retval = SHFileOperation(&shfo);
1136 if (retval == ERROR_INVALID_VERIFY_SWITCH)
1138 /* Vista and W2K8 (broken or new behavior ?) */
1139 ok(DeleteFile("test4.txt\\a.txt\\test1.txt"), "Expected test4.txt\\a.txt\\test1.txt to exist\n");
1140 RemoveDirectory("test4.txt\\a.txt");
1142 else
1144 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1145 ok(!file_exists("test4.txt\\a.txt"), "Expected test4.txt\\a.txt to not exist\n");
1148 /* copy a nonexistent file to a nonexistent directory */
1149 shfo.pFrom = "e.txt\0";
1150 shfo.pTo = "nonexistent\0";
1151 shfo.fAnyOperationsAborted = FALSE;
1152 retval = SHFileOperation(&shfo);
1153 ok(retval == 1026 ||
1154 retval == ERROR_FILE_NOT_FOUND, /* Vista */
1155 "Expected 1026 or ERROR_FILE_NOT_FOUND, got %d\n", retval);
1156 ok(!file_exists("nonexistent\\e.txt"), "Expected nonexistent\\e.txt to not exist\n");
1157 ok(!file_exists("nonexistent"), "Expected nonexistent to not exist\n");
1159 /* Overwrite tests */
1160 clean_after_shfo_tests();
1161 init_shfo_tests();
1162 shfo.fFlags = FOF_NOCONFIRMATION;
1163 shfo.pFrom = "test1.txt\0";
1164 shfo.pTo = "test2.txt\0";
1165 shfo.fAnyOperationsAborted = FALSE;
1166 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1167 retval = SHFileOperation(&shfo);
1168 ok(retval == 0, "Expected 0, got %d\n", retval);
1169 ok(file_has_content("test2.txt", "test1.txt\n"), "The file was not copied\n");
1171 shfo.pFrom = "test3.txt\0test1.txt\0";
1172 shfo.pTo = "test2.txt\0one.txt\0";
1173 shfo.fFlags = FOF_NOCONFIRMATION | FOF_MULTIDESTFILES;
1174 /* without FOF_NOCONFIRMATION the confirmation is Yes/Yes to All/No/Cancel */
1175 retval = SHFileOperation(&shfo);
1176 ok(retval == 0, "Expected 0, got %d\n", retval);
1177 ok(file_has_content("test2.txt", "test3.txt\n"), "The file was not copied\n");
1179 shfo.pFrom = "one.txt\0";
1180 shfo.pTo = "testdir2\0";
1181 shfo.fFlags = FOF_NOCONFIRMATION;
1182 /* without FOF_NOCONFIRMATION the confirmation is Yes/No */
1183 retval = SHFileOperation(&shfo);
1184 ok(retval == 0, "Expected 0, got %d\n", retval);
1185 ok(file_has_content("testdir2\\one.txt", "test1.txt\n"), "The file was not copied\n");
1187 createTestFile("test4.txt\\test1.txt");
1188 shfo.pFrom = "test4.txt\0";
1189 shfo.pTo = "testdir2\0";
1190 shfo.fFlags = FOF_NOCONFIRMATION;
1191 ok(!SHFileOperation(&shfo), "First SHFileOperation failed\n");
1192 createTestFile("test4.txt\\.\\test1.txt"); /* modify the content of the file */
1193 /* without FOF_NOCONFIRMATION the confirmation is "This folder already contains a folder named ..." */
1194 retval = SHFileOperation(&shfo);
1195 ok(retval == 0, "Expected 0, got %d\n", retval);
1196 ok(file_has_content("testdir2\\test4.txt\\test1.txt", "test4.txt\\.\\test1.txt\n"), "The file was not copied\n");
1198 createTestFile("one.txt");
1200 /* pFrom contains bogus 2nd name longer than MAX_PATH */
1201 memset(from, 'a', MAX_PATH*2);
1202 memset(from+MAX_PATH*2, 0, 2);
1203 lstrcpyA(from, "one.txt");
1204 shfo.pFrom = from;
1205 shfo.pTo = "two.txt\0";
1206 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1207 retval = SHFileOperation(&shfo);
1208 ok(retval == 1148 || retval == 1026 ||
1209 retval == ERROR_ACCESS_DENIED, /* win2k */
1210 "Expected 1148, 1026 or ERROR_ACCESS_DENIED, got %d\n", retval);
1211 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1212 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1214 createTestFile("one.txt");
1216 /* pTo contains bogus 2nd name longer than MAX_PATH */
1217 memset(to, 'a', MAX_PATH*2);
1218 memset(to+MAX_PATH*2, 0, 2);
1219 lstrcpyA(to, "two.txt");
1220 shfo.pFrom = "one.txt\0";
1221 shfo.pTo = to;
1222 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1223 retval = SHFileOperation(&shfo);
1224 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1225 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1226 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1228 createTestFile("one.txt");
1230 /* no FOF_MULTIDESTFILES, two files in pTo */
1231 shfo.pFrom = "one.txt\0";
1232 shfo.pTo = "two.txt\0three.txt\0";
1233 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1234 retval = SHFileOperation(&shfo);
1235 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1236 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1237 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1239 createTestFile("one.txt");
1241 /* both pFrom and pTo contain bogus 2nd names longer than MAX_PATH */
1242 memset(from, 'a', MAX_PATH*2);
1243 memset(from+MAX_PATH*2, 0, 2);
1244 memset(to, 'a', MAX_PATH*2);
1245 memset(to+MAX_PATH*2, 0, 2);
1246 lstrcpyA(from, "one.txt");
1247 lstrcpyA(to, "two.txt");
1248 shfo.pFrom = from;
1249 shfo.pTo = to;
1250 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1251 retval = SHFileOperation(&shfo);
1252 ok(retval == 1148 || retval == 1026 ||
1253 retval == ERROR_ACCESS_DENIED, /* win2k */
1254 "Expected 1148, 1026 or ERROR_ACCESS_DENIED, got %d\n", retval);
1255 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1256 ok(!DeleteFileA("two.txt"), "Expected file to not exist\n");
1258 createTestFile("one.txt");
1260 /* pTo contains bogus 2nd name longer than MAX_PATH, FOF_MULTIDESTFILES */
1261 memset(to, 'a', MAX_PATH*2);
1262 memset(to+MAX_PATH*2, 0, 2);
1263 lstrcpyA(to, "two.txt");
1264 shfo.pFrom = "one.txt\0";
1265 shfo.pTo = to;
1266 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1267 FOF_SILENT | FOF_NOERRORUI;
1268 retval = SHFileOperation(&shfo);
1269 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1270 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1271 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1273 createTestFile("one.txt");
1274 createTestFile("two.txt");
1276 /* pTo contains bogus 2nd name longer than MAX_PATH,
1277 * multiple source files,
1278 * dest directory does not exist
1280 memset(to, 'a', 2 * MAX_PATH);
1281 memset(to+MAX_PATH*2, 0, 2);
1282 lstrcpyA(to, "threedir");
1283 shfo.pFrom = "one.txt\0two.txt\0";
1284 shfo.pTo = to;
1285 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1286 retval = SHFileOperation(&shfo);
1287 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1288 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1289 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1290 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1291 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1292 ok(!DeleteFileA("threedir"), "Expected file to not exist\n");
1293 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1295 createTestFile("one.txt");
1296 createTestFile("two.txt");
1297 CreateDirectoryA("threedir", NULL);
1299 /* pTo contains bogus 2nd name longer than MAX_PATH,
1300 * multiple source files,
1301 * dest directory does exist
1303 memset(to, 'a', 2 * MAX_PATH);
1304 memset(to+MAX_PATH*2, 0, 2);
1305 lstrcpyA(to, "threedir");
1306 shfo.pFrom = "one.txt\0two.txt\0";
1307 shfo.pTo = to;
1308 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1309 retval = SHFileOperation(&shfo);
1310 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1311 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1312 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1313 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1314 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1315 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1317 if (0) {
1318 /* this crashes on win9x */
1319 createTestFile("one.txt");
1320 createTestFile("two.txt");
1322 /* pTo contains bogus 2nd name longer than MAX_PATH,
1323 * multiple source files, FOF_MULTIDESTFILES
1324 * dest dir does not exist
1327 memset(to, 'a', 2 * MAX_PATH);
1328 memset(to+MAX_PATH*2, 0, 2);
1329 lstrcpyA(to, "threedir");
1330 shfo.pFrom = "one.txt\0two.txt\0";
1331 shfo.pTo = to;
1332 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1333 FOF_SILENT | FOF_NOERRORUI;
1334 retval = SHFileOperation(&shfo);
1335 ok(retval == ERROR_CANCELLED ||
1336 retval == ERROR_SUCCESS, /* win2k3 */
1337 "Expected ERROR_CANCELLED or ERROR_SUCCESS, got %d\n", retval);
1338 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1339 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1340 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1341 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1342 ok(!RemoveDirectoryA("threedir"), "Expected dir to not exist\n");
1344 /* file exists in win2k */
1345 DeleteFileA("threedir");
1349 createTestFile("one.txt");
1350 createTestFile("two.txt");
1351 CreateDirectoryA("threedir", NULL);
1353 /* pTo contains bogus 2nd name longer than MAX_PATH,
1354 * multiple source files, FOF_MULTIDESTFILES
1355 * dest dir does exist
1357 memset(to, 'a', 2 * MAX_PATH);
1358 memset(to+MAX_PATH*2, 0, 2);
1359 lstrcpyA(to, "threedir");
1360 ptr = to + lstrlenA(to) + 1;
1361 lstrcpyA(ptr, "fourdir");
1362 shfo.pFrom = "one.txt\0two.txt\0";
1363 shfo.pTo = to;
1364 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1365 FOF_SILENT | FOF_NOERRORUI;
1366 retval = SHFileOperation(&shfo);
1367 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1368 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1369 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1370 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1371 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1372 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1373 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1374 ok(!RemoveDirectoryA("fourdir"), "Expected dir to not exist\n");
1376 createTestFile("one.txt");
1377 createTestFile("two.txt");
1378 CreateDirectoryA("threedir", NULL);
1380 /* multiple source files, FOF_MULTIDESTFILES
1381 * multiple dest files, but first dest dir exists
1382 * num files in lists is equal
1384 shfo.pFrom = "one.txt\0two.txt\0";
1385 shfo.pTo = "threedir\0fourdir\0";
1386 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1387 FOF_SILENT | FOF_NOERRORUI;
1388 retval = SHFileOperation(&shfo);
1389 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1390 ok(!DeleteFileA("threedir\\one.txt"), "Expected file to not exist\n");
1391 ok(!DeleteFileA("threedir\\two.txt"), "Expected file to not exist\n");
1392 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1393 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1394 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1395 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1396 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1398 createTestFile("one.txt");
1399 createTestFile("two.txt");
1400 CreateDirectoryA("threedir", NULL);
1402 /* multiple source files, FOF_MULTIDESTFILES
1403 * multiple dest files, but first dest dir exists
1404 * num files in lists is not equal
1406 shfo.pFrom = "one.txt\0two.txt\0";
1407 shfo.pTo = "threedir\0fourdir\0five\0";
1408 shfo.fFlags = FOF_MULTIDESTFILES | FOF_NOCONFIRMATION |
1409 FOF_SILENT | FOF_NOERRORUI;
1410 retval = SHFileOperation(&shfo);
1411 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1412 ok(DeleteFileA("threedir\\one.txt"), "Expected file to exist\n");
1413 ok(DeleteFileA("threedir\\two.txt"), "Expected file to exist\n");
1414 ok(DeleteFileA("one.txt"), "Expected file to exist\n");
1415 ok(DeleteFileA("two.txt"), "Expected file to exist\n");
1416 ok(RemoveDirectoryA("threedir"), "Expected dir to exist\n");
1417 ok(!DeleteFileA("fourdir"), "Expected file to not exist\n");
1418 ok(!RemoveDirectoryA("fourdir"), "Expected dit to not exist\n");
1419 ok(!DeleteFileA("five"), "Expected file to not exist\n");
1420 ok(!RemoveDirectoryA("five"), "Expected dit to not exist\n");
1422 createTestFile("aa.txt");
1423 createTestFile("ab.txt");
1424 CreateDirectoryA("one", NULL);
1425 CreateDirectoryA("two", NULL);
1427 /* pFrom has a glob, pTo has more than one dest */
1428 shfo.pFrom = "a*.txt\0";
1429 shfo.pTo = "one\0two\0";
1430 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1431 retval = SHFileOperation(&shfo);
1432 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1433 ok(DeleteFileA("one\\aa.txt"), "Expected file to exist\n");
1434 ok(DeleteFileA("one\\ab.txt"), "Expected file to exist\n");
1435 ok(!DeleteFileA("two\\aa.txt"), "Expected file to not exist\n");
1436 ok(!DeleteFileA("two\\ab.txt"), "Expected file to not exist\n");
1437 ok(DeleteFileA("aa.txt"), "Expected file to exist\n");
1438 ok(DeleteFileA("ab.txt"), "Expected file to exist\n");
1439 ok(RemoveDirectoryA("one"), "Expected dir to exist\n");
1440 ok(RemoveDirectoryA("two"), "Expected dir to exist\n");
1443 /* tests the FO_MOVE action */
1444 static void test_move(void)
1446 SHFILEOPSTRUCTA shfo, shfo2;
1447 CHAR from[5*MAX_PATH];
1448 CHAR to[5*MAX_PATH];
1449 DWORD retval;
1451 shfo.hwnd = NULL;
1452 shfo.wFunc = FO_MOVE;
1453 shfo.pFrom = from;
1454 shfo.pTo = to;
1455 shfo.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1456 shfo.hNameMappings = NULL;
1457 shfo.lpszProgressTitle = NULL;
1459 set_curr_dir_path(from, "test1.txt\0");
1460 set_curr_dir_path(to, "test4.txt\0");
1461 ok(!SHFileOperationA(&shfo), "Prepare test to check how directories are moved recursively\n");
1462 ok(!file_exists("test1.txt"), "test1.txt should not exist\n");
1463 ok(file_exists("test4.txt\\test1.txt"), "The file is not moved\n");
1465 set_curr_dir_path(from, "test?.txt\0");
1466 set_curr_dir_path(to, "testdir2\0");
1467 ok(!file_exists("testdir2\\test2.txt"), "The file is not moved yet\n");
1468 ok(!file_exists("testdir2\\test4.txt"), "The directory is not moved yet\n");
1469 ok(!SHFileOperationA(&shfo), "Files and directories are moved to directory\n");
1470 ok(file_exists("testdir2\\test2.txt"), "The file is moved\n");
1471 ok(file_exists("testdir2\\test4.txt"), "The directory is moved\n");
1472 ok(file_exists("testdir2\\test4.txt\\test1.txt"), "The file in subdirectory is moved\n");
1474 clean_after_shfo_tests();
1475 init_shfo_tests();
1477 memcpy(&shfo2, &shfo, sizeof(SHFILEOPSTRUCTA));
1478 shfo2.fFlags |= FOF_MULTIDESTFILES;
1480 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1481 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1482 ok(!SHFileOperationA(&shfo2), "Move many files\n");
1483 ok(file_exists("test6.txt"), "The file is moved - many files are "
1484 "specified as a target\n");
1485 DeleteFileA("test6.txt");
1486 DeleteFileA("test7.txt");
1487 RemoveDirectoryA("test8.txt");
1489 init_shfo_tests();
1491 /* number of sources do not correspond to number of targets */
1492 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1493 set_curr_dir_path(to, "test6.txt\0test7.txt\0");
1494 ok(SHFileOperationA(&shfo2), "Can't move many files\n");
1495 ok(!file_exists("test6.txt"), "The file is not moved - many files are "
1496 "specified as a target\n");
1498 init_shfo_tests();
1500 set_curr_dir_path(from, "test3.txt\0");
1501 set_curr_dir_path(to, "test4.txt\\test1.txt\0");
1502 ok(!SHFileOperationA(&shfo), "File is moved moving to other directory\n");
1503 ok(file_exists("test4.txt\\test1.txt"), "The file is moved\n");
1505 set_curr_dir_path(from, "test1.txt\0test2.txt\0test4.txt\0");
1506 set_curr_dir_path(to, "test6.txt\0test7.txt\0test8.txt\0");
1507 ok(SHFileOperationA(&shfo), "Cannot move many files\n");
1508 ok(file_exists("test1.txt"), "The file is not moved. Many files are specified\n");
1509 ok(file_exists("test4.txt"), "The directory is not moved. Many files are specified\n");
1511 set_curr_dir_path(from, "test1.txt\0");
1512 set_curr_dir_path(to, "test6.txt\0");
1513 ok(!SHFileOperationA(&shfo), "Move file\n");
1514 ok(!file_exists("test1.txt"), "The file is moved\n");
1515 ok(file_exists("test6.txt"), "The file is moved\n");
1516 set_curr_dir_path(from, "test6.txt\0");
1517 set_curr_dir_path(to, "test1.txt\0");
1518 ok(!SHFileOperationA(&shfo), "Move file back\n");
1520 set_curr_dir_path(from, "test4.txt\0");
1521 set_curr_dir_path(to, "test6.txt\0");
1522 ok(!SHFileOperationA(&shfo), "Move dir\n");
1523 ok(!file_exists("test4.txt"), "The dir is moved\n");
1524 ok(file_exists("test6.txt"), "The dir is moved\n");
1525 set_curr_dir_path(from, "test6.txt\0");
1526 set_curr_dir_path(to, "test4.txt\0");
1527 ok(!SHFileOperationA(&shfo), "Move dir back\n");
1529 /* move one file to two others */
1530 init_shfo_tests();
1531 shfo.pFrom = "test1.txt\0";
1532 shfo.pTo = "a.txt\0b.txt\0";
1533 retval = SHFileOperationA(&shfo);
1534 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1535 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1536 ok(DeleteFile("a.txt"), "Expected a.txt to exist\n");
1537 ok(!file_exists("b.txt"), "Expected b.txt to not exist\n");
1539 /* move two files to one other */
1540 shfo.pFrom = "test2.txt\0test3.txt\0";
1541 shfo.pTo = "test1.txt\0";
1542 retval = SHFileOperationA(&shfo);
1543 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1544 ok(!file_exists("test1.txt"), "Expected test1.txt to not exist\n");
1545 ok(file_exists("test2.txt"), "Expected test2.txt to exist\n");
1546 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1548 /* move a directory into itself */
1549 shfo.pFrom = "test4.txt\0";
1550 shfo.pTo = "test4.txt\\b.txt\0";
1551 retval = SHFileOperationA(&shfo);
1552 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1553 ok(!RemoveDirectory("test4.txt\\b.txt"), "Expected test4.txt\\b.txt to not exist\n");
1554 ok(file_exists("test4.txt"), "Expected test4.txt to exist\n");
1556 /* move many files without FOF_MULTIDESTFILES */
1557 shfo.pFrom = "test2.txt\0test3.txt\0";
1558 shfo.pTo = "d.txt\0e.txt\0";
1559 retval = SHFileOperationA(&shfo);
1560 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1561 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1562 ok(!DeleteFile("e.txt"), "Expected e.txt to not exist\n");
1564 /* number of sources != number of targets */
1565 shfo.pTo = "d.txt\0";
1566 shfo.fFlags |= FOF_MULTIDESTFILES;
1567 retval = SHFileOperationA(&shfo);
1568 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1569 ok(!DeleteFile("d.txt"), "Expected d.txt to not exist\n");
1571 /* FO_MOVE does not create dest directories */
1572 shfo.pFrom = "test2.txt\0";
1573 shfo.pTo = "dir1\\dir2\\test2.txt\0";
1574 retval = SHFileOperationA(&shfo);
1575 expect_retval(ERROR_CANCELLED, DE_OPCANCELLED /* Win9x, NT4 */);
1576 ok(!file_exists("dir1"), "Expected dir1 to not exist\n");
1578 /* try to overwrite an existing file */
1579 shfo.pTo = "test3.txt\0";
1580 retval = SHFileOperationA(&shfo);
1581 ok(retval == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", retval);
1582 ok(!file_exists("test2.txt"), "Expected test2.txt to not exist\n");
1583 ok(file_exists("test3.txt"), "Expected test3.txt to exist\n");
1586 static void test_sh_create_dir(void)
1588 CHAR path[MAX_PATH];
1589 int ret;
1591 if(!pSHCreateDirectoryExA)
1593 win_skip("skipping SHCreateDirectoryExA tests\n");
1594 return;
1597 set_curr_dir_path(path, "testdir2\\test4.txt\0");
1598 ret = pSHCreateDirectoryExA(NULL, path, NULL);
1599 ok(ERROR_SUCCESS == ret, "SHCreateDirectoryEx failed to create directory recursively, ret = %d\n", ret);
1600 ok(file_exists("testdir2"), "The first directory is not created\n");
1601 ok(file_exists("testdir2\\test4.txt"), "The second directory is not created\n");
1603 ret = pSHCreateDirectoryExA(NULL, path, NULL);
1604 ok(ERROR_ALREADY_EXISTS == ret, "SHCreateDirectoryEx should fail to create existing directory, ret = %d\n", ret);
1606 ret = pSHCreateDirectoryExA(NULL, "c:\\testdir3", NULL);
1607 ok(file_exists("c:\\testdir3"), "The directory is not created\n");
1610 static void test_sh_path_prepare(void)
1612 HRESULT res;
1613 CHAR path[MAX_PATH];
1615 if(!pSHPathPrepareForWriteA)
1617 win_skip("skipping SHPathPrepareForWriteA tests\n");
1618 return;
1621 /* directory exists, SHPPFW_NONE */
1622 set_curr_dir_path(path, "testdir2\0");
1623 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1624 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1626 /* directory exists, SHPPFW_IGNOREFILENAME */
1627 set_curr_dir_path(path, "testdir2\\test4.txt\0");
1628 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
1629 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1631 /* directory exists, SHPPFW_DIRCREATE */
1632 set_curr_dir_path(path, "testdir2\0");
1633 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1634 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1636 /* directory exists, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1637 set_curr_dir_path(path, "testdir2\\test4.txt\0");
1638 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
1639 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1640 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1642 /* file exists, SHPPFW_NONE */
1643 set_curr_dir_path(path, "test1.txt\0");
1644 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1645 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1647 /* file exists, SHPPFW_DIRCREATE */
1648 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1649 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1651 /* file exists, SHPPFW_NONE, trailing \ */
1652 set_curr_dir_path(path, "test1.txt\\\0");
1653 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1654 ok(res == HRESULT_FROM_WIN32(ERROR_DIRECTORY), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_DIRECTORY)\n", res);
1656 /* relative path exists, SHPPFW_DIRCREATE */
1657 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2", SHPPFW_DIRCREATE);
1658 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1660 /* relative path doesn't exist, SHPPFW_DIRCREATE -- Windows does not create the directory in this case */
1661 res = pSHPathPrepareForWriteA(0, 0, ".\\testdir2\\test4.txt", SHPPFW_DIRCREATE);
1662 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1663 ok(!file_exists(".\\testdir2\\test4.txt\\"), ".\\testdir2\\test4.txt\\ exists but shouldn't\n");
1665 /* directory doesn't exist, SHPPFW_NONE */
1666 set_curr_dir_path(path, "nonexistent\0");
1667 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_NONE);
1668 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1670 /* directory doesn't exist, SHPPFW_IGNOREFILENAME */
1671 set_curr_dir_path(path, "nonexistent\\notreal\0");
1672 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME);
1673 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == 0x%08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1674 ok(!file_exists("nonexistent\\notreal"), "nonexistent\\notreal exists but shouldn't\n");
1675 ok(!file_exists("nonexistent\\"), "nonexistent\\ exists but shouldn't\n");
1677 /* directory doesn't exist, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE */
1678 set_curr_dir_path(path, "testdir2\\test4.txt\\\0");
1679 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_IGNOREFILENAME|SHPPFW_DIRCREATE);
1680 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1681 ok(file_exists("testdir2\\test4.txt\\"), "testdir2\\test4.txt doesn't exist but should\n");
1683 /* nested directory doesn't exist, SHPPFW_DIRCREATE */
1684 set_curr_dir_path(path, "nonexistent\\notreal\0");
1685 res = pSHPathPrepareForWriteA(0, 0, path, SHPPFW_DIRCREATE);
1686 ok(res == S_OK, "res == 0x%08x, expected S_OK\n", res);
1687 ok(file_exists("nonexistent\\notreal"), "nonexistent\\notreal doesn't exist but should\n");
1689 /* SHPPFW_ASKDIRCREATE, SHPPFW_NOWRITECHECK, and SHPPFW_MEDIACHECKONLY are untested */
1691 if(!pSHPathPrepareForWriteW)
1693 skip("Skipping SHPathPrepareForWriteW tests\n");
1694 return;
1696 /* unicode directory doesn't exist, SHPPFW_NONE */
1697 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
1698 ok(res == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), "res == %08x, expected HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND)\n", res);
1699 ok(!file_existsW(UNICODE_PATH), "unicode path was created but shouldn't be\n");
1700 RemoveDirectoryW(UNICODE_PATH);
1702 /* unicode directory doesn't exist, SHPPFW_DIRCREATE */
1703 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
1704 ok(res == S_OK, "res == %08x, expected S_OK\n", res);
1705 ok(file_existsW(UNICODE_PATH), "unicode path should've been created\n");
1707 /* unicode directory exists, SHPPFW_NONE */
1708 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_NONE);
1709 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
1711 /* unicode directory exists, SHPPFW_DIRCREATE */
1712 res = pSHPathPrepareForWriteW(0, 0, UNICODE_PATH, SHPPFW_DIRCREATE);
1713 ok(res == S_OK, "ret == %08x, expected S_OK\n", res);
1714 RemoveDirectoryW(UNICODE_PATH);
1717 static void test_unicode(void)
1719 SHFILEOPSTRUCTW shfoW;
1720 int ret;
1721 HANDLE file;
1723 if (!pSHFileOperationW)
1725 skip("SHFileOperationW() is missing\n");
1726 return;
1729 shfoW.hwnd = NULL;
1730 shfoW.wFunc = FO_DELETE;
1731 shfoW.pFrom = UNICODE_PATH;
1732 shfoW.pTo = '\0';
1733 shfoW.fFlags = FOF_NOCONFIRMATION | FOF_SILENT | FOF_NOERRORUI;
1734 shfoW.hNameMappings = NULL;
1735 shfoW.lpszProgressTitle = NULL;
1737 /* Clean up before start test */
1738 DeleteFileW(UNICODE_PATH);
1739 RemoveDirectoryW(UNICODE_PATH);
1741 /* Make sure we are on a system that supports unicode */
1742 SetLastError(0xdeadbeef);
1743 file = CreateFileW(UNICODE_PATH, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
1744 if (GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
1746 skip("Unicode tests skipped on non-unicode system\n");
1747 return;
1749 CloseHandle(file);
1751 /* Try to delete a file with unicode filename */
1752 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
1753 ret = pSHFileOperationW(&shfoW);
1754 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
1755 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
1757 /* Try to trash a file with unicode filename */
1758 createTestFileW(UNICODE_PATH);
1759 shfoW.fFlags |= FOF_ALLOWUNDO;
1760 ok(file_existsW(UNICODE_PATH), "The file does not exist\n");
1761 ret = pSHFileOperationW(&shfoW);
1762 ok(!ret, "File is not removed, ErrorCode: %d\n", ret);
1763 ok(!file_existsW(UNICODE_PATH), "The file should have been removed\n");
1765 if(!pSHCreateDirectoryExW)
1767 skip("Skipping SHCreateDirectoryExW tests\n");
1768 return;
1771 /* Try to delete a directory with unicode filename */
1772 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
1773 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
1774 ok(file_existsW(UNICODE_PATH), "The directory is not created\n");
1775 shfoW.fFlags &= ~FOF_ALLOWUNDO;
1776 ret = pSHFileOperationW(&shfoW);
1777 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
1778 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
1780 /* Try to trash a directory with unicode filename */
1781 ret = pSHCreateDirectoryExW(NULL, UNICODE_PATH, NULL);
1782 ok(!ret, "SHCreateDirectoryExW returned %d\n", ret);
1783 ok(file_existsW(UNICODE_PATH), "The directory was not created\n");
1784 shfoW.fFlags |= FOF_ALLOWUNDO;
1785 ret = pSHFileOperationW(&shfoW);
1786 ok(!ret, "Directory is not removed, ErrorCode: %d\n", ret);
1787 ok(!file_existsW(UNICODE_PATH), "The directory should have been removed\n");
1790 START_TEST(shlfileop)
1792 InitFunctionPointers();
1794 clean_after_shfo_tests();
1796 init_shfo_tests();
1797 test_get_file_info();
1798 test_get_file_info_iconlist();
1799 clean_after_shfo_tests();
1801 init_shfo_tests();
1802 test_delete();
1803 clean_after_shfo_tests();
1805 init_shfo_tests();
1806 test_rename();
1807 clean_after_shfo_tests();
1809 init_shfo_tests();
1810 test_copy();
1811 clean_after_shfo_tests();
1813 init_shfo_tests();
1814 test_move();
1815 clean_after_shfo_tests();
1817 test_sh_create_dir();
1818 clean_after_shfo_tests();
1820 init_shfo_tests();
1821 test_sh_path_prepare();
1822 clean_after_shfo_tests();
1824 test_unicode();