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

Rizwan Kassim
Powered by
ViewCVS 0.9.2