[SCRRUN]
[reactos.git] / rostests / winetests / scrrun / filesystem.c
1 /*
2 *
3 * Copyright 2012 Alistair Leslie-Hughes
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #define COBJMACROS
21 #include <stdio.h>
22
23 #include "windows.h"
24 #include "ole2.h"
25 #include "olectl.h"
26 #include "oleauto.h"
27 #include "dispex.h"
28
29 #include "wine/test.h"
30
31 #include "initguid.h"
32 #include "scrrun.h"
33
34 static IFileSystem3 *fs3;
35
36 static void test_interfaces(void)
37 {
38 static const WCHAR nonexistent_dirW[] = {
39 'c', ':', '\\', 'N', 'o', 'n', 'e', 'x', 'i', 's', 't', 'e', 'n', 't', 0};
40 static const WCHAR pathW[] = {'p','a','t','h',0};
41 static const WCHAR file_kernel32W[] = {
42 '\\', 'k', 'e', 'r', 'n', 'e', 'l', '3', '2', '.', 'd', 'l', 'l', 0};
43 HRESULT hr;
44 IDispatch *disp;
45 IDispatchEx *dispex;
46 IObjectWithSite *site;
47 VARIANT_BOOL b;
48 BSTR path;
49 WCHAR windows_path[MAX_PATH];
50 WCHAR file_path[MAX_PATH];
51
52 IFileSystem3_QueryInterface(fs3, &IID_IDispatch, (void**)&disp);
53
54 GetSystemDirectoryW(windows_path, MAX_PATH);
55 lstrcpyW(file_path, windows_path);
56 lstrcatW(file_path, file_kernel32W);
57
58 hr = IDispatch_QueryInterface(disp, &IID_IObjectWithSite, (void**)&site);
59 ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
60
61 hr = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
62 ok(hr == E_NOINTERFACE, "got 0x%08x, expected 0x%08x\n", hr, E_NOINTERFACE);
63
64 b = VARIANT_TRUE;
65 hr = IFileSystem3_FileExists(fs3, NULL, &b);
66 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
67 ok(b == VARIANT_FALSE, "got %x\n", b);
68
69 hr = IFileSystem3_FileExists(fs3, NULL, NULL);
70 ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, E_POINTER);
71
72 path = SysAllocString(pathW);
73 b = VARIANT_TRUE;
74 hr = IFileSystem3_FileExists(fs3, path, &b);
75 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
76 ok(b == VARIANT_FALSE, "got %x\n", b);
77 SysFreeString(path);
78
79 path = SysAllocString(file_path);
80 b = VARIANT_FALSE;
81 hr = IFileSystem3_FileExists(fs3, path, &b);
82 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
83 ok(b == VARIANT_TRUE, "got %x\n", b);
84 SysFreeString(path);
85
86 path = SysAllocString(windows_path);
87 b = VARIANT_TRUE;
88 hr = IFileSystem3_FileExists(fs3, path, &b);
89 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
90 ok(b == VARIANT_FALSE, "got %x\n", b);
91 SysFreeString(path);
92
93 /* Folder Exists */
94 hr = IFileSystem3_FolderExists(fs3, NULL, NULL);
95 ok(hr == E_POINTER, "got 0x%08x, expected 0x%08x\n", hr, E_POINTER);
96
97 path = SysAllocString(windows_path);
98 hr = IFileSystem3_FolderExists(fs3, path, &b);
99 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
100 ok(b == VARIANT_TRUE, "Folder doesn't exists\n");
101 SysFreeString(path);
102
103 path = SysAllocString(nonexistent_dirW);
104 hr = IFileSystem3_FolderExists(fs3, path, &b);
105 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
106 ok(b == VARIANT_FALSE, "Folder exists\n");
107 SysFreeString(path);
108
109 path = SysAllocString(file_path);
110 hr = IFileSystem3_FolderExists(fs3, path, &b);
111 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
112 ok(b == VARIANT_FALSE, "Folder exists\n");
113 SysFreeString(path);
114
115 IDispatch_Release(disp);
116 }
117
118 static void test_createfolder(void)
119 {
120 HRESULT hr;
121 WCHAR pathW[MAX_PATH];
122 BSTR path;
123 IFolder *folder;
124
125 /* create existing directory */
126 GetCurrentDirectoryW(sizeof(pathW)/sizeof(WCHAR), pathW);
127 path = SysAllocString(pathW);
128 folder = (void*)0xdeabeef;
129 hr = IFileSystem3_CreateFolder(fs3, path, &folder);
130 ok(hr == CTL_E_FILEALREADYEXISTS, "got 0x%08x\n", hr);
131 ok(folder == NULL, "got %p\n", folder);
132 SysFreeString(path);
133 }
134
135 static void test_textstream(void)
136 {
137 static WCHAR testfileW[] = {'t','e','s','t','f','i','l','e','.','t','x','t',0};
138 ITextStream *stream;
139 VARIANT_BOOL b;
140 HANDLE file;
141 HRESULT hr;
142 BSTR name, data;
143
144 file = CreateFileW(testfileW, GENERIC_READ, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
145 CloseHandle(file);
146
147 name = SysAllocString(testfileW);
148 b = VARIANT_FALSE;
149 hr = IFileSystem3_FileExists(fs3, name, &b);
150 ok(hr == S_OK, "got 0x%08x, expected 0x%08x\n", hr, S_OK);
151 ok(b == VARIANT_TRUE, "got %x\n", b);
152
153 hr = IFileSystem3_OpenTextFile(fs3, name, ForReading, VARIANT_FALSE, TristateFalse, &stream);
154 ok(hr == S_OK, "got 0x%08x\n", hr);
155
156 b = 10;
157 hr = ITextStream_get_AtEndOfStream(stream, &b);
158 todo_wine {
159 ok(hr == S_FALSE || broken(hr == S_OK), "got 0x%08x\n", hr);
160 ok(b == VARIANT_TRUE, "got 0x%x\n", b);
161 }
162 ITextStream_Release(stream);
163
164 hr = IFileSystem3_OpenTextFile(fs3, name, ForWriting, VARIANT_FALSE, TristateFalse, &stream);
165 ok(hr == S_OK, "got 0x%08x\n", hr);
166
167 b = 10;
168 hr = ITextStream_get_AtEndOfStream(stream, &b);
169 todo_wine {
170 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
171 ok(b == VARIANT_TRUE || broken(b == 10), "got 0x%x\n", b);
172 }
173 b = 10;
174 hr = ITextStream_get_AtEndOfLine(stream, &b);
175 todo_wine {
176 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
177 ok(b == VARIANT_FALSE || broken(b == 10), "got 0x%x\n", b);
178 }
179 hr = ITextStream_Read(stream, 1, &data);
180 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
181
182 hr = ITextStream_ReadLine(stream, &data);
183 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
184
185 hr = ITextStream_ReadAll(stream, &data);
186 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
187
188 ITextStream_Release(stream);
189
190 hr = IFileSystem3_OpenTextFile(fs3, name, ForAppending, VARIANT_FALSE, TristateFalse, &stream);
191 ok(hr == S_OK, "got 0x%08x\n", hr);
192 SysFreeString(name);
193
194 b = 10;
195 hr = ITextStream_get_AtEndOfStream(stream, &b);
196 todo_wine {
197 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
198 ok(b == VARIANT_TRUE || broken(b == 10), "got 0x%x\n", b);
199 }
200 b = 10;
201 hr = ITextStream_get_AtEndOfLine(stream, &b);
202 todo_wine {
203 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
204 ok(b == VARIANT_FALSE || broken(b == 10), "got 0x%x\n", b);
205 }
206 hr = ITextStream_Read(stream, 1, &data);
207 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
208
209 hr = ITextStream_ReadLine(stream, &data);
210 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
211
212 hr = ITextStream_ReadAll(stream, &data);
213 ok(hr == CTL_E_BADFILEMODE, "got 0x%08x\n", hr);
214
215 ITextStream_Release(stream);
216
217 DeleteFileW(testfileW);
218 }
219
220 static void test_GetFileVersion(void)
221 {
222 static const WCHAR k32W[] = {'\\','k','e','r','n','e','l','3','2','.','d','l','l',0};
223 static const WCHAR k33W[] = {'\\','k','e','r','n','e','l','3','3','.','d','l','l',0};
224 WCHAR pathW[MAX_PATH], filenameW[MAX_PATH];
225 BSTR path, version;
226 HRESULT hr;
227
228 GetSystemDirectoryW(pathW, sizeof(pathW)/sizeof(WCHAR));
229
230 lstrcpyW(filenameW, pathW);
231 lstrcatW(filenameW, k32W);
232
233 path = SysAllocString(filenameW);
234 hr = IFileSystem3_GetFileVersion(fs3, path, &version);
235 ok(hr == S_OK, "got 0x%08x\n", hr);
236 ok(*version != 0, "got %s\n", wine_dbgstr_w(version));
237 SysFreeString(version);
238 SysFreeString(path);
239
240 lstrcpyW(filenameW, pathW);
241 lstrcatW(filenameW, k33W);
242
243 path = SysAllocString(filenameW);
244 version = (void*)0xdeadbeef;
245 hr = IFileSystem3_GetFileVersion(fs3, path, &version);
246 ok(broken(hr == S_OK) || hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "got 0x%08x\n", hr);
247 if (hr == S_OK)
248 {
249 ok(*version == 0, "got %s\n", wine_dbgstr_w(version));
250 SysFreeString(version);
251 }
252 else
253 ok(version == (void*)0xdeadbeef, "got %p\n", version);
254 SysFreeString(path);
255 }
256
257 static void test_GetParentFolderName(void)
258 {
259 static const WCHAR path1[] = {'a',0};
260 static const WCHAR path2[] = {'a','/','a','/','a',0};
261 static const WCHAR path3[] = {'a','\\','a','\\','a',0};
262 static const WCHAR path4[] = {'a','/','a','/','/','\\','\\',0};
263 static const WCHAR path5[] = {'c',':','\\','\\','a',0};
264 static const WCHAR path6[] = {'a','c',':','\\','a',0};
265 static const WCHAR result2[] = {'a','/','a',0};
266 static const WCHAR result3[] = {'a','\\','a',0};
267 static const WCHAR result4[] = {'a',0};
268 static const WCHAR result5[] = {'c',':','\\',0};
269 static const WCHAR result6[] = {'a','c',':',0};
270
271 static const struct {
272 const WCHAR *path;
273 const WCHAR *result;
274 } tests[] = {
275 {NULL, NULL},
276 {path1, NULL},
277 {path2, result2},
278 {path3, result3},
279 {path4, result4},
280 {path5, result5},
281 {path6, result6}
282 };
283
284 BSTR path, result;
285 HRESULT hr;
286 int i;
287
288 hr = IFileSystem3_GetParentFolderName(fs3, NULL, NULL);
289 ok(hr == E_POINTER, "GetParentFolderName returned %x, expected E_POINTER\n", hr);
290
291 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
292 result = (BSTR)0xdeadbeef;
293 path = tests[i].path ? SysAllocString(tests[i].path) : NULL;
294 hr = IFileSystem3_GetParentFolderName(fs3, path, &result);
295 ok(hr == S_OK, "%d) GetParentFolderName returned %x, expected S_OK\n", i, hr);
296 if(!tests[i].result)
297 ok(!result, "%d) result = %s\n", i, wine_dbgstr_w(result));
298 else
299 ok(!lstrcmpW(result, tests[i].result), "%d) result = %s\n", i, wine_dbgstr_w(result));
300 SysFreeString(path);
301 SysFreeString(result);
302 }
303 }
304
305 static void test_GetFileName(void)
306 {
307 static const WCHAR path1[] = {'a',0};
308 static const WCHAR path2[] = {'a','/','a','.','b',0};
309 static const WCHAR path3[] = {'a','\\',0};
310 static const WCHAR path4[] = {'c',':',0};
311 static const WCHAR path5[] = {'/','\\',0};
312 static const WCHAR result2[] = {'a','.','b',0};
313 static const WCHAR result3[] = {'a',0};
314
315 static const struct {
316 const WCHAR *path;
317 const WCHAR *result;
318 } tests[] = {
319 {NULL, NULL},
320 {path1, path1},
321 {path2, result2},
322 {path3, result3},
323 {path4, NULL},
324 {path5, NULL}
325 };
326
327 BSTR path, result;
328 HRESULT hr;
329 int i;
330
331 hr = IFileSystem3_GetFileName(fs3, NULL, NULL);
332 ok(hr == E_POINTER, "GetFileName returned %x, expected E_POINTER\n", hr);
333
334 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
335 result = (BSTR)0xdeadbeef;
336 path = tests[i].path ? SysAllocString(tests[i].path) : NULL;
337 hr = IFileSystem3_GetFileName(fs3, path, &result);
338 ok(hr == S_OK, "%d) GetFileName returned %x, expected S_OK\n", i, hr);
339 if(!tests[i].result)
340 ok(!result, "%d) result = %s\n", i, wine_dbgstr_w(result));
341 else
342 ok(!lstrcmpW(result, tests[i].result), "%d) result = %s\n", i, wine_dbgstr_w(result));
343 SysFreeString(path);
344 SysFreeString(result);
345 }
346 }
347
348 static void test_GetBaseName(void)
349 {
350 static const WCHAR path1[] = {'a',0};
351 static const WCHAR path2[] = {'a','/','a','.','b','.','c',0};
352 static const WCHAR path3[] = {'a','.','b','\\',0};
353 static const WCHAR path4[] = {'c',':',0};
354 static const WCHAR path5[] = {'/','\\',0};
355 static const WCHAR path6[] = {'.','a',0};
356 static const WCHAR result1[] = {'a',0};
357 static const WCHAR result2[] = {'a','.','b',0};
358 static const WCHAR result6[] = {0};
359
360 static const struct {
361 const WCHAR *path;
362 const WCHAR *result;
363 } tests[] = {
364 {NULL, NULL},
365 {path1, result1},
366 {path2, result2},
367 {path3, result1},
368 {path4, NULL},
369 {path5, NULL},
370 {path6, result6}
371 };
372
373 BSTR path, result;
374 HRESULT hr;
375 int i;
376
377 hr = IFileSystem3_GetBaseName(fs3, NULL, NULL);
378 ok(hr == E_POINTER, "GetBaseName returned %x, expected E_POINTER\n", hr);
379
380 for(i=0; i<sizeof(tests)/sizeof(tests[0]); i++) {
381 result = (BSTR)0xdeadbeef;
382 path = tests[i].path ? SysAllocString(tests[i].path) : NULL;
383 hr = IFileSystem3_GetBaseName(fs3, path, &result);
384 ok(hr == S_OK, "%d) GetBaseName returned %x, expected S_OK\n", i, hr);
385 if(!tests[i].result)
386 ok(!result, "%d) result = %s\n", i, wine_dbgstr_w(result));
387 else
388 ok(!lstrcmpW(result, tests[i].result), "%d) result = %s\n", i, wine_dbgstr_w(result));
389 SysFreeString(path);
390 SysFreeString(result);
391 }
392 }
393
394 static void test_GetAbsolutePathName(void)
395 {
396 static const WCHAR dir1[] = {'t','e','s','t','_','d','i','r','1',0};
397 static const WCHAR dir2[] = {'t','e','s','t','_','d','i','r','2',0};
398 static const WCHAR dir_match1[] = {'t','e','s','t','_','d','i','r','*',0};
399 static const WCHAR dir_match2[] = {'t','e','s','t','_','d','i','*',0};
400 static const WCHAR cur_dir[] = {'.',0};
401
402 WIN32_FIND_DATAW fdata;
403 HANDLE find;
404 WCHAR buf[MAX_PATH], buf2[MAX_PATH];
405 BSTR path, result;
406 HRESULT hr;
407
408 hr = IFileSystem3_GetAbsolutePathName(fs3, NULL, NULL);
409 ok(hr == E_POINTER, "GetAbsolutePathName returned %x, expected E_POINTER\n", hr);
410
411 hr = IFileSystem3_GetAbsolutePathName(fs3, NULL, &result);
412 ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
413 GetFullPathNameW(cur_dir, MAX_PATH, buf, NULL);
414 ok(!lstrcmpW(buf, result), "result = %s, expected %s\n", wine_dbgstr_w(result), wine_dbgstr_w(buf));
415 SysFreeString(result);
416
417 find = FindFirstFileW(dir_match2, &fdata);
418 if(find != INVALID_HANDLE_VALUE) {
419 skip("GetAbsolutePathName tests\n");
420 FindClose(find);
421 return;
422 }
423
424 path = SysAllocString(dir_match1);
425 hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
426 ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
427 GetFullPathNameW(dir_match1, MAX_PATH, buf2, NULL);
428 ok(!lstrcmpW(buf2, result), "result = %s, expected %s\n", wine_dbgstr_w(result), wine_dbgstr_w(buf2));
429 SysFreeString(result);
430
431 ok(CreateDirectoryW(dir1, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(dir1));
432 hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
433 ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
434 GetFullPathNameW(dir1, MAX_PATH, buf, NULL);
435 ok(!lstrcmpW(buf, result) || broken(!lstrcmpW(buf2, result)), "result = %s, expected %s\n",
436 wine_dbgstr_w(result), wine_dbgstr_w(buf));
437 SysFreeString(result);
438
439 ok(CreateDirectoryW(dir2, NULL), "CreateDirectory(%s) failed\n", wine_dbgstr_w(dir2));
440 hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
441 ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
442 if(!lstrcmpW(buf, result) || !lstrcmpW(buf2, result)) {
443 ok(!lstrcmpW(buf, result) || broken(!lstrcmpW(buf2, result)), "result = %s, expected %s\n",
444 wine_dbgstr_w(result), wine_dbgstr_w(buf));
445 }else {
446 GetFullPathNameW(dir2, MAX_PATH, buf, NULL);
447 ok(!lstrcmpW(buf, result), "result = %s, expected %s\n",
448 wine_dbgstr_w(result), wine_dbgstr_w(buf));
449 }
450 SysFreeString(result);
451
452 SysFreeString(path);
453 path = SysAllocString(dir_match2);
454 hr = IFileSystem3_GetAbsolutePathName(fs3, path, &result);
455 ok(hr == S_OK, "GetAbsolutePathName returned %x, expected S_OK\n", hr);
456 GetFullPathNameW(dir_match2, MAX_PATH, buf, NULL);
457 ok(!lstrcmpW(buf, result), "result = %s, expected %s\n", wine_dbgstr_w(result), wine_dbgstr_w(buf));
458 SysFreeString(result);
459 SysFreeString(path);
460
461 RemoveDirectoryW(dir1);
462 RemoveDirectoryW(dir2);
463 }
464
465 static void test_GetFile(void)
466 {
467 static const WCHAR get_file[] = {'g','e','t','_','f','i','l','e','.','t','s','t',0};
468
469 BSTR path = SysAllocString(get_file);
470 FileAttribute fa;
471 VARIANT size;
472 DWORD gfa;
473 IFile *file;
474 HRESULT hr;
475 HANDLE hf;
476
477 hr = IFileSystem3_GetFile(fs3, path, NULL);
478 ok(hr == E_POINTER, "GetFile returned %x, expected E_POINTER\n", hr);
479 hr = IFileSystem3_GetFile(fs3, NULL, &file);
480 ok(hr == E_INVALIDARG, "GetFile returned %x, expected E_INVALIDARG\n", hr);
481
482 if(GetFileAttributesW(path) != INVALID_FILE_ATTRIBUTES) {
483 skip("File already exists, skipping GetFile tests\n");
484 SysFreeString(path);
485 return;
486 }
487
488 file = (IFile*)0xdeadbeef;
489 hr = IFileSystem3_GetFile(fs3, path, &file);
490 ok(!file, "file != NULL\n");
491 ok(hr == CTL_E_FILENOTFOUND, "GetFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
492
493 hf = CreateFileW(path, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_READONLY, NULL);
494 if(hf == INVALID_HANDLE_VALUE) {
495 skip("Can't create temporary file\n");
496 SysFreeString(path);
497 return;
498 }
499 CloseHandle(hf);
500
501 hr = IFileSystem3_GetFile(fs3, path, &file);
502 ok(hr == S_OK, "GetFile returned %x, expected S_OK\n", hr);
503
504 hr = IFile_get_Attributes(file, &fa);
505 gfa = GetFileAttributesW(get_file) & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN |
506 FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_ARCHIVE |
507 FILE_ATTRIBUTE_REPARSE_POINT | FILE_ATTRIBUTE_COMPRESSED);
508 ok(hr == S_OK, "get_Attributes returned %x, expected S_OK\n", hr);
509 ok(fa == gfa, "fa = %x, expected %x\n", fa, gfa);
510
511 hr = IFile_get_Size(file, &size);
512 ok(hr == S_OK, "get_Size returned %x, expected S_OK\n", hr);
513 ok(V_VT(&size) == VT_I4, "V_VT(&size) = %d, expected VT_I4\n", V_VT(&size));
514 ok(V_I4(&size) == 0, "V_I4(&size) = %d, expected 0\n", V_I4(&size));
515 IFile_Release(file);
516
517 hr = IFileSystem3_DeleteFile(fs3, path, FALSE);
518 ok(hr==CTL_E_PERMISSIONDENIED || broken(hr==S_OK),
519 "DeleteFile returned %x, expected CTL_E_PERMISSIONDENIED\n", hr);
520 if(hr != S_OK) {
521 hr = IFileSystem3_DeleteFile(fs3, path, TRUE);
522 ok(hr == S_OK, "DeleteFile returned %x, expected S_OK\n", hr);
523 }
524 hr = IFileSystem3_DeleteFile(fs3, path, TRUE);
525 ok(hr == CTL_E_FILENOTFOUND, "DeleteFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
526
527 SysFreeString(path);
528 }
529
530 static inline BOOL create_file(const WCHAR *name)
531 {
532 HANDLE f = CreateFileW(name, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
533 CloseHandle(f);
534 return f != INVALID_HANDLE_VALUE;
535 }
536
537 static inline void create_path(const WCHAR *folder, const WCHAR *name, WCHAR *ret)
538 {
539 DWORD len = lstrlenW(folder);
540 memmove(ret, folder, len*sizeof(WCHAR));
541 ret[len] = '\\';
542 memmove(ret+len+1, name, (lstrlenW(name)+1)*sizeof(WCHAR));
543 }
544
545 static void test_CopyFolder(void)
546 {
547 static const WCHAR filesystem3_dir[] = {'f','i','l','e','s','y','s','t','e','m','3','_','t','e','s','t',0};
548 static const WCHAR s1[] = {'s','r','c','1',0};
549 static const WCHAR s[] = {'s','r','c','*',0};
550 static const WCHAR d[] = {'d','s','t',0};
551 static const WCHAR empty[] = {0};
552
553 WCHAR tmp[MAX_PATH];
554 BSTR bsrc, bdst;
555 HRESULT hr;
556
557 if(!CreateDirectoryW(filesystem3_dir, NULL)) {
558 skip("can't create temporary directory\n");
559 return;
560 }
561
562 create_path(filesystem3_dir, s1, tmp);
563 bsrc = SysAllocString(tmp);
564 create_path(filesystem3_dir, d, tmp);
565 bdst = SysAllocString(tmp);
566 hr = IFileSystem3_CopyFile(fs3, bsrc, bdst, VARIANT_TRUE);
567 ok(hr == CTL_E_FILENOTFOUND, "CopyFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
568
569 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
570 ok(hr == CTL_E_PATHNOTFOUND, "CopyFolder returned %x, expected CTL_E_PATHNOTFOUND\n", hr);
571
572 ok(create_file(bsrc), "can't create %s file\n", wine_dbgstr_w(bsrc));
573 hr = IFileSystem3_CopyFile(fs3, bsrc, bdst, VARIANT_TRUE);
574 ok(hr == S_OK, "CopyFile returned %x, expected S_OK\n", hr);
575
576 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
577 ok(hr == CTL_E_PATHNOTFOUND, "CopyFolder returned %x, expected CTL_E_PATHNOTFOUND\n", hr);
578
579 hr = IFileSystem3_DeleteFile(fs3, bsrc, VARIANT_FALSE);
580 ok(hr == S_OK, "DeleteFile returned %x, expected S_OK\n", hr);
581
582 ok(CreateDirectoryW(bsrc, NULL), "can't create %s\n", wine_dbgstr_w(bsrc));
583 hr = IFileSystem3_CopyFile(fs3, bsrc, bdst, VARIANT_TRUE);
584 ok(hr == CTL_E_FILENOTFOUND, "CopyFile returned %x, expected CTL_E_FILENOTFOUND\n", hr);
585
586 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
587 ok(hr == CTL_E_FILEALREADYEXISTS, "CopyFolder returned %x, expected CTL_E_FILEALREADYEXISTS\n", hr);
588
589 hr = IFileSystem3_DeleteFile(fs3, bdst, VARIANT_TRUE);
590 ok(hr == S_OK, "DeleteFile returned %x, expected S_OK\n", hr);
591
592 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
593 ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
594
595 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
596 ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
597 create_path(tmp, s1, tmp);
598 ok(GetFileAttributesW(tmp) == INVALID_FILE_ATTRIBUTES,
599 "%s file exists\n", wine_dbgstr_w(tmp));
600
601 create_path(filesystem3_dir, d, tmp);
602 create_path(tmp, empty, tmp);
603 SysFreeString(bdst);
604 bdst = SysAllocString(tmp);
605 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
606 ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
607 create_path(tmp, s1, tmp);
608 ok(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES,
609 "%s directory doesn't exist\n", wine_dbgstr_w(tmp));
610 ok(RemoveDirectoryW(tmp), "can't remove %s directory\n", wine_dbgstr_w(tmp));
611 create_path(filesystem3_dir, d, tmp);
612 SysFreeString(bdst);
613 bdst = SysAllocString(tmp);
614
615
616 create_path(filesystem3_dir, s, tmp);
617 SysFreeString(bsrc);
618 bsrc = SysAllocString(tmp);
619 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
620 ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
621 create_path(filesystem3_dir, d, tmp);
622 create_path(tmp, s1, tmp);
623 ok(GetFileAttributesW(tmp) != INVALID_FILE_ATTRIBUTES,
624 "%s directory doesn't exist\n", wine_dbgstr_w(tmp));
625
626 hr = IFileSystem3_DeleteFolder(fs3, bdst, VARIANT_FALSE);
627 ok(hr == S_OK, "DeleteFolder returned %x, expected S_OK\n", hr);
628
629 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
630 ok(hr == CTL_E_PATHNOTFOUND, "CopyFolder returned %x, expected CTL_E_PATHNOTFOUND\n", hr);
631
632 create_path(filesystem3_dir, s1, tmp);
633 SysFreeString(bsrc);
634 bsrc = SysAllocString(tmp);
635 create_path(tmp, s1, tmp);
636 ok(create_file(tmp), "can't create %s file\n", wine_dbgstr_w(tmp));
637 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_FALSE);
638 ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
639
640 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_FALSE);
641 ok(hr == CTL_E_FILEALREADYEXISTS, "CopyFolder returned %x, expected CTL_E_FILEALREADYEXISTS\n", hr);
642
643 hr = IFileSystem3_CopyFolder(fs3, bsrc, bdst, VARIANT_TRUE);
644 ok(hr == S_OK, "CopyFolder returned %x, expected S_OK\n", hr);
645 SysFreeString(bsrc);
646 SysFreeString(bdst);
647
648 bsrc = SysAllocString(filesystem3_dir);
649 hr = IFileSystem3_DeleteFolder(fs3, bsrc, VARIANT_FALSE);
650 ok(hr == S_OK, "DeleteFolder returned %x, expected S_OK\n", hr);
651 SysFreeString(bsrc);
652 }
653
654 START_TEST(filesystem)
655 {
656 HRESULT hr;
657
658 CoInitialize(NULL);
659
660 hr = CoCreateInstance(&CLSID_FileSystemObject, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
661 &IID_IFileSystem3, (void**)&fs3);
662 if(FAILED(hr)) {
663 win_skip("Could not create FileSystem object: %08x\n", hr);
664 return;
665 }
666
667 test_interfaces();
668 test_createfolder();
669 test_textstream();
670 test_GetFileVersion();
671 test_GetParentFolderName();
672 test_GetFileName();
673 test_GetBaseName();
674 test_GetAbsolutePathName();
675 test_GetFile();
676 test_CopyFolder();
677
678 IFileSystem3_Release(fs3);
679
680 CoUninitialize();
681 }