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.13 #include <stdio.h>
|
22 rizwank 2.3 #include <stdlib.h>
23 #include <string.h>
|
24 cs130_alex 2.2 #include <sys/stat.h>
|
25 rizwank 2.11 #include <stdarg.h>
|
26 rizwank 2.13 #include <malloc.h>
27
28 #include <stdarg.h>
29 #include <stdio.h>
30
31 #include "windef.h"
32 #include "winbase.h"
33 #include "winerror.h"
34 #include "fdi.h"
35
36 #include <fcntl.h>
37
38 #include "tvfs.h"
39 #include "data.h"
|
40 rizwank 1.1
41 #ifndef STANDALONE
42 #include <wine/test.h>
43 #define ok2 ok
44 #else
|
45 rizwank 2.14 #include "standalone.h"
|
46 rizwank 2.13 /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ -DWIN_ENV tvfs.c cabinet_fdi.c FDI.lib
|
47 rizwank 2.14 standalone.h is used if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */
|
48 rizwank 1.1 #endif
49
|
50 rizwank 1.8 FNALLOC(final_alloc) {
|
51 rizwank 2.11 trace(" FNALLOC just called with %d\n",cb);
52 return malloc(cb);
|
53 rizwank 1.3 }
|
54 rizwank 1.8 FNFREE(final_free) {
|
55 rizwank 2.11 trace(" FNFREE just called with %d\n",pv);
56 free(pv);
57 return;
|
58 rizwank 1.3 }
|
59 rizwank 2.14
|
60 rizwank 2.10 /*Possible non trivial addition:
61 Notify receives some information about the cab file(see FDI documentation).
62 Since this info is different depending on the value of fdint, and Notify should
63 be generic, it is not simple or nice to check this information.
64 */
|
65 rizwank 2.3 FNFDINOTIFY(notification_function)
66 {
|
67 rizwank 2.11 trace(" FNFDINOTIFY real just called with %d, %d \n",fdint,pfdin);
68 switch (fdint)
69 {
70 case fdintCABINET_INFO:
71 {
72 trace(
73 "fdintCABINET_INFO:\n"
74 "-next cab name: %s\n"
75 "-next disk: %s\n"
76 "-path name: %s\n"
77 "-set ID: %d\n"
78 "-number in set: %d\n",
|
79 rizwank 2.14 pfdin->psz1, pfdin->psz2, pfdin->psz3, pfdin->setID, pfdin->iCabinet
|
80 rizwank 2.11 );
81 return 0;
82 }
83 case fdintPARTIAL_FILE:
84 {
85 trace("dintPARTIAL_FILE\n");
86
87 return 0;
88 }
89 case fdintCOPY_FILE:
90 {
91 int fih = 0;
92 char target[256];
93 trace(
94 "fdintCOPY_FILE:\n"
95 "-name: %s\n"
96 "-uncompressed size: %d\n"
97 "-date: %d\n"
98 "-time: %d\n"
99 "-attributes: %d\n"
100 "-file's folder index: %d\n",
|
101 rizwank 2.14 pfdin->psz1, pfdin->cb, pfdin->date, pfdin->time, pfdin->attribs, pfdin->iFolder
|
102 rizwank 2.11 );
103 sprintf(target, "./%s",pfdin->psz1);
104 fih = tvfs_open (target,
105 _O_BINARY | _O_CREAT | _O_WRONLY | _O_SEQUENTIAL,
106 _S_IREAD | _S_IWRITE
107 );
108 return fih;
109 }
110 case fdintCLOSE_FILE_INFO:
111 {
|
112 rizwank 2.12 #ifdef VERBOSE
|
113 rizwank 2.11 trace(
114 "fdintCLOSE_FILE:\n"
115 "-name: %s\n"
116 "-handle: %d\n"
117 "-date: %d\n"
118 "-time: %d\n"
119 "-attributes: %d\n"
120 "-file's folder index: %d\n"
121 "-run: %d\n",
|
122 rizwank 2.14 pfdin->psz1, pfdin->hf, pfdin->date, pfdin->time, pfdin->attribs, pfdin->iFolder, pfdin->cb
|
123 rizwank 2.11 );
|
124 rizwank 2.12 #endif
|
125 rizwank 2.11
126 tvfs_close(pfdin->hf);
127 return TRUE;
128 }
129 case fdintNEXT_CABINET:
130 {
131 trace("fdintNEXT_CABINET\n");
132 return 0;
133 }
134 case fdintENUMERATE:
135 {
136 trace("fdintENUMERATE\n");
137 return 0;
138 }
139 }
140 return 0;
|
141 rizwank 2.3 }
|
142 cs130_alex 2.1
|
143 rizwank 2.3 static void printCabInfo(FDICABINETINFO cabinfo){
|
144 rizwank 2.11 trace(" Cabinet Data : cbC %d cF %d cFi %d si %d iC %d fr %d hp %d hn %d\n",
145 cabinfo.cbCabinet,
146 cabinfo.cFolders ,
147 cabinfo.cFiles ,
148 cabinfo.setID,
149 cabinfo.iCabinet,
150 cabinfo.fReserve ,
151 cabinfo.hasprev ,
152 cabinfo.hasnext );
|
153 rizwank 2.7 }
|
154 cs130_alex 2.1
|
155 cs130_alex 2.2 static void CheckCabInfo(char * cabname,
|
156 rizwank 2.11 FDICABINETINFO cabinfo,
157 long TcbCabinet,
158 USHORT TcFolders,
159 USHORT TcFiles,
160 USHORT TsetID,
161 USHORT TiCabinet,
162 BOOL TfReserve,
163 BOOL Thasprev,
164 BOOL Thasnext){
165 ok2 ( cabinfo.cbCabinet == TcbCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
166 ok2 ( cabinfo.cFolders == TcFolders, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
167 ok2 ( cabinfo.cFiles == TcFiles, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
168 ok2 ( cabinfo.setID == TsetID, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
169 ok2 ( cabinfo.iCabinet == TiCabinet, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
170 ok2 ( cabinfo.fReserve == TfReserve, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
171 ok2 ( cabinfo.hasprev == Thasprev, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
172 ok2 ( cabinfo.hasnext == Thasnext, "FDIIsCabinet,cabinfo %s data did not match! Failed!\n", cabname);
173 }
|
174 rizwank 2.14 /* TODO : Message should contain variable values */
175 /* TODO : Use ok - is ok in standalone different fron winetest? */
|
176 rizwank 2.11
177 static HFDI hfdi_unknown;
|
178 rizwank 1.4 /* yes its global and ugly */
179
|
180 rizwank 2.0 /* Is CPU386 or Unknown more commonly used? */
|
181 rizwank 1.1
|
182 rizwank 1.4 static void TestCreate(void) {
|
183 rizwank 2.11
184 ERF error_structure;
185
186 trace("Starting TestCreate()\n");
187
188 hfdi_unknown = FDICreate(
189 final_alloc,
190 final_free,
191 tvfs_open, tvfs_read, tvfs_write, tvfs_close, tvfs_lseek,
192 cpuUNKNOWN,
193 &error_structure
194 );
195
196 ok(hfdi_unknown != NULL,"FDICreate (CPU = unknown) (functions=tvfs) failed!\n");
197
198 trace("Ending TestCreate()\n");
|
199 rizwank 1.7 }
200
201 static void TestInfo(void) {
|
202 rizwank 2.11
203 int fd;
204
205 FDICABINETINFO fdi_cabinfo_simple, fdi_cabinfo_complex;
206
207 trace("Starting TestInfo()\n");
208
209 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
210 fd = tvfs_open( name_simple_cab, _O_BINARY, 0 );
211
212 ok( FDIIsCabinet( hfdi_unknown, fd, &fdi_cabinfo_simple) == TRUE,
213 "FDIIsCabinet (Virtual File = Simple.cab) failed!\n");
214
215 printCabInfo(fdi_cabinfo_simple);
216 CheckCabInfo("simple.cab",fdi_cabinfo_simple,121,1,1,0,0,0,0,0);
217
218 tvfs_close(fd);
219 tvfs_free();
220
221 trace("Ending TestInfo()\n");
|
222 rizwank 1.7 }
|
223 cs130_alex 2.1
|
224 rizwank 2.3 static void TestCopy(void){
|
225 rizwank 2.11
226 char name_file_path[256];
227 int result;
228
229 trace("Starting TestCopy()\n");
230 trace("---simple.cab\n");
231
232 tvfs_create( name_simple_cab, file_simple_cab, size_simple_cab);
233 FDICopy(hfdi_unknown,
234 "simple.cab",
235 "",
236 0,
237 notification_function,
238 NULL,
239 NULL);
240
241 /* Filename when extracted is ./<filename> */
242 sprintf(name_file_path, "./%s", name_simple_txt);
243 result = tvfs_compare(name_file_path, file_simple_txt, size_simple_txt);
244 if (result)
245 trace ("File %s compare failed!\n",name_file_path);
246 rizwank 2.11 tvfs_free();
247
248 trace("Ending TestCopy()\n");
|
249 cs130_alex 2.1 }
250
|
251 rizwank 1.7 static void TestDestroy(void) {
|
252 rizwank 2.11 trace("Starting TestDestroy()\n");
253 ok(FDIDestroy(hfdi_unknown), "FDIDestroy (CPU = unknown) (functions=tvfs) failed!\n");
254 trace("Ending TestDestroy()\n");
|
255 rizwank 1.4 }
|
256 rizwank 1.1
|
257 rizwank 2.13 START_TEST(cabinet_fdi)
|
258 rizwank 1.1 {
|
259 rizwank 2.11 TestCreate();
260 TestInfo();
261 TestCopy();
262 TestDestroy();
263 tvfs_free();
|
264 rizwank 1.1 }
|