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);
47 static void append_str(char **str, const char *data)
53 static void create_inf_file(LPCSTR filename)
57 DWORD dwNumberOfBytesWritten;
58 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
59 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
61 append_str(&ptr, "[Version]\n");
62 append_str(&ptr, "Signature=\"$Chicago$\"\n");
63 append_str(&ptr, "AdvancedINF=2.5\n");
64 append_str(&ptr, "[DefaultInstall]\n");
65 append_str(&ptr, "RegisterOCXs=RegisterOCXsSection\n");
66 append_str(&ptr, "[RegisterOCXsSection]\n");
67 append_str(&ptr, "%%11%%\\ole32.dll\n");
69 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
73 static void get_temp_filename(LPSTR path)
78 GetTempFileName(CURR_DIR, "set", 0, temp);
79 ptr = strrchr(temp, '\\');
81 lstrcpy(path, ptr + 1);
84 static BOOL file_exists(LPSTR path)
86 return GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES;
89 static BOOL check_format(LPSTR path, LPSTR inf)
94 static const CHAR format[] = "\\INF\\oem";
96 GetWindowsDirectory(check, MAX_PATH);
97 lstrcat(check, format);
98 res = !strncasecmp(check, path, lstrlen(check)) &&
99 path[lstrlen(check)] != '\\';
101 return (!inf) ? res : res && (inf == path + lstrlen(check) - 3);
104 static void test_SetupCopyOEMInf(void)
106 CHAR toolong[MAX_PATH * 2];
107 CHAR path[MAX_PATH], dest[MAX_PATH];
108 CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
113 /* try NULL SourceInfFileName */
114 SetLastError(0xdeadbeef);
115 res = SetupCopyOEMInf(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
116 ok(res == FALSE, "Expected FALSE, got %d\n", res);
117 ok(GetLastError() == ERROR_INVALID_PARAMETER,
118 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
120 /* try empty SourceInfFileName */
121 SetLastError(0xdeadbeef);
122 res = SetupCopyOEMInf("", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
123 ok(res == FALSE, "Expected FALSE, got %d\n", res);
124 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
125 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
127 /* try a relative nonexistent SourceInfFileName */
128 SetLastError(0xdeadbeef);
129 res = SetupCopyOEMInf("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
130 ok(res == FALSE, "Expected FALSE, got %d\n", res);
131 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
132 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
134 /* try an absolute nonexistent SourceInfFileName */
135 lstrcpy(path, CURR_DIR);
136 lstrcat(path, "\\nonexistent");
137 SetLastError(0xdeadbeef);
138 res = SetupCopyOEMInf(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
139 ok(res == FALSE, "Expected FALSE, got %d\n", res);
140 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
141 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
143 /* try a long SourceInfFileName */
144 memset(toolong, 'a', MAX_PATH * 2);
145 toolong[MAX_PATH * 2 - 1] = '\0';
146 SetLastError(0xdeadbeef);
147 res = SetupCopyOEMInf(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
148 ok(res == FALSE, "Expected FALSE, got %d\n", res);
149 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
150 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
152 get_temp_filename(tmpfile);
153 create_inf_file(tmpfile);
155 /* try a relative SourceInfFileName */
156 SetLastError(0xdeadbeef);
157 res = SetupCopyOEMInf(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
158 ok(res == FALSE, "Expected FALSE, got %d\n", res);
159 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
160 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
161 ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
163 /* try SP_COPY_REPLACEONLY, dest does not exist */
164 SetLastError(0xdeadbeef);
165 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
166 ok(res == FALSE, "Expected FALSE, got %d\n", res);
167 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
168 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
169 ok(file_exists(tmpfile), "Expected source inf to exist\n");
171 /* try an absolute SourceInfFileName, without DestinationInfFileName */
172 lstrcpy(path, CURR_DIR);
174 lstrcat(path, tmpfile);
175 SetLastError(0xdeadbeef);
176 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
177 ok(res == TRUE, "Expected TRUE, got %d\n", res);
178 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
179 ok(file_exists(path), "Expected source inf to exist\n");
181 /* try SP_COPY_REPLACEONLY, dest exists */
182 SetLastError(0xdeadbeef);
183 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
184 ok(res == TRUE, "Expected TRUE, got %d\n", res);
185 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
186 ok(file_exists(path), "Expected source inf to exist\n");
188 /* try SP_COPY_NOOVERWRITE */
189 SetLastError(0xdeadbeef);
190 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
191 ok(res == FALSE, "Expected FALSE, got %d\n", res);
192 ok(GetLastError() == ERROR_FILE_EXISTS,
193 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
195 /* get the DestinationInfFileName */
196 SetLastError(0xdeadbeef);
197 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
198 ok(res == TRUE, "Expected TRUE, got %d\n", res);
199 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
200 ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
201 ok(file_exists(dest), "Expected destination inf to exist\n");
202 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
203 ok(file_exists(path), "Expected source inf to exist\n");
205 lstrcpy(dest_save, dest);
206 DeleteFile(dest_save);
208 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
209 * - inf is still copied
211 lstrcpy(dest, "aaa");
213 SetLastError(0xdeadbeef);
214 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
215 ok(res == FALSE, "Expected FALSE, got %d\n", res);
216 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
217 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
218 ok(file_exists(path), "Expected source inf to exist\n");
219 ok(file_exists(dest_save), "Expected dest inf to exist\n");
220 ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
221 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
223 /* get the DestinationInfFileName and DestinationInfFileNameSize */
224 SetLastError(0xdeadbeef);
225 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
226 ok(res == TRUE, "Expected TRUE, got %d\n", res);
227 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
228 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
229 ok(file_exists(dest), "Expected destination inf to exist\n");
230 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
231 ok(file_exists(path), "Expected source inf to exist\n");
232 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
234 /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
235 SetLastError(0xdeadbeef);
236 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
237 ok(res == TRUE, "Expected TRUE, got %d\n", res);
238 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
239 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
240 ok(file_exists(dest), "Expected destination inf to exist\n");
241 ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
242 ok(file_exists(path), "Expected source inf to exist\n");
243 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
245 /* try SP_COPY_DELETESOURCE */
246 SetLastError(0xdeadbeef);
247 res = SetupCopyOEMInf(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
248 ok(res == TRUE, "Expected TRUE, got %d\n", res);
249 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
250 ok(!file_exists(path), "Expected source inf to not exist\n");
253 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
258 handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
259 WriteFile(handle, data, size, &written, NULL);
263 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
270 handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
271 buffer = HeapAlloc(GetProcessHeap(), 0, size);
274 ReadFile(handle, buffer, size, &read, NULL);
275 if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
276 HeapFree(GetProcessHeap(), 0, buffer);
282 static const BYTE uncompressed[] = {
283 'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
285 static const BYTE comp_lzx[] = {
286 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
287 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
289 static const BYTE comp_zip[] = {
290 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
291 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
292 0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
293 0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
294 0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
295 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
296 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
297 0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
298 0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
299 0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
301 static const BYTE comp_cab_lzx[] = {
302 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
303 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
304 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
305 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
306 0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
307 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
308 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
310 static const BYTE comp_cab_zip[] = {
311 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
312 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
313 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
314 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
315 0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
316 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
319 static void test_SetupGetFileCompressionInfo(void)
321 DWORD ret, source_size, target_size;
322 char source[MAX_PATH], temp[MAX_PATH], *name;
325 GetTempPathA(sizeof(temp), temp);
326 GetTempFileNameA(temp, "fci", 0, source);
328 create_source_file(source, uncompressed, sizeof(uncompressed));
330 ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
331 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
333 ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
334 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
336 ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
337 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
339 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
340 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
342 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
343 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
346 source_size = target_size = 0;
349 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
350 ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
351 ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
352 ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
353 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
354 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
359 static void test_SetupGetFileCompressionInfoEx(void)
362 DWORD required_len, source_size, target_size;
363 char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
366 GetTempPathA(sizeof(temp), temp);
367 GetTempFileNameA(temp, "doc", 0, source);
369 ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
370 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
372 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
373 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
375 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
376 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
377 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
379 create_source_file(source, comp_lzx, sizeof(comp_lzx));
381 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
382 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
383 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
384 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
385 ok(source_size == sizeof(comp_lzx), "got %d\n", source_size);
386 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
387 ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
390 create_source_file(source, comp_zip, sizeof(comp_zip));
392 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
393 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
394 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
395 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
396 ok(source_size == sizeof(comp_zip), "got %d\n", source_size);
397 ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
398 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
401 create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
403 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
404 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
405 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
406 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
407 ok(source_size == sizeof(comp_cab_lzx), "got %d\n", source_size);
408 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
409 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
412 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
414 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
415 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
416 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
417 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
418 ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
419 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
420 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
424 static void test_SetupDecompressOrCopyFile(void)
427 char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
430 GetTempPathA(sizeof(temp), temp);
431 GetTempFileNameA(temp, "doc", 0, source);
432 GetTempFileNameA(temp, "doc", 0, target);
434 /* parameter tests */
436 create_source_file(source, uncompressed, sizeof(uncompressed));
438 ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
439 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
441 type = FILE_COMPRESSION_NONE;
442 ret = SetupDecompressOrCopyFileA(NULL, target, &type);
443 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
445 ret = SetupDecompressOrCopyFileA(source, NULL, &type);
446 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
448 type = 5; /* try an invalid compression type */
449 ret = SetupDecompressOrCopyFileA(source, target, &type);
450 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
454 /* no compression tests */
456 ret = SetupDecompressOrCopyFileA(source, target, NULL);
457 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
458 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
460 /* try overwriting existing file */
461 ret = SetupDecompressOrCopyFileA(source, target, NULL);
462 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
465 type = FILE_COMPRESSION_NONE;
466 ret = SetupDecompressOrCopyFileA(source, target, &type);
467 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
468 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
471 type = FILE_COMPRESSION_WINLZA;
472 ret = SetupDecompressOrCopyFileA(source, target, &type);
473 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
474 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
477 /* lz compression tests */
479 create_source_file(source, comp_lzx, sizeof(comp_lzx));
481 ret = SetupDecompressOrCopyFileA(source, target, NULL);
482 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
485 /* zip compression tests */
487 create_source_file(source, comp_zip, sizeof(comp_zip));
489 ret = SetupDecompressOrCopyFileA(source, target, NULL);
490 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
491 ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
494 /* cabinet compression tests */
496 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
498 p = strrchr(target, '\\');
499 lstrcpyA(p + 1, "wine");
501 ret = SetupDecompressOrCopyFileA(source, target, NULL);
502 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
503 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
505 /* try overwriting existing file */
506 ret = SetupDecompressOrCopyFileA(source, target, NULL);
507 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
509 /* try zip compression */
510 type = FILE_COMPRESSION_MSZIP;
511 ret = SetupDecompressOrCopyFileA(source, target, &type);
512 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
513 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
515 /* try no compression */
516 type = FILE_COMPRESSION_NONE;
517 ret = SetupDecompressOrCopyFileA(source, target, &type);
518 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
519 ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
527 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
529 pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
531 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
533 test_SetupCopyOEMInf();
534 test_SetupGetFileCompressionInfo();
536 if (pSetupGetFileCompressionInfoExA)
537 test_SetupGetFileCompressionInfoEx();
539 skip("SetupGetFileCompressionInfoExA is not available\n");
541 test_SetupDecompressOrCopyFile();