Check file sharing permissions based on the file inode instead of the
[wine] / dlls / kernel / tests / file.c
1 /*
2  * Unit tests for file functions in Wine
3  *
4  * Copyright (c) 2002 Jakob Eriksson
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
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <time.h>
25
26 #include "wine/test.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
30
31 LPCSTR filename = "testfile.xxx";
32 LPCSTR sillytext =
33 "en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla."
34 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
35 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
36 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
37 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
38 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
39 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
40 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
41 "1234 43 4kljf lf &%%%&&&&&& 34 4 34   3############# 33 3 3 3 # 3## 3"
42 "sdlkfjasdlkfj a dslkj adsklf  \n  \nasdklf askldfa sdlkf \nsadklf asdklf asdf ";
43
44
45 static void test__hread( void )
46 {
47     HFILE filehandle;
48     char buffer[10000];
49     long bytes_read;
50     long bytes_wanted;
51     long i;
52
53     SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL); /* be sure to remove stale files */
54     DeleteFileA( filename );
55     filehandle = _lcreat( filename, 0 );
56     if (filehandle == HFILE_ERROR)
57     {
58         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
59         return;
60     }
61
62     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
63
64     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
65
66     filehandle = _lopen( filename, OF_READ );
67
68     ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError(  ) );
69
70     bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
71
72     ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
73
74     for (bytes_wanted = 0; bytes_wanted < lstrlenA( sillytext ); bytes_wanted++)
75     {
76         ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
77         ok( _hread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
78         for (i = 0; i < bytes_wanted; i++)
79         {
80             ok( buffer[i] == sillytext[i], "that's not what's written\n" );
81         }
82     }
83
84     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
85
86     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
87 }
88
89
90 static void test__hwrite( void )
91 {
92     HFILE filehandle;
93     char buffer[10000];
94     long bytes_read;
95     long bytes_written;
96     long blocks;
97     long i;
98     char *contents;
99     HLOCAL memory_object;
100     char checksum[1];
101
102     filehandle = _lcreat( filename, 0 );
103     if (filehandle == HFILE_ERROR)
104     {
105         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
106         return;
107     }
108
109     ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains\n" );
110
111     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
112
113     filehandle = _lopen( filename, OF_READ );
114
115     bytes_read = _hread( filehandle, buffer, 1);
116
117     ok( 0 == bytes_read, "file read size error\n" );
118
119     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
120
121     filehandle = _lopen( filename, OF_READWRITE );
122
123     bytes_written = 0;
124     checksum[0] = '\0';
125     srand( (unsigned)time( NULL ) );
126     for (blocks = 0; blocks < 100; blocks++)
127     {
128         for (i = 0; i < (long)sizeof( buffer ); i++)
129         {
130             buffer[i] = rand(  );
131             checksum[0] = checksum[0] + buffer[i];
132         }
133         ok( HFILE_ERROR != _hwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
134         bytes_written = bytes_written + sizeof( buffer );
135     }
136
137     ok( HFILE_ERROR != _hwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
138     bytes_written++;
139
140     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
141
142     memory_object = LocalAlloc( LPTR, bytes_written );
143
144     ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)\n" );
145
146     contents = LocalLock( memory_object );
147
148     filehandle = _lopen( filename, OF_READ );
149
150     contents = LocalLock( memory_object );
151
152     ok( NULL != contents, "LocalLock whines\n" );
153
154     ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
155
156     checksum[0] = '\0';
157     i = 0;
158     do
159     {
160         checksum[0] = checksum[0] + contents[i];
161         i++;
162     }
163     while (i < bytes_written - 1);
164
165     ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
166
167     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
168
169     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
170 }
171
172
173 static void test__lclose( void )
174 {
175     HFILE filehandle;
176
177     filehandle = _lcreat( filename, 0 );
178     if (filehandle == HFILE_ERROR)
179     {
180         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
181         return;
182     }
183
184     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
185
186     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
187
188     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
189 }
190
191
192 static void test__lcreat( void )
193 {
194     HFILE filehandle;
195     char buffer[10000];
196     WIN32_FIND_DATAA search_results;
197     char slashname[] = "testfi/";
198     int err;
199     HANDLE find;
200
201     filehandle = _lcreat( filename, 0 );
202     if (filehandle == HFILE_ERROR)
203     {
204         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
205         return;
206     }
207
208     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
209
210     ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
211
212     ok( _hread( filehandle, buffer, strlen( sillytext ) ) ==  lstrlenA( sillytext ), "erratic _hread return value\n" );
213
214     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
215
216     ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" );
217
218     ok( DeleteFileA(filename) != 0, "DeleteFile failed (%ld)\n", GetLastError());
219
220     filehandle = _lcreat( filename, 1 ); /* readonly */
221     ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError(  ) );
222
223     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less\n" );
224
225     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
226
227     ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" );
228
229     ok( 0 == DeleteFileA( filename ), "shouldn't be able to delete a readonly file\n" );
230
231     ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" );
232
233     ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file!\n" );
234
235     filehandle = _lcreat( filename, 2 );
236     ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError(  ) );
237
238     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
239
240     ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
241
242     ok( _hread( filehandle, buffer, strlen( sillytext ) ) ==  lstrlenA( sillytext ), "erratic _hread return value\n" );
243
244     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
245
246     ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" );
247
248     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
249
250     filehandle = _lcreat( filename, 4 ); /* SYSTEM file */
251     ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError(  ) );
252
253     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
254
255     ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
256
257     ok( _hread( filehandle, buffer, strlen( sillytext ) ) ==  lstrlenA( sillytext ), "erratic _hread return value\n" );
258
259     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
260
261     ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" );
262
263     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
264
265     filehandle=_lcreat (slashname, 0); /* illegal name */
266     if (HFILE_ERROR==filehandle) {
267       err=GetLastError ();
268       ok (err==ERROR_INVALID_NAME || err==ERROR_PATH_NOT_FOUND,
269           "creating file \"%s\" failed with error %d\n", slashname, err);
270     } else { /* only NT succeeds */
271       _lclose(filehandle);
272       find=FindFirstFileA (slashname, &search_results);
273       if (INVALID_HANDLE_VALUE!=find)
274       {
275         ok (0!=FindClose (find), "FindClose complains (%ld)\n", GetLastError ());
276         slashname[strlen(slashname)-1]=0;
277         ok (!strcmp (slashname, search_results.cFileName),
278             "found unexpected name \"%s\"\n", search_results.cFileName);
279         ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes,
280             "attributes of file \"%s\" are 0x%04lx\n", search_results.cFileName,
281             search_results.dwFileAttributes);
282       }
283       ok (0!=DeleteFileA (slashname), "Can't delete \"%s\" (%ld)\n", slashname,
284           GetLastError ());
285     }
286
287     filehandle=_lcreat (filename, 8); /* illegal attribute */
288     if (HFILE_ERROR==filehandle)
289       ok (0, "couldn't create volume label \"%s\"\n", filename);
290     else {
291       _lclose(filehandle);
292       find=FindFirstFileA (filename, &search_results);
293       if (INVALID_HANDLE_VALUE==find)
294         ok (0, "file \"%s\" not found\n", filename);
295       else {
296         ok (0!=FindClose (find), "FindClose complains (%ld)\n", GetLastError ());
297         ok (!strcmp (filename, search_results.cFileName),
298             "found unexpected name \"%s\"\n", search_results.cFileName);
299         ok (FILE_ATTRIBUTE_ARCHIVE==search_results.dwFileAttributes,
300             "attributes of file \"%s\" are 0x%04lx\n", search_results.cFileName,
301             search_results.dwFileAttributes);
302       }
303       ok (0!=DeleteFileA (filename), "Can't delete \"%s\" (%ld)\n", slashname,
304           GetLastError ());
305     }
306 }
307
308
309 static void test__llseek( void )
310 {
311     INT i;
312     HFILE filehandle;
313     char buffer[1];
314     long bytes_read;
315
316     filehandle = _lcreat( filename, 0 );
317     if (filehandle == HFILE_ERROR)
318     {
319         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
320         return;
321     }
322
323     for (i = 0; i < 400; i++)
324     {
325         ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
326     }
327     ok( HFILE_ERROR != _llseek( filehandle, 400 * strlen( sillytext ), FILE_CURRENT ), "should be able to seek\n" );
328     ok( HFILE_ERROR != _llseek( filehandle, 27 + 35 * strlen( sillytext ), FILE_BEGIN ), "should be able to seek\n" );
329
330     bytes_read = _hread( filehandle, buffer, 1);
331     ok( 1 == bytes_read, "file read size error\n" );
332     ok( buffer[0] == sillytext[27], "_llseek error, it got lost seeking\n" );
333     ok( HFILE_ERROR != _llseek( filehandle, -400 * strlen( sillytext ), FILE_END ), "should be able to seek\n" );
334
335     bytes_read = _hread( filehandle, buffer, 1);
336     ok( 1 == bytes_read, "file read size error\n" );
337     ok( buffer[0] == sillytext[0], "_llseek error, it got lost seeking\n" );
338     ok( HFILE_ERROR != _llseek( filehandle, 1000000, FILE_END ), "should be able to seek past file; poor, poor Windows programmers\n" );
339     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
340
341     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
342 }
343
344
345 static void test__llopen( void )
346 {
347     HFILE filehandle;
348     UINT bytes_read;
349     char buffer[10000];
350
351     filehandle = _lcreat( filename, 0 );
352     if (filehandle == HFILE_ERROR)
353     {
354         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
355         return;
356     }
357
358     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
359     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
360
361     filehandle = _lopen( filename, OF_READ );
362     ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write!\n" );
363     bytes_read = _hread( filehandle, buffer, strlen( sillytext ) );
364     ok( strlen( sillytext )  == bytes_read, "file read size error\n" );
365     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
366
367     filehandle = _lopen( filename, OF_READWRITE );
368     bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
369     ok( strlen( sillytext )  == bytes_read, "file read size error\n" );
370     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
371     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
372
373     filehandle = _lopen( filename, OF_WRITE );
374     ok( HFILE_ERROR == _hread( filehandle, buffer, 1 ), "you should only be able to write this file\n" );
375     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine\n" );
376     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
377
378     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
379     /* TODO - add tests for the SHARE modes  -  use two processes to pull this one off */
380 }
381
382
383 static void test__lread( void )
384 {
385     HFILE filehandle;
386     char buffer[10000];
387     long bytes_read;
388     UINT bytes_wanted;
389     UINT i;
390
391     filehandle = _lcreat( filename, 0 );
392     if (filehandle == HFILE_ERROR)
393     {
394         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
395         return;
396     }
397
398     ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
399
400     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
401
402     filehandle = _lopen( filename, OF_READ );
403
404     ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError());
405
406     bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) );
407
408     ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
409
410     for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
411     {
412         ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
413         ok( _lread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value\n" );
414         for (i = 0; i < bytes_wanted; i++)
415         {
416             ok( buffer[i] == sillytext[i], "that's not what's written\n" );
417         }
418     }
419
420     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
421
422     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
423 }
424
425
426 static void test__lwrite( void )
427 {
428     HFILE filehandle;
429     char buffer[10000];
430     long bytes_read;
431     long bytes_written;
432     long blocks;
433     long i;
434     char *contents;
435     HLOCAL memory_object;
436     char checksum[1];
437
438     filehandle = _lcreat( filename, 0 );
439     if (filehandle == HFILE_ERROR)
440     {
441         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
442         return;
443     }
444
445     ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains\n" );
446
447     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
448
449     filehandle = _lopen( filename, OF_READ );
450
451     bytes_read = _hread( filehandle, buffer, 1);
452
453     ok( 0 == bytes_read, "file read size error\n" );
454
455     ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
456
457     filehandle = _lopen( filename, OF_READWRITE );
458
459     bytes_written = 0;
460     checksum[0] = '\0';
461     srand( (unsigned)time( NULL ) );
462     for (blocks = 0; blocks < 100; blocks++)
463     {
464         for (i = 0; i < (long)sizeof( buffer ); i++)
465         {
466             buffer[i] = rand(  );
467             checksum[0] = checksum[0] + buffer[i];
468         }
469         ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
470         bytes_written = bytes_written + sizeof( buffer );
471     }
472
473     ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
474     bytes_written++;
475
476     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
477
478     memory_object = LocalAlloc( LPTR, bytes_written );
479
480     ok( 0 != memory_object, "LocalAlloc fails, could be out of memory\n" );
481
482     contents = LocalLock( memory_object );
483
484     filehandle = _lopen( filename, OF_READ );
485
486     contents = LocalLock( memory_object );
487
488     ok( NULL != contents, "LocalLock whines\n" );
489
490     ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
491
492     checksum[0] = '\0';
493     i = 0;
494     do
495     {
496         checksum[0] += contents[i];
497         i++;
498     }
499     while (i < bytes_written - 1);
500
501     ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
502
503     ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
504
505     ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError(  ) );
506 }
507
508 static void test_CopyFileA(void)
509 {
510     char temp_path[MAX_PATH];
511     char source[MAX_PATH], dest[MAX_PATH];
512     static const char prefix[] = "pfx";
513     DWORD ret;
514
515     ret = GetTempPathA(MAX_PATH, temp_path);
516     ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
517     ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
518
519     ret = GetTempFileNameA(temp_path, prefix, 0, source);
520     ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
521
522     ret = GetTempFileNameA(temp_path, prefix, 0, dest);
523     ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
524
525     ret = CopyFileA(source, dest, TRUE);
526     ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
527        "CopyFileA: unexpected error %ld\n", GetLastError());
528
529     ret = CopyFileA(source, dest, FALSE);
530     ok(ret,  "CopyFileA: error %ld\n", GetLastError());
531
532     ret = DeleteFileA(source);
533     ok(ret, "DeleteFileA: error %ld\n", GetLastError());
534     ret = DeleteFileA(dest);
535     ok(ret, "DeleteFileA: error %ld\n", GetLastError());
536 }
537
538 static void test_CopyFileW(void)
539 {
540     WCHAR temp_path[MAX_PATH];
541     WCHAR source[MAX_PATH], dest[MAX_PATH];
542     static const WCHAR prefix[] = {'p','f','x',0};
543     DWORD ret;
544
545     ret = GetTempPathW(MAX_PATH, temp_path);
546     if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
547         return;
548     ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
549     ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
550
551     ret = GetTempFileNameW(temp_path, prefix, 0, source);
552     ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
553
554     ret = GetTempFileNameW(temp_path, prefix, 0, dest);
555     ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
556
557     ret = CopyFileW(source, dest, TRUE);
558     ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
559        "CopyFileW: unexpected error %ld\n", GetLastError());
560
561     ret = CopyFileW(source, dest, FALSE);
562     ok(ret,  "CopyFileW: error %ld\n", GetLastError());
563
564     ret = DeleteFileW(source);
565     ok(ret, "DeleteFileW: error %ld\n", GetLastError());
566     ret = DeleteFileW(dest);
567     ok(ret, "DeleteFileW: error %ld\n", GetLastError());
568 }
569
570 static void test_CreateFileA(void)
571 {
572     HANDLE hFile;
573     char temp_path[MAX_PATH];
574     char filename[MAX_PATH];
575     static const char prefix[] = "pfx";
576     DWORD ret;
577
578     ret = GetTempPathA(MAX_PATH, temp_path);
579     ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
580     ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
581
582     ret = GetTempFileNameA(temp_path, prefix, 0, filename);
583     ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
584
585     hFile = CreateFileA(filename, GENERIC_READ, 0, NULL,
586                         CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
587     ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS,
588         "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
589
590     ret = DeleteFileA(filename);
591     ok(ret, "DeleteFileA: error %ld\n", GetLastError());
592 }
593
594 static void test_CreateFileW(void)
595 {
596     HANDLE hFile;
597     WCHAR temp_path[MAX_PATH];
598     WCHAR filename[MAX_PATH];
599     static const WCHAR prefix[] = {'p','f','x',0};
600     DWORD ret;
601
602     ret = GetTempPathW(MAX_PATH, temp_path);
603     if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
604         return;
605     ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
606     ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
607
608     ret = GetTempFileNameW(temp_path, prefix, 0, filename);
609     ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
610
611     hFile = CreateFileW(filename, GENERIC_READ, 0, NULL,
612                         CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
613     ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS,
614         "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
615
616     ret = DeleteFileW(filename);
617     ok(ret, "DeleteFileW: error %ld\n", GetLastError());
618 }
619
620
621 static void test_GetTempFileNameA() {
622     UINT result;
623     char out[MAX_PATH];
624     char *expected = "c:\\windows\\abc2.tmp";
625
626     /* this test may depend on the config file settings */
627     result = GetTempFileNameA("C:", "abc", 1, out);
628     ok( result != 0, "GetTempFileNameA: error %ld\n", GetLastError() );
629     ok( ((out[0] == 'C') && (out[1] == ':')) && (out[2] == '\\'), "GetTempFileNameA: first three characters should be C:\\, string was actually %s\n", out );
630
631     result = GetTempFileNameA("c:\\windows\\", "abc", 2, out);
632     ok( result != 0, "GetTempFileNameA: error %ld\n", GetLastError() );
633     ok( lstrcmpiA( out, expected ) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n", out, expected );
634 }
635
636
637 static void test_DeleteFileA( void )
638 {
639     BOOL ret;
640
641     ret = DeleteFileA(NULL);
642     ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
643                 GetLastError() == ERROR_PATH_NOT_FOUND),
644        "DeleteFileA(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
645
646     ret = DeleteFileA("");
647     ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND ||
648                 GetLastError() == ERROR_BAD_PATHNAME),
649        "DeleteFileA(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
650 }
651
652 static void test_DeleteFileW( void )
653 {
654     BOOL ret;
655     WCHAR emptyW[]={'\0'};
656
657     ret = DeleteFileW(NULL);
658     if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
659         return;
660     ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
661        "DeleteFileW(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
662
663     ret = DeleteFileW(emptyW);
664     ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
665        "DeleteFileW(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
666 }
667
668 #define IsDotDir(x)     ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
669
670 static void test_MoveFileA(void)
671 {
672     char tempdir[MAX_PATH];
673     char source[MAX_PATH], dest[MAX_PATH];
674     static const char prefix[] = "pfx";
675     DWORD ret;
676
677     ret = GetTempPathA(MAX_PATH, tempdir);
678     ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
679     ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
680
681     ret = GetTempFileNameA(tempdir, prefix, 0, source);
682     ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
683
684     ret = GetTempFileNameA(tempdir, prefix, 0, dest);
685     ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
686
687     ret = MoveFileA(source, dest);
688     ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS,
689        "MoveFileA: unexpected error %ld\n", GetLastError());
690
691     ret = DeleteFileA(dest);
692     ok(ret, "DeleteFileA: error %ld\n", GetLastError());
693
694     ret = MoveFileA(source, dest);
695     ok(ret, "MoveFileA: failed, error %ld\n", GetLastError());
696
697     lstrcatA(tempdir, "Remove Me");
698     ret = CreateDirectoryA(tempdir, NULL);
699     ok(ret == TRUE, "CreateDirectoryA failed\n");
700
701     lstrcpyA(source, dest);
702     lstrcpyA(dest, tempdir);
703     lstrcatA(dest, "\\wild?.*");
704     ret = MoveFileA(source, dest);
705     todo_wine {
706       ok(!ret, "MoveFileA: shouldn't move to wildcard file\n");
707       ok(GetLastError() == ERROR_INVALID_NAME,
708               "MoveFileA: with wildcards, unexpected error %ld\n", GetLastError());
709 #if 0
710       if (ret || (GetLastError() != ERROR_INVALID_NAME))
711       {
712         WIN32_FIND_DATAA fd;
713         char temppath[MAX_PATH];
714         HANDLE hFind;
715
716         lstrcpyA(temppath, tempdir);
717         lstrcatA(temppath, "\\*.*");
718         hFind = FindFirstFileA(temppath, &fd);
719         if (INVALID_HANDLE_VALUE != hFind)
720         {
721           LPSTR lpName;
722           do
723           {
724             lpName = fd.cAlternateFileName;
725             if (!lpName[0])
726               lpName = fd.cFileName;
727             ok(IsDotDir(lpName), "MoveFileA: wildcards file created!\n");
728           }
729           while (FindNextFileA(hFind, &fd));
730           FindClose(hFind);
731         }
732       }
733 #endif
734       ret = DeleteFileA(source);
735       ok(ret, "DeleteFileA: error %ld\n", GetLastError());
736       ret = DeleteFileA(dest);
737       ok(!ret, "DeleteFileA: error %ld\n", GetLastError());
738     }
739
740     ret = RemoveDirectoryA(tempdir);
741     ok(ret, "DeleteDirectoryA: error %ld\n", GetLastError());
742 }
743
744 static void test_MoveFileW(void)
745 {
746     WCHAR temp_path[MAX_PATH];
747     WCHAR source[MAX_PATH], dest[MAX_PATH];
748     static const WCHAR prefix[] = {'p','f','x',0};
749     DWORD ret;
750
751     ret = GetTempPathW(MAX_PATH, temp_path);
752     if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
753         return;
754     ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
755     ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
756
757     ret = GetTempFileNameW(temp_path, prefix, 0, source);
758     ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
759
760     ret = GetTempFileNameW(temp_path, prefix, 0, dest);
761     ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
762
763     ret = MoveFileW(source, dest);
764     ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS,
765        "CopyFileW: unexpected error %ld\n", GetLastError());
766
767     ret = DeleteFileW(source);
768     ok(ret, "DeleteFileW: error %ld\n", GetLastError());
769     ret = DeleteFileW(dest);
770     ok(ret, "DeleteFileW: error %ld\n", GetLastError());
771 }
772
773 #define PATTERN_OFFSET 0x10
774
775 static void test_offset_in_overlapped_structure(void)
776 {
777     HANDLE hFile;
778     OVERLAPPED ov;
779     DWORD done;
780     BOOL rc;
781     BYTE buf[256], pattern[] = "TeSt";
782     UINT i;
783     char temp_path[MAX_PATH], temp_fname[MAX_PATH];
784
785     ok(GetTempPathA(MAX_PATH, temp_path) != 0, "GetTempPathA error %ld\n", GetLastError());
786     ok(GetTempFileNameA(temp_path, "pfx", 0, temp_fname) != 0, "GetTempFileNameA error %ld\n", GetLastError());
787
788     /*** Write File *****************************************************/
789
790     hFile = CreateFileA(temp_fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
791     ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
792
793     for(i = 0; i < sizeof(buf); i++) buf[i] = i;
794     ok(WriteFile(hFile, buf, sizeof(buf), &done, NULL), "WriteFile error %ld\n", GetLastError());
795     ok(done == sizeof(buf), "expected number of bytes written %lu\n", done);
796
797     memset(&ov, 0, sizeof(ov));
798     ov.Offset = PATTERN_OFFSET;
799     ov.OffsetHigh = 0;
800     rc=WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
801     /* Win 9x does not support the overlapped I/O on files */
802     if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
803         ok(rc, "WriteFile error %ld\n", GetLastError());
804         ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
805         trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));
806         ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
807            "expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern));
808
809         ov.Offset = sizeof(buf) * 2;
810         ov.OffsetHigh = 0;
811         ok(WriteFile(hFile, pattern, sizeof(pattern), &done, &ov), "WriteFile error %ld\n", GetLastError());
812         ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
813         /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
814         ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (sizeof(buf) * 2 + sizeof(pattern)),
815            "expected file offset %d\n", sizeof(buf) * 2 + sizeof(pattern));
816     }
817
818     CloseHandle(hFile);
819
820     /*** Read File *****************************************************/
821
822     hFile = CreateFileA(temp_fname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
823     ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
824
825     memset(buf, 0, sizeof(buf));
826     memset(&ov, 0, sizeof(ov));
827     ov.Offset = PATTERN_OFFSET;
828     ov.OffsetHigh = 0;
829     rc=ReadFile(hFile, buf, sizeof(pattern), &done, &ov);
830     /* Win 9x does not support the overlapped I/O on files */
831     if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
832         ok(rc, "ReadFile error %ld\n", GetLastError());
833         ok(done == sizeof(pattern), "expected number of bytes read %lu\n", done);
834         trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));
835         ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
836            "expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern));
837         ok(!memcmp(buf, pattern, sizeof(pattern)), "pattern match failed\n");
838     }
839
840     CloseHandle(hFile);
841
842     ok(DeleteFileA(temp_fname), "DeleteFileA error %ld\n", GetLastError());
843 }
844
845 static void test_LockFile(void)
846 {
847     HANDLE handle;
848     DWORD written;
849     OVERLAPPED overlapped;
850
851     handle = CreateFileA( filename, GENERIC_READ | GENERIC_WRITE,
852                           FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
853                           CREATE_ALWAYS, 0, 0 );
854     if (handle == INVALID_HANDLE_VALUE)
855     {
856         ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
857         return;
858     }
859     ok( WriteFile( handle, sillytext, strlen(sillytext), &written, NULL ), "write failed\n" );
860
861     ok( LockFile( handle, 0, 0, 0, 0 ), "LockFile failed\n" );
862     ok( UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile failed\n" );
863     ok( !UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile succeeded\n" );
864
865     ok( LockFile( handle, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
866     /* overlapping locks must fail */
867     ok( !LockFile( handle, 12, 0, 10, 0 ), "LockFile 12,10 succeeded\n" );
868     ok( !LockFile( handle, 5, 0, 6, 0 ), "LockFile 5,6 succeeded\n" );
869     /* non-overlapping locks must succeed */
870     ok( LockFile( handle, 5, 0, 5, 0 ), "LockFile 5,5 failed\n" );
871
872     ok( !UnlockFile( handle, 10, 0, 10, 0 ), "UnlockFile 10,10 succeeded\n" );
873     ok( UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 failed\n" );
874     ok( !UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" );
875     ok( UnlockFile( handle, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" );
876
877     overlapped.Offset = 100;
878     overlapped.OffsetHigh = 0;
879     overlapped.hEvent = 0;
880     ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 100,100 failed\n" );
881     /* overlapping shared locks are OK */
882     overlapped.Offset = 150;
883     ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" );
884     /* but exclusive is not */
885     ok( !LockFileEx( handle, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY, 0, 50, 0, &overlapped ),
886         "LockFileEx exclusive 150,50 succeeded\n" );
887     ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 150,100 failed\n" );
888     ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 150,100 again succeeded\n" );
889     overlapped.Offset = 100;
890     ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 failed\n" );
891     ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 again succeeded\n" );
892
893     ok( LockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "LockFile failed\n" );
894     ok( !LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" );
895     ok( !LockFile( handle, 0, 0x20000000, 20, 0 ), "LockFile 0x20000000,20 succeeded\n" );
896     ok( UnlockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "UnlockFile failed\n" );
897
898     /* wrap-around lock should not do anything */
899     /* (but still succeeds on NT4 so we don't check result) */
900     LockFile( handle, 0, 0x10000000, 0, 0xf0000001 );
901     ok( LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 failed\n" );
902     ok( UnlockFile( handle, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" );
903
904     /* zero-byte lock */
905     ok( LockFile( handle, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" );
906     ok( !LockFile( handle, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
907     ok( LockFile( handle, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
908     ok( LockFile( handle, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
909     ok( UnlockFile( handle, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
910     ok( UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" );
911     ok( UnlockFile( handle, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" );
912
913     CloseHandle( handle );
914     DeleteFileA( filename );
915 }
916
917 static inline int is_sharing_compatible( DWORD access1, DWORD sharing1, DWORD access2, DWORD sharing2 )
918 {
919     if (!access1 || !access2) return 1;
920     if ((access1 & GENERIC_READ) && !(sharing2 & FILE_SHARE_READ)) return 0;
921     if ((access1 & GENERIC_WRITE) && !(sharing2 & FILE_SHARE_WRITE)) return 0;
922     if ((access2 & GENERIC_READ) && !(sharing1 & FILE_SHARE_READ)) return 0;
923     if ((access2 & GENERIC_WRITE) && !(sharing1 & FILE_SHARE_WRITE)) return 0;
924     return 1;
925 }
926
927 static void test_file_sharing(void)
928 {
929     static const DWORD access_modes[4] = { 0, GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE };
930     static const DWORD sharing_modes[4] = { 0, FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE };
931     int a1, s1, a2, s2;
932
933     for (a1 = 0; a1 < 4; a1++)
934     {
935         for (s1 = 0; s1 < 4; s1++)
936         {
937             HANDLE h = CreateFileA( filename, access_modes[a1], sharing_modes[s1],
938                                     NULL, CREATE_ALWAYS, 0, 0 );
939             if (h == INVALID_HANDLE_VALUE)
940             {
941                 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
942                 return;
943             }
944             for (a2 = 0; a2 < 4; a2++)
945             {
946                 for (s2 = 0; s2 < 4; s2++)
947                 {
948                     HANDLE h2 = CreateFileA( filename, access_modes[a2], sharing_modes[s2],
949                                           NULL, CREATE_ALWAYS, 0, 0 );
950                     if (is_sharing_compatible( access_modes[a1], sharing_modes[s1],
951                                                access_modes[a2], sharing_modes[s2] ))
952                     {
953                         ok( h2 != INVALID_HANDLE_VALUE,
954                             "open failed for modes %lx/%lx/%lx/%lx err %ld\n",
955                             access_modes[a1], sharing_modes[s1],
956                             access_modes[a2], sharing_modes[s2], GetLastError() );
957                     }
958                     else
959                     {
960                         ok( h2 == INVALID_HANDLE_VALUE,
961                             "open succeeded for modes %lx/%lx/%lx/%lx\n",
962                             access_modes[a1], sharing_modes[s1],
963                             access_modes[a2], sharing_modes[s2] );
964                         if (h2 == INVALID_HANDLE_VALUE)
965                             ok( GetLastError() == ERROR_SHARING_VIOLATION,
966                                 "wrong error code %ld\n", GetLastError() );
967                     }
968                     if (h2 != INVALID_HANDLE_VALUE) CloseHandle( h2 );
969                 }
970             }
971             CloseHandle( h );
972         }
973     }
974     DeleteFileA( filename );
975 }
976
977 static void test_FindFirstFileA()
978 {
979     HANDLE handle;
980     WIN32_FIND_DATAA search_results;
981     int err;
982
983     handle = FindFirstFileA("C:\\",&search_results);
984     err = GetLastError();
985     ok ( handle == INVALID_HANDLE_VALUE , "FindFirstFile on Root directory should Fail\n");
986     if (handle == INVALID_HANDLE_VALUE)
987       ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err);
988     handle = FindFirstFileA("C:\\*",&search_results);
989     ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed\n" );
990     ok ( FindClose(handle) == TRUE, "Failed to close handle\n");
991 }
992
993 static void test_FindNextFileA()
994 {
995     HANDLE handle;
996     WIN32_FIND_DATAA search_results;
997     int err;
998
999     handle = FindFirstFileA("C:\\*",&search_results);
1000     ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed\n" );
1001     while (FindNextFile(handle, &search_results))
1002     {
1003         /* get to the end of the files */
1004     }
1005     ok ( FindClose(handle) == TRUE, "Failed to close handle\n");
1006     err = GetLastError();
1007     ok ( err == ERROR_NO_MORE_FILES, "GetLastError should return ERROR_NO_MORE_FILES\n");
1008 }
1009
1010 static void test_MapFile()
1011 {
1012     HANDLE handle, hmap;
1013
1014     /* be sure to remove stale files */
1015     SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL);
1016     DeleteFile(filename);
1017     handle = CreateFile( filename, GENERIC_READ|GENERIC_WRITE, 0, 0,
1018                          CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1019     ok( handle != INVALID_HANDLE_VALUE, "couldn't create test file\n");
1020
1021     hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL );
1022     ok( hmap == NULL, "mapped zero size file\n");
1023     ok( GetLastError() == ERROR_FILE_INVALID, "not ERROR_FILE_INVALID\n");
1024
1025     hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0, NULL );
1026     ok( hmap == NULL, "mapping should fail\n");
1027     /* GetLastError() varies between win9x and WinNT */
1028
1029     hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0x10000, NULL );
1030     ok( hmap == NULL, "mapping should fail\n");
1031     /* GetLastError() varies between win9x and WinNT */
1032
1033     hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0x1000, NULL );
1034     ok( hmap != NULL, "mapping should succeed\n");
1035
1036     ok( CloseHandle( hmap ), "can't close mapping handle\n");
1037     ok( CloseHandle( handle ), "can't close file handle\n");
1038     ok( DeleteFileA( filename ), "DeleteFile failed after map\n" );
1039 }
1040
1041 START_TEST(file)
1042 {
1043     test__hread(  );
1044     test__hwrite(  );
1045     test__lclose(  );
1046     test__lcreat(  );
1047     test__llseek(  );
1048     test__llopen(  );
1049     test__lread(  );
1050     test__lwrite(  );
1051     test_GetTempFileNameA();
1052     test_CopyFileA();
1053     test_CopyFileW();
1054     test_CreateFileA();
1055     test_CreateFileW();
1056     test_DeleteFileA();
1057     test_DeleteFileW();
1058     test_MoveFileA();
1059     test_MoveFileW();
1060     test_FindFirstFileA();
1061     test_FindNextFileA();
1062     test_LockFile();
1063     test_file_sharing();
1064     test_offset_in_overlapped_structure();
1065     test_MapFile();
1066 }