version 1.2, 2005/02/04 08:51:51
|
version 1.7, 2005/02/11 08:50:58
|
|
|
* 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 <stdlib.h> | #include <stdlib.h> |
| |
#ifndef STANDALONE | #ifndef STANDALONE |
|
|
#define todo_wine | #define todo_wine |
#endif | #endif |
| |
|
|
#include <winerror.h> | #include <winerror.h> |
#include <fdi.h> | #include <fdi.h> |
|
#include <fcntl.h> |
|
|
|
static int fakeFD = 12; |
|
|
|
/* This is the hex string representation of the file created by compressing |
|
a simple text file with the contents "This is a test file." |
|
|
|
The file was created using COMPRESS.EXE from the Windows Server 2003 |
|
Resource Kit from Microsoft. The resource kit was retrieved from the |
|
following URL: |
|
|
|
http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en |
|
*/ |
|
|
|
|
|
static unsigned char compressed_file[] = |
|
{0x4D,0x53,0x43,0x46,0x00,0x00,0x00,0x00,0x75,0x00, |
|
0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00, |
|
0x00,0x00,0x00,0x00,0x03,0x01,0x01,0x00,0x01,0x00, |
|
0x00,0x00,0x39,0x30,0x00,0x00,0x45,0x00,0x00,0x00, |
|
0x01,0x00,0x01,0x00,0x26,0x00,0x00,0x00,0x00,0x00, |
|
0x00,0x00,0x00,0x00,0x4A,0x32,0xB2,0xBE,0x20,0x00, |
|
0x74,0x65,0x73,0x74,0x2E,0x74,0x78,0x74,0x00,0x9C, |
|
0x74,0xD0,0x75,0x28,0x00,0x26,0x00,0x43,0x4B,0x0B, |
|
0xCE,0x57,0xC8,0xC9,0xCF,0x4B,0xD7,0x51,0x48,0xCC, |
|
0x4B,0x51,0x28,0xC9,0x48,0xCC,0xCB,0x2E,0x56,0x48, |
|
0xCB,0x2F,0x52,0x48,0xCC,0xC9,0x01,0x72,0x53,0x15, |
|
0xD2,0x32,0x8B,0x33,0xF4,0xB8,0x00}; |
|
static int szcompressed_file = sizeof(compressed_file); |
|
|
|
/* |
|
static const char uncompressed_data[] = "This is a test file."; |
|
static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1; |
|
|
|
static char *buf; |
|
*/ |
| |
/* To do in FDI: -from wine/include/fdi.h | /* To do in FDI: -from wine/include/fdi.h |
FDICreate | FDICreate |
Memory Allocation -FNALLOC(cb) |
|
Memory Free -FNFREE(pv) |
|
File Open -FNOPEN(pszFile,oflag,pmode) | File Open -FNOPEN(pszFile,oflag,pmode) |
File Read -FNREAD(hf, pv, cb) | File Read -FNREAD(hf, pv, cb) |
File Write -FNWRITE(hf, pv, cb) | File Write -FNWRITE(hf, pv, cb) |
|
|
FDIDestroy | FDIDestroy |
*/ | */ |
| |
|
FDICABINETINFO fdici; |
|
|
|
|
|
/* Currently mostly dummy function pointers */ |
|
|
|
FNALLOC(debug_alloc) { |
|
printf(" FNALLOC just called with %d\n",cb); |
|
return malloc(cb); |
|
} |
|
|
|
FNFREE(debug_free) { |
|
printf(" FNFREE just called with %d\n",pv); |
|
free(pv); |
|
return; |
|
} |
|
|
|
/* |
|
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). |
|
|
|
Match i/o specs of _open, _read, _write, _close, and _lseek. |
|
|
|
*/ |
|
|
|
/* |
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open.2c_._wopen.asp |
|
_open I: const char *filename, int oflag, int pmode O: int (handler), -1 for err. |
|
*/ |
|
|
|
FNOPEN(dummy_open) { |
|
printf(" FNOPEN (dummy) just called with %d, %d, %d\n",pszFile, oflag, pmode); |
|
return 0; |
|
} |
|
|
|
FNOPEN(fake_open) { |
|
printf(" FNOPEN (fake) just called with %d, %d, %d\n",pszFile, oflag, pmode); |
|
printf(" Returning %d as file descriptor\n",fakeFD); |
|
return 12; |
|
} |
|
|
|
FNOPEN(real_open) { |
|
int handler = _open(pszFile,oflag,pmode); |
|
printf(" FNOPEN (real) just called with %s, %d, %d\n",pszFile, oflag, pmode); |
|
printf(" FNOPEN (real) returning handler (%d)\n",handler); |
|
return handler; |
|
} |
|
|
|
|
|
/* |
|
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open.2c_._wopen.asp |
|
_read I: int fd, void *buffer, unsigned int count O: int (szBuffer) |
|
*/ |
|
|
|
FNREAD(dummy_read) { |
|
printf(" FNREAD (dummy) just called with %d, %d, %d\n",hf, pv, cb); |
|
return 0; |
|
} |
|
|
|
FNREAD(fake_read) { |
|
printf(" FNREAD (fake) just called with %d, %d, %d\n",hf, pv, cb); |
|
if (hf == fakeFD) { |
|
printf (" Called with fake file descriptor, populating buffer and size (%d)\n",szcompressed_file); |
|
memcpy (pv, compressed_file ,cb); |
|
/* TODO */ |
|
} |
|
else { |
|
printf (" FNREAD (fake) was called with the unknown file handler. Failed!\n",hf); |
|
} |
|
return szcompressed_file; |
|
} |
|
|
|
FNREAD(real_read) { |
|
int szBuffer = _read(hf,pv,cb); |
|
printf(" FNREAD (read) just called with %d, %d, %d\n",hf, pv, cb); |
|
printf(" FNREAD (read) returning size (%d)\n",szBuffer); |
|
return szBuffer; |
|
} |
|
|
|
|
|
|
|
FNWRITE(dummy_write) { |
|
printf(" FNWRITE just called with %d, %d, %d\n",hf, pv, cb); |
|
return 0; |
|
} |
|
|
|
|
|
FNCLOSE(dummy_close) { |
|
printf(" FNCLOSE just called with %d\n",hf); |
|
return 0; |
|
} |
|
|
|
FNSEEK(dummy_seek) { |
|
printf(" FNSEEK just called with %d, %d, %d\n",hf, dist, seektype); |
|
return 0; |
|
} |
|
|
|
HFDI hfdi_unknown_dummy, hfdi_unknown_fake,hfdi_unknown_real; |
|
FDICABINETINFO fdi_cabinfo; |
|
/* yes its global and ugly */ |
|
|
|
|
|
static void TestCreate(void) { |
|
|
|
ERF error_structure; |
|
|
|
printf("Starting TestCreate()\n"); |
|
|
|
hfdi_unknown_dummy = FDICreate( |
|
debug_alloc, |
|
debug_free, |
|
dummy_open, |
|
dummy_read, |
|
dummy_write, |
|
dummy_close, |
|
dummy_seek, |
|
cpuUNKNOWN, |
|
&error_structure |
|
); |
|
ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n"); |
|
|
|
hfdi_unknown_fake = FDICreate( |
|
debug_alloc, |
|
debug_free, |
|
fake_open, |
|
fake_read, |
|
dummy_write, |
|
dummy_close, |
|
dummy_seek, |
|
cpuUNKNOWN, |
|
&error_structure |
|
); |
|
ok(hfdi_unknown_fake != NULL,"FDICreate (CPU = unknown) (functions=fake) failed!\n"); |
|
|
|
hfdi_unknown_real = FDICreate( |
|
debug_alloc, |
|
debug_free, |
|
real_open, |
|
real_read, |
|
dummy_write, |
|
dummy_close, |
|
dummy_seek, |
|
cpuUNKNOWN, |
|
&error_structure |
|
); |
|
ok(hfdi_unknown_real != NULL,"FDICreate (CPU = unknown) (functions=real) failed!\n"); |
|
|
|
printf("Ending TestCreate()\n"); |
|
} |
|
|
|
static void TestInfo(void) { |
|
int realfd; |
|
int sizer; |
|
char *buffer = malloc(szcompressed_file); |
|
|
|
printf("Starting TestInfo()\n"); |
|
/* |
|
1=> Does it return T (and fill FDICABINETINFO) if the file descriptor=>cabinet? |
|
2=> Does it return F (and ignore FDICABINETINFO) if the file descriptor != cabinet? |
|
3=> Does it return F (and ignore FDICABINETINFO) if the file descriptor == error? |
|
*/ |
|
ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo) == FALSE, |
|
"FDIIsCabinet (File = Error) failed!\n"); |
|
|
|
ok ( FDIIsCabinet( hfdi_unknown_fake, fakeFD, &fdi_cabinfo) == FALSE, |
|
"FDIIsCabinet (File = WrongType) failed!\n"); |
|
|
|
sizer = fake_read ( 12,buffer,szcompressed_file ); |
|
printf(buffer); |
|
|
|
realfd = real_open( "TEST1.cab" , _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, 0); |
|
ok ( FDIIsCabinet( hfdi_unknown_real, realfd, &fdi_cabinfo) == TRUE, |
|
"FDIIsCabinet (File = Cabinet) failed!\n"); |
|
|
|
|
|
} |
|
|
|
|
|
static void TestDestroy(void) { |
|
printf("Starting TestDestroy()\n"); |
|
/* Only two things to check in FDIDestroy |
|
1=> Does it return T if its passed an hfdi |
|
2=> Does it return F if its passed a non hfdi |
|
EDIT : Causes GPL if FDIDestroy is called on an invalid pointer. |
|
ok( 0 == FDIDestroy(0), "Return true incorrectly in TestDestroy()!\n"); |
|
*/ |
| |
|
ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n"); |
|
ok(FDIDestroy(hfdi_unknown_fake), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n"); |
|
printf("Ending TestDestroy()\n"); |
| |
|
} |
| |
| |
START_TEST(paths) | START_TEST(paths) |
{ | { |
/* |
|
TestCreate(); | TestCreate(); |
TestInfo(); | TestInfo(); |
|
/* |
TestCopy(); | TestCopy(); |
TestDestroy(); |
|
*/ | */ |
} |
TestDestroy(); |
|
|
|
|
| |
|
} |