(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 2.12

version 1.7, 2005/02/11 08:50:58 version 2.12, 2005/03/01 07:25:39
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 19 
Line 19 
  */  */
  
 #include <stdlib.h> #include <stdlib.h>
   #include <string.h>
   #include <sys/stat.h>
   #include <stdarg.h>
  
 #ifndef STANDALONE #ifndef STANDALONE
 #include <wine/test.h> #include <wine/test.h>
 #define ok2 ok #define ok2 ok
 #else #else
 /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ cabinet_fdi.c FDI.lib  /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ tvfs.c 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 */   These are only called if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */
 #include <assert.h> #include <assert.h>
 #include <stdio.h> #include <stdio.h>
Line 40 
Line 43 
                 exit(1);         \                 exit(1);         \
         } } while(0)         } } while(0)
 #define todo_wine #define todo_wine
   
   static void trace(const char *s, ...)
   {
       va_list ellipsis;
       va_start (ellipsis, s);
       vprintf(s, ellipsis);
       va_end(ellipsis);
   }
   
 #endif #endif
  
 #include <winerror.h> #include <winerror.h>
 #include <fdi.h> #include <fdi.h>
 #include <fcntl.h> #include <fcntl.h>
   #include "tvfs.h"
   #include "data.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  #define VERBOSE
    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  #ifndef DEBUG_ALLOC
         FDICreate  FNALLOC(final_alloc) {
                 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  
 */  
   
         FDICABINETINFO  fdici;  
   
   
 /* Currently mostly dummy function pointers */  
   
 FNALLOC(debug_alloc) {  
         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);  
         free(pv);         free(pv);
         return;         return;
 } }
   #else
 /*  FNALLOC(final_alloc) {
         It is not necessary for these functions to actually call _open etc.;      trace("   FNALLOC just called with %d\n",cb);
         these functions could instead call fopen, fread, fwrite, fclose, and fseek,      return malloc(cb);
         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;  
 } }
   FNFREE(final_free) {
 FNOPEN(real_open) {      trace("   FNFREE just called with %d\n",pv);
         int handler = _open(pszFile,oflag,pmode);      free(pv);
         printf("   FNOPEN (real) just called with %s, %d, %d\n",pszFile, oflag, pmode);      return;
         printf("   FNOPEN (real) returning handler (%d)\n",handler);  
         return handler;  
 } }
   #endif
   /*Possible non trivial addition:
 /*  Notify receives some information about the cab file(see FDI documentation).
         http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open.2c_._wopen.asp  Since this info is different depending on the value of fdint, and Notify should
         _read           I: int fd, void *buffer, unsigned int count             O:      int (szBuffer)  be generic, it is not simple or nice to check this information.
 */ */
   FNFDINOTIFY(notification_function)
   {
   #ifdef VERBOSE
       trace("   FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin);
   #endif
       switch (fdint)
       {
           case fdintCABINET_INFO:
           {
   #ifdef VERBOSE
               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
               );
   #endif
               return 0;
           }
           case fdintPARTIAL_FILE:
           {
   #ifdef VERBOSE
               trace("dintPARTIAL_FILE\n");
   #endif
  
 FNREAD(dummy_read) {  
          printf("   FNREAD (dummy) just called with %d, %d, %d\n",hf, pv, cb);  
         return 0;         return 0;
 } }
           case fdintCOPY_FILE:
           {
               int fih = 0;
               char target[256];
   #ifdef VERBOSE
               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
               );
   #endif
               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:
           {
               char filebuf[256];
               int result;
   #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
  
 FNREAD(fake_read) {              tvfs_close(pfdin->hf);
          printf("   FNREAD (fake) just called with %d, %d, %d\n",hf, pv, cb);              return TRUE;
          if (hf == fakeFD) {  
                  printf ("   Called with fake file descriptor, populating buffer and size (%d)\n",szcompressed_file);  
                  memcpy (pv, compressed_file ,cb);  
                  /* TODO */  
                  }                  }
          else {          case fdintNEXT_CABINET:
                  printf ("   FNREAD (fake) was called with the unknown file handler. Failed!\n",hf);          {
   #ifdef VERBOSE
               trace("fdintNEXT_CABINET\n");
   #endif
               return 0;
          }          }
         return szcompressed_file;          case fdintENUMERATE:
           {
   #ifdef VERBOSE
               trace("fdintENUMERATE\n");
   #endif
               return 0;
 } }
   
 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;         return 0;
 } }
  
   static void printCabInfo(FDICABINETINFO  cabinfo){
 FNCLOSE(dummy_close) {  #ifdef VERBOSE
          printf("   FNCLOSE just called with %d\n",hf);      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 );
   #endif
 } }
  
 FNSEEK(dummy_seek) {  static void CheckCabInfo(char *  cabname,
          printf("   FNSEEK just called with %d, %d, %d\n",hf, dist, seektype);      FDICABINETINFO cabinfo,
         return 0;      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);
 } }
  
 HFDI hfdi_unknown_dummy, hfdi_unknown_fake,hfdi_unknown_real;  static HFDI hfdi_unknown;
 FDICABINETINFO  fdi_cabinfo;  
 /* yes its global and ugly */ /* yes its global and ugly */
  
   /* Is CPU386 or Unknown more commonly used? */
  
 static void TestCreate(void) { static void TestCreate(void) {
  
         ERF error_structure;         ERF error_structure;
  
         printf("Starting TestCreate()\n");      trace("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(      hfdi_unknown = FDICreate(
                 debug_alloc,          final_alloc,
                 debug_free,          final_free,
                 fake_open,          tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
                 fake_read,  
                 dummy_write,  
                 dummy_close,  
                 dummy_seek,  
                 cpuUNKNOWN,                 cpuUNKNOWN,
                 &error_structure                 &error_structure
         );         );
         ok(hfdi_unknown_fake != NULL,"FDICreate (CPU = unknown) (functions=fake) failed!\n");  
  
         hfdi_unknown_real = FDICreate(      ok(hfdi_unknown != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
                 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");      trace("Ending TestCreate()\n");
 } }
  
 static void TestInfo(void) { static void TestInfo(void) {
         int realfd;  
         int sizer;  
         char *buffer = malloc(szcompressed_file);  
  
         printf("Starting TestInfo()\n");      int fd;
                 /*  
                 1=> Does it return T (and fill FDICABINETINFO) if the file descriptor=>cabinet?      FDICABINETINFO  fdi_cabinfo_simple, fdi_cabinfo_complex;
                 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?      trace("Starting TestInfo()\n");
                                 */  
         ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo) == FALSE,  
                         "FDIIsCabinet (File = Error) failed!\n");  
  
         ok ( FDIIsCabinet( hfdi_unknown_fake, fakeFD, &fdi_cabinfo) == FALSE,      tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
                         "FDIIsCabinet (File = WrongType) failed!\n");      fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
  
         sizer = fake_read ( 12,buffer,szcompressed_file );      ok( FDIIsCabinet( hfdi_unknown, fd, &fdi_cabinfo_simple) == TRUE,
         printf(buffer);      "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
  
         realfd = real_open( "TEST1.cab" , _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, 0);      printCabInfo(fdi_cabinfo_simple);
         ok ( FDIIsCabinet( hfdi_unknown_real, realfd, &fdi_cabinfo) == TRUE,      CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);
                         "FDIIsCabinet (File = Cabinet) failed!\n");  
  
       tvfs_close(fd);
  
       tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
       fd = tvfs_open( name_complex_cab, _O_BINARY, 0 );
   
       ok( FDIIsCabinet( hfdi_unknown, fd, &fdi_cabinfo_complex) == TRUE,
       "FDIIsCabinet (Virtual File = Complex.cab) failed!\n");
   
       printCabInfo(fdi_cabinfo_complex);
       CheckCabInfo("complex.cab",fdi_cabinfo_complex,12918,1,2,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  
            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");      trace("Starting TestCopy()\n");
         ok(FDIDestroy(hfdi_unknown_fake), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");      trace("---simple.cab\n");
         printf("Ending TestDestroy()\n");  
  
       tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
       FDICopy(hfdi_unknown,
           "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("---complex.cab\n");
       tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
       FDICopy(hfdi_unknown,
           "complex.cab",
           "",
           0,
           notification_function,
           NULL,
           NULL);
   
       /* Filename when extracted is ./<filename> */
       sprintf(name_file_path, "./%s", name_README);
       result = tvfs_compare(name_file_path, file_README, size_README);
       if (result)
           trace ("File %s compare failed!\n",name_file_path);
   
       sprintf(name_file_path, "./%s", name_lgpl_txt);
       result = tvfs_compare(name_file_path, file_lgpl_txt, size_lgpl_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_unknown), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");
       trace("Ending TestDestroy()\n");
   }
  
 START_TEST(paths) START_TEST(paths)
 { {
   
         TestCreate();         TestCreate();
         TestInfo();         TestInfo();
         /*  
         TestCopy();         TestCopy();
         */  
         TestDestroy();         TestDestroy();
       tvfs_free();
 } }


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

Rizwan Kassim
Powered by
ViewCVS 0.9.2