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
|
106 rizwank 2.10 /*Possible non trivial addition:
107 Notify receives some information about the cab file(see FDI documentation).
108 Since this info is different depending on the value of fdint, and Notify should
109 be generic, it is not simple or nice to check this information.
110 */
|
111 rizwank 2.3 FNFDINOTIFY(notification_function)
112 {
113 switch (fdint)
114 {
115 case fdintCABINET_INFO:
116 {
117 return 0;
118 }
119 case fdintPARTIAL_FILE:
120 {
121 return 0;
122 }
123 case fdintCOPY_FILE:
|
124 rizwank 2.9 {
|
125 rizwank 2.3 int fih = 0;
126 char target[256];
127 sprintf(target, "./%s",pfdin->psz1);
|
128 rizwank 2.10 fih = tvfs_open (target,
|
129 rizwank 2.3 _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
130 _S_IREAD | _S_IWRITE
|
131 rizwank 2.10 );
|
132 rizwank 2.7 return fih;
|
133 rizwank 2.5 }
|
134 rizwank 2.3 case fdintCLOSE_FILE_INFO:
135 {
|
136 rizwank 2.7 char filebuf[256];
137 int result;
|
138 rizwank 2.10
|
139 rizwank 2.8 /*
|
140 rizwank 2.7 printf("Testing direct file compare and lseek of %s\n", name_simple_txt);
141 printf("Reading and comparing file\n");
142 result = tvfs_read(7, filebuf, size_simple_txt);
143 result = tvfs_compare( filebuf , file_simple_txt, size_simple_txt);
|
144 rizwank 2.8
|
145 rizwank 2.9 */
|
146 rizwank 2.10 tvfs_close(pfdin->hf);
|
147 rizwank 2.9 return TRUE;
|
148 rizwank 2.3 }
149 case fdintNEXT_CABINET:
150 {
151 return 0;
152 }
153 case fdintENUMERATE:
154 {
|
155 rizwank 2.10 return 0;
|
156 rizwank 2.3 }
157 }
158 return 0;
159 }
|
160 cs130_alex 2.1
|
161 rizwank 2.3 static void printCabInfo(FDICABINETINFO cabinfo){
|
162 rizwank 2.4 printf(" Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
|
163 cs130_alex 2.1 cabinfo.cbCabinet,
|
164 rizwank 2.5 cabinfo.cFolders ,
|
165 cs130_alex 2.1 cabinfo.cFiles ,
166 cabinfo.setID,
167 cabinfo.iCabinet,
168 cabinfo.fReserve ,
169 cabinfo.hasprev ,
|
170 rizwank 2.3 cabinfo.hasnext );
|
171 cs130_alex 2.1 }
|
172 rizwank 2.7 #ifndef TVFS
173 FNREAD(real_read) {
174 int szBuffer = _read(hf,pv,cb);
175 printf(" FNREAD (read) just called with %d, %d, %d\n",hf, pv, cb);
176 printf(" FNREAD (read) returning size (%d)\n",szBuffer);
177 return szBuffer;
178 }
179 FNCLOSE(real_close) {
180 int closevalue = _close(hf);
181 printf(" FNCLOSE (real) just called with %d - returning %d\n",hf,closevalue);
182 return closevalue;
183 }
184
185 FNWRITE(real_write) {
186 int write_value = _write(hf, pv, cb);
187 printf(" FNWRITE just called with %d, %d, %d - returning %d\n",hf, pv, cb, write_value);
188 return write_value;
189 }
190
191 FNSEEK(real_seek) {
192 long lseek_value = _lseek(hf, dist, seektype);
193 rizwank 2.7 printf(" FNSEEK just called with %d, %d, %d - returning %d\n",hf, dist, seektype,lseek_value);
194 return lseek_value;
195 }
196
197 FNOPEN(real_open) {
198 int handler = _open(pszFile,oflag,pmode);
199 printf(" FNOPEN (real) just called with %s, %d, %d\n",pszFile, oflag, pmode);
200 printf(" FNOPEN (real) returning handler (%d)\n",handler);
201 return handler;
202 }
203 #endif
|
204 cs130_alex 2.1
|
205 cs130_alex 2.2 static void CheckCabInfo(char * cabname,
206 FDICABINETINFO cabinfo,
|
207 rizwank 2.3 long TcbCabinet,
208 USHORT TcFolders,
209 USHORT TcFiles,
210 USHORT TsetID,
211 USHORT TiCabinet,
212 BOOL TfReserve,
213 BOOL Thasprev,
214 BOOL Thasnext){
|
215 rizwank 2.5 ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
216 ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
217 ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
218 ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
219 ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
220 ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
221 ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
222 ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
|
223 cs130_alex 2.1 }
|
224 rizwank 2.5 HFDI hfdi_unknown_dummy, hfdi_unknown_tvfs;
|
225 rizwank 1.4 /* yes its global and ugly */
226
|
227 rizwank 2.0 /* Is CPU386 or Unknown more commonly used? */
|
228 rizwank 1.1
|
229 rizwank 1.4 static void TestCreate(void) {
230
231 ERF error_structure;
232
233 printf("Starting TestCreate()\n");
234
|
235 rizwank 1.7 hfdi_unknown_dummy = FDICreate(
|
236 rizwank 1.8 final_alloc,
237 final_free,
|
238 rizwank 1.5 dummy_open,
239 dummy_read,
240 dummy_write,
241 dummy_close,
242 dummy_seek,
243 cpuUNKNOWN,
244 &error_structure
245 );
|
246 rizwank 1.7 ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");
247
|
248 rizwank 2.5 hfdi_unknown_tvfs = FDICreate(
|
249 rizwank 1.8 final_alloc,
|
250 rizwank 2.6 final_free,
|
251 rizwank 2.7 #ifdef TVFS
252 tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
253 #else
254 real_open, real_read, real_write, real_close,real_seek,
255 #endif
|
256 rizwank 2.6 cpuUNKNOWN,
|
257 rizwank 1.7 &error_structure
258 );
|
259 rizwank 2.5 ok(hfdi_unknown_tvfs != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
|
260 rizwank 1.7
261 printf("Ending TestCreate()\n");
262 }
263
264 static void TestInfo(void) {
|
265 rizwank 2.7 #ifdef TVFS
|
266 rizwank 2.5 int fd;
267
|
268 rizwank 1.8 FDICABINETINFO fdi_cabinfo_dummy, fdi_cabinfo_simple, fdi_cabinfo_complex;
|
269 rizwank 1.7
270 printf("Starting TestInfo()\n");
|
271 rizwank 1.8
272 /* TEST : ERR filehandle associated, dummy functions should return FALSE */
273 ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo_dummy) == FALSE,
|
274 rizwank 1.7 "FDIIsCabinet (File = Error) failed!\n");
|
275 rizwank 1.8
276
|
277 rizwank 2.5 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
278 fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
|
279 rizwank 2.0
|
280 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_simple) == TRUE,
281 "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
|
282 rizwank 2.0
|
283 rizwank 2.5 printCabInfo(fdi_cabinfo_simple);
284 CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);
|
285 rizwank 2.0
|
286 rizwank 2.5 tvfs_close(fd);
|
287 rizwank 2.4
|
288 rizwank 2.0
|
289 rizwank 2.5 tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
290 fd = tvfs_open( name_complex_cab, _O_BINARY, 0 );
|
291 rizwank 2.0
|
292 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_complex) == TRUE,
293 "FDIIsCabinet (Virtual File = Complex.cab) failed!\n");
|
294 rizwank 1.7
|
295 cs130_alex 2.1 printCabInfo(fdi_cabinfo_complex);
|
296 rizwank 2.5 CheckCabInfo("complex.cab",fdi_cabinfo_complex,12918,1,2,0,0,0,0,0);
|
297 rizwank 2.0
|
298 rizwank 2.8 tvfs_close(fd);
299 tvfs_free();
|
300 rizwank 1.7
|
301 rizwank 2.5 printf("Ending TestInfo()\n");
|
302 rizwank 2.7 #endif
|
303 rizwank 1.7 }
|
304 cs130_alex 2.1
|
305 rizwank 2.3 static void TestCopy(void){
|
306 rizwank 2.8
307 char name_file_path[256];
308 int result;
309
|
310 rizwank 2.3 printf("Starting TestCopy()\n");
311 printf("---simple.cab\n");
|
312 rizwank 2.8 #ifdef TVFS
313 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
314 #endif
315 FDICopy(hfdi_unknown_tvfs,
316 "simple.cab",
317 "",
318 0,
319 notification_function,
320 NULL,
321 NULL);
322
323 #ifdef TVFS
324 /* Filename when extracted is ./<filename> */
325 sprintf(name_file_path, "./%s", name_simple_txt);
326 result = tvfs_compare(name_file_path, file_simple_txt, size_simple_txt);
327 if (result)
328 printf ("File compare failed!\n");
329 tvfs_free();
330 #endif
331
332
333 rizwank 2.8 printf("---complex.cab\n");
334 #ifdef TVFS
335 tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
336 #endif
|
337 rizwank 2.5 FDICopy(hfdi_unknown_tvfs,
|
338 rizwank 2.7 "complex.cab",
|
339 rizwank 2.5 "",
|
340 rizwank 2.3 0,
341 notification_function,
342 NULL,
343 NULL);
344
|
345 rizwank 2.8 #ifdef TVFS
346 /* Filename when extracted is ./<filename> */
347 sprintf(name_file_path, "./%s", name_README);
348 result = tvfs_compare(name_file_path, file_README, size_README);
349 if (result)
350 printf ("File compare failed!\n");
351 tvfs_free();
352 #endif
353
354
355
356 printf("Ending TestCopy()\n");
|
357 cs130_alex 2.1 }
358
|
359 rizwank 1.7 static void TestDestroy(void) {
360 printf("Starting TestDestroy()\n");
|
361 rizwank 2.0
|
362 rizwank 1.7 ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");
|
363 rizwank 2.5 ok(FDIDestroy(hfdi_unknown_tvfs), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");
|
364 rizwank 1.7 printf("Ending TestDestroy()\n");
|
365 rizwank 1.4 }
|
366 rizwank 1.1
367 START_TEST(paths)
368 {
|
369 rizwank 1.4 TestCreate();
|
370 rizwank 1.7 TestInfo();
|
371 rizwank 1.2 TestCopy();
372 TestDestroy();
|
373 rizwank 2.5 tvfs_free();
|
374 rizwank 1.1 }
|