2 * Unit tests for SetupIterateCabinet
4 * Copyright 2007 Hans Leidekker
5 * Copyright 2010 Andrew Nguyen
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
30 #include "wine/test.h"
32 static const BYTE comp_cab_zip_multi
[] = {
33 0x4d, 0x53, 0x43, 0x46, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
34 0x2c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x01, 0x01, 0x00, 0x03, 0x00, 0x00, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x71, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x00,
36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd1, 0x38, 0xf0, 0x48, 0x20, 0x00, 0x74, 0x72, 0x69, 0x73,
37 0x74, 0x72, 0x61, 0x6d, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd1,
38 0x38, 0xf0, 0x48, 0x20, 0x00, 0x77, 0x69, 0x6e, 0x65, 0x00, 0x08, 0x00, 0x00, 0x00, 0x18, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0xd1, 0x38, 0xf0, 0x48, 0x20, 0x00, 0x73, 0x68, 0x61, 0x6e, 0x64, 0x79,
40 0x00, 0x67, 0x2c, 0x03, 0x85, 0x23, 0x00, 0x20, 0x00, 0x43, 0x4b, 0xcb, 0x49, 0x2c, 0x2d, 0x4a,
41 0xcd, 0x4b, 0x4e, 0xe5, 0xe5, 0x2a, 0xcd, 0x4b, 0xce, 0xcf, 0x2d, 0x28, 0x4a, 0x2d, 0x2e, 0x4e,
42 0x4d, 0xe1, 0xe5, 0x2a, 0x2e, 0x49, 0x2d, 0xca, 0x03, 0x8a, 0x02, 0x00
45 static const WCHAR docW
[] = {'d','o','c',0};
47 static void create_source_fileA(LPSTR filename
, const BYTE
*data
, DWORD size
)
52 handle
= CreateFileA(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
53 FILE_ATTRIBUTE_NORMAL
, NULL
);
54 WriteFile(handle
, data
, size
, &written
, NULL
);
58 static void create_source_fileW(LPWSTR filename
, const BYTE
*data
, DWORD size
)
63 handle
= CreateFileW(filename
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
64 FILE_ATTRIBUTE_NORMAL
, NULL
);
65 WriteFile(handle
, data
, size
, &written
, NULL
);
69 static UINT CALLBACK
dummy_callbackA(PVOID Context
, UINT Notification
,
70 UINT_PTR Param1
, UINT_PTR Param2
)
72 ok(0, "Received unexpected notification (%p, %u, %lu, %lu)\n", Context
,
73 Notification
, Param1
, Param2
);
77 static UINT CALLBACK
dummy_callbackW(PVOID Context
, UINT Notification
,
78 UINT_PTR Param1
, UINT_PTR Param2
)
80 ok(0, "Received unexpected notification (%p, %u, %lu, %lu)\n", Context
,
81 Notification
, Param1
, Param2
);
85 static void test_invalid_parametersA(void)
88 char source
[MAX_PATH
], temp
[MAX_PATH
];
94 PSP_FILE_CALLBACK_A MsgHandler
;
95 DWORD expected_lasterror
;
97 } invalid_parameters
[] =
99 {NULL
, NULL
, ERROR_INVALID_PARAMETER
},
100 {NULL
, dummy_callbackA
, ERROR_INVALID_PARAMETER
},
101 {"c:\\nonexistent.cab", NULL
, ERROR_FILE_NOT_FOUND
},
102 {"c:\\nonexistent.cab", dummy_callbackA
, ERROR_FILE_NOT_FOUND
},
103 {source
, NULL
, ERROR_INVALID_DATA
, 1},
104 {source
, dummy_callbackA
, ERROR_INVALID_DATA
, 1},
107 GetTempPathA(sizeof(temp
), temp
);
108 GetTempFileNameA(temp
, "doc", 0, source
);
110 create_source_fileA(source
, NULL
, 0);
112 for (i
= 0; i
< ARRAY_SIZE(invalid_parameters
); i
++)
114 SetLastError(0xdeadbeef);
115 ret
= SetupIterateCabinetA(invalid_parameters
[i
].CabinetFile
, 0,
116 invalid_parameters
[i
].MsgHandler
, NULL
);
117 ok(!ret
, "[%d] Expected SetupIterateCabinetA to return 0, got %d\n", i
, ret
);
118 todo_wine_if (invalid_parameters
[i
].todo_lasterror
)
119 ok(GetLastError() == invalid_parameters
[i
].expected_lasterror
,
120 "[%d] Expected GetLastError() to return %u, got %u\n",
121 i
, invalid_parameters
[i
].expected_lasterror
, GetLastError());
124 SetLastError(0xdeadbeef);
125 ret
= SetupIterateCabinetA("", 0, NULL
, NULL
);
126 ok(!ret
, "Expected SetupIterateCabinetA to return 0, got %d\n", ret
);
127 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
128 GetLastError() == ERROR_FILE_NOT_FOUND
, /* Win9x/NT4/Win2k */
129 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
132 SetLastError(0xdeadbeef);
133 ret
= SetupIterateCabinetA("", 0, dummy_callbackA
, NULL
);
134 ok(!ret
, "Expected SetupIterateCabinetA to return 0, got %d\n", ret
);
135 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
136 GetLastError() == ERROR_FILE_NOT_FOUND
, /* Win9x/NT4/Win2k */
137 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
143 static void test_invalid_parametersW(void)
145 static const WCHAR nonexistentW
[] = {'c',':','\\','n','o','n','e','x','i','s','t','e','n','t','.','c','a','b',0};
146 static const WCHAR emptyW
[] = {0};
149 WCHAR source
[MAX_PATH
], temp
[MAX_PATH
];
155 PSP_FILE_CALLBACK_W MsgHandler
;
156 DWORD expected_lasterror
;
158 } invalid_parameters
[] =
160 {nonexistentW
, NULL
, ERROR_FILE_NOT_FOUND
},
161 {nonexistentW
, dummy_callbackW
, ERROR_FILE_NOT_FOUND
},
162 {source
, NULL
, ERROR_INVALID_DATA
, 1},
163 {source
, dummy_callbackW
, ERROR_INVALID_DATA
, 1},
166 ret
= SetupIterateCabinetW(NULL
, 0, NULL
, NULL
);
167 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
169 win_skip("SetupIterateCabinetW is not available\n");
173 GetTempPathW(ARRAY_SIZE(temp
), temp
);
174 GetTempFileNameW(temp
, docW
, 0, source
);
176 create_source_fileW(source
, NULL
, 0);
178 for (i
= 0; i
< ARRAY_SIZE(invalid_parameters
); i
++)
180 SetLastError(0xdeadbeef);
181 ret
= SetupIterateCabinetW(invalid_parameters
[i
].CabinetFile
, 0,
182 invalid_parameters
[i
].MsgHandler
, NULL
);
183 ok(!ret
, "[%d] Expected SetupIterateCabinetW to return 0, got %d\n", i
, ret
);
184 todo_wine_if (invalid_parameters
[i
].todo_lasterror
)
185 ok(GetLastError() == invalid_parameters
[i
].expected_lasterror
,
186 "[%d] Expected GetLastError() to return %u, got %u\n",
187 i
, invalid_parameters
[i
].expected_lasterror
, GetLastError());
190 SetLastError(0xdeadbeef);
191 ret
= SetupIterateCabinetW(NULL
, 0, NULL
, NULL
);
192 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
193 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
194 GetLastError() == ERROR_NOT_ENOUGH_MEMORY
, /* Vista/Win2k8 */
195 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
198 SetLastError(0xdeadbeef);
199 ret
= SetupIterateCabinetW(NULL
, 0, dummy_callbackW
, NULL
);
200 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
201 ok(GetLastError() == ERROR_INVALID_PARAMETER
||
202 GetLastError() == ERROR_NOT_ENOUGH_MEMORY
, /* Vista/Win2k8 */
203 "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n",
206 SetLastError(0xdeadbeef);
207 ret
= SetupIterateCabinetW(emptyW
, 0, NULL
, NULL
);
208 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
209 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
210 GetLastError() == ERROR_FILE_NOT_FOUND
, /* NT4/Win2k */
211 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
214 SetLastError(0xdeadbeef);
215 ret
= SetupIterateCabinetW(emptyW
, 0, dummy_callbackW
, NULL
);
216 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
217 ok(GetLastError() == ERROR_NOT_ENOUGH_MEMORY
||
218 GetLastError() == ERROR_FILE_NOT_FOUND
, /* NT4/Win2k */
219 "Expected GetLastError() to return ERROR_NOT_ENOUGH_MEMORY, got %u\n",
225 static UINT CALLBACK
crash_callbackA(PVOID Context
, UINT Notification
,
226 UINT_PTR Param1
, UINT_PTR Param2
)
228 *(volatile char*)0 = 2;
232 static UINT CALLBACK
crash_callbackW(PVOID Context
, UINT Notification
,
233 UINT_PTR Param1
, UINT_PTR Param2
)
235 *(volatile char*)0 = 2;
239 static void test_invalid_callbackA(void)
242 char source
[MAX_PATH
], temp
[MAX_PATH
];
244 GetTempPathA(sizeof(temp
), temp
);
245 GetTempFileNameA(temp
, "doc", 0, source
);
247 create_source_fileA(source
, comp_cab_zip_multi
, sizeof(comp_cab_zip_multi
));
249 SetLastError(0xdeadbeef);
250 ret
= SetupIterateCabinetA(source
, 0, NULL
, NULL
);
251 ok(!ret
, "Expected SetupIterateCabinetA to return 0, got %d\n", ret
);
252 ok(GetLastError() == ERROR_INVALID_DATA
,
253 "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
256 SetLastError(0xdeadbeef);
257 ret
= SetupIterateCabinetA(source
, 0, crash_callbackA
, NULL
);
258 ok(!ret
, "Expected SetupIterateCabinetA to return 0, got %d\n", ret
);
259 ok(GetLastError() == ERROR_INVALID_DATA
,
260 "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
266 static void test_invalid_callbackW(void)
269 WCHAR source
[MAX_PATH
], temp
[MAX_PATH
];
271 ret
= SetupIterateCabinetW(NULL
, 0, NULL
, NULL
);
272 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
274 win_skip("SetupIterateCabinetW is not available\n");
278 GetTempPathW(ARRAY_SIZE(temp
), temp
);
279 GetTempFileNameW(temp
, docW
, 0, source
);
281 create_source_fileW(source
, comp_cab_zip_multi
, sizeof(comp_cab_zip_multi
));
283 SetLastError(0xdeadbeef);
284 ret
= SetupIterateCabinetW(source
, 0, NULL
, NULL
);
285 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
286 ok(GetLastError() == ERROR_INVALID_DATA
,
287 "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
290 SetLastError(0xdeadbeef);
291 ret
= SetupIterateCabinetW(source
, 0, crash_callbackW
, NULL
);
292 ok(!ret
, "Expected SetupIterateCabinetW to return 0, got %d\n", ret
);
293 ok(GetLastError() == ERROR_INVALID_DATA
,
294 "Expected GetLastError() to return ERROR_INVALID_DATA, got %u\n",
300 static const char *expected_files
[] = {"tristram", "wine", "shandy"};
309 static UINT CALLBACK
simple_callbackA(PVOID Context
, UINT Notification
,
310 UINT_PTR Param1
, UINT_PTR Param2
)
313 struct contextA
*ctx
= Context
;
315 switch (Notification
)
317 case SPFILENOTIFY_CABINETINFO
:
319 CABINET_INFO_A
*info
= (CABINET_INFO_A
*)Param1
;
321 ok(!strcmp(info
->CabinetFile
, ""),
322 "Expected empty CabinetFile, got \"%s\"\n", info
->CabinetFile
);
327 case SPFILENOTIFY_FILEINCABINET
:
329 FILE_IN_CABINET_INFO_A
*info
= (FILE_IN_CABINET_INFO_A
*)Param1
;
330 const char *cabinet_file
= (const char *)Param2
;
334 if (index
< ARRAY_SIZE(expected_files
))
336 ok(!strcmp(expected_files
[index
], info
->NameInCabinet
),
337 "[%d] Expected file \"%s\", got \"%s\"\n",
338 index
, expected_files
[index
], info
->NameInCabinet
);
339 ok(!strcmp(ctx
->cabinet
, cabinet_file
),
340 "[%d] Expected cabinet \"%s\", got \"%s\"\n",
341 index
, ctx
->cabinet
, cabinet_file
);
343 strcpy(info
->FullTargetName
, ctx
->target
);
348 ok(0, "Unexpectedly enumerated more than number of files in cabinet, index = %d\n", index
);
352 case SPFILENOTIFY_FILEEXTRACTED
:
354 FILEPATHS_A
*info
= (FILEPATHS_A
*)Param1
;
356 ok(!strcmp(ctx
->cabinet
, info
->Source
),
357 "[%d] Expected cabinet \"%s\", got \"%s\"\n",
358 index
, ctx
->cabinet
, info
->Source
);
359 ok(!strcmp(ctx
->target
, info
->Target
),
360 "[%d] Expected target \"%s\", got \"%s\"\n",
361 index
, ctx
->target
, info
->Target
);
362 ok(info
->Win32Error
== 0,
363 "[%d] Expected Win32Error 0, got %u\n",
364 index
, info
->Win32Error
);
374 static void test_simple_enumerationA(void)
377 char source
[MAX_PATH
], temp
[MAX_PATH
];
378 char target
[MAX_PATH
];
381 GetTempPathA(sizeof(temp
), temp
);
382 GetTempFileNameA(temp
, "doc", 0, source
);
383 GetTempFileNameA(temp
, "doc", 0, target
);
385 create_source_fileA(source
, comp_cab_zip_multi
, sizeof(comp_cab_zip_multi
));
388 ctx
.cabinet
= source
;
390 ret
= SetupIterateCabinetA(source
, 0, simple_callbackA
, &ctx
);
391 ok(ret
== 1, "Expected SetupIterateCabinetA to return 1, got %d\n", ret
);
392 ok(ctx
.count
== ARRAY_SIZE(expected_files
), "Unexpectedly enumerated %d files\n", ctx
.count
);
398 static const WCHAR tristramW
[] = {'t','r','i','s','t','r','a','m',0};
399 static const WCHAR wineW
[] = {'w','i','n','e',0};
400 static const WCHAR shandyW
[] = {'s','h','a','n','d','y',0};
401 static const WCHAR
*expected_filesW
[] = {tristramW
, wineW
, shandyW
};
406 const WCHAR
*cabinet
;
410 static UINT CALLBACK
simple_callbackW(PVOID Context
, UINT Notification
,
411 UINT_PTR Param1
, UINT_PTR Param2
)
413 static const WCHAR emptyW
[] = {0};
415 struct contextW
*ctx
= Context
;
417 switch (Notification
)
419 case SPFILENOTIFY_CABINETINFO
:
421 CABINET_INFO_W
*info
= (CABINET_INFO_W
*)Param1
;
423 ok(!lstrcmpW(info
->CabinetFile
, emptyW
),
424 "Expected empty CabinetFile, got %s\n", wine_dbgstr_w(info
->CabinetFile
));
429 case SPFILENOTIFY_FILEINCABINET
:
431 FILE_IN_CABINET_INFO_W
*info
= (FILE_IN_CABINET_INFO_W
*)Param1
;
432 const WCHAR
*cabinet_file
= (const WCHAR
*)Param2
;
436 if (index
< ARRAY_SIZE(expected_filesW
))
438 ok(!lstrcmpW(expected_filesW
[index
], info
->NameInCabinet
),
439 "[%d] Expected file %s, got %s\n",
440 index
, wine_dbgstr_w(expected_filesW
[index
]), wine_dbgstr_w(info
->NameInCabinet
));
441 ok(!lstrcmpW(ctx
->cabinet
, cabinet_file
),
442 "[%d] Expected cabinet %s, got %s\n",
443 index
, wine_dbgstr_w(ctx
->cabinet
), wine_dbgstr_w(cabinet_file
));
445 lstrcpyW(info
->FullTargetName
, ctx
->target
);
450 ok(0, "Unexpectedly enumerated more than number of files in cabinet, index = %d\n", index
);
454 case SPFILENOTIFY_FILEEXTRACTED
:
456 FILEPATHS_W
*info
= (FILEPATHS_W
*)Param1
;
458 ok(!lstrcmpW(ctx
->cabinet
, info
->Source
),
459 "[%d] Expected cabinet %s, got %s\n",
460 index
, wine_dbgstr_w(ctx
->cabinet
), wine_dbgstr_w(info
->Source
));
461 ok(!lstrcmpW(ctx
->target
, info
->Target
),
462 "[%d] Expected target %s, got %s\n",
463 index
, wine_dbgstr_w(ctx
->target
), wine_dbgstr_w(info
->Target
));
464 ok(info
->Win32Error
== 0,
465 "[%d] Expected Win32Error 0, got %u\n",
466 index
, info
->Win32Error
);
476 static void test_simple_enumerationW(void)
479 WCHAR source
[MAX_PATH
], temp
[MAX_PATH
];
480 WCHAR target
[MAX_PATH
];
483 ret
= SetupIterateCabinetW(NULL
, 0, NULL
, NULL
);
484 if (!ret
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
486 win_skip("SetupIterateCabinetW is not available\n");
490 GetTempPathW(ARRAY_SIZE(temp
), temp
);
491 GetTempFileNameW(temp
, docW
, 0, source
);
492 GetTempFileNameW(temp
, docW
, 0, target
);
494 create_source_fileW(source
, comp_cab_zip_multi
, sizeof(comp_cab_zip_multi
));
497 ctx
.cabinet
= source
;
499 ret
= SetupIterateCabinetW(source
, 0, simple_callbackW
, &ctx
);
500 ok(ret
== 1, "Expected SetupIterateCabinetW to return 1, got %d\n", ret
);
501 ok(ctx
.count
== ARRAY_SIZE(expected_files
), "Unexpectedly enumerated %d files\n", ctx
.count
);
509 test_invalid_parametersA();
510 test_invalid_parametersW();
512 /* Tests crash on NT4/Win9x/Win2k and Wine. */
515 test_invalid_callbackA();
516 test_invalid_callbackW();
519 test_simple_enumerationA();
520 test_simple_enumerationW();