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