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 #include <winerror.h>
48 #include <fdi.h>
|
49 rizwank 1.7 #include <fcntl.h>
|
50 rizwank 2.5 #include "tvfs.h"
51 #include "data.h"
|
52 rizwank 1.7
|
53 rizwank 1.8 /* Do malloc and free output debug messages?
54 #define DEBUG_ALLOC
55 */
|
56 rizwank 1.7
|
57 rizwank 1.8 #ifndef DEBUG_ALLOC
58 FNALLOC(final_alloc) {
59 return malloc(cb);
60 }
61 FNFREE(final_free) {
62 free(pv);
63 return;
64 }
65 #else
66 FNALLOC(final_alloc) {
|
67 rizwank 1.5 printf(" FNALLOC just called with %d\n",cb);
68 return malloc(cb);
|
69 rizwank 1.3 }
|
70 rizwank 1.8 FNFREE(final_free) {
|
71 rizwank 1.5 printf(" FNFREE just called with %d\n",pv);
72 free(pv);
|
73 rizwank 1.3 return;
74 }
|
75 rizwank 1.8 #endif
76
|
77 rizwank 1.3
78 FNOPEN(dummy_open) {
|
79 rizwank 1.8 printf(" FNOPEN (dummy) just called with %d, %d, %d\n",pszFile, oflag, pmode);
|
80 rizwank 1.3 return 0;
81 }
82
83 FNREAD(dummy_read) {
|
84 rizwank 1.8 printf(" FNREAD (dummy) just called with %d, %d, %d\n",hf, pv, cb);
|
85 rizwank 1.5 return 0;
|
86 rizwank 1.3 }
|
87 rizwank 1.7
|
88 rizwank 1.8 FNCLOSE(dummy_close) {
89 printf(" FNCLOSE (dummy) just called with %d - returning %d\n",hf,0);
|
90 rizwank 1.5 return 0;
|
91 rizwank 1.3 }
92
|
93 rizwank 1.8 FNWRITE(dummy_write) {
94 printf(" FNWRITE just called with %d, %d, %d\n",hf, pv, cb);
|
95 rizwank 1.5 return 0;
|
96 rizwank 1.3 }
|
97 rizwank 1.1
|
98 rizwank 1.3 FNSEEK(dummy_seek) {
|
99 rizwank 1.8 printf(" FNSEEK just called with %d, %d, %d\n",hf, dist, seektype);
|
100 rizwank 1.5 return 0;
|
101 rizwank 1.3 }
102
|
103 cs130_alex 2.1 FNFDINOTIFY(dummy_notification){
104 printf(" FNFDINOTIFY just called with %d, %d \n",fdint,pfdin);
105 return 0;
106 }
107
|
108 rizwank 2.3 FNFDINOTIFY(notification_function)
109 {
110 printf(" FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin);
111 switch (fdint)
112 {
113 case fdintCABINET_INFO:
114 {
115 printf("fdintCABINET_INFO\n");
116 return 0;
117 }
118 case fdintPARTIAL_FILE:
119 {
120 printf("dintPARTIAL_FILE\n");
121 return 0;
122 }
123 case fdintCOPY_FILE:
124 {
125 int fih = 0;
126 char target[256];
127
128 printf("fdintCOPY_FILE\n");
129 rizwank 2.3 printf(" file name: %s\n", pfdin->psz1);
130 sprintf(target, "./%s",pfdin->psz1);
131 printf("%s\n",target);
132
|
133 rizwank 2.6 fih = tvfs_open (target,
|
134 rizwank 2.3 _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
135 _S_IREAD | _S_IWRITE
|
136 rizwank 2.6 );
|
137 rizwank 2.3 return fih;
|
138 rizwank 2.5 }
|
139 rizwank 2.3 case fdintCLOSE_FILE_INFO:
140 {
141
142 printf("fdintCLOSE_FILE_INFO\n");
143 return 0;
144 }
145 case fdintNEXT_CABINET:
146 {
147
148 printf("fdintNEXT_CABINET\n");
149 return 0;
150 }
151 case fdintENUMERATE:
152 {
153 printf("fdintENUMERATE\n");
154 return 0;
155 }
156 }
157 return 0;
158 }
|
159 cs130_alex 2.1
|
160 rizwank 2.3 static void printCabInfo(FDICABINETINFO cabinfo){
|
161 rizwank 2.4 printf(" Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
|
162 cs130_alex 2.1 cabinfo.cbCabinet,
|
163 rizwank 2.5 cabinfo.cFolders ,
|
164 cs130_alex 2.1 cabinfo.cFiles ,
165 cabinfo.setID,
166 cabinfo.iCabinet,
167 cabinfo.fReserve ,
168 cabinfo.hasprev ,
|
169 rizwank 2.3 cabinfo.hasnext );
|
170 cs130_alex 2.1 }
171
|
172 cs130_alex 2.2 static void CheckCabInfo(char * cabname,
173 FDICABINETINFO cabinfo,
|
174 rizwank 2.3 long TcbCabinet,
175 USHORT TcFolders,
176 USHORT TcFiles,
177 USHORT TsetID,
178 USHORT TiCabinet,
179 BOOL TfReserve,
180 BOOL Thasprev,
181 BOOL Thasnext){
|
182 rizwank 2.5 ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
183 ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
184 ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
185 ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
186 ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
187 ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
188 ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
189 ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
|
190 cs130_alex 2.1 }
|
191 rizwank 2.5 HFDI hfdi_unknown_dummy, hfdi_unknown_tvfs;
|
192 rizwank 1.4 /* yes its global and ugly */
193
|
194 rizwank 2.0 /* Is CPU386 or Unknown more commonly used? */
|
195 rizwank 1.1
|
196 rizwank 1.4 static void TestCreate(void) {
197
198 ERF error_structure;
199
200 printf("Starting TestCreate()\n");
201
|
202 rizwank 1.7 hfdi_unknown_dummy = FDICreate(
|
203 rizwank 1.8 final_alloc,
204 final_free,
|
205 rizwank 1.5 dummy_open,
206 dummy_read,
207 dummy_write,
208 dummy_close,
209 dummy_seek,
210 cpuUNKNOWN,
211 &error_structure
212 );
|
213 rizwank 1.7 ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");
214
|
215 rizwank 2.5 hfdi_unknown_tvfs = FDICreate(
|
216 rizwank 1.8 final_alloc,
|
217 rizwank 2.6 final_free,
|
218 rizwank 2.5 tvfs_open,
219 tvfs_read,
220 tvfs_write,
221 tvfs_close,
222 tvfs_lseek,
|
223 rizwank 2.6 cpuUNKNOWN,
|
224 rizwank 1.7 &error_structure
225 );
|
226 rizwank 2.5 ok(hfdi_unknown_tvfs != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
|
227 rizwank 1.7
228 printf("Ending TestCreate()\n");
229 }
230
231 static void TestInfo(void) {
|
232 rizwank 1.8
|
233 rizwank 2.5 int fd;
234
|
235 rizwank 1.8 FDICABINETINFO fdi_cabinfo_dummy, fdi_cabinfo_simple, fdi_cabinfo_complex;
|
236 rizwank 1.7
237 printf("Starting TestInfo()\n");
|
238 rizwank 1.8
239 /* TEST : ERR filehandle associated, dummy functions should return FALSE */
240 ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo_dummy) == FALSE,
|
241 rizwank 1.7 "FDIIsCabinet (File = Error) failed!\n");
|
242 rizwank 1.8
243
|
244 rizwank 2.5 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
245 fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
|
246 rizwank 2.0
|
247 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_simple) == TRUE,
248 "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
|
249 rizwank 2.0
|
250 rizwank 2.5 printCabInfo(fdi_cabinfo_simple);
251 CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);
|
252 rizwank 2.0
|
253 rizwank 2.5 tvfs_close(fd);
|
254 rizwank 2.4
|
255 rizwank 2.0
|
256 rizwank 2.5 tvfs_create( name_complex_cab, file_complex_cab, size_complex_cab);
257 fd = tvfs_open( name_complex_cab, _O_BINARY, 0 );
|
258 rizwank 2.0
|
259 rizwank 2.5 ok( FDIIsCabinet( hfdi_unknown_tvfs, fd, &fdi_cabinfo_complex) == TRUE,
260 "FDIIsCabinet (Virtual File = Complex.cab) failed!\n");
|
261 rizwank 1.7
|
262 cs130_alex 2.1 printCabInfo(fdi_cabinfo_complex);
|
263 rizwank 2.5 CheckCabInfo("complex.cab",fdi_cabinfo_complex,12918,1,2,0,0,0,0,0);
|
264 rizwank 2.0
|
265 rizwank 2.5 tvfs_close(fd);
|
266 rizwank 1.7
|
267 rizwank 2.5 printf("Ending TestInfo()\n");
268 printf(" SEEK_CUR %d \n",SEEK_CUR);
|
269 rizwank 1.7 }
|
270 cs130_alex 2.1
|
271 rizwank 2.3 static void TestCopy(void){
272 printf("Starting TestCopy()\n");
273 printf("---simple.cab\n");
|
274 rizwank 2.5 FDICopy(hfdi_unknown_tvfs,
|
275 rizwank 2.3 "simple.cab",
|
276 rizwank 2.5 "",
|
277 rizwank 2.3 0,
278 notification_function,
279 NULL,
280 NULL);
281
282 printf("Ending TestCopy()\n");
|
283 cs130_alex 2.1 }
284
|
285 rizwank 1.7 static void TestDestroy(void) {
286 printf("Starting TestDestroy()\n");
|
287 rizwank 2.0
|
288 rizwank 1.7 ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");
|
289 rizwank 2.5 ok(FDIDestroy(hfdi_unknown_tvfs), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");
|
290 rizwank 1.7 printf("Ending TestDestroy()\n");
|
291 rizwank 1.4 }
|
292 rizwank 1.1
293 START_TEST(paths)
294 {
|
295 rizwank 1.4 TestCreate();
|
296 rizwank 1.7 TestInfo();
|
297 rizwank 1.2 TestCopy();
298 TestDestroy();
|
299 rizwank 2.5 tvfs_free();
|
300 rizwank 1.1 }
|