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.7
154 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 if (result)
159 printf ("File compare failed!\n");
160
|
161 rizwank 2.3 return 0;
162 }
163 case fdintNEXT_CABINET:
164 {
165
166 printf("fdintNEXT_CABINET\n");
167 return 0;
168 }
169 case fdintENUMERATE:
170 {
171 printf("fdintENUMERATE\n");
172 return 0;
173 }
174 }
175 return 0;
176 }
|
177 cs130_alex 2.1
|
178 rizwank 2.3 static void printCabInfo(FDICABINETINFO cabinfo){
|
179 rizwank 2.4 printf(" Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
|
180 cs130_alex 2.1 cabinfo.cbCabinet,
|
181 rizwank 2.5 cabinfo.cFolders ,
|
182 cs130_alex 2.1 cabinfo.cFiles ,
183 cabinfo.setID,
184 cabinfo.iCabinet,
185 cabinfo.fReserve ,
186 cabinfo.hasprev ,
|
187 rizwank 2.3 cabinfo.hasnext );
|
188 cs130_alex 2.1 }
|
189 rizwank 2.7 #ifndef TVFS
190 FNREAD(real_read) {
191 int szBuffer = _read(hf,pv,cb);
192 printf(" FNREAD (read) just called with %d, %d, %d\n",hf, pv, cb);
193 printf(" FNREAD (read) returning size (%d)\n",szBuffer);
194 return szBuffer;
195 }
196 FNCLOSE(real_close) {
197 int closevalue = _close(hf);
198 printf(" FNCLOSE (real) just called with %d - returning %d\n",hf,closevalue);
199 return closevalue;
200 }
201
202 FNWRITE(real_write) {
203 int write_value = _write(hf, pv, cb);
204 printf(" FNWRITE just called with %d, %d, %d - returning %d\n",hf, pv, cb, write_value);
205 return write_value;
206 }
207
208 FNSEEK(real_seek) {
209 long lseek_value = _lseek(hf, dist, seektype);
210 rizwank 2.7 printf(" FNSEEK just called with %d, %d, %d - returning %d\n",hf, dist, seektype,lseek_value);
211 return lseek_value;
212 }
213
214 FNOPEN(real_open) {
215 int handler = _open(pszFile,oflag,pmode);
216 printf(" FNOPEN (real) just called with %s, %d, %d\n",pszFile, oflag, pmode);
217 printf(" FNOPEN (real) returning handler (%d)\n",handler);
218 return handler;
219 }
220 #endif
|
221 cs130_alex 2.1
|
222 cs130_alex 2.2 static void CheckCabInfo(char * cabname,
223 FDICABINETINFO cabinfo,
|
224 rizwank 2.3 long TcbCabinet,
225 USHORT TcFolders,
226 USHORT TcFiles,
227 USHORT TsetID,
228 USHORT TiCabinet,
229 BOOL TfReserve,
230 BOOL Thasprev,
231 BOOL Thasnext){
|
232 rizwank 2.5 ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
233 ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
234 ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
235 ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
236 ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
237 ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
238 ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
239 ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
|
240 cs130_alex 2.1 }
|
241 rizwank 2.5 HFDI hfdi_unknown_dummy, hfdi_unknown_tvfs;
|
242 rizwank 1.4 /* yes its global and ugly */
243
|
244 rizwank 2.0 /* Is CPU386 or Unknown more commonly used? */
|
245 rizwank 1.1
|
246 rizwank 1.4 static void TestCreate(void) {
247
248 ERF error_structure;
249
250 printf("Starting TestCreate()\n");
251
|
252 rizwank 1.7 hfdi_unknown_dummy = FDICreate(
|
253 rizwank 1.8 final_alloc,
254 final_free,
|
255 rizwank 1.5 dummy_open,
256 dummy_read,
257 dummy_write,
258 dummy_close,
259 dummy_seek,
260 cpuUNKNOWN,
261 &error_structure
262 );
|
263 rizwank 1.7 ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");
264
|
265 rizwank 2.5 hfdi_unknown_tvfs = FDICreate(
|
266 rizwank 1.8 final_alloc,
|
267 rizwank 2.6 final_free,
|
268 rizwank 2.7 #ifdef TVFS
269 tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
270 #else
271 real_open, real_read, real_write, real_close,real_seek,
272 #endif
|
273 rizwank 2.6 cpuUNKNOWN,
|
274 rizwank 1.7 &error_structure
275 );
|
276 rizwank 2.5 ok(hfdi_unknown_tvfs != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
|
277 rizwank 1.7
278 printf("Ending TestCreate()\n");
279 }
280
281 static void TestInfo(void) {
|
282 rizwank 2.7 #ifdef TVFS
|
283 rizwank 2.5 int fd;
284
|
285 rizwank 1.8 FDICABINETINFO fdi_cabinfo_dummy, fdi_cabinfo_simple, fdi_cabinfo_complex;
|
286 rizwank 1.7
287 printf("Starting TestInfo()\n");
|
288 rizwank 1.8
289 /* TEST : ERR filehandle associated, dummy functions should return FALSE */
290 ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo_dummy) == FALSE,
|
291 rizwank 1.7 "FDIIsCabinet (File = Error) failed!\n");
|
292 rizwank 1.8
293
|
294 rizwank 2.5 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
295 fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
|
296 rizwank 2.0
|
297 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_simple) == TRUE,
298 "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
|
299 rizwank 2.0
|
300 rizwank 2.5 printCabInfo(fdi_cabinfo_simple);
301 CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);
|
302 rizwank 2.0
|
303 rizwank 2.5 tvfs_close(fd);
|
304 rizwank 2.4
|
305 rizwank 2.0
|
306 rizwank 2.5 tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
307 fd = tvfs_open( name_complex_cab, _O_BINARY, 0 );
|
308 rizwank 2.0
|
309 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_complex) == TRUE,
310 "FDIIsCabinet (Virtual File = Complex.cab) failed!\n");
|
311 rizwank 1.7
|
312 cs130_alex 2.1 printCabInfo(fdi_cabinfo_complex);
|
313 rizwank 2.5 CheckCabInfo("complex.cab",fdi_cabinfo_complex,12918,1,2,0,0,0,0,0);
|
314 rizwank 2.0
|
315 rizwank 2.5 tvfs_close(fd);
|
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 printf("Starting TestCopy()\n");
323 printf("---simple.cab\n");
|
324 rizwank 2.5 FDICopy(hfdi_unknown_tvfs,
|
325 rizwank 2.7 "complex.cab",
|
326 rizwank 2.5 "",
|
327 rizwank 2.3 0,
328 notification_function,
329 NULL,
330 NULL);
331
332 printf("Ending TestCopy()\n");
|
333 cs130_alex 2.1 }
334
|
335 rizwank 1.7 static void TestDestroy(void) {
336 printf("Starting TestDestroy()\n");
|
337 rizwank 2.0
|
338 rizwank 1.7 ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");
|
339 rizwank 2.5 ok(FDIDestroy(hfdi_unknown_tvfs), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");
|
340 rizwank 1.7 printf("Ending TestDestroy()\n");
|
341 rizwank 1.4 }
|
342 rizwank 1.1
343 START_TEST(paths)
344 {
|
345 rizwank 1.4 TestCreate();
|
346 rizwank 1.7 TestInfo();
|
347 rizwank 1.2 TestCopy();
348 TestDestroy();
|
349 rizwank 2.5 tvfs_free();
|
350 rizwank 1.1 }
|