Fix the error codes returned by DeleteFile{A,W} to match NT.
[wine/wine64.git] / dlls / kernel / tests / file.c
bloba8b1fcc919aa6675ebed251d636c32b5134f14b3
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 <stdlib.h>
23 #include <time.h>
25 #include "wine/test.h"
26 #include "winbase.h"
27 #include "winerror.h"
30 LPCSTR filename = "testfile.xxx";
31 LPCSTR sillytext =
32 "en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla."
33 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
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 "sdlkfjasdlkfj a dslkj adsklf \n \nasdklf askldfa sdlkf \nsadklf asdklf asdf ";
44 static void test__hread( void )
46 HFILE filehandle;
47 char buffer[10000];
48 long bytes_read;
49 long bytes_wanted;
50 UINT i;
52 SetFileAttributesA(filename,FILE_ATTRIBUTE_NORMAL); /* be sure to remove stale files */
53 DeleteFileA( filename );
54 filehandle = _lcreat( filename, 0 );
55 if (filehandle == HFILE_ERROR)
57 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
58 return;
61 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
63 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
65 filehandle = _lopen( filename, OF_READ );
67 ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)", filename, GetLastError( ) );
69 bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
71 ok( strlen( sillytext ) == bytes_read, "file read size error" );
73 for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
75 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains" );
76 ok( _hread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value" );
77 for (i = 0; i < bytes_wanted; i++)
79 ok( buffer[i] == sillytext[i], "that's not what's written" );
83 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains" );
85 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
89 static void test__hwrite( void )
91 HFILE filehandle;
92 char buffer[10000];
93 long bytes_read;
94 UINT bytes_written;
95 UINT blocks;
96 UINT i;
97 char *contents;
98 HLOCAL memory_object;
99 char checksum[1];
101 filehandle = _lcreat( filename, 0 );
102 if (filehandle == HFILE_ERROR)
104 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
105 return;
108 ok( HFILE_ERROR != _hwrite( filehandle, "", 0 ), "_hwrite complains" );
110 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
112 filehandle = _lopen( filename, OF_READ );
114 bytes_read = _hread( filehandle, buffer, 1);
116 ok( 0 == bytes_read, "file read size error" );
118 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
120 filehandle = _lopen( filename, OF_READWRITE );
122 bytes_written = 0;
123 checksum[0] = '\0';
124 srand( (unsigned)time( NULL ) );
125 for (blocks = 0; blocks < 100; blocks++)
127 for (i = 0; i < sizeof( buffer ); i++)
129 buffer[i] = rand( );
130 checksum[0] = checksum[0] + buffer[i];
132 ok( HFILE_ERROR != _hwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains" );
133 bytes_written = bytes_written + sizeof( buffer );
136 ok( HFILE_ERROR != _hwrite( filehandle, checksum, 1 ), "_hwrite complains" );
137 bytes_written++;
139 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains" );
141 memory_object = LocalAlloc( LPTR, bytes_written );
143 ok( 0 != memory_object, "LocalAlloc fails. (Could be out of memory.)" );
145 contents = LocalLock( memory_object );
147 filehandle = _lopen( filename, OF_READ );
149 contents = LocalLock( memory_object );
151 ok( NULL != contents, "LocalLock whines" );
153 ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length" );
155 checksum[0] = '\0';
156 i = 0;
159 checksum[0] = checksum[0] + contents[i];
160 i++;
162 while (i < bytes_written - 1);
164 ok( checksum[0] == contents[i], "stored checksum differ from computed checksum" );
166 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains" );
168 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
172 static void test__lclose( void )
174 HFILE filehandle;
176 filehandle = _lcreat( filename, 0 );
177 if (filehandle == HFILE_ERROR)
179 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
180 return;
183 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
185 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
187 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
191 static void test__lcreat( void )
193 HFILE filehandle;
194 char buffer[10000];
195 WIN32_FIND_DATAA search_results;
197 filehandle = _lcreat( filename, 0 );
198 if (filehandle == HFILE_ERROR)
200 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
201 return;
204 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
206 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains" );
208 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == strlen( sillytext ), "erratic _hread return value" );
210 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
212 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file" );
214 ok( DeleteFileA(filename) != 0, "DeleteFile failed (%ld)", GetLastError());
216 filehandle = _lcreat( filename, 1 ); /* readonly */
217 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)", filename, GetLastError( ) );
219 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write never the less" );
221 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
223 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should be able to find file" );
225 ok( 0 == DeleteFileA( filename ), "shouldn't be able to delete a readonly file" );
227 ok( SetFileAttributesA(filename, FILE_ATTRIBUTE_NORMAL ) != 0, "couldn't change attributes on file" );
229 ok( DeleteFileA( filename ) != 0, "now it should be possible to delete the file!" );
231 filehandle = _lcreat( filename, 2 );
232 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)", filename, GetLastError( ) );
234 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
236 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains" );
238 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == strlen( sillytext ), "erratic _hread return value" );
240 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
242 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file" );
244 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
246 filehandle = _lcreat( filename, 4 ); /* SYSTEM file */
247 ok( HFILE_ERROR != filehandle, "couldn't create file \"%s\" (err=%ld)", filename, GetLastError( ) );
249 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
251 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains" );
253 ok( _hread( filehandle, buffer, strlen( sillytext ) ) == strlen( sillytext ), "erratic _hread return value" );
255 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
257 ok( INVALID_HANDLE_VALUE != FindFirstFileA( filename, &search_results ), "should STILL be able to find file" );
259 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
263 void test__llseek( void )
265 INT i;
266 HFILE filehandle;
267 char buffer[1];
268 long bytes_read;
270 filehandle = _lcreat( filename, 0 );
271 if (filehandle == HFILE_ERROR)
273 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
274 return;
277 for (i = 0; i < 400; i++)
279 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
281 ok( HFILE_ERROR != _llseek( filehandle, 400 * strlen( sillytext ), FILE_CURRENT ), "should be able to seek" );
282 ok( HFILE_ERROR != _llseek( filehandle, 27 + 35 * strlen( sillytext ), FILE_BEGIN ), "should be able to seek" );
284 bytes_read = _hread( filehandle, buffer, 1);
285 ok( 1 == bytes_read, "file read size error" );
286 ok( buffer[0] == sillytext[27], "_llseek error, it got lost seeking" );
287 ok( HFILE_ERROR != _llseek( filehandle, -400 * strlen( sillytext ), FILE_END ), "should be able to seek" );
289 bytes_read = _hread( filehandle, buffer, 1);
290 ok( 1 == bytes_read, "file read size error" );
291 ok( buffer[0] == sillytext[0], "_llseek error, it got lost seeking" );
292 ok( HFILE_ERROR != _llseek( filehandle, 1000000, FILE_END ), "should be able to seek past file; poor, poor Windows programmers" );
293 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
295 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
299 static void test__llopen( void )
301 HFILE filehandle;
302 UINT bytes_read;
303 char buffer[10000];
305 filehandle = _lcreat( filename, 0 );
306 if (filehandle == HFILE_ERROR)
308 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
309 return;
312 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
313 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
315 filehandle = _lopen( filename, OF_READ );
316 ok( HFILE_ERROR == _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite shouldn't be able to write!" );
317 bytes_read = _hread( filehandle, buffer, strlen( sillytext ) );
318 ok( strlen( sillytext ) == bytes_read, "file read size error" );
319 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
321 filehandle = _lopen( filename, OF_READWRITE );
322 bytes_read = _hread( filehandle, buffer, 2 * strlen( sillytext ) );
323 ok( strlen( sillytext ) == bytes_read, "file read size error" );
324 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine" );
325 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
327 filehandle = _lopen( filename, OF_WRITE );
328 ok( HFILE_ERROR == _hread( filehandle, buffer, 1 ), "you should only be able to write this file" );
329 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite should write just fine" );
330 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
332 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
333 /* TODO - add tests for the SHARE modes - use two processes to pull this one off */
337 static void test__lread( void )
339 HFILE filehandle;
340 char buffer[10000];
341 long bytes_read;
342 UINT bytes_wanted;
343 UINT i;
345 filehandle = _lcreat( filename, 0 );
346 if (filehandle == HFILE_ERROR)
348 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
349 return;
352 ok( HFILE_ERROR != _hwrite( filehandle, sillytext, strlen( sillytext ) ), "_hwrite complains" );
354 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
356 filehandle = _lopen( filename, OF_READ );
358 ok( HFILE_ERROR != filehandle, "couldn't open file \"%s\" again (err=%ld)", filename, GetLastError());
360 bytes_read = _lread( filehandle, buffer, 2 * strlen( sillytext ) );
362 ok( strlen( sillytext ) == bytes_read, "file read size error" );
364 for (bytes_wanted = 0; bytes_wanted < strlen( sillytext ); bytes_wanted++)
366 ok( 0 == _llseek( filehandle, 0, FILE_BEGIN ), "_llseek complains" );
367 ok( _lread( filehandle, buffer, bytes_wanted ) == bytes_wanted, "erratic _hread return value" );
368 for (i = 0; i < bytes_wanted; i++)
370 ok( buffer[i] == sillytext[i], "that's not what's written" );
374 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
376 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
380 static void test__lwrite( void )
382 HFILE filehandle;
383 char buffer[10000];
384 long bytes_read;
385 UINT bytes_written;
386 UINT blocks;
387 UINT i;
388 char *contents;
389 HLOCAL memory_object;
390 char checksum[1];
392 filehandle = _lcreat( filename, 0 );
393 if (filehandle == HFILE_ERROR)
395 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
396 return;
399 ok( HFILE_ERROR != _lwrite( filehandle, "", 0 ), "_hwrite complains" );
401 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
403 filehandle = _lopen( filename, OF_READ );
405 bytes_read = _hread( filehandle, buffer, 1);
407 ok( 0 == bytes_read, "file read size error" );
409 ok( HFILE_ERROR != _lclose(filehandle), "_lclose complains" );
411 filehandle = _lopen( filename, OF_READWRITE );
413 bytes_written = 0;
414 checksum[0] = '\0';
415 srand( (unsigned)time( NULL ) );
416 for (blocks = 0; blocks < 100; blocks++)
418 for (i = 0; i < sizeof( buffer ); i++)
420 buffer[i] = rand( );
421 checksum[0] = checksum[0] + buffer[i];
423 ok( HFILE_ERROR != _lwrite( filehandle, buffer, sizeof( buffer ) ), "_hwrite complains" );
424 bytes_written = bytes_written + sizeof( buffer );
427 ok( HFILE_ERROR != _lwrite( filehandle, checksum, 1 ), "_hwrite complains" );
428 bytes_written++;
430 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains" );
432 memory_object = LocalAlloc( LPTR, bytes_written );
434 ok( 0 != memory_object, "LocalAlloc fails, could be out of memory" );
436 contents = LocalLock( memory_object );
438 filehandle = _lopen( filename, OF_READ );
440 contents = LocalLock( memory_object );
442 ok( NULL != contents, "LocalLock whines" );
444 ok( bytes_written == _hread( filehandle, contents, bytes_written), "read length differ from write length" );
446 checksum[0] = '\0';
447 i = 0;
450 checksum[0] += contents[i];
451 i++;
453 while (i < bytes_written - 1);
455 ok( checksum[0] == contents[i], "stored checksum differ from computed checksum" );
457 ok( HFILE_ERROR != _lclose( filehandle ), "_lclose complains" );
459 ok( DeleteFileA( filename ) != 0, "DeleteFile failed (%ld)", GetLastError( ) );
462 void test_CopyFileA(void)
464 char temp_path[MAX_PATH];
465 char source[MAX_PATH], dest[MAX_PATH];
466 static const char prefix[] = "pfx";
467 DWORD ret;
469 ret = GetTempPathA(MAX_PATH, temp_path);
470 ok(ret != 0, "GetTempPathA error %ld", GetLastError());
471 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH");
473 ret = GetTempFileNameA(temp_path, prefix, 0, source);
474 ok(ret != 0, "GetTempFileNameA error %ld", GetLastError());
476 ret = GetTempFileNameA(temp_path, prefix, 0, dest);
477 ok(ret != 0, "GetTempFileNameA error %ld", GetLastError());
479 ret = CopyFileA(source, dest, TRUE);
480 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
481 "CopyFileA: unexpected error %ld\n", GetLastError());
483 ret = CopyFileA(source, dest, FALSE);
484 ok(ret, "CopyFileA: error %ld\n", GetLastError());
486 ret = DeleteFileA(source);
487 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
488 ret = DeleteFileA(dest);
489 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
492 void test_CopyFileW(void)
494 WCHAR temp_path[MAX_PATH];
495 WCHAR source[MAX_PATH], dest[MAX_PATH];
496 static const WCHAR prefix[] = {'p','f','x',0};
497 DWORD ret;
499 ret = GetTempPathW(MAX_PATH, temp_path);
500 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
501 return;
502 ok(ret != 0, "GetTempPathW error %ld", GetLastError());
503 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH");
505 ret = GetTempFileNameW(temp_path, prefix, 0, source);
506 ok(ret != 0, "GetTempFileNameW error %ld", GetLastError());
508 ret = GetTempFileNameW(temp_path, prefix, 0, dest);
509 ok(ret != 0, "GetTempFileNameW error %ld", GetLastError());
511 ret = CopyFileW(source, dest, TRUE);
512 ok(!ret && GetLastError() == ERROR_FILE_EXISTS,
513 "CopyFileW: unexpected error %ld\n", GetLastError());
515 ret = CopyFileW(source, dest, FALSE);
516 ok(ret, "CopyFileW: error %ld\n", GetLastError());
518 ret = DeleteFileW(source);
519 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
520 ret = DeleteFileW(dest);
521 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
524 void test_CreateFileA(void)
526 HANDLE hFile;
527 char temp_path[MAX_PATH];
528 char filename[MAX_PATH];
529 static const char prefix[] = "pfx";
530 DWORD ret;
532 ret = GetTempPathA(MAX_PATH, temp_path);
533 ok(ret != 0, "GetTempPathA error %ld", GetLastError());
534 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH");
536 ret = GetTempFileNameA(temp_path, prefix, 0, filename);
537 ok(ret != 0, "GetTempFileNameA error %ld", GetLastError());
539 hFile = CreateFileA(filename, GENERIC_READ, 0, NULL,
540 CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
541 ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS,
542 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS");
544 ret = DeleteFileA(filename);
545 ok(ret, "DeleteFileA: error %ld\n", GetLastError());
548 void test_CreateFileW(void)
550 HANDLE hFile;
551 WCHAR temp_path[MAX_PATH];
552 WCHAR filename[MAX_PATH];
553 static const WCHAR prefix[] = {'p','f','x',0};
554 DWORD ret;
556 ret = GetTempPathW(MAX_PATH, temp_path);
557 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
558 return;
559 ok(ret != 0, "GetTempPathW error %ld", GetLastError());
560 ok(ret < MAX_PATH, "temp path should fit into MAX_PATH");
562 ret = GetTempFileNameW(temp_path, prefix, 0, filename);
563 ok(ret != 0, "GetTempFileNameW error %ld", GetLastError());
565 hFile = CreateFileW(filename, GENERIC_READ, 0, NULL,
566 CREATE_NEW, FILE_FLAG_RANDOM_ACCESS, 0);
567 ok(hFile == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_EXISTS,
568 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS");
570 ret = DeleteFileW(filename);
571 ok(ret, "DeleteFileW: error %ld\n", GetLastError());
574 static void test_DeleteFileA( void )
576 BOOL ret;
578 ret = DeleteFileA(NULL);
579 ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER ||
580 GetLastError() == ERROR_PATH_NOT_FOUND),
581 "DeleteFileA(NULL) returned ret=%d error=%ld",ret,GetLastError());
583 ret = DeleteFileA("");
584 ok(!ret && (GetLastError() == ERROR_PATH_NOT_FOUND ||
585 GetLastError() == ERROR_BAD_PATHNAME),
586 "DeleteFileA(\"\") returned ret=%d error=%ld",ret,GetLastError());
589 static void test_DeleteFileW( void )
591 BOOL ret;
592 WCHAR emptyW[]={'\0'};
594 ret = DeleteFileW(NULL);
595 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
596 return;
597 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
598 "DeleteFileW(NULL) returned ret=%d error=%ld",ret,GetLastError());
600 ret = DeleteFileW(emptyW);
601 ok(!ret && GetLastError() == ERROR_PATH_NOT_FOUND,
602 "DeleteFileW(\"\") returned ret=%d error=%ld",ret,GetLastError());
605 #define PATTERN_OFFSET 0x10
607 void test_offset_in_overlapped_structure(void)
609 HANDLE hFile;
610 OVERLAPPED ov;
611 DWORD done;
612 BYTE buf[256], pattern[] = "TeSt";
613 UINT i;
614 char temp_path[MAX_PATH], temp_fname[MAX_PATH];
616 ok(GetTempPathA(MAX_PATH, temp_path) != 0, "GetTempPathA error %ld", GetLastError());
617 ok(GetTempFileNameA(temp_path, "pfx", 0, temp_fname) != 0, "GetTempFileNameA error %ld", GetLastError());
619 /*** Write File *****************************************************/
621 hFile = CreateFileA(temp_fname, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
622 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld", GetLastError());
624 for(i = 0; i < sizeof(buf); i++) buf[i] = i;
625 ok(WriteFile(hFile, buf, sizeof(buf), &done, NULL), "WriteFile error %ld", GetLastError());
626 ok(done == sizeof(buf), "expected number of bytes written %lu", done);
628 memset(&ov, 0, sizeof(ov));
629 ov.Offset = PATTERN_OFFSET;
630 ov.OffsetHigh = 0;
631 ok(WriteFile(hFile, pattern, sizeof(pattern), &done, &ov), "WriteFile error %ld", GetLastError());
632 ok(done == sizeof(pattern), "expected number of bytes written %lu", done);
633 trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));
634 ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
635 "expected file offset %d", PATTERN_OFFSET + sizeof(pattern));
637 ov.Offset = sizeof(buf) * 2;
638 ov.OffsetHigh = 0;
639 ok(WriteFile(hFile, pattern, sizeof(pattern), &done, &ov), "WriteFile error %ld", GetLastError());
640 ok(done == sizeof(pattern), "expected number of bytes written %lu", done);
641 /*trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));*/
642 ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (sizeof(buf) * 2 + sizeof(pattern)),
643 "expected file offset %d", sizeof(buf) * 2 + sizeof(pattern));
645 CloseHandle(hFile);
647 /*** Read File *****************************************************/
649 hFile = CreateFileA(temp_fname, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0);
650 ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA error %ld", GetLastError());
652 memset(buf, 0, sizeof(buf));
653 memset(&ov, 0, sizeof(ov));
654 ov.Offset = PATTERN_OFFSET;
655 ov.OffsetHigh = 0;
656 ok(ReadFile(hFile, buf, sizeof(pattern), &done, &ov), "ReadFile error %ld", GetLastError());
657 ok(done == sizeof(pattern), "expected number of bytes read %lu", done);
658 trace("Current offset = %04lx\n", SetFilePointer(hFile, 0, NULL, FILE_CURRENT));
659 ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
660 "expected file offset %d", PATTERN_OFFSET + sizeof(pattern));
661 ok(!memcmp(buf, pattern, sizeof(pattern)), "pattern match failed");
663 CloseHandle(hFile);
665 ok(DeleteFileA(temp_fname), "DeleteFileA error %ld\n", GetLastError());
668 START_TEST(file)
670 test__hread( );
671 test__hwrite( );
672 test__lclose( );
673 test__lcreat( );
674 test__llseek( );
675 test__llopen( );
676 test__lread( );
677 test__lwrite( );
678 test_CopyFileA();
679 test_CopyFileW();
680 test_CreateFileA();
681 test_CreateFileW();
682 test_DeleteFileA();
683 test_DeleteFileW();
684 test_offset_in_overlapped_structure();