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