(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.8 and 2.15

version 1.8, 2005/02/11 09:56:01 version 2.15, 2005/03/18 00:28:59
Line 1 
Line 1 
 /* /*
  * 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
Line 18 
Line 18 
  * 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 <winerror.h>  #include "windef.h"
 #include <fdi.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> #include <fcntl.h>
   #endif
  
 /* Do malloc and free output debug messages?  #define VERBOSE
 #define DEBUG_ALLOC  
 */  
   
 /* What is our "Fake" Filedescriptor? */  
 static int fakeFD = 22881;  
   
 /*  
    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[] =  
    {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  
         FDICreate  
                 File Write                              -FNWRITE(hf, pv, cb)  
                 File Seek                               -FNSEEK(hf,dist,seektype)  
                 Error Structure  
         FDICopy  
                 Notification function  
                 Decryption function  
         FDIDestroy  
 */  
  
 /* Currently mostly dummy function pointers */  #include "tvfs.h"
   #include "simplecab.h"
  
 #ifndef DEBUG_ALLOC  #ifndef STANDALONE
 FNALLOC(final_alloc) {  #include <wine/test.h>
         return malloc(cb);  #define ok2 ok
 }  
 FNFREE(final_free) {  
         free(pv);  
         return;  
 }  
 #else #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(final_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(final_free) {
         printf("   FNFREE just called with %d\n",pv);      trace("   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.;  
         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.  /*Possible non trivial addition:
   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.
 /*  
         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.  
         DUMMY  : FUNCTIONAL             FAKE : FUNCTIONAL               REAL : FUNCTIONAL  
 */ */
   FNFDINOTIFY(notification_function)
 FNOPEN(dummy_open) {  {
         printf("  FNOPEN (dummy) 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");
  
 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/en-us/vclib/html/_CRT__read.asp  
         _read           I: int fd, void *buffer, unsigned int count             O:      int (szBuffer)  
         DUMMY  : FUNCTIONAL             FAKE : FUNCTIONAL, INCOMPLETE           REAL : FUNCTIONAL  
 */  
   
 FNREAD(dummy_read) {  
         printf("   FNREAD (dummy) just called with %d, %d, %d\n",hf, pv, cb);  
         return 0;         return 0;
 } }
           case fdintCOPY_FILE:
 /* Doesn't keep virtual file location pointer */          {
 FNREAD(fake_read) {              int fih = 0;
         printf("   FNREAD (fake) just called with %d, %d, %d\n",hf, pv, cb);              char target[256];
         if (hf == fakeFD) {              trace(
                 printf ("   Called with fake file descriptor, populating buffer and size (%d)\n",cb);                  "fdintCOPY_FILE:\n"
                 memcpy (pv, compressed_file ,cb);                  "-name: %s\n"
                 }                  "-uncompressed size: %d\n"
         else {                  "-date: %d\n"
                 printf ("   FNREAD (fake) was called with the unknown file handler. Failed!\n",hf);                  "-time: %d\n"
         }                  "-attributes: %d\n"
         return cb;                  "-file's folder index: %d\n",
 }                  pfdin->psz1, pfdin->cb, pfdin->date, pfdin->time, pfdin->attribs, pfdin->iFolder
               );
 FNREAD(real_read) {              sprintf(target, "./%s",pfdin->psz1);
         int szBuffer = _read(hf,pv,cb);              fih = tvfs_open (target,
         printf("   FNREAD (read) just called with %d, %d, %d\n",hf, pv, cb);                  _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
         printf("   FNREAD (read) returning size (%d)\n",szBuffer);                  _S_IREAD | _S_IWRITE
         return szBuffer;              );
               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
  
 /*              tvfs_close(pfdin->hf);
         http://msdn.microsoft.com/library/en-us/vclib/html/_CRT__close.asp              return TRUE;
         _close          I: int fd   O:  int (0=success 1=failure)          }
         DUMMY  : FUNCTIONAL             FAKE : FUNCTIONAL               REAL : FUNCTIONAL          case fdintNEXT_CABINET:
 */          {
               trace("fdintNEXT_CABINET\n");
 FNCLOSE(dummy_close) {  
         printf("   FNCLOSE (dummy) just called with %d - returning %d\n",hf,0);  
         return 0;         return 0;
 } }
           case fdintENUMERATE:
 FNCLOSE(fake_close) {          {
         printf("   FNCLOSE (fake) just called with %d - returning %d\n",hf,0);              trace("fdintENUMERATE\n");
         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;  
 } }
   
   
 FNWRITE(dummy_write) {  
         printf("   FNWRITE just called with %d, %d, %d\n",hf, pv, cb);  
         return 0;         return 0;
 } }
  
 FNSEEK(dummy_seek) {  static void printCabInfo(FDICABINETINFO  cabinfo){
         printf("   FNSEEK just called with %d, %d, %d\n",hf, dist, seektype);      trace("   Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
         return 0;          cabinfo.cbCabinet,
           cabinfo.cFolders ,
           cabinfo.cFiles ,
           cabinfo.setID,
           cabinfo.iCabinet,
           cabinfo.fReserve ,
           cabinfo.hasprev ,
           cabinfo.hasnext );
   }
   
   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 */
  
 HFDI hfdi_unknown_dummy, hfdi_unknown_fake,hfdi_unknown_real;  static HFDI hfdi_simple;
 /* yes its global and ugly */ /* yes its global and ugly */
  
  
Line 225 
Line 188 
  
         ERF error_structure;         ERF error_structure;
  
         printf("Starting TestCreate()\n");      trace("Starting TestCreate()\n");
       /* Is CPU386 or Unknown more commonly used? */
         hfdi_unknown_dummy = FDICreate(      hfdi_simple = FDICreate(
                 final_alloc,                 final_alloc,
                 final_free,                 final_free,
                 dummy_open,          tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
                 dummy_read,  
                 dummy_write,  
                 dummy_close,  
                 dummy_seek,  
                 cpuUNKNOWN,                 cpuUNKNOWN,
                 &error_structure                 &error_structure
         );         );
         ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");  
  
         hfdi_unknown_fake = FDICreate(      ok(hfdi_simple != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
                 final_alloc,  
                 final_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(      trace("Ending TestCreate()\n");
                 final_alloc,  
                 final_free,  
                 real_open,  
                 real_read,  
                 dummy_write,  
                 real_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) { 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 fd;
         int sizer;  
         FDICABINETINFO  fdi_cabinfo_dummy, fdi_cabinfo_simple, fdi_cabinfo_complex;      FDICABINETINFO  fdi_cabinfo_simple;
   
         printf("Starting TestInfo()\n");      trace("Starting TestInfo()\n");
   
         /* TEST : ERR filehandle associated, dummy functions should return FALSE */      tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
         ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo_dummy) == FALSE,      fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
                         "FDIIsCabinet (File = Error) failed!\n");  
       ok( FDIIsCabinet( hfdi_simple, fd, &fdi_cabinfo_simple) == TRUE,
         /* TEST : Fake filehandle associated, memory manually copied, should return TRUE */      "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
         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( "working.cab" , _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, 0);  
         ok ( FDIIsCabinet( hfdi_unknown_real, realfd, &fdi_cabinfo_complex) == TRUE,  
                         "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 );  
  
       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");
 } }
  
   static void TestCopy(void){
  
 static void TestDestroy(void) {      char name_file_path[256];
         printf("Starting TestDestroy()\n");      int result;
                 /* Only two things to check in FDIDestroy  
         1=> Does it return T if its passed an hfdi      trace("Starting TestCopy()\n");
         2=> Does it return F if its passed a non hfdi      trace("---simple.cab\n");
                 EDIT : Causes GPL if FDIDestroy is called on an invalid pointer.  
                 ok( 0 == FDIDestroy(0), "Return true incorrectly in TestDestroy()!\n");      tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
                 */      FDICopy(hfdi_simple,
           "simple.cab",
           "",
           0,
           notification_function,
           NULL,
           NULL);
  
         ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");      /* Filename when extracted is ./<filename> */
         ok(FDIDestroy(hfdi_unknown_fake), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");      sprintf(name_file_path, "./%s", name_simple_txt);
         printf("Ending TestDestroy()\n");      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(paths)  START_TEST(cabinet_fdi)
 { {
   
         TestCreate();         TestCreate();
         TestInfo();         TestInfo();
         /*  
         TestCopy();         TestCopy();
         */  
         TestDestroy();         TestDestroy();
       tvfs_free();
 } }


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

Rizwan Kassim
Powered by
ViewCVS 0.9.2