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