setupapi/tests: Use skip instead of trace.
[wine] / dlls / setupapi / tests / misc.c
1 /*
2  * Miscellaneous tests
3  *
4  * Copyright 2007 James Hawkins
5  * Copyright 2007 Hans Leidekker
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "setupapi.h"
32
33 #include "wine/test.h"
34
35 static CHAR CURR_DIR[MAX_PATH];
36
37 /* test:
38  *  - fails if not administrator
39  *  - what if it's not a .inf file?
40  *  - copied to %windir%/Inf
41  *  - SourceInfFileName should be a full path
42  *  - SourceInfFileName should be <= MAX_PATH
43  *  - copy styles
44  */
45
46 static BOOL (WINAPI *pSetupGetFileCompressionInfoExA)(PCSTR, PSTR, DWORD, PDWORD, PDWORD, PDWORD, PUINT);
47 static BOOL (WINAPI *pSetupCopyOEMInfA)(PCSTR, PCSTR, DWORD, DWORD, PSTR, DWORD, PDWORD, PSTR *);
48 static BOOL (WINAPI *pSetupQueryInfOriginalFileInformationA)(PSP_INF_INFORMATION, UINT, PSP_ALTPLATFORM_INFO, PSP_ORIGINAL_FILE_INFO_A);
49
50 static void append_str(char **str, const char *data)
51 {
52     sprintf(*str, data);
53     *str += strlen(*str);
54 }
55
56 static void create_inf_file(LPCSTR filename)
57 {
58     char data[1024];
59     char *ptr = data;
60     DWORD dwNumberOfBytesWritten;
61     HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
62                            CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
63
64     append_str(&ptr, "[Version]\n");
65     append_str(&ptr, "Signature=\"$Chicago$\"\n");
66     append_str(&ptr, "AdvancedINF=2.5\n");
67     append_str(&ptr, "[DefaultInstall]\n");
68     append_str(&ptr, "RegisterOCXs=RegisterOCXsSection\n");
69     append_str(&ptr, "[RegisterOCXsSection]\n");
70     append_str(&ptr, "%%11%%\\ole32.dll\n");
71
72     WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
73     CloseHandle(hf);
74 }
75
76 static void get_temp_filename(LPSTR path)
77 {
78     CHAR temp[MAX_PATH];
79     LPSTR ptr;
80
81     GetTempFileName(CURR_DIR, "set", 0, temp);
82     ptr = strrchr(temp, '\\');
83
84     lstrcpy(path, ptr + 1);
85 }
86
87 static BOOL file_exists(LPSTR path)
88 {
89     return GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES;
90 }
91
92 static BOOL check_format(LPSTR path, LPSTR inf)
93 {
94     CHAR check[MAX_PATH];
95     BOOL res;
96
97     static const CHAR format[] = "\\INF\\oem";
98
99     GetWindowsDirectory(check, MAX_PATH);
100     lstrcat(check, format);
101     res = CompareString(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, check, -1, path, lstrlen(check)) == CSTR_EQUAL &&
102           path[lstrlen(check)] != '\\';
103
104     return (!inf) ? res : res && (inf == path + lstrlen(check) - 3);
105 }
106
107 static void test_original_file_name(LPCSTR original, LPCSTR dest)
108 {
109     HINF hinf;
110     PSP_INF_INFORMATION pspii;
111     SP_ORIGINAL_FILE_INFO spofi;
112     BOOL res;
113     DWORD size;
114
115     if (!pSetupQueryInfOriginalFileInformationA)
116     {
117         skip("SetupQueryInfOriginalFileInformationA is not available\n");
118         return;
119     }
120
121     hinf = SetupOpenInfFileA(dest, NULL, INF_STYLE_WIN4, NULL);
122     ok(hinf != NULL, "SetupOpenInfFileA failed with error %d\n", GetLastError());
123
124     res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
125     ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
126
127     pspii = HeapAlloc(GetProcessHeap(), 0, size);
128
129     res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, pspii, size, NULL);
130     ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
131
132     spofi.cbSize = 0;
133     res = pSetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
134     ok(!res && GetLastError() == ERROR_INVALID_USER_BUFFER,
135         "SetupQueryInfOriginalFileInformationA should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", GetLastError());
136
137     spofi.cbSize = sizeof(spofi);
138     res = pSetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
139     ok(res, "SetupQueryInfOriginalFileInformationA failed with error %d\n", GetLastError());
140     ok(!spofi.OriginalCatalogName[0], "spofi.OriginalCatalogName should have been \"\" instead of \"%s\"\n", spofi.OriginalCatalogName);
141     todo_wine
142     ok(!strcmp(original, spofi.OriginalInfName), "spofi.OriginalInfName of %s didn't match real original name %s\n", spofi.OriginalInfName, original);
143
144     HeapFree(GetProcessHeap(), 0, pspii);
145
146     SetupCloseInfFile(hinf);
147 }
148
149 static void test_SetupCopyOEMInf(void)
150 {
151     CHAR toolong[MAX_PATH * 2];
152     CHAR path[MAX_PATH], dest[MAX_PATH];
153     CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
154     LPSTR inf;
155     DWORD size;
156     BOOL res;
157
158     /* try NULL SourceInfFileName */
159     SetLastError(0xdeadbeef);
160     res = pSetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
161     ok(res == FALSE, "Expected FALSE, got %d\n", res);
162     ok(GetLastError() == ERROR_INVALID_PARAMETER,
163        "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
164
165     /* try empty SourceInfFileName */
166     SetLastError(0xdeadbeef);
167     res = pSetupCopyOEMInfA("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
168     ok(res == FALSE, "Expected FALSE, got %d\n", res);
169     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
170        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
171
172     /* try a relative nonexistent SourceInfFileName */
173     SetLastError(0xdeadbeef);
174     res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
175     ok(res == FALSE, "Expected FALSE, got %d\n", res);
176     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
177        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
178
179     /* try an absolute nonexistent SourceInfFileName */
180     lstrcpy(path, CURR_DIR);
181     lstrcat(path, "\\nonexistent");
182     SetLastError(0xdeadbeef);
183     res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
184     ok(res == FALSE, "Expected FALSE, got %d\n", res);
185     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
186        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
187
188     /* try a long SourceInfFileName */
189     memset(toolong, 'a', MAX_PATH * 2);
190     toolong[MAX_PATH * 2 - 1] = '\0';
191     SetLastError(0xdeadbeef);
192     res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
193     ok(res == FALSE, "Expected FALSE, got %d\n", res);
194     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
195        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
196
197     get_temp_filename(tmpfile);
198     create_inf_file(tmpfile);
199
200     /* try a relative SourceInfFileName */
201     SetLastError(0xdeadbeef);
202     res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
203     ok(res == FALSE, "Expected FALSE, got %d\n", res);
204     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
205        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
206     ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
207
208     /* try SP_COPY_REPLACEONLY, dest does not exist */
209     SetLastError(0xdeadbeef);
210     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
211     ok(res == FALSE, "Expected FALSE, got %d\n", res);
212     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
213        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
214     ok(file_exists(tmpfile), "Expected source inf to exist\n");
215
216     /* try an absolute SourceInfFileName, without DestinationInfFileName */
217     lstrcpy(path, CURR_DIR);
218     lstrcat(path, "\\");
219     lstrcat(path, tmpfile);
220     SetLastError(0xdeadbeef);
221     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
222     ok(res == TRUE, "Expected TRUE, got %d\n", res);
223     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
224     ok(file_exists(path), "Expected source inf to exist\n");
225
226     /* try SP_COPY_REPLACEONLY, dest exists */
227     SetLastError(0xdeadbeef);
228     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
229     ok(res == TRUE, "Expected TRUE, got %d\n", res);
230     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
231     ok(file_exists(path), "Expected source inf to exist\n");
232
233     /* try SP_COPY_NOOVERWRITE */
234     SetLastError(0xdeadbeef);
235     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
236     ok(res == FALSE, "Expected FALSE, got %d\n", res);
237     ok(GetLastError() == ERROR_FILE_EXISTS,
238        "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
239
240     /* get the DestinationInfFileName */
241     SetLastError(0xdeadbeef);
242     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
243     ok(res == TRUE, "Expected TRUE, got %d\n", res);
244     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
245     ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
246     ok(file_exists(dest), "Expected destination inf to exist\n");
247     ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
248     ok(file_exists(path), "Expected source inf to exist\n");
249
250     lstrcpy(dest_save, dest);
251     DeleteFile(dest_save);
252
253     /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
254      *   - inf is still copied
255      */
256     lstrcpy(dest, "aaa");
257     size = 0;
258     SetLastError(0xdeadbeef);
259     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
260     ok(res == FALSE, "Expected FALSE, got %d\n", res);
261     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
262        "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
263     ok(file_exists(path), "Expected source inf to exist\n");
264     ok(file_exists(dest_save), "Expected dest inf to exist\n");
265     ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
266     ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
267
268     /* get the DestinationInfFileName and DestinationInfFileNameSize */
269     SetLastError(0xdeadbeef);
270     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
271     ok(res == TRUE, "Expected TRUE, got %d\n", res);
272     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
273     ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
274     ok(file_exists(dest), "Expected destination inf to exist\n");
275     ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
276     ok(file_exists(path), "Expected source inf to exist\n");
277     ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
278
279     test_original_file_name(strrchr(path, '\\') + 1, dest);
280
281     /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
282     SetLastError(0xdeadbeef);
283     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
284     ok(res == TRUE, "Expected TRUE, got %d\n", res);
285     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
286     ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
287     ok(file_exists(dest), "Expected destination inf to exist\n");
288     ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
289     ok(file_exists(path), "Expected source inf to exist\n");
290     ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
291
292     /* try SP_COPY_DELETESOURCE */
293     SetLastError(0xdeadbeef);
294     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
295     ok(res == TRUE, "Expected TRUE, got %d\n", res);
296     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
297     ok(!file_exists(path), "Expected source inf to not exist\n");
298 }
299
300 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
301 {
302     HANDLE handle;
303     DWORD written;
304
305     handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
306     WriteFile(handle, data, size, &written, NULL);
307     CloseHandle(handle);
308 }
309
310 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
311 {
312     DWORD read;
313     HANDLE handle;
314     BOOL ret = FALSE;
315     LPBYTE buffer;
316
317     handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
318     buffer = HeapAlloc(GetProcessHeap(), 0, size);
319     if (buffer)
320     {
321         ReadFile(handle, buffer, size, &read, NULL);
322         if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
323         HeapFree(GetProcessHeap(), 0, buffer);
324     }
325     CloseHandle(handle);
326     return ret;
327 }
328
329 static const BYTE uncompressed[] = {
330     'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
331 };
332 static const BYTE comp_lzx[] = {
333     0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
334     0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
335 };
336 static const BYTE comp_zip[] = {
337     0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
338     0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
339     0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
340     0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
341     0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
342     0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
343     0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
344     0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
345     0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
346     0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
347 };
348 static const BYTE comp_cab_lzx[] = {
349     0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350     0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
351     0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
352     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
353     0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
354     0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
355     0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
356 };
357 static const BYTE comp_cab_zip[] =  {
358     0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
359     0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
360     0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
361     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
362     0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
363     0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
364 };
365
366 static void test_SetupGetFileCompressionInfo(void)
367 {
368     DWORD ret, source_size, target_size;
369     char source[MAX_PATH], temp[MAX_PATH], *name;
370     UINT type;
371
372     GetTempPathA(sizeof(temp), temp);
373     GetTempFileNameA(temp, "fci", 0, source);
374
375     create_source_file(source, uncompressed, sizeof(uncompressed));
376
377     ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
378     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
379
380     ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
381     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
382
383     ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
384     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
385
386     ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
387     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
388
389     ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
390     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
391
392     name = NULL;
393     source_size = target_size = 0;
394     type = 5;
395
396     ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
397     ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
398     ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
399     ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
400     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
401     ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
402
403     DeleteFileA(source);
404 }
405
406 static void test_SetupGetFileCompressionInfoEx(void)
407 {
408     BOOL ret;
409     DWORD required_len, source_size, target_size;
410     char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
411     UINT type;
412
413     GetTempPathA(sizeof(temp), temp);
414     GetTempFileNameA(temp, "doc", 0, source);
415
416     ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
417     ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
418
419     ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
420     ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
421
422     ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
423     ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
424     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
425
426     create_source_file(source, comp_lzx, sizeof(comp_lzx));
427
428     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
429     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
430     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
431     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
432     ok(source_size == sizeof(comp_lzx), "got %d\n", source_size);
433     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
434     ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
435     DeleteFileA(source);
436
437     create_source_file(source, comp_zip, sizeof(comp_zip));
438
439     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
440     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
441     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
442     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
443     ok(source_size == sizeof(comp_zip), "got %d\n", source_size);
444     ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
445     ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
446     DeleteFileA(source);
447
448     create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
449
450     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
451     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
452     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
453     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
454     ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size);
455     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
456     ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
457     DeleteFileA(source);
458
459     create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
460
461     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
462     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
463     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
464     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
465     ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
466     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
467     ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
468     DeleteFileA(source);
469 }
470
471 static void test_SetupDecompressOrCopyFile(void)
472 {
473     DWORD ret;
474     char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
475     UINT type;
476
477     GetTempPathA(sizeof(temp), temp);
478     GetTempFileNameA(temp, "doc", 0, source);
479     GetTempFileNameA(temp, "doc", 0, target);
480
481     /* parameter tests */
482
483     create_source_file(source, uncompressed, sizeof(uncompressed));
484
485     ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
486     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
487
488     type = FILE_COMPRESSION_NONE;
489     ret = SetupDecompressOrCopyFileA(NULL, target, &type);
490     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
491
492     ret = SetupDecompressOrCopyFileA(source, NULL, &type);
493     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
494
495     type = 5; /* try an invalid compression type */
496     ret = SetupDecompressOrCopyFileA(source, target, &type);
497     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
498
499     DeleteFileA(target);
500
501     /* no compression tests */
502
503     ret = SetupDecompressOrCopyFileA(source, target, NULL);
504     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
505     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
506
507     /* try overwriting existing file */
508     ret = SetupDecompressOrCopyFileA(source, target, NULL);
509     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
510     DeleteFileA(target);
511
512     type = FILE_COMPRESSION_NONE;
513     ret = SetupDecompressOrCopyFileA(source, target, &type);
514     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
515     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
516     DeleteFileA(target);
517
518     type = FILE_COMPRESSION_WINLZA;
519     ret = SetupDecompressOrCopyFileA(source, target, &type);
520     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
521     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
522     DeleteFileA(target);
523
524     /* lz compression tests */
525
526     create_source_file(source, comp_lzx, sizeof(comp_lzx));
527
528     ret = SetupDecompressOrCopyFileA(source, target, NULL);
529     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
530     DeleteFileA(target);
531
532     /* zip compression tests */
533
534     create_source_file(source, comp_zip, sizeof(comp_zip));
535
536     ret = SetupDecompressOrCopyFileA(source, target, NULL);
537     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
538     ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
539     DeleteFileA(target);
540
541     /* cabinet compression tests */
542
543     create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
544
545     p = strrchr(target, '\\');
546     lstrcpyA(p + 1, "wine");
547
548     ret = SetupDecompressOrCopyFileA(source, target, NULL);
549     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
550     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
551
552     /* try overwriting existing file */
553     ret = SetupDecompressOrCopyFileA(source, target, NULL);
554     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
555
556     /* try zip compression */
557     type = FILE_COMPRESSION_MSZIP;
558     ret = SetupDecompressOrCopyFileA(source, target, &type);
559     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
560     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
561
562     /* try no compression */
563     type = FILE_COMPRESSION_NONE;
564     ret = SetupDecompressOrCopyFileA(source, target, &type);
565     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
566     ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
567
568     DeleteFileA(target);
569     DeleteFileA(source);
570 }
571
572 START_TEST(misc)
573 {
574     HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
575
576     pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
577     pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
578     pSetupQueryInfOriginalFileInformationA = (void*)GetProcAddress(hsetupapi, "SetupQueryInfOriginalFileInformationA");
579
580     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
581
582     if (pSetupCopyOEMInfA)
583         test_SetupCopyOEMInf();
584     else
585         skip("SetupCopyOEMInfA is not available\n");
586
587     test_SetupGetFileCompressionInfo();
588
589     if (pSetupGetFileCompressionInfoExA)
590         test_SetupGetFileCompressionInfoEx();
591     else
592         skip("SetupGetFileCompressionInfoExA is not available\n");
593
594     test_SetupDecompressOrCopyFile();
595 }