kernel32: Disable FT_Thunk entry point when Windows version is NT.
[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_original_file_name(LPCSTR original, LPCSTR dest)
107 {
108     HINF hinf;
109     PSP_INF_INFORMATION pspii;
110     SP_ORIGINAL_FILE_INFO spofi;
111     BOOL res;
112     DWORD size;
113
114     hinf = SetupOpenInfFileA(dest, NULL, INF_STYLE_WIN4, NULL);
115     ok(hinf != NULL, "SetupOpenInfFileA failed with error %d\n", GetLastError());
116
117     res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
118     ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
119
120     pspii = HeapAlloc(GetProcessHeap(), 0, size);
121
122     res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, pspii, size, NULL);
123     ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
124
125     spofi.cbSize = 0;
126     res = SetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
127     ok(!res && GetLastError() == ERROR_INVALID_USER_BUFFER,
128         "SetupQueryInfOriginalFileInformationA should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", GetLastError());
129
130     spofi.cbSize = sizeof(spofi);
131     res = SetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
132     ok(res, "SetupQueryInfOriginalFileInformationA failed with error %d\n", GetLastError());
133     ok(!spofi.OriginalCatalogName[0], "spofi.OriginalCatalogName should have been \"\" instead of \"%s\"\n", spofi.OriginalCatalogName);
134     todo_wine
135     ok(!strcmp(original, spofi.OriginalInfName), "spofi.OriginalInfName of %s didn't match real original name %s\n", spofi.OriginalInfName, original);
136
137     HeapFree(GetProcessHeap(), 0, pspii);
138
139     SetupCloseInfFile(hinf);
140 }
141
142 static void test_SetupCopyOEMInf(void)
143 {
144     CHAR toolong[MAX_PATH * 2];
145     CHAR path[MAX_PATH], dest[MAX_PATH];
146     CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
147     LPSTR inf;
148     DWORD size;
149     BOOL res;
150
151     /* try NULL SourceInfFileName */
152     SetLastError(0xdeadbeef);
153     res = pSetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
154     ok(res == FALSE, "Expected FALSE, got %d\n", res);
155     ok(GetLastError() == ERROR_INVALID_PARAMETER,
156        "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
157
158     /* try empty SourceInfFileName */
159     SetLastError(0xdeadbeef);
160     res = pSetupCopyOEMInfA("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
161     ok(res == FALSE, "Expected FALSE, got %d\n", res);
162     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
163        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
164
165     /* try a relative nonexistent SourceInfFileName */
166     SetLastError(0xdeadbeef);
167     res = pSetupCopyOEMInfA("nonexistent", 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 an absolute nonexistent SourceInfFileName */
173     lstrcpy(path, CURR_DIR);
174     lstrcat(path, "\\nonexistent");
175     SetLastError(0xdeadbeef);
176     res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
177     ok(res == FALSE, "Expected FALSE, got %d\n", res);
178     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
179        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
180
181     /* try a long SourceInfFileName */
182     memset(toolong, 'a', MAX_PATH * 2);
183     toolong[MAX_PATH * 2 - 1] = '\0';
184     SetLastError(0xdeadbeef);
185     res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
186     ok(res == FALSE, "Expected FALSE, got %d\n", res);
187     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
188        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
189
190     get_temp_filename(tmpfile);
191     create_inf_file(tmpfile);
192
193     /* try a relative SourceInfFileName */
194     SetLastError(0xdeadbeef);
195     res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
196     ok(res == FALSE, "Expected FALSE, got %d\n", res);
197     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
198        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
199     ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
200
201     /* try SP_COPY_REPLACEONLY, dest does not exist */
202     SetLastError(0xdeadbeef);
203     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
204     ok(res == FALSE, "Expected FALSE, got %d\n", res);
205     ok(GetLastError() == ERROR_FILE_NOT_FOUND,
206        "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
207     ok(file_exists(tmpfile), "Expected source inf to exist\n");
208
209     /* try an absolute SourceInfFileName, without DestinationInfFileName */
210     lstrcpy(path, CURR_DIR);
211     lstrcat(path, "\\");
212     lstrcat(path, tmpfile);
213     SetLastError(0xdeadbeef);
214     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
215     ok(res == TRUE, "Expected TRUE, got %d\n", res);
216     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
217     ok(file_exists(path), "Expected source inf to exist\n");
218
219     /* try SP_COPY_REPLACEONLY, dest exists */
220     SetLastError(0xdeadbeef);
221     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, 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_NOOVERWRITE */
227     SetLastError(0xdeadbeef);
228     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
229     ok(res == FALSE, "Expected FALSE, got %d\n", res);
230     ok(GetLastError() == ERROR_FILE_EXISTS,
231        "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
232
233     /* get the DestinationInfFileName */
234     SetLastError(0xdeadbeef);
235     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
236     ok(res == TRUE, "Expected TRUE, got %d\n", res);
237     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
238     ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
239     ok(file_exists(dest), "Expected destination inf to exist\n");
240     ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
241     ok(file_exists(path), "Expected source inf to exist\n");
242
243     lstrcpy(dest_save, dest);
244     DeleteFile(dest_save);
245
246     /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
247      *   - inf is still copied
248      */
249     lstrcpy(dest, "aaa");
250     size = 0;
251     SetLastError(0xdeadbeef);
252     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
253     ok(res == FALSE, "Expected FALSE, got %d\n", res);
254     ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
255        "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
256     ok(file_exists(path), "Expected source inf to exist\n");
257     ok(file_exists(dest_save), "Expected dest inf to exist\n");
258     ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
259     ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
260
261     /* get the DestinationInfFileName and DestinationInfFileNameSize */
262     SetLastError(0xdeadbeef);
263     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
264     ok(res == TRUE, "Expected TRUE, got %d\n", res);
265     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
266     ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
267     ok(file_exists(dest), "Expected destination inf to exist\n");
268     ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
269     ok(file_exists(path), "Expected source inf to exist\n");
270     ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
271
272     test_original_file_name(strrchr(path, '\\') + 1, dest);
273
274     /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
275     SetLastError(0xdeadbeef);
276     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
277     ok(res == TRUE, "Expected TRUE, got %d\n", res);
278     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
279     ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
280     ok(file_exists(dest), "Expected destination inf to exist\n");
281     ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
282     ok(file_exists(path), "Expected source inf to exist\n");
283     ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
284
285     /* try SP_COPY_DELETESOURCE */
286     SetLastError(0xdeadbeef);
287     res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
288     ok(res == TRUE, "Expected TRUE, got %d\n", res);
289     ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
290     ok(!file_exists(path), "Expected source inf to not exist\n");
291 }
292
293 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
294 {
295     HANDLE handle;
296     DWORD written;
297
298     handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
299     WriteFile(handle, data, size, &written, NULL);
300     CloseHandle(handle);
301 }
302
303 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
304 {
305     DWORD read;
306     HANDLE handle;
307     BOOL ret = FALSE;
308     LPBYTE buffer;
309
310     handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
311     buffer = HeapAlloc(GetProcessHeap(), 0, size);
312     if (buffer)
313     {
314         ReadFile(handle, buffer, size, &read, NULL);
315         if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
316         HeapFree(GetProcessHeap(), 0, buffer);
317     }
318     CloseHandle(handle);
319     return ret;
320 }
321
322 static const BYTE uncompressed[] = {
323     'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
324 };
325 static const BYTE comp_lzx[] = {
326     0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
327     0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
328 };
329 static const BYTE comp_zip[] = {
330     0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
331     0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
332     0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
333     0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
334     0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
335     0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
336     0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
337     0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
338     0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
339     0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
340 };
341 static const BYTE comp_cab_lzx[] = {
342     0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343     0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
344     0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
345     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
346     0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
347     0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
348     0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
349 };
350 static const BYTE comp_cab_zip[] =  {
351     0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352     0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
353     0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
354     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
355     0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
356     0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
357 };
358
359 static void test_SetupGetFileCompressionInfo(void)
360 {
361     DWORD ret, source_size, target_size;
362     char source[MAX_PATH], temp[MAX_PATH], *name;
363     UINT type;
364
365     GetTempPathA(sizeof(temp), temp);
366     GetTempFileNameA(temp, "fci", 0, source);
367
368     create_source_file(source, uncompressed, sizeof(uncompressed));
369
370     ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
371     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
372
373     ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
374     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
375
376     ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
377     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
378
379     ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
380     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
381
382     ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
383     ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
384
385     name = NULL;
386     source_size = target_size = 0;
387     type = 5;
388
389     ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
390     ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
391     ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
392     ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
393     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
394     ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
395
396     DeleteFileA(source);
397 }
398
399 static void test_SetupGetFileCompressionInfoEx(void)
400 {
401     BOOL ret;
402     DWORD required_len, source_size, target_size;
403     char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
404     UINT type;
405
406     GetTempPathA(sizeof(temp), temp);
407     GetTempFileNameA(temp, "doc", 0, source);
408
409     ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
410     ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
411
412     ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
413     ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
414
415     ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
416     ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
417     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
418
419     create_source_file(source, comp_lzx, sizeof(comp_lzx));
420
421     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
422     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
423     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
424     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
425     ok(source_size == sizeof(comp_lzx), "got %d\n", source_size);
426     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
427     ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
428     DeleteFileA(source);
429
430     create_source_file(source, comp_zip, sizeof(comp_zip));
431
432     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
433     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
434     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
435     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
436     ok(source_size == sizeof(comp_zip), "got %d\n", source_size);
437     ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
438     ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
439     DeleteFileA(source);
440
441     create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
442
443     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
444     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
445     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
446     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
447     ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size);
448     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
449     ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
450     DeleteFileA(source);
451
452     create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
453
454     ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
455     ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
456     ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
457     ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
458     ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
459     ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
460     ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
461     DeleteFileA(source);
462 }
463
464 static void test_SetupDecompressOrCopyFile(void)
465 {
466     DWORD ret;
467     char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
468     UINT type;
469
470     GetTempPathA(sizeof(temp), temp);
471     GetTempFileNameA(temp, "doc", 0, source);
472     GetTempFileNameA(temp, "doc", 0, target);
473
474     /* parameter tests */
475
476     create_source_file(source, uncompressed, sizeof(uncompressed));
477
478     ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
479     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
480
481     type = FILE_COMPRESSION_NONE;
482     ret = SetupDecompressOrCopyFileA(NULL, target, &type);
483     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
484
485     ret = SetupDecompressOrCopyFileA(source, NULL, &type);
486     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
487
488     type = 5; /* try an invalid compression type */
489     ret = SetupDecompressOrCopyFileA(source, target, &type);
490     ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
491
492     DeleteFileA(target);
493
494     /* no compression tests */
495
496     ret = SetupDecompressOrCopyFileA(source, target, NULL);
497     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
498     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
499
500     /* try overwriting existing file */
501     ret = SetupDecompressOrCopyFileA(source, target, NULL);
502     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
503     DeleteFileA(target);
504
505     type = FILE_COMPRESSION_NONE;
506     ret = SetupDecompressOrCopyFileA(source, target, &type);
507     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
508     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
509     DeleteFileA(target);
510
511     type = FILE_COMPRESSION_WINLZA;
512     ret = SetupDecompressOrCopyFileA(source, target, &type);
513     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
514     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
515     DeleteFileA(target);
516
517     /* lz compression tests */
518
519     create_source_file(source, comp_lzx, sizeof(comp_lzx));
520
521     ret = SetupDecompressOrCopyFileA(source, target, NULL);
522     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
523     DeleteFileA(target);
524
525     /* zip compression tests */
526
527     create_source_file(source, comp_zip, sizeof(comp_zip));
528
529     ret = SetupDecompressOrCopyFileA(source, target, NULL);
530     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
531     ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
532     DeleteFileA(target);
533
534     /* cabinet compression tests */
535
536     create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
537
538     p = strrchr(target, '\\');
539     lstrcpyA(p + 1, "wine");
540
541     ret = SetupDecompressOrCopyFileA(source, target, NULL);
542     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
543     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
544
545     /* try overwriting existing file */
546     ret = SetupDecompressOrCopyFileA(source, target, NULL);
547     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
548
549     /* try zip compression */
550     type = FILE_COMPRESSION_MSZIP;
551     ret = SetupDecompressOrCopyFileA(source, target, &type);
552     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
553     ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
554
555     /* try no compression */
556     type = FILE_COMPRESSION_NONE;
557     ret = SetupDecompressOrCopyFileA(source, target, &type);
558     ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
559     ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
560
561     DeleteFileA(target);
562     DeleteFileA(source);
563 }
564
565 START_TEST(misc)
566 {
567     HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
568
569     pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
570     pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
571
572     GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
573
574     if (pSetupCopyOEMInfA)
575         test_SetupCopyOEMInf();
576     else
577         skip("SetupCopyOEMInfA is not available\n");
578
579     test_SetupGetFileCompressionInfo();
580
581     if (pSetupGetFileCompressionInfoExA)
582         test_SetupGetFileCompressionInfoEx();
583     else
584         skip("SetupGetFileCompressionInfoExA is not available\n");
585
586     test_SetupDecompressOrCopyFile();
587 }