(file) Return to cabinet_fdi.c CVS log (file) (dir) Up to [RizwankCVS] / group3 / wine / dlls / cabinet / tests

  1 rizwank 1.1 /*
  2              * Unit test suite for cabinet.dll - FDI functions
  3              *
  4              * Copyright 2004 Rizwan Kassim, Dan Kegel
  5              *
  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             #include <stdlib.h>
 22 rizwank 1.1 
 23             #ifndef STANDALONE
 24             #include <wine/test.h>
 25             #define ok2 ok
 26             #else
 27             /* To build outside Wine tree, compile with cl -DSTANDALONE -D_X86_ cabinet_fdi.c FDI.lib 
 28               These are only called if standalone are used, defining ok and START_TEST, which would normally be declared in winetree */
 29             #include <assert.h> 
 30             #include <stdio.h>
 31             #define START_TEST(name) main(int argc, char **argv)
 32             #define ok(condition, msg)       \
 33             	do { if(!(condition)) {  \
 34             		fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__); \
 35             		exit(1);         \
 36             	} } while(0)
 37             #define ok2(condition, msg, arg) \
 38                     do { if(!(condition)) {  \
 39             		fprintf(stderr,"failed at %d, msg:" msg "\n",__LINE__, arg); \
 40             		exit(1);         \
 41             	} } while(0)
 42             #define todo_wine
 43 rizwank 1.1 #endif 
 44             
 45             #include <winerror.h>
 46             #include <fdi.h>
 47 rizwank 1.7 #include <fcntl.h>
 48             
 49             static int fakeFD = 12;
 50             
 51             /* This is the hex string representation of the file created by compressing
 52                a simple text file with the contents "This is a test file."
 53              
 54                The file was created using COMPRESS.EXE from the Windows Server 2003
 55                Resource Kit from Microsoft.  The resource kit was retrieved from the
 56                following URL:  
 57             
 58                http://www.microsoft.com/downloads/details.aspx?FamilyID=9d467a69-57ff-4ae7-96ee-b18c4790cffd&displaylang=en
 59              */
 60             
 61             
 62             static unsigned char compressed_file[] = 
 63                {0x4D,0x53,0x43,0x46,0x00,0x00,0x00,0x00,0x75,0x00,
 64             	0x00,0x00,0x00,0x00,0x00,0x00,0x2C,0x00,0x00,0x00,
 65             	0x00,0x00,0x00,0x00,0x03,0x01,0x01,0x00,0x01,0x00,
 66             	0x00,0x00,0x39,0x30,0x00,0x00,0x45,0x00,0x00,0x00,
 67             	0x01,0x00,0x01,0x00,0x26,0x00,0x00,0x00,0x00,0x00,
 68 rizwank 1.7 	0x00,0x00,0x00,0x00,0x4A,0x32,0xB2,0xBE,0x20,0x00,
 69             	0x74,0x65,0x73,0x74,0x2E,0x74,0x78,0x74,0x00,0x9C,
 70             	0x74,0xD0,0x75,0x28,0x00,0x26,0x00,0x43,0x4B,0x0B,
 71             	0xCE,0x57,0xC8,0xC9,0xCF,0x4B,0xD7,0x51,0x48,0xCC,
 72             	0x4B,0x51,0x28,0xC9,0x48,0xCC,0xCB,0x2E,0x56,0x48,
 73             	0xCB,0x2F,0x52,0x48,0xCC,0xC9,0x01,0x72,0x53,0x15,
 74             	0xD2,0x32,0x8B,0x33,0xF4,0xB8,0x00};
 75             static int szcompressed_file = sizeof(compressed_file);
 76             
 77              /*
 78             static const char uncompressed_data[] = "This is a test file.";
 79             static const DWORD uncompressed_data_size = sizeof(uncompressed_data) - 1;
 80             
 81             static char *buf;
 82             */
 83 rizwank 1.1 
 84             /*	To do in FDI:				-from wine/include/fdi.h
 85             	FDICreate
 86             		File Open				-FNOPEN(pszFile,oflag,pmode)
 87             		File Read				-FNREAD(hf, pv, cb)
 88             		File Write				-FNWRITE(hf, pv, cb)
 89             		File Close				-FNCLOSE(hf)
 90             		File Seek				-FNSEEK(hf,dist,seektype)
 91             		Error Structure
 92             	FDIlsCabinet
 93             		FDICabinetInfo Structure
 94             	FDICopy
 95             		Notification function
 96             		Decryption function
 97             	FDIDestroy
 98             */
 99             
