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 *);
47 static BOOL (WINAPI *pSetupQueryInfOriginalFileInformationA)(PSP_INF_INFORMATION, UINT, PSP_ALTPLATFORM_INFO, PSP_ORIGINAL_FILE_INFO_A);
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 if (!pSetupQueryInfOriginalFileInformationA)
116 skip("SetupQueryInfOriginalFileInformationA is not available\n");
120 hinf = SetupOpenInfFileA(dest, NULL, INF_STYLE_WIN4, NULL);
121 ok(hinf != NULL, "SetupOpenInfFileA failed with error %d\n", GetLastError());
123 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
124 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
126 pspii = HeapAlloc(GetProcessHeap(), 0, size);
128 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, pspii, size, NULL);
129 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
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());
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);
141 ok(!strcmp(original, spofi.OriginalInfName), "spofi.OriginalInfName of %s didn't match real original name %s\n", spofi.OriginalInfName, original);
143 HeapFree(GetProcessHeap(), 0, pspii);
145 SetupCloseInfFile(hinf);
148 static void test_SetupCopyOEMInf(void)
150 CHAR toolong[MAX_PATH * 2];
151 CHAR path[MAX_PATH], dest[MAX_PATH];
152 CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
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());
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());
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());
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());
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());
196 get_temp_filename(tmpfile);
197 create_inf_file(tmpfile);
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");
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");
215 /* try an absolute SourceInfFileName, without DestinationInfFileName */
216 lstrcpy(path, CURR_DIR);
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");
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");
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());
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");
249 lstrcpy(dest_save, dest);
250 DeleteFile(dest_save);
252 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
253 * - inf is still copied
255 lstrcpy(dest, "aaa");
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");
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");
278 test_original_file_name(strrchr(path, '\\') + 1, dest);
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");
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");
299 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
304 handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
305 WriteFile(handle, data, size, &written, NULL);
309 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
316 handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
317 buffer = HeapAlloc(GetProcessHeap(), 0, size);
320 ReadFile(handle, buffer, size, &read, NULL);
321 if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
322 HeapFree(GetProcessHeap(), 0, buffer);
328 static const BYTE uncompressed[] = {
329 'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
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
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
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
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
365 static void test_SetupGetFileCompressionInfo(void)
367 DWORD ret, source_size, target_size;
368 char source[MAX_PATH], temp[MAX_PATH], *name;
371 GetTempPathA(sizeof(temp), temp);
372 GetTempFileNameA(temp, "fci", 0, source);
374 create_source_file(source, uncompressed, sizeof(uncompressed));
376 ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
377 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
379 ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
380 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
382 ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
383 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
385 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
386 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
388 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
389 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
392 source_size = target_size = 0;
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);
405 static void test_SetupGetFileCompressionInfoEx(void)
408 DWORD required_len, source_size, target_size;
409 char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
412 GetTempPathA(sizeof(temp), temp);
413 GetTempFileNameA(temp, "doc", 0, source);
415 ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
416 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
418 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
419 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
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);
425 create_source_file(source, comp_lzx, sizeof(comp_lzx));
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);
436 create_source_file(source, comp_zip, sizeof(comp_zip));
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);
447 create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
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);
458 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
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);
470 static void test_SetupDecompressOrCopyFile(void)
473 char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
476 GetTempPathA(sizeof(temp), temp);
477 GetTempFileNameA(temp, "doc", 0, source);
478 GetTempFileNameA(temp, "doc", 0, target);
480 /* parameter tests */
482 create_source_file(source, uncompressed, sizeof(uncompressed));
484 ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
485 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
487 type = FILE_COMPRESSION_NONE;
488 ret = SetupDecompressOrCopyFileA(NULL, target, &type);
489 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
491 ret = SetupDecompressOrCopyFileA(source, NULL, &type);
492 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
494 type = 5; /* try an invalid compression type */
495 ret = SetupDecompressOrCopyFileA(source, target, &type);
496 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
500 /* no compression tests */
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");
506 /* try overwriting existing file */
507 ret = SetupDecompressOrCopyFileA(source, target, NULL);
508 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
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");
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");
523 /* lz compression tests */
525 create_source_file(source, comp_lzx, sizeof(comp_lzx));
527 ret = SetupDecompressOrCopyFileA(source, target, NULL);
528 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
531 /* zip compression tests */
533 create_source_file(source, comp_zip, sizeof(comp_zip));
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");
540 /* cabinet compression tests */
542 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
544 p = strrchr(target, '\\');
545 lstrcpyA(p + 1, "wine");
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");
551 /* try overwriting existing file */
552 ret = SetupDecompressOrCopyFileA(source, target, NULL);
553 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
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");
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");
573 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
575 pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
576 pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
577 pSetupQueryInfOriginalFileInformationA = (void*)GetProcAddress(hsetupapi, "SetupQueryInfOriginalFileInformationA");
579 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
581 if (pSetupCopyOEMInfA)
582 test_SetupCopyOEMInf();
584 skip("SetupCopyOEMInfA is not available\n");
586 test_SetupGetFileCompressionInfo();
588 if (pSetupGetFileCompressionInfoExA)
589 test_SetupGetFileCompressionInfoEx();
591 skip("SetupGetFileCompressionInfoExA is not available\n");
593 test_SetupDecompressOrCopyFile();