2 * Unit tests for cabinet.dll extract functions
4 * Copyright (C) 2006 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/test.h"
27 /* make the max size large so there is only one cab file */
28 #define MEDIA_SIZE 999999999
29 #define FOLDER_THRESHOLD 900000
31 /* The following definitions were copied from dlls/cabinet/cabinet.h
32 * because they are undocumented in windows.
35 /* SESSION Operation */
36 #define EXTRACT_FILLFILELIST 0x00000001
37 #define EXTRACT_EXTRACTFILES 0x00000002
41 struct FILELIST
*next
;
48 struct FILELIST
*FileList
;
51 CHAR Destination
[MAX_PATH
];
52 CHAR CurrentFile
[MAX_PATH
];
53 CHAR Reserved
[MAX_PATH
];
54 struct FILELIST
*FilterList
;
57 /* function pointers */
59 static HRESULT (WINAPI
*pExtract
)(SESSION
*, LPCSTR
);
61 CHAR CURR_DIR
[MAX_PATH
];
63 static void init_function_pointers(void)
65 hCabinet
= GetModuleHandleA("cabinet.dll");
67 pExtract
= (void *)GetProcAddress(hCabinet
, "Extract");
70 /* creates a file with the specified name for tests */
71 static void createTestFile(const CHAR
*name
)
76 file
= CreateFileA(name
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, NULL
);
77 ok(file
!= INVALID_HANDLE_VALUE
, "Failure to open file %s\n", name
);
78 WriteFile(file
, name
, strlen(name
), &written
, NULL
);
79 WriteFile(file
, "\n", strlen("\n"), &written
, NULL
);
83 static void create_test_files(void)
87 GetCurrentDirectoryA(MAX_PATH
, CURR_DIR
);
88 len
= lstrlenA(CURR_DIR
);
90 if(len
&& (CURR_DIR
[len
-1] == '\\'))
93 createTestFile("a.txt");
94 createTestFile("b.txt");
95 CreateDirectoryA("testdir", NULL
);
96 createTestFile("testdir\\c.txt");
97 createTestFile("testdir\\d.txt");
98 CreateDirectoryA("dest", NULL
);
101 static void delete_test_files(void)
103 DeleteFileA("a.txt");
104 DeleteFileA("b.txt");
105 DeleteFileA("testdir\\c.txt");
106 DeleteFileA("testdir\\d.txt");
107 RemoveDirectoryA("testdir");
109 DeleteFileA("extract.cab");
112 /* the FCI callbacks */
114 static void * CDECL
mem_alloc(ULONG cb
)
116 return HeapAlloc(GetProcessHeap(), 0, cb
);
119 static void CDECL
mem_free(void *memory
)
121 HeapFree(GetProcessHeap(), 0, memory
);
124 static BOOL CDECL
get_next_cabinet(PCCAB pccab
, ULONG cbPrevCab
, void *pv
)
129 static LONG CDECL
progress(UINT typeStatus
, ULONG cb1
, ULONG cb2
, void *pv
)
134 static int CDECL
file_placed(PCCAB pccab
, char *pszFile
, LONG cbFile
,
135 BOOL fContinuation
, void *pv
)
140 static INT_PTR CDECL
fci_open(char *pszFile
, int oflag
, int pmode
, int *err
, void *pv
)
144 DWORD dwShareMode
= 0;
145 DWORD dwCreateDisposition
= OPEN_EXISTING
;
147 dwAccess
= GENERIC_READ
| GENERIC_WRITE
;
148 /* FILE_SHARE_DELETE is not supported by Windows Me/98/95 */
149 dwShareMode
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
151 if (GetFileAttributesA(pszFile
) != INVALID_FILE_ATTRIBUTES
)
152 dwCreateDisposition
= OPEN_EXISTING
;
154 dwCreateDisposition
= CREATE_NEW
;
156 handle
= CreateFileA(pszFile
, dwAccess
, dwShareMode
, NULL
,
157 dwCreateDisposition
, 0, NULL
);
159 ok(handle
!= INVALID_HANDLE_VALUE
, "Failed to CreateFile %s\n", pszFile
);
161 return (INT_PTR
)handle
;
164 static UINT CDECL
fci_read(INT_PTR hf
, void *memory
, UINT cb
, int *err
, void *pv
)
166 HANDLE handle
= (HANDLE
)hf
;
170 res
= ReadFile(handle
, memory
, cb
, &dwRead
, NULL
);
171 ok(res
, "Failed to ReadFile\n");
176 static UINT CDECL
fci_write(INT_PTR hf
, void *memory
, UINT cb
, int *err
, void *pv
)
178 HANDLE handle
= (HANDLE
)hf
;
182 res
= WriteFile(handle
, memory
, cb
, &dwWritten
, NULL
);
183 ok(res
, "Failed to WriteFile\n");
188 static int CDECL
fci_close(INT_PTR hf
, int *err
, void *pv
)
190 HANDLE handle
= (HANDLE
)hf
;
191 ok(CloseHandle(handle
), "Failed to CloseHandle\n");
196 static LONG CDECL
fci_seek(INT_PTR hf
, LONG dist
, int seektype
, int *err
, void *pv
)
198 HANDLE handle
= (HANDLE
)hf
;
201 ret
= SetFilePointer(handle
, dist
, NULL
, seektype
);
202 ok(ret
!= INVALID_SET_FILE_POINTER
, "Failed to SetFilePointer\n");
207 static int CDECL
fci_delete(char *pszFile
, int *err
, void *pv
)
209 BOOL ret
= DeleteFileA(pszFile
);
210 ok(ret
, "Failed to DeleteFile %s\n", pszFile
);
215 static BOOL CDECL
get_temp_file(char *pszTempName
, int cbTempName
, void *pv
)
219 tempname
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
);
220 GetTempFileNameA(".", "xx", 0, tempname
);
222 if (tempname
&& (strlen(tempname
) < (unsigned)cbTempName
))
224 lstrcpyA(pszTempName
, tempname
);
225 HeapFree(GetProcessHeap(), 0, tempname
);
229 HeapFree(GetProcessHeap(), 0, tempname
);
234 static INT_PTR CDECL
get_open_info(char *pszName
, USHORT
*pdate
, USHORT
*ptime
,
235 USHORT
*pattribs
, int *err
, void *pv
)
237 BY_HANDLE_FILE_INFORMATION finfo
;
243 handle
= CreateFile(pszName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
244 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_SEQUENTIAL_SCAN
, NULL
);
246 ok(handle
!= INVALID_HANDLE_VALUE
, "Failed to CreateFile %s\n", pszName
);
248 res
= GetFileInformationByHandle(handle
, &finfo
);
249 ok(res
, "Expected GetFileInformationByHandle to succeed\n");
251 FileTimeToLocalFileTime(&finfo
.ftLastWriteTime
, &filetime
);
252 FileTimeToDosDateTime(&filetime
, pdate
, ptime
);
254 attrs
= GetFileAttributes(pszName
);
255 ok(attrs
!= INVALID_FILE_ATTRIBUTES
, "Failed to GetFileAttributes\n");
257 return (INT_PTR
)handle
;
260 static void add_file(HFCI hfci
, char *file
)
265 lstrcpyA(path
, CURR_DIR
);
266 lstrcatA(path
, "\\");
267 lstrcatA(path
, file
);
269 res
= FCIAddFile(hfci
, path
, file
, FALSE
, get_next_cabinet
, progress
,
270 get_open_info
, tcompTYPE_MSZIP
);
271 ok(res
, "Expected FCIAddFile to succeed\n");
274 static void set_cab_parameters(PCCAB pCabParams
)
276 ZeroMemory(pCabParams
, sizeof(CCAB
));
278 pCabParams
->cb
= MEDIA_SIZE
;
279 pCabParams
->cbFolderThresh
= FOLDER_THRESHOLD
;
280 pCabParams
->setID
= 0xbeef;
281 lstrcpyA(pCabParams
->szCabPath
, CURR_DIR
);
282 lstrcatA(pCabParams
->szCabPath
, "\\");
283 lstrcpyA(pCabParams
->szCab
, "extract.cab");
286 static void create_cab_file(void)
291 static CHAR a_txt
[] = "a.txt",
293 testdir_c_txt
[] = "testdir\\c.txt",
294 testdir_d_txt
[] = "testdir\\d.txt";
297 set_cab_parameters(&cabParams
);
299 hfci
= FCICreate(&erf
, file_placed
, mem_alloc
, mem_free
, fci_open
,
300 fci_read
, fci_write
, fci_close
, fci_seek
, fci_delete
,
301 get_temp_file
, &cabParams
, NULL
);
303 ok(hfci
!= NULL
, "Failed to create an FCI context\n");
305 add_file(hfci
, a_txt
);
306 add_file(hfci
, b_txt
);
307 add_file(hfci
, testdir_c_txt
);
308 add_file(hfci
, testdir_d_txt
);
310 res
= FCIFlushCabinet(hfci
, FALSE
, get_next_cabinet
, progress
);
311 ok(res
, "Failed to flush the cabinet\n");
313 res
= FCIDestroy(hfci
);
314 ok(res
, "Failed to destroy the cabinet\n");
317 static BOOL
check_list(struct FILELIST
**node
, const char *filename
, BOOL do_extract
)
322 if (lstrcmpA((*node
)->FileName
, filename
))
325 if ((*node
)->DoExtract
!= do_extract
)
328 *node
= (*node
)->next
;
332 static void test_Extract(void)
336 struct FILELIST
*node
;
338 /* native windows crashes if
339 * - invalid parameters are sent in
340 * - you call EXTRACT_EXTRACTFILES without calling
341 * EXTRACT_FILLFILELIST first or at the same time
344 /* try to extract all files */
345 ZeroMemory(&session
, sizeof(SESSION
));
346 lstrcpyA(session
.Destination
, "dest");
347 session
.Operation
= EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
;
348 res
= pExtract(&session
, "extract.cab");
349 node
= session
.FileList
;
350 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
351 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
352 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
353 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
354 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
355 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
356 ok(session
.FileCount
== 4, "Expected 4, got %d\n", session
.FileCount
);
357 ok(session
.Operation
== (EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
),
358 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session
.Operation
);
359 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
360 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
361 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
362 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
363 ok(!session
.FilterList
, "Expected empty filter list\n");
364 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
365 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
366 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
367 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
368 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
369 ok(check_list(&node
, "testdir\\d.txt", FALSE
), "list entry wrong\n");
370 ok(check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
371 ok(check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
372 ok(check_list(&node
, "a.txt", FALSE
), "list entry wrong\n");
374 /* try fill file list operation */
375 ZeroMemory(&session
, sizeof(SESSION
));
376 lstrcpyA(session
.Destination
, "dest");
377 session
.Operation
= EXTRACT_FILLFILELIST
;
378 res
= pExtract(&session
, "extract.cab");
379 node
= session
.FileList
;
380 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
381 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
382 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
383 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
384 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
385 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
386 ok(session
.FileCount
== 4, "Expected 4, got %d\n", session
.FileCount
);
387 ok(session
.Operation
== EXTRACT_FILLFILELIST
,
388 "Expected EXTRACT_FILLFILELIST, got %d\n", session
.Operation
);
389 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
390 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
391 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
392 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
393 ok(!session
.FilterList
, "Expected empty filter list\n");
394 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
395 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
396 ok(check_list(&node
, "testdir\\d.txt", TRUE
), "list entry wrong\n");
397 ok(check_list(&node
, "testdir\\c.txt", TRUE
), "list entry wrong\n");
398 ok(check_list(&node
, "b.txt", TRUE
), "list entry wrong\n");
399 ok(check_list(&node
, "a.txt", TRUE
), "list entry wrong\n");
401 /* try extract files operation once file list is filled */
402 session
.Operation
= EXTRACT_EXTRACTFILES
;
403 res
= pExtract(&session
, "extract.cab");
404 node
= session
.FileList
;
405 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
406 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
407 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
408 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
409 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
410 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
411 ok(session
.FileCount
== 4, "Expected 4, got %d\n", session
.FileCount
);
412 ok(session
.Operation
== EXTRACT_EXTRACTFILES
,
413 "Expected EXTRACT_EXTRACTFILES, got %d\n", session
.Operation
);
414 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
415 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
416 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
417 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
418 ok(!session
.FilterList
, "Expected empty filter list\n");
419 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
420 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
421 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
422 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
423 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
424 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
425 ok(check_list(&node
, "testdir\\d.txt", FALSE
), "list entry wrong\n");
426 ok(check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
427 ok(check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
428 ok(check_list(&node
, "a.txt", FALSE
), "list entry wrong\n");
430 /* Extract does not extract files if the dest dir does not exist */
431 res
= pExtract(&session
, "extract.cab");
432 node
= session
.FileList
;
433 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
434 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
435 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
436 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
437 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
438 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
439 ok(session
.FileCount
== 4, "Expected 4, got %d\n", session
.FileCount
);
440 ok(session
.Operation
== EXTRACT_EXTRACTFILES
,
441 "Expected EXTRACT_EXTRACTFILES, got %d\n", session
.Operation
);
442 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
443 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
444 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
445 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
446 ok(!session
.FilterList
, "Expected empty filter list\n");
447 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
448 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
449 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
450 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
451 ok(check_list(&node
, "testdir\\d.txt", FALSE
), "list entry wrong\n");
452 ok(check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
453 ok(check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
454 ok(check_list(&node
, "a.txt", FALSE
), "list entry wrong\n");
456 /* remove two of the files in the list */
457 session
.FileList
->next
= session
.FileList
->next
->next
;
458 session
.FileList
->next
->next
= NULL
;
459 session
.FilterList
= NULL
;
460 CreateDirectoryA("dest", NULL
);
461 res
= pExtract(&session
, "extract.cab");
462 node
= session
.FileList
;
463 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
464 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
465 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
466 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
467 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
468 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
469 ok(session
.FileCount
== 4, "Expected 4, got %d\n", session
.FileCount
);
470 ok(session
.Operation
== EXTRACT_EXTRACTFILES
,
471 "Expected EXTRACT_EXTRACTFILES, got %d\n", session
.Operation
);
472 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
473 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
474 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
475 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
476 ok(!session
.FilterList
, "Expected empty filter list\n");
477 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
478 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
479 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
480 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
481 ok(check_list(&node
, "testdir\\d.txt", FALSE
), "list entry wrong\n");
482 ok(!check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
483 ok(check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
484 ok(!check_list(&node
, "a.txt", FALSE
), "list entry wrong\n");
486 session
.Operation
= EXTRACT_FILLFILELIST
;
487 session
.FileList
= NULL
;
488 res
= pExtract(&session
, "extract.cab");
489 node
= session
.FileList
;
490 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
491 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
492 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
493 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
494 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
495 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
496 ok(session
.FileCount
== 8, "Expected 8, got %d\n", session
.FileCount
);
497 ok(session
.Operation
== EXTRACT_FILLFILELIST
,
498 "Expected EXTRACT_FILLFILELIST, got %d\n", session
.Operation
);
499 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
500 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
501 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
502 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
503 ok(!session
.FilterList
, "Expected empty filter list\n");
504 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
505 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
506 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
507 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
508 ok(check_list(&node
, "testdir\\d.txt", TRUE
), "list entry wrong\n");
509 ok(!check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
510 ok(!check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
511 ok(!check_list(&node
, "a.txt", FALSE
), "list entry wrong\n");
513 session
.Operation
= 0;
514 res
= pExtract(&session
, "extract.cab");
515 node
= session
.FileList
;
516 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
517 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
518 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
519 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
520 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
521 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
522 ok(session
.FileCount
== 8, "Expected 8, got %d\n", session
.FileCount
);
523 ok(session
.Operation
== 0, "Expected 0, got %d\n", session
.Operation
);
524 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
525 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
526 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
527 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
528 ok(!session
.FilterList
, "Expected empty filter list\n");
529 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
530 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
531 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
532 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
533 ok(check_list(&node
, "testdir\\d.txt", TRUE
), "list entry wrong\n");
534 ok(check_list(&node
, "testdir\\c.txt", TRUE
), "list entry wrong\n");
535 ok(check_list(&node
, "b.txt", TRUE
), "list entry wrong\n");
536 ok(check_list(&node
, "a.txt", TRUE
), "list entry wrong\n");
538 session
.Operation
= 0;
539 session
.FilterList
= session
.FileList
;
540 res
= pExtract(&session
, "extract.cab");
541 node
= session
.FileList
;
542 ok(res
== S_OK
, "Expected S_OK, got %d\n", res
);
543 ok(session
.FileSize
== 40, "Expected 40, got %d\n", session
.FileSize
);
544 ok(session
.Error
.erfOper
== FDIERROR_NONE
,
545 "Expected FDIERROR_NONE, got %d\n", session
.Error
.erfOper
);
546 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
547 ok(session
.Error
.fError
== FALSE
, "Expected FALSE, got %d\n", session
.Error
.fError
);
548 ok(session
.FileCount
== 8, "Expected 8, got %d\n", session
.FileCount
);
549 ok(session
.Operation
== 0, "Expected 0, got %d\n", session
.Operation
);
550 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
551 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\d.txt"),
552 "Expected dest\\testdir\\d.txt, got %s\n", session
.CurrentFile
);
553 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
554 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
555 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
556 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
557 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
558 ok(check_list(&node
, "testdir\\d.txt", FALSE
), "list entry wrong\n");
559 ok(check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
560 ok(check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
561 ok(check_list(&node
, "a.txt", FALSE
), "list entry wrong\n");
562 node
= session
.FilterList
;
563 ok(check_list(&node
, "testdir\\d.txt", FALSE
), "list entry wrong\n");
564 ok(check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
565 ok(check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
566 ok(check_list(&node
, "a.txt", FALSE
), "list entry wrong\n");
568 /* cabinet does not exist */
569 ZeroMemory(&session
, sizeof(SESSION
));
570 lstrcpyA(session
.Destination
, "dest");
571 session
.Operation
= EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
;
572 res
= pExtract(&session
, "nonexistent.cab");
573 node
= session
.FileList
;
574 ok(res
== HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND
),
575 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %08x\n", res
);
576 ok(session
.Error
.erfOper
== FDIERROR_CABINET_NOT_FOUND
,
577 "Expected FDIERROR_CABINET_NOT_FOUND, got %d\n", session
.Error
.erfOper
);
578 ok(session
.FileSize
== 0, "Expected 0, got %d\n", session
.FileSize
);
579 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
580 ok(session
.Error
.fError
== TRUE
, "Expected TRUE, got %d\n", session
.Error
.fError
);
581 ok(session
.FileCount
== 0, "Expected 0, got %d\n", session
.FileCount
);
582 ok(session
.Operation
== (EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
),
583 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session
.Operation
);
584 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
585 ok(!*session
.CurrentFile
, "Expected empty string, got %s\n", session
.CurrentFile
);
586 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
587 ok(!session
.FilterList
, "Expected empty filter list\n");
588 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
589 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
590 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
591 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
592 ok(!check_list(&node
, "testdir\\d.txt", FALSE
), "list entry should not exist\n");
593 ok(!check_list(&node
, "testdir\\c.txt", FALSE
), "list entry should not exist\n");
594 ok(!check_list(&node
, "b.txt", FALSE
), "list entry should not exist\n");
595 ok(!check_list(&node
, "a.txt", FALSE
), "list entry should not exist\n");
597 /* first file exists */
598 createTestFile("dest\\a.txt");
599 SetFileAttributes("dest\\a.txt", FILE_ATTRIBUTE_READONLY
);
600 ZeroMemory(&session
, sizeof(SESSION
));
601 lstrcpyA(session
.Destination
, "dest");
602 session
.Operation
= EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
;
603 res
= pExtract(&session
, "extract.cab");
604 node
= session
.FileList
;
607 ok(res
== HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED
) || res
== E_FAIL
,
608 "Expected HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) or E_FAIL, got %08x\n", res
);
609 ok(session
.FileSize
== 6, "Expected 6, got %d\n", session
.FileSize
);
610 ok(session
.Error
.erfOper
== FDIERROR_USER_ABORT
,
611 "Expected FDIERROR_USER_ABORT, got %d\n", session
.Error
.erfOper
);
612 ok(session
.Error
.fError
== TRUE
, "Expected TRUE, got %d\n", session
.Error
.fError
);
613 ok(session
.FileCount
== 1, "Expected 1, got %d\n", session
.FileCount
);
614 ok(!lstrcmpA(session
.CurrentFile
, "dest\\a.txt"),
615 "Expected dest\\a.txt, got %s\n", session
.CurrentFile
);
617 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
618 ok(session
.Operation
== (EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
),
619 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session
.Operation
);
620 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
621 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
622 ok(!session
.FilterList
, "Expected empty filter list\n");
623 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
626 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
627 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
628 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
629 ok(!check_list(&node
, "testdir\\d.txt", FALSE
), "list entry should not exist\n");
630 ok(!check_list(&node
, "testdir\\c.txt", FALSE
), "list entry should not exist\n");
631 ok(!check_list(&node
, "b.txt", FALSE
), "list entry should not exist\n");
633 ok(!check_list(&node
, "a.txt", FALSE
), "list entry should not exist\n");
635 SetFileAttributesA("dest\\a.txt", FILE_ATTRIBUTE_NORMAL
);
636 DeleteFileA("dest\\a.txt");
638 /* third file exists */
639 createTestFile("dest\\testdir\\c.txt");
640 SetFileAttributes("dest\\testdir\\c.txt", FILE_ATTRIBUTE_READONLY
);
641 ZeroMemory(&session
, sizeof(SESSION
));
642 lstrcpyA(session
.Destination
, "dest");
643 session
.Operation
= EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
;
644 res
= pExtract(&session
, "extract.cab");
647 ok(res
== HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED
) || res
== E_FAIL
,
648 "Expected HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) or E_FAIL, got %08x\n", res
);
649 ok(session
.FileSize
== 26, "Expected 26, got %d\n", session
.FileSize
);
650 ok(session
.Error
.erfOper
== FDIERROR_USER_ABORT
,
651 "Expected FDIERROR_USER_ABORT, got %d\n", session
.Error
.erfOper
);
652 ok(session
.Error
.fError
== TRUE
, "Expected TRUE, got %d\n", session
.Error
.fError
);
653 ok(session
.FileCount
== 3, "Expected 3, got %d\n", session
.FileCount
);
654 ok(!lstrcmpA(session
.CurrentFile
, "dest\\testdir\\c.txt"),
655 "Expected dest\\c.txt, got %s\n", session
.CurrentFile
);
657 ok(session
.Error
.erfType
== 0, "Expected 0, got %d\n", session
.Error
.erfType
);
658 ok(session
.Operation
== (EXTRACT_FILLFILELIST
| EXTRACT_EXTRACTFILES
),
659 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session
.Operation
);
660 ok(!lstrcmpA(session
.Destination
, "dest"), "Expected dest, got %s\n", session
.Destination
);
661 ok(!*session
.Reserved
, "Expected empty string, got %s\n", session
.Reserved
);
662 ok(!session
.FilterList
, "Expected empty filter list\n");
663 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
664 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
665 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
668 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
670 ok(!check_list(&node
, "testdir\\d.txt", FALSE
), "list entry should not exist\n");
671 ok(!check_list(&node
, "testdir\\c.txt", FALSE
), "list entry wrong\n");
672 ok(!check_list(&node
, "b.txt", FALSE
), "list entry wrong\n");
673 ok(check_list(&node
, "a.txt", TRUE
), "list entry wrong\n");
675 SetFileAttributesA("dest\\testdir\\c.txt", FILE_ATTRIBUTE_NORMAL
);
676 DeleteFileA("dest\\testdir\\c.txt");
678 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
679 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
684 init_function_pointers();