push c6bab2db4fc296bd36abf8f7d9cf443d4a73048e
[wine/hacks.git] / dlls / setupapi / tests / misc.c
blobe110e221e8b45c4a760fd507caa9e6a5274728e9
1 /*
2 * Miscellaneous tests
4 * Copyright 2007 James Hawkins
5 * Copyright 2007 Hans Leidekker
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.
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.
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
22 #include <stdarg.h>
23 #include <stdio.h>
24 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "winuser.h"
30 #include "winreg.h"
31 #include "setupapi.h"
33 #include "wine/test.h"
35 static CHAR CURR_DIR[MAX_PATH];
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
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);
50 static void create_inf_file(LPCSTR filename)
52 DWORD dwNumberOfBytesWritten;
53 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
54 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
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";
65 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
66 CloseHandle(hf);
69 static void get_temp_filename(LPSTR path)
71 CHAR temp[MAX_PATH];
72 LPSTR ptr;
74 GetTempFileName(CURR_DIR, "set", 0, temp);
75 ptr = strrchr(temp, '\\');
77 lstrcpy(path, ptr + 1);
80 static BOOL file_exists(LPSTR path)
82 return GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES;
85 static BOOL check_format(LPSTR path, LPSTR inf)
87 CHAR check[MAX_PATH];
88 BOOL res;
90 static const CHAR format[] = "\\INF\\oem";
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)] != '\\';
97 return (!inf) ? res : res && (inf == path + lstrlen(check) - 3);
100 static void test_original_file_name(LPCSTR original, LPCSTR dest)
102 HINF hinf;
103 PSP_INF_INFORMATION pspii;
104 SP_ORIGINAL_FILE_INFO spofi;
105 BOOL res;
106 DWORD size;
108 if (!pSetupQueryInfOriginalFileInformationA)
110 win_skip("SetupQueryInfOriginalFileInformationA is not available\n");
111 return;
114 hinf = SetupOpenInfFileA(dest, NULL, INF_STYLE_WIN4, NULL);
115 ok(hinf != NULL, "SetupOpenInfFileA failed with error %d\n", GetLastError());
117 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
118 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
120 pspii = HeapAlloc(GetProcessHeap(), 0, size);
122 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, pspii, size, NULL);
123 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
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());
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);
137 HeapFree(GetProcessHeap(), 0, pspii);
139 SetupCloseInfFile(hinf);
142 static void test_SetupCopyOEMInf(void)
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 = NULL;
148 DWORD size;
149 BOOL res;
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());
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 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista, W2K8 */
165 "Unexpected error : %d\n", GetLastError());
167 /* try a relative nonexistent SourceInfFileName */
168 SetLastError(0xdeadbeef);
169 res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
170 ok(res == FALSE, "Expected FALSE, got %d\n", res);
171 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
172 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
174 /* try an absolute nonexistent SourceInfFileName */
175 lstrcpy(path, CURR_DIR);
176 lstrcat(path, "\\nonexistent");
177 SetLastError(0xdeadbeef);
178 res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
179 ok(res == FALSE, "Expected FALSE, got %d\n", res);
180 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
181 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
183 /* try a long SourceInfFileName */
184 memset(toolong, 'a', MAX_PATH * 2);
185 toolong[MAX_PATH * 2 - 1] = '\0';
186 SetLastError(0xdeadbeef);
187 res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
188 ok(res == FALSE, "Expected FALSE, got %d\n", res);
189 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
190 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Win98 */
191 "Expected ERROR_FILE_NOT_FOUND or ERROR_FILENAME_EXCED_RANGE, got %d\n", GetLastError());
193 get_temp_filename(tmpfile);
194 create_inf_file(tmpfile);
196 /* try a relative SourceInfFileName */
197 SetLastError(0xdeadbeef);
198 res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
199 ok(res == FALSE, "Expected FALSE, got %d\n", res);
200 if (GetLastError() == ERROR_WRONG_INF_TYPE)
202 /* FIXME:
203 * Vista needs a [Manufacturer] entry in the inf file. Doing this will give some
204 * popups during the installation though as it also needs a catalog file (signed?).
206 win_skip("Needs a different inf file on Vista/W2K8\n");
207 DeleteFile(tmpfile);
208 return;
211 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
212 GetLastError() == ERROR_FILE_EXISTS, /* Win98 */
213 "Expected ERROR_FILE_NOT_FOUND or ERROR_FILE_EXISTS, got %d\n", GetLastError());
214 ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
216 /* try SP_COPY_REPLACEONLY, dest does not exist */
217 SetLastError(0xdeadbeef);
218 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
219 ok(res == FALSE, "Expected FALSE, got %d\n", res);
220 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
221 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
222 ok(file_exists(tmpfile), "Expected source inf to exist\n");
224 /* try an absolute SourceInfFileName, without DestinationInfFileName */
225 lstrcpy(path, CURR_DIR);
226 lstrcat(path, "\\");
227 lstrcat(path, tmpfile);
228 SetLastError(0xdeadbeef);
229 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
230 ok(res == TRUE, "Expected TRUE, got %d\n", res);
231 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
232 ok(file_exists(path), "Expected source inf to exist\n");
234 /* try SP_COPY_REPLACEONLY, dest exists */
235 SetLastError(0xdeadbeef);
236 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
237 ok(res == TRUE, "Expected TRUE, got %d\n", res);
238 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
239 ok(file_exists(path), "Expected source inf to exist\n");
241 /* try SP_COPY_NOOVERWRITE */
242 SetLastError(0xdeadbeef);
243 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
244 ok(res == FALSE, "Expected FALSE, got %d\n", res);
245 ok(GetLastError() == ERROR_FILE_EXISTS,
246 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
248 /* get the DestinationInfFileName */
249 SetLastError(0xdeadbeef);
250 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
251 ok(res == TRUE, "Expected TRUE, got %d\n", res);
252 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
253 ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
254 ok(file_exists(dest), "Expected destination inf to exist\n");
255 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
256 ok(file_exists(path), "Expected source inf to exist\n");
258 lstrcpy(dest_save, dest);
259 DeleteFile(dest_save);
261 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
262 * - inf is still copied
264 lstrcpy(dest, "aaa");
265 size = 0;
266 SetLastError(0xdeadbeef);
267 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
268 ok(res == FALSE, "Expected FALSE, got %d\n", res);
269 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
270 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
271 ok(file_exists(path), "Expected source inf to exist\n");
272 ok(file_exists(dest_save), "Expected dest inf to exist\n");
273 ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
274 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
276 /* get the DestinationInfFileName and DestinationInfFileNameSize */
277 SetLastError(0xdeadbeef);
278 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
279 ok(res == TRUE, "Expected TRUE, got %d\n", res);
280 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
281 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
282 ok(file_exists(dest), "Expected destination inf to exist\n");
283 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
284 ok(file_exists(path), "Expected source inf to exist\n");
285 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
287 test_original_file_name(strrchr(path, '\\') + 1, dest);
289 /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
290 SetLastError(0xdeadbeef);
291 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
292 ok(res == TRUE, "Expected TRUE, got %d\n", res);
293 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
294 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
295 ok(file_exists(dest), "Expected destination inf to exist\n");
296 ok((inf && inf[0] != 0) ||
297 broken(!inf), /* Win98 */
298 "Expected inf to point to the filename\n");
299 ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
300 ok(file_exists(path), "Expected source inf to exist\n");
301 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
303 /* try SP_COPY_DELETESOURCE */
304 SetLastError(0xdeadbeef);
305 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
306 ok(res == TRUE, "Expected TRUE, got %d\n", res);
307 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
308 ok(!file_exists(path), "Expected source inf to not exist\n");
311 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
313 HANDLE handle;
314 DWORD written;
316 handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
317 WriteFile(handle, data, size, &written, NULL);
318 CloseHandle(handle);
321 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
323 DWORD read;
324 HANDLE handle;
325 BOOL ret = FALSE;
326 LPBYTE buffer;
328 handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
329 buffer = HeapAlloc(GetProcessHeap(), 0, size);
330 if (buffer)
332 ReadFile(handle, buffer, size, &read, NULL);
333 if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
334 HeapFree(GetProcessHeap(), 0, buffer);
336 CloseHandle(handle);
337 return ret;
340 static const BYTE uncompressed[] = {
341 'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
343 static const BYTE comp_lzx[] = {
344 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
345 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
347 static const BYTE comp_zip[] = {
348 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
349 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
350 0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
351 0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
352 0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
353 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
354 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
355 0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
356 0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
357 0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
359 static const BYTE comp_cab_lzx[] = {
360 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
361 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
362 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
363 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
364 0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
365 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
366 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
368 static const BYTE comp_cab_zip[] = {
369 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
370 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
371 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
372 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
373 0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
374 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
377 static void test_SetupGetFileCompressionInfo(void)
379 DWORD ret, source_size, target_size;
380 char source[MAX_PATH], temp[MAX_PATH], *name;
381 UINT type;
383 GetTempPathA(sizeof(temp), temp);
384 GetTempFileNameA(temp, "fci", 0, source);
386 create_source_file(source, uncompressed, sizeof(uncompressed));
388 ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
389 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
391 ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
392 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
394 ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
395 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
397 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
398 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
400 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
401 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
403 name = NULL;
404 source_size = target_size = 0;
405 type = 5;
407 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
408 ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
409 ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
410 ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
411 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
412 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
414 MyFree(name);
415 DeleteFileA(source);
418 static void test_SetupGetFileCompressionInfoEx(void)
420 BOOL ret;
421 DWORD required_len, source_size, target_size;
422 char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
423 UINT type;
425 GetTempPathA(sizeof(temp), temp);
426 GetTempFileNameA(temp, "doc", 0, source);
428 ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
429 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
431 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
432 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
434 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
435 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
436 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
438 create_source_file(source, comp_lzx, sizeof(comp_lzx));
440 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
441 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
442 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
443 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
444 ok(source_size == sizeof(comp_lzx), "got %d\n", source_size);
445 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
446 ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
447 DeleteFileA(source);
449 create_source_file(source, comp_zip, sizeof(comp_zip));
451 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
452 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
453 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
454 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
455 ok(source_size == sizeof(comp_zip), "got %d\n", source_size);
456 ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
457 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
458 DeleteFileA(source);
460 create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
462 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
463 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
464 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
465 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
466 ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size);
467 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
468 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
469 DeleteFileA(source);
471 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
473 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
474 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
475 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
476 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
477 ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
478 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
479 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
480 DeleteFileA(source);
483 static void test_SetupDecompressOrCopyFile(void)
485 DWORD ret;
486 char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
487 UINT type;
489 GetTempPathA(sizeof(temp), temp);
490 GetTempFileNameA(temp, "doc", 0, source);
491 GetTempFileNameA(temp, "doc", 0, target);
493 /* parameter tests */
495 create_source_file(source, uncompressed, sizeof(uncompressed));
497 ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
498 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
500 type = FILE_COMPRESSION_NONE;
501 ret = SetupDecompressOrCopyFileA(NULL, target, &type);
502 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
504 ret = SetupDecompressOrCopyFileA(source, NULL, &type);
505 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
507 type = 5; /* try an invalid compression type */
508 ret = SetupDecompressOrCopyFileA(source, target, &type);
509 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
511 DeleteFileA(target);
513 /* no compression tests */
515 ret = SetupDecompressOrCopyFileA(source, target, NULL);
516 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
517 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
519 /* try overwriting existing file */
520 ret = SetupDecompressOrCopyFileA(source, target, NULL);
521 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
522 DeleteFileA(target);
524 type = FILE_COMPRESSION_NONE;
525 ret = SetupDecompressOrCopyFileA(source, target, &type);
526 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
527 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
528 DeleteFileA(target);
530 type = FILE_COMPRESSION_WINLZA;
531 ret = SetupDecompressOrCopyFileA(source, target, &type);
532 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
533 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
534 DeleteFileA(target);
536 /* lz compression tests */
538 create_source_file(source, comp_lzx, sizeof(comp_lzx));
540 ret = SetupDecompressOrCopyFileA(source, target, NULL);
541 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
542 DeleteFileA(target);
544 /* zip compression tests */
546 create_source_file(source, comp_zip, sizeof(comp_zip));
548 ret = SetupDecompressOrCopyFileA(source, target, NULL);
549 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
550 ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
551 DeleteFileA(target);
553 /* cabinet compression tests */
555 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
557 p = strrchr(target, '\\');
558 lstrcpyA(p + 1, "wine");
560 ret = SetupDecompressOrCopyFileA(source, target, NULL);
561 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
562 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
564 /* try overwriting existing file */
565 ret = SetupDecompressOrCopyFileA(source, target, NULL);
566 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
568 /* try zip compression */
569 type = FILE_COMPRESSION_MSZIP;
570 ret = SetupDecompressOrCopyFileA(source, target, &type);
571 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
572 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
574 /* try no compression */
575 type = FILE_COMPRESSION_NONE;
576 ret = SetupDecompressOrCopyFileA(source, target, &type);
577 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
578 ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
580 DeleteFileA(target);
581 DeleteFileA(source);
584 START_TEST(misc)
586 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
588 pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
589 pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
590 pSetupQueryInfOriginalFileInformationA = (void*)GetProcAddress(hsetupapi, "SetupQueryInfOriginalFileInformationA");
592 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
594 if (pSetupCopyOEMInfA)
595 test_SetupCopyOEMInf();
596 else
597 win_skip("SetupCopyOEMInfA is not available\n");
599 test_SetupGetFileCompressionInfo();
601 if (pSetupGetFileCompressionInfoExA)
602 test_SetupGetFileCompressionInfoEx();
603 else
604 win_skip("SetupGetFileCompressionInfoExA is not available\n");
606 test_SetupDecompressOrCopyFile();