100 rizwank 1.7 	FDICABINETINFO	fdici;
101             
102             
103 rizwank 1.5 /* Currently mostly dummy function pointers */
104 rizwank 1.1 
105 rizwank 1.5 FNALLOC(debug_alloc) {
106              	printf("   FNALLOC just called with %d\n",cb);
107             	return malloc(cb);
108 rizwank 1.3 }
109             
110 rizwank 1.5 FNFREE(debug_free) {
111             	printf("   FNFREE just called with %d\n",pv);
112             	free(pv);
113 rizwank 1.3 	return;
114             }
115             
116 rizwank 1.5 /*
117 rizwank 1.7 	It is not necessary for these functions to actually call _open etc.; 
118             	these functions could instead call fopen, fread, fwrite, fclose, and fseek,
119             	or CreateFile, ReadFile, WriteFile, CloseHandle, and SetFilePointer, etc.
120             	However, the parameters and return codes will have to be translated
121             	appropriately (e.g. the file open mode passed in to pfnopen).
122             	
123             	Match i/o specs of _open, _read, _write, _close, and _lseek.
124             			
125             */
126             
127             /*	
128             	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open.2c_._wopen.asp
129             	_open 		I: const char *filename, int oflag, int pmode	O: int (handler), -1 for err.
130 rizwank 1.5 */
131             
132 rizwank 1.3 FNOPEN(dummy_open) {
133 rizwank 1.7 	 printf("  FNOPEN (dummy) just called with %d, %d, %d\n",pszFile, oflag, pmode);
134 rizwank 1.3 	return 0;
135             }
136             
137 rizwank 1.7 FNOPEN(fake_open) {
138             	 printf("  FNOPEN (fake) just called with %d, %d, %d\n",pszFile, oflag, pmode);
139             	 printf("  Returning %d as file descriptor\n",fakeFD);
140             	return 12;
141             }
142             
143             FNOPEN(real_open) {
144             	int handler = _open(pszFile,oflag,pmode);
145             	printf("   FNOPEN (real) just called with %s, %d, %d\n",pszFile, oflag, pmode);
146             	printf("   FNOPEN (real) returning handler (%d)\n",handler);
147             	return handler;
148             }
149             	
150             
151             /*
152             	http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__open.2c_._wopen.asp
153             	_read		I: int fd, void *buffer, unsigned int count		O:	int (szBuffer)
154             */
155             
156 rizwank 1.3 FNREAD(dummy_read) {
157 rizwank 1.7 	 printf("   FNREAD (dummy) just called with %d, %d, %d\n",hf, pv, cb);
158 rizwank 1.5 	return 0;
159 rizwank 1.3 }
160 rizwank 1.7 
161             FNREAD(fake_read) {
162             	 printf("   FNREAD (fake) just called with %d, %d, %d\n",hf, pv, cb);
163             	 if (hf == fakeFD) {
164             		 printf ("   Called with fake file descriptor, populating buffer and size (%d)\n",szcompressed_file);
165             		 memcpy (pv, compressed_file ,cb);
166             		 /* TODO */
167             		 }
168             	 else {
169             		 printf ("   FNREAD (fake) was called with the unknown file handler. Failed!\n",hf);
170             	 }
171             	return szcompressed_file;
172             }
173             
174             FNREAD(real_read) {
175             	int szBuffer = _read(hf,pv,cb);
176             	printf("   FNREAD (read) just called with %d, %d, %d\n",hf, pv, cb);
177             	printf("   FNREAD (read) returning size (%d)\n",szBuffer);
178             	return szBuffer;
179             }
180             
181 rizwank 1.7 
182 rizwank 1.3 	
183             FNWRITE(dummy_write) {
184 rizwank 1.5 	 printf("   FNWRITE just called with %d, %d, %d\n",hf, pv, cb);
185             	return 0;
186 rizwank 1.3 }
187             
188             
189             FNCLOSE(dummy_close) {
190 rizwank 1.5 	 printf("   FNCLOSE just called with %d\n",hf);	
191             	return 0;
192 rizwank 1.3 }
193 rizwank 1.1 
194 rizwank 1.3 FNSEEK(dummy_seek) {
195 rizwank 1.5 	 printf("   FNSEEK just called with %d, %d, %d\n",hf, dist, seektype);	
196             	return 0;
197 rizwank 1.3 }
198             
199 rizwank 1.7 HFDI hfdi_unknown_dummy, hfdi_unknown_fake,hfdi_unknown_real;
200             FDICABINETINFO  fdi_cabinfo;
201 rizwank 1.4 /* yes its global and ugly */
202             
203 rizwank 1.1 
204 rizwank 1.4 static void TestCreate(void) {
205             			
206             	ERF error_structure;
207             	
208             	printf("Starting TestCreate()\n");
209             	
210 rizwank 1.7 	hfdi_unknown_dummy = FDICreate(
211 rizwank 1.5 		debug_alloc,
212             		debug_free,
213             		dummy_open,
214             		dummy_read,
215             		dummy_write,
216             		dummy_close,
217             		dummy_seek,
218             		cpuUNKNOWN,
219             		&error_structure
220             	);
221 rizwank 1.7 	ok(hfdi_unknown_dummy != NULL,"FDICreate (CPU = unknown) (functions=dummy) failed!\n");		
222             
223             	hfdi_unknown_fake = FDICreate(
224             		debug_alloc,
225             		debug_free,
226             		fake_open,
227             		fake_read,
228             		dummy_write,
229             		dummy_close,
230             		dummy_seek,
231             		cpuUNKNOWN,
232             		&error_structure
233             	);
234             	ok(hfdi_unknown_fake != NULL,"FDICreate (CPU = unknown) (functions=fake) failed!\n");		
235             
236             	hfdi_unknown_real = FDICreate(
237             		debug_alloc,
238             		debug_free,
239             		real_open,
240             		real_read,
241             		dummy_write,
242 rizwank 1.7 		dummy_close,
243             		dummy_seek,
244             		cpuUNKNOWN,
245             		&error_structure
246             	);
247             	ok(hfdi_unknown_real != NULL,"FDICreate (CPU = unknown) (functions=real) failed!\n");		
248             		
249             	printf("Ending TestCreate()\n");		
250             }
251             
252             static void TestInfo(void) {
253             	int realfd;
254             	int sizer;
255             	char *buffer = malloc(szcompressed_file);
256             	
257             	printf("Starting TestInfo()\n");
258             		/* 
259             		1=> Does it return T (and fill FDICABINETINFO) if the file descriptor=>cabinet?
260             		2=> Does it return F (and ignore FDICABINETINFO) if the file descriptor != cabinet?
261             		3=> Does it return F (and ignore FDICABINETINFO) if the file descriptor == error?
262             				*/
263 rizwank 1.7 	ok ( FDIIsCabinet( hfdi_unknown_dummy, -1, &fdi_cabinfo) == FALSE,
264             			"FDIIsCabinet (File = Error) failed!\n");	
265             	
266             	ok ( FDIIsCabinet( hfdi_unknown_fake, fakeFD, &fdi_cabinfo) == FALSE,
267             			"FDIIsCabinet (File = WrongType) failed!\n");
268 rizwank 1.5 	
269 rizwank 1.7 	sizer = fake_read ( 12,buffer,szcompressed_file );
270             	printf(buffer);
271 rizwank 1.5 	
272 rizwank 1.7 	realfd = real_open( "TEST1.cab" , _O_BINARY | _O_RDONLY | _O_SEQUENTIAL, 0);
273             	ok ( FDIIsCabinet( hfdi_unknown_real, realfd, &fdi_cabinfo) == TRUE,
274             			"FDIIsCabinet (File = Cabinet) failed!\n");
275             	
276             	
277             }
278             		
279             
280             static void TestDestroy(void) {
281             	printf("Starting TestDestroy()\n");
282             		/* Only two things to check in FDIDestroy
283             	   1=> Does it return T if its passed an hfdi
284             	   2=> Does it return F if its passed a non hfdi
285             	   	EDIT : Causes GPL if FDIDestroy is called on an invalid pointer.
286             		ok( 0 == FDIDestroy(0), "Return true incorrectly in TestDestroy()!\n");
287             		*/
288             				
289             	ok(FDIDestroy(hfdi_unknown_dummy), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");
290             	ok(FDIDestroy(hfdi_unknown_fake), "FDIDestroy (CPU = unknown) (functions=fake) failed!\n");		
291             	printf("Ending TestDestroy()\n");
292 rizwank 1.5 		
293 rizwank 1.4 }
294 rizwank 1.1 
295 rizwank 1.7 
296 rizwank 1.1 START_TEST(paths)
297             {
298 rizwank 1.4 	
299             	TestCreate();
300 rizwank 1.7 	TestInfo();
301 rizwank 1.2 	/*
302             	TestCopy();
303 rizwank 1.3 	*/
304 rizwank 1.2 	TestDestroy();
305 rizwank 1.3 	
306 rizwank 1.1 }

Rizwan Kassim
Powered by
ViewCVS 0.9.2