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