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 1.1
25 #ifndef STANDALONE
26 #include <wine/test.h>
27 #define ok2 ok
28 #else
|
29 rizwank 2.5 /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ tvfs.c cabinet_fdi.c FDI.lib
|
30 rizwank 1.1 These are only called if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */
31 #include <assert.h>
32 #include <stdio.h>
33 #define START_TEST(name) main(int argc, char **argv)
34 #define ok(condition, msg) \
35 do { if(!(condition)) { \
36 fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__); \
37 exit(1); \
38 } } while(0)
39 #define ok2(condition, msg, arg) \
40 do { if(!(condition)) { \
41 fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__, arg); \
42 exit(1); \
43 } } while(0)
44 #define todo_wine
45 #endif
46
|
47 rizwank 2.7 #define TVFS
48
|
49 rizwank 1.1 #include <winerror.h>
50 #include <fdi.h>
|
51 rizwank 1.7 #include <fcntl.h>
|
52 rizwank 2.5 #include "tvfs.h"
53 #include "data.h"
|
54 rizwank 1.7
|
55 rizwank 1.8 /* Do malloc and free output debug messages?
56 #define DEBUG_ALLOC
57 */
|
58 rizwank 1.7
|
59 rizwank 1.8 #ifndef DEBUG_ALLOC
60 FNALLOC(final_alloc) {
61 return malloc(cb);
62 }
63 FNFREE(final_free) {
64 free(pv);
65 return;
66 }
67 #else
68 FNALLOC(final_alloc) {
|
69 rizwank 1.5 printf(" FNALLOC just called with %d\n",cb);
70 return malloc(cb);
|
71 rizwank 1.3 }
|
72 rizwank 1.8 FNFREE(final_free) {
|
73 rizwank 1.5 printf(" FNFREE just called with %d\n",pv);
74 free(pv);
|
75 rizwank 1.3 return;
76 }
|
77 rizwank 1.8 #endif
78
|
79 rizwank 1.3
80 FNOPEN(dummy_open) {
|
81 rizwank 1.8 printf(" FNOPEN (dummy) just called with %d, %d, %d\n",pszFile, oflag, pmode);
|
82 rizwank 1.3 return 0;
83 }
84
85 FNREAD(dummy_read) {
|
86 rizwank 1.8 printf(" FNREAD (dummy) just called with %d, %d, %d\n",hf, pv, cb);
|
87 rizwank 1.5 return 0;
|
88 rizwank 1.3 }
|
89 rizwank 1.7
|
90 rizwank 1.8 FNCLOSE(dummy_close) {
91 printf(" FNCLOSE (dummy) just called with %d - returning %d\n",hf,0);
|
92 rizwank 1.5 return 0;
|
93 rizwank 1.3 }
94
|
95 rizwank 1.8 FNWRITE(dummy_write) {
96 printf(" FNWRITE just called with %d, %d, %d\n",hf, pv, cb);
|
97 rizwank 1.5 return 0;
|
98 rizwank 1.3 }
|
99 rizwank 1.1
|
100 rizwank 1.3 FNSEEK(dummy_seek) {
|
101 rizwank 1.8 printf(" FNSEEK just called with %d, %d, %d\n",hf, dist, seektype);
|
102 rizwank 1.5 return 0;
|
103 rizwank 1.3 }
104
|
105 cs130_alex 2.1 FNFDINOTIFY(dummy_notification){
106 printf(" FNFDINOTIFY just called with %d, %d \n",fdint,pfdin);
107 return 0;
108 }
109
|
110 rizwank 2.3 FNFDINOTIFY(notification_function)
111 {
112 printf(" FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin);
113 switch (fdint)
114 {
115 case fdintCABINET_INFO:
116 {
117 printf("fdintCABINET_INFO\n");
118 return 0;
119 }
120 case fdintPARTIAL_FILE:
121 {
122 printf("dintPARTIAL_FILE\n");
123 return 0;
124 }
125 case fdintCOPY_FILE:
126 {
127 int fih = 0;
128 char target[256];
129
130 printf("fdintCOPY_FILE\n");
131 rizwank 2.3 printf(" file name: %s\n", pfdin->psz1);
132 sprintf(target, "./%s",pfdin->psz1);
133 printf("%s\n",target);
|
134 rizwank 2.7 #ifdef TVFS
|
135 rizwank 2.6 fih = tvfs_open (target,
|
136 rizwank 2.3 _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
137 _S_IREAD | _S_IWRITE
|
138 rizwank 2.6 );
|
139 rizwank 2.7 return fih;
140 #else
141 fih = real_open (target,
142 _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
143 _S_IREAD | _S_IWRITE
144 );
145 return fih;
146 #endif
|
147 rizwank 2.5 }
|
148 rizwank 2.3 case fdintCLOSE_FILE_INFO:
149 {
|
150 rizwank 2.7 char filebuf[256];
151 int result;
|
152 rizwank 2.3
|
153 rizwank 2.8 /*
|
154 rizwank 2.7 printf("Testing direct file compare and lseek of %s\n", name_simple_txt);
155 printf("Reading and comparing file\n");
156 result = tvfs_read(7, filebuf, size_simple_txt);
157 result = tvfs_compare( filebuf , file_simple_txt, size_simple_txt);
|
158 rizwank 2.8
159 */
|
160 rizwank 2.3 return 0;
161 }
162 case fdintNEXT_CABINET:
163 {
164
165 printf("fdintNEXT_CABINET\n");
166 return 0;
167 }
168 case fdintENUMERATE:
169 {
170 printf("fdintENUMERATE\n");
171 return 0;
172 }
173 }
174 return 0;
175 }
|
176 cs130_alex 2.1
|
177 rizwank 2.3 static void printCabInfo(FDICABINETINFO cabinfo){
|
178 rizwank 2.4 printf(" Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
|
179 cs130_alex 2.1 cabinfo.cbCabinet,
|
180 rizwank 2.5 cabinfo.cFolders ,
|
181 cs130_alex 2.1 cabinfo.cFiles ,
182 cabinfo.setID,
183 cabinfo.iCabinet,
184 cabinfo.fReserve ,
185 cabinfo.hasprev ,
|
186 rizwank 2.3 cabinfo.hasnext );
|
187 cs130_alex 2.1 }
|
188 rizwank 2.7 #ifndef TVFS
189 FNREAD(real_read) {
190 int szBuffer = _read(hf,pv,cb);
191 printf(" FNREAD (read) just called with %d, %d, %d\n",hf, pv, cb);
192 printf(" FNREAD (read) returning size (%d)\n",szBuffer);
193 return szBuffer;
194 }
195 FNCLOSE(real_close) {
196 int closevalue = _close(hf);
197 printf(" FNCLOSE (real) just called with %d - returning %d\n",hf,closevalue);
198 return closevalue;
199 }
200
201 FNWRITE(real_write) {
202 int write_value = _write(hf, pv, cb);
203 printf(" FNWRITE just called with %d, %d, %d - returning %d\n",hf, pv, cb, write_value);
204 return write_value;
205 }
206
207 FNSEEK(real_seek) {
208 long lseek_value = _lseek(hf, dist, seektype);
209 rizwank 2.7 printf(" FNSEEK just called with %d, %d, %d - returning %d\n",hf, dist, seektype,lseek_value);
210 return lseek_value;
211 }
212
213 FNOPEN(real_open) {
214 int handler = _open(pszFile,oflag,pmode);
215 printf(" FNOPEN (real) just called with %s, %d, %d\n",pszFile, oflag, pmode);
216 printf(" FNOPEN (real) returning handler (%d)\n",handler);
217 return handler;
218 }
219 #endif
|
220 cs130_alex 2.1
|
221 cs130_alex 2.2 static void CheckCabInfo(char * cabname,
222 FDICABINETINFO cabinfo,
|
223 rizwank 2.3 long TcbCabinet,
224 USHORT TcFolders,
225 USHORT TcFiles,
226 USHORT TsetID,
227 USHORT TiCabinet,
228 BOOL TfReserve,
229 BOOL Thasprev,
230 BOOL Thasnext){
|
231 rizwank 2.5 ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
232 ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
233 ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
234 ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
235 ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
236 ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
237 ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
238 ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
|
239 cs130_alex 2.1 }
|
240 rizwank 2.5 HFDI hfdi_unknown_dummy, hfdi_unknown_tvfs;
|
241 rizwank 1.4 /* yes its global and ugly */
242
|
243 rizwank 2.0 /* Is CPU386 or Unknown more commonly used? */
|
244 rizwank 1.1
|
245 rizwank 1.4 static void TestCreate(void) {
246
247 ERF error_structure;
248
249 printf("Starting TestCreate()\n");
250
|
251 rizwank 1.7 hfdi_unknown_dummy = FDICreate(
|
252 rizwank 1.8 final_alloc,
253 final_free,
|
254 rizwank 1.5 dummy_open,
255 dummy_read,
256 dummy_write,
257 dummy_close,
258 dummy_seek,
259 cpuUNKNOWN,
260 &error_structure
261 );
|
262 rizwank 1.7 ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");
263
|
264 rizwank 2.5 hfdi_unknown_tvfs = FDICreate(
|
265 rizwank 1.8 final_alloc,
|
266 rizwank 2.6 final_free,
|
267 rizwank 2.7 #ifdef TVFS
268 tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
269 #else
270 real_open, real_read, real_write, real_close,real_seek,
271 #endif
|
272 rizwank 2.6 cpuUNKNOWN,
|
273 rizwank 1.7 &error_structure
274 );
|
275 rizwank 2.5 ok(hfdi_unknown_tvfs != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
|
276 rizwank 1.7
277 printf("Ending TestCreate()\n");
278 }
279
280 static void TestInfo(void) {
|
281 rizwank 2.7 #ifdef TVFS
|
282 rizwank 2.5 int fd;
283
|
284 rizwank 1.8 FDICABINETINFO fdi_cabinfo_dummy, fdi_cabinfo_simple, fdi_cabinfo_complex;
|
285 rizwank 1.7
286 printf("Starting TestInfo()\n");
|
287 rizwank 1.8
288 /* TEST : ERR filehandle associated, dummy functions should return FALSE */
289 ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo_dummy) == FALSE,
|
290 rizwank 1.7 "FDIIsCabinet (File = Error) failed!\n");
|
291 rizwank 1.8
292
|
293 rizwank 2.5 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
294 fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
|
295 rizwank 2.0
|
296 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_simple) == TRUE,
297 "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
|
298 rizwank 2.0
|
299 rizwank 2.5 printCabInfo(fdi_cabinfo_simple);
300 CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);
|
301 rizwank 2.0
|
302 rizwank 2.5 tvfs_close(fd);
|
303 rizwank 2.4
|
304 rizwank 2.0
|
305 rizwank 2.5 tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
306 fd = tvfs_open( name_complex_cab, _O_BINARY, 0 );
|
307 rizwank 2.0
|
308 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_complex) == TRUE,
309 "FDIIsCabinet (Virtual File = Complex.cab) failed!\n");
|
310 rizwank 1.7
|
311 cs130_alex 2.1 printCabInfo(fdi_cabinfo_complex);
|
312 rizwank 2.5 CheckCabInfo("complex.cab",fdi_cabinfo_complex,12918,1,2,0,0,0,0,0);
|
313 rizwank 2.0
|
314 rizwank 2.8 tvfs_close(fd);
315 tvfs_free();
|
316 rizwank 1.7
|
317 rizwank 2.5 printf("Ending TestInfo()\n");
|
318 rizwank 2.7 #endif
|
319 rizwank 1.7 }
|
320 cs130_alex 2.1
|
321 rizwank 2.3 static void TestCopy(void){
|
322 rizwank 2.8
323 char name_file_path[256];
324 int result;
325
|
326 rizwank 2.3 printf("Starting TestCopy()\n");
327 printf("---simple.cab\n");
|
328 rizwank 2.8 #ifdef TVFS
329 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
330 #endif
331 FDICopy(hfdi_unknown_tvfs,
332 "simple.cab",
333 "",
334 0,
335 notification_function,
336 NULL,
337 NULL);
338
339 #ifdef TVFS
340 /* Filename when extracted is ./<filename> */
341 sprintf(name_file_path, "./%s", name_simple_txt);
342 result = tvfs_compare(name_file_path, file_simple_txt, size_simple_txt);
343 if (result)
344 printf ("File compare failed!\n");
345 tvfs_free();
346 #endif
347
348
349 rizwank 2.8 printf("---complex.cab\n");
350 #ifdef TVFS
351 tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
352 #endif
|
353 rizwank 2.5 FDICopy(hfdi_unknown_tvfs,
|
354 rizwank 2.7 "complex.cab",
|
355 rizwank 2.5 "",
|
356 rizwank 2.3 0,
357 notification_function,
358 NULL,
359 NULL);
360
|
361 rizwank 2.8 #ifdef TVFS
362 /* Filename when extracted is ./<filename> */
363 sprintf(name_file_path, "./%s", name_README);
364 result = tvfs_compare(name_file_path, file_README, size_README);
365 if (result)
366 printf ("File compare failed!\n");
367 tvfs_free();
368 #endif
369
370
371
372 printf("Ending TestCopy()\n");
|
373 cs130_alex 2.1 }
374
|
375 rizwank 1.7 static void TestDestroy(void) {
376 printf("Starting TestDestroy()\n");
|
377 rizwank 2.0
|
378 rizwank 1.7 ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");
|
379 rizwank 2.5 ok(FDIDestroy(hfdi_unknown_tvfs), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");
|
380 rizwank 1.7 printf("Ending TestDestroy()\n");
|
381 rizwank 1.4 }
|
382 rizwank 1.1
383 START_TEST(paths)
384 {
|
385 rizwank 1.4 TestCreate();
|
386 rizwank 1.7 TestInfo();
|
387 rizwank 1.2 TestCopy();
388 TestDestroy();
|
389 rizwank 2.5 tvfs_free();
|
390 rizwank 1.1 }
|