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
25 #include "wine/test.h"
30 LPCSTR filename = "testfile.xxx";
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 )
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());
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( lstrlenA( sillytext ) == bytes_read, "file read size error" );
73 for (bytes_wanted = 0; bytes_wanted < lstrlenA( 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 )
101 filehandle = _lcreat( filename, 0 );
102 if (filehandle == HFILE_ERROR)
104 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
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 );
124 srand( (unsigned)time( NULL ) );
125 for (blocks = 0; blocks < 100; blocks++)
127 for (i = 0; i < sizeof( buffer ); i++)
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" );
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" );
159 checksum[0] = checksum[0] + contents[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 )
176 filehandle = _lcreat( filename, 0 );
177 if (filehandle == HFILE_ERROR)
179 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
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 )
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());
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 ) ) == lstrlenA( 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 ) ) == lstrlenA( 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 ) ) == lstrlenA( 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 )
270 filehandle = _lcreat( filename, 0 );
271 if (filehandle == HFILE_ERROR)
273 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
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 )
305 filehandle = _lcreat( filename, 0 );
306 if (filehandle == HFILE_ERROR)
308 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
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 )
345 filehandle = _lcreat( filename, 0 );
346 if (filehandle == HFILE_ERROR)
348 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
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( lstrlenA( 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 )
389 HLOCAL memory_object;
392 filehandle = _lcreat( filename, 0 );
393 if (filehandle == HFILE_ERROR)
395 ok(0,"couldn't create file \"%s\" (err=%ld)",filename,GetLastError());
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 );
415 srand( (unsigned)time( NULL ) );
416 for (blocks = 0; blocks < 100; blocks++)
418 for (i = 0; i < sizeof( buffer ); i++)
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" );
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" );
450 checksum[0] += contents[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";
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};
499 ret = GetTempPathW(MAX_PATH, temp_path);
500 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
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)
527 char temp_path[MAX_PATH];
528 char filename[MAX_PATH];
529 static const char prefix[] = "pfx";
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)
551 WCHAR temp_path[MAX_PATH];
552 WCHAR filename[MAX_PATH];
553 static const WCHAR prefix[] = {'p','f','x',0};
556 ret = GetTempPathW(MAX_PATH, temp_path);
557 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
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 )
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 )
592 WCHAR emptyW[]={'\0'};
594 ret = DeleteFileW(NULL);
595 if (ret==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED)
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)
612 BYTE buf[256], pattern[] = "TeSt";
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;
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;
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));
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;
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");
665 ok(DeleteFileA(temp_fname), "DeleteFileA error %ld\n", GetLastError());
684 test_offset_in_overlapped_structure();