(file) Return to cabinet_fdi.c CVS log (file) (dir) Up to [RizwankCVS] / group3 / wine / dlls / cabinet / tests

Diff for /group3/wine/dlls/cabinet/tests/cabinet_fdi.c between version 1.7 and 1.8

version 1.7, 2005/02/11 08:50:58 version 1.8, 2005/02/11 09:56:01
Line 46 
Line 46 
 #include <fdi.h> #include <fdi.h>
 #include <fcntl.h> #include <fcntl.h>
  
 static int fakeFD = 12;  /* Do malloc and free output debug messages?
   #define DEBUG_ALLOC
 /* 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  /* What is our "Fake" Filedescriptor? */
    Resource Kit from Microsoft.  The resource kit was retrieved from the  static int fakeFD = 22881;
    following URL:  
  
    http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en  /*
  */     This hex data is the output of compress.exe (Windows Server 2003 Resource Kit)
  
      The cab file is mirrored in the file system as simple.cab
  
      The 'test.txt' in the cab file contains the string 'So long, and thanks for all the fish.'
   */
 static unsigned char compressed_file[] = static unsigned char compressed_file[] =
    {0x4D,0x53,0x43,0x46,0x00,0x00,0x00,0x00,0x75,0x00,    {0x4D,0x53,0x43,0x46,0x00,0x00,0x00,0x00,0x75,0x00,
         0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,         0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,
Line 74 
Line 75 
         0xD2,0x32,0x8B,0x33,0xF4,0xB8,0x00};         0xD2,0x32,0x8B,0x33,0xF4,0xB8,0x00};
 static int szcompressed_file = sizeof(compressed_file); static int szcompressed_file = sizeof(compressed_file);
  
   
  /*  /*
 static const char uncompressed_data[] = "This is a test file."; static const char uncompressed_data[] = "This is a test file.";
 static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1; static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1;
Line 81 
Line 83 
 static char *buf; static char *buf;
 */ */
  
 /*      To do in FDI:                           -from wine/include/fdi.h  /*
           To do in FDI:                           -from wine/include/fdi.h
         FDICreate         FDICreate
                 File Open                               -FNOPEN(pszFile,oflag,pmode)  
                 File Read                               -FNREAD(hf, pv, cb)  
                 File Write                              -FNWRITE(hf, pv, cb)                 File Write                              -FNWRITE(hf, pv, cb)
                 File Close                              -FNCLOSE(hf)  
                 File Seek                               -FNSEEK(hf,dist,seektype)                 File Seek                               -FNSEEK(hf,dist,seektype)
                 Error Structure                 Error Structure
         FDIlsCabinet  
                 FDICabinetInfo Structure  
         FDICopy         FDICopy
                 Notification function                 Notification function
                 Decryption function                 Decryption function
         FDIDestroy         FDIDestroy
 */ */
  
         FDICABINETINFO  fdici;  
   
   
 /* Currently mostly dummy function pointers */ /* Currently mostly dummy function pointers */
  
 FNALLOC(debug_alloc) {  #ifndef DEBUG_ALLOC
   FNALLOC(final_alloc) {
           return malloc(cb);
   }
   FNFREE(final_free) {
           free(pv);
           return;
   }
   #else
   FNALLOC(final_alloc) {
         printf("   FNALLOC just called with %d\n",cb);         printf("   FNALLOC just called with %d\n",cb);
         return malloc(cb);         return malloc(cb);
 } }
   FNFREE(final_free) {
 FNFREE(debug_free) {  
         printf("   FNFREE just called with %d\n",pv);         printf("   FNFREE just called with %d\n",pv);
         free(pv);         free(pv);
         return;         return;
 } }
   #endif
   
  
 /* /*
         It is not necessary for these functions to actually call _open etc.;         It is not necessary for these functions to actually call _open etc.;
Line 125 
Line 130 
 */ */
  
 /* /*
         http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open.2c_._wopen.asp          http://msdn.microsoft.com/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.         _open           I: const char *filename, int oflag, int pmode   O: int (handler), -1 for err.
           DUMMY  : FUNCTIONAL             FAKE : FUNCTIONAL               REAL : FUNCTIONAL
 */ */
  
 FNOPEN(dummy_open) { FNOPEN(dummy_open) {
Line 147 
Line 153 
         return handler;         return handler;
 } }
  
   
 /* /*
         http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open.2c_._wopen.asp          http://msdn.microsoft.com/library/en-us/vclib/html/_CRT__read.asp
         _read           I: int fd, void *buffer, unsigned int count             O:      int (szBuffer)         _read           I: int fd, void *buffer, unsigned int count             O:      int (szBuffer)
           DUMMY  : FUNCTIONAL             FAKE : FUNCTIONAL, INCOMPLETE           REAL : FUNCTIONAL
 */ */
  
 FNREAD(dummy_read) { FNREAD(dummy_read) {
Line 158 
Line 164 
         return 0;         return 0;
 } }
  
   /* Doesn't keep virtual file location pointer */
 FNREAD(fake_read) { FNREAD(fake_read) {
          printf("   FNREAD (fake) just called with %d, %d, %d\n",hf, pv, cb);          printf("   FNREAD (fake) just called with %d, %d, %d\n",hf, pv, cb);
          if (hf == fakeFD) {          if (hf == fakeFD) {
                  printf ("   Called with fake file descriptor, populating buffer and size (%d)\n",szcompressed_file);                  printf ("   Called with fake file descriptor, populating buffer and size (%d)\n",cb);
                  memcpy (pv, compressed_file ,cb);                  memcpy (pv, compressed_file ,cb);
                  /* TODO */  
                  }                  }
          else {          else {
                  printf ("   FNREAD (fake) was called with the unknown file handler. Failed!\n",hf);                  printf ("   FNREAD (fake) was called with the unknown file handler. Failed!\n",hf);
          }          }
         return szcompressed_file;          return cb;
 } }
  
 FNREAD(real_read) { FNREAD(real_read) {
Line 178 
Line 184 
         return szBuffer;         return szBuffer;
 } }
  
   /*
           http://msdn.microsoft.com/library/en-us/vclib/html/_CRT__close.asp
           _close          I: int fd   O:  int (0=success 1=failure)
           DUMMY  : FUNCTIONAL             FAKE : FUNCTIONAL               REAL : FUNCTIONAL
   */
  
   FNCLOSE(dummy_close) {
           printf("   FNCLOSE (dummy) just called with %d - returning %d\n",hf,0);
           return 0;
   }
  
 FNWRITE(dummy_write) {  FNCLOSE(fake_close) {
          printf("   FNWRITE just called with %d, %d, %d\n",hf, pv, cb);          printf("   FNCLOSE (fake) just called with %d - returning %d\n",hf,0);
         return 0;         return 0;
 } }
  
   FNCLOSE(real_close) {
           int closevalue = _close(hf);
           printf("   FNCLOSE (real) just called with %d - returning %d\n",hf,closevalue);
           return closevalue;
   }
   
  
 FNCLOSE(dummy_close) {  FNWRITE(dummy_write) {
          printf("   FNCLOSE just called with %d\n",hf);          printf("   FNWRITE just called with %d, %d, %d\n",hf, pv, cb);
         return 0;         return 0;
 } }
  
