(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 cs130_alex 2.2  #include <sys/stat.h>
 25 rizwank    2.11 #include <stdarg.h>
 26 rizwank    2.13 #include <malloc.h>
 27                  
 28                 #include <stdarg.h>
 29                 #include <stdio.h>
 30                  
 31                 #include "windef.h"
 32                 #include "winbase.h"
 33                 #include "winerror.h"
 34                 #include "fdi.h"
 35                  
 36                 #ifndef WIN_ENV
 37                 #include <msvcrt/fcntl.h>
 38                 #else
 39                 #include <fcntl.h>
 40                 #endif
 41                 
 42                 #include "tvfs.h"
 43                 #include "data.h"
 44 rizwank    1.1  
 45                 #ifndef STANDALONE
 46                 #include <wine/test.h>
 47 rizwank    2.13 #define _S_IREAD  0x0100
 48                 #define _S_IWRITE 0x0080
 49 rizwank    1.1  #define ok2 ok
 50                 #else
 51 rizwank    2.13 /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ -DWIN_ENV tvfs.c cabinet_fdi.c FDI.lib 
 52 rizwank    1.1    These are only called if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */
 53                 #include <assert.h> 
 54 rizwank    2.13 
 55 rizwank    1.1  #define START_TEST(name) main(int argc, char **argv)
 56 rizwank    2.11 #define ok(condition, msg)    \
 57                     do { if(!(condition)) {  \
 58 rizwank    2.12         fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__); \
 59 rizwank    2.11     exit(1);    \
 60                     } } while(0)
 61 rizwank    1.1  #define ok2(condition, msg, arg) \
 62 rizwank    2.11     do { if(!(condition)) {  \
 63 rizwank    2.12         fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__, arg); \
 64 rizwank    2.11     exit(1);    \
 65                     } } while(0)
 66 rizwank    1.1  #define todo_wine
 67 rizwank    2.11 
 68                 static void trace(const char *s, ...)
 69                 {
 70 rizwank    2.12     va_list ellipsis;
 71                     va_start (ellipsis, s);
 72                     vprintf(s, ellipsis);
 73                     va_end(ellipsis);
 74 rizwank    2.11 }
 75                 
 76 rizwank    1.1  #endif 
 77                 
 78 rizwank    1.8  /* Do malloc and free output debug messages? 
 79                 #define DEBUG_ALLOC
 80 rizwank    2.11 #define VERBOSE
 81 rizwank    1.8  */
 82 rizwank    1.7  
 83 rizwank    1.8  #ifndef DEBUG_ALLOC
 84                 FNALLOC(final_alloc) {
 85 rizwank    2.11     return malloc(cb);
 86 rizwank    1.8  }
 87                 FNFREE(final_free) {
 88 rizwank    2.11     free(pv);
 89                     return;
 90 rizwank    1.8  }
 91                 #else
 92                 FNALLOC(final_alloc) {
 93 rizwank    2.11     trace("   FNALLOC just called with %d\n",cb);
 94                     return malloc(cb);
 95 rizwank    1.3  }
 96 rizwank    1.8  FNFREE(final_free) {
 97 rizwank    2.11     trace("   FNFREE just called with %d\n",pv);
 98                     free(pv);
 99                     return;
100 rizwank    1.3  }
101 rizwank    1.8  #endif
102 rizwank    2.10 /*Possible non trivial addition:
103                 Notify receives some information about the cab file(see FDI documentation). 
104                 Since this info is different depending on the value of fdint, and Notify should
105                 be generic, it is not simple or nice to check this information.
106                 */
107 rizwank    2.3  FNFDINOTIFY(notification_function)
108                 {
109 rizwank    2.12 #ifdef VERBOSE
110 rizwank    2.11     trace("   FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin);
111 rizwank    2.12 #endif
112 rizwank    2.11     switch (fdint)
113                     {
114                         case fdintCABINET_INFO: 
115                         {
116 rizwank    2.12 #ifdef VERBOSE
117 rizwank    2.11             trace(
118                                 "fdintCABINET_INFO:\n"
119                                 "-next cab name: %s\n"
120                                 "-next disk: %s\n"
121                                 "-path name: %s\n"
122                                 "-set ID: %d\n"
123                                 "-number in set: %d\n",
124                                 pfdin->psz1,
125                                 pfdin->psz2,
126                                 pfdin->psz3,
127                                 pfdin->setID,
128                                 pfdin->iCabinet
129                             );
130 rizwank    2.12 #endif
131 rizwank    2.11             return 0;
132                         }
133                         case fdintPARTIAL_FILE: 
134                         {
135 rizwank    2.12 #ifdef VERBOSE
136 rizwank    2.11             trace("dintPARTIAL_FILE\n");    
137 rizwank    2.12 #endif
138 rizwank    2.11             
139                             return 0;
140                         }
141                         case fdintCOPY_FILE:
142                         {
143                             int fih = 0;
144                             char target[256];
145 rizwank    2.12 #ifdef VERBOSE
146 rizwank    2.11             trace(
147                                 "fdintCOPY_FILE:\n"
148                                 "-name: %s\n"
149                                 "-uncompressed size: %d\n"
150                                 "-date: %d\n"
151                                 "-time: %d\n"
152                                 "-attributes: %d\n"
153                                 "-file's folder index: %d\n",
154                                 pfdin->psz1,
155                                 pfdin->cb,
156                                 pfdin->date,
157                                 pfdin->time,
158                                 pfdin->attribs,
159                                 pfdin->iFolder
160                             );
161 rizwank    2.12 #endif
162 rizwank    2.11             sprintf(target, "./%s",pfdin->psz1);
163                             fih = tvfs_open (target,
164                                 _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
165                                 _S_IREAD | _S_IWRITE 
166                             );
167                             return fih;    
168                         }    
169                         case fdintCLOSE_FILE_INFO:    
170                         {
171 rizwank    2.12 #ifdef VERBOSE
172 rizwank    2.11             trace(
173                                 "fdintCLOSE_FILE:\n"
174                                 "-name: %s\n"
175                                 "-handle: %d\n"
176                                 "-date: %d\n"
177                                 "-time: %d\n"
178                                 "-attributes: %d\n"
179                                 "-file's folder index: %d\n"
180                                 "-run: %d\n",
181                                 pfdin->psz1,
182                                 pfdin->hf,
183                                 pfdin->date,
184                                 pfdin->time,
185                                 pfdin->attribs,
186                                 pfdin->iFolder,
187                                 pfdin->cb
188                             );
189 rizwank    2.12 #endif
190 rizwank    2.11     
191                             tvfs_close(pfdin->hf);
192                             return TRUE;
193                         }
194                         case fdintNEXT_CABINET: 
195                         {
196 rizwank    2.12 #ifdef VERBOSE
197 rizwank    2.11             trace("fdintNEXT_CABINET\n");
198 rizwank    2.12 #endif
199 rizwank    2.11             return 0;
200                         }
201                         case fdintENUMERATE:
202                         {
203 rizwank    2.12 #ifdef VERBOSE
204 rizwank    2.11             trace("fdintENUMERATE\n");
205 rizwank    2.12 #endif
206 rizwank    2.11             return 0;
207                         }
208                     }
209                     return 0;
210 rizwank    2.3  }
211 cs130_alex 2.1  
212 rizwank    2.3  static void printCabInfo(FDICABINETINFO  cabinfo){
213 rizwank    2.12 #ifdef VERBOSE
214 rizwank    2.11     trace("   Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
215                         cabinfo.cbCabinet,
216                         cabinfo.cFolders ,
217                         cabinfo.cFiles ,
218                         cabinfo.setID,
219                         cabinfo.iCabinet,
220                         cabinfo.fReserve ,
221                         cabinfo.hasprev ,
222                         cabinfo.hasnext );
223 rizwank    2.12 #endif
224 rizwank    2.7  }
225 cs130_alex 2.1  
226 cs130_alex 2.2  static void CheckCabInfo(char *  cabname,
227 rizwank    2.11     FDICABINETINFO cabinfo, 
228                     long    TcbCabinet,
229                     USHORT    TcFolders,    
230                     USHORT    TcFiles,    
231                     USHORT    TsetID,    
232                     USHORT    TiCabinet,    
233                     BOOL    TfReserve,    
234                     BOOL    Thasprev,    
235                     BOOL    Thasnext){
236                     ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
237                     ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
238                     ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
239                     ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
240                     ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
241                     ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
242                     ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
243                     ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
244                    }
245                 
246                 static HFDI hfdi_unknown;
247 rizwank    1.4  /* yes its global and ugly */
248                 
249 rizwank    2.0  /* Is CPU386 or Unknown more commonly used? */
250 rizwank    1.1  
251 rizwank    1.4  static void TestCreate(void) {
252 rizwank    2.11     
253                     ERF error_structure;
254                     
255                     trace("Starting TestCreate()\n");
256                     
257                     hfdi_unknown = FDICreate(
258                         final_alloc,
259                         final_free, 
260                         tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
261                         cpuUNKNOWN,
262                         &error_structure
263                     );
264                 
265                     ok(hfdi_unknown != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");    
266                     
267                     trace("Ending TestCreate()\n");    
268 rizwank    1.7  }
269                 
270                 static void TestInfo(void) {
271 rizwank    2.11 
272                     int fd;
273                     
274                     FDICABINETINFO  fdi_cabinfo_simple, fdi_cabinfo_complex;
275                     
276                     trace("Starting TestInfo()\n");
277                 
278                     tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
279                     fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
280                 
281                     ok( FDIIsCabinet( hfdi_unknown, fd, &fdi_cabinfo_simple) == TRUE,
282                     "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
283                     
284                     printCabInfo(fdi_cabinfo_simple);
285                     CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);    
286                     
287                     tvfs_close(fd); 
288                 
289                     tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
290                     fd = tvfs_open( name_complex_cab, _O_BINARY, 0 );
291                 
292 rizwank    2.11     ok( FDIIsCabinet( hfdi_unknown, fd, &fdi_cabinfo_complex) == TRUE,
293                     "FDIIsCabinet (Virtual File = Complex.cab) failed!\n");
294                     
295                     printCabInfo(fdi_cabinfo_complex);
296                     CheckCabInfo("complex.cab",fdi_cabinfo_complex,12918,1,2,0,0,0,0,0);    
297                     
298                     tvfs_close(fd);
299                     tvfs_free();    
300                     
301                     trace("Ending TestInfo()\n");
302 rizwank    1.7  }
303 cs130_alex 2.1  
304 rizwank    2.3  static void TestCopy(void){
305 rizwank    2.11     
306                     char name_file_path[256];
307                     int result;
308                     
309                     trace("Starting TestCopy()\n");
310                     trace("---simple.cab\n");
311                 
312                     tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
313                     FDICopy(hfdi_unknown,
314                         "simple.cab",
315                         "",
316                         0,
317                         notification_function,
318                         NULL,
319                         NULL);
320                 
321                     /* Filename when extracted is ./<filename> */
322                     sprintf(name_file_path, "./%s", name_simple_txt);
323                     result = tvfs_compare(name_file_path, file_simple_txt, size_simple_txt);
324                     if (result)
325                         trace ("File %s compare failed!\n",name_file_path);    
326 rizwank    2.11     tvfs_free();
327                 
328                     trace("---complex.cab\n");
329                     tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
330                     FDICopy(hfdi_unknown,
331                         "complex.cab",
332                         "",
333                         0,
334                         notification_function,
335                         NULL,
336                         NULL);
337                 
338 rizwank    2.13    
339 rizwank    2.11     tvfs_free();
340                     
341                     trace("Ending TestCopy()\n");   
342 cs130_alex 2.1  }
343                 
344 rizwank    1.7  static void TestDestroy(void) {
345 rizwank    2.11     trace("Starting TestDestroy()\n");
346                     ok(FDIDestroy(hfdi_unknown), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");  
347                     trace("Ending TestDestroy()\n");
348 rizwank    1.4  }
349 rizwank    1.1  
350 rizwank    2.13 START_TEST(cabinet_fdi)
351 rizwank    1.1  {
352 rizwank    2.11     TestCreate();
353                     TestInfo();
354                     TestCopy();
355                     TestDestroy();
356                     tvfs_free();
357 rizwank    1.1  }

Rizwan Kassim
Powered by
ViewCVS 0.9.2