(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.3 and 2.7

version 1.3, 2005/02/04 09:17:22 version 2.7, 2005/02/26 04:24:51
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 <stdlib.h> #include <stdlib.h>
   #include <string.h>
   #include <sys/stat.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 43 
Line 44 
 #define todo_wine #define todo_wine
 #endif #endif
  
   #define TVFS
  
 #include <winerror.h> #include <winerror.h>
 #include <fdi.h> #include <fdi.h>
   #include <fcntl.h>
   #include "tvfs.h"
   #include "data.h"
  
 /*      To do in FDI:                           -from wine/include/fdi.h  /* Do malloc and free output debug messages?
         FDICreate  #define DEBUG_ALLOC
                 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 dummy function pointers */  #ifndef DEBUG_ALLOC
   FNALLOC(final_alloc) {
 FNALLOC(dummy_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 0;          return malloc(cb);
 } }
   FNFREE(final_free) {
 FNFREE(dummy_free) {  
         printf("FNFREE just called with %d\n",pv);         printf("FNFREE just called with %d\n",pv);
           free(pv);
         return;         return;
 } }
   #endif
   
  
 FNOPEN(dummy_open) { FNOPEN(dummy_open) {
          printf("FNOPEN just called with %d, %d, %d\n",pszFile, oflag, pmode);          printf("  FNOPEN (dummy) just called with %d, %d, %d\n",pszFile, oflag, pmode);
         return 0;         return 0;
 } }
  
 FNREAD(dummy_read) { FNREAD(dummy_read) {
 /*       printf("FNREAD just called with %d, %d, %d\n",hf, pv, cb);          printf("   FNREAD (dummy) just called with %d, %d, %d\n",hf, pv, cb);
          return void;          return 0;
 */      return 0;  }
   
   FNCLOSE(dummy_close) {
           printf("   FNCLOSE (dummy) just called with %d - returning %d\n",hf,0);
           return 0;
 } }
  
 FNWRITE(dummy_write) { FNWRITE(dummy_write) {
 /*       printf("FNWRITE just called with %d, %d, %d\n",hf, pv, cb);          printf("   FNWRITE just called with %d, %d, %d\n",hf, pv, cb);
          return void;          return 0;
 */      return 0;  
 } }
  
   FNSEEK(dummy_seek) {
           printf("   FNSEEK just called with %d, %d, %d\n",hf, dist, seektype);
           return 0;
   }
  
 FNCLOSE(dummy_close) {  FNFDINOTIFY(dummy_notification){
 /*       printf("FNCLOSE just called with %d\n",hf);          printf("   FNFDINOTIFY just called with %d, %d \n",fdint,pfdin);
         return void;          return 0;
 */      return 0;  
 } }
  
 FNSEEK(dummy_seek) {  FNFDINOTIFY(notification_function)
 /*       printf("FNSEEK just called with %d, %d, %d\n",hf, dist, seektype);  {
         return void;          printf("   FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin);
 */      return 0;          switch (fdint)
           {
                   case fdintCABINET_INFO:
                   {
                           printf("fdintCABINET_INFO\n");
                           return 0;
                   }
                   case fdintPARTIAL_FILE:
                   {
                           printf("dintPARTIAL_FILE\n");
                           return 0;
 } }
                   case fdintCOPY_FILE:
                   {
                           int fih = 0;
                           char target[256];
  
 static void TestDestroy(void) {                          printf("fdintCOPY_FILE\n");
         /* Only two things to check in FDIDestroy                          printf("  file name: %s\n",     pfdin->psz1);
            1=> Does it return T if its passed an hfdi                          sprintf(target, "./%s",pfdin->psz1);
            2=> Does it return F if its passed a non hfdi                          printf("%s\n",target);
         */  #ifdef TVFS
                                   fih = tvfs_open (target,
                                           _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
                                           _S_IREAD | _S_IWRITE
                                                                   );
                           return fih;
   #else
                                   fih = real_open (target,
                                           _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
                                           _S_IREAD | _S_IWRITE
                                                                   );
                           return fih;
   #endif
                   }
                   case fdintCLOSE_FILE_INFO:
                   {
                           char filebuf[256];
                           int result;
  
         ok( 0 == FDIDestroy(0), "Return true incorrectly in TestDestroy()!\n");  
         /*          printf("Testing direct file compare and lseek of %s\n", name_simple_txt);
                 TODO : check if its passed an hfdi          printf("Reading and comparing file\n");
                 */          result = tvfs_read(7, filebuf, size_simple_txt);
           result = tvfs_compare( filebuf , file_simple_txt, size_simple_txt);
           if (result)
                   printf ("File compare failed!\n");
   
                           return 0;
                   }
                   case fdintNEXT_CABINET:
                   {
   
                           printf("fdintNEXT_CABINET\n");
                           return 0;
                   }
                   case fdintENUMERATE:
                   {
                                   printf("fdintENUMERATE\n");
                                   return 0;
                   }
 } }
           return 0;
   }
   
   static void printCabInfo(FDICABINETINFO  cabinfo){
                   printf("   Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
                   cabinfo.cbCabinet,
                   cabinfo.cFolders ,
                   cabinfo.cFiles ,
                   cabinfo.setID,
                   cabinfo.iCabinet,
                   cabinfo.fReserve ,
                   cabinfo.hasprev ,
                   cabinfo.hasnext );
   }
   #ifndef TVFS
   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;
   }
   FNCLOSE(real_close) {
           int closevalue = _close(hf);
           printf("   FNCLOSE (real) just called with %d - returning %d\n",hf,closevalue);
           return closevalue;
   }
   
   FNWRITE(real_write) {
           int write_value = _write(hf, pv, cb);
           printf("   FNWRITE just called with %d, %d, %d - returning %d\n",hf, pv, cb, write_value);
           return write_value;
   }
   
   FNSEEK(real_seek) {
           long lseek_value = _lseek(hf, dist, seektype);
           printf("   FNSEEK just called with %d, %d, %d - returning %d\n",hf, dist, seektype,lseek_value);
           return lseek_value;
   }
   
   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;
   }
   #endif
   
   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);
                                                   }
   HFDI hfdi_unknown_dummy, hfdi_unknown_tvfs;
   /* yes its global and ugly */
   
   /* Is CPU386 or Unknown more commonly used? */
   
   static void TestCreate(void) {
   
           ERF error_structure;
   
           printf("Starting TestCreate()\n");
   
           hfdi_unknown_dummy = FDICreate(
                   final_alloc,
                   final_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_tvfs = FDICreate(
                   final_alloc,
                   final_free,
   #ifdef TVFS
                   tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
   #else
                   real_open, real_read, real_write, real_close,real_seek,
   #endif
                   cpuUNKNOWN,
                   &error_structure
           );
           ok(hfdi_unknown_tvfs != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
   
           printf("Ending TestCreate()\n");
   }
   
   static void TestInfo(void) {
   #ifdef TVFS
           int fd;
   
           FDICABINETINFO  fdi_cabinfo_dummy, fdi_cabinfo_simple, fdi_cabinfo_complex;
  
           printf("Starting TestInfo()\n");
   
           /* TEST : ERR filehandle associated, dummy functions should return FALSE */
           ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo_dummy) == FALSE,
                           "FDIIsCabinet (File = Error) failed!\n");
   
   
           tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
           fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
   
           ok( FDIIsCabinet( hfdi_unknown_tvfs, 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_create( name_complex_cab, file_complex_cab, size_complex_cab);
           fd = tvfs_open( name_complex_cab, _O_BINARY, 0 );
   
           ok( FDIIsCabinet( hfdi_unknown_tvfs, 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);
   
           printf("Ending TestInfo()\n");
   #endif
   }
   
   static void TestCopy(void){
           printf("Starting TestCopy()\n");
           printf("---simple.cab\n");
           FDICopy(hfdi_unknown_tvfs,
                           "complex.cab",
                           "",
                           0,
                           notification_function,
                           NULL,
                           NULL);
   
           printf("Ending TestCopy()\n");
   }
   
   static void TestDestroy(void) {
           printf("Starting TestDestroy()\n");
   
           ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");
           ok(FDIDestroy(hfdi_unknown_tvfs), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");
           printf("Ending TestDestroy()\n");
   }
  
 START_TEST(paths) START_TEST(paths)
 { {
         /*  
         TestCreate();         TestCreate();
         TestInfo();         TestInfo();
         TestCopy();         TestCopy();
         */  
         TestDestroy();         TestDestroy();
           tvfs_free();
 } }


Legend:
Removed from v.1.3  
changed lines
  Added in v.2.7

Rizwan Kassim
Powered by
ViewCVS 0.9.2