4a985bed22efe76283987325ac473682a2c2dce5
[reactos.git] / rostests / winetests / advpack / files.c
1 /*
2 * Unit tests for advpack.dll file functions
3 *
4 * Copyright (C) 2006 James Hawkins
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include <stdio.h>
22 #include <windows.h>
23 #include <advpub.h>
24 #include <fci.h>
25 #include "wine/test.h"
26
27 /* make the max size large so there is only one cab file */
28 #define MEDIA_SIZE 999999999
29 #define FOLDER_THRESHOLD 900000
30
31 /* function pointers */
32 static HMODULE hAdvPack;
33 static HRESULT (WINAPI *pAddDelBackupEntry)(LPCSTR, LPCSTR, LPCSTR, DWORD);
34 static HRESULT (WINAPI *pExtractFiles)(LPCSTR, LPCSTR, DWORD, LPCSTR, LPVOID, DWORD);
35 static HRESULT (WINAPI *pExtractFilesW)(const WCHAR*,const WCHAR*,DWORD,const WCHAR*,void*,DWORD);
36 static HRESULT (WINAPI *pAdvInstallFile)(HWND,LPCSTR,LPCSTR,LPCSTR,LPCSTR,DWORD,DWORD);
37
38 static CHAR CURR_DIR[MAX_PATH];
39
40 static void init_function_pointers(void)
41 {
42 hAdvPack = LoadLibraryA("advpack.dll");
43
44 if (hAdvPack)
45 {
46 pAddDelBackupEntry = (void *)GetProcAddress(hAdvPack, "AddDelBackupEntry");
47 pExtractFiles = (void *)GetProcAddress(hAdvPack, "ExtractFiles");
48 pExtractFilesW = (void *)GetProcAddress(hAdvPack, "ExtractFilesW");
49 pAdvInstallFile = (void*)GetProcAddress(hAdvPack, "AdvInstallFile");
50 }
51 }
52
53 /* creates a file with the specified name for tests */
54 static void createTestFile(const CHAR *name)
55 {
56 HANDLE file;
57 DWORD written;
58
59 file = CreateFileA(name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
60 ok(file != INVALID_HANDLE_VALUE, "Failure to open file %s\n", name);
61 WriteFile(file, name, strlen(name), &written, NULL);
62 WriteFile(file, "\n", strlen("\n"), &written, NULL);
63 CloseHandle(file);
64 }
65
66 static void create_test_files(void)
67 {
68 createTestFile("a.txt");
69 createTestFile("b.txt");
70 CreateDirectoryA("testdir", NULL);
71 createTestFile("testdir\\c.txt");
72 createTestFile("testdir\\d.txt");
73 CreateDirectoryA("dest", NULL);
74 }
75
76 static void delete_test_files(void)
77 {
78 DeleteFileA("a.txt");
79 DeleteFileA("b.txt");
80 DeleteFileA("testdir\\c.txt");
81 DeleteFileA("testdir\\d.txt");
82 RemoveDirectoryA("testdir");
83 RemoveDirectoryA("dest");
84
85 DeleteFileA("extract.cab");
86 }
87
88 static BOOL check_ini_file_attr(LPSTR filename)
89 {
90 BOOL ret;
91 DWORD expected = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY;
92 DWORD attr = GetFileAttributesA(filename);
93
94 ret = (attr & expected) && (attr != INVALID_FILE_ATTRIBUTES);
95 SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL);
96
97 return ret;
98 }
99
100 static void test_AddDelBackupEntry(void)
101 {
102 BOOL ret;
103 HRESULT res;
104 CHAR path[MAX_PATH];
105 CHAR windir[MAX_PATH];
106
107 lstrcpyA(path, CURR_DIR);
108 lstrcatA(path, "\\backup\\basename.INI");
109
110 /* native AddDelBackupEntry crashes if lpcszBaseName is NULL */
111
112 /* try a NULL file list */
113 res = pAddDelBackupEntry(NULL, "backup", "basename", AADBE_ADD_ENTRY);
114 ok(res == S_OK, "Expected S_OK, got %d\n", res);
115 ok(!DeleteFileA(path), "Expected path to not exist\n");
116
117 lstrcpyA(path, CURR_DIR);
118 lstrcatA(path, "\\backup\\.INI");
119
120 /* try an empty base name */
121 res = pAddDelBackupEntry("one\0two\0three\0", "backup", "", AADBE_ADD_ENTRY);
122 ok(res == S_OK, "Expected S_OK, got %d\n", res);
123 ok(!DeleteFileA(path), "Expected path to not exist\n");
124
125 lstrcpyA(path, CURR_DIR);
126 lstrcatA(path, "\\basename.INI");
127
128 /* try an invalid flag */
129 res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", 0);
130 ok(res == S_OK, "Expected S_OK, got %d\n", res);
131 ok(!DeleteFileA(path), "Expected path to not exist\n");
132
133 lstrcpyA(path, "c:\\basename.INI");
134
135 /* create the INF file */
136 res = pAddDelBackupEntry("one\0two\0three\0", "c:\\", "basename", AADBE_ADD_ENTRY);
137 ok(res == S_OK, "Expected S_OK, got %d\n", res);
138 if (GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES)
139 {
140 ok(check_ini_file_attr(path), "Expected ini file to be hidden\n");
141 ok(DeleteFileA(path), "Expected path to exist\n");
142 }
143 else
144 win_skip("Test file could not be created\n");
145
146 lstrcpyA(path, CURR_DIR);
147 lstrcatA(path, "\\backup\\basename.INI");
148
149 /* try to create the INI file in a nonexistent directory */
150 RemoveDirectoryA("backup");
151 res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY);
152 ok(res == S_OK, "Expected S_OK, got %d\n", res);
153 ok(!check_ini_file_attr(path), "Expected ini file to not be hidden\n");
154 ok(!DeleteFileA(path), "Expected path to not exist\n");
155
156 /* try an existent, relative backup directory */
157 CreateDirectoryA("backup", NULL);
158 res = pAddDelBackupEntry("one\0two\0three\0", "backup", "basename", AADBE_ADD_ENTRY);
159 ok(res == S_OK, "Expected S_OK, got %d\n", res);
160 ok(check_ini_file_attr(path), "Expected ini file to be hidden\n");
161 ok(DeleteFileA(path), "Expected path to exist\n");
162 RemoveDirectoryA("backup");
163
164 GetWindowsDirectoryA(windir, sizeof(windir));
165 sprintf(path, "%s\\basename.INI", windir);
166
167 /* try a NULL backup dir, INI is created in the windows directory */
168 res = pAddDelBackupEntry("one\0two\0three\0", NULL, "basename", AADBE_ADD_ENTRY);
169 ok(res == S_OK, "Expected S_OK, got %d\n", res);
170
171 /* remove the entries with AADBE_DEL_ENTRY */
172 SetFileAttributesA(path, FILE_ATTRIBUTE_NORMAL);
173 res = pAddDelBackupEntry("one\0three\0", NULL, "basename", AADBE_DEL_ENTRY);
174 SetFileAttributesA(path, FILE_ATTRIBUTE_NORMAL);
175 ok(res == S_OK, "Expected S_OK, got %d\n", res);
176 ret = DeleteFileA(path);
177 ok(ret == TRUE ||
178 broken(ret == FALSE), /* win98 */
179 "Expected path to exist\n");
180 }
181
182 /* the FCI callbacks */
183
184 static void * CDECL mem_alloc(ULONG cb)
185 {
186 return HeapAlloc(GetProcessHeap(), 0, cb);
187 }
188
189 static void CDECL mem_free(void *memory)
190 {
191 HeapFree(GetProcessHeap(), 0, memory);
192 }
193
194 static BOOL CDECL get_next_cabinet(PCCAB pccab, ULONG cbPrevCab, void *pv)
195 {
196 return TRUE;
197 }
198
199 static LONG CDECL progress(UINT typeStatus, ULONG cb1, ULONG cb2, void *pv)
200 {
201 return 0;
202 }
203
204 static int CDECL file_placed(PCCAB pccab, char *pszFile, LONG cbFile,
205 BOOL fContinuation, void *pv)
206 {
207 return 0;
208 }
209
210 static INT_PTR CDECL fci_open(char *pszFile, int oflag, int pmode, int *err, void *pv)
211 {
212 HANDLE handle;
213 DWORD dwAccess = 0;
214 DWORD dwShareMode = 0;
215 DWORD dwCreateDisposition = OPEN_EXISTING;
216
217 dwAccess = GENERIC_READ | GENERIC_WRITE;
218 /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
219 dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
220
221 if (GetFileAttributesA(pszFile) != INVALID_FILE_ATTRIBUTES)
222 dwCreateDisposition = OPEN_EXISTING;
223 else
224 dwCreateDisposition = CREATE_NEW;
225
226 handle = CreateFileA(pszFile, dwAccess, dwShareMode, NULL,
227 dwCreateDisposition, 0, NULL);
228
229 ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszFile);
230
231 return (INT_PTR)handle;
232 }
233
234 static UINT CDECL fci_read(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
235 {
236 HANDLE handle = (HANDLE)hf;
237 DWORD dwRead;
238 BOOL res;
239
240 res = ReadFile(handle, memory, cb, &dwRead, NULL);
241 ok(res, "Failed to ReadFile\n");
242
243 return dwRead;
244 }
245
246 static UINT CDECL fci_write(INT_PTR hf, void *memory, UINT cb, int *err, void *pv)
247 {
248 HANDLE handle = (HANDLE)hf;
249 DWORD dwWritten;
250 BOOL res;
251
252 res = WriteFile(handle, memory, cb, &dwWritten, NULL);
253 ok(res, "Failed to WriteFile\n");
254
255 return dwWritten;
256 }
257
258 static int CDECL fci_close(INT_PTR hf, int *err, void *pv)
259 {
260 HANDLE handle = (HANDLE)hf;
261 ok(CloseHandle(handle), "Failed to CloseHandle\n");
262
263 return 0;
264 }
265
266 static LONG CDECL fci_seek(INT_PTR hf, LONG dist, int seektype, int *err, void *pv)
267 {
268 HANDLE handle = (HANDLE)hf;
269 DWORD ret;
270
271 ret = SetFilePointer(handle, dist, NULL, seektype);
272 ok(ret != INVALID_SET_FILE_POINTER, "Failed to SetFilePointer\n");
273
274 return ret;
275 }
276
277 static int CDECL fci_delete(char *pszFile, int *err, void *pv)
278 {
279 BOOL ret = DeleteFileA(pszFile);
280 ok(ret, "Failed to DeleteFile %s\n", pszFile);
281
282 return 0;
283 }
284
285 static BOOL CDECL get_temp_file(char *pszTempName, int cbTempName, void *pv)
286 {
287 LPSTR tempname;
288
289 tempname = HeapAlloc(GetProcessHeap(), 0, MAX_PATH);
290 GetTempFileNameA(".", "xx", 0, tempname);
291
292 if (tempname && (strlen(tempname) < (unsigned)cbTempName))
293 {
294 lstrcpyA(pszTempName, tempname);
295 HeapFree(GetProcessHeap(), 0, tempname);
296 return TRUE;
297 }
298
299 HeapFree(GetProcessHeap(), 0, tempname);
300
301 return FALSE;
302 }
303
304 static INT_PTR CDECL get_open_info(char *pszName, USHORT *pdate, USHORT *ptime,
305 USHORT *pattribs, int *err, void *pv)
306 {
307 BY_HANDLE_FILE_INFORMATION finfo;
308 FILETIME filetime;
309 HANDLE handle;
310 DWORD attrs;
311 BOOL res;
312
313 handle = CreateFile(pszName, GENERIC_READ, FILE_SHARE_READ, NULL,
314 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
315
316 ok(handle != INVALID_HANDLE_VALUE, "Failed to CreateFile %s\n", pszName);
317
318 res = GetFileInformationByHandle(handle, &finfo);
319 ok(res, "Expected GetFileInformationByHandle to succeed\n");
320
321 FileTimeToLocalFileTime(&finfo.ftLastWriteTime, &filetime);
322 FileTimeToDosDateTime(&filetime, pdate, ptime);
323
324 attrs = GetFileAttributes(pszName);
325 ok(attrs != INVALID_FILE_ATTRIBUTES, "Failed to GetFileAttributes\n");
326
327 return (INT_PTR)handle;
328 }
329
330 static void add_file(HFCI hfci, char *file)
331 {
332 char path[MAX_PATH];
333 BOOL res;
334
335 lstrcpyA(path, CURR_DIR);
336 lstrcatA(path, "\\");
337 lstrcatA(path, file);
338
339 res = FCIAddFile(hfci, path, file, FALSE, get_next_cabinet, progress,
340 get_open_info, tcompTYPE_MSZIP);
341 ok(res, "Expected FCIAddFile to succeed\n");
342 }
343
344 static void set_cab_parameters(PCCAB pCabParams)
345 {
346 ZeroMemory(pCabParams, sizeof(CCAB));
347
348 pCabParams->cb = MEDIA_SIZE;
349 pCabParams->cbFolderThresh = FOLDER_THRESHOLD;
350 pCabParams->setID = 0xbeef;
351 lstrcpyA(pCabParams->szCabPath, CURR_DIR);
352 lstrcatA(pCabParams->szCabPath, "\\");
353 lstrcpyA(pCabParams->szCab, "extract.cab");
354 }
355
356 static void create_cab_file(void)
357 {
358 CCAB cabParams;
359 HFCI hfci;
360 ERF erf;
361 static CHAR a_txt[] = "a.txt",
362 b_txt[] = "b.txt",
363 testdir_c_txt[] = "testdir\\c.txt",
364 testdir_d_txt[] = "testdir\\d.txt";
365 BOOL res;
366
367 set_cab_parameters(&cabParams);
368
369 hfci = FCICreate(&erf, file_placed, mem_alloc, mem_free, fci_open,
370 fci_read, fci_write, fci_close, fci_seek, fci_delete,
371 get_temp_file, &cabParams, NULL);
372
373 ok(hfci != NULL, "Failed to create an FCI context\n");
374
375 add_file(hfci, a_txt);
376 add_file(hfci, b_txt);
377 add_file(hfci, testdir_c_txt);
378 add_file(hfci, testdir_d_txt);
379
380 res = FCIFlushCabinet(hfci, FALSE, get_next_cabinet, progress);
381 ok(res, "Failed to flush the cabinet\n");
382
383 res = FCIDestroy(hfci);
384 ok(res, "Failed to destroy the cabinet\n");
385 }
386
387 static void test_ExtractFiles(void)
388 {
389 HRESULT hr;
390 char destFolder[MAX_PATH];
391
392 lstrcpyA(destFolder, CURR_DIR);
393 lstrcatA(destFolder, "\\");
394 lstrcatA(destFolder, "dest");
395
396 /* try NULL cab file */
397 hr = pExtractFiles(NULL, destFolder, 0, NULL, NULL, 0);
398 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
399 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
400
401 /* try NULL destination */
402 hr = pExtractFiles("extract.cab", NULL, 0, NULL, NULL, 0);
403 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
404 ok(!RemoveDirectoryA("dest"), "Expected dest to not exist\n");
405
406 /* extract all files in the cab to nonexistent destination directory */
407 hr = pExtractFiles("extract.cab", destFolder, 0, NULL, NULL, 0);
408 ok(hr == HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND) ||
409 hr == E_FAIL, /* win95 */
410 "Expected %08x or %08x, got %08x\n", E_FAIL,
411 HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND), hr);
412 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
413 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
414 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
415 ok(!RemoveDirectoryA("dest"), "Expected dest to not exist\n");
416
417 /* extract all files in the cab to the destination directory */
418 CreateDirectoryA("dest", NULL);
419 hr = pExtractFiles("extract.cab", destFolder, 0, NULL, NULL, 0);
420 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
421 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
422 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
423 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
424 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
425 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
426
427 /* extract all files to a relative destination directory */
428 hr = pExtractFiles("extract.cab", "dest", 0, NULL, NULL, 0);
429 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
430 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
431 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
432 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
433 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
434 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
435
436 /* only extract two of the files from the cab */
437 hr = pExtractFiles("extract.cab", "dest", 0, "a.txt:testdir\\c.txt", NULL, 0);
438 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
439 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
440 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
441 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
442 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
443 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
444
445 /* use valid chars before and after file list */
446 hr = pExtractFiles("extract.cab", "dest", 0, " :\t: a.txt:testdir\\c.txt \t:", NULL, 0);
447 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
448 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
449 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
450 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
451 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
452 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
453
454 /* use invalid chars before and after file list */
455 hr = pExtractFiles("extract.cab", "dest", 0, " +-\\ a.txt:testdir\\c.txt a_:", NULL, 0);
456 ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr);
457 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
458 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
459 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
460
461 /* try an empty file list */
462 hr = pExtractFiles("extract.cab", "dest", 0, "", NULL, 0);
463 ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr);
464 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
465 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
466
467 /* try a nonexistent file in the file list */
468 hr = pExtractFiles("extract.cab", "dest", 0, "a.txt:idontexist:testdir\\c.txt", NULL, 0);
469 ok(hr == E_FAIL, "Expected E_FAIL, got %d\n", hr);
470 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
471 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
472 ok(!RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to not exist\n");
473
474 if(pExtractFilesW) {
475 static const WCHAR extract_cabW[] = {'e','x','t','r','a','c','t','.','c','a','b',0};
476 static const WCHAR destW[] = {'d','e','s','t',0};
477 static const WCHAR file_listW[] =
478 {'a','.','t','x','t',':','t','e','s','t','d','i','r','\\','c','.','t','x','t',0};
479
480 hr = pExtractFilesW(extract_cabW, destW, 0, file_listW, NULL, 0);
481 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
482 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
483 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
484 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
485 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
486 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
487 }else {
488 win_skip("ExtractFilesW not available\n");
489 }
490 }
491
492 static void test_AdvInstallFile(void)
493 {
494 HRESULT hr;
495 HMODULE hmod;
496 char destFolder[MAX_PATH];
497
498 hmod = LoadLibrary("setupapi.dll");
499 if (!hmod)
500 {
501 skip("setupapi.dll not present\n");
502 return;
503 }
504
505 FreeLibrary(hmod);
506
507 lstrcpyA(destFolder, CURR_DIR);
508 lstrcatA(destFolder, "\\");
509 lstrcatA(destFolder, "dest");
510
511 createTestFile("source.txt");
512
513 /* try invalid source directory */
514 hr = pAdvInstallFile(NULL, NULL, "source.txt", destFolder, "destination.txt", 0, 0);
515 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
516 ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");
517
518 /* try invalid source file */
519 hr = pAdvInstallFile(NULL, CURR_DIR, NULL, destFolder, "destination.txt", 0, 0);
520 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
521 ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");
522
523 /* try invalid destination directory */
524 hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", NULL, "destination.txt", 0, 0);
525 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %d\n", hr);
526 ok(!DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to not exist\n");
527
528 /* try copying to nonexistent destination directory */
529 hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder, "destination.txt", 0, 0);
530 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
531 ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n");
532
533 /* native windows screws up if the source file doesn't exist */
534
535 /* test AIF_NOOVERWRITE behavior, asks the user to overwrite if AIF_QUIET is not specified */
536 createTestFile("dest\\destination.txt");
537 hr = pAdvInstallFile(NULL, CURR_DIR, "source.txt", destFolder,
538 "destination.txt", AIF_NOOVERWRITE | AIF_QUIET, 0);
539 ok(hr == S_OK, "Expected S_OK, got %d\n", hr);
540 ok(DeleteFileA("dest\\destination.txt"), "Expected dest\\destination.txt to exist\n");
541 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
542
543 DeleteFileA("source.txt");
544 }
545
546 START_TEST(files)
547 {
548 DWORD len;
549 char temp_path[MAX_PATH], prev_path[MAX_PATH];
550
551 init_function_pointers();
552
553 GetCurrentDirectoryA(MAX_PATH, prev_path);
554 GetTempPath(MAX_PATH, temp_path);
555 SetCurrentDirectoryA(temp_path);
556
557 lstrcpyA(CURR_DIR, temp_path);
558 len = lstrlenA(CURR_DIR);
559
560 if(len && (CURR_DIR[len - 1] == '\\'))
561 CURR_DIR[len - 1] = 0;
562
563 create_test_files();
564 create_cab_file();
565
566 test_AddDelBackupEntry();
567 test_ExtractFiles();
568 test_AdvInstallFile();
569
570 delete_test_files();
571
572 FreeLibrary(hAdvPack);
573 SetCurrentDirectoryA(prev_path);
574 }