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 defintions 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 *mem_alloc(ULONG cb)
116 return HeapAlloc(GetProcessHeap(), 0, cb);
119 static void mem_free(void *memory)
121 HeapFree(GetProcessHeap(), 0, memory);
124 static BOOL get_next_cabinet(PCCAB pccab, ULONG cbPrevCab, void *pv)
129 static long progress(UINT typeStatus, ULONG cb1, ULONG cb2, void *pv)
134 static int file_placed(PCCAB pccab, char *pszFile, long cbFile,
135 BOOL fContinuation, void *pv)
140 static INT_PTR 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 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 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 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 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 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 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 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 *filelist, const char *filename, BOOL extracted)
321 for (fl = filelist; fl; fl = fl->next)
322 if (!lstrcmp(filename, fl->FileName))
323 return (extracted == fl->Extracted);
328 static void test_Extract(void)
333 /* native windows crashes if
334 * - invalid parameters are sent in
335 * - you call EXTRACT_EXTRACTFILES without calling
336 * EXTRACT_FILLFILELIST first or at the same time
339 /* try to extract all files */
340 ZeroMemory(&session, sizeof(SESSION));
341 lstrcpyA(session.Destination, "dest");
342 session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
343 res = pExtract(&session, "extract.cab");
344 ok(res == S_OK, "Expected S_OK, got %d\n", res);
347 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
349 ok(session.Error.erfOper == FDIERROR_NONE,
350 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
351 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
352 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
353 ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
354 ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
355 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
356 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
357 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
358 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
359 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
360 ok(!session.FilterList, "Expected empty filter list\n");
361 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
362 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
363 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
364 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
365 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
366 ok(check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry wrong\n");
367 ok(check_list(session.FileList, "testdir\\c.txt", FALSE), "list entry wrong\n");
368 ok(check_list(session.FileList, "b.txt", FALSE), "list entry wrong\n");
369 ok(check_list(session.FileList, "a.txt", FALSE), "list entry wrong\n");
371 /* try fill file list operation */
372 ZeroMemory(&session, sizeof(SESSION));
373 lstrcpyA(session.Destination, "dest");
374 session.Operation = EXTRACT_FILLFILELIST;
375 res = pExtract(&session, "extract.cab");
376 ok(res == S_OK, "Expected S_OK, got %d\n", res);
379 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
381 ok(session.Error.erfOper == FDIERROR_NONE,
382 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
383 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
384 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
385 ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
386 ok(session.Operation == EXTRACT_FILLFILELIST,
387 "Expected EXTRACT_FILLFILELIST, got %d\n", session.Operation);
388 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
389 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
390 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
391 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
392 ok(!session.FilterList, "Expected empty filter list\n");
393 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
394 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
397 ok(check_list(session.FileList, "testdir\\d.txt", TRUE), "list entry wrong\n");
398 ok(check_list(session.FileList, "testdir\\c.txt", TRUE), "list entry wrong\n");
399 ok(check_list(session.FileList, "b.txt", TRUE), "list entry wrong\n");
400 ok(check_list(session.FileList, "a.txt", TRUE), "list entry wrong\n");
403 /* try extract files operation once file list is filled */
404 session.Operation = EXTRACT_EXTRACTFILES;
405 res = pExtract(&session, "extract.cab");
406 ok(res == S_OK, "Expected S_OK, got %d\n", res);
409 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
411 ok(session.Error.erfOper == FDIERROR_NONE,
412 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
413 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
414 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
415 ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
416 ok(session.Operation == EXTRACT_EXTRACTFILES,
417 "Expected EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
418 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
419 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
420 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
421 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
422 ok(!session.FilterList, "Expected empty filter list\n");
423 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
424 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
425 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
426 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
427 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
428 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
429 ok(check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry wrong\n");
430 ok(check_list(session.FileList, "testdir\\c.txt", FALSE), "list entry wrong\n");
431 ok(check_list(session.FileList, "b.txt", FALSE), "list entry wrong\n");
432 ok(check_list(session.FileList, "a.txt", FALSE), "list entry wrong\n");
434 /* Extract does not extract files if the dest dir does not exist */
435 res = pExtract(&session, "extract.cab");
436 ok(res == S_OK, "Expected S_OK, got %d\n", res);
439 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
441 ok(session.Error.erfOper == FDIERROR_NONE,
442 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
443 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
444 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
445 ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
446 ok(session.Operation == EXTRACT_EXTRACTFILES,
447 "Expected EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
448 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
449 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
450 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
451 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
452 ok(!session.FilterList, "Expected empty filter list\n");
453 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
454 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
455 ok(check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry wrong\n");
456 ok(check_list(session.FileList, "testdir\\c.txt", FALSE), "list entry wrong\n");
457 ok(check_list(session.FileList, "b.txt", FALSE), "list entry wrong\n");
458 ok(check_list(session.FileList, "a.txt", FALSE), "list entry wrong\n");
460 /* remove two of the files in the list */
461 session.FileList->next = session.FileList->next->next;
462 session.FileList->next->next = NULL;
463 session.FilterList = NULL;
464 CreateDirectoryA("dest", NULL);
465 res = pExtract(&session, "extract.cab");
466 ok(res == S_OK, "Expected S_OK, got %d\n", res);
469 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
471 ok(session.Error.erfOper == FDIERROR_NONE,
472 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
473 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
474 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
475 ok(session.FileCount == 4, "Expected 4, got %d\n", session.FileCount);
476 ok(session.Operation == EXTRACT_EXTRACTFILES,
477 "Expected EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
478 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
479 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
480 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
481 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
482 ok(!session.FilterList, "Expected empty filter list\n");
483 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
484 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
485 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
486 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
489 ok(check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry wrong\n");
490 ok(!check_list(session.FileList, "testdir\\c.txt", FALSE), "list entry wrong\n");
491 ok(check_list(session.FileList, "b.txt", FALSE), "list entry wrong\n");
492 ok(!check_list(session.FileList, "a.txt", FALSE), "list entry wrong\n");
495 session.Operation = EXTRACT_FILLFILELIST;
496 session.FileList = NULL;
497 res = pExtract(&session, "extract.cab");
498 ok(res == S_OK, "Expected S_OK, got %d\n", res);
501 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
503 ok(session.Error.erfOper == FDIERROR_NONE,
504 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
505 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
506 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
507 ok(session.FileCount == 8, "Expected 8, got %d\n", session.FileCount);
508 ok(session.Operation == EXTRACT_FILLFILELIST,
509 "Expected EXTRACT_FILLFILELIST, got %d\n", session.Operation);
510 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
511 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
512 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
513 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
514 ok(!session.FilterList, "Expected empty filter list\n");
515 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
516 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
517 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
518 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
521 ok(check_list(session.FileList, "testdir\\d.txt", TRUE), "list entry wrong\n");
522 ok(check_list(session.FileList, "testdir\\c.txt", TRUE), "list entry wrong\n");
523 ok(check_list(session.FileList, "b.txt", TRUE), "list entry wrong\n");
524 ok(check_list(session.FileList, "a.txt", TRUE), "list entry wrong\n");
527 session.Operation = 0;
528 res = pExtract(&session, "extract.cab");
529 ok(res == S_OK, "Expected S_OK, got %d\n", res);
532 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
534 ok(session.Error.erfOper == FDIERROR_NONE,
535 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
536 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
537 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
538 ok(session.FileCount == 8, "Expected 8, got %d\n", session.FileCount);
539 ok(session.Operation == 0, "Expected 0, got %d\n", session.Operation);
540 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
541 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
542 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
543 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
544 ok(!session.FilterList, "Expected empty filter list\n");
545 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
546 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
547 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
548 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
551 ok(check_list(session.FileList, "testdir\\d.txt", TRUE), "list entry wrong\n");
552 ok(check_list(session.FileList, "testdir\\c.txt", TRUE), "list entry wrong\n");
553 ok(check_list(session.FileList, "b.txt", TRUE), "list entry wrong\n");
554 ok(check_list(session.FileList, "a.txt", TRUE), "list entry wrong\n");
557 session.Operation = 0;
558 session.FilterList = session.FileList;
559 res = pExtract(&session, "extract.cab");
560 ok(res == S_OK, "Expected S_OK, got %d\n", res);
563 ok(session.FileSize == 40, "Expected 40, got %d\n", session.FileSize);
565 ok(session.Error.erfOper == FDIERROR_NONE,
566 "Expected FDIERROR_NONE, got %d\n", session.Error.erfOper);
567 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
568 ok(session.Error.fError == FALSE, "Expected FALSE, got %d\n", session.Error.fError);
569 ok(session.FileCount == 8, "Expected 8, got %d\n", session.FileCount);
570 ok(session.Operation == 0, "Expected 0, got %d\n", session.Operation);
571 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
572 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\d.txt"),
573 "Expected dest\\testdir\\d.txt, got %s\n", session.CurrentFile);
574 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
575 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
576 ok(DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to exist\n");
577 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
578 ok(DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to exist\n");
580 ok(check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry wrong\n");
581 ok(check_list(session.FileList, "testdir\\c.txt", FALSE), "list entry wrong\n");
582 ok(check_list(session.FileList, "b.txt", FALSE), "list entry wrong\n");
583 ok(check_list(session.FileList, "a.txt", FALSE), "list entry wrong\n");
584 ok(check_list(session.FilterList, "testdir\\d.txt", FALSE), "list entry wrong\n");
585 ok(check_list(session.FilterList, "testdir\\c.txt", FALSE), "list entry wrong\n");
586 ok(check_list(session.FilterList, "b.txt", FALSE), "list entry wrong\n");
587 ok(check_list(session.FilterList, "a.txt", FALSE), "list entry wrong\n");
589 /* cabinet does not exist */
590 ZeroMemory(&session, sizeof(SESSION));
591 lstrcpyA(session.Destination, "dest");
592 session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
593 res = pExtract(&session, "nonexistent.cab");
596 ok(res == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND),
597 "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got %08x\n", res);
598 ok(session.Error.erfOper == FDIERROR_CABINET_NOT_FOUND,
599 "Expected FDIERROR_CABINET_NOT_FOUND, got %d\n", session.Error.erfOper);
601 ok(session.FileSize == 0, "Expected 0, got %d\n", session.FileSize);
602 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
603 ok(session.Error.fError == TRUE, "Expected TRUE, got %d\n", session.Error.fError);
604 ok(session.FileCount == 0, "Expected 0, got %d\n", session.FileCount);
605 ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
606 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
607 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
608 ok(!*session.CurrentFile, "Expected empty string, got %s\n", session.CurrentFile);
609 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
610 ok(!session.FilterList, "Expected empty filter list\n");
611 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
612 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
613 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
614 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
615 ok(!check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry should not exist\n");
616 ok(!check_list(session.FileList, "testdir\\c.txt", FALSE), "list entry should not exist\n");
617 ok(!check_list(session.FileList, "b.txt", FALSE), "list entry should not exist\n");
618 ok(!check_list(session.FileList, "a.txt", FALSE), "list entry should not exist\n");
620 /* first file exists */
621 createTestFile("dest\\a.txt");
622 SetFileAttributes("dest\\a.txt", FILE_ATTRIBUTE_READONLY);
623 ZeroMemory(&session, sizeof(SESSION));
624 lstrcpyA(session.Destination, "dest");
625 session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
626 res = pExtract(&session, "extract.cab");
629 ok(res == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED),
630 "Expected HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), got %08x\n", res);
631 ok(session.FileSize == 6, "Expected 6, got %d\n", session.FileSize);
632 ok(session.Error.erfOper == FDIERROR_USER_ABORT,
633 "Expected FDIERROR_USER_ABORT, got %d\n", session.Error.erfOper);
634 ok(session.Error.fError == TRUE, "Expected TRUE, got %d\n", session.Error.fError);
635 ok(session.FileCount == 1, "Expected 1, got %d\n", session.FileCount);
636 ok(!lstrcmpA(session.CurrentFile, "dest\\a.txt"),
637 "Expected dest\\a.txt, got %s\n", session.CurrentFile);
639 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
640 ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
641 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
642 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
643 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
644 ok(!session.FilterList, "Expected empty filter list\n");
645 ok(!DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to not exist\n");
648 ok(!DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to not exist\n");
649 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
650 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
651 ok(!check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry should not exist\n");
652 ok(!check_list(session.FileList, "testdir\\c.txt", FALSE), "list entry should not exist\n");
653 ok(!check_list(session.FileList, "b.txt", FALSE), "list entry should not exist\n");
654 ok(!check_list(session.FileList, "a.txt", FALSE), "list entry should not exist\n");
657 SetFileAttributesA("dest\\a.txt", FILE_ATTRIBUTE_NORMAL);
658 DeleteFileA("dest\\a.txt");
660 /* third file exists */
661 createTestFile("dest\\testdir\\c.txt");
662 SetFileAttributes("dest\\testdir\\c.txt", FILE_ATTRIBUTE_READONLY);
663 ZeroMemory(&session, sizeof(SESSION));
664 lstrcpyA(session.Destination, "dest");
665 session.Operation = EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES;
666 res = pExtract(&session, "extract.cab");
669 ok(res == HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED),
670 "Expected HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED), got %08x\n", res);
671 ok(session.FileSize == 26, "Expected 26, got %d\n", session.FileSize);
672 ok(session.Error.erfOper == FDIERROR_USER_ABORT,
673 "Expected FDIERROR_USER_ABORT, got %d\n", session.Error.erfOper);
674 ok(session.Error.fError == TRUE, "Expected TRUE, got %d\n", session.Error.fError);
675 ok(session.FileCount == 3, "Expected 3, got %d\n", session.FileCount);
676 ok(!lstrcmpA(session.CurrentFile, "dest\\testdir\\c.txt"),
677 "Expected dest\\c.txt, got %s\n", session.CurrentFile);
679 ok(session.Error.erfType == 0, "Expected 0, got %d\n", session.Error.erfType);
680 ok(session.Operation == (EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES),
681 "Expected EXTRACT_FILLFILELIST | EXTRACT_EXTRACTFILES, got %d\n", session.Operation);
682 ok(!lstrcmpA(session.Destination, "dest"), "Expected dest, got %s\n", session.Destination);
683 ok(!*session.Reserved, "Expected empty string, got %s\n", session.Reserved);
684 ok(!session.FilterList, "Expected empty filter list\n");
685 ok(DeleteFileA("dest\\a.txt"), "Expected dest\\a.txt to exist\n");
686 ok(DeleteFileA("dest\\b.txt"), "Expected dest\\b.txt to exist\n");
687 ok(!DeleteFileA("dest\\testdir\\c.txt"), "Expected dest\\testdir\\c.txt to not exist\n");
690 ok(!DeleteFileA("dest\\testdir\\d.txt"), "Expected dest\\testdir\\d.txt to not exist\n");
691 ok(!check_list(session.FileList, "testdir\\d.txt", FALSE), "list entry should not exist\n");
692 ok(check_list(session.FileList, "testdir\\c.txt", TRUE), "list entry wrong\n");
694 ok(check_list(session.FileList, "b.txt", FALSE), "list entry wrong\n");
695 ok(check_list(session.FileList, "a.txt", FALSE), "list entry wrong\n");
697 SetFileAttributesA("dest\\testdir\\c.txt", FILE_ATTRIBUTE_NORMAL);
698 DeleteFileA("dest\\testdir\\c.txt");
700 ok(RemoveDirectoryA("dest\\testdir"), "Expected dest\\testdir to exist\n");
701 ok(RemoveDirectoryA("dest"), "Expected dest to exist\n");
706 init_function_pointers();