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