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