push e9c4c6cdd0babd7b2cb4288f191bb331b756eaf2
[wine/hacks.git] / dlls / setupapi / tests / misc.c
blob4b8bd0378c30579e4a54f714c4376dc07b10f411
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);
49 static BOOL (WINAPI *pSetupUninstallOEMInfA)(PCSTR, DWORD, PVOID);
51 static void create_inf_file(LPCSTR filename)
53 DWORD dwNumberOfBytesWritten;
54 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
55 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
57 static const char data[] =
58 "[Version]\n"
59 "Signature=\"$Chicago$\"\n"
60 "AdvancedINF=2.5\n"
61 "[DefaultInstall]\n"
62 "RegisterOCXs=RegisterOCXsSection\n"
63 "[RegisterOCXsSection]\n"
64 "%%11%%\\ole32.dll\n";
66 WriteFile(hf, data, sizeof(data) - 1, &dwNumberOfBytesWritten, NULL);
67 CloseHandle(hf);
70 static void get_temp_filename(LPSTR path)
72 CHAR temp[MAX_PATH];
73 LPSTR ptr;
75 GetTempFileName(CURR_DIR, "set", 0, temp);
76 ptr = strrchr(temp, '\\');
78 lstrcpy(path, ptr + 1);
81 static BOOL file_exists(LPSTR path)
83 return GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES;
86 static BOOL check_format(LPSTR path, LPSTR inf)
88 CHAR check[MAX_PATH];
89 BOOL res;
91 static const CHAR format[] = "\\INF\\oem";
93 GetWindowsDirectory(check, MAX_PATH);
94 lstrcat(check, format);
95 res = CompareString(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, check, -1, path, lstrlen(check)) == CSTR_EQUAL &&
96 path[lstrlen(check)] != '\\';
98 return (!inf) ? res : res && (inf == path + lstrlen(check) - 3);
101 static void test_original_file_name(LPCSTR original, LPCSTR dest)
103 HINF hinf;
104 PSP_INF_INFORMATION pspii;
105 SP_ORIGINAL_FILE_INFO spofi;
106 BOOL res;
107 DWORD size;
109 if (!pSetupQueryInfOriginalFileInformationA)
111 win_skip("SetupQueryInfOriginalFileInformationA is not available\n");
112 return;
115 hinf = SetupOpenInfFileA(dest, NULL, INF_STYLE_WIN4, NULL);
116 ok(hinf != NULL, "SetupOpenInfFileA failed with error %d\n", GetLastError());
118 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
119 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
121 pspii = HeapAlloc(GetProcessHeap(), 0, size);
123 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, pspii, size, NULL);
124 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
126 spofi.cbSize = 0;
127 res = pSetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
128 ok(!res && GetLastError() == ERROR_INVALID_USER_BUFFER,
129 "SetupQueryInfOriginalFileInformationA should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", GetLastError());
131 spofi.cbSize = sizeof(spofi);
132 res = pSetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
133 ok(res, "SetupQueryInfOriginalFileInformationA failed with error %d\n", GetLastError());
134 ok(!spofi.OriginalCatalogName[0], "spofi.OriginalCatalogName should have been \"\" instead of \"%s\"\n", spofi.OriginalCatalogName);
135 todo_wine
136 ok(!strcmp(original, spofi.OriginalInfName), "spofi.OriginalInfName of %s didn't match real original name %s\n", spofi.OriginalInfName, original);
138 HeapFree(GetProcessHeap(), 0, pspii);
140 SetupCloseInfFile(hinf);
143 static void test_SetupCopyOEMInf(void)
145 CHAR toolong[MAX_PATH * 2];
146 CHAR path[MAX_PATH], dest[MAX_PATH];
147 CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
148 LPSTR inf = NULL;
149 DWORD size;
150 BOOL res;
152 /* try NULL SourceInfFileName */
153 SetLastError(0xdeadbeef);
154 res = pSetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
155 ok(res == FALSE, "Expected FALSE, got %d\n", res);
156 ok(GetLastError() == ERROR_INVALID_PARAMETER,
157 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
159 /* try empty SourceInfFileName */
160 SetLastError(0xdeadbeef);
161 res = pSetupCopyOEMInfA("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
162 ok(res == FALSE, "Expected FALSE, got %d\n", res);
163 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
164 GetLastError() == ERROR_BAD_PATHNAME || /* Win98 */
165 GetLastError() == ERROR_INVALID_PARAMETER, /* Vista, W2K8 */
166 "Unexpected error : %d\n", GetLastError());
168 /* try a relative nonexistent SourceInfFileName */
169 SetLastError(0xdeadbeef);
170 res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
171 ok(res == FALSE, "Expected FALSE, got %d\n", res);
172 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
173 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
175 /* try an absolute nonexistent SourceInfFileName */
176 lstrcpy(path, CURR_DIR);
177 lstrcat(path, "\\nonexistent");
178 SetLastError(0xdeadbeef);
179 res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
180 ok(res == FALSE, "Expected FALSE, got %d\n", res);
181 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
182 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
184 /* try a long SourceInfFileName */
185 memset(toolong, 'a', MAX_PATH * 2);
186 toolong[MAX_PATH * 2 - 1] = '\0';
187 SetLastError(0xdeadbeef);
188 res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
189 ok(res == FALSE, "Expected FALSE, got %d\n", res);
190 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
191 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Win98 */
192 "Expected ERROR_FILE_NOT_FOUND or ERROR_FILENAME_EXCED_RANGE, got %d\n", GetLastError());
194 get_temp_filename(tmpfile);
195 create_inf_file(tmpfile);
197 /* try a relative SourceInfFileName */
198 SetLastError(0xdeadbeef);
199 res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
200 ok(res == FALSE, "Expected FALSE, got %d\n", res);
201 if (GetLastError() == ERROR_WRONG_INF_TYPE)
203 /* FIXME:
204 * Vista needs a [Manufacturer] entry in the inf file. Doing this will give some
205 * popups during the installation though as it also needs a catalog file (signed?).
207 win_skip("Needs a different inf file on Vista/W2K8\n");
208 DeleteFile(tmpfile);
209 return;
212 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
213 GetLastError() == ERROR_FILE_EXISTS, /* Win98 */
214 "Expected ERROR_FILE_NOT_FOUND or ERROR_FILE_EXISTS, got %d\n", GetLastError());
215 ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
217 /* try SP_COPY_REPLACEONLY, dest does not exist */
218 SetLastError(0xdeadbeef);
219 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
220 ok(res == FALSE, "Expected FALSE, got %d\n", res);
221 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
222 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
223 ok(file_exists(tmpfile), "Expected source inf to exist\n");
225 /* try an absolute SourceInfFileName, without DestinationInfFileName */
226 lstrcpy(path, CURR_DIR);
227 lstrcat(path, "\\");
228 lstrcat(path, tmpfile);
229 SetLastError(0xdeadbeef);
230 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
231 ok(res == TRUE, "Expected TRUE, got %d\n", res);
232 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
233 ok(file_exists(path), "Expected source inf to exist\n");
235 /* try SP_COPY_REPLACEONLY, dest exists */
236 SetLastError(0xdeadbeef);
237 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
238 ok(res == TRUE, "Expected TRUE, got %d\n", res);
239 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
240 ok(file_exists(path), "Expected source inf to exist\n");
242 /* try SP_COPY_NOOVERWRITE */
243 SetLastError(0xdeadbeef);
244 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
245 ok(res == FALSE, "Expected FALSE, got %d\n", res);
246 ok(GetLastError() == ERROR_FILE_EXISTS,
247 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
249 /* get the DestinationInfFileName */
250 SetLastError(0xdeadbeef);
251 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
252 ok(res == TRUE, "Expected TRUE, got %d\n", res);
253 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
254 ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
255 ok(file_exists(dest), "Expected destination inf to exist\n");
256 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
257 ok(file_exists(path), "Expected source inf to exist\n");
259 lstrcpy(dest_save, dest);
260 DeleteFile(dest_save);
262 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
263 * - inf is still copied
265 lstrcpy(dest, "aaa");
266 size = 0;
267 SetLastError(0xdeadbeef);
268 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
269 ok(res == FALSE, "Expected FALSE, got %d\n", res);
270 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
271 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
272 ok(file_exists(path), "Expected source inf to exist\n");
273 ok(file_exists(dest_save), "Expected dest inf to exist\n");
274 ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
275 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
277 /* get the DestinationInfFileName and DestinationInfFileNameSize */
278 SetLastError(0xdeadbeef);
279 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
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, NULL), "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");
288 test_original_file_name(strrchr(path, '\\') + 1, dest);
290 /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
291 SetLastError(0xdeadbeef);
292 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
293 ok(res == TRUE, "Expected TRUE, got %d\n", res);
294 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
295 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
296 ok(file_exists(dest), "Expected destination inf to exist\n");
297 ok((inf && inf[0] != 0) ||
298 broken(!inf), /* Win98 */
299 "Expected inf to point to the filename\n");
300 ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
301 ok(file_exists(path), "Expected source inf to exist\n");
302 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
304 /* try SP_COPY_DELETESOURCE */
305 SetLastError(0xdeadbeef);
306 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
307 ok(res == TRUE, "Expected TRUE, got %d\n", res);
308 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
309 ok(!file_exists(path), "Expected source inf to not exist\n");
312 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
314 HANDLE handle;
315 DWORD written;
317 handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
318 WriteFile(handle, data, size, &written, NULL);
319 CloseHandle(handle);
322 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
324 DWORD read;
325 HANDLE handle;
326 BOOL ret = FALSE;
327 LPBYTE buffer;
329 handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
330 buffer = HeapAlloc(GetProcessHeap(), 0, size);
331 if (buffer)
333 ReadFile(handle, buffer, size, &read, NULL);
334 if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
335 HeapFree(GetProcessHeap(), 0, buffer);
337 CloseHandle(handle);
338 return ret;
341 static const BYTE uncompressed[] = {
342 'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
344 static const BYTE comp_lzx[] = {
345 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
346 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
348 static const BYTE comp_zip[] = {
349 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
350 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
351 0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
352 0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
353 0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
354 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
355 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
356 0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
357 0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
358 0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
360 static const BYTE comp_cab_lzx[] = {
361 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
363 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
365 0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
366 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
367 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
369 static const BYTE comp_cab_zip[] = {
370 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
371 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
372 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
373 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
374 0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
375 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
378 static void test_SetupGetFileCompressionInfo(void)
380 DWORD ret, source_size, target_size;
381 char source[MAX_PATH], temp[MAX_PATH], *name;
382 UINT type;
384 GetTempPathA(sizeof(temp), temp);
385 GetTempFileNameA(temp, "fci", 0, source);
387 create_source_file(source, uncompressed, sizeof(uncompressed));
389 ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
390 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
392 ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
393 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
395 ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
396 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
398 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
399 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
401 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
402 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
404 name = NULL;
405 source_size = target_size = 0;
406 type = 5;
408 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
409 ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
410 ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
411 ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
412 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
413 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
415 MyFree(name);
416 DeleteFileA(source);
419 static void test_SetupGetFileCompressionInfoEx(void)
421 BOOL ret;
422 DWORD required_len, source_size, target_size;
423 char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
424 UINT type;
426 GetTempPathA(sizeof(temp), temp);
427 GetTempFileNameA(temp, "doc", 0, source);
429 ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
430 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
432 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
433 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
435 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
436 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
437 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
439 create_source_file(source, comp_lzx, sizeof(comp_lzx));
441 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
442 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
443 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
444 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
445 ok(source_size == sizeof(comp_lzx), "got %d\n", source_size);
446 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
447 ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
448 DeleteFileA(source);
450 create_source_file(source, comp_zip, sizeof(comp_zip));
452 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
453 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
454 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
455 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
456 ok(source_size == sizeof(comp_zip), "got %d\n", source_size);
457 ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
458 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
459 DeleteFileA(source);
461 create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
463 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
464 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
465 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
466 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
467 ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size);
468 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
469 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
470 DeleteFileA(source);
472 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
474 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
475 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
476 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
477 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
478 ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
479 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
480 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
481 DeleteFileA(source);
484 static void test_SetupDecompressOrCopyFile(void)
486 DWORD ret;
487 char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
488 UINT type;
490 GetTempPathA(sizeof(temp), temp);
491 GetTempFileNameA(temp, "doc", 0, source);
492 GetTempFileNameA(temp, "doc", 0, target);
494 /* parameter tests */
496 create_source_file(source, uncompressed, sizeof(uncompressed));
498 ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
499 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
501 type = FILE_COMPRESSION_NONE;
502 ret = SetupDecompressOrCopyFileA(NULL, target, &type);
503 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
505 ret = SetupDecompressOrCopyFileA(source, NULL, &type);
506 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
508 type = 5; /* try an invalid compression type */
509 ret = SetupDecompressOrCopyFileA(source, target, &type);
510 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
512 DeleteFileA(target);
514 /* no compression tests */
516 ret = SetupDecompressOrCopyFileA(source, target, NULL);
517 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
518 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
520 /* try overwriting existing file */
521 ret = SetupDecompressOrCopyFileA(source, target, NULL);
522 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
523 DeleteFileA(target);
525 type = FILE_COMPRESSION_NONE;
526 ret = SetupDecompressOrCopyFileA(source, target, &type);
527 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
528 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
529 DeleteFileA(target);
531 type = FILE_COMPRESSION_WINLZA;
532 ret = SetupDecompressOrCopyFileA(source, target, &type);
533 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
534 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
535 DeleteFileA(target);
537 /* lz compression tests */
539 create_source_file(source, comp_lzx, sizeof(comp_lzx));
541 ret = SetupDecompressOrCopyFileA(source, target, NULL);
542 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
543 DeleteFileA(target);
545 /* zip compression tests */
547 create_source_file(source, comp_zip, sizeof(comp_zip));
549 ret = SetupDecompressOrCopyFileA(source, target, NULL);
550 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
551 ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
552 DeleteFileA(target);
554 /* cabinet compression tests */
556 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
558 p = strrchr(target, '\\');
559 lstrcpyA(p + 1, "wine");
561 ret = SetupDecompressOrCopyFileA(source, target, NULL);
562 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
563 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
565 /* try overwriting existing file */
566 ret = SetupDecompressOrCopyFileA(source, target, NULL);
567 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
569 /* try zip compression */
570 type = FILE_COMPRESSION_MSZIP;
571 ret = SetupDecompressOrCopyFileA(source, target, &type);
572 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
573 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
575 /* try no compression */
576 type = FILE_COMPRESSION_NONE;
577 ret = SetupDecompressOrCopyFileA(source, target, &type);
578 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
579 ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
581 DeleteFileA(target);
582 DeleteFileA(source);
585 static void test_SetupUninstallOEMInf(void)
587 BOOL ret;
589 SetLastError(0xdeadbeef);
590 ret = pSetupUninstallOEMInfA(NULL, 0, NULL);
591 ok(!ret, "Expected failure\n");
592 ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
594 SetLastError(0xdeadbeef);
595 ret = pSetupUninstallOEMInfA("", 0, NULL);
596 todo_wine
598 ok(!ret, "Expected failure\n");
599 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
602 SetLastError(0xdeadbeef);
603 ret = pSetupUninstallOEMInfA("nonexistent.inf", 0, NULL);
604 todo_wine
606 ok(!ret, "Expected failure\n");
607 ok(GetLastError() == ERROR_FILE_NOT_FOUND, "Expected ERROR_FILE_NOT_FOUND, got %08x\n", GetLastError());
611 START_TEST(misc)
613 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
615 pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
616 pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
617 pSetupQueryInfOriginalFileInformationA = (void*)GetProcAddress(hsetupapi, "SetupQueryInfOriginalFileInformationA");
618 pSetupUninstallOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupUninstallOEMInfA");
620 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
622 if (pSetupCopyOEMInfA)
623 test_SetupCopyOEMInf();
624 else
625 win_skip("SetupCopyOEMInfA is not available\n");
627 test_SetupGetFileCompressionInfo();
629 if (pSetupGetFileCompressionInfoExA)
630 test_SetupGetFileCompressionInfoEx();
631 else
632 win_skip("SetupGetFileCompressionInfoExA is not available\n");
634 test_SetupDecompressOrCopyFile();
636 if (pSetupUninstallOEMInfA)
637 test_SetupUninstallOEMInf();
638 else
639 win_skip("SetupUninstallOEMInfA is not available\n");