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_SetupCopyOEMInf(void)
108 CHAR toolong[MAX_PATH * 2];
109 CHAR path[MAX_PATH], dest[MAX_PATH];
110 CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
115 /* try NULL SourceInfFileName */
116 SetLastError(0xdeadbeef);
117 res = pSetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
118 ok(res == FALSE, "Expected FALSE, got %d\n", res);
119 ok(GetLastError() == ERROR_INVALID_PARAMETER,
120 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
122 /* try empty SourceInfFileName */
123 SetLastError(0xdeadbeef);
124 res = pSetupCopyOEMInfA("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
125 ok(res == FALSE, "Expected FALSE, got %d\n", res);
126 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
127 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
129 /* try a relative nonexistent SourceInfFileName */
130 SetLastError(0xdeadbeef);
131 res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
132 ok(res == FALSE, "Expected FALSE, got %d\n", res);
133 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
134 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
136 /* try an absolute nonexistent SourceInfFileName */
137 lstrcpy(path, CURR_DIR);
138 lstrcat(path, "\\nonexistent");
139 SetLastError(0xdeadbeef);
140 res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
141 ok(res == FALSE, "Expected FALSE, got %d\n", res);
142 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
143 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
145 /* try a long SourceInfFileName */
146 memset(toolong, 'a', MAX_PATH * 2);
147 toolong[MAX_PATH * 2 - 1] = '\0';
148 SetLastError(0xdeadbeef);
149 res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
150 ok(res == FALSE, "Expected FALSE, got %d\n", res);
151 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
152 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
154 get_temp_filename(tmpfile);
155 create_inf_file(tmpfile);
157 /* try a relative SourceInfFileName */
158 SetLastError(0xdeadbeef);
159 res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
160 ok(res == FALSE, "Expected FALSE, got %d\n", res);
161 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
162 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
163 ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
165 /* try SP_COPY_REPLACEONLY, dest does not exist */
166 SetLastError(0xdeadbeef);
167 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, 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());
171 ok(file_exists(tmpfile), "Expected source inf to exist\n");
173 /* try an absolute SourceInfFileName, without DestinationInfFileName */
174 lstrcpy(path, CURR_DIR);
176 lstrcat(path, tmpfile);
177 SetLastError(0xdeadbeef);
178 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
179 ok(res == TRUE, "Expected TRUE, got %d\n", res);
180 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
181 ok(file_exists(path), "Expected source inf to exist\n");
183 /* try SP_COPY_REPLACEONLY, dest exists */
184 SetLastError(0xdeadbeef);
185 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
186 ok(res == TRUE, "Expected TRUE, got %d\n", res);
187 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
188 ok(file_exists(path), "Expected source inf to exist\n");
190 /* try SP_COPY_NOOVERWRITE */
191 SetLastError(0xdeadbeef);
192 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
193 ok(res == FALSE, "Expected FALSE, got %d\n", res);
194 ok(GetLastError() == ERROR_FILE_EXISTS,
195 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
197 /* get the DestinationInfFileName */
198 SetLastError(0xdeadbeef);
199 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
200 ok(res == TRUE, "Expected TRUE, got %d\n", res);
201 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
202 ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
203 ok(file_exists(dest), "Expected destination inf to exist\n");
204 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
205 ok(file_exists(path), "Expected source inf to exist\n");
207 lstrcpy(dest_save, dest);
208 DeleteFile(dest_save);
210 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
211 * - inf is still copied
213 lstrcpy(dest, "aaa");
215 SetLastError(0xdeadbeef);
216 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
217 ok(res == FALSE, "Expected FALSE, got %d\n", res);
218 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
219 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
220 ok(file_exists(path), "Expected source inf to exist\n");
221 ok(file_exists(dest_save), "Expected dest inf to exist\n");
222 ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
223 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
225 /* get the DestinationInfFileName and DestinationInfFileNameSize */
226 SetLastError(0xdeadbeef);
227 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, 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(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
231 ok(file_exists(dest), "Expected destination inf to exist\n");
232 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
233 ok(file_exists(path), "Expected source inf to exist\n");
234 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
236 /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
237 SetLastError(0xdeadbeef);
238 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
239 ok(res == TRUE, "Expected TRUE, got %d\n", res);
240 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
241 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
242 ok(file_exists(dest), "Expected destination inf to exist\n");
243 ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
244 ok(file_exists(path), "Expected source inf to exist\n");
245 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
247 /* try SP_COPY_DELETESOURCE */
248 SetLastError(0xdeadbeef);
249 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
250 ok(res == TRUE, "Expected TRUE, got %d\n", res);
251 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
252 ok(!file_exists(path), "Expected source inf to not exist\n");
255 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
260 handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
261 WriteFile(handle, data, size, &written, NULL);
265 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
272 handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
273 buffer = HeapAlloc(GetProcessHeap(), 0, size);
276 ReadFile(handle, buffer, size, &read, NULL);
277 if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
278 HeapFree(GetProcessHeap(), 0, buffer);
284 static const BYTE uncompressed[] = {
285 'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
287 static const BYTE comp_lzx[] = {
288 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
289 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
291 static const BYTE comp_zip[] = {
292 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
293 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
294 0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
295 0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
296 0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
297 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
298 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
299 0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
300 0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
301 0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
303 static const BYTE comp_cab_lzx[] = {
304 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
305 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
306 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
307 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
308 0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
309 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
310 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
312 static const BYTE comp_cab_zip[] = {
313 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
314 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
315 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
316 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
317 0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
318 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
321 static void test_SetupGetFileCompressionInfo(void)
323 DWORD ret, source_size, target_size;
324 char source[MAX_PATH], temp[MAX_PATH], *name;
327 GetTempPathA(sizeof(temp), temp);
328 GetTempFileNameA(temp, "fci", 0, source);
330 create_source_file(source, uncompressed, sizeof(uncompressed));
332 ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
333 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
335 ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
336 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
338 ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
339 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
341 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
342 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
344 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
345 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
348 source_size = target_size = 0;
351 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
352 ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
353 ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
354 ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
355 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
356 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
361 static void test_SetupGetFileCompressionInfoEx(void)
364 DWORD required_len, source_size, target_size;
365 char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
368 GetTempPathA(sizeof(temp), temp);
369 GetTempFileNameA(temp, "doc", 0, source);
371 ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
372 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
374 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
375 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
377 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
378 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
379 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
381 create_source_file(source, comp_lzx, sizeof(comp_lzx));
383 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
384 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
385 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
386 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
387 ok(source_size == sizeof(comp_lzx), "got %d\n", source_size);
388 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
389 ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
392 create_source_file(source, comp_zip, sizeof(comp_zip));
394 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
395 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
396 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
397 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
398 ok(source_size == sizeof(comp_zip), "got %d\n", source_size);
399 ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
400 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
403 create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
405 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
406 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
407 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
408 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
409 ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size);
410 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
411 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
414 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
416 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
417 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
418 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
419 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
420 ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
421 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
422 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
426 static void test_SetupDecompressOrCopyFile(void)
429 char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
432 GetTempPathA(sizeof(temp), temp);
433 GetTempFileNameA(temp, "doc", 0, source);
434 GetTempFileNameA(temp, "doc", 0, target);
436 /* parameter tests */
438 create_source_file(source, uncompressed, sizeof(uncompressed));
440 ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
441 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
443 type = FILE_COMPRESSION_NONE;
444 ret = SetupDecompressOrCopyFileA(NULL, target, &type);
445 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
447 ret = SetupDecompressOrCopyFileA(source, NULL, &type);
448 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
450 type = 5; /* try an invalid compression type */
451 ret = SetupDecompressOrCopyFileA(source, target, &type);
452 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
456 /* no compression tests */
458 ret = SetupDecompressOrCopyFileA(source, target, NULL);
459 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
460 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
462 /* try overwriting existing file */
463 ret = SetupDecompressOrCopyFileA(source, target, NULL);
464 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
467 type = FILE_COMPRESSION_NONE;
468 ret = SetupDecompressOrCopyFileA(source, target, &type);
469 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
470 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
473 type = FILE_COMPRESSION_WINLZA;
474 ret = SetupDecompressOrCopyFileA(source, target, &type);
475 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
476 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
479 /* lz compression tests */
481 create_source_file(source, comp_lzx, sizeof(comp_lzx));
483 ret = SetupDecompressOrCopyFileA(source, target, NULL);
484 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
487 /* zip compression tests */
489 create_source_file(source, comp_zip, sizeof(comp_zip));
491 ret = SetupDecompressOrCopyFileA(source, target, NULL);
492 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
493 ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
496 /* cabinet compression tests */
498 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
500 p = strrchr(target, '\\');
501 lstrcpyA(p + 1, "wine");
503 ret = SetupDecompressOrCopyFileA(source, target, NULL);
504 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
505 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
507 /* try overwriting existing file */
508 ret = SetupDecompressOrCopyFileA(source, target, NULL);
509 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
511 /* try zip compression */
512 type = FILE_COMPRESSION_MSZIP;
513 ret = SetupDecompressOrCopyFileA(source, target, &type);
514 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
515 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
517 /* try no compression */
518 type = FILE_COMPRESSION_NONE;
519 ret = SetupDecompressOrCopyFileA(source, target, &type);
520 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
521 ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
529 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
531 pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
532 pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
534 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
536 if (pSetupCopyOEMInfA)
537 test_SetupCopyOEMInf();
539 skip("SetupCopyOEMInfA is not available\n");
541 test_SetupGetFileCompressionInfo();
543 if (pSetupGetFileCompressionInfoExA)
544 test_SetupGetFileCompressionInfoEx();
546 skip("SetupGetFileCompressionInfoExA is not available\n");
548 test_SetupDecompressOrCopyFile();