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
32 #include "wine/test.h"
34 static CHAR CURR_DIR[MAX_PATH];
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
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 *);
49 static void append_str(char **str, const char *data)
55 static void create_inf_file(LPCSTR filename)
59 DWORD dwNumberOfBytesWritten;
60 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
61 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
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");
71 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
75 static void get_temp_filename(LPSTR path)
80 GetTempFileName(CURR_DIR, "set", 0, temp);
81 ptr = strrchr(temp, '\\');
83 lstrcpy(path, ptr + 1);
86 static BOOL file_exists(LPSTR path)
88 return GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES;
91 static BOOL check_format(LPSTR path, LPSTR inf)
96 static const CHAR format[] = "\\INF\\oem";
98 GetWindowsDirectory(check, MAX_PATH);
99 lstrcat(check, format);
100 res = !strncasecmp(check, path, lstrlen(check)) &&
101 path[lstrlen(check)] != '\\';
103 return (!inf) ? res : res && (inf == path + lstrlen(check) - 3);
106 static void test_original_file_name(LPCSTR original, LPCSTR dest)
109 PSP_INF_INFORMATION pspii;
110 SP_ORIGINAL_FILE_INFO spofi;
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());
126 res = SetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
127 ok(!res && GetLastError() == ERROR_INVALID_USER_BUFFER,
128 "SetupQueryInfOriginalFileInformationA should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", GetLastError());
130 spofi.cbSize = sizeof(spofi);
131 res = SetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
132 ok(res, "SetupQueryInfOriginalFileInformationA failed with error %d\n", GetLastError());
133 ok(!spofi.OriginalCatalogName[0], "spofi.OriginalCatalogName should have been \"\" instead of \"%s\"\n", spofi.OriginalCatalogName);
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];
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 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
165 /* try a relative nonexistent SourceInfFileName */
166 SetLastError(0xdeadbeef);
167 res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
168 ok(res == FALSE, "Expected FALSE, got %d\n", res);
169 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
170 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
172 /* try an absolute nonexistent SourceInfFileName */
173 lstrcpy(path, CURR_DIR);
174 lstrcat(path, "\\nonexistent");
175 SetLastError(0xdeadbeef);
176 res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
177 ok(res == FALSE, "Expected FALSE, got %d\n", res);
178 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
179 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
181 /* try a long SourceInfFileName */
182 memset(toolong, 'a', MAX_PATH * 2);
183 toolong[MAX_PATH * 2 - 1] = '\0';
184 SetLastError(0xdeadbeef);
185 res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
186 ok(res == FALSE, "Expected FALSE, got %d\n", res);
187 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
188 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
190 get_temp_filename(tmpfile);
191 create_inf_file(tmpfile);
193 /* try a relative SourceInfFileName */
194 SetLastError(0xdeadbeef);
195 res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
196 ok(res == FALSE, "Expected FALSE, got %d\n", res);
197 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
198 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
199 ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
201 /* try SP_COPY_REPLACEONLY, dest does not exist */
202 SetLastError(0xdeadbeef);
203 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
204 ok(res == FALSE, "Expected FALSE, got %d\n", res);
205 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
206 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
207 ok(file_exists(tmpfile), "Expected source inf to exist\n");
209 /* try an absolute SourceInfFileName, without DestinationInfFileName */
210 lstrcpy(path, CURR_DIR);
212 lstrcat(path, tmpfile);
213 SetLastError(0xdeadbeef);
214 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
215 ok(res == TRUE, "Expected TRUE, got %d\n", res);
216 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
217 ok(file_exists(path), "Expected source inf to exist\n");
219 /* try SP_COPY_REPLACEONLY, dest exists */
220 SetLastError(0xdeadbeef);
221 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
222 ok(res == TRUE, "Expected TRUE, got %d\n", res);
223 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
224 ok(file_exists(path), "Expected source inf to exist\n");
226 /* try SP_COPY_NOOVERWRITE */
227 SetLastError(0xdeadbeef);
228 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
229 ok(res == FALSE, "Expected FALSE, got %d\n", res);
230 ok(GetLastError() == ERROR_FILE_EXISTS,
231 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
233 /* get the DestinationInfFileName */
234 SetLastError(0xdeadbeef);
235 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
236 ok(res == TRUE, "Expected TRUE, got %d\n", res);
237 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
238 ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
239 ok(file_exists(dest), "Expected destination inf to exist\n");
240 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
241 ok(file_exists(path), "Expected source inf to exist\n");
243 lstrcpy(dest_save, dest);
244 DeleteFile(dest_save);
246 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
247 * - inf is still copied
249 lstrcpy(dest, "aaa");
251 SetLastError(0xdeadbeef);
252 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
253 ok(res == FALSE, "Expected FALSE, got %d\n", res);
254 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
255 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
256 ok(file_exists(path), "Expected source inf to exist\n");
257 ok(file_exists(dest_save), "Expected dest inf to exist\n");
258 ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
259 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
261 /* get the DestinationInfFileName and DestinationInfFileNameSize */
262 SetLastError(0xdeadbeef);
263 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
264 ok(res == TRUE, "Expected TRUE, got %d\n", res);
265 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
266 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
267 ok(file_exists(dest), "Expected destination inf to exist\n");
268 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
269 ok(file_exists(path), "Expected source inf to exist\n");
270 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
272 test_original_file_name(strrchr(path, '\\') + 1, dest);
274 /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
275 SetLastError(0xdeadbeef);
276 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
277 ok(res == TRUE, "Expected TRUE, got %d\n", res);
278 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
279 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
280 ok(file_exists(dest), "Expected destination inf to exist\n");
281 ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
282 ok(file_exists(path), "Expected source inf to exist\n");
283 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
285 /* try SP_COPY_DELETESOURCE */
286 SetLastError(0xdeadbeef);
287 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
288 ok(res == TRUE, "Expected TRUE, got %d\n", res);
289 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
290 ok(!file_exists(path), "Expected source inf to not exist\n");
293 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
298 handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
299 WriteFile(handle, data, size, &written, NULL);
303 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
310 handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
311 buffer = HeapAlloc(GetProcessHeap(), 0, size);
314 ReadFile(handle, buffer, size, &read, NULL);
315 if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
316 HeapFree(GetProcessHeap(), 0, buffer);
322 static const BYTE uncompressed[] = {
323 'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
325 static const BYTE comp_lzx[] = {
326 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
327 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
329 static const BYTE comp_zip[] = {
330 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
331 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
332 0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
333 0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
334 0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
335 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
336 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
337 0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
338 0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
339 0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
341 static const BYTE comp_cab_lzx[] = {
342 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
343 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
344 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
345 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
346 0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
347 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
348 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
350 static const BYTE comp_cab_zip[] = {
351 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
353 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
355 0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
356 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
359 static void test_SetupGetFileCompressionInfo(void)
361 DWORD ret, source_size, target_size;
362 char source[MAX_PATH], temp[MAX_PATH], *name;
365 GetTempPathA(sizeof(temp), temp);
366 GetTempFileNameA(temp, "fci", 0, source);
368 create_source_file(source, uncompressed, sizeof(uncompressed));
370 ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
371 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
373 ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
374 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
376 ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
377 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
379 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
380 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
382 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
383 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
386 source_size = target_size = 0;
389 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
390 ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
391 ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
392 ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
393 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
394 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
399 static void test_SetupGetFileCompressionInfoEx(void)
402 DWORD required_len, source_size, target_size;
403 char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
406 GetTempPathA(sizeof(temp), temp);
407 GetTempFileNameA(temp, "doc", 0, source);
409 ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
410 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
412 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
413 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
415 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
416 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
417 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
419 create_source_file(source, comp_lzx, sizeof(comp_lzx));
421 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
422 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
423 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
424 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
425 ok(source_size == sizeof(comp_lzx), "got %d\n", source_size);
426 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
427 ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
430 create_source_file(source, comp_zip, sizeof(comp_zip));
432 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
433 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
434 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
435 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
436 ok(source_size == sizeof(comp_zip), "got %d\n", source_size);
437 ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
438 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
441 create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
443 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
444 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
445 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
446 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
447 ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size);
448 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
449 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
452 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
454 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
455 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
456 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
457 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
458 ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
459 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
460 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
464 static void test_SetupDecompressOrCopyFile(void)
467 char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
470 GetTempPathA(sizeof(temp), temp);
471 GetTempFileNameA(temp, "doc", 0, source);
472 GetTempFileNameA(temp, "doc", 0, target);
474 /* parameter tests */
476 create_source_file(source, uncompressed, sizeof(uncompressed));
478 ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
479 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
481 type = FILE_COMPRESSION_NONE;
482 ret = SetupDecompressOrCopyFileA(NULL, target, &type);
483 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
485 ret = SetupDecompressOrCopyFileA(source, NULL, &type);
486 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
488 type = 5; /* try an invalid compression type */
489 ret = SetupDecompressOrCopyFileA(source, target, &type);
490 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
494 /* no compression tests */
496 ret = SetupDecompressOrCopyFileA(source, target, NULL);
497 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
498 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
500 /* try overwriting existing file */
501 ret = SetupDecompressOrCopyFileA(source, target, NULL);
502 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
505 type = FILE_COMPRESSION_NONE;
506 ret = SetupDecompressOrCopyFileA(source, target, &type);
507 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
508 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
511 type = FILE_COMPRESSION_WINLZA;
512 ret = SetupDecompressOrCopyFileA(source, target, &type);
513 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
514 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
517 /* lz compression tests */
519 create_source_file(source, comp_lzx, sizeof(comp_lzx));
521 ret = SetupDecompressOrCopyFileA(source, target, NULL);
522 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
525 /* zip compression tests */
527 create_source_file(source, comp_zip, sizeof(comp_zip));
529 ret = SetupDecompressOrCopyFileA(source, target, NULL);
530 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
531 ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
534 /* cabinet compression tests */
536 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
538 p = strrchr(target, '\\');
539 lstrcpyA(p + 1, "wine");
541 ret = SetupDecompressOrCopyFileA(source, target, NULL);
542 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
543 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
545 /* try overwriting existing file */
546 ret = SetupDecompressOrCopyFileA(source, target, NULL);
547 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
549 /* try zip compression */
550 type = FILE_COMPRESSION_MSZIP;
551 ret = SetupDecompressOrCopyFileA(source, target, &type);
552 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
553 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
555 /* try no compression */
556 type = FILE_COMPRESSION_NONE;
557 ret = SetupDecompressOrCopyFileA(source, target, &type);
558 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
559 ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
567 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
569 pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
570 pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
572 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
574 if (pSetupCopyOEMInfA)
575 test_SetupCopyOEMInf();
577 skip("SetupCopyOEMInfA is not available\n");
579 test_SetupGetFileCompressionInfo();
581 if (pSetupGetFileCompressionInfoExA)
582 test_SetupGetFileCompressionInfoEx();
584 skip("SetupGetFileCompressionInfoExA is not available\n");
586 test_SetupDecompressOrCopyFile();