2 * Unit tests for file functions in Wine
4 * Copyright (c) 2002, 2004 Jakob Eriksson
5 * Copyright (c) 2008 Jeff Zaroyko
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 /* ReplaceFile requires Windows 2000 or newer */
24 #define _WIN32_WINNT 0x0500
30 #include "wine/test.h"
35 static HANDLE (WINAPI
*pFindFirstFileExA
)(LPCSTR
,FINDEX_INFO_LEVELS
,LPVOID
,FINDEX_SEARCH_OPS
,LPVOID
,DWORD
);
36 static BOOL (WINAPI
*pReplaceFileA
)(LPCSTR
, LPCSTR
, LPCSTR
, DWORD
, LPVOID
, LPVOID
);
37 static BOOL (WINAPI
*pReplaceFileW
)(LPCWSTR
, LPCWSTR
, LPCWSTR
, DWORD
, LPVOID
, LPVOID
);
38 static UINT (WINAPI
*pGetSystemWindowsDirectoryA
)(LPSTR
, UINT
);
40 /* keep filename and filenameW the same */
41 static const char filename
[] = "testfile.xxx";
42 static const WCHAR filenameW
[] = { 't','e','s','t','f','i','l','e','.','x','x','x',0 };
43 static const char sillytext
[] =
44 "en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla."
45 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
46 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
47 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
48 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
49 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
50 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
51 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
52 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
53 "sdlkfjasdlkfj a dslkj adsklf \n \nasdklf askldfa sdlkf \nsadklf asdklf asdf ";
55 static void InitFunctionPointers(void)
57 HMODULE hkernel32
= GetModuleHandleA("kernel32");
59 pFindFirstFileExA
=(void*)GetProcAddress(hkernel32
, "FindFirstFileExA");
60 pReplaceFileA
=(void*)GetProcAddress(hkernel32
, "ReplaceFileA");
61 pReplaceFileW
=(void*)GetProcAddress(hkernel32
, "ReplaceFileW");
62 pGetSystemWindowsDirectoryA
=(void*)GetProcAddress(hkernel32
, "GetSystemWindowsDirectoryA");
65 static void test__hread( void )
74 SetFileAttributesA(filename
,FILE_ATTRIBUTE_NORMAL
); /* be sure to remove stale files */
75 DeleteFileA( filename
);
76 filehandle
= _lcreat( filename
, 0 );
77 if (filehandle
== HFILE_ERROR
)
79 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
83 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
85 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
87 filehandle
= _lopen( filename
, OF_READ
);
89 ok( HFILE_ERROR
!= filehandle
, "couldn't open file \"%s\" again (err=%d)\n", filename
, GetLastError( ) );
91 bytes_read
= _hread( filehandle
, buffer
, 2 * strlen( sillytext
) );
93 ok( lstrlenA( sillytext
) == bytes_read
, "file read size error\n" );
95 for (bytes_wanted
= 0; bytes_wanted
< lstrlenA( sillytext
); bytes_wanted
++)
97 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
98 ok( _hread( filehandle
, buffer
, bytes_wanted
) == bytes_wanted
, "erratic _hread return value\n" );
99 for (i
= 0; i
< bytes_wanted
; i
++)
101 ok( buffer
[i
] == sillytext
[i
], "that's not what's written\n" );
105 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
107 ret
= DeleteFileA( filename
);
108 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError( ) );
112 static void test__hwrite( void )
121 HLOCAL memory_object
;
125 filehandle
= _lcreat( filename
, 0 );
126 if (filehandle
== HFILE_ERROR
)
128 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
132 ok( HFILE_ERROR
!= _hwrite( filehandle
, "", 0 ), "_hwrite complains\n" );
134 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
136 filehandle
= _lopen( filename
, OF_READ
);
138 bytes_read
= _hread( filehandle
, buffer
, 1);
140 ok( 0 == bytes_read
, "file read size error\n" );
142 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
144 filehandle
= _lopen( filename
, OF_READWRITE
);
148 srand( (unsigned)time( NULL
) );
149 for (blocks
= 0; blocks
< 100; blocks
++)
151 for (i
= 0; i
< (long)sizeof( buffer
); i
++)
154 checksum
[0] = checksum
[0] + buffer
[i
];
156 ok( HFILE_ERROR
!= _hwrite( filehandle
, buffer
, sizeof( buffer
) ), "_hwrite complains\n" );
157 bytes_written
= bytes_written
+ sizeof( buffer
);
160 ok( HFILE_ERROR
!= _hwrite( filehandle
, checksum
, 1 ), "_hwrite complains\n" );
163 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
165 memory_object
= LocalAlloc( LPTR
, bytes_written
);
167 ok( 0 != memory_object
, "LocalAlloc fails. (Could be out of memory.)\n" );
169 contents
= LocalLock( memory_object
);
171 filehandle
= _lopen( filename
, OF_READ
);
173 contents
= LocalLock( memory_object
);
175 ok( NULL
!= contents
, "LocalLock whines\n" );
177 ok( bytes_written
== _hread( filehandle
, contents
, bytes_written
), "read length differ from write length\n" );
183 checksum
[0] = checksum
[0] + contents
[i
];
186 while (i
< bytes_written
- 1);
188 ok( checksum
[0] == contents
[i
], "stored checksum differ from computed checksum\n" );
190 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
192 ret
= DeleteFileA( filename
);
193 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError( ) );
197 static void test__lclose( void )
202 filehandle
= _lcreat( filename
, 0 );
203 if (filehandle
== HFILE_ERROR
)
205 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
209 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
211 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
213 ret
= DeleteFileA( filename
);
214 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError( ) );
218 static void test__lcreat( void )
222 WIN32_FIND_DATAA search_results
;
223 char slashname
[] = "testfi/";
228 filehandle
= _lcreat( filename
, 0 );
229 if (filehandle
== HFILE_ERROR
)
231 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
235 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
237 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
239 ok( _hread( filehandle
, buffer
, strlen( sillytext
) ) == lstrlenA( sillytext
), "erratic _hread return value\n" );
241 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
243 ok( INVALID_HANDLE_VALUE
!= FindFirstFileA( filename
, &search_results
), "should be able to find file\n" );
245 ret
= DeleteFileA(filename
);
246 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError());
248 filehandle
= _lcreat( filename
, 1 ); /* readonly */
249 ok( HFILE_ERROR
!= filehandle
, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError( ) );
251 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite shouldn't be able to write never the less\n" );
253 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
255 ok( INVALID_HANDLE_VALUE
!= FindFirstFileA( filename
, &search_results
), "should be able to find file\n" );
257 ok( 0 == DeleteFileA( filename
), "shouldn't be able to delete a readonly file\n" );
259 ok( SetFileAttributesA(filename
, FILE_ATTRIBUTE_NORMAL
) != 0, "couldn't change attributes on file\n" );
261 ok( DeleteFileA( filename
) != 0, "now it should be possible to delete the file!\n" );
263 filehandle
= _lcreat( filename
, 2 );
264 ok( HFILE_ERROR
!= filehandle
, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError( ) );
266 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
268 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
270 ok( _hread( filehandle
, buffer
, strlen( sillytext
) ) == lstrlenA( sillytext
), "erratic _hread return value\n" );
272 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
274 ok( INVALID_HANDLE_VALUE
!= FindFirstFileA( filename
, &search_results
), "should STILL be able to find file\n" );
276 ret
= DeleteFileA( filename
);
277 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
279 filehandle
= _lcreat( filename
, 4 ); /* SYSTEM file */
280 ok( HFILE_ERROR
!= filehandle
, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError( ) );
282 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
284 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
286 ok( _hread( filehandle
, buffer
, strlen( sillytext
) ) == lstrlenA( sillytext
), "erratic _hread return value\n" );
288 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
290 ok( INVALID_HANDLE_VALUE
!= FindFirstFileA( filename
, &search_results
), "should STILL be able to find file\n" );
292 ret
= DeleteFileA( filename
);
293 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
295 filehandle
=_lcreat (slashname
, 0); /* illegal name */
296 if (HFILE_ERROR
==filehandle
) {
298 ok (err
==ERROR_INVALID_NAME
|| err
==ERROR_PATH_NOT_FOUND
,
299 "creating file \"%s\" failed with error %d\n", slashname
, err
);
300 } else { /* only NT succeeds */
302 find
=FindFirstFileA (slashname
, &search_results
);
303 if (INVALID_HANDLE_VALUE
!=find
)
305 ret
= FindClose (find
);
306 ok (0 != ret
, "FindClose complains (%d)\n", GetLastError ());
307 slashname
[strlen(slashname
)-1]=0;
308 ok (!strcmp (slashname
, search_results
.cFileName
),
309 "found unexpected name \"%s\"\n", search_results
.cFileName
);
310 ok (FILE_ATTRIBUTE_ARCHIVE
==search_results
.dwFileAttributes
,
311 "attributes of file \"%s\" are 0x%04x\n", search_results
.cFileName
,
312 search_results
.dwFileAttributes
);
314 ret
= DeleteFileA( slashname
);
315 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
318 filehandle
=_lcreat (filename
, 8); /* illegal attribute */
319 if (HFILE_ERROR
==filehandle
)
320 ok (0, "couldn't create volume label \"%s\"\n", filename
);
323 find
=FindFirstFileA (filename
, &search_results
);
324 if (INVALID_HANDLE_VALUE
==find
)
325 ok (0, "file \"%s\" not found\n", filename
);
327 ret
= FindClose(find
);
328 ok ( 0 != ret
, "FindClose complains (%d)\n", GetLastError ());
329 ok (!strcmp (filename
, search_results
.cFileName
),
330 "found unexpected name \"%s\"\n", search_results
.cFileName
);
331 search_results
.dwFileAttributes
&= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
;
332 ok (FILE_ATTRIBUTE_ARCHIVE
==search_results
.dwFileAttributes
,
333 "attributes of file \"%s\" are 0x%04x\n", search_results
.cFileName
,
334 search_results
.dwFileAttributes
);
336 ret
= DeleteFileA( filename
);
337 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
342 static void test__llseek( void )
350 filehandle
= _lcreat( filename
, 0 );
351 if (filehandle
== HFILE_ERROR
)
353 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
357 for (i
= 0; i
< 400; i
++)
359 ok( _hwrite( filehandle
, sillytext
, strlen( sillytext
) ) != -1, "_hwrite complains\n" );
361 ok( _llseek( filehandle
, 400 * strlen( sillytext
), FILE_CURRENT
) != -1, "should be able to seek\n" );
362 ok( _llseek( filehandle
, 27 + 35 * strlen( sillytext
), FILE_BEGIN
) != -1, "should be able to seek\n" );
364 bytes_read
= _hread( filehandle
, buffer
, 1);
365 ok( 1 == bytes_read
, "file read size error\n" );
366 ok( buffer
[0] == sillytext
[27], "_llseek error, it got lost seeking\n" );
367 ok( _llseek( filehandle
, -400 * (LONG
)strlen( sillytext
), FILE_END
) != -1, "should be able to seek\n" );
369 bytes_read
= _hread( filehandle
, buffer
, 1);
370 ok( 1 == bytes_read
, "file read size error\n" );
371 ok( buffer
[0] == sillytext
[0], "_llseek error, it got lost seeking\n" );
372 ok( _llseek( filehandle
, 1000000, FILE_END
) != -1, "should be able to seek past file; poor, poor Windows programmers\n" );
373 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
375 ret
= DeleteFileA( filename
);
376 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
380 static void test__llopen( void )
387 filehandle
= _lcreat( filename
, 0 );
388 if (filehandle
== HFILE_ERROR
)
390 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
394 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
395 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
397 filehandle
= _lopen( filename
, OF_READ
);
398 ok( HFILE_ERROR
== _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite shouldn't be able to write!\n" );
399 bytes_read
= _hread( filehandle
, buffer
, strlen( sillytext
) );
400 ok( strlen( sillytext
) == bytes_read
, "file read size error\n" );
401 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
403 filehandle
= _lopen( filename
, OF_READWRITE
);
404 bytes_read
= _hread( filehandle
, buffer
, 2 * strlen( sillytext
) );
405 ok( strlen( sillytext
) == bytes_read
, "file read size error\n" );
406 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite should write just fine\n" );
407 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
409 filehandle
= _lopen( filename
, OF_WRITE
);
410 ok( HFILE_ERROR
== _hread( filehandle
, buffer
, 1 ), "you should only be able to write this file\n" );
411 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite should write just fine\n" );
412 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
414 ret
= DeleteFileA( filename
);
415 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
416 /* TODO - add tests for the SHARE modes - use two processes to pull this one off */
420 static void test__lread( void )
429 filehandle
= _lcreat( filename
, 0 );
430 if (filehandle
== HFILE_ERROR
)
432 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
436 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
438 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
440 filehandle
= _lopen( filename
, OF_READ
);
442 ok( HFILE_ERROR
!= filehandle
, "couldn't open file \"%s\" again (err=%d)\n", filename
, GetLastError());
444 bytes_read
= _lread( filehandle
, buffer
, 2 * strlen( sillytext
) );
446 ok( lstrlenA( sillytext
) == bytes_read
, "file read size error\n" );
448 for (bytes_wanted
= 0; bytes_wanted
< strlen( sillytext
); bytes_wanted
++)
450 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
451 ok( _lread( filehandle
, buffer
, bytes_wanted
) == bytes_wanted
, "erratic _hread return value\n" );
452 for (i
= 0; i
< bytes_wanted
; i
++)
454 ok( buffer
[i
] == sillytext
[i
], "that's not what's written\n" );
458 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
460 ret
= DeleteFileA( filename
);
461 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
465 static void test__lwrite( void )
474 HLOCAL memory_object
;
478 filehandle
= _lcreat( filename
, 0 );
479 if (filehandle
== HFILE_ERROR
)
481 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
485 ok( HFILE_ERROR
!= _lwrite( filehandle
, "", 0 ), "_hwrite complains\n" );
487 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
489 filehandle
= _lopen( filename
, OF_READ
);
491 bytes_read
= _hread( filehandle
, buffer
, 1);
493 ok( 0 == bytes_read
, "file read size error\n" );
495 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
497 filehandle
= _lopen( filename
, OF_READWRITE
);
501 srand( (unsigned)time( NULL
) );
502 for (blocks
= 0; blocks
< 100; blocks
++)
504 for (i
= 0; i
< (long)sizeof( buffer
); i
++)
507 checksum
[0] = checksum
[0] + buffer
[i
];
509 ok( HFILE_ERROR
!= _lwrite( filehandle
, buffer
, sizeof( buffer
) ), "_hwrite complains\n" );
510 bytes_written
= bytes_written
+ sizeof( buffer
);
513 ok( HFILE_ERROR
!= _lwrite( filehandle
, checksum
, 1 ), "_hwrite complains\n" );
516 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
518 memory_object
= LocalAlloc( LPTR
, bytes_written
);
520 ok( 0 != memory_object
, "LocalAlloc fails, could be out of memory\n" );
522 contents
= LocalLock( memory_object
);
524 filehandle
= _lopen( filename
, OF_READ
);
526 contents
= LocalLock( memory_object
);
528 ok( NULL
!= contents
, "LocalLock whines\n" );
530 ok( bytes_written
== _hread( filehandle
, contents
, bytes_written
), "read length differ from write length\n" );
536 checksum
[0] += contents
[i
];
539 while (i
< bytes_written
- 1);
541 ok( checksum
[0] == contents
[i
], "stored checksum differ from computed checksum\n" );
543 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
545 ret
= DeleteFileA( filename
);
546 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
549 static void test_CopyFileA(void)
551 char temp_path
[MAX_PATH
];
552 char source
[MAX_PATH
], dest
[MAX_PATH
];
553 static const char prefix
[] = "pfx";
560 ret
= GetTempPathA(MAX_PATH
, temp_path
);
561 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
562 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
564 ret
= GetTempFileNameA(temp_path
, prefix
, 0, source
);
565 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
567 /* make the source have not zero size */
568 hfile
= CreateFileA(source
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
569 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open source file\n");
570 retok
= WriteFile(hfile
, prefix
, sizeof(prefix
), &ret
, NULL
);
571 ok( retok
&& ret
== sizeof(prefix
),
572 "WriteFile error %d\n", GetLastError());
573 ok(GetFileSize(hfile
, NULL
) == sizeof(prefix
), "source file has wrong size\n");
574 /* get the file time and change it to prove the difference */
575 ret
= GetFileTime(hfile
, NULL
, NULL
, &ft1
);
576 ok( ret
, "GetFileTime error %d\n", GetLastError());
577 ft1
.dwLowDateTime
-= 600000000; /* 60 second */
578 ret
= SetFileTime(hfile
, NULL
, NULL
, &ft1
);
579 ok( ret
, "SetFileTime error %d\n", GetLastError());
580 GetFileTime(hfile
, NULL
, NULL
, &ft1
); /* get the actual time back */
583 ret
= GetTempFileNameA(temp_path
, prefix
, 0, dest
);
584 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
586 SetLastError(0xdeadbeef);
587 ret
= CopyFileA(source
, dest
, TRUE
);
588 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
589 "CopyFileA: unexpected error %d\n", GetLastError());
591 ret
= CopyFileA(source
, dest
, FALSE
);
592 ok(ret
, "CopyFileA: error %d\n", GetLastError());
594 /* make sure that destination has correct size */
595 hfile
= CreateFileA(dest
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
596 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open destination file\n");
597 ret
= GetFileSize(hfile
, NULL
);
598 ok(ret
== sizeof(prefix
), "destination file has wrong size %d\n", ret
);
600 /* make sure that destination has the same filetime */
601 ret
= GetFileTime(hfile
, NULL
, NULL
, &ft2
);
602 ok( ret
, "GetFileTime error %d\n", GetLastError());
603 ok(CompareFileTime(&ft1
, &ft2
) == 0, "destination file has wrong filetime\n");
605 SetLastError(0xdeadbeef);
606 ret
= CopyFileA(source
, dest
, FALSE
);
607 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
,
608 "CopyFileA: ret = %d, unexpected error %d\n", ret
, GetLastError());
610 /* make sure that destination still has correct size */
611 ret
= GetFileSize(hfile
, NULL
);
612 ok(ret
== sizeof(prefix
), "destination file has wrong size %d\n", ret
);
613 retok
= ReadFile(hfile
, buf
, sizeof(buf
), &ret
, NULL
);
614 ok( retok
&& ret
== sizeof(prefix
),
615 "ReadFile: error %d\n", GetLastError());
616 ok(!memcmp(prefix
, buf
, sizeof(prefix
)), "buffer contents mismatch\n");
619 ret
= DeleteFileA(source
);
620 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
621 ret
= DeleteFileA(dest
);
622 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
625 static void test_CopyFileW(void)
627 WCHAR temp_path
[MAX_PATH
];
628 WCHAR source
[MAX_PATH
], dest
[MAX_PATH
];
629 static const WCHAR prefix
[] = {'p','f','x',0};
632 ret
= GetTempPathW(MAX_PATH
, temp_path
);
633 if (ret
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
635 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
636 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
638 ret
= GetTempFileNameW(temp_path
, prefix
, 0, source
);
639 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
641 ret
= GetTempFileNameW(temp_path
, prefix
, 0, dest
);
642 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
644 ret
= CopyFileW(source
, dest
, TRUE
);
645 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
646 "CopyFileW: unexpected error %d\n", GetLastError());
648 ret
= CopyFileW(source
, dest
, FALSE
);
649 ok(ret
, "CopyFileW: error %d\n", GetLastError());
651 ret
= DeleteFileW(source
);
652 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
653 ret
= DeleteFileW(dest
);
654 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
657 static void test_CreateFileA(void)
660 char temp_path
[MAX_PATH
];
661 char filename
[MAX_PATH
];
662 static const char prefix
[] = "pfx";
665 ret
= GetTempPathA(MAX_PATH
, temp_path
);
666 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
667 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
669 ret
= GetTempFileNameA(temp_path
, prefix
, 0, filename
);
670 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
672 SetLastError(0xdeadbeef);
673 hFile
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
,
674 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
675 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_EXISTS
,
676 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
678 SetLastError(0xdeadbeef);
679 hFile
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
680 CREATE_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
681 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
682 "hFile %p, last error %u\n", hFile
, GetLastError());
686 SetLastError(0xdeadbeef);
687 hFile
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
688 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
689 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
690 "hFile %p, last error %u\n", hFile
, GetLastError());
694 ret
= DeleteFileA(filename
);
695 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
697 SetLastError(0xdeadbeef);
698 hFile
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
699 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
700 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == 0,
701 "hFile %p, last error %u\n", hFile
, GetLastError());
705 ret
= DeleteFileA(filename
);
706 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
709 static void test_CreateFileW(void)
712 WCHAR temp_path
[MAX_PATH
];
713 WCHAR filename
[MAX_PATH
];
714 static const WCHAR emptyW
[]={'\0'};
715 static const WCHAR prefix
[] = {'p','f','x',0};
716 static const WCHAR bogus
[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 };
719 ret
= GetTempPathW(MAX_PATH
, temp_path
);
720 if (ret
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
722 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
723 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
725 ret
= GetTempFileNameW(temp_path
, prefix
, 0, filename
);
726 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
728 SetLastError(0xdeadbeef);
729 hFile
= CreateFileW(filename
, GENERIC_READ
, 0, NULL
,
730 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
731 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_EXISTS
,
732 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
734 SetLastError(0xdeadbeef);
735 hFile
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
736 CREATE_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
737 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
738 "hFile %p, last error %u\n", hFile
, GetLastError());
742 SetLastError(0xdeadbeef);
743 hFile
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
744 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
745 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
746 "hFile %p, last error %u\n", hFile
, GetLastError());
750 ret
= DeleteFileW(filename
);
751 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
753 SetLastError(0xdeadbeef);
754 hFile
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
755 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
756 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == 0,
757 "hFile %p, last error %u\n", hFile
, GetLastError());
761 ret
= DeleteFileW(filename
);
762 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
766 /* this crashes on NT4.0 */
767 hFile
= CreateFileW(NULL
, GENERIC_READ
, 0, NULL
,
768 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
769 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
770 "CreateFileW(NULL) returned ret=%p error=%u\n",hFile
,GetLastError());
773 hFile
= CreateFileW(emptyW
, GENERIC_READ
, 0, NULL
,
774 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
775 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
776 "CreateFileW(\"\") returned ret=%p error=%d\n",hFile
,GetLastError());
778 /* test the result of opening a nonexistent driver name */
779 hFile
= CreateFileW(bogus
, 0, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
780 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
781 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
782 "CreateFileW on invalid VxD name returned ret=%p error=%d\n",hFile
,GetLastError());
784 ret
= CreateDirectoryW(filename
, NULL
);
785 ok(ret
== TRUE
, "couldn't create temporary directory\n");
786 hFile
= CreateFileW(filename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
787 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
788 ok(hFile
!= INVALID_HANDLE_VALUE
,
789 "expected CreateFile to succeed on existing directory, error: %d\n", GetLastError());
791 ret
= RemoveDirectoryW(filename
);
792 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
795 static void test_GetTempFileNameA(void)
799 char expected
[MAX_PATH
+ 10];
800 char windowsdir
[MAX_PATH
+ 10];
801 char windowsdrive
[3];
803 result
= GetWindowsDirectory(windowsdir
, sizeof(windowsdir
));
804 ok(result
< sizeof(windowsdir
), "windowsdir is abnormally long!\n");
805 ok(result
!= 0, "GetWindowsDirectory: error %d\n", GetLastError());
807 /* If the Windows directory is the root directory, it ends in backslash, not else. */
808 if (strlen(windowsdir
) != 3) /* As in "C:\" or "F:\" */
810 strcat(windowsdir
, "\\");
813 windowsdrive
[0] = windowsdir
[0];
814 windowsdrive
[1] = windowsdir
[1];
815 windowsdrive
[2] = '\0';
817 result
= GetTempFileNameA(windowsdrive
, "abc", 1, out
);
818 ok(result
!= 0, "GetTempFileNameA: error %d\n", GetLastError());
819 ok(((out
[0] == windowsdrive
[0]) && (out
[1] == ':')) && (out
[2] == '\\'),
820 "GetTempFileNameA: first three characters should be %c:\\, string was actually %s\n",
821 windowsdrive
[0], out
);
823 result
= GetTempFileNameA(windowsdir
, "abc", 2, out
);
824 ok(result
!= 0, "GetTempFileNameA: error %d\n", GetLastError());
826 strcat(expected
, windowsdir
);
827 strcat(expected
, "abc2.tmp");
828 ok(lstrcmpiA(out
, expected
) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n",
832 static void test_DeleteFileA( void )
836 ret
= DeleteFileA(NULL
);
837 ok(!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
||
838 GetLastError() == ERROR_PATH_NOT_FOUND
),
839 "DeleteFileA(NULL) returned ret=%d error=%d\n",ret
,GetLastError());
841 ret
= DeleteFileA("");
842 ok(!ret
&& (GetLastError() == ERROR_PATH_NOT_FOUND
||
843 GetLastError() == ERROR_BAD_PATHNAME
),
844 "DeleteFileA(\"\") returned ret=%d error=%d\n",ret
,GetLastError());
846 ret
= DeleteFileA("nul");
847 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
848 GetLastError() == ERROR_INVALID_PARAMETER
||
849 GetLastError() == ERROR_ACCESS_DENIED
||
850 GetLastError() == ERROR_INVALID_FUNCTION
),
851 "DeleteFileA(\"nul\") returned ret=%d error=%d\n",ret
,GetLastError());
854 static void test_DeleteFileW( void )
857 WCHAR pathW
[MAX_PATH
];
858 WCHAR pathsubW
[MAX_PATH
];
859 static const WCHAR dirW
[] = {'d','e','l','e','t','e','f','i','l','e',0};
860 static const WCHAR subdirW
[] = {'\\','s','u','b',0};
861 static const WCHAR emptyW
[]={'\0'};
863 ret
= DeleteFileW(NULL
);
864 if (ret
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
866 ok(!ret
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
867 "DeleteFileW(NULL) returned ret=%d error=%d\n",ret
,GetLastError());
869 ret
= DeleteFileW(emptyW
);
870 ok(!ret
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
871 "DeleteFileW(\"\") returned ret=%d error=%d\n",ret
,GetLastError());
873 /* test DeleteFile on empty directory */
874 ret
= GetTempPathW(MAX_PATH
, pathW
);
875 if (ret
+ sizeof(dirW
)/sizeof(WCHAR
)-1 + sizeof(subdirW
)/sizeof(WCHAR
)-1 >= MAX_PATH
)
877 ok(0, "MAX_PATH exceeded in constructing paths\n");
880 lstrcatW(pathW
, dirW
);
881 lstrcpyW(pathsubW
, pathW
);
882 lstrcatW(pathsubW
, subdirW
);
883 ret
= CreateDirectoryW(pathW
, NULL
);
884 ok(ret
== TRUE
, "couldn't create directory deletefile\n");
885 ret
= DeleteFileW(pathW
);
886 ok(ret
== FALSE
, "DeleteFile should fail for empty directories\n");
887 ret
= RemoveDirectoryW(pathW
);
888 ok(ret
== TRUE
, "expected to remove directory deletefile\n");
890 /* test DeleteFile on non-empty directory */
891 ret
= CreateDirectoryW(pathW
, NULL
);
892 ok(ret
== TRUE
, "couldn't create directory deletefile\n");
893 ret
= CreateDirectoryW(pathsubW
, NULL
);
894 ok(ret
== TRUE
, "couldn't create directory deletefile\\sub\n");
895 ret
= DeleteFileW(pathW
);
896 ok(ret
== FALSE
, "DeleteFile should fail for non-empty directories\n");
897 ret
= RemoveDirectoryW(pathsubW
);
898 ok(ret
== TRUE
, "expected to remove directory deletefile\\sub\n");
899 ret
= RemoveDirectoryW(pathW
);
900 ok(ret
== TRUE
, "expected to remove directory deletefile\n");
903 #define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
905 static void test_MoveFileA(void)
907 char tempdir
[MAX_PATH
];
908 char source
[MAX_PATH
], dest
[MAX_PATH
];
909 static const char prefix
[] = "pfx";
912 ret
= GetTempPathA(MAX_PATH
, tempdir
);
913 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
914 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
916 ret
= GetTempFileNameA(tempdir
, prefix
, 0, source
);
917 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
919 ret
= GetTempFileNameA(tempdir
, prefix
, 0, dest
);
920 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
922 ret
= MoveFileA(source
, dest
);
923 ok(!ret
&& GetLastError() == ERROR_ALREADY_EXISTS
,
924 "MoveFileA: unexpected error %d\n", GetLastError());
926 ret
= DeleteFileA(dest
);
927 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
929 ret
= MoveFileA(source
, dest
);
930 ok(ret
, "MoveFileA: failed, error %d\n", GetLastError());
932 lstrcatA(tempdir
, "Remove Me");
933 ret
= CreateDirectoryA(tempdir
, NULL
);
934 ok(ret
== TRUE
, "CreateDirectoryA failed\n");
936 lstrcpyA(source
, dest
);
937 lstrcpyA(dest
, tempdir
);
938 lstrcatA(dest
, "\\wild?.*");
939 /* FIXME: if we create a file with wildcards we can't delete it now that DeleteFile works correctly */
940 ret
= MoveFileA(source
, dest
);
941 ok(!ret
, "MoveFileA: shouldn't move to wildcard file\n");
942 ok(GetLastError() == ERROR_INVALID_NAME
|| /* NT */
943 GetLastError() == ERROR_FILE_NOT_FOUND
, /* Win9x */
944 "MoveFileA: with wildcards, unexpected error %d\n", GetLastError());
945 if (ret
|| (GetLastError() != ERROR_INVALID_NAME
))
948 char temppath
[MAX_PATH
];
951 lstrcpyA(temppath
, tempdir
);
952 lstrcatA(temppath
, "\\*.*");
953 hFind
= FindFirstFileA(temppath
, &fd
);
954 if (INVALID_HANDLE_VALUE
!= hFind
)
959 lpName
= fd
.cAlternateFileName
;
961 lpName
= fd
.cFileName
;
962 ok(IsDotDir(lpName
), "MoveFileA: wildcards file created!\n");
964 while (FindNextFileA(hFind
, &fd
));
968 ret
= DeleteFileA(source
);
969 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
970 ret
= DeleteFileA(dest
);
971 ok(!ret
, "DeleteFileA: error %d\n", GetLastError());
972 ret
= RemoveDirectoryA(tempdir
);
973 ok(ret
, "DeleteDirectoryA: error %d\n", GetLastError());
976 static void test_MoveFileW(void)
978 WCHAR temp_path
[MAX_PATH
];
979 WCHAR source
[MAX_PATH
], dest
[MAX_PATH
];
980 static const WCHAR prefix
[] = {'p','f','x',0};
983 ret
= GetTempPathW(MAX_PATH
, temp_path
);
984 if (ret
==0 && GetLastError()==ERROR_CALL_NOT_IMPLEMENTED
)
986 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
987 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
989 ret
= GetTempFileNameW(temp_path
, prefix
, 0, source
);
990 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
992 ret
= GetTempFileNameW(temp_path
, prefix
, 0, dest
);
993 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
995 ret
= MoveFileW(source
, dest
);
996 ok(!ret
&& GetLastError() == ERROR_ALREADY_EXISTS
,
997 "CopyFileW: unexpected error %d\n", GetLastError());
999 ret
= DeleteFileW(source
);
1000 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
1001 ret
= DeleteFileW(dest
);
1002 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
1005 #define PATTERN_OFFSET 0x10
1007 static void test_offset_in_overlapped_structure(void)
1013 BYTE buf
[256], pattern
[] = "TeSt";
1015 char temp_path
[MAX_PATH
], temp_fname
[MAX_PATH
];
1018 ret
=GetTempPathA(MAX_PATH
, temp_path
);
1019 ok( ret
, "GetTempPathA error %d\n", GetLastError());
1020 ret
=GetTempFileNameA(temp_path
, "pfx", 0, temp_fname
);
1021 ok( ret
, "GetTempFileNameA error %d\n", GetLastError());
1023 /*** Write File *****************************************************/
1025 hFile
= CreateFileA(temp_fname
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
1026 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError());
1028 for(i
= 0; i
< sizeof(buf
); i
++) buf
[i
] = i
;
1029 ret
= WriteFile(hFile
, buf
, sizeof(buf
), &done
, NULL
);
1030 ok( ret
, "WriteFile error %d\n", GetLastError());
1031 ok(done
== sizeof(buf
), "expected number of bytes written %u\n", done
);
1033 memset(&ov
, 0, sizeof(ov
));
1034 S(U(ov
)).Offset
= PATTERN_OFFSET
;
1035 S(U(ov
)).OffsetHigh
= 0;
1036 rc
=WriteFile(hFile
, pattern
, sizeof(pattern
), &done
, &ov
);
1037 /* Win 9x does not support the overlapped I/O on files */
1038 if (rc
|| GetLastError()!=ERROR_INVALID_PARAMETER
) {
1039 ok(rc
, "WriteFile error %d\n", GetLastError());
1040 ok(done
== sizeof(pattern
), "expected number of bytes written %u\n", done
);
1041 offset
= SetFilePointer(hFile
, 0, NULL
, FILE_CURRENT
);
1042 ok(offset
== PATTERN_OFFSET
+ sizeof(pattern
), "wrong file offset %d\n", offset
);
1044 S(U(ov
)).Offset
= sizeof(buf
) * 2;
1045 S(U(ov
)).OffsetHigh
= 0;
1046 ret
= WriteFile(hFile
, pattern
, sizeof(pattern
), &done
, &ov
);
1047 ok( ret
, "WriteFile error %d\n", GetLastError());
1048 ok(done
== sizeof(pattern
), "expected number of bytes written %u\n", done
);
1049 offset
= SetFilePointer(hFile
, 0, NULL
, FILE_CURRENT
);
1050 ok(offset
== sizeof(buf
) * 2 + sizeof(pattern
), "wrong file offset %d\n", offset
);
1055 /*** Read File *****************************************************/
1057 hFile
= CreateFileA(temp_fname
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, 0);
1058 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError());
1060 memset(buf
, 0, sizeof(buf
));
1061 memset(&ov
, 0, sizeof(ov
));
1062 S(U(ov
)).Offset
= PATTERN_OFFSET
;
1063 S(U(ov
)).OffsetHigh
= 0;
1064 rc
=ReadFile(hFile
, buf
, sizeof(pattern
), &done
, &ov
);
1065 /* Win 9x does not support the overlapped I/O on files */
1066 if (rc
|| GetLastError()!=ERROR_INVALID_PARAMETER
) {
1067 ok(rc
, "ReadFile error %d\n", GetLastError());
1068 ok(done
== sizeof(pattern
), "expected number of bytes read %u\n", done
);
1069 offset
= SetFilePointer(hFile
, 0, NULL
, FILE_CURRENT
);
1070 ok(offset
== PATTERN_OFFSET
+ sizeof(pattern
), "wrong file offset %d\n", offset
);
1071 ok(!memcmp(buf
, pattern
, sizeof(pattern
)), "pattern match failed\n");
1076 ret
= DeleteFileA(temp_fname
);
1077 ok( ret
, "DeleteFileA error %d\n", GetLastError());
1080 static void test_LockFile(void)
1084 OVERLAPPED overlapped
;
1085 int limited_LockFile
;
1086 int limited_UnLockFile
;
1089 handle
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1090 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1091 CREATE_ALWAYS
, 0, 0 );
1092 if (handle
== INVALID_HANDLE_VALUE
)
1094 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
1097 ok( WriteFile( handle
, sillytext
, strlen(sillytext
), &written
, NULL
), "write failed\n" );
1099 ok( LockFile( handle
, 0, 0, 0, 0 ), "LockFile failed\n" );
1100 ok( UnlockFile( handle
, 0, 0, 0, 0 ), "UnlockFile failed\n" );
1102 limited_UnLockFile
= 0;
1103 if (UnlockFile( handle
, 0, 0, 0, 0 ))
1105 limited_UnLockFile
= 1;
1108 ok( LockFile( handle
, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
1109 /* overlapping locks must fail */
1110 ok( !LockFile( handle
, 12, 0, 10, 0 ), "LockFile 12,10 succeeded\n" );
1111 ok( !LockFile( handle
, 5, 0, 6, 0 ), "LockFile 5,6 succeeded\n" );
1112 /* non-overlapping locks must succeed */
1113 ok( LockFile( handle
, 5, 0, 5, 0 ), "LockFile 5,5 failed\n" );
1115 ok( !UnlockFile( handle
, 10, 0, 10, 0 ), "UnlockFile 10,10 succeeded\n" );
1116 ok( UnlockFile( handle
, 10, 0, 20, 0 ), "UnlockFile 10,20 failed\n" );
1117 ok( !UnlockFile( handle
, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" );
1118 ok( UnlockFile( handle
, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" );
1120 S(U(overlapped
)).Offset
= 100;
1121 S(U(overlapped
)).OffsetHigh
= 0;
1122 overlapped
.hEvent
= 0;
1124 /* Test for broken LockFileEx a la Windows 95 OSR2. */
1125 if (LockFileEx( handle
, 0, 0, 100, 0, &overlapped
))
1127 /* LockFileEx is probably OK, test it more. */
1128 ok( LockFileEx( handle
, 0, 0, 100, 0, &overlapped
),
1129 "LockFileEx 100,100 failed\n" );
1132 /* overlapping shared locks are OK */
1133 S(U(overlapped
)).Offset
= 150;
1134 limited_UnLockFile
|| ok( LockFileEx( handle
, 0, 0, 100, 0, &overlapped
), "LockFileEx 150,100 failed\n" );
1136 /* but exclusive is not */
1137 ok( !LockFileEx( handle
, LOCKFILE_EXCLUSIVE_LOCK
|LOCKFILE_FAIL_IMMEDIATELY
,
1138 0, 50, 0, &overlapped
),
1139 "LockFileEx exclusive 150,50 succeeded\n" );
1140 if (!UnlockFileEx( handle
, 0, 100, 0, &overlapped
))
1141 { /* UnLockFile is capable. */
1142 S(U(overlapped
)).Offset
= 100;
1143 ok( !UnlockFileEx( handle
, 0, 100, 0, &overlapped
),
1144 "UnlockFileEx 150,100 again succeeded\n" );
1147 ret
= LockFile( handle
, 0, 0x10000000, 0, 0xf0000000 );
1150 ok( !LockFile( handle
, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" );
1151 ok( !LockFile( handle
, 0, 0x20000000, 20, 0 ), "LockFile 0x20000000,20 succeeded\n" );
1152 ok( UnlockFile( handle
, 0, 0x10000000, 0, 0xf0000000 ), "UnlockFile failed\n" );
1155 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong LockFile error %u\n", GetLastError() );
1157 /* wrap-around lock should not do anything */
1158 /* (but still succeeds on NT4 so we don't check result) */
1159 LockFile( handle
, 0, 0x10000000, 0, 0xf0000001 );
1161 limited_LockFile
= 0;
1162 if (!LockFile( handle
, ~0, ~0, 1, 0 ))
1164 limited_LockFile
= 1;
1167 limited_UnLockFile
|| ok( UnlockFile( handle
, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" );
1169 /* zero-byte lock */
1170 ok( LockFile( handle
, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" );
1171 limited_LockFile
|| ok( !LockFile( handle
, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
1172 ok( LockFile( handle
, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
1173 limited_LockFile
|| ok( !LockFile( handle
, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
1175 ok( UnlockFile( handle
, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
1176 !ok( UnlockFile( handle
, 100, 0, 10, 0 ), "UnlockFile 100,10 failed\n" );
1178 ok( UnlockFile( handle
, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" );
1180 CloseHandle( handle
);
1181 DeleteFileA( filename
);
1184 static inline int is_sharing_compatible( DWORD access1
, DWORD sharing1
, DWORD access2
, DWORD sharing2
, BOOL is_win9x
)
1188 if (!access1
) sharing1
= FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
;
1189 if (!access2
) sharing2
= FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
;
1194 if (!access1
) access1
= GENERIC_READ
;
1197 if (!access2
) access2
= GENERIC_READ
;
1200 if ((access1
& GENERIC_READ
) && !(sharing2
& FILE_SHARE_READ
)) return 0;
1201 if ((access1
& GENERIC_WRITE
) && !(sharing2
& FILE_SHARE_WRITE
)) return 0;
1202 if ((access1
& DELETE
) && !(sharing2
& FILE_SHARE_DELETE
)) return 0;
1203 if ((access2
& GENERIC_READ
) && !(sharing1
& FILE_SHARE_READ
)) return 0;
1204 if ((access2
& GENERIC_WRITE
) && !(sharing1
& FILE_SHARE_WRITE
)) return 0;
1205 if ((access2
& DELETE
) && !(sharing1
& FILE_SHARE_DELETE
)) return 0;
1209 static void test_file_sharing(void)
1211 static const DWORD access_modes
[] =
1212 { 0, GENERIC_READ
, GENERIC_WRITE
, GENERIC_READ
|GENERIC_WRITE
,
1213 DELETE
, GENERIC_READ
|DELETE
, GENERIC_WRITE
|DELETE
, GENERIC_READ
|GENERIC_WRITE
|DELETE
};
1214 static const DWORD sharing_modes
[] =
1215 { 0, FILE_SHARE_READ
,
1216 FILE_SHARE_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
1217 FILE_SHARE_DELETE
, FILE_SHARE_READ
|FILE_SHARE_DELETE
,
1218 FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
};
1222 BOOL is_win9x
= FALSE
;
1224 /* make sure the file exists */
1225 h
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0 );
1226 if (h
== INVALID_HANDLE_VALUE
)
1228 ok(0, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError());
1231 is_win9x
= GetFileAttributesW(filenameW
) == INVALID_FILE_ATTRIBUTES
;
1234 for (a1
= 0; a1
< sizeof(access_modes
)/sizeof(access_modes
[0]); a1
++)
1236 for (s1
= 0; s1
< sizeof(sharing_modes
)/sizeof(sharing_modes
[0]); s1
++)
1238 /* Win9x doesn't support FILE_SHARE_DELETE */
1239 if (is_win9x
&& (sharing_modes
[s1
] & FILE_SHARE_DELETE
))
1242 SetLastError(0xdeadbeef);
1243 h
= CreateFileA( filename
, access_modes
[a1
], sharing_modes
[s1
],
1244 NULL
, OPEN_EXISTING
, 0, 0 );
1245 if (h
== INVALID_HANDLE_VALUE
)
1247 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
1250 for (a2
= 0; a2
< sizeof(access_modes
)/sizeof(access_modes
[0]); a2
++)
1252 for (s2
= 0; s2
< sizeof(sharing_modes
)/sizeof(sharing_modes
[0]); s2
++)
1254 /* Win9x doesn't support FILE_SHARE_DELETE */
1255 if (is_win9x
&& (sharing_modes
[s2
] & FILE_SHARE_DELETE
))
1258 SetLastError(0xdeadbeef);
1259 h2
= CreateFileA( filename
, access_modes
[a2
], sharing_modes
[s2
],
1260 NULL
, OPEN_EXISTING
, 0, 0 );
1262 if (is_sharing_compatible( access_modes
[a1
], sharing_modes
[s1
],
1263 access_modes
[a2
], sharing_modes
[s2
], is_win9x
))
1265 ret
= GetLastError();
1267 ok( h2
!= INVALID_HANDLE_VALUE
,
1268 "open failed for modes %x/%x/%x/%x\n",
1269 access_modes
[a1
], sharing_modes
[s1
],
1270 access_modes
[a2
], sharing_modes
[s2
] );
1271 ok( ret
== 0xdeadbeef /* Win9x */ ||
1273 "wrong error code %d\n", ret
);
1279 ret
= GetLastError();
1281 ok( h2
== INVALID_HANDLE_VALUE
,
1282 "open succeeded for modes %x/%x/%x/%x\n",
1283 access_modes
[a1
], sharing_modes
[s1
],
1284 access_modes
[a2
], sharing_modes
[s2
] );
1285 ok( ret
== ERROR_SHARING_VIOLATION
,
1286 "wrong error code %d\n", ret
);
1294 SetLastError(0xdeadbeef);
1295 h
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, OPEN_ALWAYS
, 0, 0 );
1296 ok( h
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError() );
1298 SetLastError(0xdeadbeef);
1299 h2
= CreateFileA( filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
1300 ok( h2
== INVALID_HANDLE_VALUE
, "CreateFileA should fail\n");
1301 ok( GetLastError() == ERROR_SHARING_VIOLATION
, "wrong error code %d\n", GetLastError() );
1303 h2
= CreateFileA( filename
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
1304 ok( h2
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError() );
1309 DeleteFileA( filename
);
1312 static char get_windows_drive(void)
1314 char windowsdir
[MAX_PATH
];
1315 GetWindowsDirectory(windowsdir
, sizeof(windowsdir
));
1316 return windowsdir
[0];
1319 static void test_FindFirstFileA(void)
1322 WIN32_FIND_DATAA data
;
1324 char buffer
[5] = "C:\\";
1327 /* try FindFirstFileA on "C:\" */
1328 buffer
[0] = get_windows_drive();
1330 SetLastError( 0xdeadbeaf );
1331 handle
= FindFirstFileA(buffer
, &data
);
1332 err
= GetLastError();
1333 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on root directory should fail\n" );
1334 ok ( err
== ERROR_FILE_NOT_FOUND
, "Bad Error number %d\n", err
);
1336 /* try FindFirstFileA on "C:\*" */
1337 strcpy(buffer2
, buffer
);
1338 strcat(buffer2
, "*");
1339 handle
= FindFirstFileA(buffer2
, &data
);
1340 ok ( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s should succeed\n", buffer2
);
1341 ok ( strcmp( data
.cFileName
, "." ) && strcmp( data
.cFileName
, ".." ),
1342 "FindFirstFile shouldn't return '%s' in drive root\n", data
.cFileName
);
1343 if (FindNextFileA( handle
, &data
))
1344 ok ( strcmp( data
.cFileName
, "." ) && strcmp( data
.cFileName
, ".." ),
1345 "FindNextFile shouldn't return '%s' in drive root\n", data
.cFileName
);
1346 ok ( FindClose(handle
) == TRUE
, "Failed to close handle %s\n", buffer2
);
1348 /* try FindFirstFileA on windows dir */
1349 GetWindowsDirectory( buffer2
, sizeof(buffer2
) );
1350 strcat(buffer2
, "\\*");
1351 handle
= FindFirstFileA(buffer2
, &data
);
1352 ok( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s should succeed\n", buffer2
);
1353 ok( !strcmp( data
.cFileName
, "." ), "FindFirstFile should return '.' first\n" );
1354 ok( FindNextFileA( handle
, &data
), "FindNextFile failed\n" );
1355 ok( !strcmp( data
.cFileName
, ".." ), "FindNextFile should return '..' as second entry\n" );
1356 while (FindNextFileA( handle
, &data
))
1357 ok ( strcmp( data
.cFileName
, "." ) && strcmp( data
.cFileName
, ".." ),
1358 "FindNextFile shouldn't return '%s'\n", data
.cFileName
);
1359 ok ( FindClose(handle
) == TRUE
, "Failed to close handle %s\n", buffer2
);
1361 /* try FindFirstFileA on "C:\foo\" */
1362 SetLastError( 0xdeadbeaf );
1363 strcpy(buffer2
, buffer
);
1364 strcat(buffer2
, "foo\\");
1365 handle
= FindFirstFileA(buffer2
, &data
);
1366 err
= GetLastError();
1367 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1369 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
1372 /* try FindFirstFileA on "C:\foo\bar.txt" */
1373 SetLastError( 0xdeadbeaf );
1374 strcpy(buffer2
, buffer
);
1375 strcat(buffer2
, "foo\\bar.txt");
1376 handle
= FindFirstFileA(buffer2
, &data
);
1377 err
= GetLastError();
1378 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1379 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
1381 /* try FindFirstFileA on "C:\foo\*.*" */
1382 SetLastError( 0xdeadbeaf );
1383 strcpy(buffer2
, buffer
);
1384 strcat(buffer2
, "foo\\*.*");
1385 handle
= FindFirstFileA(buffer2
, &data
);
1386 err
= GetLastError();
1387 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1388 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
1390 /* try FindFirstFileA on "foo\bar.txt" */
1391 SetLastError( 0xdeadbeaf );
1392 strcpy(buffer2
, "foo\\bar.txt");
1393 handle
= FindFirstFileA(buffer2
, &data
);
1394 err
= GetLastError();
1395 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1396 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
1398 /* try FindFirstFileA on "c:\nul" */
1399 SetLastError( 0xdeadbeaf );
1400 strcpy(buffer2
, buffer
);
1401 strcat(buffer2
, "nul");
1402 handle
= FindFirstFileA(buffer2
, &data
);
1403 err
= GetLastError();
1404 ok( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s failed\n", buffer2
);
1405 ok( 0 == lstrcmpiA(data
.cFileName
, "nul"), "wrong name %s\n", data
.cFileName
);
1406 ok( FILE_ATTRIBUTE_ARCHIVE
== data
.dwFileAttributes
||
1407 FILE_ATTRIBUTE_DEVICE
== data
.dwFileAttributes
/* Win9x */,
1408 "wrong attributes %x\n", data
.dwFileAttributes
);
1409 if (data
.dwFileAttributes
== FILE_ATTRIBUTE_ARCHIVE
)
1411 ok( 0 == data
.nFileSizeHigh
, "wrong size %d\n", data
.nFileSizeHigh
);
1412 ok( 0 == data
.nFileSizeLow
, "wrong size %d\n", data
.nFileSizeLow
);
1414 SetLastError( 0xdeadbeaf );
1415 ok( !FindNextFileA( handle
, &data
), "FindNextFileA succeeded\n" );
1416 ok( GetLastError() == ERROR_NO_MORE_FILES
, "bad error %d\n", GetLastError() );
1417 ok( FindClose( handle
), "failed to close handle\n" );
1419 /* try FindFirstFileA on "lpt1" */
1420 SetLastError( 0xdeadbeaf );
1421 strcpy(buffer2
, "lpt1");
1422 handle
= FindFirstFileA(buffer2
, &data
);
1423 err
= GetLastError();
1424 ok( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s failed\n", buffer2
);
1425 ok( 0 == lstrcmpiA(data
.cFileName
, "lpt1"), "wrong name %s\n", data
.cFileName
);
1426 ok( FILE_ATTRIBUTE_ARCHIVE
== data
.dwFileAttributes
||
1427 FILE_ATTRIBUTE_DEVICE
== data
.dwFileAttributes
/* Win9x */,
1428 "wrong attributes %x\n", data
.dwFileAttributes
);
1429 if (data
.dwFileAttributes
== FILE_ATTRIBUTE_ARCHIVE
)
1431 ok( 0 == data
.nFileSizeHigh
, "wrong size %d\n", data
.nFileSizeHigh
);
1432 ok( 0 == data
.nFileSizeLow
, "wrong size %d\n", data
.nFileSizeLow
);
1434 SetLastError( 0xdeadbeaf );
1435 ok( !FindNextFileA( handle
, &data
), "FindNextFileA succeeded\n" );
1436 ok( GetLastError() == ERROR_NO_MORE_FILES
, "bad error %d\n", GetLastError() );
1437 ok( FindClose( handle
), "failed to close handle\n" );
1439 /* try FindFirstFileA on "c:\nul\*" */
1440 SetLastError( 0xdeadbeaf );
1441 strcpy(buffer2
, buffer
);
1442 strcat(buffer2
, "nul\\*");
1443 handle
= FindFirstFileA(buffer2
, &data
);
1444 err
= GetLastError();
1445 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1446 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
1448 /* try FindFirstFileA on "c:\nul*" */
1449 SetLastError( 0xdeadbeaf );
1450 strcpy(buffer2
, buffer
);
1451 strcat(buffer2
, "nul*");
1452 handle
= FindFirstFileA(buffer2
, &data
);
1453 err
= GetLastError();
1454 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1455 ok ( err
== ERROR_FILE_NOT_FOUND
, "Bad Error number %d\n", err
);
1457 /* try FindFirstFileA on "c:\foo\bar\nul" */
1458 SetLastError( 0xdeadbeaf );
1459 strcpy(buffer2
, buffer
);
1460 strcat(buffer2
, "foo\\bar\\nul");
1461 handle
= FindFirstFileA(buffer2
, &data
);
1462 err
= GetLastError();
1463 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1464 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
1466 /* try FindFirstFileA on "c:\foo\nul\bar" */
1467 SetLastError( 0xdeadbeaf );
1468 strcpy(buffer2
, buffer
);
1469 strcat(buffer2
, "foo\\nul\\bar");
1470 handle
= FindFirstFileA(buffer2
, &data
);
1471 err
= GetLastError();
1472 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
1473 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
1476 static void test_FindNextFileA(void)
1479 WIN32_FIND_DATAA search_results
;
1481 char buffer
[5] = "C:\\*";
1483 buffer
[0] = get_windows_drive();
1484 handle
= FindFirstFileA(buffer
,&search_results
);
1485 ok ( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on C:\\* should succeed\n" );
1486 while (FindNextFile(handle
, &search_results
))
1488 /* get to the end of the files */
1490 ok ( FindClose(handle
) == TRUE
, "Failed to close handle\n");
1491 err
= GetLastError();
1492 ok ( err
== ERROR_NO_MORE_FILES
, "GetLastError should return ERROR_NO_MORE_FILES\n");
1495 static void test_FindFirstFileExA(void)
1497 WIN32_FIND_DATAA search_results
;
1500 if (!pFindFirstFileExA
)
1502 skip("FindFirstFileExA() is missing\n");
1506 CreateDirectoryA("test-dir", NULL
);
1507 _lclose(_lcreat("test-dir\\file1", 0));
1508 _lclose(_lcreat("test-dir\\file2", 0));
1509 CreateDirectoryA("test-dir\\dir1", NULL
);
1510 /* FindExLimitToDirectories is ignored */
1511 SetLastError(0xdeadbeef);
1512 handle
= pFindFirstFileExA("test-dir\\*", FindExInfoStandard
, &search_results
, FindExSearchLimitToDirectories
, NULL
, 0);
1513 if (handle
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1515 skip("FindFirstFileExA is not implemented\n");
1518 ok(handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile failed (err=%u)\n", GetLastError());
1519 ok(strcmp(search_results
.cFileName
, ".") == 0, "First entry should be '.', is %s\n", search_results
.cFileName
);
1521 #define CHECK_NAME(fn) (strcmp((fn), "file1") == 0 || strcmp((fn), "file2") == 0 || strcmp((fn), "dir1") == 0)
1523 ok(FindNextFile(handle
, &search_results
), "Fetching second file failed\n");
1524 ok(strcmp(search_results
.cFileName
, "..") == 0, "Second entry should be '..' is %s\n", search_results
.cFileName
);
1526 ok(FindNextFile(handle
, &search_results
), "Fetching third file failed\n");
1527 ok(CHECK_NAME(search_results
.cFileName
), "Invalid third entry - %s\n", search_results
.cFileName
);
1529 ok(FindNextFile(handle
, &search_results
), "Fetching fourth file failed\n");
1530 ok(CHECK_NAME(search_results
.cFileName
), "Invalid fourth entry - %s\n", search_results
.cFileName
);
1532 ok(FindNextFile(handle
, &search_results
), "Fetching fifth file failed\n");
1533 ok(CHECK_NAME(search_results
.cFileName
), "Invalid fifth entry - %s\n", search_results
.cFileName
);
1537 ok(FindNextFile(handle
, &search_results
) == FALSE
, "Fetching sixth file should failed\n");
1539 FindClose( handle
);
1542 DeleteFileA("test-dir\\file1");
1543 DeleteFileA("test-dir\\file2");
1544 RemoveDirectoryA("test-dir\\dir1");
1545 RemoveDirectoryA("test-dir");
1548 static int test_Mapfile_createtemp(HANDLE
*handle
)
1550 SetFileAttributesA(filename
,FILE_ATTRIBUTE_NORMAL
);
1551 DeleteFile(filename
);
1552 *handle
= CreateFile(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, 0,
1553 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1554 if (*handle
!= INVALID_HANDLE_VALUE
) {
1562 static void test_MapFile(void)
1567 ok(test_Mapfile_createtemp(&handle
), "Couldn't create test file.\n");
1569 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0, 0x1000, "named_file_map" );
1570 ok( hmap
!= NULL
, "mapping should work, I named it!\n" );
1572 ok( CloseHandle( hmap
), "can't close mapping handle\n");
1574 /* We have to close file before we try new stuff with mapping again.
1575 Else we would always succeed on XP or block descriptors on 95. */
1576 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0, 0, NULL
);
1577 ok( hmap
!= NULL
, "We should still be able to map!\n" );
1578 ok( CloseHandle( hmap
), "can't close mapping handle\n");
1579 ok( CloseHandle( handle
), "can't close file handle\n");
1582 ok(test_Mapfile_createtemp(&handle
), "Couldn't create test file.\n");
1584 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0, 0, NULL
);
1585 ok( hmap
== NULL
, "mapped zero size file\n");
1586 ok( GetLastError() == ERROR_FILE_INVALID
, "not ERROR_FILE_INVALID\n");
1588 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0x80000000, 0, NULL
);
1589 ok( hmap
== NULL
|| broken(hmap
!= NULL
) /* NT4 */, "mapping should fail\n");
1590 /* GetLastError() varies between win9x and WinNT and also depends on the filesystem */
1592 CloseHandle( hmap
);
1594 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0x80000000, 0x10000, NULL
);
1595 ok( hmap
== NULL
|| broken(hmap
!= NULL
) /* NT4 */, "mapping should fail\n");
1596 /* GetLastError() varies between win9x and WinNT and also depends on the filesystem */
1598 CloseHandle( hmap
);
1600 /* On XP you can now map again, on Win 95 you cannot. */
1602 ok( CloseHandle( handle
), "can't close file handle\n");
1603 ok( DeleteFileA( filename
), "DeleteFile failed after map\n" );
1606 static void test_GetFileType(void)
1609 HANDLE h
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0 );
1610 ok( h
!= INVALID_HANDLE_VALUE
, "open %s failed\n", filename
);
1611 type
= GetFileType(h
);
1612 ok( type
== FILE_TYPE_DISK
, "expected type disk got %d\n", type
);
1614 h
= CreateFileA( "nul", GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
1615 ok( h
!= INVALID_HANDLE_VALUE
, "open nul failed\n" );
1616 type
= GetFileType(h
);
1617 ok( type
== FILE_TYPE_CHAR
, "expected type char for nul got %d\n", type
);
1619 DeleteFileA( filename
);
1622 static int completion_count
;
1624 static void CALLBACK
FileIOComplete(DWORD dwError
, DWORD dwBytes
, LPOVERLAPPED ovl
)
1626 /* printf("(%ld, %ld, %p { %ld, %ld, %ld, %ld, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->Offset, ovl->OffsetHigh, ovl->hEvent);*/
1627 ReleaseSemaphore(ovl
->hEvent
, 1, NULL
);
1631 static void test_async_file_errors(void)
1633 char szFile
[MAX_PATH
];
1634 HANDLE hSem
= CreateSemaphoreW(NULL
, 1, 1, NULL
);
1636 LPVOID lpBuffer
= HeapAlloc(GetProcessHeap(), 0, 4096);
1638 S(U(ovl
)).Offset
= 0;
1639 S(U(ovl
)).OffsetHigh
= 0;
1641 completion_count
= 0;
1643 GetWindowsDirectoryA(szFile
, sizeof(szFile
)/sizeof(szFile
[0])-1-strlen("\\win.ini"));
1644 strcat(szFile
, "\\win.ini");
1645 hFile
= CreateFileA(szFile
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1646 NULL
, OPEN_ALWAYS
, FILE_FLAG_OVERLAPPED
, NULL
);
1647 if (hFile
== INVALID_HANDLE_VALUE
) /* win9x doesn't like FILE_SHARE_DELETE */
1648 hFile
= CreateFileA(szFile
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1649 NULL
, OPEN_ALWAYS
, FILE_FLAG_OVERLAPPED
, NULL
);
1650 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA(%s ...) failed\n", szFile
);
1655 while (WaitForSingleObjectEx(hSem
, INFINITE
, TRUE
) == WAIT_IO_COMPLETION
)
1657 res
= ReadFileEx(hFile
, lpBuffer
, 4096, &ovl
, FileIOComplete
);
1658 /*printf("Offset = %ld, result = %s\n", ovl.Offset, res ? "TRUE" : "FALSE");*/
1661 if (!GetOverlappedResult(hFile
, &ovl
, &count
, FALSE
))
1663 S(U(ovl
)).Offset
+= count
;
1664 /* i/o completion routine only called if ReadFileEx returned success.
1665 * we only care about violations of this rule so undo what should have
1669 ok(completion_count
== 0, "completion routine should only be called when ReadFileEx succeeds (this rule was violated %d times)\n", completion_count
);
1670 /*printf("Error = %ld\n", GetLastError());*/
1671 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1674 static void test_read_write(void)
1676 DWORD bytes
, ret
, old_prot
;
1678 char temp_path
[MAX_PATH
];
1679 char filename
[MAX_PATH
];
1681 static const char prefix
[] = "pfx";
1683 ret
= GetTempPathA(MAX_PATH
, temp_path
);
1684 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
1685 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
1687 ret
= GetTempFileNameA(temp_path
, prefix
, 0, filename
);
1688 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
1690 hFile
= CreateFileA(filename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
1691 CREATE_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
1692 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA: error %d\n", GetLastError());
1694 SetLastError(12345678);
1696 ret
= WriteFile(hFile
, NULL
, 0, &bytes
, NULL
);
1697 ok(ret
&& GetLastError() == 12345678,
1698 "ret = %d, error %d\n", ret
, GetLastError());
1699 ok(!bytes
, "bytes = %d\n", bytes
);
1701 SetLastError(12345678);
1703 ret
= WriteFile(hFile
, NULL
, 10, &bytes
, NULL
);
1704 ok((!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
) || /* Win2k */
1705 (ret
&& GetLastError() == 12345678), /* Win9x */
1706 "ret = %d, error %d\n", ret
, GetLastError());
1707 ok(!bytes
|| /* Win2k */
1708 bytes
== 10, /* Win9x */
1709 "bytes = %d\n", bytes
);
1711 /* make sure the file contains data */
1712 WriteFile(hFile
, "this is the test data", 21, &bytes
, NULL
);
1713 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
1715 SetLastError(12345678);
1717 ret
= ReadFile(hFile
, NULL
, 0, &bytes
, NULL
);
1718 ok(ret
&& GetLastError() == 12345678,
1719 "ret = %d, error %d\n", ret
, GetLastError());
1720 ok(!bytes
, "bytes = %d\n", bytes
);
1722 SetLastError(12345678);
1724 ret
= ReadFile(hFile
, NULL
, 10, &bytes
, NULL
);
1725 ok(!ret
&& (GetLastError() == ERROR_NOACCESS
|| /* Win2k */
1726 GetLastError() == ERROR_INVALID_PARAMETER
), /* Win9x */
1727 "ret = %d, error %d\n", ret
, GetLastError());
1728 ok(!bytes
, "bytes = %d\n", bytes
);
1730 /* test passing protected memory as buffer */
1732 mem
= VirtualAlloc( NULL
, 0x4000, MEM_COMMIT
, PAGE_READWRITE
);
1733 ok( mem
!= NULL
, "failed to allocate virtual mem error %u\n", GetLastError() );
1735 ret
= WriteFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
1736 ok( ret
, "WriteFile failed error %u\n", GetLastError() );
1737 ok( bytes
== 0x4000, "only wrote %x bytes\n", bytes
);
1739 ret
= VirtualProtect( mem
+ 0x2000, 0x2000, PAGE_NOACCESS
, &old_prot
);
1740 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
1742 ret
= WriteFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
1743 ok( !ret
, "WriteFile succeeded\n" );
1744 ok( GetLastError() == ERROR_INVALID_USER_BUFFER
||
1745 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1746 "wrong error %u\n", GetLastError() );
1747 ok( bytes
== 0, "wrote %x bytes\n", bytes
);
1749 ret
= WriteFile( (HANDLE
)0xdead, mem
, 0x4000, &bytes
, NULL
);
1750 ok( !ret
, "WriteFile succeeded\n" );
1751 ok( GetLastError() == ERROR_INVALID_HANDLE
|| /* handle is checked before buffer on NT */
1752 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1753 "wrong error %u\n", GetLastError() );
1754 ok( bytes
== 0, "wrote %x bytes\n", bytes
);
1756 ret
= VirtualProtect( mem
, 0x2000, PAGE_NOACCESS
, &old_prot
);
1757 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
1759 ret
= WriteFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
1760 ok( !ret
, "WriteFile succeeded\n" );
1761 ok( GetLastError() == ERROR_INVALID_USER_BUFFER
||
1762 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1763 "wrong error %u\n", GetLastError() );
1764 ok( bytes
== 0, "wrote %x bytes\n", bytes
);
1766 SetFilePointer( hFile
, 0, NULL
, FILE_BEGIN
);
1768 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
1769 ok( !ret
, "ReadFile succeeded\n" );
1770 ok( GetLastError() == ERROR_NOACCESS
||
1771 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1772 "wrong error %u\n", GetLastError() );
1773 ok( bytes
== 0, "read %x bytes\n", bytes
);
1775 ret
= VirtualProtect( mem
, 0x2000, PAGE_READONLY
, &old_prot
);
1776 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
1778 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
1779 ok( !ret
, "ReadFile succeeded\n" );
1780 ok( GetLastError() == ERROR_NOACCESS
||
1781 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1782 "wrong error %u\n", GetLastError() );
1783 ok( bytes
== 0, "read %x bytes\n", bytes
);
1785 ret
= VirtualProtect( mem
, 0x2000, PAGE_READWRITE
, &old_prot
);
1786 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
1788 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
1789 ok( !ret
, "ReadFile succeeded\n" );
1790 ok( GetLastError() == ERROR_NOACCESS
||
1791 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1792 "wrong error %u\n", GetLastError() );
1793 ok( bytes
== 0, "read %x bytes\n", bytes
);
1795 SetFilePointer( hFile
, 0x1234, NULL
, FILE_BEGIN
);
1796 SetEndOfFile( hFile
);
1797 SetFilePointer( hFile
, 0, NULL
, FILE_BEGIN
);
1799 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
1800 ok( !ret
, "ReadFile succeeded\n" );
1801 ok( GetLastError() == ERROR_NOACCESS
||
1802 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1803 "wrong error %u\n", GetLastError() );
1804 ok( bytes
== 0, "read %x bytes\n", bytes
);
1806 ret
= ReadFile( hFile
, mem
, 0x2000, &bytes
, NULL
);
1807 ok( ret
, "ReadFile failed error %u\n", GetLastError() );
1808 ok( bytes
== 0x1234, "read %x bytes\n", bytes
);
1810 ret
= ReadFile( hFile
, NULL
, 1, &bytes
, NULL
);
1811 ok( !ret
, "ReadFile succeeded\n" );
1812 ok( GetLastError() == ERROR_NOACCESS
||
1813 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
1814 "wrong error %u\n", GetLastError() );
1815 ok( bytes
== 0, "read %x bytes\n", bytes
);
1817 VirtualFree( mem
, 0, MEM_FREE
);
1819 ret
= CloseHandle(hFile
);
1820 ok( ret
, "CloseHandle: error %d\n", GetLastError());
1821 ret
= DeleteFileA(filename
);
1822 ok( ret
, "DeleteFileA: error %d\n", GetLastError());
1825 static void test_OpenFile(void)
1832 static const char file
[] = "regedit.exe";
1833 static const char foo
[] = ".\\foo-bar-foo.baz";
1834 static const char *foo_too_long
= ".\\foo-bar-foo.baz+++++++++++++++"
1835 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
1836 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
1837 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
1838 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
1839 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
1840 char buff
[MAX_PATH
];
1841 char buff_long
[4*MAX_PATH
];
1842 char filled_0xA5
[OFS_MAXPATHNAME
];
1846 /* Check for existing file */
1847 if (!pGetSystemWindowsDirectoryA
)
1848 length
= GetWindowsDirectoryA(buff
, MAX_PATH
);
1850 length
= pGetSystemWindowsDirectoryA(buff
, MAX_PATH
);
1852 if (length
+ sizeof(file
) < MAX_PATH
)
1854 p
= buff
+ strlen(buff
);
1855 if (p
> buff
&& p
[-1] != '\\') *p
++ = '\\';
1857 memset(&ofs
, 0xA5, sizeof(ofs
));
1858 SetLastError(0xfaceabee);
1860 hFile
= OpenFile(buff
, &ofs
, OF_EXIST
);
1861 ok( hFile
== TRUE
, "%s not found : %d\n", buff
, GetLastError() );
1862 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
1863 "GetLastError() returns %d\n", GetLastError() );
1864 ok( ofs
.cBytes
== sizeof(ofs
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1865 ok( ofs
.nErrCode
== ERROR_SUCCESS
, "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1866 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
1867 "OpenFile returned '%s', but was expected to return '%s' or string filled with 0xA5\n",
1868 ofs
.szPathName
, buff
);
1871 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
1872 length
= GetCurrentDirectoryA(MAX_PATH
, buff
);
1874 /* Check for nonexistent file */
1875 if (length
+ sizeof(foo
) < MAX_PATH
)
1877 p
= buff
+ strlen(buff
);
1878 if (p
> buff
&& p
[-1] != '\\') *p
++ = '\\';
1879 strcpy( p
, foo
+ 2 );
1880 memset(&ofs
, 0xA5, sizeof(ofs
));
1881 SetLastError(0xfaceabee);
1883 hFile
= OpenFile(foo
, &ofs
, OF_EXIST
);
1884 ok( hFile
== HFILE_ERROR
, "hFile != HFILE_ERROR : %d\n", GetLastError());
1885 ok( GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() returns %d\n", GetLastError() );
1887 ok( ofs
.cBytes
== 0xA5, "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1888 ok( ofs
.nErrCode
== ERROR_FILE_NOT_FOUND
, "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1889 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0 || strncmp(ofs
.szPathName
, filled_0xA5
, OFS_MAXPATHNAME
) == 0,
1890 "OpenFile returned '%s', but was expected to return '%s' or string filled with 0xA5\n",
1891 ofs
.szPathName
, buff
);
1894 length
= GetCurrentDirectoryA(MAX_PATH
, buff_long
);
1895 length
+= lstrlenA(foo_too_long
+ 1);
1897 /* Check for nonexistent file with too long filename */
1898 if (length
>= OFS_MAXPATHNAME
&& length
< sizeof(buff_long
))
1900 lstrcatA(buff_long
, foo_too_long
+ 1); /* Avoid '.' during concatenation */
1901 memset(&ofs
, 0xA5, sizeof(ofs
));
1902 SetLastError(0xfaceabee);
1904 hFile
= OpenFile(foo_too_long
, &ofs
, OF_EXIST
);
1905 ok( hFile
== HFILE_ERROR
, "hFile != HFILE_ERROR : %d\n", GetLastError());
1906 ok( GetLastError() == ERROR_INVALID_DATA
|| GetLastError() == ERROR_FILENAME_EXCED_RANGE
,
1907 "GetLastError() returns %d\n", GetLastError() );
1909 ok( ofs
.cBytes
== 0xA5, "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1910 ok( ofs
.nErrCode
== ERROR_INVALID_DATA
|| ofs
.nErrCode
== ERROR_FILENAME_EXCED_RANGE
,
1911 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1912 ok( strncmp(ofs
.szPathName
, filled_0xA5
, OFS_MAXPATHNAME
) == 0,
1913 "OpenFile returned '%s', but was expected to return string filled with 0xA5\n",
1917 length
= GetCurrentDirectoryA(MAX_PATH
, buff
) + sizeof(filename
);
1919 if (length
>= MAX_PATH
)
1921 trace("Buffer too small, requested length = %d, but MAX_PATH = %d. Skipping test.\n", length
, MAX_PATH
);
1924 p
= buff
+ strlen(buff
);
1925 if (p
> buff
&& p
[-1] != '\\') *p
++ = '\\';
1926 strcpy( p
, filename
);
1928 memset(&ofs
, 0xA5, sizeof(ofs
));
1929 SetLastError(0xfaceabee);
1930 /* Create an empty file */
1931 hFile
= OpenFile(filename
, &ofs
, OF_CREATE
);
1932 ok( hFile
!= HFILE_ERROR
, "OpenFile failed to create nonexistent file\n" );
1933 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
1934 "GetLastError() returns %d\n", GetLastError() );
1935 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1936 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
1937 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1938 ret
= _lclose(hFile
);
1939 ok( !ret
, "_lclose() returns %d\n", ret
);
1940 retval
= GetFileAttributesA(filename
);
1941 ok( retval
!= INVALID_FILE_ATTRIBUTES
, "GetFileAttributesA: error %d\n", GetLastError() );
1943 memset(&ofs
, 0xA5, sizeof(ofs
));
1944 SetLastError(0xfaceabee);
1945 /* Check various opening options: */
1946 /* for reading only, */
1947 hFile
= OpenFile(filename
, &ofs
, OF_READ
);
1948 ok( hFile
!= HFILE_ERROR
, "OpenFile failed on read\n" );
1949 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
1950 "GetLastError() returns %d\n", GetLastError() );
1951 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1952 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
1953 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1954 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
1955 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
1956 ret
= _lclose(hFile
);
1957 ok( !ret
, "_lclose() returns %d\n", ret
);
1959 memset(&ofs
, 0xA5, sizeof(ofs
));
1960 SetLastError(0xfaceabee);
1961 /* for writing only, */
1962 hFile
= OpenFile(filename
, &ofs
, OF_WRITE
);
1963 ok( hFile
!= HFILE_ERROR
, "OpenFile failed on write\n" );
1964 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
1965 "GetLastError() returns %d\n", GetLastError() );
1966 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1967 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
1968 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1969 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
1970 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
1971 ret
= _lclose(hFile
);
1972 ok( !ret
, "_lclose() returns %d\n", ret
);
1974 memset(&ofs
, 0xA5, sizeof(ofs
));
1975 SetLastError(0xfaceabee);
1976 /* for reading and writing, */
1977 hFile
= OpenFile(filename
, &ofs
, OF_READWRITE
);
1978 ok( hFile
!= HFILE_ERROR
, "OpenFile failed on read/write\n" );
1979 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
1980 "GetLastError() returns %d\n", GetLastError() );
1981 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1982 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
1983 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1984 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
1985 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
1986 ret
= _lclose(hFile
);
1987 ok( !ret
, "_lclose() returns %d\n", ret
);
1989 memset(&ofs
, 0xA5, sizeof(ofs
));
1990 SetLastError(0xfaceabee);
1991 /* for checking file presence. */
1992 hFile
= OpenFile(filename
, &ofs
, OF_EXIST
);
1993 ok( hFile
== 1, "OpenFile failed on finding our created file\n" );
1994 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
1995 "GetLastError() returns %d\n", GetLastError() );
1996 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
1997 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
1998 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
1999 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2000 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
2002 memset(&ofs
, 0xA5, sizeof(ofs
));
2003 SetLastError(0xfaceabee);
2004 /* Delete the file and make sure it doesn't exist anymore */
2005 hFile
= OpenFile(filename
, &ofs
, OF_DELETE
);
2006 ok( hFile
== 1, "OpenFile failed on delete (%d)\n", hFile
);
2007 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2008 "GetLastError() returns %d\n", GetLastError() );
2009 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2010 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
2011 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2012 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2013 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
2015 retval
= GetFileAttributesA(filename
);
2016 ok( retval
== INVALID_FILE_ATTRIBUTES
, "GetFileAttributesA succeeded on deleted file\n" );
2019 static void test_overlapped(void)
2024 /* GetOverlappedResult crashes if the 2nd or 3rd param are NULL */
2026 memset( &ov
, 0, sizeof ov
);
2028 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2030 ok( result
== 0, "wrong result %u\n", result
);
2032 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
2036 ov
.InternalHigh
= 0xabcd;
2037 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2039 ok( result
== 0xabcd, "wrong result %u\n", result
);
2041 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
2043 SetLastError( 0xb00 );
2045 ov
.Internal
= STATUS_INVALID_HANDLE
;
2046 ov
.InternalHigh
= 0xabcd;
2047 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2048 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
2049 ok( r
== FALSE
, "should return false\n");
2050 ok( result
== 0xabcd || result
== 0 /* win9x */, "wrong result %u\n", result
);
2052 SetLastError( 0xb00 );
2054 ov
.Internal
= STATUS_PENDING
;
2055 ov
.InternalHigh
= 0xabcd;
2056 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2057 ok( GetLastError() == ERROR_IO_INCOMPLETE
|| GetLastError() == ERROR_INVALID_HANDLE
/* win9x */,
2058 "wrong error %u\n", GetLastError() );
2059 ok( r
== FALSE
, "should return false\n");
2060 ok( result
== 0, "wrong result %u\n", result
);
2062 SetLastError( 0xb00 );
2063 ov
.hEvent
= CreateEvent( NULL
, 1, 1, NULL
);
2064 ov
.Internal
= STATUS_PENDING
;
2065 ov
.InternalHigh
= 0xabcd;
2066 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2067 ok( GetLastError() == ERROR_IO_INCOMPLETE
|| GetLastError() == ERROR_INVALID_HANDLE
/* win9x */,
2068 "wrong error %u\n", GetLastError() );
2069 ok( r
== FALSE
, "should return false\n");
2071 ResetEvent( ov
.hEvent
);
2073 SetLastError( 0xb00 );
2074 ov
.Internal
= STATUS_PENDING
;
2075 ov
.InternalHigh
= 0;
2076 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2077 ok( GetLastError() == ERROR_IO_INCOMPLETE
|| GetLastError() == ERROR_INVALID_HANDLE
/* win9x */,
2078 "wrong error %u\n", GetLastError() );
2079 ok( r
== FALSE
, "should return false\n");
2081 r
= CloseHandle( ov
.hEvent
);
2082 ok( r
== TRUE
, "close handle failed\n");
2085 static void test_RemoveDirectory(void)
2088 char directory
[] = "removeme";
2090 rc
= CreateDirectory(directory
, NULL
);
2091 ok( rc
, "Createdirectory failed, gle=%d\n", GetLastError() );
2093 rc
= SetCurrentDirectory(directory
);
2094 ok( rc
, "SetCurrentDirectory failed, gle=%d\n", GetLastError() );
2096 rc
= RemoveDirectory(".");
2099 rc
= SetCurrentDirectory("..");
2100 ok( rc
, "SetCurrentDirectory failed, gle=%d\n", GetLastError() );
2102 rc
= RemoveDirectory(directory
);
2103 ok( rc
, "RemoveDirectory failed, gle=%d\n", GetLastError() );
2107 static BOOL
check_file_time( const FILETIME
*ft1
, const FILETIME
*ft2
, UINT tolerance
)
2109 ULONGLONG t1
= ((ULONGLONG
)ft1
->dwHighDateTime
<< 32) | ft1
->dwLowDateTime
;
2110 ULONGLONG t2
= ((ULONGLONG
)ft2
->dwHighDateTime
<< 32) | ft2
->dwLowDateTime
;
2111 return abs(t1
- t2
) <= tolerance
;
2114 static void test_ReplaceFileA(void)
2116 char replaced
[MAX_PATH
], replacement
[MAX_PATH
], backup
[MAX_PATH
];
2117 HANDLE hReplacedFile
, hReplacementFile
, hBackupFile
;
2118 static const char replacedData
[] = "file-to-replace";
2119 static const char replacementData
[] = "new-file";
2120 static const char backupData
[] = "backup-file";
2121 FILETIME ftReplaced
, ftReplacement
, ftBackup
;
2122 static const char prefix
[] = "pfx";
2123 char temp_path
[MAX_PATH
];
2129 skip("ReplaceFileA() is missing\n");
2133 ret
= GetTempPathA(MAX_PATH
, temp_path
);
2134 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
2135 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
2137 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replaced
);
2138 ok(ret
!= 0, "GetTempFileNameA error (replaced) %d\n", GetLastError());
2140 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
2141 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
2143 ret
= GetTempFileNameA(temp_path
, prefix
, 0, backup
);
2144 ok(ret
!= 0, "GetTempFileNameA error (backup) %d\n", GetLastError());
2146 /* place predictable data in the file to be replaced */
2147 hReplacedFile
= CreateFileA(replaced
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2148 ok(hReplacedFile
!= INVALID_HANDLE_VALUE
,
2149 "failed to open replaced file\n");
2150 retok
= WriteFile(hReplacedFile
, replacedData
, sizeof(replacedData
), &ret
, NULL
);
2151 ok( retok
&& ret
== sizeof(replacedData
),
2152 "WriteFile error (replaced) %d\n", GetLastError());
2153 ok(GetFileSize(hReplacedFile
, NULL
) == sizeof(replacedData
),
2154 "replaced file has wrong size\n");
2155 /* place predictable data in the file to be the replacement */
2156 hReplacementFile
= CreateFileA(replacement
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2157 ok(hReplacementFile
!= INVALID_HANDLE_VALUE
,
2158 "failed to open replacement file\n");
2159 retok
= WriteFile(hReplacementFile
, replacementData
, sizeof(replacementData
), &ret
, NULL
);
2160 ok( retok
&& ret
== sizeof(replacementData
),
2161 "WriteFile error (replacement) %d\n", GetLastError());
2162 ok(GetFileSize(hReplacementFile
, NULL
) == sizeof(replacementData
),
2163 "replacement file has wrong size\n");
2164 /* place predictable data in the backup file (to be over-written) */
2165 hBackupFile
= CreateFileA(backup
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2166 ok(hBackupFile
!= INVALID_HANDLE_VALUE
,
2167 "failed to open backup file\n");
2168 retok
= WriteFile(hBackupFile
, backupData
, sizeof(backupData
), &ret
, NULL
);
2169 ok( retok
&& ret
== sizeof(backupData
),
2170 "WriteFile error (replacement) %d\n", GetLastError());
2171 ok(GetFileSize(hBackupFile
, NULL
) == sizeof(backupData
),
2172 "backup file has wrong size\n");
2173 /* change the filetime on the "replaced" file to ensure that it changes */
2174 ret
= GetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
);
2175 ok( ret
, "GetFileTime error (replaced) %d\n", GetLastError());
2176 ftReplaced
.dwLowDateTime
-= 600000000; /* 60 second */
2177 ret
= SetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
);
2178 ok( ret
, "SetFileTime error (replaced) %d\n", GetLastError());
2179 GetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
); /* get the actual time back */
2180 CloseHandle(hReplacedFile
);
2181 /* change the filetime on the backup to ensure that it changes */
2182 ret
= GetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
);
2183 ok( ret
, "GetFileTime error (backup) %d\n", GetLastError());
2184 ftBackup
.dwLowDateTime
-= 1200000000; /* 120 second */
2185 ret
= SetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
);
2186 ok( ret
, "SetFileTime error (backup) %d\n", GetLastError());
2187 GetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
); /* get the actual time back */
2188 CloseHandle(hBackupFile
);
2189 /* get the filetime on the replacement file to perform checks */
2190 ret
= GetFileTime(hReplacementFile
, NULL
, NULL
, &ftReplacement
);
2191 ok( ret
, "GetFileTime error (replacement) %d\n", GetLastError());
2192 CloseHandle(hReplacementFile
);
2194 /* perform replacement w/ backup
2195 * TODO: flags are not implemented
2197 SetLastError(0xdeadbeef);
2198 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
2199 ok(ret
, "ReplaceFileA: unexpected error %d\n", GetLastError());
2200 /* make sure that the backup has the size of the old "replaced" file */
2201 hBackupFile
= CreateFileA(backup
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
2202 ok(hBackupFile
!= INVALID_HANDLE_VALUE
,
2203 "failed to open backup file\n");
2204 ret
= GetFileSize(hBackupFile
, NULL
);
2205 ok(ret
== sizeof(replacedData
),
2206 "backup file has wrong size %d\n", ret
);
2207 /* make sure that the "replaced" file has the size of the replacement file */
2208 hReplacedFile
= CreateFileA(replaced
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
2209 ok(hReplacedFile
!= INVALID_HANDLE_VALUE
,
2210 "failed to open replaced file\n");
2211 ret
= GetFileSize(hReplacedFile
, NULL
);
2212 ok(ret
== sizeof(replacementData
),
2213 "replaced file has wrong size %d\n", ret
);
2214 /* make sure that the replacement file no-longer exists */
2215 hReplacementFile
= CreateFileA(replacement
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
2216 ok(hReplacementFile
== INVALID_HANDLE_VALUE
,
2217 "unexpected error, replacement file should not exist %d\n", GetLastError());
2218 /* make sure that the backup has the old "replaced" filetime */
2219 ret
= GetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
);
2220 ok( ret
, "GetFileTime error (backup %d\n", GetLastError());
2221 ok(check_file_time(&ftBackup
, &ftReplaced
, 20000000), "backup file has wrong filetime\n");
2222 CloseHandle(hBackupFile
);
2223 /* make sure that the "replaced" has the old replacement filetime */
2224 ret
= GetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
);
2225 ok( ret
, "GetFileTime error (backup %d\n", GetLastError());
2226 ok(check_file_time(&ftReplaced
, &ftReplacement
, 20000000),
2227 "replaced file has wrong filetime %x%08x / %x%08x\n",
2228 ftReplaced
.dwHighDateTime
, ftReplaced
.dwLowDateTime
,
2229 ftReplacement
.dwHighDateTime
, ftReplacement
.dwLowDateTime
);
2230 CloseHandle(hReplacedFile
);
2232 /* re-create replacement file for pass w/o backup (blank) */
2233 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
2234 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
2235 /* perform replacement w/o backup
2236 * TODO: flags are not implemented
2238 SetLastError(0xdeadbeef);
2239 ret
= pReplaceFileA(replaced
, replacement
, NULL
, 0, 0, 0);
2240 ok(ret
, "ReplaceFileA: unexpected error %d\n", GetLastError());
2242 /* re-create replacement file for pass w/ backup (backup-file not existing) */
2243 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
2244 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
2245 ret
= DeleteFileA(backup
);
2246 ok(ret
, "DeleteFileA: error (backup) %d\n", GetLastError());
2247 /* perform replacement w/ backup (no pre-existing backup)
2248 * TODO: flags are not implemented
2250 SetLastError(0xdeadbeef);
2251 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
2252 ok(ret
, "ReplaceFileA: unexpected error %d\n", GetLastError());
2254 /* re-create replacement file for pass w/ no permissions to "replaced" */
2255 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
2256 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
2257 ret
= SetFileAttributesA(replaced
, FILE_ATTRIBUTE_READONLY
);
2258 ok(ret
, "SetFileAttributesA: error setting to read only %d\n", GetLastError());
2259 /* perform replacement w/ backup (no permission to "replaced")
2260 * TODO: flags are not implemented
2262 SetLastError(0xdeadbeef);
2263 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
2264 ok(ret
!= ERROR_UNABLE_TO_REMOVE_REPLACED
, "ReplaceFileA: unexpected error %d\n", GetLastError());
2265 /* make sure that the replacement file still exists */
2266 hReplacementFile
= CreateFileA(replacement
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
2267 ok(hReplacementFile
!= INVALID_HANDLE_VALUE
||
2268 broken(GetLastError() == ERROR_FILE_NOT_FOUND
), /* win2k */
2269 "unexpected error, replacement file should still exist %d\n", GetLastError());
2270 CloseHandle(hReplacementFile
);
2271 ret
= SetFileAttributesA(replaced
, FILE_ATTRIBUTE_NORMAL
);
2272 ok(ret
, "SetFileAttributesA: error setting to normal %d\n", GetLastError());
2274 /* replacement file still exists, make pass w/o "replaced" */
2275 ret
= DeleteFileA(replaced
);
2276 ok(ret
, "DeleteFileA: error (replaced) %d\n", GetLastError());
2277 /* perform replacement w/ backup (no pre-existing backup or "replaced")
2278 * TODO: flags are not implemented
2280 SetLastError(0xdeadbeef);
2281 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
2282 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
2283 "ReplaceFileA: unexpected error %d\n", GetLastError());
2285 /* perform replacement w/o existing "replacement" file
2286 * TODO: flags are not implemented
2288 SetLastError(0xdeadbeef);
2289 ret
= pReplaceFileA(replaced
, replacement
, NULL
, 0, 0, 0);
2290 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
2291 "ReplaceFileA: unexpected error %d\n", GetLastError());
2294 * if the first round (w/ backup) worked then as long as there is no
2295 * failure then there is no need to check this round (w/ backup is the
2296 * more complete case)
2299 /* delete temporary files, replacement and replaced are already deleted */
2300 ret
= DeleteFileA(backup
);
2302 broken(GetLastError() == ERROR_ACCESS_DENIED
), /* win2k */
2303 "DeleteFileA: error (backup) %d\n", GetLastError());
2307 * ReplaceFileW is a simpler case of ReplaceFileA, there is no
2308 * need to be as thorough.
2310 static void test_ReplaceFileW(void)
2312 WCHAR replaced
[MAX_PATH
], replacement
[MAX_PATH
], backup
[MAX_PATH
];
2313 static const WCHAR prefix
[] = {'p','f','x',0};
2314 WCHAR temp_path
[MAX_PATH
];
2319 skip("ReplaceFileW() is missing\n");
2323 ret
= GetTempPathW(MAX_PATH
, temp_path
);
2324 if (ret
==0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
2326 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
2327 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
2329 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replaced
);
2330 ok(ret
!= 0, "GetTempFileNameW error (replaced) %d\n", GetLastError());
2332 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
2333 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
2335 ret
= GetTempFileNameW(temp_path
, prefix
, 0, backup
);
2336 ok(ret
!= 0, "GetTempFileNameW error (backup) %d\n", GetLastError());
2338 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
2339 ok(ret
, "ReplaceFileW: error %d\n", GetLastError());
2341 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
2342 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
2343 ret
= pReplaceFileW(replaced
, replacement
, NULL
, 0, 0, 0);
2344 ok(ret
, "ReplaceFileW: error %d\n", GetLastError());
2346 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
2347 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
2348 ret
= DeleteFileW(backup
);
2349 ok(ret
, "DeleteFileW: error (backup) %d\n", GetLastError());
2350 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
2351 ok(ret
, "ReplaceFileW: error %d\n", GetLastError());
2353 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
2354 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
2355 ret
= SetFileAttributesW(replaced
, FILE_ATTRIBUTE_READONLY
);
2356 ok(ret
, "SetFileAttributesW: error setting to read only %d\n", GetLastError());
2358 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
2359 ok(ret
!= ERROR_UNABLE_TO_REMOVE_REPLACED
,
2360 "ReplaceFileW: unexpected error %d\n", GetLastError());
2361 ret
= SetFileAttributesW(replaced
, FILE_ATTRIBUTE_NORMAL
);
2362 ok(ret
, "SetFileAttributesW: error setting to normal %d\n", GetLastError());
2364 ret
= DeleteFileW(replaced
);
2365 ok(ret
, "DeleteFileW: error (replaced) %d\n", GetLastError());
2366 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
2367 ok(!ret
, "ReplaceFileW: error %d\n", GetLastError());
2369 ret
= pReplaceFileW(replaced
, replacement
, NULL
, 0, 0, 0);
2370 ok(!ret
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
2371 "ReplaceFileW: unexpected error %d\n", GetLastError());
2373 ret
= DeleteFileW(backup
);
2375 broken(GetLastError() == ERROR_ACCESS_DENIED
), /* win2k */
2376 "DeleteFileW: error (backup) %d\n", GetLastError());
2381 InitFunctionPointers();
2391 test_GetTempFileNameA();
2400 test_FindFirstFileA();
2401 test_FindNextFileA();
2402 test_FindFirstFileExA();
2404 test_file_sharing();
2405 test_offset_in_overlapped_structure();
2408 test_async_file_errors();
2412 test_RemoveDirectory();
2413 test_ReplaceFileA();
2414 test_ReplaceFileW();