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
33 #include "wine/test.h"
35 static CHAR CURR_DIR[MAX_PATH];
38 * - fails if not administrator
39 * - what if it's not a .inf file?
40 * - copied to %windir%/Inf
41 * - SourceInfFileName should be a full path
42 * - SourceInfFileName should be <= MAX_PATH
46 static BOOL (WINAPI *pSetupGetFileCompressionInfoExA)(PCSTR, PSTR, DWORD, PDWORD, PDWORD, PDWORD, PUINT);
47 static BOOL (WINAPI *pSetupCopyOEMInfA)(PCSTR, PCSTR, DWORD, DWORD, PSTR, DWORD, PDWORD, PSTR *);
48 static BOOL (WINAPI *pSetupQueryInfOriginalFileInformationA)(PSP_INF_INFORMATION, UINT, PSP_ALTPLATFORM_INFO, PSP_ORIGINAL_FILE_INFO_A);
50 static void append_str(char **str, const char *data)
56 static void create_inf_file(LPCSTR filename)
60 DWORD dwNumberOfBytesWritten;
61 HANDLE hf = CreateFile(filename, GENERIC_WRITE, 0, NULL,
62 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
64 append_str(&ptr, "[Version]\n");
65 append_str(&ptr, "Signature=\"$Chicago$\"\n");
66 append_str(&ptr, "AdvancedINF=2.5\n");
67 append_str(&ptr, "[DefaultInstall]\n");
68 append_str(&ptr, "RegisterOCXs=RegisterOCXsSection\n");
69 append_str(&ptr, "[RegisterOCXsSection]\n");
70 append_str(&ptr, "%%11%%\\ole32.dll\n");
72 WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL);
76 static void get_temp_filename(LPSTR path)
81 GetTempFileName(CURR_DIR, "set", 0, temp);
82 ptr = strrchr(temp, '\\');
84 lstrcpy(path, ptr + 1);
87 static BOOL file_exists(LPSTR path)
89 return GetFileAttributes(path) != INVALID_FILE_ATTRIBUTES;
92 static BOOL check_format(LPSTR path, LPSTR inf)
97 static const CHAR format[] = "\\INF\\oem";
99 GetWindowsDirectory(check, MAX_PATH);
100 lstrcat(check, format);
101 res = CompareString(LOCALE_SYSTEM_DEFAULT, NORM_IGNORECASE, check, -1, path, lstrlen(check)) == CSTR_EQUAL &&
102 path[lstrlen(check)] != '\\';
104 return (!inf) ? res : res && (inf == path + lstrlen(check) - 3);
107 static void test_original_file_name(LPCSTR original, LPCSTR dest)
110 PSP_INF_INFORMATION pspii;
111 SP_ORIGINAL_FILE_INFO spofi;
115 if (!pSetupQueryInfOriginalFileInformationA)
117 skip("SetupQueryInfOriginalFileInformationA is not available\n");
121 hinf = SetupOpenInfFileA(dest, NULL, INF_STYLE_WIN4, NULL);
122 ok(hinf != NULL, "SetupOpenInfFileA failed with error %d\n", GetLastError());
124 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, NULL, 0, &size);
125 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
127 pspii = HeapAlloc(GetProcessHeap(), 0, size);
129 res = SetupGetInfInformation(hinf, INFINFO_INF_SPEC_IS_HINF, pspii, size, NULL);
130 ok(res, "SetupGetInfInformation failed with error %d\n", GetLastError());
133 res = pSetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
134 ok(!res && GetLastError() == ERROR_INVALID_USER_BUFFER,
135 "SetupQueryInfOriginalFileInformationA should have failed with ERROR_INVALID_USER_BUFFER instead of %d\n", GetLastError());
137 spofi.cbSize = sizeof(spofi);
138 res = pSetupQueryInfOriginalFileInformationA(pspii, 0, NULL, &spofi);
139 ok(res, "SetupQueryInfOriginalFileInformationA failed with error %d\n", GetLastError());
140 ok(!spofi.OriginalCatalogName[0], "spofi.OriginalCatalogName should have been \"\" instead of \"%s\"\n", spofi.OriginalCatalogName);
142 ok(!strcmp(original, spofi.OriginalInfName), "spofi.OriginalInfName of %s didn't match real original name %s\n", spofi.OriginalInfName, original);
144 HeapFree(GetProcessHeap(), 0, pspii);
146 SetupCloseInfFile(hinf);
149 static void test_SetupCopyOEMInf(void)
151 CHAR toolong[MAX_PATH * 2];
152 CHAR path[MAX_PATH], dest[MAX_PATH];
153 CHAR tmpfile[MAX_PATH], dest_save[MAX_PATH];
158 /* try NULL SourceInfFileName */
159 SetLastError(0xdeadbeef);
160 res = pSetupCopyOEMInfA(NULL, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
161 ok(res == FALSE, "Expected FALSE, got %d\n", res);
162 ok(GetLastError() == ERROR_INVALID_PARAMETER,
163 "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
165 /* try empty SourceInfFileName */
166 SetLastError(0xdeadbeef);
167 res = pSetupCopyOEMInfA("", 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 GetLastError() == ERROR_BAD_PATHNAME, /* Win98 */
171 "Expected ERROR_FILE_NOT_FOUND or ERROR_BAD_PATHNAME, got %d\n", GetLastError());
173 /* try a relative nonexistent SourceInfFileName */
174 SetLastError(0xdeadbeef);
175 res = pSetupCopyOEMInfA("nonexistent", NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
176 ok(res == FALSE, "Expected FALSE, got %d\n", res);
177 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
178 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
180 /* try an absolute nonexistent SourceInfFileName */
181 lstrcpy(path, CURR_DIR);
182 lstrcat(path, "\\nonexistent");
183 SetLastError(0xdeadbeef);
184 res = pSetupCopyOEMInfA(path, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
185 ok(res == FALSE, "Expected FALSE, got %d\n", res);
186 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
187 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
189 /* try a long SourceInfFileName */
190 memset(toolong, 'a', MAX_PATH * 2);
191 toolong[MAX_PATH * 2 - 1] = '\0';
192 SetLastError(0xdeadbeef);
193 res = pSetupCopyOEMInfA(toolong, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
194 ok(res == FALSE, "Expected FALSE, got %d\n", res);
195 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
196 GetLastError() == ERROR_FILENAME_EXCED_RANGE, /* Win98 */
197 "Expected ERROR_FILE_NOT_FOUND or ERROR_FILENAME_EXCED_RANGE, got %d\n", GetLastError());
199 get_temp_filename(tmpfile);
200 create_inf_file(tmpfile);
202 /* try a relative SourceInfFileName */
203 SetLastError(0xdeadbeef);
204 res = pSetupCopyOEMInfA(tmpfile, NULL, 0, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
205 ok(res == FALSE, "Expected FALSE, got %d\n", res);
206 ok(GetLastError() == ERROR_FILE_NOT_FOUND ||
207 GetLastError() == ERROR_FILE_EXISTS, /* Win98 */
208 "Expected ERROR_FILE_NOT_FOUND or ERROR_FILE_EXISTS, got %d\n", GetLastError());
209 ok(file_exists(tmpfile), "Expected tmpfile to exist\n");
211 /* try SP_COPY_REPLACEONLY, dest does not exist */
212 SetLastError(0xdeadbeef);
213 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
214 ok(res == FALSE, "Expected FALSE, got %d\n", res);
215 ok(GetLastError() == ERROR_FILE_NOT_FOUND,
216 "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
217 ok(file_exists(tmpfile), "Expected source inf to exist\n");
219 /* try an absolute SourceInfFileName, without DestinationInfFileName */
220 lstrcpy(path, CURR_DIR);
222 lstrcat(path, tmpfile);
223 SetLastError(0xdeadbeef);
224 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, NULL, 0, NULL, NULL);
225 ok(res == TRUE, "Expected TRUE, got %d\n", res);
226 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
227 ok(file_exists(path), "Expected source inf to exist\n");
229 /* try SP_COPY_REPLACEONLY, dest exists */
230 SetLastError(0xdeadbeef);
231 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_REPLACEONLY, NULL, 0, NULL, NULL);
232 ok(res == TRUE, "Expected TRUE, got %d\n", res);
233 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
234 ok(file_exists(path), "Expected source inf to exist\n");
236 /* try SP_COPY_NOOVERWRITE */
237 SetLastError(0xdeadbeef);
238 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_NOOVERWRITE, NULL, 0, NULL, NULL);
239 ok(res == FALSE, "Expected FALSE, got %d\n", res);
240 ok(GetLastError() == ERROR_FILE_EXISTS,
241 "Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
243 /* get the DestinationInfFileName */
244 SetLastError(0xdeadbeef);
245 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, NULL, NULL);
246 ok(res == TRUE, "Expected TRUE, got %d\n", res);
247 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
248 ok(lstrlen(dest) != 0, "Expected a non-zero length string\n");
249 ok(file_exists(dest), "Expected destination inf to exist\n");
250 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
251 ok(file_exists(path), "Expected source inf to exist\n");
253 lstrcpy(dest_save, dest);
254 DeleteFile(dest_save);
256 /* get the DestinationInfFileName, DestinationInfFileNameSize is too small
257 * - inf is still copied
259 lstrcpy(dest, "aaa");
261 SetLastError(0xdeadbeef);
262 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, 5, &size, NULL);
263 ok(res == FALSE, "Expected FALSE, got %d\n", res);
264 ok(GetLastError() == ERROR_INSUFFICIENT_BUFFER,
265 "Expected ERROR_INSUFFICIENT_BUFFER, got %d\n", GetLastError());
266 ok(file_exists(path), "Expected source inf to exist\n");
267 ok(file_exists(dest_save), "Expected dest inf to exist\n");
268 ok(!lstrcmp(dest, "aaa"), "Expected dest to be unchanged\n");
269 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
271 /* get the DestinationInfFileName and DestinationInfFileNameSize */
272 SetLastError(0xdeadbeef);
273 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, NULL);
274 ok(res == TRUE, "Expected TRUE, got %d\n", res);
275 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
276 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
277 ok(file_exists(dest), "Expected destination inf to exist\n");
278 ok(check_format(dest, NULL), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
279 ok(file_exists(path), "Expected source inf to exist\n");
280 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
282 test_original_file_name(strrchr(path, '\\') + 1, dest);
284 /* get the DestinationInfFileName, DestinationInfFileNameSize, and DestinationInfFileNameComponent */
285 SetLastError(0xdeadbeef);
286 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, 0, dest, MAX_PATH, &size, &inf);
287 ok(res == TRUE, "Expected TRUE, got %d\n", res);
288 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
289 ok(lstrlen(dest) + 1 == size, "Expected sizes to match, got (%d, %d)\n", lstrlen(dest), size);
290 ok(file_exists(dest), "Expected destination inf to exist\n");
291 ok(check_format(dest, inf), "Expected %%windir%%\\inf\\OEMx.inf, got %s\n", dest);
292 ok(file_exists(path), "Expected source inf to exist\n");
293 ok(size == lstrlen(dest_save) + 1, "Expected size to be lstrlen(dest_save) + 1\n");
295 /* try SP_COPY_DELETESOURCE */
296 SetLastError(0xdeadbeef);
297 res = pSetupCopyOEMInfA(path, NULL, SPOST_NONE, SP_COPY_DELETESOURCE, NULL, 0, NULL, NULL);
298 ok(res == TRUE, "Expected TRUE, got %d\n", res);
299 ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
300 ok(!file_exists(path), "Expected source inf to not exist\n");
303 static void create_source_file(LPSTR filename, const BYTE *data, DWORD size)
308 handle = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
309 WriteFile(handle, data, size, &written, NULL);
313 static BOOL compare_file_data(LPSTR file, const BYTE *data, DWORD size)
320 handle = CreateFileA(file, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
321 buffer = HeapAlloc(GetProcessHeap(), 0, size);
324 ReadFile(handle, buffer, size, &read, NULL);
325 if (read == size && !memcmp(data, buffer, size)) ret = TRUE;
326 HeapFree(GetProcessHeap(), 0, buffer);
332 static const BYTE uncompressed[] = {
333 'u','n','c','o','m','p','r','e','s','s','e','d','\r','\n'
335 static const BYTE comp_lzx[] = {
336 0x53, 0x5a, 0x44, 0x44, 0x88, 0xf0, 0x27, 0x33, 0x41, 0x00, 0x0e, 0x00, 0x00, 0x00, 0xff, 0x00,
337 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x3f, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64
339 static const BYTE comp_zip[] = {
340 0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11,
341 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x04, 0x00, 0x15, 0x00, 0x77, 0x69,
342 0x6e, 0x65, 0x55, 0x54, 0x09, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46, 0xfd, 0x0d, 0x10, 0x46, 0x55,
343 0x78, 0x04, 0x00, 0xe8, 0x03, 0xe8, 0x03, 0x00, 0x00, 0x75, 0x6e, 0x63, 0x6f, 0x6d, 0x70, 0x72,
344 0x65, 0x73, 0x73, 0x65, 0x64, 0x50, 0x4b, 0x01, 0x02, 0x17, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00,
345 0x00, 0xbd, 0xae, 0x81, 0x36, 0x75, 0x11, 0x2c, 0x1b, 0x0e, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00,
346 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa4, 0x81, 0x00,
347 0x00, 0x00, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x55, 0x54, 0x05, 0x00, 0x03, 0xd6, 0x0d, 0x10, 0x46,
348 0x55, 0x78, 0x00, 0x00, 0x50, 0x4b, 0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
349 0x3f, 0x00, 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00
351 static const BYTE comp_cab_lzx[] = {
352 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
353 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
354 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03, 0x0f, 0x0e, 0x00, 0x00, 0x00,
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x36, 0x86, 0x72, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
356 0x00, 0x19, 0xd0, 0x1a, 0xe3, 0x22, 0x00, 0x0e, 0x00, 0x5b, 0x80, 0x80, 0x8d, 0x00, 0x30, 0xe0,
357 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x75, 0x6e, 0x63,
358 0x6f, 0x6d, 0x70, 0x72, 0x65, 0x73, 0x73, 0x65, 0x64, 0x0d, 0x0a
360 static const BYTE comp_cab_zip[] = {
361 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
362 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
363 0x00, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0e, 0x00, 0x00, 0x00,
364 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x36, 0x2f, 0xa5, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65,
365 0x00, 0x7c, 0x80, 0x26, 0x2b, 0x12, 0x00, 0x0e, 0x00, 0x43, 0x4b, 0x2b, 0xcd, 0x4b, 0xce, 0xcf,
366 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e, 0x4d, 0xe1, 0xe5, 0x02, 0x00
369 static void test_SetupGetFileCompressionInfo(void)
371 DWORD ret, source_size, target_size;
372 char source[MAX_PATH], temp[MAX_PATH], *name;
375 GetTempPathA(sizeof(temp), temp);
376 GetTempFileNameA(temp, "fci", 0, source);
378 create_source_file(source, uncompressed, sizeof(uncompressed));
380 ret = SetupGetFileCompressionInfoA(NULL, NULL, NULL, NULL, NULL);
381 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
383 ret = SetupGetFileCompressionInfoA(source, NULL, NULL, NULL, NULL);
384 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
386 ret = SetupGetFileCompressionInfoA(source, &name, NULL, NULL, NULL);
387 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
389 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, NULL, NULL);
390 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
392 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, NULL);
393 ok(ret == ERROR_INVALID_PARAMETER, "SetupGetFileCompressionInfo failed unexpectedly\n");
396 source_size = target_size = 0;
399 ret = SetupGetFileCompressionInfoA(source, &name, &source_size, &target_size, &type);
400 ok(!ret, "SetupGetFileCompressionInfo failed unexpectedly\n");
401 ok(name && !lstrcmpA(name, source), "got %s, expected %s\n", name, source);
402 ok(source_size == sizeof(uncompressed), "got %d\n", source_size);
403 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
404 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
410 static void test_SetupGetFileCompressionInfoEx(void)
413 DWORD required_len, source_size, target_size;
414 char source[MAX_PATH], temp[MAX_PATH], name[MAX_PATH];
417 GetTempPathA(sizeof(temp), temp);
418 GetTempFileNameA(temp, "doc", 0, source);
420 ret = pSetupGetFileCompressionInfoExA(NULL, NULL, 0, NULL, NULL, NULL, NULL);
421 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
423 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, NULL, NULL, NULL, NULL);
424 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
426 ret = pSetupGetFileCompressionInfoExA(source, NULL, 0, &required_len, NULL, NULL, NULL);
427 ok(!ret, "SetupGetFileCompressionInfoEx succeeded unexpectedly\n");
428 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
430 create_source_file(source, comp_lzx, sizeof(comp_lzx));
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_lzx), "got %d\n", source_size);
437 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
438 ok(type == FILE_COMPRESSION_WINLZA, "got %d, expected FILE_COMPRESSION_WINLZA\n", type);
441 create_source_file(source, comp_zip, sizeof(comp_zip));
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_zip), "got %d\n", source_size);
448 ok(target_size == sizeof(comp_zip), "got %d\n", target_size);
449 ok(type == FILE_COMPRESSION_NONE, "got %d, expected FILE_COMPRESSION_NONE\n", type);
452 create_source_file(source, comp_cab_lzx, sizeof(comp_cab_lzx));
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_lzx), "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);
463 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
465 ret = pSetupGetFileCompressionInfoExA(source, name, sizeof(name), &required_len, &source_size, &target_size, &type);
466 ok(ret, "SetupGetFileCompressionInfoEx failed unexpectedly: %d\n", ret);
467 ok(!lstrcmpA(name, source), "got %s, expected %s\n", name, source);
468 ok(required_len == lstrlenA(source) + 1, "got %d, expected %d\n", required_len, lstrlenA(source) + 1);
469 ok(source_size == sizeof(comp_cab_zip), "got %d\n", source_size);
470 ok(target_size == sizeof(uncompressed), "got %d\n", target_size);
471 ok(type == FILE_COMPRESSION_MSZIP, "got %d, expected FILE_COMPRESSION_MSZIP\n", type);
475 static void test_SetupDecompressOrCopyFile(void)
478 char source[MAX_PATH], target[MAX_PATH], temp[MAX_PATH], *p;
481 GetTempPathA(sizeof(temp), temp);
482 GetTempFileNameA(temp, "doc", 0, source);
483 GetTempFileNameA(temp, "doc", 0, target);
485 /* parameter tests */
487 create_source_file(source, uncompressed, sizeof(uncompressed));
489 ret = SetupDecompressOrCopyFileA(NULL, NULL, NULL);
490 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
492 type = FILE_COMPRESSION_NONE;
493 ret = SetupDecompressOrCopyFileA(NULL, target, &type);
494 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
496 ret = SetupDecompressOrCopyFileA(source, NULL, &type);
497 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
499 type = 5; /* try an invalid compression type */
500 ret = SetupDecompressOrCopyFileA(source, target, &type);
501 ok(ret == ERROR_INVALID_PARAMETER, "SetupDecompressOrCopyFile failed unexpectedly\n");
505 /* no compression tests */
507 ret = SetupDecompressOrCopyFileA(source, target, NULL);
508 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
509 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
511 /* try overwriting existing file */
512 ret = SetupDecompressOrCopyFileA(source, target, NULL);
513 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
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, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
522 type = FILE_COMPRESSION_WINLZA;
523 ret = SetupDecompressOrCopyFileA(source, target, &type);
524 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
525 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
528 /* lz compression tests */
530 create_source_file(source, comp_lzx, sizeof(comp_lzx));
532 ret = SetupDecompressOrCopyFileA(source, target, NULL);
533 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
536 /* zip compression tests */
538 create_source_file(source, comp_zip, sizeof(comp_zip));
540 ret = SetupDecompressOrCopyFileA(source, target, NULL);
541 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
542 ok(compare_file_data(target, comp_zip, sizeof(comp_zip)), "incorrect target file\n");
545 /* cabinet compression tests */
547 create_source_file(source, comp_cab_zip, sizeof(comp_cab_zip));
549 p = strrchr(target, '\\');
550 lstrcpyA(p + 1, "wine");
552 ret = SetupDecompressOrCopyFileA(source, target, NULL);
553 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
554 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
556 /* try overwriting existing file */
557 ret = SetupDecompressOrCopyFileA(source, target, NULL);
558 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
560 /* try zip compression */
561 type = FILE_COMPRESSION_MSZIP;
562 ret = SetupDecompressOrCopyFileA(source, target, &type);
563 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
564 ok(compare_file_data(target, uncompressed, sizeof(uncompressed)), "incorrect target file\n");
566 /* try no compression */
567 type = FILE_COMPRESSION_NONE;
568 ret = SetupDecompressOrCopyFileA(source, target, &type);
569 ok(!ret, "SetupDecompressOrCopyFile failed unexpectedly: %d\n", ret);
570 ok(compare_file_data(target, comp_cab_zip, sizeof(comp_cab_zip)), "incorrect target file\n");
578 HMODULE hsetupapi = GetModuleHandle("setupapi.dll");
580 pSetupGetFileCompressionInfoExA = (void*)GetProcAddress(hsetupapi, "SetupGetFileCompressionInfoExA");
581 pSetupCopyOEMInfA = (void*)GetProcAddress(hsetupapi, "SetupCopyOEMInfA");
582 pSetupQueryInfOriginalFileInformationA = (void*)GetProcAddress(hsetupapi, "SetupQueryInfOriginalFileInformationA");
584 GetCurrentDirectoryA(MAX_PATH, CURR_DIR);
586 if (pSetupCopyOEMInfA)
587 test_SetupCopyOEMInf();
589 skip("SetupCopyOEMInfA is not available\n");
591 test_SetupGetFileCompressionInfo();
593 if (pSetupGetFileCompressionInfoExA)
594 test_SetupGetFileCompressionInfoEx();
596 skip("SetupGetFileCompressionInfoExA is not available\n");
598 test_SetupDecompressOrCopyFile();