Line 197 
Line 218 
 } }
  
 HFDI hfdi_unknown_dummy, hfdi_unknown_fake,hfdi_unknown_real; HFDI hfdi_unknown_dummy, hfdi_unknown_fake,hfdi_unknown_real;
 FDICABINETINFO  fdi_cabinfo;  
 /* yes its global and ugly */ /* yes its global and ugly */
  
  
Line 208 
Line 228 
         printf("Starting TestCreate()\n");         printf("Starting TestCreate()\n");
  
         hfdi_unknown_dummy = FDICreate(         hfdi_unknown_dummy = FDICreate(
                 debug_alloc,                  final_alloc,
                 debug_free,                  final_free,
                 dummy_open,                 dummy_open,
                 dummy_read,                 dummy_read,
                 dummy_write,                 dummy_write,
Line 221 
Line 241 
         ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");         ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");
  
         hfdi_unknown_fake = FDICreate(         hfdi_unknown_fake = FDICreate(
                 debug_alloc,                  final_alloc,
                 debug_free,                  final_free,
                 fake_open,                 fake_open,
                 fake_read,                 fake_read,
                 dummy_write,                 dummy_write,
Line 234 
Line 254 
         ok(hfdi_unknown_fake != NULL,"FDICreate (CPU = unknown) (functions=fake) failed!\n");         ok(hfdi_unknown_fake != NULL,"FDICreate (CPU = unknown) (functions=fake) failed!\n");
  
         hfdi_unknown_real = FDICreate(         hfdi_unknown_real = FDICreate(
                 debug_alloc,                  final_alloc,
                 debug_free,                  final_free,
                 real_open,                 real_open,
                 real_read,                 real_read,
                 dummy_write,                 dummy_write,
                 dummy_close,                  real_close,
                 dummy_seek,                 dummy_seek,
                 cpuUNKNOWN,                 cpuUNKNOWN,
                 &error_structure                 &error_structure
Line 250 
Line 270 
 } }
  
 static void TestInfo(void) { static void TestInfo(void) {
           /* Noticed Behavior :
                   FDIIsCabinet does not open the file on its own, it requires a file open/close to be done externally.
                           WHY?
                   The only functions in HFDI that FDIIsCabinet directly accesses is FNREAD
                   Important cases to check :
                           If the filedescriptor == ERR, does it FAIL?                                                     (dummy_read)
                           If the filedescriptor == NOTCABINET, does it FAIL?                                      (fake_read, real_read)
                           If the filedescriptor == CABINET, does it SUCCEED?                                      (fake_read, real_read)
                           If the filedescriptor == CABINET, does it populate FDICABINETINFO?      (fake_read, real_read)
           */
   
         int realfd;         int realfd;
         int sizer;         int sizer;
         char *buffer = malloc(szcompressed_file);          FDICABINETINFO  fdi_cabinfo_dummy, fdi_cabinfo_simple, fdi_cabinfo_complex;
  
         printf("Starting TestInfo()\n");         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,          /* TEST : ERR filehandle associated, dummy functions should return FALSE */
                         "FDIIsCabinet (File = WrongType) failed!\n");          ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo_dummy) == FALSE,
                           "FDIIsCabinet (File = Error) failed!\n");
  
         sizer = fake_read ( 12,buffer,szcompressed_file );          /* TEST : Fake filehandle associated, memory manually copied, should return TRUE */
         printf(buffer);          ok ( FDIIsCabinet( hfdi_unknown_fake, fakeFD, &fdi_cabinfo_simple) == TRUE,
                           "FDIIsCabinet (FakeFile = Cabinet) failed!\n");
   
                   ok ( fdi_cabinfo_simple.cbCabinet == 117, "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
                   ok ( fdi_cabinfo_simple.cFolders == 1, "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
                   ok ( fdi_cabinfo_simple.cFiles == 1, "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
                   ok ( fdi_cabinfo_simple.setID == 12345, "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
                   ok ( fdi_cabinfo_simple.iCabinet == 0, "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
                   ok ( fdi_cabinfo_simple.fReserve == 'b', "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
                   ok ( fdi_cabinfo_simple.hasprev == 117, "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
                   ok ( fdi_cabinfo_simple.hasnext == 117, "FDIIsCabinet,cabinfo (FakeFile = Cabinet) data did not match! Failed!\n");
  
         realfd = real_open( "TEST1.cab" , _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, 0);          realfd = real_open( "working.cab" , _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, 0);
         ok ( FDIIsCabinet( hfdi_unknown_real, realfd, &fdi_cabinfo) == TRUE,          ok ( FDIIsCabinet( hfdi_unknown_real, realfd, &fdi_cabinfo_complex) == TRUE,
                         "FDIIsCabinet (File = Cabinet) failed!\n");                         "FDIIsCabinet (File = Cabinet) failed!\n");
           real_close(realfd);
  
           printf("Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %b hp %d hn %d\n,",
                           fdi_cabinfo_complex.cbCabinet,
                           fdi_cabinfo_complex.cFolders ,
                           fdi_cabinfo_complex.cFiles ,
                           fdi_cabinfo_complex.setID,
                           fdi_cabinfo_complex.iCabinet,
                           fdi_cabinfo_complex.fReserve ,
                           fdi_cabinfo_complex.hasprev ,
                           fdi_cabinfo_complex.hasnext );
  
 } }
  


Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

Rizwan Kassim
Powered by
ViewCVS 0.9.2