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

  1 rizwank 1.1 /*
  2              * Unit test suite for cabinet.dll - FDI functions
  3              *
  4 rizwank 2.5  * Copyright 2004 Rizwan Kassim, Dan Kegel, Alexander Liber
  5 rizwank 1.1  *
  6              * This library is free software; you can redistribute it and/or
  7              * modify it under the terms of the GNU Lesser General Public
  8              * License as published by the Free Software Foundation; either
  9              * version 2.1 of the License, or (at your option) any later version.
 10              *
 11              * This library is distributed in the hope that it will be useful,
 12              * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13              * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14              * Lesser General Public License for more details.
 15              *
 16              * You should have received a copy of the GNU Lesser General Public
 17              * License along with this library; if not, write to the Free Software
 18              * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 19              */
 20             
 21 rizwank 2.13 #include <stdio.h>
 22 rizwank 2.3  #include <stdlib.h>
 23              #include <string.h>
 24 rizwank 2.11 #include <stdarg.h>
 25 rizwank 2.13 #include <malloc.h>
 26               
 27              #include <stdarg.h>
 28              #include <stdio.h>
 29               
 30              #include "windef.h"
 31              #include "winbase.h"
 32              #include "winerror.h"
 33              #include "fdi.h"
 34 rizwank 2.15 
 35              #ifndef WIN_ENV 
 36              #include <msvcrt/fcntl.h>
 37              #include <msvcrt/sys/stat.h>
 38              #else
 39              #include <sys/stat.h>
 40 rizwank 2.13 #include <fcntl.h>
 41 rizwank 2.15 #endif
 42              
 43              #define VERBOSE
 44 rizwank 2.13 
 45              #include "tvfs.h"
 46 rizwank 2.15 #include "simplecab.h"
 47 rizwank 1.1  
 48              #ifndef STANDALONE
 49              #include <wine/test.h>
 50              #define ok2 ok
 51              #else
 52 rizwank 2.14 #include "standalone.h"
 53 rizwank 2.13 /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ -DWIN_ENV tvfs.c cabinet_fdi.c FDI.lib 
 54 rizwank 2.14   standalone.h is used if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */
 55 rizwank 1.1  #endif 
 56              
 57 rizwank 1.8  FNALLOC(final_alloc) {
 58 rizwank 2.11     trace("   FNALLOC just called with %d\n",cb);
 59                  return malloc(cb);
 60 rizwank 1.3  }
 61 rizwank 1.8  FNFREE(final_free) {
 62 rizwank 2.11     trace("   FNFREE just called with %d\n",pv);
 63                  free(pv);
 64                  return;
 65 rizwank 1.3  }
 66 rizwank 2.14 
 67 rizwank 2.10 /*Possible non trivial addition:
 68              Notify receives some information about the cab file(see FDI documentation). 
 69              Since this info is different depending on the value of fdint, and Notify should
 70              be generic, it is not simple or nice to check this information.
 71              */
 72 rizwank 2.3  FNFDINOTIFY(notification_function)
 73              {
 74 rizwank 2.11     trace("   FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin);
 75                  switch (fdint)
 76                  {
 77                      case fdintCABINET_INFO: 
 78                      {
 79                          trace(
 80                              "fdintCABINET_INFO:\n"
 81                              "-next cab name: %s\n"
 82                              "-next disk: %s\n"
 83                              "-path name: %s\n"
 84                              "-set ID: %d\n"
 85                              "-number in set: %d\n",
 86 rizwank 2.14                 pfdin->psz1, pfdin->psz2, pfdin->psz3, pfdin->setID, pfdin->iCabinet
 87 rizwank 2.11             );
 88                          return 0;
 89                      }
 90                      case fdintPARTIAL_FILE: 
 91                      {
 92                          trace("dintPARTIAL_FILE\n");    
 93                          
 94                          return 0;
 95                      }
 96                      case fdintCOPY_FILE:
 97                      {
 98                          int fih = 0;
 99                          char target[256];
100                          trace(
101                              "fdintCOPY_FILE:\n"
102                              "-name: %s\n"
103                              "-uncompressed size: %d\n"
104                              "-date: %d\n"
105                              "-time: %d\n"
106                              "-attributes: %d\n"
107                              "-file's folder index: %d\n",
108 rizwank 2.14                 pfdin->psz1, pfdin->cb, pfdin->date, pfdin->time, pfdin->attribs, pfdin->iFolder
109 rizwank 2.11             );
110                          sprintf(target, "./%s",pfdin->psz1);
111                          fih = tvfs_open (target,
112                              _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
113                              _S_IREAD | _S_IWRITE 
114                          );
115                          return fih;    
116                      }    
117                      case fdintCLOSE_FILE_INFO:    
118                      {
119 rizwank 2.12 #ifdef VERBOSE
120 rizwank 2.11             trace(
121                              "fdintCLOSE_FILE:\n"
122                              "-name: %s\n"
123                              "-handle: %d\n"
124                              "-date: %d\n"
125                              "-time: %d\n"
126                              "-attributes: %d\n"
127                              "-file's folder index: %d\n"
128                              "-run: %d\n",
129 rizwank 2.14                 pfdin->psz1, pfdin->hf, pfdin->date, pfdin->time, pfdin->attribs, pfdin->iFolder, pfdin->cb
130 rizwank 2.11             );
131 rizwank 2.12 #endif
132 rizwank 2.11     
133                          tvfs_close(pfdin->hf);
134                          return TRUE;
135                      }
136                      case fdintNEXT_CABINET: 
137                      {
138                          trace("fdintNEXT_CABINET\n");
139                          return 0;
140                      }
141                      case fdintENUMERATE:
142                      {
143                          trace("fdintENUMERATE\n");
144                          return 0;
145                      }
146                  }
147                  return 0;
148 rizwank 2.3  }
149 cs130_alex 2.1  
150 rizwank    2.3  static void printCabInfo(FDICABINETINFO  cabinfo){
151 rizwank    2.11     trace("   Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
152                         cabinfo.cbCabinet,
153                         cabinfo.cFolders ,
154                         cabinfo.cFiles ,
155                         cabinfo.setID,
156                         cabinfo.iCabinet,
157                         cabinfo.fReserve ,
158                         cabinfo.hasprev ,
159                         cabinfo.hasnext );
160 rizwank    2.7  }
161 cs130_alex 2.1  
162 cs130_alex 2.2  static void CheckCabInfo(char *  cabname,
163 rizwank    2.11     FDICABINETINFO cabinfo, 
164                     long    TcbCabinet,
165                     USHORT    TcFolders,    
166                     USHORT    TcFiles,    
167                     USHORT    TsetID,    
168                     USHORT    TiCabinet,    
169                     BOOL    TfReserve,    
170                     BOOL    Thasprev,    
171                     BOOL    Thasnext){
172                     ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
173                     ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
174                     ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
175                     ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
176                     ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
177                     ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
178                     ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
179                     ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
180                    }
181 rizwank    2.14    /* TODO :  Message should contain variable values */
182 rizwank    2.11 
183 rizwank    2.15 static HFDI hfdi_simple;
184 rizwank    1.4  /* yes its global and ugly */
185                 
186 rizwank    1.1  
187 rizwank    1.4  static void TestCreate(void) {
188 rizwank    2.11     
189                     ERF error_structure;
190                     
191                     trace("Starting TestCreate()\n");
192 rizwank    2.15     /* Is CPU386 or Unknown more commonly used? */
193                     hfdi_simple = FDICreate(
194 rizwank    2.11         final_alloc,
195                         final_free, 
196                         tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
197                         cpuUNKNOWN,
198                         &error_structure
199                     );
200                 
201 rizwank    2.15     ok(hfdi_simple != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");    
202 rizwank    2.11     
203                     trace("Ending TestCreate()\n");    
204 rizwank    1.7  }
205                 
206                 static void TestInfo(void) {
207 rizwank    2.11 
208                     int fd;
209                     
210 rizwank    2.15     FDICABINETINFO  fdi_cabinfo_simple;
211 rizwank    2.11     
212                     trace("Starting TestInfo()\n");
213                 
214                     tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
215                     fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
216                 
217 rizwank    2.15     ok( FDIIsCabinet( hfdi_simple, fd, &fdi_cabinfo_simple) == TRUE,
218 rizwank    2.11     "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
219                     
220                     printCabInfo(fdi_cabinfo_simple);
221                     CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);    
222                     
223                     tvfs_close(fd); 
224                     tvfs_free();    
225                     
226                     trace("Ending TestInfo()\n");
227 rizwank    1.7  }
228 cs130_alex 2.1  
229 rizwank    2.3  static void TestCopy(void){
230 rizwank    2.11     
231                     char name_file_path[256];
232                     int result;
233                     
234                     trace("Starting TestCopy()\n");
235                     trace("---simple.cab\n");
236                 
237                     tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
238 rizwank    2.15     FDICopy(hfdi_simple,
239 rizwank    2.11         "simple.cab",
240                         "",
241                         0,
242                         notification_function,
243                         NULL,
244                         NULL);
245                 
246                     /* Filename when extracted is ./<filename> */
247                     sprintf(name_file_path, "./%s", name_simple_txt);
248                     result = tvfs_compare(name_file_path, file_simple_txt, size_simple_txt);
249                     if (result)
250                         trace ("File %s compare failed!\n",name_file_path);    
251                     tvfs_free();
252                     
253                     trace("Ending TestCopy()\n");   
254 cs130_alex 2.1  }
255                 
256 rizwank    1.7  static void TestDestroy(void) {
257 rizwank    2.11     trace("Starting TestDestroy()\n");
258 rizwank    2.15     ok(FDIDestroy(hfdi_simple), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");  
259 rizwank    2.11     trace("Ending TestDestroy()\n");
260 rizwank    1.4  }
261 rizwank    1.1  
262 rizwank    2.13 START_TEST(cabinet_fdi)
263 rizwank    1.1  {
264 rizwank    2.11     TestCreate();
265                     TestInfo();
266                     TestCopy();
267                     TestDestroy();
268                     tvfs_free();
269 rizwank    1.1  }

Rizwan Kassim
Powered by
ViewCVS 0.9.2