Removed todo_wine from some tests that succeed now.
[wine/multimedia.git] / dlls / kernel / tests / file.c
blob8edebfd15cf5d83cd9f41f821562ba10aa680dc2
1 /*
2 * Unit tests for file functions in Wine
4 * Copyright (c) 2002 Jakob Eriksson
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.
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.
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
22 #include <stdarg.h>
23 #include <stdlib.h>
24 #include <time.h>
26 #include "wine/test.h"
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winerror.h"
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 ";
45 static void test__hread( void )
47 HFILE filehandle;
48 char buffer[10000];
49 long bytes_read;
50 long bytes_wanted;
51 long i;
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)
58 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
59 return;
62 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
64 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
66 filehandle = _lopen( filename, OF_READ );
68 ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError( ) );
70 bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
72 ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
74 for (bytes_wanted = 0; bytes_wanted < lstrlenA( sillytext ); bytes_wanted++)
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++)
80 ok( buffer[i] == sillytext[i], "that's not what's written\n" );
84 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
86 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
90 static void test__hwrite( void )
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];
102 filehandle = _lcreat( filename, 0 );
103 if (filehandle == HFILE_ERROR)
105 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
106 return;
109 ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains\n" );
111 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
113 filehandle = _lopen( filename, OF_READ );
115 bytes_read = _hread( filehandle, buffer, 1);
117 ok( 0 == bytes_read, "file read size error\n" );
119 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
121 filehandle = _lopen( filename, OF_READWRITE );
123 bytes_written = 0;
124 checksum[0] = '\0';
125 srand( (unsigned)time( NULL ) );
126 for (blocks = 0; blocks < 100; blocks++)
128 for (i = 0; i < (long)sizeof( buffer ); i++)
130 buffer[i] = rand( );
131 checksum[0] = checksum[0] + buffer[i];
133 ok( HFILE_ERROR != _hwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
134 bytes_written = bytes_written + sizeof( buffer );
137 ok( HFILE_ERROR != _hwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
138 bytes_written++;
140 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
142 memory_object = LocalAlloc( LPTR, bytes_written );
144 ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)\n" );
146 contents = LocalLock( memory_object );
148 filehandle = _lopen( filename, OF_READ );
150 contents = LocalLock( memory_object );
152 ok( NULL != contents, "LocalLock whines\n" );
154 ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
156 checksum[0] = '\0';
157 i = 0;
160 checksum[0] = checksum[0] + contents[i];
161 i++;
163 while (i < bytes_written - 1);
165 ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
167 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
169 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
173 static void test__lclose( void )
175 HFILE filehandle;
177 filehandle = _lcreat( filename, 0 );
178 if (filehandle == HFILE_ERROR)
180 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
181 return;
184 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
186 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
188 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
192 static void test__lcreat( void )
194 HFILE filehandle;
195 char buffer[10000];
196 WIN32_FIND_DATAA search_results;
197 char slashname[] = "testfi/";
198 int err;
199 HANDLE find;
201 filehandle = _lcreat( filename, 0 );
202 if (filehandle == HFILE_ERROR)
204 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
205 return;
208 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
210 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
212 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
214 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
216 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" );
218 ok( DeleteFileA(filename) != 0, "DeleteFile failed (%ld)\n", GetLastError());
220 filehandle = _lcreat( filename, 1 ); /* readonly */
221 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
223 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less\n" );
225 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
227 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file\n" );
229 ok( 0 == DeleteFileA( filename ), "shouldn't be able to delete a readonly file\n" );
231 ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file\n" );
233 ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file!\n" );
235 filehandle = _lcreat( filename, 2 );
236 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
238 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
240 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
242 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
244 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
246 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" );
248 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
250 filehandle = _lcreat( filename, 4 ); /* SYSTEM file */
251 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)\n", filename, GetLastError( ) );
253 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
255 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains\n" );
257 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == lstrlenA( sillytext ), "erratic _hread return value\n" );
259 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
261 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file\n" );
263 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
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)
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);
283 ok (0!=DeleteFileA (slashname), "Can't delete \"%s\" (%ld)\n", slashname,
284 GetLastError ());
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);
303 ok (0!=DeleteFileA (filename), "Can't delete \"%s\" (%ld)\n", slashname,
304 GetLastError ());
309 static void test__llseek( void )
311 INT i;
312 HFILE filehandle;
313 char buffer[1];
314 long bytes_read;
316 filehandle = _lcreat( filename, 0 );
317 if (filehandle == HFILE_ERROR)
319 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
320 return;
323 for (i = 0; i < 400; i++)
325 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
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" );
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" );
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" );
341 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
345 static void test__llopen( void )
347 HFILE filehandle;
348 UINT bytes_read;
349 char buffer[10000];
351 filehandle = _lcreat( filename, 0 );
352 if (filehandle == HFILE_ERROR)
354 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
355 return;
358 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
359 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
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" );
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" );
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" );
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 */
383 static void test__lread( void )
385 HFILE filehandle;
386 char buffer[10000];
387 long bytes_read;
388 UINT bytes_wanted;
389 UINT i;
391 filehandle = _lcreat( filename, 0 );
392 if (filehandle == HFILE_ERROR)
394 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
395 return;
398 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains\n" );
400 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
402 filehandle = _lopen( filename, OF_READ );
404 ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)\n", filename, GetLastError());
406 bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) );
408 ok( lstrlenA( sillytext ) == bytes_read, "file read size error\n" );
410 for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
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++)
416 ok( buffer[i] == sillytext[i], "that's not what's written\n" );
420 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
422 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
426 static void test__lwrite( void )
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];
438 filehandle = _lcreat( filename, 0 );
439 if (filehandle == HFILE_ERROR)
441 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
442 return;
445 ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains\n" );
447 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
449 filehandle = _lopen( filename, OF_READ );
451 bytes_read = _hread( filehandle, buffer, 1);
453 ok( 0 == bytes_read, "file read size error\n" );
455 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains\n" );
457 filehandle = _lopen( filename, OF_READWRITE );
459 bytes_written = 0;
460 checksum[0] = '\0';
461 srand( (unsigned)time( NULL ) );
462 for (blocks = 0; blocks < 100; blocks++)
464 for (i = 0; i < (long)sizeof( buffer ); i++)
466 buffer[i] = rand( );
467 checksum[0] = checksum[0] + buffer[i];
469 ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains\n" );
470 bytes_written = bytes_written + sizeof( buffer );
473 ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains\n" );
474 bytes_written++;
476 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
478 memory_object = LocalAlloc( LPTR, bytes_written );
480 ok( 0 != memory_object, "LocalAlloc fails, could be out of memory\n" );
482 contents = LocalLock( memory_object );
484 filehandle = _lopen( filename, OF_READ );
486 contents = LocalLock( memory_object );
488 ok( NULL != contents, "LocalLock whines\n" );
490 ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length\n" );
492 checksum[0] = '\0';
493 i = 0;
496 checksum[0] += contents[i];
497 i++;
499 while (i < bytes_written - 1);
501 ok( checksum[0] == contents[i], "stored checksum differ from computed checksum\n" );
503 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains\n" );
505 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)\n", GetLastError( ) );
508 static void test_CopyFileA(void)
510 char temp_path[MAX_PATH];
511 char source[MAX_PATH], dest[MAX_PATH];
512 static const char prefix[] = "pfx";
513 DWORD ret;
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");
519 ret = GetTempFileNameA(temp_path, prefix, 0, source);
520 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
522 ret = GetTempFileNameA(temp_path, prefix, 0, dest);
523 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
525 ret = CopyFileA(source, dest, TRUE);
526 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
527 "CopyFileA: unexpected error %ld\n", GetLastError());
529 ret = CopyFileA(source, dest, FALSE);
530 ok(ret, "CopyFileA: error %ld\n", GetLastError());
532 ret = DeleteFileA(source);
533 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
534 ret = DeleteFileA(dest);
535 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
538 static void test_CopyFileW(void)
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;
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");
551 ret = GetTempFileNameW(temp_path, prefix, 0, source);
552 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
554 ret = GetTempFileNameW(temp_path, prefix, 0, dest);
555 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
557 ret = CopyFileW(source, dest, TRUE);
558 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
559 "CopyFileW: unexpected error %ld\n", GetLastError());
561 ret = CopyFileW(source, dest, FALSE);
562 ok(ret, "CopyFileW: error %ld\n", GetLastError());
564 ret = DeleteFileW(source);
565 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
566 ret = DeleteFileW(dest);
567 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
570 static void test_CreateFileA(void)
572 HANDLE hFile;
573 char temp_path[MAX_PATH];
574 char filename[MAX_PATH];
575 static const char prefix[] = "pfx";
576 DWORD ret;
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");
582 ret = GetTempFileNameA(temp_path, prefix, 0, filename);
583 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
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");
590 ret = DeleteFileA(filename);
591 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
594 static void test_CreateFileW(void)
596 HANDLE hFile;
597 WCHAR temp_path[MAX_PATH];
598 WCHAR filename[MAX_PATH];
599 static const WCHAR emptyW[]={'\0'};
600 static const WCHAR prefix[] = {'p','f','x',0};
601 DWORD ret;
603 ret = GetTempPathW(MAX_PATH, temp_path);
604 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
605 return;
606 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
607 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
609 ret = GetTempFileNameW(temp_path, prefix, 0, filename);
610 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
612 hFile = CreateFileW(filename, GENERIC_READ, 0, NULL,
613 CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
614 ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS,
615 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
617 ret = DeleteFileW(filename);
618 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
620 hFile = CreateFileW(NULL, GENERIC_READ, 0, NULL,
621 CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
622 ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND,
623 "CreateFileW(NULL) returned ret=%p error=%ld\n",hFile,GetLastError());
625 hFile = CreateFileW(emptyW, GENERIC_READ, 0, NULL,
626 CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
627 ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_PATH_NOT_FOUND,
628 "CreateFileW(\"\") returned ret=%p error=%ld\n",hFile,GetLastError());
631 static void test_GetTempFileNameA()
633 UINT result;
634 char out[MAX_PATH];
635 char expected[MAX_PATH + 10];
636 char windowsdir[MAX_PATH + 10];
637 char windowsdrive[3];
639 result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
640 ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
641 ok(result != 0, "GetWindowsDirectory: error %ld\n", GetLastError());
643 /* If the Windows directory is the root directory, it ends in backslash, not else. */
644 if (strlen(windowsdir) != 3) /* As in "C:\" or "F:\" */
646 strcat(windowsdir, "\\");
649 windowsdrive[0] = windowsdir[0];
650 windowsdrive[1] = windowsdir[1];
651 windowsdrive[2] = '\0';
653 result = GetTempFileNameA(windowsdrive, "abc", 1, out);
654 ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError());
655 ok(((out[0] == windowsdrive[0]) && (out[1] == ':')) && (out[2] == '\\'),
656 "GetTempFileNameA: first three characters should be %c:\\, string was actually %s\n",
657 windowsdrive[0], out);
659 result = GetTempFileNameA(windowsdir, "abc", 2, out);
660 ok(result != 0, "GetTempFileNameA: error %ld\n", GetLastError());
661 expected[0] = '\0';
662 strcat(expected, windowsdir);
663 strcat(expected, "abc2.tmp");
664 ok(lstrcmpiA(out, expected) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n",
665 out, expected);
668 static void test_DeleteFileA( void )
670 BOOL ret;
672 ret = DeleteFileA(NULL);
673 ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
674 GetLastError() == ERROR_PATH_NOT_FOUND),
675 "DeleteFileA(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
677 ret = DeleteFileA("");
678 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND ||
679 GetLastError() == ERROR_BAD_PATHNAME),
680 "DeleteFileA(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
682 ret = DeleteFileA("nul");
683 ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND ||
684 GetLastError() == ERROR_INVALID_PARAMETER),
685 "DeleteFileA(\"nul\") returned ret=%d error=%ld\n",ret,GetLastError());
688 static void test_DeleteFileW( void )
690 BOOL ret;
691 static const WCHAR emptyW[]={'\0'};
693 ret = DeleteFileW(NULL);
694 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
695 return;
696 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
697 "DeleteFileW(NULL) returned ret=%d error=%ld\n",ret,GetLastError());
699 ret = DeleteFileW(emptyW);
700 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
701 "DeleteFileW(\"\") returned ret=%d error=%ld\n",ret,GetLastError());
704 #define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
706 static void test_MoveFileA(void)
708 char tempdir[MAX_PATH];
709 char source[MAX_PATH], dest[MAX_PATH];
710 static const char prefix[] = "pfx";
711 DWORD ret;
713 ret = GetTempPathA(MAX_PATH, tempdir);
714 ok(ret != 0, "GetTempPathA error %ld\n", GetLastError());
715 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
717 ret = GetTempFileNameA(tempdir, prefix, 0, source);
718 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
720 ret = GetTempFileNameA(tempdir, prefix, 0, dest);
721 ok(ret != 0, "GetTempFileNameA error %ld\n", GetLastError());
723 ret = MoveFileA(source, dest);
724 ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS,
725 "MoveFileA: unexpected error %ld\n", GetLastError());
727 ret = DeleteFileA(dest);
728 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
730 ret = MoveFileA(source, dest);
731 ok(ret, "MoveFileA: failed, error %ld\n", GetLastError());
733 lstrcatA(tempdir, "Remove Me");
734 ret = CreateDirectoryA(tempdir, NULL);
735 ok(ret == TRUE, "CreateDirectoryA failed\n");
737 lstrcpyA(source, dest);
738 lstrcpyA(dest, tempdir);
739 lstrcatA(dest, "\\wild?.*");
740 /* FIXME: if we create a file with wildcards we can't delete it now that DeleteFile works correctly */
741 ret = MoveFileA(source, dest);
742 ok(!ret, "MoveFileA: shouldn't move to wildcard file\n");
743 ok(GetLastError() == ERROR_INVALID_NAME,
744 "MoveFileA: with wildcards, unexpected error %ld\n", GetLastError());
745 if (ret || (GetLastError() != ERROR_INVALID_NAME))
747 WIN32_FIND_DATAA fd;
748 char temppath[MAX_PATH];
749 HANDLE hFind;
751 lstrcpyA(temppath, tempdir);
752 lstrcatA(temppath, "\\*.*");
753 hFind = FindFirstFileA(temppath, &fd);
754 if (INVALID_HANDLE_VALUE != hFind)
756 LPSTR lpName;
759 lpName = fd.cAlternateFileName;
760 if (!lpName[0])
761 lpName = fd.cFileName;
762 ok(IsDotDir(lpName), "MoveFileA: wildcards file created!\n");
764 while (FindNextFileA(hFind, &fd));
765 FindClose(hFind);
768 ret = DeleteFileA(source);
769 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
770 ret = DeleteFileA(dest);
771 ok(!ret, "DeleteFileA: error %ld\n", GetLastError());
772 ret = RemoveDirectoryA(tempdir);
773 ok(ret, "DeleteDirectoryA: error %ld\n", GetLastError());
776 static void test_MoveFileW(void)
778 WCHAR temp_path[MAX_PATH];
779 WCHAR source[MAX_PATH], dest[MAX_PATH];
780 static const WCHAR prefix[] = {'p','f','x',0};
781 DWORD ret;
783 ret = GetTempPathW(MAX_PATH, temp_path);
784 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
785 return;
786 ok(ret != 0, "GetTempPathW error %ld\n", GetLastError());
787 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
789 ret = GetTempFileNameW(temp_path, prefix, 0, source);
790 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
792 ret = GetTempFileNameW(temp_path, prefix, 0, dest);
793 ok(ret != 0, "GetTempFileNameW error %ld\n", GetLastError());
795 ret = MoveFileW(source, dest);
796 ok(!ret && GetLastError() == ERROR_ALREADY_EXISTS,
797 "CopyFileW: unexpected error %ld\n", GetLastError());
799 ret = DeleteFileW(source);
800 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
801 ret = DeleteFileW(dest);
802 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
805 #define PATTERN_OFFSET 0x10
807 static void test_offset_in_overlapped_structure(void)
809 HANDLE hFile;
810 OVERLAPPED ov;
811 DWORD done;
812 BOOL rc;
813 BYTE buf[256], pattern[] = "TeSt";
814 UINT i;
815 char temp_path[MAX_PATH], temp_fname[MAX_PATH];
817 ok(GetTempPathA(MAX_PATH, temp_path) != 0, "GetTempPathA error %ld\n", GetLastError());
818 ok(GetTempFileNameA(temp_path, "pfx", 0, temp_fname) != 0, "GetTempFileNameA error %ld\n", GetLastError());
820 /*** Write File *****************************************************/
822 hFile = CreateFileA(temp_fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
823 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
825 for(i = 0; i < sizeof(buf); i++) buf[i] = i;
826 ok(WriteFile(hFile, buf, sizeof(buf), &done, NULL), "WriteFile error %ld\n", GetLastError());
827 ok(done == sizeof(buf), "expected number of bytes written %lu\n", done);
829 memset(&ov, 0, sizeof(ov));
830 ov.Offset = PATTERN_OFFSET;
831 ov.OffsetHigh = 0;
832 rc=WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
833 /* Win 9x does not support the overlapped I/O on files */
834 if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
835 ok(rc, "WriteFile error %ld\n", GetLastError());
836 ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
837 /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
838 ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
839 "expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern));
841 ov.Offset = sizeof(buf) * 2;
842 ov.OffsetHigh = 0;
843 ok(WriteFile(hFile, pattern, sizeof(pattern), &done, &ov), "WriteFile error %ld\n", GetLastError());
844 ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
845 /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
846 ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (sizeof(buf) * 2 + sizeof(pattern)),
847 "expected file offset %d\n", sizeof(buf) * 2 + sizeof(pattern));
850 CloseHandle(hFile);
852 /*** Read File *****************************************************/
854 hFile = CreateFileA(temp_fname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
855 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld\n", GetLastError());
857 memset(buf, 0, sizeof(buf));
858 memset(&ov, 0, sizeof(ov));
859 ov.Offset = PATTERN_OFFSET;
860 ov.OffsetHigh = 0;
861 rc=ReadFile(hFile, buf, sizeof(pattern), &done, &ov);
862 /* Win 9x does not support the overlapped I/O on files */
863 if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
864 ok(rc, "ReadFile error %ld\n", GetLastError());
865 ok(done == sizeof(pattern), "expected number of bytes read %lu\n", done);
866 /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
867 ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
868 "expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern));
869 ok(!memcmp(buf, pattern, sizeof(pattern)), "pattern match failed\n");
872 CloseHandle(hFile);
874 ok(DeleteFileA(temp_fname), "DeleteFileA error %ld\n", GetLastError());
877 static void test_LockFile(void)
879 HANDLE handle;
880 DWORD written;
881 OVERLAPPED overlapped;
883 handle = CreateFileA( filename, GENERIC_READ | GENERIC_WRITE,
884 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
885 CREATE_ALWAYS, 0, 0 );
886 if (handle == INVALID_HANDLE_VALUE)
888 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
889 return;
891 ok( WriteFile( handle, sillytext, strlen(sillytext), &written, NULL ), "write failed\n" );
893 ok( LockFile( handle, 0, 0, 0, 0 ), "LockFile failed\n" );
894 ok( UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile failed\n" );
895 ok( !UnlockFile( handle, 0, 0, 0, 0 ), "UnlockFile succeeded\n" );
897 ok( LockFile( handle, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
898 /* overlapping locks must fail */
899 ok( !LockFile( handle, 12, 0, 10, 0 ), "LockFile 12,10 succeeded\n" );
900 ok( !LockFile( handle, 5, 0, 6, 0 ), "LockFile 5,6 succeeded\n" );
901 /* non-overlapping locks must succeed */
902 ok( LockFile( handle, 5, 0, 5, 0 ), "LockFile 5,5 failed\n" );
904 ok( !UnlockFile( handle, 10, 0, 10, 0 ), "UnlockFile 10,10 succeeded\n" );
905 ok( UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 failed\n" );
906 ok( !UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" );
907 ok( UnlockFile( handle, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" );
909 overlapped.Offset = 100;
910 overlapped.OffsetHigh = 0;
911 overlapped.hEvent = 0;
912 ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 100,100 failed\n" );
913 /* overlapping shared locks are OK */
914 overlapped.Offset = 150;
915 ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" );
916 /* but exclusive is not */
917 ok( !LockFileEx( handle, LOCKFILE_EXCLUSIVE_LOCK|LOCKFILE_FAIL_IMMEDIATELY, 0, 50, 0, &overlapped ),
918 "LockFileEx exclusive 150,50 succeeded\n" );
919 ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 150,100 failed\n" );
920 ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 150,100 again succeeded\n" );
921 overlapped.Offset = 100;
922 ok( UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 failed\n" );
923 ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ), "UnlockFileEx 100,100 again succeeded\n" );
925 ok( LockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "LockFile failed\n" );
926 ok( !LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" );
927 ok( !LockFile( handle, 0, 0x20000000, 20, 0 ), "LockFile 0x20000000,20 succeeded\n" );
928 ok( UnlockFile( handle, 0, 0x10000000, 0, 0xf0000000 ), "UnlockFile failed\n" );
930 /* wrap-around lock should not do anything */
931 /* (but still succeeds on NT4 so we don't check result) */
932 LockFile( handle, 0, 0x10000000, 0, 0xf0000001 );
933 ok( LockFile( handle, ~0, ~0, 1, 0 ), "LockFile ~0,1 failed\n" );
934 ok( UnlockFile( handle, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" );
936 /* zero-byte lock */
937 ok( LockFile( handle, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" );
938 ok( !LockFile( handle, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
939 ok( LockFile( handle, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
940 ok( LockFile( handle, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
941 ok( UnlockFile( handle, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
942 ok( UnlockFile( handle, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" );
943 ok( UnlockFile( handle, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" );
945 CloseHandle( handle );
946 DeleteFileA( filename );
949 static inline int is_sharing_compatible( DWORD access1, DWORD sharing1, DWORD access2, DWORD sharing2 )
951 if (!access1 || !access2) return 1;
952 if ((access1 & GENERIC_READ) && !(sharing2 & FILE_SHARE_READ)) return 0;
953 if ((access1 & GENERIC_WRITE) && !(sharing2 & FILE_SHARE_WRITE)) return 0;
954 if ((access2 & GENERIC_READ) && !(sharing1 & FILE_SHARE_READ)) return 0;
955 if ((access2 & GENERIC_WRITE) && !(sharing1 & FILE_SHARE_WRITE)) return 0;
956 return 1;
959 static void test_file_sharing(void)
961 static const DWORD access_modes[4] = { 0, GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE };
962 static const DWORD sharing_modes[4] = { 0, FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE };
963 int a1, s1, a2, s2;
965 /* make sure the file exists */
966 HANDLE h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
967 CloseHandle( h );
969 for (a1 = 0; a1 < 4; a1++)
971 for (s1 = 0; s1 < 4; s1++)
973 HANDLE h = CreateFileA( filename, access_modes[a1], sharing_modes[s1],
974 NULL, OPEN_EXISTING, 0, 0 );
975 if (h == INVALID_HANDLE_VALUE)
977 ok(0,"couldn't create file \"%s\" (err=%ld)\n",filename,GetLastError());
978 return;
980 for (a2 = 0; a2 < 4; a2++)
982 for (s2 = 0; s2 < 4; s2++)
984 HANDLE h2 = CreateFileA( filename, access_modes[a2], sharing_modes[s2],
985 NULL, OPEN_EXISTING, 0, 0 );
986 if (is_sharing_compatible( access_modes[a1], sharing_modes[s1],
987 access_modes[a2], sharing_modes[s2] ))
989 ok( h2 != INVALID_HANDLE_VALUE,
990 "open failed for modes %lx/%lx/%lx/%lx err %ld\n",
991 access_modes[a1], sharing_modes[s1],
992 access_modes[a2], sharing_modes[s2], GetLastError() );
994 else
996 ok( h2 == INVALID_HANDLE_VALUE,
997 "open succeeded for modes %lx/%lx/%lx/%lx\n",
998 access_modes[a1], sharing_modes[s1],
999 access_modes[a2], sharing_modes[s2] );
1000 if (h2 == INVALID_HANDLE_VALUE)
1001 ok( GetLastError() == ERROR_SHARING_VIOLATION,
1002 "wrong error code %ld\n", GetLastError() );
1004 if (h2 != INVALID_HANDLE_VALUE) CloseHandle( h2 );
1007 CloseHandle( h );
1010 DeleteFileA( filename );
1013 static void test_FindFirstFileA()
1015 HANDLE handle;
1016 WIN32_FIND_DATAA search_results;
1017 int err;
1019 handle = FindFirstFileA("C:\\",&search_results);
1020 err = GetLastError();
1021 ok ( handle == INVALID_HANDLE_VALUE , "FindFirstFile on Root directory should Fail\n");
1022 if (handle == INVALID_HANDLE_VALUE)
1023 ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err);
1024 handle = FindFirstFileA("C:\\*",&search_results);
1025 ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed\n" );
1026 ok ( FindClose(handle) == TRUE, "Failed to close handle\n");
1029 static void test_FindNextFileA()
1031 HANDLE handle;
1032 WIN32_FIND_DATAA search_results;
1033 int err;
1035 handle = FindFirstFileA("C:\\*",&search_results);
1036 ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on C:\\* should succeed\n" );
1037 while (FindNextFile(handle, &search_results))
1039 /* get to the end of the files */
1041 ok ( FindClose(handle) == TRUE, "Failed to close handle\n");
1042 err = GetLastError();
1043 ok ( err == ERROR_NO_MORE_FILES, "GetLastError should return ERROR_NO_MORE_FILES\n");
1046 static void test_MapFile()
1048 HANDLE handle, hmap;
1050 /* be sure to remove stale files */
1051 SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL);
1052 DeleteFile(filename);
1053 handle = CreateFile( filename, GENERIC_READ|GENERIC_WRITE, 0, 0,
1054 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
1055 ok( handle != INVALID_HANDLE_VALUE, "couldn't create test file\n");
1057 hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0, NULL );
1058 ok( hmap == NULL, "mapped zero size file\n");
1059 ok( GetLastError() == ERROR_FILE_INVALID, "not ERROR_FILE_INVALID\n");
1061 hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0, NULL );
1062 ok( hmap == NULL, "mapping should fail\n");
1063 /* GetLastError() varies between win9x and WinNT */
1065 hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0x1000, 0x10000, NULL );
1066 ok( hmap == NULL, "mapping should fail\n");
1067 /* GetLastError() varies between win9x and WinNT */
1069 hmap = CreateFileMapping( handle, NULL, PAGE_READWRITE, 0, 0x1000, NULL );
1070 ok( hmap != NULL, "mapping should succeed\n");
1072 ok( CloseHandle( hmap ), "can't close mapping handle\n");
1073 ok( CloseHandle( handle ), "can't close file handle\n");
1074 ok( DeleteFileA( filename ), "DeleteFile failed after map\n" );
1077 static void test_GetFileType(void)
1079 DWORD type;
1080 HANDLE h = CreateFileA( filename, GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, 0 );
1081 ok( h != INVALID_HANDLE_VALUE, "open %s failed\n", filename );
1082 type = GetFileType(h);
1083 ok( type == FILE_TYPE_DISK, "expected type disk got %ld\n", type );
1084 CloseHandle( h );
1085 h = CreateFileA( "nul", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0 );
1086 ok( h != INVALID_HANDLE_VALUE, "open nul failed\n" );
1087 type = GetFileType(h);
1088 ok( type == FILE_TYPE_CHAR, "expected type char for nul got %ld\n", type );
1089 CloseHandle( h );
1090 DeleteFileA( filename );
1093 START_TEST(file)
1095 test__hread( );
1096 test__hwrite( );
1097 test__lclose( );
1098 test__lcreat( );
1099 test__llseek( );
1100 test__llopen( );
1101 test__lread( );
1102 test__lwrite( );
1103 test_GetTempFileNameA();
1104 test_CopyFileA();
1105 test_CopyFileW();
1106 test_CreateFileA();
1107 test_CreateFileW();
1108 test_DeleteFileA();
1109 test_DeleteFileW();
1110 test_MoveFileA();
1111 test_MoveFileW();
1112 test_FindFirstFileA();
1113 test_FindNextFileA();
1114 test_LockFile();
1115 test_file_sharing();
1116 test_offset_in_overlapped_structure();
1117 test_MapFile();
1118 test_GetFileType();