version 1.5, 2005/02/04 09:37:43
|
version 2.15, 2005/03/18 00:28:59
|
|
|
/* | /* |
* Unit test suite for cabinet.dll - FDI functions | * Unit test suite for cabinet.dll - FDI functions |
* | * |
* Copyright 2004 Rizwan Kassim, Dan Kegel |
* Copyright 2004 Rizwan Kassim, Dan Kegel, Alexander Liber |
* | * |
* This library is free software; you can redistribute it and/or | * This library is free software; you can redistribute it and/or |
* modify it under the terms of the GNU Lesser General Public | * modify it under the terms of the GNU Lesser General Public |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
*/ | */ |
| |
|
#include <stdio.h> |
#include <stdlib.h> | #include <stdlib.h> |
|
#include <string.h> |
|
#include <stdarg.h> |
|
#include <malloc.h> |
| |
#ifndef STANDALONE |
#include <stdarg.h> |
#include <wine/test.h> |
|
#define ok2 ok |
|
#else |
|
/* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ cabinet_fdi.c FDI.lib |
|
These are only called if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */ |
|
#include <assert.h> |
|
#include <stdio.h> | #include <stdio.h> |
#define START_TEST(name) main(int argc, char **argv) |
|
#define ok(condition, msg) \ |
|
do { if(!(condition)) { \ |
|
fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__); \ |
|
exit(1); \ |
|
} } while(0) |
|
#define ok2(condition, msg, arg) \ |
|
do { if(!(condition)) { \ |
|
fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__, arg); \ |
|
exit(1); \ |
|
} } while(0) |
|
#define todo_wine |
|
#endif |
|
| |
|
#include "windef.h" |
|
#include "winbase.h" |
|
#include "winerror.h" |
|
#include "fdi.h" |
|
|
|
#ifndef WIN_ENV |
|
#include <msvcrt/fcntl.h> |
|
#include <msvcrt/sys/stat.h> |
|
#else |
|
#include <sys/stat.h> |
|
#include <fcntl.h> |
|
#endif |
| |
#include <winerror.h> |
#define VERBOSE |
#include <fdi.h> |
|
| |
/* To do in FDI: -from wine/include/fdi.h |
#include "tvfs.h" |
FDICreate |
#include "simplecab.h" |
Memory Allocation -FNALLOC(cb) |
|
Memory Free -FNFREE(pv) |
|
File Open -FNOPEN(pszFile,oflag,pmode) |
|
File Read -FNREAD(hf, pv, cb) |
|
File Write -FNWRITE(hf, pv, cb) |
|
File Close -FNCLOSE(hf) |
|
File Seek -FNSEEK(hf,dist,seektype) |
|
Error Structure |
|
FDIlsCabinet |
|
FDICabinetInfo Structure |
|
FDICopy |
|
Notification function |
|
Decryption function |
|
FDIDestroy |
|
*/ |
|
| |
/* Currently mostly dummy function pointers */ |
#ifndef STANDALONE |
|
#include <wine/test.h> |
|
#define ok2 ok |
|
#else |
|
#include "standalone.h" |
|
/* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ -DWIN_ENV tvfs.c cabinet_fdi.c FDI.lib |
|
standalone.h is used if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */ |
|
#endif |
| |
FNALLOC(debug_alloc) { |
FNALLOC(final_alloc) { |
printf(" FNALLOC just called with %d\n",cb); |
trace(" FNALLOC just called with %d\n",cb); |
return malloc(cb); | return malloc(cb); |
} | } |
|
FNFREE(final_free) { |
FNFREE(debug_free) { |
trace(" FNFREE just called with %d\n",pv); |
printf(" FNFREE just called with %d\n",pv); |
|
free(pv); | free(pv); |
return; | return; |
} | } |
| |
/* |
/*Possible non trivial addition: |
It is not necessary for these functions to actually call _open etc.; these functions could instead call fopen, fread, fwrite, fclose, and fseek, or CreateFile, ReadFile, WriteFile, CloseHandle, and SetFilePointer, etc. However, the parameters and return codes will have to be translated appropriately (e.g. the file open mode passed in to pfnopen). |
Notify receives some information about the cab file(see FDI documentation). |
|
Since this info is different depending on the value of fdint, and Notify should |
|
be generic, it is not simple or nice to check this information. |
*/ | */ |
|
FNFDINOTIFY(notification_function) |
FNOPEN(dummy_open) { |
{ |
printf(" FNOPEN just called with %d, %d, %d\n",pszFile, oflag, pmode); |
trace(" FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin); |
|
switch (fdint) |
|
{ |
|
case fdintCABINET_INFO: |
|
{ |
|
trace( |
|
"fdintCABINET_INFO:\n" |
|
"-next cab name: %s\n" |
|
"-next disk: %s\n" |
|
"-path name: %s\n" |
|
"-set ID: %d\n" |
|
"-number in set: %d\n", |
|
pfdin->psz1, pfdin->psz2, pfdin->psz3, pfdin->setID, pfdin->iCabinet |
|
); |
return 0; | return 0; |
} | } |
|
case fdintPARTIAL_FILE: |
|
{ |
|
trace("dintPARTIAL_FILE\n"); |
| |
FNREAD(dummy_read) { |
|
printf(" FNREAD just called with %d, %d, %d\n",hf, pv, cb); |
|
return 0; | return 0; |
} | } |
|
case fdintCOPY_FILE: |
|
{ |
|
int fih = 0; |
|
char target[256]; |
|
trace( |
|
"fdintCOPY_FILE:\n" |
|
"-name: %s\n" |
|
"-uncompressed size: %d\n" |
|
"-date: %d\n" |
|
"-time: %d\n" |
|
"-attributes: %d\n" |
|
"-file's folder index: %d\n", |
|
pfdin->psz1, pfdin->cb, pfdin->date, pfdin->time, pfdin->attribs, pfdin->iFolder |
|
); |
|
sprintf(target, "./%s",pfdin->psz1); |
|
fih = tvfs_open (target, |
|
_O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL, |
|
_S_IREAD | _S_IWRITE |
|
); |
|
return fih; |
|
} |
|
case fdintCLOSE_FILE_INFO: |
|
{ |
|
#ifdef VERBOSE |
|
trace( |
|
"fdintCLOSE_FILE:\n" |
|
"-name: %s\n" |
|
"-handle: %d\n" |
|
"-date: %d\n" |
|
"-time: %d\n" |
|
"-attributes: %d\n" |
|
"-file's folder index: %d\n" |
|
"-run: %d\n", |
|
pfdin->psz1, pfdin->hf, pfdin->date, pfdin->time, pfdin->attribs, pfdin->iFolder, pfdin->cb |
|
); |
|
#endif |
| |
FNWRITE(dummy_write) { |
tvfs_close(pfdin->hf); |
printf(" FNWRITE just called with %d, %d, %d\n",hf, pv, cb); |
return TRUE; |
|
} |
|
case fdintNEXT_CABINET: |
|
{ |
|
trace("fdintNEXT_CABINET\n"); |
return 0; | return 0; |
} | } |
|
case fdintENUMERATE: |
|
{ |
FNCLOSE(dummy_close) { |
trace("fdintENUMERATE\n"); |
printf(" FNCLOSE just called with %d\n",hf); |
|
return 0; | return 0; |
} | } |
|
} |
FNSEEK(dummy_seek) { |
|
printf(" FNSEEK just called with %d, %d, %d\n",hf, dist, seektype); |
|
return 0; | return 0; |
} | } |
| |
HFDI hfdi_386, hfdi_286, hfdi_unknown; |
static void printCabInfo(FDICABINETINFO cabinfo){ |
/* yes its global and ugly */ |
trace(" Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n", |
|
cabinfo.cbCabinet, |
static void TestDestroy(void) { |
cabinfo.cFolders , |
printf("Starting TestDestroy()\n"); |
cabinfo.cFiles , |
/* Only two things to check in FDIDestroy |
cabinfo.setID, |
1=> Does it return T if its passed an hfdi |
cabinfo.iCabinet, |
2=> Does it return F if its passed a non hfdi |
cabinfo.fReserve , |
EDIT : Causes GPL if FDIDestroy is called on an invalid pointer. |
cabinfo.hasprev , |
ok( 0 == FDIDestroy(0), "Return true incorrectly in TestDestroy()!\n"); |
cabinfo.hasnext ); |
*/ |
} |
ok(FDIDestroy(hfdi_386), "Failed on destroying 386 hfdi!\n"); |
|
ok(FDIDestroy(hfdi_286), "Failed on destroying 286 hfdi!\n"); |
|
ok(FDIDestroy(hfdi_unknown), "Failed on destroying unknown hfdi!\n"); |
|
printf("Ending TestDestroy()\n"); |
|
| |
|
static void CheckCabInfo(char * cabname, |
|
FDICABINETINFO cabinfo, |
|
long TcbCabinet, |
|
USHORT TcFolders, |
|
USHORT TcFiles, |
|
USHORT TsetID, |
|
USHORT TiCabinet, |
|
BOOL TfReserve, |
|
BOOL Thasprev, |
|
BOOL Thasnext){ |
|
ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
|
ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
|
ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
|
ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
|
ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
|
ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
|
ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
|
ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname); |
} | } |
|
/* TODO : Message should contain variable values */ |
|
|
|
static HFDI hfdi_simple; |
|
/* yes its global and ugly */ |
|
|
| |
static void TestCreate(void) { | static void TestCreate(void) { |
| |
ERF error_structure; | ERF error_structure; |
| |
printf("Starting TestCreate()\n"); |
trace("Starting TestCreate()\n"); |
|
/* Is CPU386 or Unknown more commonly used? */ |
hfdi_386 = FDICreate( |
hfdi_simple = FDICreate( |
debug_alloc, |
final_alloc, |
debug_free, |
final_free, |
dummy_open, |
tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek, |
dummy_read, |
cpuUNKNOWN, |
dummy_write, |
|
dummy_close, |
|
dummy_seek, |
|
cpu80386, |
|
&error_structure | &error_structure |
); | ); |
ok(hfdi_386 != NULL,"FDICreate (CPU = cpu80386) failed!\n"); |
|
| |
hfdi_286 = FDICreate( |
ok(hfdi_simple != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n"); |
debug_alloc, |
|
debug_free, |
|
dummy_open, |
|
dummy_read, |
|
dummy_write, |
|
dummy_close, |
|
dummy_seek, |
|
cpu80286, |
|
&error_structure |
|
); |
|
ok(hfdi_286 != NULL,"FDICreate (CPU = cpu80286) failed!\n"); |
|
| |
hfdi_unknown = FDICreate( |
trace("Ending TestCreate()\n"); |
debug_alloc, |
} |
debug_free, |
|
dummy_open, |
static void TestInfo(void) { |
dummy_read, |
|
dummy_write, |
|
dummy_close, |
|
dummy_seek, |
|
cpuUNKNOWN, |
|
&error_structure |
|
); |
|
ok(hfdi_unknown != NULL,"FDICreate (CPU = unknown) failed!\n"); |
|
| |
|
int fd; |
| |
|
FDICABINETINFO fdi_cabinfo_simple; |
| |
|
trace("Starting TestInfo()\n"); |
| |
printf("Ending TestCreate()\n"); |
tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab); |
|
fd = tvfs_open( name_simple_cab, _O_BINARY, 0 ); |
|
|
|
ok( FDIIsCabinet( hfdi_simple, fd, &fdi_cabinfo_simple) == TRUE, |
|
"FDIIsCabinet (Virtual File = Simple.cab) failed!\n"); |
|
|
|
printCabInfo(fdi_cabinfo_simple); |
|
CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0); |
|
|
|
tvfs_close(fd); |
|
tvfs_free(); |
|
|
|
trace("Ending TestInfo()\n"); |
} | } |
| |
START_TEST(paths) |
static void TestCopy(void){ |
{ |
|
| |
|
char name_file_path[256]; |
|
int result; |
|
|
|
trace("Starting TestCopy()\n"); |
|
trace("---simple.cab\n"); |
|
|
|
tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab); |
|
FDICopy(hfdi_simple, |
|
"simple.cab", |
|
"", |
|
0, |
|
notification_function, |
|
NULL, |
|
NULL); |
|
|
|
/* Filename when extracted is ./<filename> */ |
|
sprintf(name_file_path, "./%s", name_simple_txt); |
|
result = tvfs_compare(name_file_path, file_simple_txt, size_simple_txt); |
|
if (result) |
|
trace ("File %s compare failed!\n",name_file_path); |
|
tvfs_free(); |
|
|
|
trace("Ending TestCopy()\n"); |
|
} |
|
|
|
static void TestDestroy(void) { |
|
trace("Starting TestDestroy()\n"); |
|
ok(FDIDestroy(hfdi_simple), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n"); |
|
trace("Ending TestDestroy()\n"); |
|
} |
|
|
|
START_TEST(cabinet_fdi) |
|
{ |
TestCreate(); | TestCreate(); |
/* |
|
TestInfo(); | TestInfo(); |
TestCopy(); | TestCopy(); |
*/ |
|
TestDestroy(); | TestDestroy(); |
|
tvfs_free(); |
} | } |