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
31 #include "wine/test.h"
36 static HANDLE (WINAPI
*pFindFirstFileExA
)(LPCSTR
,FINDEX_INFO_LEVELS
,LPVOID
,FINDEX_SEARCH_OPS
,LPVOID
,DWORD
);
37 static BOOL (WINAPI
*pReplaceFileA
)(LPCSTR
, LPCSTR
, LPCSTR
, DWORD
, LPVOID
, LPVOID
);
38 static BOOL (WINAPI
*pReplaceFileW
)(LPCWSTR
, LPCWSTR
, LPCWSTR
, DWORD
, LPVOID
, LPVOID
);
39 static UINT (WINAPI
*pGetSystemWindowsDirectoryA
)(LPSTR
, UINT
);
40 static BOOL (WINAPI
*pGetVolumeNameForVolumeMountPointA
)(LPCSTR
, LPSTR
, DWORD
);
41 static DWORD (WINAPI
*pQueueUserAPC
)(PAPCFUNC pfnAPC
, HANDLE hThread
, ULONG_PTR dwData
);
43 /* keep filename and filenameW the same */
44 static const char filename
[] = "testfile.xxx";
45 static const WCHAR filenameW
[] = { 't','e','s','t','f','i','l','e','.','x','x','x',0 };
46 static const char sillytext
[] =
47 "en larvig liten text dx \033 gx hej 84 hej 4484 ! \001\033 bla bl\na.. bla bla."
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 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
54 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
55 "1234 43 4kljf lf &%%%&&&&&& 34 4 34 3############# 33 3 3 3 # 3## 3"
56 "sdlkfjasdlkfj a dslkj adsklf \n \nasdklf askldfa sdlkf \nsadklf asdklf asdf ";
59 const char *file
; /* file string to test */
60 const DWORD err
; /* Win NT and further error code */
61 const LONG err2
; /* Win 9x & ME error code or -1 */
62 const DWORD options
; /* option flag to use for open */
63 const BOOL todo_flag
; /* todo_wine indicator */
66 static void InitFunctionPointers(void)
68 HMODULE hkernel32
= GetModuleHandleA("kernel32");
70 pFindFirstFileExA
=(void*)GetProcAddress(hkernel32
, "FindFirstFileExA");
71 pReplaceFileA
=(void*)GetProcAddress(hkernel32
, "ReplaceFileA");
72 pReplaceFileW
=(void*)GetProcAddress(hkernel32
, "ReplaceFileW");
73 pGetSystemWindowsDirectoryA
=(void*)GetProcAddress(hkernel32
, "GetSystemWindowsDirectoryA");
74 pGetVolumeNameForVolumeMountPointA
= (void *) GetProcAddress(hkernel32
, "GetVolumeNameForVolumeMountPointA");
75 pQueueUserAPC
= (void *) GetProcAddress(hkernel32
, "QueueUserAPC");
78 static void test__hread( void )
87 SetFileAttributesA(filename
,FILE_ATTRIBUTE_NORMAL
); /* be sure to remove stale files */
88 DeleteFileA( filename
);
89 filehandle
= _lcreat( filename
, 0 );
90 if (filehandle
== HFILE_ERROR
)
92 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
96 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
98 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
100 filehandle
= _lopen( filename
, OF_READ
);
102 ok( HFILE_ERROR
!= filehandle
, "couldn't open file \"%s\" again (err=%d)\n", filename
, GetLastError( ) );
104 bytes_read
= _hread( filehandle
, buffer
, 2 * strlen( sillytext
) );
106 ok( lstrlenA( sillytext
) == bytes_read
, "file read size error\n" );
108 for (bytes_wanted
= 0; bytes_wanted
< lstrlenA( sillytext
); bytes_wanted
++)
110 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
111 ok( _hread( filehandle
, buffer
, bytes_wanted
) == bytes_wanted
, "erratic _hread return value\n" );
112 for (i
= 0; i
< bytes_wanted
; i
++)
114 ok( buffer
[i
] == sillytext
[i
], "that's not what's written\n" );
118 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
120 ret
= DeleteFileA( filename
);
121 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError( ) );
125 static void test__hwrite( void )
134 HLOCAL memory_object
;
138 filehandle
= _lcreat( filename
, 0 );
139 if (filehandle
== HFILE_ERROR
)
141 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
145 ok( HFILE_ERROR
!= _hwrite( filehandle
, "", 0 ), "_hwrite complains\n" );
147 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
149 filehandle
= _lopen( filename
, OF_READ
);
151 bytes_read
= _hread( filehandle
, buffer
, 1);
153 ok( 0 == bytes_read
, "file read size error\n" );
155 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
157 filehandle
= _lopen( filename
, OF_READWRITE
);
161 srand( (unsigned)time( NULL
) );
162 for (blocks
= 0; blocks
< 100; blocks
++)
164 for (i
= 0; i
< (LONG
)sizeof( buffer
); i
++)
167 checksum
[0] = checksum
[0] + buffer
[i
];
169 ok( HFILE_ERROR
!= _hwrite( filehandle
, buffer
, sizeof( buffer
) ), "_hwrite complains\n" );
170 bytes_written
= bytes_written
+ sizeof( buffer
);
173 ok( HFILE_ERROR
!= _hwrite( filehandle
, checksum
, 1 ), "_hwrite complains\n" );
176 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
178 memory_object
= LocalAlloc( LPTR
, bytes_written
);
180 ok( 0 != memory_object
, "LocalAlloc fails. (Could be out of memory.)\n" );
182 contents
= LocalLock( memory_object
);
183 ok( NULL
!= contents
, "LocalLock whines\n" );
185 filehandle
= _lopen( filename
, OF_READ
);
187 contents
= LocalLock( memory_object
);
188 ok( NULL
!= contents
, "LocalLock whines\n" );
190 ok( bytes_written
== _hread( filehandle
, contents
, bytes_written
), "read length differ from write length\n" );
196 checksum
[0] = checksum
[0] + contents
[i
];
199 while (i
< bytes_written
- 1);
201 ok( checksum
[0] == contents
[i
], "stored checksum differ from computed checksum\n" );
203 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
205 ret
= DeleteFileA( filename
);
206 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError( ) );
208 LocalFree( contents
);
212 static void test__lclose( void )
217 filehandle
= _lcreat( filename
, 0 );
218 if (filehandle
== HFILE_ERROR
)
220 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
224 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
226 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
228 ret
= DeleteFileA( filename
);
229 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError( ) );
233 static void test__lcreat( void )
237 WIN32_FIND_DATAA search_results
;
238 char slashname
[] = "testfi/";
243 filehandle
= _lcreat( filename
, 0 );
244 if (filehandle
== HFILE_ERROR
)
246 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
250 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
252 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
254 ok( _hread( filehandle
, buffer
, strlen( sillytext
) ) == lstrlenA( sillytext
), "erratic _hread return value\n" );
256 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
258 find
= FindFirstFileA( filename
, &search_results
);
259 ok( INVALID_HANDLE_VALUE
!= find
, "should be able to find file\n" );
262 ret
= DeleteFileA(filename
);
263 ok( ret
!= 0, "DeleteFile failed (%d)\n", GetLastError());
265 filehandle
= _lcreat( filename
, 1 ); /* readonly */
266 ok( HFILE_ERROR
!= filehandle
, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError( ) );
268 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite shouldn't be able to write never the less\n" );
270 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
272 find
= FindFirstFileA( filename
, &search_results
);
273 ok( INVALID_HANDLE_VALUE
!= find
, "should be able to find file\n" );
276 ok( 0 == DeleteFileA( filename
), "shouldn't be able to delete a readonly file\n" );
278 ok( SetFileAttributesA(filename
, FILE_ATTRIBUTE_NORMAL
) != 0, "couldn't change attributes on file\n" );
280 ok( DeleteFileA( filename
) != 0, "now it should be possible to delete the file!\n" );
282 filehandle
= _lcreat( filename
, 2 );
283 ok( HFILE_ERROR
!= filehandle
, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError( ) );
285 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
287 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
289 ok( _hread( filehandle
, buffer
, strlen( sillytext
) ) == lstrlenA( sillytext
), "erratic _hread return value\n" );
291 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
293 find
= FindFirstFileA( filename
, &search_results
);
294 ok( INVALID_HANDLE_VALUE
!= find
, "should STILL be able to find file\n" );
297 ret
= DeleteFileA( filename
);
298 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
300 filehandle
= _lcreat( filename
, 4 ); /* SYSTEM file */
301 ok( HFILE_ERROR
!= filehandle
, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError( ) );
303 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
305 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
307 ok( _hread( filehandle
, buffer
, strlen( sillytext
) ) == lstrlenA( sillytext
), "erratic _hread return value\n" );
309 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
311 find
= FindFirstFileA( filename
, &search_results
);
312 ok( INVALID_HANDLE_VALUE
!= find
, "should STILL be able to find file\n" );
315 ret
= DeleteFileA( filename
);
316 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
318 filehandle
=_lcreat (slashname
, 0); /* illegal name */
319 if (HFILE_ERROR
==filehandle
) {
321 ok (err
==ERROR_INVALID_NAME
|| err
==ERROR_PATH_NOT_FOUND
,
322 "creating file \"%s\" failed with error %d\n", slashname
, err
);
323 } else { /* only NT succeeds */
325 find
=FindFirstFileA (slashname
, &search_results
);
326 if (INVALID_HANDLE_VALUE
!=find
)
328 ret
= FindClose (find
);
329 ok (0 != ret
, "FindClose complains (%d)\n", GetLastError ());
330 slashname
[strlen(slashname
)-1]=0;
331 ok (!strcmp (slashname
, search_results
.cFileName
),
332 "found unexpected name \"%s\"\n", search_results
.cFileName
);
333 ok (FILE_ATTRIBUTE_ARCHIVE
==search_results
.dwFileAttributes
,
334 "attributes of file \"%s\" are 0x%04x\n", search_results
.cFileName
,
335 search_results
.dwFileAttributes
);
337 ret
= DeleteFileA( slashname
);
338 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
341 filehandle
=_lcreat (filename
, 8); /* illegal attribute */
342 if (HFILE_ERROR
==filehandle
)
343 ok (0, "couldn't create volume label \"%s\"\n", filename
);
346 find
=FindFirstFileA (filename
, &search_results
);
347 if (INVALID_HANDLE_VALUE
==find
)
348 ok (0, "file \"%s\" not found\n", filename
);
350 ret
= FindClose(find
);
351 ok ( 0 != ret
, "FindClose complains (%d)\n", GetLastError ());
352 ok (!strcmp (filename
, search_results
.cFileName
),
353 "found unexpected name \"%s\"\n", search_results
.cFileName
);
354 search_results
.dwFileAttributes
&= ~FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
;
355 ok (FILE_ATTRIBUTE_ARCHIVE
==search_results
.dwFileAttributes
,
356 "attributes of file \"%s\" are 0x%04x\n", search_results
.cFileName
,
357 search_results
.dwFileAttributes
);
359 ret
= DeleteFileA( filename
);
360 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
365 static void test__llseek( void )
373 filehandle
= _lcreat( filename
, 0 );
374 if (filehandle
== HFILE_ERROR
)
376 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
380 for (i
= 0; i
< 400; i
++)
382 ok( _hwrite( filehandle
, sillytext
, strlen( sillytext
) ) != -1, "_hwrite complains\n" );
384 ok( _llseek( filehandle
, 400 * strlen( sillytext
), FILE_CURRENT
) != -1, "should be able to seek\n" );
385 ok( _llseek( filehandle
, 27 + 35 * strlen( sillytext
), FILE_BEGIN
) != -1, "should be able to seek\n" );
387 bytes_read
= _hread( filehandle
, buffer
, 1);
388 ok( 1 == bytes_read
, "file read size error\n" );
389 ok( buffer
[0] == sillytext
[27], "_llseek error, it got lost seeking\n" );
390 ok( _llseek( filehandle
, -400 * (LONG
)strlen( sillytext
), FILE_END
) != -1, "should be able to seek\n" );
392 bytes_read
= _hread( filehandle
, buffer
, 1);
393 ok( 1 == bytes_read
, "file read size error\n" );
394 ok( buffer
[0] == sillytext
[0], "_llseek error, it got lost seeking\n" );
395 ok( _llseek( filehandle
, 1000000, FILE_END
) != -1, "should be able to seek past file; poor, poor Windows programmers\n" );
396 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
398 ret
= DeleteFileA( filename
);
399 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
403 static void test__llopen( void )
410 filehandle
= _lcreat( filename
, 0 );
411 if (filehandle
== HFILE_ERROR
)
413 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
417 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
418 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
420 filehandle
= _lopen( filename
, OF_READ
);
421 ok( HFILE_ERROR
== _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite shouldn't be able to write!\n" );
422 bytes_read
= _hread( filehandle
, buffer
, strlen( sillytext
) );
423 ok( strlen( sillytext
) == bytes_read
, "file read size error\n" );
424 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
426 filehandle
= _lopen( filename
, OF_READWRITE
);
427 bytes_read
= _hread( filehandle
, buffer
, 2 * strlen( sillytext
) );
428 ok( strlen( sillytext
) == bytes_read
, "file read size error\n" );
429 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite should write just fine\n" );
430 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
432 filehandle
= _lopen( filename
, OF_WRITE
);
433 ok( HFILE_ERROR
== _hread( filehandle
, buffer
, 1 ), "you should only be able to write this file\n" );
434 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite should write just fine\n" );
435 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
437 ret
= DeleteFileA( filename
);
438 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
439 /* TODO - add tests for the SHARE modes - use two processes to pull this one off */
443 static void test__lread( void )
452 filehandle
= _lcreat( filename
, 0 );
453 if (filehandle
== HFILE_ERROR
)
455 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
459 ok( HFILE_ERROR
!= _hwrite( filehandle
, sillytext
, strlen( sillytext
) ), "_hwrite complains\n" );
461 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
463 filehandle
= _lopen( filename
, OF_READ
);
465 ok( HFILE_ERROR
!= filehandle
, "couldn't open file \"%s\" again (err=%d)\n", filename
, GetLastError());
467 bytes_read
= _lread( filehandle
, buffer
, 2 * strlen( sillytext
) );
469 ok( lstrlenA( sillytext
) == bytes_read
, "file read size error\n" );
471 for (bytes_wanted
= 0; bytes_wanted
< strlen( sillytext
); bytes_wanted
++)
473 ok( 0 == _llseek( filehandle
, 0, FILE_BEGIN
), "_llseek complains\n" );
474 ok( _lread( filehandle
, buffer
, bytes_wanted
) == bytes_wanted
, "erratic _hread return value\n" );
475 for (i
= 0; i
< bytes_wanted
; i
++)
477 ok( buffer
[i
] == sillytext
[i
], "that's not what's written\n" );
481 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
483 ret
= DeleteFileA( filename
);
484 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
488 static void test__lwrite( void )
497 HLOCAL memory_object
;
501 filehandle
= _lcreat( filename
, 0 );
502 if (filehandle
== HFILE_ERROR
)
504 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
508 ok( HFILE_ERROR
!= _lwrite( filehandle
, "", 0 ), "_hwrite complains\n" );
510 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
512 filehandle
= _lopen( filename
, OF_READ
);
514 bytes_read
= _hread( filehandle
, buffer
, 1);
516 ok( 0 == bytes_read
, "file read size error\n" );
518 ok( HFILE_ERROR
!= _lclose(filehandle
), "_lclose complains\n" );
520 filehandle
= _lopen( filename
, OF_READWRITE
);
524 srand( (unsigned)time( NULL
) );
525 for (blocks
= 0; blocks
< 100; blocks
++)
527 for (i
= 0; i
< (INT
)sizeof( buffer
); i
++)
530 checksum
[0] = checksum
[0] + buffer
[i
];
532 ok( HFILE_ERROR
!= _lwrite( filehandle
, buffer
, sizeof( buffer
) ), "_hwrite complains\n" );
533 bytes_written
= bytes_written
+ sizeof( buffer
);
536 ok( HFILE_ERROR
!= _lwrite( filehandle
, checksum
, 1 ), "_hwrite complains\n" );
539 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
541 memory_object
= LocalAlloc( LPTR
, bytes_written
);
543 ok( 0 != memory_object
, "LocalAlloc fails, could be out of memory\n" );
545 contents
= LocalLock( memory_object
);
546 ok( NULL
!= contents
, "LocalLock whines\n" );
548 filehandle
= _lopen( filename
, OF_READ
);
550 contents
= LocalLock( memory_object
);
551 ok( NULL
!= contents
, "LocalLock whines\n" );
553 ok( bytes_written
== _hread( filehandle
, contents
, bytes_written
), "read length differ from write length\n" );
559 checksum
[0] += contents
[i
];
562 while (i
< bytes_written
- 1);
564 ok( checksum
[0] == contents
[i
], "stored checksum differ from computed checksum\n" );
566 ok( HFILE_ERROR
!= _lclose( filehandle
), "_lclose complains\n" );
568 ret
= DeleteFileA( filename
);
569 ok( ret
, "DeleteFile failed (%d)\n", GetLastError( ) );
571 LocalFree( contents
);
574 static void test_CopyFileA(void)
576 char temp_path
[MAX_PATH
];
577 char source
[MAX_PATH
], dest
[MAX_PATH
];
578 static const char prefix
[] = "pfx";
586 ret
= GetTempPathA(MAX_PATH
, temp_path
);
587 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
588 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
590 ret
= GetTempFileNameA(temp_path
, prefix
, 0, source
);
591 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
593 ret
= MoveFileA(source
, source
);
594 todo_wine
ok(ret
, "MoveFileA: failed, error %d\n", GetLastError());
596 /* copying a file to itself must fail */
597 retok
= CopyFileA(source
, source
, FALSE
);
598 ok( !retok
&& (GetLastError() == ERROR_SHARING_VIOLATION
|| broken(GetLastError() == ERROR_FILE_EXISTS
) /* Win 9x */),
599 "copying a file to itself didn't fail (ret=%d, err=%d)\n", retok
, GetLastError());
601 /* make the source have not zero size */
602 hfile
= CreateFileA(source
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
603 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open source file\n");
604 retok
= WriteFile(hfile
, prefix
, sizeof(prefix
), &ret
, NULL
);
605 ok( retok
&& ret
== sizeof(prefix
),
606 "WriteFile error %d\n", GetLastError());
607 ok(GetFileSize(hfile
, NULL
) == sizeof(prefix
), "source file has wrong size\n");
608 /* get the file time and change it to prove the difference */
609 ret
= GetFileTime(hfile
, NULL
, NULL
, &ft1
);
610 ok( ret
, "GetFileTime error %d\n", GetLastError());
611 ft1
.dwLowDateTime
-= 600000000; /* 60 second */
612 ret
= SetFileTime(hfile
, NULL
, NULL
, &ft1
);
613 ok( ret
, "SetFileTime error %d\n", GetLastError());
614 GetFileTime(hfile
, NULL
, NULL
, &ft1
); /* get the actual time back */
617 ret
= GetTempFileNameA(temp_path
, prefix
, 0, dest
);
618 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
620 SetLastError(0xdeadbeef);
621 ret
= CopyFileA(source
, dest
, TRUE
);
622 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
623 "CopyFileA: unexpected error %d\n", GetLastError());
625 ret
= CopyFileA(source
, dest
, FALSE
);
626 ok(ret
, "CopyFileA: error %d\n", GetLastError());
628 /* copying from a read-locked source fails */
629 hfile
= CreateFileA(source
, GENERIC_READ
, FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0);
630 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open source file, error %d\n", GetLastError());
631 retok
= CopyFileA(source
, dest
, FALSE
);
632 ok(!retok
&& GetLastError() == ERROR_SHARING_VIOLATION
,
633 "copying from a read-locked file succeeded when it shouldn't have\n");
634 /* in addition, the source is opened before the destination */
635 retok
= CopyFileA("25f99d3b-4ba4-4f66-88f5-2906886993cc", dest
, FALSE
);
636 ok(!retok
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
637 "copying from a file that doesn't exist failed in an unexpected way (ret=%d, err=%d)\n", retok
, GetLastError());
640 /* copying from a r+w opened, r shared source succeeds */
641 hfile
= CreateFileA(source
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
642 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open source file, error %d\n", GetLastError());
643 retok
= CopyFileA(source
, dest
, FALSE
);
645 "copying from an r+w opened and r shared file failed (ret=%d, err=%d)\n", retok
, GetLastError());
648 /* copying from a delete-locked source is unreliable */
649 hfile
= CreateFileA(source
, DELETE
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
650 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open source file, error %d\n", GetLastError());
651 retok
= CopyFileA(source
, dest
, FALSE
);
652 ok((!retok
&& GetLastError() == ERROR_SHARING_VIOLATION
) || broken(retok
) /* 98, Vista, 2k8, 7 */,
653 "copying from a delete-locked file failed (ret=%d, err=%d)\n", retok
, GetLastError());
656 /* copying to a write-locked destination fails */
657 hfile
= CreateFileA(dest
, GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
658 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open destination file, error %d\n", GetLastError());
659 retok
= CopyFileA(source
, dest
, FALSE
);
660 ok(!retok
&& GetLastError() == ERROR_SHARING_VIOLATION
,
661 "copying to a write-locked file didn't fail (ret=%d, err=%d)\n", retok
, GetLastError());
664 /* copying to a r+w opened, w shared destination mostly succeeds */
665 hfile
= CreateFileA(dest
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0);
666 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open destination file, error %d\n", GetLastError());
667 retok
= CopyFileA(source
, dest
, FALSE
);
668 ok(retok
|| broken(!retok
&& GetLastError() == ERROR_SHARING_VIOLATION
) /* Win 9x */,
669 "copying to a r+w opened and w shared file failed (ret=%d, err=%d)\n", retok
, GetLastError());
672 /* copying to a delete-locked destination fails, even when the destination is delete-shared */
673 hfile
= CreateFileA(dest
, DELETE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, NULL
, OPEN_EXISTING
, 0, 0);
674 ok(hfile
!= INVALID_HANDLE_VALUE
|| broken(GetLastError() == ERROR_INVALID_PARAMETER
) /* Win 9x */,
675 "failed to open destination file, error %d\n", GetLastError());
676 if (hfile
!= INVALID_HANDLE_VALUE
)
678 retok
= CopyFileA(source
, dest
, FALSE
);
679 ok(!retok
&& GetLastError() == ERROR_SHARING_VIOLATION
,
680 "copying to a delete-locked shared file didn't fail (ret=%d, err=%d)\n", retok
, GetLastError());
684 /* copy to a file that's opened the way Wine opens the source */
685 hfile
= CreateFileA(dest
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0);
686 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open destination file, error %d\n", GetLastError());
687 retok
= CopyFileA(source
, dest
, FALSE
);
688 ok(retok
|| broken(GetLastError() == ERROR_SHARING_VIOLATION
) /* Win 9x */,
689 "copying to a file opened the way Wine opens the source failed (ret=%d, err=%d)\n", retok
, GetLastError());
692 /* make sure that destination has correct size */
693 hfile
= CreateFileA(dest
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
694 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open destination file\n");
695 ret
= GetFileSize(hfile
, NULL
);
696 ok(ret
== sizeof(prefix
), "destination file has wrong size %d\n", ret
);
698 /* make sure that destination has the same filetime */
699 ret
= GetFileTime(hfile
, NULL
, NULL
, &ft2
);
700 ok( ret
, "GetFileTime error %d\n", GetLastError());
701 ok(CompareFileTime(&ft1
, &ft2
) == 0, "destination file has wrong filetime\n");
703 SetLastError(0xdeadbeef);
704 ret
= CopyFileA(source
, dest
, FALSE
);
705 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
,
706 "CopyFileA: ret = %d, unexpected error %d\n", ret
, GetLastError());
708 /* make sure that destination still has correct size */
709 ret
= GetFileSize(hfile
, NULL
);
710 ok(ret
== sizeof(prefix
), "destination file has wrong size %d\n", ret
);
711 retok
= ReadFile(hfile
, buf
, sizeof(buf
), &ret
, NULL
);
712 ok( retok
&& ret
== sizeof(prefix
),
713 "ReadFile: error %d\n", GetLastError());
714 ok(!memcmp(prefix
, buf
, sizeof(prefix
)), "buffer contents mismatch\n");
716 /* check error on copying over a mapped file that was opened with FILE_SHARE_READ */
717 hmapfile
= CreateFileMapping(hfile
, NULL
, PAGE_READONLY
| SEC_COMMIT
, 0, 0, NULL
);
718 ok(hmapfile
!= NULL
, "CreateFileMapping: error %d\n", GetLastError());
720 ret
= CopyFileA(source
, dest
, FALSE
);
721 ok(!ret
&& GetLastError() == ERROR_SHARING_VIOLATION
,
722 "CopyFileA with mapped dest file: expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
724 CloseHandle(hmapfile
);
727 hfile
= CreateFileA(dest
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0);
728 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open destination file\n");
730 /* check error on copying over a mapped file that was opened with FILE_SHARE_WRITE */
731 hmapfile
= CreateFileMapping(hfile
, NULL
, PAGE_READONLY
| SEC_COMMIT
, 0, 0, NULL
);
732 ok(hmapfile
!= NULL
, "CreateFileMapping: error %d\n", GetLastError());
734 ret
= CopyFileA(source
, dest
, FALSE
);
735 ok(!ret
, "CopyFileA: expected failure\n");
736 ok(GetLastError() == ERROR_USER_MAPPED_FILE
||
737 broken(GetLastError() == ERROR_SHARING_VIOLATION
), /* Win9x */
738 "CopyFileA with mapped dest file: expected ERROR_USER_MAPPED_FILE, got %d\n", GetLastError());
740 CloseHandle(hmapfile
);
743 ret
= DeleteFileA(source
);
744 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
745 ret
= DeleteFileA(dest
);
746 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
749 static void test_CopyFileW(void)
751 WCHAR temp_path
[MAX_PATH
];
752 WCHAR source
[MAX_PATH
], dest
[MAX_PATH
];
753 static const WCHAR prefix
[] = {'p','f','x',0};
756 ret
= GetTempPathW(MAX_PATH
, temp_path
);
757 if (ret
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
759 win_skip("GetTempPathW is not available\n");
762 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
763 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
765 ret
= GetTempFileNameW(temp_path
, prefix
, 0, source
);
766 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
768 ret
= GetTempFileNameW(temp_path
, prefix
, 0, dest
);
769 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
771 ret
= CopyFileW(source
, dest
, TRUE
);
772 ok(!ret
&& GetLastError() == ERROR_FILE_EXISTS
,
773 "CopyFileW: unexpected error %d\n", GetLastError());
775 ret
= CopyFileW(source
, dest
, FALSE
);
776 ok(ret
, "CopyFileW: error %d\n", GetLastError());
778 ret
= DeleteFileW(source
);
779 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
780 ret
= DeleteFileW(dest
);
781 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
786 * Debugging routine to dump a buffer in a hexdump-like fashion.
788 static void dumpmem(unsigned char *mem
, int len
)
799 p
+= sprintf(p
, "%02x ", mem
[x
]);
800 *c
++ = (mem
[x
] >= 32 && mem
[x
] <= 127) ? mem
[x
] : '.';
801 } while (++x
% 16 && x
< len
);
803 trace("%04x: %-48s- %s\n", x
, hex
, txt
);
807 static void test_CreateFileA(void)
810 char temp_path
[MAX_PATH
], dirname
[MAX_PATH
];
811 char filename
[MAX_PATH
];
812 static const char prefix
[] = "pfx";
813 char windowsdir
[MAX_PATH
];
814 char Volume_1
[MAX_PATH
];
815 unsigned char buffer
[512];
816 char directory
[] = "removeme";
817 static const char nt_drive
[] = "\\\\?\\A:";
819 struct test_list p
[] = {
820 {"", ERROR_PATH_NOT_FOUND
, -1, FILE_ATTRIBUTE_NORMAL
, TRUE
}, /* dir as file w \ */
821 {"", ERROR_SUCCESS
, ERROR_PATH_NOT_FOUND
, FILE_FLAG_BACKUP_SEMANTICS
, FALSE
}, /* dir as dir w \ */
822 {"a", ERROR_FILE_NOT_FOUND
, -1, FILE_ATTRIBUTE_NORMAL
, FALSE
}, /* non-exist file */
823 {"a\\", ERROR_FILE_NOT_FOUND
, ERROR_PATH_NOT_FOUND
, FILE_ATTRIBUTE_NORMAL
, FALSE
}, /* non-exist dir */
824 {"removeme", ERROR_ACCESS_DENIED
, -1, FILE_ATTRIBUTE_NORMAL
, FALSE
}, /* exist dir w/o \ */
825 {"removeme\\", ERROR_PATH_NOT_FOUND
, -1, FILE_ATTRIBUTE_NORMAL
, TRUE
}, /* exst dir w \ */
826 {"c:", ERROR_ACCESS_DENIED
, ERROR_PATH_NOT_FOUND
, FILE_ATTRIBUTE_NORMAL
, FALSE
}, /* device in file namespace */
827 {"c:", ERROR_SUCCESS
, ERROR_PATH_NOT_FOUND
, FILE_FLAG_BACKUP_SEMANTICS
, FALSE
}, /* device in file namespace as dir */
828 {"c:\\", ERROR_PATH_NOT_FOUND
, ERROR_ACCESS_DENIED
, FILE_ATTRIBUTE_NORMAL
, TRUE
}, /* root dir w \ */
829 {"c:\\", ERROR_SUCCESS
, ERROR_ACCESS_DENIED
, FILE_FLAG_BACKUP_SEMANTICS
, FALSE
}, /* root dir w \ as dir */
830 {"\\\\?\\c:", ERROR_SUCCESS
, ERROR_BAD_NETPATH
, FILE_ATTRIBUTE_NORMAL
,FALSE
}, /* dev namespace drive */
831 {"\\\\?\\c:\\", ERROR_PATH_NOT_FOUND
, ERROR_BAD_NETPATH
, FILE_ATTRIBUTE_NORMAL
, TRUE
}, /* dev namespace drive w \ */
832 {NULL
, 0, -1, 0, FALSE
}
834 BY_HANDLE_FILE_INFORMATION Finfo
;
836 ret
= GetTempPathA(MAX_PATH
, temp_path
);
837 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
838 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
840 ret
= GetTempFileNameA(temp_path
, prefix
, 0, filename
);
841 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
843 SetLastError(0xdeadbeef);
844 hFile
= CreateFileA(filename
, GENERIC_READ
, 0, NULL
,
845 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
846 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_EXISTS
,
847 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
849 SetLastError(0xdeadbeef);
850 hFile
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
851 CREATE_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
852 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
853 "hFile %p, last error %u\n", hFile
, GetLastError());
857 SetLastError(0xdeadbeef);
858 hFile
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
859 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
860 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
861 "hFile %p, last error %u\n", hFile
, GetLastError());
865 ret
= DeleteFileA(filename
);
866 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
868 SetLastError(0xdeadbeef);
869 hFile
= CreateFileA(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
870 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
871 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == 0,
872 "hFile %p, last error %u\n", hFile
, GetLastError());
876 ret
= DeleteFileA(filename
);
877 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
879 SetLastError(0xdeadbeef);
880 hFile
= CreateFileA("c:\\*.*", GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
881 ok(hFile
== INVALID_HANDLE_VALUE
, "hFile should have been INVALID_HANDLE_VALUE\n");
882 ok(GetLastError() == ERROR_INVALID_NAME
||
883 broken(GetLastError() == ERROR_FILE_NOT_FOUND
), /* Win98 */
884 "LastError should have been ERROR_INVALID_NAME or ERROR_FILE_NOT_FOUND but got %u\n", GetLastError());
886 /* get windows drive letter */
887 ret
= GetWindowsDirectory(windowsdir
, sizeof(windowsdir
));
888 ok(ret
< sizeof(windowsdir
), "windowsdir is abnormally long!\n");
889 ok(ret
!= 0, "GetWindowsDirectory: error %d\n", GetLastError());
891 /* test error return codes from CreateFile for some cases */
892 ret
= GetTempPathA(MAX_PATH
, temp_path
);
893 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
894 strcpy(dirname
, temp_path
);
895 strcat(dirname
, directory
);
896 ret
= CreateDirectory(dirname
, NULL
);
897 ok( ret
, "Createdirectory failed, gle=%d\n", GetLastError() );
898 /* set current drive & directory to known location */
899 SetCurrentDirectoryA( temp_path
);
904 /* update the drive id in the table entry with the current one */
905 if (p
[i
].file
[1] == ':')
907 strcpy(filename
, p
[i
].file
);
908 filename
[0] = windowsdir
[0];
910 else if (p
[i
].file
[0] == '\\' && p
[i
].file
[5] == ':')
912 strcpy(filename
, p
[i
].file
);
913 filename
[4] = windowsdir
[0];
917 /* prefix the table entry with the current temp directory */
918 strcpy(filename
, temp_path
);
919 strcat(filename
, p
[i
].file
);
921 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
922 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
924 p
[i
].options
, NULL
);
925 /* if we get ACCESS_DENIED when we do not expect it, assume
926 * no access to the volume
928 if (hFile
== INVALID_HANDLE_VALUE
&&
929 GetLastError() == ERROR_ACCESS_DENIED
&&
930 p
[i
].err
!= ERROR_ACCESS_DENIED
)
933 skip("Either no authority to volume, or is todo_wine for %s err=%d should be %d\n", filename
, GetLastError(), p
[i
].err
);
935 skip("Do not have authority to access volumes. Test for %s skipped\n", filename
);
937 /* otherwise validate results with expectations */
938 else if (p
[i
].todo_flag
)
940 (hFile
== INVALID_HANDLE_VALUE
&&
941 (p
[i
].err
== GetLastError() || p
[i
].err2
== GetLastError())) ||
942 (hFile
!= INVALID_HANDLE_VALUE
&& p
[i
].err
== ERROR_SUCCESS
),
943 "CreateFileA failed on %s, hFile %p, err=%u, should be %u\n",
944 filename
, hFile
, GetLastError(), p
[i
].err
);
947 (hFile
== INVALID_HANDLE_VALUE
&&
948 (p
[i
].err
== GetLastError() || p
[i
].err2
== GetLastError())) ||
949 (hFile
!= INVALID_HANDLE_VALUE
&& p
[i
].err
== ERROR_SUCCESS
),
950 "CreateFileA failed on %s, hFile %p, err=%u, should be %u\n",
951 filename
, hFile
, GetLastError(), p
[i
].err
);
952 if (hFile
!= INVALID_HANDLE_VALUE
)
953 CloseHandle( hFile
);
956 ret
= RemoveDirectoryA(dirname
);
957 ok(ret
, "RemoveDirectoryA: error %d\n", GetLastError());
960 /* test opening directory as a directory */
961 hFile
= CreateFileA( temp_path
, GENERIC_READ
,
965 FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
966 if (hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() != ERROR_PATH_NOT_FOUND
)
968 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_SUCCESS
,
969 "CreateFileA did not work, last error %u on volume <%s>\n",
970 GetLastError(), temp_path
);
972 if (hFile
!= INVALID_HANDLE_VALUE
)
974 ret
= GetFileInformationByHandle( hFile
, &Finfo
);
977 ok(Finfo
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
,
978 "CreateFileA probably did not open temp directory %s correctly\n file information does not include FILE_ATTRIBUTE_DIRECTORY, actual=0x%08x\n",
979 temp_path
, Finfo
.dwFileAttributes
);
981 CloseHandle( hFile
);
985 skip("Probable Win9x, got ERROR_PATH_NOT_FOUND w/ FILE_FLAG_BACKUP_SEMANTICS or %s\n", temp_path
);
988 /* *** Test opening volumes/devices using drive letter *** */
990 /* test using drive letter in non-rewrite format without trailing \ */
991 /* this should work */
992 strcpy(filename
, nt_drive
);
993 filename
[4] = windowsdir
[0];
994 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
995 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
997 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_NO_BUFFERING
, NULL
);
998 if (hFile
!= INVALID_HANDLE_VALUE
||
999 (GetLastError() != ERROR_ACCESS_DENIED
&& GetLastError() != ERROR_BAD_NETPATH
))
1001 /* if we have adm rights to volume, then try rest of tests */
1002 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA did not open %s, last error=%u\n",
1003 filename
, GetLastError());
1004 if (hFile
!= INVALID_HANDLE_VALUE
)
1006 /* if we opened the volume/device, try to read it. Since it */
1007 /* opened, we should be able to read it. We don't care about*/
1008 /* what the data is at this time. */
1010 ret
= ReadFile( hFile
, buffer
, len
, &len
, NULL
);
1011 todo_wine
ok(ret
, "Failed to read volume, last error %u, %u, for %s\n",
1012 GetLastError(), ret
, filename
);
1015 trace("buffer is\n");
1016 dumpmem(buffer
, 64);
1018 CloseHandle( hFile
);
1021 /* test using drive letter with trailing \ and in non-rewrite */
1022 /* this should not work */
1023 strcpy(filename
, nt_drive
);
1024 filename
[4] = windowsdir
[0];
1025 strcat( filename
, "\\" );
1026 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1027 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1028 NULL
, OPEN_EXISTING
,
1029 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_NO_BUFFERING
, NULL
);
1031 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
1032 "CreateFileA should have returned ERROR_PATH_NOT_FOUND on %s, but got %u\n",
1033 filename
, GetLastError());
1034 if (hFile
!= INVALID_HANDLE_VALUE
)
1035 CloseHandle( hFile
);
1037 /* test using temp path with trailing \ and in non-rewrite as dir */
1038 /* this should work */
1039 strcpy(filename
, nt_drive
);
1041 strcat( filename
, temp_path
);
1042 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1043 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1044 NULL
, OPEN_EXISTING
,
1045 FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
1046 ok(hFile
!= INVALID_HANDLE_VALUE
,
1047 "CreateFileA should have worked on %s, but got %u\n",
1048 filename
, GetLastError());
1049 if (hFile
!= INVALID_HANDLE_VALUE
)
1050 CloseHandle( hFile
);
1052 /* test using drive letter without trailing \ and in device ns */
1053 /* this should work */
1054 strcpy(filename
, nt_drive
);
1055 filename
[4] = windowsdir
[0];
1057 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1058 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1059 NULL
, OPEN_EXISTING
,
1060 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_NO_BUFFERING
, NULL
);
1061 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA did not open %s, last error=%u\n",
1062 filename
, GetLastError());
1063 if (hFile
!= INVALID_HANDLE_VALUE
)
1064 CloseHandle( hFile
);
1066 /* If we see ERROR_BAD_NETPATH then on Win9x or WinME, so skip */
1067 else if (GetLastError() == ERROR_BAD_NETPATH
)
1068 skip("Probable Win9x, got ERROR_BAD_NETPATH (53)\n");
1070 skip("Do not have authority to access volumes. Tests skipped\n");
1073 /* *** Test opening volumes/devices using GUID *** */
1075 if (pGetVolumeNameForVolumeMountPointA
)
1077 strcpy(filename
, "c:\\");
1078 filename
[0] = windowsdir
[0];
1079 ret
= pGetVolumeNameForVolumeMountPointA( filename
, Volume_1
, MAX_PATH
);
1080 ok(ret
, "GetVolumeNameForVolumeMountPointA failed, for %s, last error=%d\n", filename
, GetLastError());
1083 ok(strlen(Volume_1
) == 49, "GetVolumeNameForVolumeMountPointA returned wrong length name <%s>\n", Volume_1
);
1085 /* test the result of opening a unique volume name (GUID)
1086 * with the trailing \
1087 * this should error out
1089 strcpy(filename
, Volume_1
);
1090 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1091 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1092 NULL
, OPEN_EXISTING
,
1093 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_NO_BUFFERING
, NULL
);
1095 ok(hFile
== INVALID_HANDLE_VALUE
,
1096 "CreateFileA should not have opened %s, hFile %p\n",
1099 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
1100 "CreateFileA should have returned ERROR_PATH_NOT_FOUND on %s, but got %u\n",
1101 filename
, GetLastError());
1102 if (hFile
!= INVALID_HANDLE_VALUE
)
1103 CloseHandle( hFile
);
1105 /* test the result of opening a unique volume name (GUID)
1106 * with the temp path string as dir
1109 strcpy(filename
, Volume_1
);
1110 strcat(filename
, temp_path
+3);
1111 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1112 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1113 NULL
, OPEN_EXISTING
,
1114 FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
1116 ok(hFile
!= INVALID_HANDLE_VALUE
,
1117 "CreateFileA should have opened %s, but got %u\n",
1118 filename
, GetLastError());
1119 if (hFile
!= INVALID_HANDLE_VALUE
)
1120 CloseHandle( hFile
);
1122 /* test the result of opening a unique volume name (GUID)
1123 * without the trailing \ and in device namespace
1126 strcpy(filename
, Volume_1
);
1129 hFile
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1130 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1131 NULL
, OPEN_EXISTING
,
1132 FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_NO_BUFFERING
, NULL
);
1133 if (hFile
!= INVALID_HANDLE_VALUE
|| GetLastError() != ERROR_ACCESS_DENIED
)
1135 /* if we have adm rights to volume, then try rest of tests */
1136 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA did not open %s, last error=%u\n",
1137 filename
, GetLastError());
1138 if (hFile
!= INVALID_HANDLE_VALUE
)
1140 /* if we opened the volume/device, try to read it. Since it */
1141 /* opened, we should be able to read it. We don't care about*/
1142 /* what the data is at this time. */
1144 ret
= ReadFile( hFile
, buffer
, len
, &len
, NULL
);
1145 todo_wine
ok(ret
, "Failed to read volume, last error %u, %u, for %s\n",
1146 GetLastError(), ret
, filename
);
1149 trace("buffer is\n");
1150 dumpmem(buffer
, 64);
1152 CloseHandle( hFile
);
1156 skip("Do not have authority to access volumes. Tests skipped\n");
1159 win_skip("GetVolumeNameForVolumeMountPointA not functioning\n");
1162 win_skip("GetVolumeNameForVolumeMountPointA not found\n");
1165 static void test_CreateFileW(void)
1168 WCHAR temp_path
[MAX_PATH
];
1169 WCHAR filename
[MAX_PATH
];
1170 static const WCHAR emptyW
[]={'\0'};
1171 static const WCHAR prefix
[] = {'p','f','x',0};
1172 static const WCHAR bogus
[] = { '\\', '\\', '.', '\\', 'B', 'O', 'G', 'U', 'S', 0 };
1175 ret
= GetTempPathW(MAX_PATH
, temp_path
);
1176 if (ret
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1178 win_skip("GetTempPathW is not available\n");
1181 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
1182 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
1184 ret
= GetTempFileNameW(temp_path
, prefix
, 0, filename
);
1185 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
1187 SetLastError(0xdeadbeef);
1188 hFile
= CreateFileW(filename
, GENERIC_READ
, 0, NULL
,
1189 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
1190 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_EXISTS
,
1191 "CREATE_NEW should fail if file exists and last error value should be ERROR_FILE_EXISTS\n");
1193 SetLastError(0xdeadbeef);
1194 hFile
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1195 CREATE_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
1196 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
1197 "hFile %p, last error %u\n", hFile
, GetLastError());
1201 SetLastError(0xdeadbeef);
1202 hFile
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1203 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
1204 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_ALREADY_EXISTS
,
1205 "hFile %p, last error %u\n", hFile
, GetLastError());
1209 ret
= DeleteFileW(filename
);
1210 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
1212 SetLastError(0xdeadbeef);
1213 hFile
= CreateFileW(filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
1214 OPEN_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
1215 ok(hFile
!= INVALID_HANDLE_VALUE
&& GetLastError() == 0,
1216 "hFile %p, last error %u\n", hFile
, GetLastError());
1220 ret
= DeleteFileW(filename
);
1221 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
1225 /* this crashes on NT4.0 */
1226 hFile
= CreateFileW(NULL
, GENERIC_READ
, 0, NULL
,
1227 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
1228 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
1229 "CreateFileW(NULL) returned ret=%p error=%u\n",hFile
,GetLastError());
1232 hFile
= CreateFileW(emptyW
, GENERIC_READ
, 0, NULL
,
1233 CREATE_NEW
, FILE_FLAG_RANDOM_ACCESS
, 0);
1234 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
1235 "CreateFileW(\"\") returned ret=%p error=%d\n",hFile
,GetLastError());
1237 /* test the result of opening a nonexistent driver name */
1238 hFile
= CreateFileW(bogus
, 0, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1239 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
1240 ok(hFile
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_FILE_NOT_FOUND
,
1241 "CreateFileW on invalid VxD name returned ret=%p error=%d\n",hFile
,GetLastError());
1243 ret
= CreateDirectoryW(filename
, NULL
);
1244 ok(ret
== TRUE
, "couldn't create temporary directory\n");
1245 hFile
= CreateFileW(filename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
1246 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
| FILE_FLAG_BACKUP_SEMANTICS
, NULL
);
1247 ok(hFile
!= INVALID_HANDLE_VALUE
,
1248 "expected CreateFile to succeed on existing directory, error: %d\n", GetLastError());
1250 ret
= RemoveDirectoryW(filename
);
1251 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
1254 static void test_GetTempFileNameA(void)
1258 char expected
[MAX_PATH
+ 10];
1259 char windowsdir
[MAX_PATH
+ 10];
1260 char windowsdrive
[3];
1262 result
= GetWindowsDirectory(windowsdir
, sizeof(windowsdir
));
1263 ok(result
< sizeof(windowsdir
), "windowsdir is abnormally long!\n");
1264 ok(result
!= 0, "GetWindowsDirectory: error %d\n", GetLastError());
1266 /* If the Windows directory is the root directory, it ends in backslash, not else. */
1267 if (strlen(windowsdir
) != 3) /* As in "C:\" or "F:\" */
1269 strcat(windowsdir
, "\\");
1272 windowsdrive
[0] = windowsdir
[0];
1273 windowsdrive
[1] = windowsdir
[1];
1274 windowsdrive
[2] = '\0';
1276 result
= GetTempFileNameA(windowsdrive
, "abc", 1, out
);
1277 ok(result
!= 0, "GetTempFileNameA: error %d\n", GetLastError());
1278 ok(((out
[0] == windowsdrive
[0]) && (out
[1] == ':')) && (out
[2] == '\\'),
1279 "GetTempFileNameA: first three characters should be %c:\\, string was actually %s\n",
1280 windowsdrive
[0], out
);
1282 result
= GetTempFileNameA(windowsdir
, "abc", 2, out
);
1283 ok(result
!= 0, "GetTempFileNameA: error %d\n", GetLastError());
1285 strcat(expected
, windowsdir
);
1286 strcat(expected
, "abc2.tmp");
1287 ok(lstrcmpiA(out
, expected
) == 0, "GetTempFileNameA: Unexpected output \"%s\" vs \"%s\"\n",
1291 static void test_DeleteFileA( void )
1294 char temp_path
[MAX_PATH
], temp_file
[MAX_PATH
];
1297 ret
= DeleteFileA(NULL
);
1298 ok(!ret
&& (GetLastError() == ERROR_INVALID_PARAMETER
||
1299 GetLastError() == ERROR_PATH_NOT_FOUND
),
1300 "DeleteFileA(NULL) returned ret=%d error=%d\n",ret
,GetLastError());
1302 ret
= DeleteFileA("");
1303 ok(!ret
&& (GetLastError() == ERROR_PATH_NOT_FOUND
||
1304 GetLastError() == ERROR_BAD_PATHNAME
),
1305 "DeleteFileA(\"\") returned ret=%d error=%d\n",ret
,GetLastError());
1307 ret
= DeleteFileA("nul");
1308 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
1309 GetLastError() == ERROR_INVALID_PARAMETER
||
1310 GetLastError() == ERROR_ACCESS_DENIED
||
1311 GetLastError() == ERROR_INVALID_FUNCTION
),
1312 "DeleteFileA(\"nul\") returned ret=%d error=%d\n",ret
,GetLastError());
1314 GetTempPathA(MAX_PATH
, temp_path
);
1315 GetTempFileName(temp_path
, "tst", 0, temp_file
);
1317 SetLastError(0xdeadbeef);
1318 hfile
= CreateFile(temp_file
, GENERIC_READ
, FILE_SHARE_DELETE
| FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
1319 ok(hfile
!= INVALID_HANDLE_VALUE
, "CreateFile error %d\n", GetLastError());
1321 SetLastError(0xdeadbeef);
1322 ret
= DeleteFile(temp_file
);
1324 ok(ret
, "DeleteFile error %d\n", GetLastError());
1326 SetLastError(0xdeadbeef);
1327 ret
= CloseHandle(hfile
);
1328 ok(ret
, "CloseHandle error %d\n", GetLastError());
1329 ret
= DeleteFile(temp_file
);
1331 ok(!ret
, "DeleteFile should fail\n");
1334 static void test_DeleteFileW( void )
1337 WCHAR pathW
[MAX_PATH
];
1338 WCHAR pathsubW
[MAX_PATH
];
1339 static const WCHAR dirW
[] = {'d','e','l','e','t','e','f','i','l','e',0};
1340 static const WCHAR subdirW
[] = {'\\','s','u','b',0};
1341 static const WCHAR emptyW
[]={'\0'};
1343 ret
= DeleteFileW(NULL
);
1344 if (ret
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1346 win_skip("DeleteFileW is not available\n");
1349 ok(!ret
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
1350 "DeleteFileW(NULL) returned ret=%d error=%d\n",ret
,GetLastError());
1352 ret
= DeleteFileW(emptyW
);
1353 ok(!ret
&& GetLastError() == ERROR_PATH_NOT_FOUND
,
1354 "DeleteFileW(\"\") returned ret=%d error=%d\n",ret
,GetLastError());
1356 /* test DeleteFile on empty directory */
1357 ret
= GetTempPathW(MAX_PATH
, pathW
);
1358 if (ret
+ sizeof(dirW
)/sizeof(WCHAR
)-1 + sizeof(subdirW
)/sizeof(WCHAR
)-1 >= MAX_PATH
)
1360 ok(0, "MAX_PATH exceeded in constructing paths\n");
1363 lstrcatW(pathW
, dirW
);
1364 lstrcpyW(pathsubW
, pathW
);
1365 lstrcatW(pathsubW
, subdirW
);
1366 ret
= CreateDirectoryW(pathW
, NULL
);
1367 ok(ret
== TRUE
, "couldn't create directory deletefile\n");
1368 ret
= DeleteFileW(pathW
);
1369 ok(ret
== FALSE
, "DeleteFile should fail for empty directories\n");
1370 ret
= RemoveDirectoryW(pathW
);
1371 ok(ret
== TRUE
, "expected to remove directory deletefile\n");
1373 /* test DeleteFile on non-empty directory */
1374 ret
= CreateDirectoryW(pathW
, NULL
);
1375 ok(ret
== TRUE
, "couldn't create directory deletefile\n");
1376 ret
= CreateDirectoryW(pathsubW
, NULL
);
1377 ok(ret
== TRUE
, "couldn't create directory deletefile\\sub\n");
1378 ret
= DeleteFileW(pathW
);
1379 ok(ret
== FALSE
, "DeleteFile should fail for non-empty directories\n");
1380 ret
= RemoveDirectoryW(pathsubW
);
1381 ok(ret
== TRUE
, "expected to remove directory deletefile\\sub\n");
1382 ret
= RemoveDirectoryW(pathW
);
1383 ok(ret
== TRUE
, "expected to remove directory deletefile\n");
1386 #define IsDotDir(x) ((x[0] == '.') && ((x[1] == 0) || ((x[1] == '.') && (x[2] == 0))))
1388 static void test_MoveFileA(void)
1390 char tempdir
[MAX_PATH
];
1391 char source
[MAX_PATH
], dest
[MAX_PATH
];
1392 static const char prefix
[] = "pfx";
1398 ret
= GetTempPathA(MAX_PATH
, tempdir
);
1399 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
1400 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
1402 ret
= GetTempFileNameA(tempdir
, prefix
, 0, source
);
1403 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
1405 ret
= GetTempFileNameA(tempdir
, prefix
, 0, dest
);
1406 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
1408 ret
= MoveFileA(source
, dest
);
1409 ok(!ret
&& GetLastError() == ERROR_ALREADY_EXISTS
,
1410 "MoveFileA: unexpected error %d\n", GetLastError());
1412 ret
= DeleteFileA(dest
);
1413 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
1415 hfile
= CreateFileA(source
, GENERIC_READ
| GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0);
1416 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open source file\n");
1418 retok
= WriteFile(hfile
, prefix
, sizeof(prefix
), &ret
, NULL
);
1419 ok( retok
&& ret
== sizeof(prefix
),
1420 "WriteFile error %d\n", GetLastError());
1422 hmapfile
= CreateFileMapping(hfile
, NULL
, PAGE_READONLY
| SEC_COMMIT
, 0, 0, NULL
);
1423 ok(hmapfile
!= NULL
, "CreateFileMapping: error %d\n", GetLastError());
1425 ret
= MoveFileA(source
, dest
);
1427 ok(!ret
, "MoveFileA: expected failure\n");
1428 ok(GetLastError() == ERROR_SHARING_VIOLATION
||
1429 broken(GetLastError() == ERROR_ACCESS_DENIED
), /* Win9x and WinMe */
1430 "MoveFileA: expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
1433 CloseHandle(hmapfile
);
1436 /* if MoveFile succeeded, move back to dest */
1437 if (ret
) MoveFile(dest
, source
);
1439 hfile
= CreateFileA(source
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
1440 ok(hfile
!= INVALID_HANDLE_VALUE
, "failed to open source file\n");
1442 hmapfile
= CreateFileMapping(hfile
, NULL
, PAGE_READONLY
| SEC_COMMIT
, 0, 0, NULL
);
1443 ok(hmapfile
!= NULL
, "CreateFileMapping: error %d\n", GetLastError());
1445 ret
= MoveFileA(source
, dest
);
1447 ok(!ret
, "MoveFileA: expected failure\n");
1448 ok(GetLastError() == ERROR_SHARING_VIOLATION
||
1449 broken(GetLastError() == ERROR_ACCESS_DENIED
), /* Win9x and WinMe */
1450 "MoveFileA: expected ERROR_SHARING_VIOLATION, got %d\n", GetLastError());
1453 CloseHandle(hmapfile
);
1456 /* if MoveFile succeeded, move back to dest */
1457 if (ret
) MoveFile(dest
, source
);
1459 ret
= MoveFileA(source
, dest
);
1460 ok(ret
, "MoveFileA: failed, error %d\n", GetLastError());
1462 lstrcatA(tempdir
, "Remove Me");
1463 ret
= CreateDirectoryA(tempdir
, NULL
);
1464 ok(ret
== TRUE
, "CreateDirectoryA failed\n");
1466 lstrcpyA(source
, dest
);
1467 lstrcpyA(dest
, tempdir
);
1468 lstrcatA(dest
, "\\wild?.*");
1469 /* FIXME: if we create a file with wildcards we can't delete it now that DeleteFile works correctly */
1470 ret
= MoveFileA(source
, dest
);
1471 ok(!ret
, "MoveFileA: shouldn't move to wildcard file\n");
1472 ok(GetLastError() == ERROR_INVALID_NAME
|| /* NT */
1473 GetLastError() == ERROR_FILE_NOT_FOUND
, /* Win9x */
1474 "MoveFileA: with wildcards, unexpected error %d\n", GetLastError());
1475 if (ret
|| (GetLastError() != ERROR_INVALID_NAME
))
1477 WIN32_FIND_DATAA fd
;
1478 char temppath
[MAX_PATH
];
1481 lstrcpyA(temppath
, tempdir
);
1482 lstrcatA(temppath
, "\\*.*");
1483 hFind
= FindFirstFileA(temppath
, &fd
);
1484 if (INVALID_HANDLE_VALUE
!= hFind
)
1489 lpName
= fd
.cAlternateFileName
;
1491 lpName
= fd
.cFileName
;
1492 ok(IsDotDir(lpName
), "MoveFileA: wildcards file created!\n");
1494 while (FindNextFileA(hFind
, &fd
));
1498 ret
= DeleteFileA(source
);
1499 ok(ret
, "DeleteFileA: error %d\n", GetLastError());
1500 ret
= DeleteFileA(dest
);
1501 ok(!ret
, "DeleteFileA: error %d\n", GetLastError());
1502 ret
= RemoveDirectoryA(tempdir
);
1503 ok(ret
, "DeleteDirectoryA: error %d\n", GetLastError());
1506 static void test_MoveFileW(void)
1508 WCHAR temp_path
[MAX_PATH
];
1509 WCHAR source
[MAX_PATH
], dest
[MAX_PATH
];
1510 static const WCHAR prefix
[] = {'p','f','x',0};
1513 ret
= GetTempPathW(MAX_PATH
, temp_path
);
1514 if (ret
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
1516 win_skip("GetTempPathW is not available\n");
1519 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
1520 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
1522 ret
= GetTempFileNameW(temp_path
, prefix
, 0, source
);
1523 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
1525 ret
= GetTempFileNameW(temp_path
, prefix
, 0, dest
);
1526 ok(ret
!= 0, "GetTempFileNameW error %d\n", GetLastError());
1528 ret
= MoveFileW(source
, dest
);
1529 ok(!ret
&& GetLastError() == ERROR_ALREADY_EXISTS
,
1530 "CopyFileW: unexpected error %d\n", GetLastError());
1532 ret
= DeleteFileW(source
);
1533 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
1534 ret
= DeleteFileW(dest
);
1535 ok(ret
, "DeleteFileW: error %d\n", GetLastError());
1538 #define PATTERN_OFFSET 0x10
1540 static void test_offset_in_overlapped_structure(void)
1546 BYTE buf
[256], pattern
[] = "TeSt";
1548 char temp_path
[MAX_PATH
], temp_fname
[MAX_PATH
];
1551 ret
=GetTempPathA(MAX_PATH
, temp_path
);
1552 ok( ret
, "GetTempPathA error %d\n", GetLastError());
1553 ret
=GetTempFileNameA(temp_path
, "pfx", 0, temp_fname
);
1554 ok( ret
, "GetTempFileNameA error %d\n", GetLastError());
1556 /*** Write File *****************************************************/
1558 hFile
= CreateFileA(temp_fname
, GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, 0);
1559 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError());
1561 for(i
= 0; i
< sizeof(buf
); i
++) buf
[i
] = i
;
1562 ret
= WriteFile(hFile
, buf
, sizeof(buf
), &done
, NULL
);
1563 ok( ret
, "WriteFile error %d\n", GetLastError());
1564 ok(done
== sizeof(buf
), "expected number of bytes written %u\n", done
);
1566 memset(&ov
, 0, sizeof(ov
));
1567 S(U(ov
)).Offset
= PATTERN_OFFSET
;
1568 S(U(ov
)).OffsetHigh
= 0;
1569 rc
=WriteFile(hFile
, pattern
, sizeof(pattern
), &done
, &ov
);
1570 /* Win 9x does not support the overlapped I/O on files */
1571 if (rc
|| GetLastError()!=ERROR_INVALID_PARAMETER
) {
1572 ok(rc
, "WriteFile error %d\n", GetLastError());
1573 ok(done
== sizeof(pattern
), "expected number of bytes written %u\n", done
);
1574 offset
= SetFilePointer(hFile
, 0, NULL
, FILE_CURRENT
);
1575 ok(offset
== PATTERN_OFFSET
+ sizeof(pattern
), "wrong file offset %d\n", offset
);
1577 S(U(ov
)).Offset
= sizeof(buf
) * 2;
1578 S(U(ov
)).OffsetHigh
= 0;
1579 ret
= WriteFile(hFile
, pattern
, sizeof(pattern
), &done
, &ov
);
1580 ok( ret
, "WriteFile error %d\n", GetLastError());
1581 ok(done
== sizeof(pattern
), "expected number of bytes written %u\n", done
);
1582 offset
= SetFilePointer(hFile
, 0, NULL
, FILE_CURRENT
);
1583 ok(offset
== sizeof(buf
) * 2 + sizeof(pattern
), "wrong file offset %d\n", offset
);
1588 /*** Read File *****************************************************/
1590 hFile
= CreateFileA(temp_fname
, GENERIC_READ
, 0, NULL
, OPEN_EXISTING
, 0, 0);
1591 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError());
1593 memset(buf
, 0, sizeof(buf
));
1594 memset(&ov
, 0, sizeof(ov
));
1595 S(U(ov
)).Offset
= PATTERN_OFFSET
;
1596 S(U(ov
)).OffsetHigh
= 0;
1597 rc
=ReadFile(hFile
, buf
, sizeof(pattern
), &done
, &ov
);
1598 /* Win 9x does not support the overlapped I/O on files */
1599 if (rc
|| GetLastError()!=ERROR_INVALID_PARAMETER
) {
1600 ok(rc
, "ReadFile error %d\n", GetLastError());
1601 ok(done
== sizeof(pattern
), "expected number of bytes read %u\n", done
);
1602 offset
= SetFilePointer(hFile
, 0, NULL
, FILE_CURRENT
);
1603 ok(offset
== PATTERN_OFFSET
+ sizeof(pattern
), "wrong file offset %d\n", offset
);
1604 ok(!memcmp(buf
, pattern
, sizeof(pattern
)), "pattern match failed\n");
1609 ret
= DeleteFileA(temp_fname
);
1610 ok( ret
, "DeleteFileA error %d\n", GetLastError());
1613 static void test_LockFile(void)
1615 HANDLE handle
, handle2
;
1617 OVERLAPPED overlapped
;
1618 int limited_LockFile
;
1619 int limited_UnLockFile
;
1622 handle
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1623 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1624 CREATE_ALWAYS
, 0, 0 );
1625 if (handle
== INVALID_HANDLE_VALUE
)
1627 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
1630 handle2
= CreateFileA( filename
, GENERIC_READ
| GENERIC_WRITE
,
1631 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
1632 OPEN_EXISTING
, 0, 0 );
1633 if (handle2
== INVALID_HANDLE_VALUE
)
1635 ok( 0, "couldn't open file \"%s\" (err=%d)\n", filename
, GetLastError() );
1638 ok( WriteFile( handle
, sillytext
, strlen(sillytext
), &written
, NULL
), "write failed\n" );
1640 ok( LockFile( handle
, 0, 0, 0, 0 ), "LockFile failed\n" );
1641 ok( UnlockFile( handle
, 0, 0, 0, 0 ), "UnlockFile failed\n" );
1643 limited_UnLockFile
= 0;
1644 if (UnlockFile( handle
, 0, 0, 0, 0 ))
1646 limited_UnLockFile
= 1;
1649 ok( LockFile( handle
, 10, 0, 20, 0 ), "LockFile 10,20 failed\n" );
1650 /* overlapping locks must fail */
1651 ok( !LockFile( handle
, 12, 0, 10, 0 ), "LockFile 12,10 succeeded\n" );
1652 ok( !LockFile( handle
, 5, 0, 6, 0 ), "LockFile 5,6 succeeded\n" );
1653 /* non-overlapping locks must succeed */
1654 ok( LockFile( handle
, 5, 0, 5, 0 ), "LockFile 5,5 failed\n" );
1656 ok( !UnlockFile( handle
, 10, 0, 10, 0 ), "UnlockFile 10,10 succeeded\n" );
1657 ok( UnlockFile( handle
, 10, 0, 20, 0 ), "UnlockFile 10,20 failed\n" );
1658 ok( !UnlockFile( handle
, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" );
1659 ok( UnlockFile( handle
, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" );
1661 S(U(overlapped
)).Offset
= 100;
1662 S(U(overlapped
)).OffsetHigh
= 0;
1663 overlapped
.hEvent
= 0;
1665 /* Test for broken LockFileEx a la Windows 95 OSR2. */
1666 if (LockFileEx( handle
, 0, 0, 100, 0, &overlapped
))
1668 /* LockFileEx is probably OK, test it more. */
1669 ok( LockFileEx( handle
, 0, 0, 100, 0, &overlapped
),
1670 "LockFileEx 100,100 failed\n" );
1673 /* overlapping shared locks are OK */
1674 S(U(overlapped
)).Offset
= 150;
1675 limited_UnLockFile
|| ok( LockFileEx( handle
, 0, 0, 100, 0, &overlapped
), "LockFileEx 150,100 failed\n" );
1677 /* but exclusive is not */
1678 ok( !LockFileEx( handle
, LOCKFILE_EXCLUSIVE_LOCK
|LOCKFILE_FAIL_IMMEDIATELY
,
1679 0, 50, 0, &overlapped
),
1680 "LockFileEx exclusive 150,50 succeeded\n" );
1681 if (!UnlockFileEx( handle
, 0, 100, 0, &overlapped
))
1682 { /* UnLockFile is capable. */
1683 S(U(overlapped
)).Offset
= 100;
1684 ok( !UnlockFileEx( handle
, 0, 100, 0, &overlapped
),
1685 "UnlockFileEx 150,100 again succeeded\n" );
1688 /* shared lock can overlap exclusive if handles are equal */
1689 S(U(overlapped
)).Offset
= 300;
1690 ok( LockFileEx( handle
, LOCKFILE_EXCLUSIVE_LOCK
, 0, 100, 0, &overlapped
),
1691 "LockFileEx exclusive 300,100 failed\n" );
1692 ok( !LockFileEx( handle2
, LOCKFILE_FAIL_IMMEDIATELY
, 0, 100, 0, &overlapped
),
1693 "LockFileEx handle2 300,100 succeeded\n" );
1694 ret
= LockFileEx( handle
, LOCKFILE_FAIL_IMMEDIATELY
, 0, 100, 0, &overlapped
);
1695 ok( ret
, "LockFileEx 300,100 failed\n" );
1696 ok( UnlockFileEx( handle
, 0, 100, 0, &overlapped
), "UnlockFileEx 300,100 failed\n" );
1697 /* exclusive lock is removed first */
1698 ok( LockFileEx( handle2
, LOCKFILE_FAIL_IMMEDIATELY
, 0, 100, 0, &overlapped
),
1699 "LockFileEx handle2 300,100 failed\n" );
1700 ok( UnlockFileEx( handle2
, 0, 100, 0, &overlapped
), "UnlockFileEx 300,100 failed\n" );
1702 ok( UnlockFileEx( handle
, 0, 100, 0, &overlapped
), "UnlockFileEx 300,100 failed\n" );
1704 ret
= LockFile( handle
, 0, 0x10000000, 0, 0xf0000000 );
1707 ok( !LockFile( handle
, ~0, ~0, 1, 0 ), "LockFile ~0,1 succeeded\n" );
1708 ok( !LockFile( handle
, 0, 0x20000000, 20, 0 ), "LockFile 0x20000000,20 succeeded\n" );
1709 ok( UnlockFile( handle
, 0, 0x10000000, 0, 0xf0000000 ), "UnlockFile failed\n" );
1712 ok( GetLastError() == ERROR_INVALID_PARAMETER
, "wrong LockFile error %u\n", GetLastError() );
1714 /* wrap-around lock should not do anything */
1715 /* (but still succeeds on NT4 so we don't check result) */
1716 LockFile( handle
, 0, 0x10000000, 0, 0xf0000001 );
1718 limited_LockFile
= 0;
1719 if (!LockFile( handle
, ~0, ~0, 1, 0 ))
1721 limited_LockFile
= 1;
1724 limited_UnLockFile
|| ok( UnlockFile( handle
, ~0, ~0, 1, 0 ), "Unlockfile ~0,1 failed\n" );
1726 /* zero-byte lock */
1727 ok( LockFile( handle
, 100, 0, 0, 0 ), "LockFile 100,0 failed\n" );
1728 if (!limited_LockFile
) ok( !LockFile( handle
, 98, 0, 4, 0 ), "LockFile 98,4 succeeded\n" );
1729 ok( LockFile( handle
, 90, 0, 10, 0 ), "LockFile 90,10 failed\n" );
1730 if (!limited_LockFile
) ok( !LockFile( handle
, 100, 0, 10, 0 ), "LockFile 100,10 failed\n" );
1732 ok( UnlockFile( handle
, 90, 0, 10, 0 ), "UnlockFile 90,10 failed\n" );
1733 ok( !UnlockFile( handle
, 100, 0, 10, 0 ), "UnlockFile 100,10 succeeded\n" );
1735 ok( UnlockFile( handle
, 100, 0, 0, 0 ), "UnlockFile 100,0 failed\n" );
1737 CloseHandle( handle2
);
1739 CloseHandle( handle
);
1740 DeleteFileA( filename
);
1743 static BOOL
create_fake_dll( LPCSTR filename
)
1745 IMAGE_DOS_HEADER
*dos
;
1746 IMAGE_NT_HEADERS
*nt
;
1747 IMAGE_SECTION_HEADER
*sec
;
1749 DWORD lfanew
= sizeof(*dos
);
1750 DWORD size
= lfanew
+ sizeof(*nt
) + sizeof(*sec
);
1754 HANDLE file
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0 );
1755 if (file
== INVALID_HANDLE_VALUE
) return FALSE
;
1757 buffer
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, size
);
1759 dos
= (IMAGE_DOS_HEADER
*)buffer
;
1760 dos
->e_magic
= IMAGE_DOS_SIGNATURE
;
1761 dos
->e_cblp
= sizeof(*dos
);
1763 dos
->e_cparhdr
= lfanew
/ 16;
1764 dos
->e_minalloc
= 0;
1765 dos
->e_maxalloc
= 0xffff;
1768 dos
->e_lfarlc
= lfanew
;
1769 dos
->e_lfanew
= lfanew
;
1771 nt
= (IMAGE_NT_HEADERS
*)(buffer
+ lfanew
);
1772 nt
->Signature
= IMAGE_NT_SIGNATURE
;
1773 #if defined __i386__
1774 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_I386
;
1775 #elif defined __x86_64__
1776 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_AMD64
;
1777 #elif defined __powerpc__
1778 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_POWERPC
;
1779 #elif defined __sparc__
1780 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_SPARC
;
1781 #elif defined __arm__
1782 nt
->FileHeader
.Machine
= IMAGE_FILE_MACHINE_ARMV7
;
1784 # error You must specify the machine type
1786 nt
->FileHeader
.NumberOfSections
= 1;
1787 nt
->FileHeader
.SizeOfOptionalHeader
= sizeof(IMAGE_OPTIONAL_HEADER
);
1788 nt
->FileHeader
.Characteristics
= IMAGE_FILE_DLL
| IMAGE_FILE_EXECUTABLE_IMAGE
;
1789 nt
->OptionalHeader
.Magic
= IMAGE_NT_OPTIONAL_HDR_MAGIC
;
1790 nt
->OptionalHeader
.MajorLinkerVersion
= 1;
1791 nt
->OptionalHeader
.MinorLinkerVersion
= 0;
1792 nt
->OptionalHeader
.ImageBase
= 0x10000000;
1793 nt
->OptionalHeader
.SectionAlignment
= 0x1000;
1794 nt
->OptionalHeader
.FileAlignment
= 0x1000;
1795 nt
->OptionalHeader
.MajorOperatingSystemVersion
= 1;
1796 nt
->OptionalHeader
.MinorOperatingSystemVersion
= 0;
1797 nt
->OptionalHeader
.MajorImageVersion
= 1;
1798 nt
->OptionalHeader
.MinorImageVersion
= 0;
1799 nt
->OptionalHeader
.MajorSubsystemVersion
= 4;
1800 nt
->OptionalHeader
.MinorSubsystemVersion
= 0;
1801 nt
->OptionalHeader
.SizeOfImage
= 0x2000;
1802 nt
->OptionalHeader
.SizeOfHeaders
= size
;
1803 nt
->OptionalHeader
.Subsystem
= IMAGE_SUBSYSTEM_WINDOWS_GUI
;
1804 nt
->OptionalHeader
.NumberOfRvaAndSizes
= IMAGE_NUMBEROF_DIRECTORY_ENTRIES
;
1806 sec
= (IMAGE_SECTION_HEADER
*)(nt
+ 1);
1807 memcpy( sec
->Name
, ".rodata", sizeof(".rodata") );
1808 sec
->Misc
.VirtualSize
= 0x1000;
1809 sec
->VirtualAddress
= 0x1000;
1810 sec
->SizeOfRawData
= 0;
1811 sec
->PointerToRawData
= 0;
1812 sec
->Characteristics
= IMAGE_SCN_MEM_READ
| IMAGE_SCN_MEM_WRITE
;
1814 ret
= WriteFile( file
, buffer
, size
, &written
, NULL
) && written
== size
;
1815 HeapFree( GetProcessHeap(), 0, buffer
);
1816 CloseHandle( file
);
1820 static unsigned int map_file_access( unsigned int access
)
1822 if (access
& GENERIC_READ
) access
|= FILE_GENERIC_READ
;
1823 if (access
& GENERIC_WRITE
) access
|= FILE_GENERIC_WRITE
;
1824 if (access
& GENERIC_EXECUTE
) access
|= FILE_GENERIC_EXECUTE
;
1825 if (access
& GENERIC_ALL
) access
|= FILE_ALL_ACCESS
;
1826 return access
& ~(GENERIC_READ
| GENERIC_WRITE
| GENERIC_EXECUTE
| GENERIC_ALL
);
1829 static int is_sharing_compatible( DWORD access1
, DWORD sharing1
, DWORD access2
, DWORD sharing2
)
1831 access1
= map_file_access( access1
);
1832 access2
= map_file_access( access2
);
1833 access1
&= FILE_READ_DATA
| FILE_WRITE_DATA
| FILE_APPEND_DATA
| FILE_EXECUTE
| DELETE
;
1834 access2
&= FILE_READ_DATA
| FILE_WRITE_DATA
| FILE_APPEND_DATA
| FILE_EXECUTE
| DELETE
;
1836 if (!access1
) sharing1
= FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
;
1837 if (!access2
) sharing2
= FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
;
1839 if ((access1
& (FILE_READ_DATA
|FILE_EXECUTE
)) && !(sharing2
& FILE_SHARE_READ
)) return 0;
1840 if ((access1
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
)) && !(sharing2
& FILE_SHARE_WRITE
)) return 0;
1841 if ((access1
& DELETE
) && !(sharing2
& FILE_SHARE_DELETE
)) return 0;
1842 if ((access2
& (FILE_READ_DATA
|FILE_EXECUTE
)) && !(sharing1
& FILE_SHARE_READ
)) return 0;
1843 if ((access2
& (FILE_WRITE_DATA
|FILE_APPEND_DATA
)) && !(sharing1
& FILE_SHARE_WRITE
)) return 0;
1844 if ((access2
& DELETE
) && !(sharing1
& FILE_SHARE_DELETE
)) return 0;
1848 static int is_sharing_map_compatible( DWORD map_access
, DWORD access2
, DWORD sharing2
)
1850 if ((map_access
== PAGE_READWRITE
|| map_access
== PAGE_EXECUTE_READWRITE
) &&
1851 !(sharing2
& FILE_SHARE_WRITE
)) return 0;
1852 access2
= map_file_access( access2
);
1853 if ((map_access
& SEC_IMAGE
) && (access2
& FILE_WRITE_DATA
)) return 0;
1857 static void test_file_sharing(void)
1859 static const DWORD access_modes
[] =
1860 { 0, GENERIC_READ
, GENERIC_WRITE
, GENERIC_READ
|GENERIC_WRITE
,
1861 DELETE
, GENERIC_READ
|DELETE
, GENERIC_WRITE
|DELETE
, GENERIC_READ
|GENERIC_WRITE
|DELETE
,
1862 GENERIC_EXECUTE
, GENERIC_EXECUTE
| DELETE
,
1863 FILE_READ_DATA
, FILE_WRITE_DATA
, FILE_APPEND_DATA
, FILE_READ_EA
, FILE_WRITE_EA
,
1864 FILE_READ_DATA
| FILE_EXECUTE
, FILE_WRITE_DATA
| FILE_EXECUTE
, FILE_APPEND_DATA
| FILE_EXECUTE
,
1865 FILE_READ_EA
| FILE_EXECUTE
, FILE_WRITE_EA
| FILE_EXECUTE
, FILE_EXECUTE
,
1866 FILE_DELETE_CHILD
, FILE_READ_ATTRIBUTES
, FILE_WRITE_ATTRIBUTES
};
1867 static const DWORD sharing_modes
[] =
1868 { 0, FILE_SHARE_READ
,
1869 FILE_SHARE_WRITE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
1870 FILE_SHARE_DELETE
, FILE_SHARE_READ
|FILE_SHARE_DELETE
,
1871 FILE_SHARE_WRITE
|FILE_SHARE_DELETE
, FILE_SHARE_READ
|FILE_SHARE_WRITE
|FILE_SHARE_DELETE
};
1872 static const DWORD mapping_modes
[] =
1873 { PAGE_READONLY
, PAGE_WRITECOPY
, PAGE_READWRITE
, SEC_IMAGE
| PAGE_WRITECOPY
};
1878 /* make sure the file exists */
1879 if (!create_fake_dll( filename
))
1881 ok(0, "couldn't create file \"%s\" (err=%d)\n", filename
, GetLastError());
1885 for (a1
= 0; a1
< sizeof(access_modes
)/sizeof(access_modes
[0]); a1
++)
1887 for (s1
= 0; s1
< sizeof(sharing_modes
)/sizeof(sharing_modes
[0]); s1
++)
1889 SetLastError(0xdeadbeef);
1890 h
= CreateFileA( filename
, access_modes
[a1
], sharing_modes
[s1
],
1891 NULL
, OPEN_EXISTING
, 0, 0 );
1892 if (h
== INVALID_HANDLE_VALUE
)
1894 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
1897 for (a2
= 0; a2
< sizeof(access_modes
)/sizeof(access_modes
[0]); a2
++)
1899 for (s2
= 0; s2
< sizeof(sharing_modes
)/sizeof(sharing_modes
[0]); s2
++)
1901 SetLastError(0xdeadbeef);
1902 h2
= CreateFileA( filename
, access_modes
[a2
], sharing_modes
[s2
],
1903 NULL
, OPEN_EXISTING
, 0, 0 );
1904 ret
= GetLastError();
1905 if (is_sharing_compatible( access_modes
[a1
], sharing_modes
[s1
],
1906 access_modes
[a2
], sharing_modes
[s2
] ))
1908 ok( h2
!= INVALID_HANDLE_VALUE
,
1909 "open failed for modes %x/%x/%x/%x\n",
1910 access_modes
[a1
], sharing_modes
[s1
],
1911 access_modes
[a2
], sharing_modes
[s2
] );
1912 ok( ret
== 0, "wrong error code %d\n", ret
);
1916 ok( h2
== INVALID_HANDLE_VALUE
,
1917 "open succeeded for modes %x/%x/%x/%x\n",
1918 access_modes
[a1
], sharing_modes
[s1
],
1919 access_modes
[a2
], sharing_modes
[s2
] );
1920 ok( ret
== ERROR_SHARING_VIOLATION
,
1921 "wrong error code %d\n", ret
);
1923 if (h2
!= INVALID_HANDLE_VALUE
) CloseHandle( h2
);
1930 for (a1
= 0; a1
< sizeof(mapping_modes
)/sizeof(mapping_modes
[0]); a1
++)
1934 create_fake_dll( filename
);
1935 SetLastError(0xdeadbeef);
1936 h
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
1937 if (h
== INVALID_HANDLE_VALUE
)
1939 ok(0,"couldn't create file \"%s\" (err=%d)\n",filename
,GetLastError());
1942 m
= CreateFileMappingA( h
, NULL
, mapping_modes
[a1
], 0, 0, NULL
);
1943 ok( m
!= 0, "failed to create mapping %x err %u\n", mapping_modes
[a1
], GetLastError() );
1947 for (a2
= 0; a2
< sizeof(access_modes
)/sizeof(access_modes
[0]); a2
++)
1949 for (s2
= 0; s2
< sizeof(sharing_modes
)/sizeof(sharing_modes
[0]); s2
++)
1951 SetLastError(0xdeadbeef);
1952 h2
= CreateFileA( filename
, access_modes
[a2
], sharing_modes
[s2
],
1953 NULL
, OPEN_EXISTING
, 0, 0 );
1955 ret
= GetLastError();
1956 if (h2
== INVALID_HANDLE_VALUE
)
1958 ok( !is_sharing_map_compatible(mapping_modes
[a1
], access_modes
[a2
], sharing_modes
[s2
]),
1959 "open failed for modes map %x/%x/%x\n",
1960 mapping_modes
[a1
], access_modes
[a2
], sharing_modes
[s2
] );
1961 ok( ret
== ERROR_SHARING_VIOLATION
,
1962 "wrong error code %d\n", ret
);
1966 if (!is_sharing_map_compatible(mapping_modes
[a1
], access_modes
[a2
], sharing_modes
[s2
]))
1967 ok( broken(1), /* no checking on nt4 */
1968 "open succeeded for modes map %x/%x/%x\n",
1969 mapping_modes
[a1
], access_modes
[a2
], sharing_modes
[s2
] );
1970 ok( ret
== 0xdeadbeef /* Win9x */ ||
1972 "wrong error code %d\n", ret
);
1978 /* try CREATE_ALWAYS over an existing mapping */
1979 SetLastError(0xdeadbeef);
1980 h2
= CreateFileA( filename
, GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1981 NULL
, CREATE_ALWAYS
, 0, 0 );
1982 ret
= GetLastError();
1983 if (mapping_modes
[a1
] & SEC_IMAGE
)
1985 ok( h2
== INVALID_HANDLE_VALUE
, "create succeeded for map %x\n", mapping_modes
[a1
] );
1986 ok( ret
== ERROR_SHARING_VIOLATION
, "wrong error code %d for %x\n", ret
, mapping_modes
[a1
] );
1990 ok( h2
== INVALID_HANDLE_VALUE
, "create succeeded for map %x\n", mapping_modes
[a1
] );
1991 ok( ret
== ERROR_USER_MAPPED_FILE
, "wrong error code %d for %x\n", ret
, mapping_modes
[a1
] );
1993 if (h2
!= INVALID_HANDLE_VALUE
) CloseHandle( h2
);
1995 /* try DELETE_ON_CLOSE over an existing mapping */
1996 SetLastError(0xdeadbeef);
1997 h2
= CreateFileA( filename
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1998 NULL
, OPEN_EXISTING
, FILE_FLAG_DELETE_ON_CLOSE
, 0 );
1999 ret
= GetLastError();
2000 if (mapping_modes
[a1
] & SEC_IMAGE
)
2002 ok( h2
== INVALID_HANDLE_VALUE
, "create succeeded for map %x\n", mapping_modes
[a1
] );
2003 ok( ret
== ERROR_ACCESS_DENIED
, "wrong error code %d for %x\n", ret
, mapping_modes
[a1
] );
2007 ok( h2
!= INVALID_HANDLE_VALUE
, "open failed for map %x err %u\n", mapping_modes
[a1
], ret
);
2009 if (h2
!= INVALID_HANDLE_VALUE
) CloseHandle( h2
);
2014 SetLastError(0xdeadbeef);
2015 h
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, FILE_SHARE_READ
, NULL
, OPEN_ALWAYS
, 0, 0 );
2016 ok( h
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError() );
2018 SetLastError(0xdeadbeef);
2019 h2
= CreateFileA( filename
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0 );
2020 ok( h2
== INVALID_HANDLE_VALUE
, "CreateFileA should fail\n");
2021 ok( GetLastError() == ERROR_SHARING_VIOLATION
, "wrong error code %d\n", GetLastError() );
2023 h2
= CreateFileA( filename
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
2024 ok( h2
!= INVALID_HANDLE_VALUE
, "CreateFileA error %d\n", GetLastError() );
2029 DeleteFileA( filename
);
2032 static char get_windows_drive(void)
2034 char windowsdir
[MAX_PATH
];
2035 GetWindowsDirectory(windowsdir
, sizeof(windowsdir
));
2036 return windowsdir
[0];
2039 static void test_FindFirstFileA(void)
2042 WIN32_FIND_DATAA data
;
2044 char buffer
[5] = "C:\\";
2046 char nonexistent
[MAX_PATH
];
2048 /* try FindFirstFileA on "C:\" */
2049 buffer
[0] = get_windows_drive();
2051 SetLastError( 0xdeadbeaf );
2052 handle
= FindFirstFileA(buffer
, &data
);
2053 err
= GetLastError();
2054 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on root directory should fail\n" );
2055 ok ( err
== ERROR_FILE_NOT_FOUND
, "Bad Error number %d\n", err
);
2057 /* try FindFirstFileA on "C:\*" */
2058 strcpy(buffer2
, buffer
);
2059 strcat(buffer2
, "*");
2060 handle
= FindFirstFileA(buffer2
, &data
);
2061 ok ( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s should succeed\n", buffer2
);
2062 ok ( strcmp( data
.cFileName
, "." ) && strcmp( data
.cFileName
, ".." ),
2063 "FindFirstFile shouldn't return '%s' in drive root\n", data
.cFileName
);
2064 if (FindNextFileA( handle
, &data
))
2065 ok ( strcmp( data
.cFileName
, "." ) && strcmp( data
.cFileName
, ".." ),
2066 "FindNextFile shouldn't return '%s' in drive root\n", data
.cFileName
);
2067 ok ( FindClose(handle
) == TRUE
, "Failed to close handle %s\n", buffer2
);
2069 /* try FindFirstFileA on windows dir */
2070 GetWindowsDirectory( buffer2
, sizeof(buffer2
) );
2071 strcat(buffer2
, "\\*");
2072 handle
= FindFirstFileA(buffer2
, &data
);
2073 ok( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s should succeed\n", buffer2
);
2074 ok( !strcmp( data
.cFileName
, "." ), "FindFirstFile should return '.' first\n" );
2075 ok( FindNextFileA( handle
, &data
), "FindNextFile failed\n" );
2076 ok( !strcmp( data
.cFileName
, ".." ), "FindNextFile should return '..' as second entry\n" );
2077 while (FindNextFileA( handle
, &data
))
2078 ok ( strcmp( data
.cFileName
, "." ) && strcmp( data
.cFileName
, ".." ),
2079 "FindNextFile shouldn't return '%s'\n", data
.cFileName
);
2080 ok ( FindClose(handle
) == TRUE
, "Failed to close handle %s\n", buffer2
);
2082 /* try FindFirstFileA on "C:\foo\" */
2083 SetLastError( 0xdeadbeaf );
2084 if (!GetTempFileNameA( buffer
, "foo", 0, nonexistent
) && GetLastError() == ERROR_ACCESS_DENIED
)
2087 GetTempPathA( sizeof(tmp
), tmp
);
2088 GetTempFileNameA( tmp
, "foo", 0, nonexistent
);
2090 DeleteFileA( nonexistent
);
2091 strcpy(buffer2
, nonexistent
);
2092 strcat(buffer2
, "\\");
2093 handle
= FindFirstFileA(buffer2
, &data
);
2094 err
= GetLastError();
2095 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2097 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
2100 /* try FindFirstFileA on "C:\foo\bar.txt" */
2101 SetLastError( 0xdeadbeaf );
2102 strcpy(buffer2
, nonexistent
);
2103 strcat(buffer2
, "\\bar.txt");
2104 handle
= FindFirstFileA(buffer2
, &data
);
2105 err
= GetLastError();
2106 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2107 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
2109 /* try FindFirstFileA on "C:\foo\*.*" */
2110 SetLastError( 0xdeadbeaf );
2111 strcpy(buffer2
, nonexistent
);
2112 strcat(buffer2
, "\\*.*");
2113 handle
= FindFirstFileA(buffer2
, &data
);
2114 err
= GetLastError();
2115 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2116 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
2118 /* try FindFirstFileA on "foo\bar.txt" */
2119 SetLastError( 0xdeadbeaf );
2120 strcpy(buffer2
, nonexistent
+ 3);
2121 strcat(buffer2
, "\\bar.txt");
2122 handle
= FindFirstFileA(buffer2
, &data
);
2123 err
= GetLastError();
2124 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2125 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
2127 /* try FindFirstFileA on "c:\nul" */
2128 SetLastError( 0xdeadbeaf );
2129 strcpy(buffer2
, buffer
);
2130 strcat(buffer2
, "nul");
2131 handle
= FindFirstFileA(buffer2
, &data
);
2132 err
= GetLastError();
2133 ok( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s failed: %d\n", buffer2
, err
);
2134 ok( 0 == lstrcmpiA(data
.cFileName
, "nul"), "wrong name %s\n", data
.cFileName
);
2135 ok( FILE_ATTRIBUTE_ARCHIVE
== data
.dwFileAttributes
||
2136 FILE_ATTRIBUTE_DEVICE
== data
.dwFileAttributes
/* Win9x */,
2137 "wrong attributes %x\n", data
.dwFileAttributes
);
2138 if (data
.dwFileAttributes
== FILE_ATTRIBUTE_ARCHIVE
)
2140 ok( 0 == data
.nFileSizeHigh
, "wrong size %d\n", data
.nFileSizeHigh
);
2141 ok( 0 == data
.nFileSizeLow
, "wrong size %d\n", data
.nFileSizeLow
);
2143 SetLastError( 0xdeadbeaf );
2144 ok( !FindNextFileA( handle
, &data
), "FindNextFileA succeeded\n" );
2145 ok( GetLastError() == ERROR_NO_MORE_FILES
, "bad error %d\n", GetLastError() );
2146 ok( FindClose( handle
), "failed to close handle\n" );
2148 /* try FindFirstFileA on "lpt1" */
2149 SetLastError( 0xdeadbeaf );
2150 strcpy(buffer2
, "lpt1");
2151 handle
= FindFirstFileA(buffer2
, &data
);
2152 err
= GetLastError();
2153 ok( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on %s failed: %d\n", buffer2
, err
);
2154 ok( 0 == lstrcmpiA(data
.cFileName
, "lpt1"), "wrong name %s\n", data
.cFileName
);
2155 ok( FILE_ATTRIBUTE_ARCHIVE
== data
.dwFileAttributes
||
2156 FILE_ATTRIBUTE_DEVICE
== data
.dwFileAttributes
/* Win9x */,
2157 "wrong attributes %x\n", data
.dwFileAttributes
);
2158 if (data
.dwFileAttributes
== FILE_ATTRIBUTE_ARCHIVE
)
2160 ok( 0 == data
.nFileSizeHigh
, "wrong size %d\n", data
.nFileSizeHigh
);
2161 ok( 0 == data
.nFileSizeLow
, "wrong size %d\n", data
.nFileSizeLow
);
2163 SetLastError( 0xdeadbeaf );
2164 ok( !FindNextFileA( handle
, &data
), "FindNextFileA succeeded\n" );
2165 ok( GetLastError() == ERROR_NO_MORE_FILES
, "bad error %d\n", GetLastError() );
2166 ok( FindClose( handle
), "failed to close handle\n" );
2168 /* try FindFirstFileA on "c:\nul\*" */
2169 SetLastError( 0xdeadbeaf );
2170 strcpy(buffer2
, buffer
);
2171 strcat(buffer2
, "nul\\*");
2172 handle
= FindFirstFileA(buffer2
, &data
);
2173 err
= GetLastError();
2174 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2175 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
2177 /* try FindFirstFileA on "c:\nul*" */
2178 SetLastError( 0xdeadbeaf );
2179 strcpy(buffer2
, buffer
);
2180 strcat(buffer2
, "nul*");
2181 handle
= FindFirstFileA(buffer2
, &data
);
2182 err
= GetLastError();
2183 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2184 ok ( err
== ERROR_FILE_NOT_FOUND
, "Bad Error number %d\n", err
);
2186 /* try FindFirstFileA on "c:\foo\bar\nul" */
2187 SetLastError( 0xdeadbeaf );
2188 strcpy(buffer2
, buffer
);
2189 strcat(buffer2
, "foo\\bar\\nul");
2190 handle
= FindFirstFileA(buffer2
, &data
);
2191 err
= GetLastError();
2192 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2193 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
2195 /* try FindFirstFileA on "c:\foo\nul\bar" */
2196 SetLastError( 0xdeadbeaf );
2197 strcpy(buffer2
, buffer
);
2198 strcat(buffer2
, "foo\\nul\\bar");
2199 handle
= FindFirstFileA(buffer2
, &data
);
2200 err
= GetLastError();
2201 ok ( handle
== INVALID_HANDLE_VALUE
, "FindFirstFile on %s should Fail\n", buffer2
);
2202 ok ( err
== ERROR_PATH_NOT_FOUND
, "Bad Error number %d\n", err
);
2205 static void test_FindNextFileA(void)
2208 WIN32_FIND_DATAA search_results
;
2210 char buffer
[5] = "C:\\*";
2212 buffer
[0] = get_windows_drive();
2213 handle
= FindFirstFileA(buffer
,&search_results
);
2214 ok ( handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile on C:\\* should succeed\n" );
2215 while (FindNextFile(handle
, &search_results
))
2217 /* get to the end of the files */
2219 ok ( FindClose(handle
) == TRUE
, "Failed to close handle\n");
2220 err
= GetLastError();
2221 ok ( err
== ERROR_NO_MORE_FILES
, "GetLastError should return ERROR_NO_MORE_FILES\n");
2224 static void test_FindFirstFileExA(FINDEX_SEARCH_OPS search_ops
)
2226 WIN32_FIND_DATAA search_results
;
2230 if (!pFindFirstFileExA
)
2232 win_skip("FindFirstFileExA() is missing\n");
2236 CreateDirectoryA("test-dir", NULL
);
2237 _lclose(_lcreat("test-dir\\file1", 0));
2238 _lclose(_lcreat("test-dir\\file2", 0));
2239 CreateDirectoryA("test-dir\\dir1", NULL
);
2240 SetLastError(0xdeadbeef);
2241 handle
= pFindFirstFileExA("test-dir\\*", FindExInfoStandard
, &search_results
, search_ops
, NULL
, 0);
2242 if (handle
== INVALID_HANDLE_VALUE
&& GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
2244 win_skip("FindFirstFileExA is not implemented\n");
2247 ok(handle
!= INVALID_HANDLE_VALUE
, "FindFirstFile failed (err=%u)\n", GetLastError());
2248 ok(strcmp(search_results
.cFileName
, ".") == 0, "First entry should be '.', is %s\n", search_results
.cFileName
);
2250 #define CHECK_NAME(fn) (strcmp((fn), "file1") == 0 || strcmp((fn), "file2") == 0 || strcmp((fn), "dir1") == 0)
2252 ok(FindNextFile(handle
, &search_results
), "Fetching second file failed\n");
2253 ok(strcmp(search_results
.cFileName
, "..") == 0, "Second entry should be '..' is %s\n", search_results
.cFileName
);
2255 ok(FindNextFile(handle
, &search_results
), "Fetching third file failed\n");
2256 ok(CHECK_NAME(search_results
.cFileName
), "Invalid third entry - %s\n", search_results
.cFileName
);
2258 SetLastError(0xdeadbeef);
2259 ret
= FindNextFile(handle
, &search_results
);
2260 if (!ret
&& (GetLastError() == ERROR_NO_MORE_FILES
) && (search_ops
== FindExSearchLimitToDirectories
))
2262 skip("File system supports directory filtering\n");
2263 /* Results from the previous call are not cleared */
2264 ok(strcmp(search_results
.cFileName
, "dir1") == 0, "Third entry should be 'dir1' is %s\n", search_results
.cFileName
);
2265 FindClose( handle
);
2269 ok(ret
, "Fetching fourth file failed\n");
2270 ok(CHECK_NAME(search_results
.cFileName
), "Invalid fourth entry - %s\n", search_results
.cFileName
);
2272 ok(FindNextFile(handle
, &search_results
), "Fetching fifth file failed\n");
2273 ok(CHECK_NAME(search_results
.cFileName
), "Invalid fifth entry - %s\n", search_results
.cFileName
);
2277 ok(FindNextFile(handle
, &search_results
) == FALSE
, "Fetching sixth file should fail\n");
2279 FindClose( handle
);
2282 DeleteFileA("test-dir\\file1");
2283 DeleteFileA("test-dir\\file2");
2284 RemoveDirectoryA("test-dir\\dir1");
2285 RemoveDirectoryA("test-dir");
2288 static int test_Mapfile_createtemp(HANDLE
*handle
)
2290 SetFileAttributesA(filename
,FILE_ATTRIBUTE_NORMAL
);
2291 DeleteFile(filename
);
2292 *handle
= CreateFile(filename
, GENERIC_READ
|GENERIC_WRITE
, 0, 0,
2293 CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
2294 if (*handle
!= INVALID_HANDLE_VALUE
) {
2302 static void test_MapFile(void)
2307 ok(test_Mapfile_createtemp(&handle
), "Couldn't create test file.\n");
2309 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0, 0x1000, "named_file_map" );
2310 ok( hmap
!= NULL
, "mapping should work, I named it!\n" );
2312 ok( CloseHandle( hmap
), "can't close mapping handle\n");
2314 /* We have to close file before we try new stuff with mapping again.
2315 Else we would always succeed on XP or block descriptors on 95. */
2316 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0, 0, NULL
);
2317 ok( hmap
!= NULL
, "We should still be able to map!\n" );
2318 ok( CloseHandle( hmap
), "can't close mapping handle\n");
2319 ok( CloseHandle( handle
), "can't close file handle\n");
2322 ok(test_Mapfile_createtemp(&handle
), "Couldn't create test file.\n");
2324 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0, 0, NULL
);
2325 ok( hmap
== NULL
, "mapped zero size file\n");
2326 ok( GetLastError() == ERROR_FILE_INVALID
, "not ERROR_FILE_INVALID\n");
2328 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0x80000000, 0, NULL
);
2329 ok( hmap
== NULL
|| broken(hmap
!= NULL
) /* NT4 */, "mapping should fail\n");
2330 /* GetLastError() varies between win9x and WinNT and also depends on the filesystem */
2332 CloseHandle( hmap
);
2334 hmap
= CreateFileMapping( handle
, NULL
, PAGE_READWRITE
, 0x80000000, 0x10000, NULL
);
2335 ok( hmap
== NULL
|| broken(hmap
!= NULL
) /* NT4 */, "mapping should fail\n");
2336 /* GetLastError() varies between win9x and WinNT and also depends on the filesystem */
2338 CloseHandle( hmap
);
2340 /* On XP you can now map again, on Win 95 you cannot. */
2342 ok( CloseHandle( handle
), "can't close file handle\n");
2343 ok( DeleteFileA( filename
), "DeleteFile failed after map\n" );
2346 static void test_GetFileType(void)
2349 HANDLE h
= CreateFileA( filename
, GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
, 0, 0 );
2350 ok( h
!= INVALID_HANDLE_VALUE
, "open %s failed\n", filename
);
2351 type
= GetFileType(h
);
2352 ok( type
== FILE_TYPE_DISK
, "expected type disk got %d\n", type
);
2354 h
= CreateFileA( "nul", GENERIC_READ
|GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2355 ok( h
!= INVALID_HANDLE_VALUE
, "open nul failed\n" );
2356 type
= GetFileType(h
);
2357 ok( type
== FILE_TYPE_CHAR
, "expected type char for nul got %d\n", type
);
2359 DeleteFileA( filename
);
2362 static int completion_count
;
2364 static void CALLBACK
FileIOComplete(DWORD dwError
, DWORD dwBytes
, LPOVERLAPPED ovl
)
2366 /* printf("(%ld, %ld, %p { %ld, %ld, %ld, %ld, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->Offset, ovl->OffsetHigh, ovl->hEvent);*/
2367 ReleaseSemaphore(ovl
->hEvent
, 1, NULL
);
2371 static void test_async_file_errors(void)
2373 char szFile
[MAX_PATH
];
2374 HANDLE hSem
= CreateSemaphoreW(NULL
, 1, 1, NULL
);
2376 LPVOID lpBuffer
= HeapAlloc(GetProcessHeap(), 0, 4096);
2378 S(U(ovl
)).Offset
= 0;
2379 S(U(ovl
)).OffsetHigh
= 0;
2381 completion_count
= 0;
2383 GetWindowsDirectoryA(szFile
, sizeof(szFile
)/sizeof(szFile
[0])-1-strlen("\\win.ini"));
2384 strcat(szFile
, "\\win.ini");
2385 hFile
= CreateFileA(szFile
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
2386 NULL
, OPEN_ALWAYS
, FILE_FLAG_OVERLAPPED
, NULL
);
2387 if (hFile
== INVALID_HANDLE_VALUE
) /* win9x doesn't like FILE_SHARE_DELETE */
2388 hFile
= CreateFileA(szFile
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2389 NULL
, OPEN_ALWAYS
, FILE_FLAG_OVERLAPPED
, NULL
);
2390 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA(%s ...) failed\n", szFile
);
2395 while (WaitForSingleObjectEx(hSem
, INFINITE
, TRUE
) == WAIT_IO_COMPLETION
)
2397 res
= ReadFileEx(hFile
, lpBuffer
, 4096, &ovl
, FileIOComplete
);
2398 /*printf("Offset = %ld, result = %s\n", ovl.Offset, res ? "TRUE" : "FALSE");*/
2401 if (!GetOverlappedResult(hFile
, &ovl
, &count
, FALSE
))
2403 S(U(ovl
)).Offset
+= count
;
2404 /* i/o completion routine only called if ReadFileEx returned success.
2405 * we only care about violations of this rule so undo what should have
2409 ok(completion_count
== 0, "completion routine should only be called when ReadFileEx succeeds (this rule was violated %d times)\n", completion_count
);
2410 /*printf("Error = %ld\n", GetLastError());*/
2411 HeapFree(GetProcessHeap(), 0, lpBuffer
);
2414 static BOOL user_apc_ran
;
2415 static void CALLBACK
user_apc(ULONG_PTR param
)
2417 user_apc_ran
= TRUE
;
2420 static void test_read_write(void)
2422 DWORD bytes
, ret
, old_prot
;
2424 char temp_path
[MAX_PATH
];
2425 char filename
[MAX_PATH
];
2427 static const char prefix
[] = "pfx";
2429 ret
= GetTempPathA(MAX_PATH
, temp_path
);
2430 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
2431 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
2433 ret
= GetTempFileNameA(temp_path
, prefix
, 0, filename
);
2434 ok(ret
!= 0, "GetTempFileNameA error %d\n", GetLastError());
2436 hFile
= CreateFileA(filename
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
,
2437 CREATE_ALWAYS
, FILE_FLAG_RANDOM_ACCESS
, 0);
2438 ok(hFile
!= INVALID_HANDLE_VALUE
, "CreateFileA: error %d\n", GetLastError());
2440 user_apc_ran
= FALSE
;
2441 if (pQueueUserAPC
) {
2442 trace("Queueing an user APC\n"); /* verify the file is non alerable */
2443 ret
= pQueueUserAPC(&user_apc
, GetCurrentThread(), 0);
2444 ok(ret
, "QueueUserAPC failed: %d\n", GetLastError());
2447 SetLastError(12345678);
2449 ret
= WriteFile(hFile
, NULL
, 0, &bytes
, NULL
);
2450 ok(ret
&& GetLastError() == 12345678,
2451 "ret = %d, error %d\n", ret
, GetLastError());
2452 ok(!bytes
, "bytes = %d\n", bytes
);
2454 SetLastError(12345678);
2456 ret
= WriteFile(hFile
, NULL
, 10, &bytes
, NULL
);
2457 ok((!ret
&& GetLastError() == ERROR_INVALID_USER_BUFFER
) || /* Win2k */
2458 (ret
&& GetLastError() == 12345678), /* Win9x */
2459 "ret = %d, error %d\n", ret
, GetLastError());
2460 ok(!bytes
|| /* Win2k */
2461 bytes
== 10, /* Win9x */
2462 "bytes = %d\n", bytes
);
2464 /* make sure the file contains data */
2465 WriteFile(hFile
, "this is the test data", 21, &bytes
, NULL
);
2466 SetFilePointer(hFile
, 0, NULL
, FILE_BEGIN
);
2468 SetLastError(12345678);
2470 ret
= ReadFile(hFile
, NULL
, 0, &bytes
, NULL
);
2471 ok(ret
&& GetLastError() == 12345678,
2472 "ret = %d, error %d\n", ret
, GetLastError());
2473 ok(!bytes
, "bytes = %d\n", bytes
);
2475 SetLastError(12345678);
2477 ret
= ReadFile(hFile
, NULL
, 10, &bytes
, NULL
);
2478 ok(!ret
&& (GetLastError() == ERROR_NOACCESS
|| /* Win2k */
2479 GetLastError() == ERROR_INVALID_PARAMETER
), /* Win9x */
2480 "ret = %d, error %d\n", ret
, GetLastError());
2481 ok(!bytes
, "bytes = %d\n", bytes
);
2483 ok(user_apc_ran
== FALSE
, "UserAPC ran, file using alertable io mode\n");
2485 SleepEx(0, TRUE
); /* get rid of apc */
2487 /* test passing protected memory as buffer */
2489 mem
= VirtualAlloc( NULL
, 0x4000, MEM_COMMIT
, PAGE_READWRITE
);
2490 ok( mem
!= NULL
, "failed to allocate virtual mem error %u\n", GetLastError() );
2492 ret
= WriteFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
2493 ok( ret
, "WriteFile failed error %u\n", GetLastError() );
2494 ok( bytes
== 0x4000, "only wrote %x bytes\n", bytes
);
2496 ret
= VirtualProtect( mem
+ 0x2000, 0x2000, PAGE_NOACCESS
, &old_prot
);
2497 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
2499 ret
= WriteFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
2500 ok( !ret
, "WriteFile succeeded\n" );
2501 ok( GetLastError() == ERROR_INVALID_USER_BUFFER
||
2502 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2503 "wrong error %u\n", GetLastError() );
2504 ok( bytes
== 0, "wrote %x bytes\n", bytes
);
2506 ret
= WriteFile( (HANDLE
)0xdead, mem
, 0x4000, &bytes
, NULL
);
2507 ok( !ret
, "WriteFile succeeded\n" );
2508 ok( GetLastError() == ERROR_INVALID_HANDLE
|| /* handle is checked before buffer on NT */
2509 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2510 "wrong error %u\n", GetLastError() );
2511 ok( bytes
== 0, "wrote %x bytes\n", bytes
);
2513 ret
= VirtualProtect( mem
, 0x2000, PAGE_NOACCESS
, &old_prot
);
2514 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
2516 ret
= WriteFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
2517 ok( !ret
, "WriteFile succeeded\n" );
2518 ok( GetLastError() == ERROR_INVALID_USER_BUFFER
||
2519 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2520 "wrong error %u\n", GetLastError() );
2521 ok( bytes
== 0, "wrote %x bytes\n", bytes
);
2523 SetFilePointer( hFile
, 0, NULL
, FILE_BEGIN
);
2525 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
2526 ok( !ret
, "ReadFile succeeded\n" );
2527 ok( GetLastError() == ERROR_NOACCESS
||
2528 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2529 "wrong error %u\n", GetLastError() );
2530 ok( bytes
== 0, "read %x bytes\n", bytes
);
2532 ret
= VirtualProtect( mem
, 0x2000, PAGE_READONLY
, &old_prot
);
2533 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
2535 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
2536 ok( !ret
, "ReadFile succeeded\n" );
2537 ok( GetLastError() == ERROR_NOACCESS
||
2538 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2539 "wrong error %u\n", GetLastError() );
2540 ok( bytes
== 0, "read %x bytes\n", bytes
);
2542 ret
= VirtualProtect( mem
, 0x2000, PAGE_READWRITE
, &old_prot
);
2543 ok( ret
, "VirtualProtect failed error %u\n", GetLastError() );
2545 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
2546 ok( !ret
, "ReadFile succeeded\n" );
2547 ok( GetLastError() == ERROR_NOACCESS
||
2548 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2549 "wrong error %u\n", GetLastError() );
2550 ok( bytes
== 0, "read %x bytes\n", bytes
);
2552 SetFilePointer( hFile
, 0x1234, NULL
, FILE_BEGIN
);
2553 SetEndOfFile( hFile
);
2554 SetFilePointer( hFile
, 0, NULL
, FILE_BEGIN
);
2556 ret
= ReadFile( hFile
, mem
, 0x4000, &bytes
, NULL
);
2557 ok( !ret
, "ReadFile succeeded\n" );
2558 ok( GetLastError() == ERROR_NOACCESS
||
2559 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2560 "wrong error %u\n", GetLastError() );
2561 ok( bytes
== 0, "read %x bytes\n", bytes
);
2563 ret
= ReadFile( hFile
, mem
, 0x2000, &bytes
, NULL
);
2564 ok( ret
, "ReadFile failed error %u\n", GetLastError() );
2565 ok( bytes
== 0x1234, "read %x bytes\n", bytes
);
2567 ret
= ReadFile( hFile
, NULL
, 1, &bytes
, NULL
);
2568 ok( !ret
, "ReadFile succeeded\n" );
2569 ok( GetLastError() == ERROR_NOACCESS
||
2570 GetLastError() == ERROR_INVALID_PARAMETER
, /* win9x */
2571 "wrong error %u\n", GetLastError() );
2572 ok( bytes
== 0, "read %x bytes\n", bytes
);
2574 VirtualFree( mem
, 0, MEM_FREE
);
2576 ret
= CloseHandle(hFile
);
2577 ok( ret
, "CloseHandle: error %d\n", GetLastError());
2578 ret
= DeleteFileA(filename
);
2579 ok( ret
, "DeleteFileA: error %d\n", GetLastError());
2582 static void test_OpenFile(void)
2589 static const char file
[] = "regedit.exe";
2590 static const char foo
[] = ".\\foo-bar-foo.baz";
2591 static const char *foo_too_long
= ".\\foo-bar-foo.baz+++++++++++++++"
2592 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
2593 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
2594 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
2595 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
2596 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++";
2597 char buff
[MAX_PATH
];
2598 char buff_long
[4*MAX_PATH
];
2599 char filled_0xA5
[OFS_MAXPATHNAME
];
2603 /* Check for existing file */
2604 if (!pGetSystemWindowsDirectoryA
)
2605 length
= GetWindowsDirectoryA(buff
, MAX_PATH
);
2607 length
= pGetSystemWindowsDirectoryA(buff
, MAX_PATH
);
2609 if (length
+ sizeof(file
) < MAX_PATH
)
2611 p
= buff
+ strlen(buff
);
2612 if (p
> buff
&& p
[-1] != '\\') *p
++ = '\\';
2614 memset(&ofs
, 0xA5, sizeof(ofs
));
2615 SetLastError(0xfaceabee);
2617 hFile
= OpenFile(buff
, &ofs
, OF_EXIST
);
2618 ok( hFile
== TRUE
, "%s not found : %d\n", buff
, GetLastError() );
2619 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2620 "GetLastError() returns %d\n", GetLastError() );
2621 ok( ofs
.cBytes
== sizeof(ofs
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2622 ok( ofs
.nErrCode
== ERROR_SUCCESS
, "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2623 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2624 "OpenFile returned '%s', but was expected to return '%s' or string filled with 0xA5\n",
2625 ofs
.szPathName
, buff
);
2628 memset(&filled_0xA5
, 0xA5, OFS_MAXPATHNAME
);
2629 length
= GetCurrentDirectoryA(MAX_PATH
, buff
);
2631 /* Check for nonexistent file */
2632 if (length
+ sizeof(foo
) < MAX_PATH
)
2634 p
= buff
+ strlen(buff
);
2635 if (p
> buff
&& p
[-1] != '\\') *p
++ = '\\';
2636 strcpy( p
, foo
+ 2 );
2637 memset(&ofs
, 0xA5, sizeof(ofs
));
2638 SetLastError(0xfaceabee);
2640 hFile
= OpenFile(foo
, &ofs
, OF_EXIST
);
2641 ok( hFile
== HFILE_ERROR
, "hFile != HFILE_ERROR : %d\n", GetLastError());
2642 ok( GetLastError() == ERROR_FILE_NOT_FOUND
, "GetLastError() returns %d\n", GetLastError() );
2644 ok( ofs
.cBytes
== 0xA5, "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2645 ok( ofs
.nErrCode
== ERROR_FILE_NOT_FOUND
, "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2646 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0 || strncmp(ofs
.szPathName
, filled_0xA5
, OFS_MAXPATHNAME
) == 0,
2647 "OpenFile returned '%s', but was expected to return '%s' or string filled with 0xA5\n",
2648 ofs
.szPathName
, buff
);
2651 length
= GetCurrentDirectoryA(MAX_PATH
, buff_long
);
2652 length
+= lstrlenA(foo_too_long
+ 1);
2654 /* Check for nonexistent file with too long filename */
2655 if (length
>= OFS_MAXPATHNAME
&& length
< sizeof(buff_long
))
2657 lstrcatA(buff_long
, foo_too_long
+ 1); /* Avoid '.' during concatenation */
2658 memset(&ofs
, 0xA5, sizeof(ofs
));
2659 SetLastError(0xfaceabee);
2661 hFile
= OpenFile(foo_too_long
, &ofs
, OF_EXIST
);
2662 ok( hFile
== HFILE_ERROR
, "hFile != HFILE_ERROR : %d\n", GetLastError());
2663 ok( GetLastError() == ERROR_INVALID_DATA
|| GetLastError() == ERROR_FILENAME_EXCED_RANGE
,
2664 "GetLastError() returns %d\n", GetLastError() );
2666 ok( ofs
.cBytes
== 0xA5, "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2667 ok( ofs
.nErrCode
== ERROR_INVALID_DATA
|| ofs
.nErrCode
== ERROR_FILENAME_EXCED_RANGE
,
2668 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2669 ok( strncmp(ofs
.szPathName
, filled_0xA5
, OFS_MAXPATHNAME
) == 0,
2670 "OpenFile returned '%s', but was expected to return string filled with 0xA5\n",
2674 length
= GetCurrentDirectoryA(MAX_PATH
, buff
) + sizeof(filename
);
2676 if (length
>= MAX_PATH
)
2678 trace("Buffer too small, requested length = %d, but MAX_PATH = %d. Skipping test.\n", length
, MAX_PATH
);
2681 p
= buff
+ strlen(buff
);
2682 if (p
> buff
&& p
[-1] != '\\') *p
++ = '\\';
2683 strcpy( p
, filename
);
2685 memset(&ofs
, 0xA5, sizeof(ofs
));
2686 SetLastError(0xfaceabee);
2687 /* Create an empty file */
2688 hFile
= OpenFile(filename
, &ofs
, OF_CREATE
);
2689 ok( hFile
!= HFILE_ERROR
, "OpenFile failed to create nonexistent file\n" );
2690 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2691 "GetLastError() returns %d\n", GetLastError() );
2692 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2693 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
2694 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2695 ret
= _lclose(hFile
);
2696 ok( !ret
, "_lclose() returns %d\n", ret
);
2697 retval
= GetFileAttributesA(filename
);
2698 ok( retval
!= INVALID_FILE_ATTRIBUTES
, "GetFileAttributesA: error %d\n", GetLastError() );
2700 memset(&ofs
, 0xA5, sizeof(ofs
));
2701 SetLastError(0xfaceabee);
2702 /* Check various opening options: */
2703 /* for reading only, */
2704 hFile
= OpenFile(filename
, &ofs
, OF_READ
);
2705 ok( hFile
!= HFILE_ERROR
, "OpenFile failed on read\n" );
2706 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2707 "GetLastError() returns %d\n", GetLastError() );
2708 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2709 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
2710 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2711 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2712 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
2713 ret
= _lclose(hFile
);
2714 ok( !ret
, "_lclose() returns %d\n", ret
);
2716 memset(&ofs
, 0xA5, sizeof(ofs
));
2717 SetLastError(0xfaceabee);
2718 /* for writing only, */
2719 hFile
= OpenFile(filename
, &ofs
, OF_WRITE
);
2720 ok( hFile
!= HFILE_ERROR
, "OpenFile failed on write\n" );
2721 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2722 "GetLastError() returns %d\n", GetLastError() );
2723 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2724 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
2725 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2726 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2727 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
2728 ret
= _lclose(hFile
);
2729 ok( !ret
, "_lclose() returns %d\n", ret
);
2731 memset(&ofs
, 0xA5, sizeof(ofs
));
2732 SetLastError(0xfaceabee);
2733 /* for reading and writing, */
2734 hFile
= OpenFile(filename
, &ofs
, OF_READWRITE
);
2735 ok( hFile
!= HFILE_ERROR
, "OpenFile failed on read/write\n" );
2736 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2737 "GetLastError() returns %d\n", GetLastError() );
2738 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2739 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
2740 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2741 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2742 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
2743 ret
= _lclose(hFile
);
2744 ok( !ret
, "_lclose() returns %d\n", ret
);
2746 memset(&ofs
, 0xA5, sizeof(ofs
));
2747 SetLastError(0xfaceabee);
2748 /* for checking file presence. */
2749 hFile
= OpenFile(filename
, &ofs
, OF_EXIST
);
2750 ok( hFile
== 1, "OpenFile failed on finding our created file\n" );
2751 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2752 "GetLastError() returns %d\n", GetLastError() );
2753 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2754 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
2755 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2756 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2757 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
2759 memset(&ofs
, 0xA5, sizeof(ofs
));
2760 SetLastError(0xfaceabee);
2761 /* Delete the file and make sure it doesn't exist anymore */
2762 hFile
= OpenFile(filename
, &ofs
, OF_DELETE
);
2763 ok( hFile
== 1, "OpenFile failed on delete (%d)\n", hFile
);
2764 ok( GetLastError() == 0xfaceabee || GetLastError() == ERROR_SUCCESS
,
2765 "GetLastError() returns %d\n", GetLastError() );
2766 ok( ofs
.cBytes
== sizeof(OFSTRUCT
), "OpenFile set ofs.cBytes to %d\n", ofs
.cBytes
);
2767 ok( ofs
.nErrCode
== ERROR_SUCCESS
|| broken(ofs
.nErrCode
!= ERROR_SUCCESS
) /* win9x */,
2768 "OpenFile set ofs.nErrCode to %d\n", ofs
.nErrCode
);
2769 ok( lstrcmpiA(ofs
.szPathName
, buff
) == 0,
2770 "OpenFile returned '%s', but was expected to return '%s'\n", ofs
.szPathName
, buff
);
2772 retval
= GetFileAttributesA(filename
);
2773 ok( retval
== INVALID_FILE_ATTRIBUTES
, "GetFileAttributesA succeeded on deleted file\n" );
2776 static void test_overlapped(void)
2781 /* GetOverlappedResult crashes if the 2nd or 3rd param are NULL */
2782 if (0) /* tested: WinXP */
2784 GetOverlappedResult(0, NULL
, &result
, FALSE
);
2785 GetOverlappedResult(0, &ov
, NULL
, FALSE
);
2786 GetOverlappedResult(0, NULL
, NULL
, FALSE
);
2789 memset( &ov
, 0, sizeof ov
);
2791 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2793 ok( result
== 0, "wrong result %u\n", result
);
2795 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
2799 ov
.InternalHigh
= 0xabcd;
2800 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2802 ok( result
== 0xabcd, "wrong result %u\n", result
);
2804 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
2806 SetLastError( 0xb00 );
2808 ov
.Internal
= STATUS_INVALID_HANDLE
;
2809 ov
.InternalHigh
= 0xabcd;
2810 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2811 ok( GetLastError() == ERROR_INVALID_HANDLE
, "wrong error %u\n", GetLastError() );
2812 ok( r
== FALSE
, "should return false\n");
2813 ok( result
== 0xabcd || result
== 0 /* win9x */, "wrong result %u\n", result
);
2815 SetLastError( 0xb00 );
2817 ov
.Internal
= STATUS_PENDING
;
2818 ov
.InternalHigh
= 0xabcd;
2819 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2820 ok( GetLastError() == ERROR_IO_INCOMPLETE
|| GetLastError() == ERROR_INVALID_HANDLE
/* win9x */,
2821 "wrong error %u\n", GetLastError() );
2822 ok( r
== FALSE
, "should return false\n");
2823 ok( result
== 0, "wrong result %u\n", result
);
2825 SetLastError( 0xb00 );
2826 ov
.hEvent
= CreateEvent( NULL
, 1, 1, NULL
);
2827 ov
.Internal
= STATUS_PENDING
;
2828 ov
.InternalHigh
= 0xabcd;
2829 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2830 ok( GetLastError() == ERROR_IO_INCOMPLETE
|| GetLastError() == ERROR_INVALID_HANDLE
/* win9x */,
2831 "wrong error %u\n", GetLastError() );
2832 ok( r
== FALSE
, "should return false\n");
2834 ResetEvent( ov
.hEvent
);
2836 SetLastError( 0xb00 );
2837 ov
.Internal
= STATUS_PENDING
;
2838 ov
.InternalHigh
= 0;
2839 r
= GetOverlappedResult(0, &ov
, &result
, 0);
2840 ok( GetLastError() == ERROR_IO_INCOMPLETE
|| GetLastError() == ERROR_INVALID_HANDLE
/* win9x */,
2841 "wrong error %u\n", GetLastError() );
2842 ok( r
== FALSE
, "should return false\n");
2844 r
= CloseHandle( ov
.hEvent
);
2845 ok( r
== TRUE
, "close handle failed\n");
2848 static void test_RemoveDirectory(void)
2851 char directory
[] = "removeme";
2853 rc
= CreateDirectory(directory
, NULL
);
2854 ok( rc
, "Createdirectory failed, gle=%d\n", GetLastError() );
2856 rc
= SetCurrentDirectory(directory
);
2857 ok( rc
, "SetCurrentDirectory failed, gle=%d\n", GetLastError() );
2859 rc
= RemoveDirectory(".");
2862 rc
= SetCurrentDirectory("..");
2863 ok( rc
, "SetCurrentDirectory failed, gle=%d\n", GetLastError() );
2865 rc
= RemoveDirectory(directory
);
2866 ok( rc
, "RemoveDirectory failed, gle=%d\n", GetLastError() );
2870 static BOOL
check_file_time( const FILETIME
*ft1
, const FILETIME
*ft2
, UINT tolerance
)
2872 ULONGLONG t1
= ((ULONGLONG
)ft1
->dwHighDateTime
<< 32) | ft1
->dwLowDateTime
;
2873 ULONGLONG t2
= ((ULONGLONG
)ft2
->dwHighDateTime
<< 32) | ft2
->dwLowDateTime
;
2874 return abs(t1
- t2
) <= tolerance
;
2877 static void test_ReplaceFileA(void)
2879 char replaced
[MAX_PATH
], replacement
[MAX_PATH
], backup
[MAX_PATH
];
2880 HANDLE hReplacedFile
, hReplacementFile
, hBackupFile
;
2881 static const char replacedData
[] = "file-to-replace";
2882 static const char replacementData
[] = "new-file";
2883 static const char backupData
[] = "backup-file";
2884 FILETIME ftReplaced
, ftReplacement
, ftBackup
;
2885 static const char prefix
[] = "pfx";
2886 char temp_path
[MAX_PATH
];
2888 BOOL retok
, removeBackup
= FALSE
;
2892 win_skip("ReplaceFileA() is missing\n");
2896 ret
= GetTempPathA(MAX_PATH
, temp_path
);
2897 ok(ret
!= 0, "GetTempPathA error %d\n", GetLastError());
2898 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
2900 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replaced
);
2901 ok(ret
!= 0, "GetTempFileNameA error (replaced) %d\n", GetLastError());
2903 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
2904 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
2906 ret
= GetTempFileNameA(temp_path
, prefix
, 0, backup
);
2907 ok(ret
!= 0, "GetTempFileNameA error (backup) %d\n", GetLastError());
2909 /* place predictable data in the file to be replaced */
2910 hReplacedFile
= CreateFileA(replaced
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2911 ok(hReplacedFile
!= INVALID_HANDLE_VALUE
,
2912 "failed to open replaced file\n");
2913 retok
= WriteFile(hReplacedFile
, replacedData
, sizeof(replacedData
), &ret
, NULL
);
2914 ok( retok
&& ret
== sizeof(replacedData
),
2915 "WriteFile error (replaced) %d\n", GetLastError());
2916 ok(GetFileSize(hReplacedFile
, NULL
) == sizeof(replacedData
),
2917 "replaced file has wrong size\n");
2918 /* place predictable data in the file to be the replacement */
2919 hReplacementFile
= CreateFileA(replacement
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2920 ok(hReplacementFile
!= INVALID_HANDLE_VALUE
,
2921 "failed to open replacement file\n");
2922 retok
= WriteFile(hReplacementFile
, replacementData
, sizeof(replacementData
), &ret
, NULL
);
2923 ok( retok
&& ret
== sizeof(replacementData
),
2924 "WriteFile error (replacement) %d\n", GetLastError());
2925 ok(GetFileSize(hReplacementFile
, NULL
) == sizeof(replacementData
),
2926 "replacement file has wrong size\n");
2927 /* place predictable data in the backup file (to be over-written) */
2928 hBackupFile
= CreateFileA(backup
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0 );
2929 ok(hBackupFile
!= INVALID_HANDLE_VALUE
,
2930 "failed to open backup file\n");
2931 retok
= WriteFile(hBackupFile
, backupData
, sizeof(backupData
), &ret
, NULL
);
2932 ok( retok
&& ret
== sizeof(backupData
),
2933 "WriteFile error (replacement) %d\n", GetLastError());
2934 ok(GetFileSize(hBackupFile
, NULL
) == sizeof(backupData
),
2935 "backup file has wrong size\n");
2936 /* change the filetime on the "replaced" file to ensure that it changes */
2937 ret
= GetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
);
2938 ok( ret
, "GetFileTime error (replaced) %d\n", GetLastError());
2939 ftReplaced
.dwLowDateTime
-= 600000000; /* 60 second */
2940 ret
= SetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
);
2941 ok( ret
, "SetFileTime error (replaced) %d\n", GetLastError());
2942 GetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
); /* get the actual time back */
2943 CloseHandle(hReplacedFile
);
2944 /* change the filetime on the backup to ensure that it changes */
2945 ret
= GetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
);
2946 ok( ret
, "GetFileTime error (backup) %d\n", GetLastError());
2947 ftBackup
.dwLowDateTime
-= 1200000000; /* 120 second */
2948 ret
= SetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
);
2949 ok( ret
, "SetFileTime error (backup) %d\n", GetLastError());
2950 GetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
); /* get the actual time back */
2951 CloseHandle(hBackupFile
);
2952 /* get the filetime on the replacement file to perform checks */
2953 ret
= GetFileTime(hReplacementFile
, NULL
, NULL
, &ftReplacement
);
2954 ok( ret
, "GetFileTime error (replacement) %d\n", GetLastError());
2955 CloseHandle(hReplacementFile
);
2957 /* perform replacement w/ backup
2958 * TODO: flags are not implemented
2960 SetLastError(0xdeadbeef);
2961 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
2962 ok(ret
, "ReplaceFileA: unexpected error %d\n", GetLastError());
2963 /* make sure that the backup has the size of the old "replaced" file */
2964 hBackupFile
= CreateFileA(backup
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
2965 ok(hBackupFile
!= INVALID_HANDLE_VALUE
,
2966 "failed to open backup file\n");
2967 ret
= GetFileSize(hBackupFile
, NULL
);
2968 ok(ret
== sizeof(replacedData
),
2969 "backup file has wrong size %d\n", ret
);
2970 /* make sure that the "replaced" file has the size of the replacement file */
2971 hReplacedFile
= CreateFileA(replaced
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
2972 ok(hReplacedFile
!= INVALID_HANDLE_VALUE
,
2973 "failed to open replaced file: %d\n", GetLastError());
2974 if (hReplacedFile
!= INVALID_HANDLE_VALUE
)
2976 ret
= GetFileSize(hReplacedFile
, NULL
);
2977 ok(ret
== sizeof(replacementData
),
2978 "replaced file has wrong size %d\n", ret
);
2979 /* make sure that the replacement file no-longer exists */
2980 hReplacementFile
= CreateFileA(replacement
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
2981 ok(hReplacementFile
== INVALID_HANDLE_VALUE
,
2982 "unexpected error, replacement file should not exist %d\n", GetLastError());
2983 /* make sure that the backup has the old "replaced" filetime */
2984 ret
= GetFileTime(hBackupFile
, NULL
, NULL
, &ftBackup
);
2985 ok( ret
, "GetFileTime error (backup %d\n", GetLastError());
2986 ok(check_file_time(&ftBackup
, &ftReplaced
, 20000000), "backup file has wrong filetime\n");
2987 CloseHandle(hBackupFile
);
2988 /* make sure that the "replaced" has the old replacement filetime */
2989 ret
= GetFileTime(hReplacedFile
, NULL
, NULL
, &ftReplaced
);
2990 ok( ret
, "GetFileTime error (backup %d\n", GetLastError());
2991 ok(check_file_time(&ftReplaced
, &ftReplacement
, 20000000),
2992 "replaced file has wrong filetime %x%08x / %x%08x\n",
2993 ftReplaced
.dwHighDateTime
, ftReplaced
.dwLowDateTime
,
2994 ftReplacement
.dwHighDateTime
, ftReplacement
.dwLowDateTime
);
2995 CloseHandle(hReplacedFile
);
2998 skip("couldn't open replacement file, skipping tests\n");
3000 /* re-create replacement file for pass w/o backup (blank) */
3001 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
3002 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
3003 /* perform replacement w/o backup
3004 * TODO: flags are not implemented
3006 SetLastError(0xdeadbeef);
3007 ret
= pReplaceFileA(replaced
, replacement
, NULL
, 0, 0, 0);
3008 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3009 "ReplaceFileA: unexpected error %d\n", GetLastError());
3011 /* re-create replacement file for pass w/ backup (backup-file not existing) */
3012 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
3013 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
3014 ret
= DeleteFileA(backup
);
3015 ok(ret
, "DeleteFileA: error (backup) %d\n", GetLastError());
3016 /* perform replacement w/ backup (no pre-existing backup)
3017 * TODO: flags are not implemented
3019 SetLastError(0xdeadbeef);
3020 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
3021 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3022 "ReplaceFileA: unexpected error %d\n", GetLastError());
3024 removeBackup
= TRUE
;
3026 /* re-create replacement file for pass w/ no permissions to "replaced" */
3027 ret
= GetTempFileNameA(temp_path
, prefix
, 0, replacement
);
3028 ok(ret
!= 0, "GetTempFileNameA error (replacement) %d\n", GetLastError());
3029 ret
= SetFileAttributesA(replaced
, FILE_ATTRIBUTE_READONLY
);
3030 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3031 "SetFileAttributesA: error setting to read only %d\n", GetLastError());
3032 /* perform replacement w/ backup (no permission to "replaced")
3033 * TODO: flags are not implemented
3035 SetLastError(0xdeadbeef);
3036 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
3037 ok(ret
!= ERROR_UNABLE_TO_REMOVE_REPLACED
, "ReplaceFileA: unexpected error %d\n", GetLastError());
3038 /* make sure that the replacement file still exists */
3039 hReplacementFile
= CreateFileA(replacement
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
3040 ok(hReplacementFile
!= INVALID_HANDLE_VALUE
||
3041 broken(GetLastError() == ERROR_FILE_NOT_FOUND
), /* win2k */
3042 "unexpected error, replacement file should still exist %d\n", GetLastError());
3043 CloseHandle(hReplacementFile
);
3044 ret
= SetFileAttributesA(replaced
, FILE_ATTRIBUTE_NORMAL
);
3045 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3046 "SetFileAttributesA: error setting to normal %d\n", GetLastError());
3048 /* replacement file still exists, make pass w/o "replaced" */
3049 ret
= DeleteFileA(replaced
);
3050 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3051 "DeleteFileA: error (replaced) %d\n", GetLastError());
3052 /* perform replacement w/ backup (no pre-existing backup or "replaced")
3053 * TODO: flags are not implemented
3055 SetLastError(0xdeadbeef);
3056 ret
= pReplaceFileA(replaced
, replacement
, backup
, 0, 0, 0);
3057 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
3058 GetLastError() == ERROR_ACCESS_DENIED
),
3059 "ReplaceFileA: unexpected error %d\n", GetLastError());
3061 /* perform replacement w/o existing "replacement" file
3062 * TODO: flags are not implemented
3064 SetLastError(0xdeadbeef);
3065 ret
= pReplaceFileA(replaced
, replacement
, NULL
, 0, 0, 0);
3066 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
3067 GetLastError() == ERROR_ACCESS_DENIED
),
3068 "ReplaceFileA: unexpected error %d\n", GetLastError());
3069 DeleteFileA( replacement
);
3072 * if the first round (w/ backup) worked then as long as there is no
3073 * failure then there is no need to check this round (w/ backup is the
3074 * more complete case)
3077 /* delete temporary files, replacement and replaced are already deleted */
3080 ret
= DeleteFileA(backup
);
3082 broken(GetLastError() == ERROR_ACCESS_DENIED
), /* win2k */
3083 "DeleteFileA: error (backup) %d\n", GetLastError());
3088 * ReplaceFileW is a simpler case of ReplaceFileA, there is no
3089 * need to be as thorough.
3091 static void test_ReplaceFileW(void)
3093 WCHAR replaced
[MAX_PATH
], replacement
[MAX_PATH
], backup
[MAX_PATH
];
3094 static const WCHAR prefix
[] = {'p','f','x',0};
3095 WCHAR temp_path
[MAX_PATH
];
3097 BOOL removeBackup
= FALSE
;
3101 win_skip("ReplaceFileW() is missing\n");
3105 ret
= GetTempPathW(MAX_PATH
, temp_path
);
3106 if (ret
== 0 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED
)
3108 win_skip("GetTempPathW is not available\n");
3111 ok(ret
!= 0, "GetTempPathW error %d\n", GetLastError());
3112 ok(ret
< MAX_PATH
, "temp path should fit into MAX_PATH\n");
3114 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replaced
);
3115 ok(ret
!= 0, "GetTempFileNameW error (replaced) %d\n", GetLastError());
3117 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
3118 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
3120 ret
= GetTempFileNameW(temp_path
, prefix
, 0, backup
);
3121 ok(ret
!= 0, "GetTempFileNameW error (backup) %d\n", GetLastError());
3123 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
3124 ok(ret
, "ReplaceFileW: error %d\n", GetLastError());
3126 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
3127 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
3128 ret
= pReplaceFileW(replaced
, replacement
, NULL
, 0, 0, 0);
3129 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3130 "ReplaceFileW: error %d\n", GetLastError());
3132 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
3133 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
3134 ret
= DeleteFileW(backup
);
3135 ok(ret
, "DeleteFileW: error (backup) %d\n", GetLastError());
3136 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
3137 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3138 "ReplaceFileW: error %d\n", GetLastError());
3140 ret
= GetTempFileNameW(temp_path
, prefix
, 0, replacement
);
3141 ok(ret
!= 0, "GetTempFileNameW error (replacement) %d\n", GetLastError());
3142 ret
= SetFileAttributesW(replaced
, FILE_ATTRIBUTE_READONLY
);
3143 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3144 "SetFileAttributesW: error setting to read only %d\n", GetLastError());
3146 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
3147 ok(ret
!= ERROR_UNABLE_TO_REMOVE_REPLACED
,
3148 "ReplaceFileW: unexpected error %d\n", GetLastError());
3149 ret
= SetFileAttributesW(replaced
, FILE_ATTRIBUTE_NORMAL
);
3150 ok(ret
|| GetLastError() == ERROR_ACCESS_DENIED
,
3151 "SetFileAttributesW: error setting to normal %d\n", GetLastError());
3153 removeBackup
= TRUE
;
3155 ret
= DeleteFileW(replaced
);
3156 ok(ret
, "DeleteFileW: error (replaced) %d\n", GetLastError());
3157 ret
= pReplaceFileW(replaced
, replacement
, backup
, 0, 0, 0);
3158 ok(!ret
, "ReplaceFileW: error %d\n", GetLastError());
3160 ret
= pReplaceFileW(replaced
, replacement
, NULL
, 0, 0, 0);
3161 ok(!ret
&& (GetLastError() == ERROR_FILE_NOT_FOUND
||
3162 GetLastError() == ERROR_ACCESS_DENIED
),
3163 "ReplaceFileW: unexpected error %d\n", GetLastError());
3164 DeleteFileW( replacement
);
3168 ret
= DeleteFileW(backup
);
3170 broken(GetLastError() == ERROR_ACCESS_DENIED
), /* win2k */
3171 "DeleteFileW: error (backup) %d\n", GetLastError());
3175 static void test_CreatFile(void)
3177 static const struct test_data
3179 DWORD disposition
, access
, error
, clean_up
;
3182 /* 0 */ { 0, 0, ERROR_INVALID_PARAMETER
, 0 },
3183 /* 1 */ { 0, GENERIC_READ
, ERROR_INVALID_PARAMETER
, 0 },
3184 /* 2 */ { 0, GENERIC_READ
|GENERIC_WRITE
, ERROR_INVALID_PARAMETER
, 0 },
3185 /* 3 */ { CREATE_NEW
, 0, ERROR_FILE_EXISTS
, 1 },
3186 /* 4 */ { CREATE_NEW
, 0, 0, 1 },
3187 /* 5 */ { CREATE_NEW
, GENERIC_READ
, 0, 1 },
3188 /* 6 */ { CREATE_NEW
, GENERIC_WRITE
, 0, 1 },
3189 /* 7 */ { CREATE_NEW
, GENERIC_READ
|GENERIC_WRITE
, 0, 0 },
3190 /* 8 */ { CREATE_ALWAYS
, 0, 0, 0 },
3191 /* 9 */ { CREATE_ALWAYS
, GENERIC_READ
, 0, 0 },
3192 /* 10*/ { CREATE_ALWAYS
, GENERIC_WRITE
, 0, 0 },
3193 /* 11*/ { CREATE_ALWAYS
, GENERIC_READ
|GENERIC_WRITE
, 0, 1 },
3194 /* 12*/ { OPEN_EXISTING
, 0, ERROR_FILE_NOT_FOUND
, 0 },
3195 /* 13*/ { CREATE_ALWAYS
, 0, 0, 0 },
3196 /* 14*/ { OPEN_EXISTING
, 0, 0, 0 },
3197 /* 15*/ { OPEN_EXISTING
, GENERIC_READ
, 0, 0 },
3198 /* 16*/ { OPEN_EXISTING
, GENERIC_WRITE
, 0, 0 },
3199 /* 17*/ { OPEN_EXISTING
, GENERIC_READ
|GENERIC_WRITE
, 0, 1 },
3200 /* 18*/ { OPEN_ALWAYS
, 0, 0, 0 },
3201 /* 19*/ { OPEN_ALWAYS
, GENERIC_READ
, 0, 0 },
3202 /* 20*/ { OPEN_ALWAYS
, GENERIC_WRITE
, 0, 0 },
3203 /* 21*/ { OPEN_ALWAYS
, GENERIC_READ
|GENERIC_WRITE
, 0, 0 },
3204 /* 22*/ { TRUNCATE_EXISTING
, 0, ERROR_INVALID_PARAMETER
, 0 },
3205 /* 23*/ { TRUNCATE_EXISTING
, GENERIC_READ
, ERROR_INVALID_PARAMETER
, 0 },
3206 /* 24*/ { TRUNCATE_EXISTING
, GENERIC_WRITE
, 0, 0 },
3207 /* 25*/ { TRUNCATE_EXISTING
, GENERIC_READ
|GENERIC_WRITE
, 0, 0 }
3209 char temp_path
[MAX_PATH
];
3210 char file_name
[MAX_PATH
];
3211 DWORD i
, ret
, written
;
3214 GetTempPath(MAX_PATH
, temp_path
);
3215 GetTempFileName(temp_path
, "tmp", 0, file_name
);
3217 for (i
= 0; i
< sizeof(td
)/sizeof(td
[0]); i
++)
3219 SetLastError(0xdeadbeef);
3220 hfile
= CreateFile(file_name
, td
[i
].access
, 0, NULL
, td
[i
].disposition
, 0, 0);
3223 ok(hfile
!= INVALID_HANDLE_VALUE
, "%d: CreateFile error %d\n", i
, GetLastError());
3224 written
= 0xdeadbeef;
3225 SetLastError(0xdeadbeef);
3226 ret
= WriteFile(hfile
, &td
[i
].error
, sizeof(td
[i
].error
), &written
, NULL
);
3227 if (td
[i
].access
& GENERIC_WRITE
)
3228 ok(ret
, "%d: WriteFile error %d\n", i
, GetLastError());
3231 ok(!ret
, "%d: WriteFile should fail\n", i
);
3232 ok(GetLastError() == ERROR_ACCESS_DENIED
, "%d: expected ERROR_ACCESS_DENIED, got %d\n", i
, GetLastError());
3238 /* FIXME: remove the condition below once Wine is fixed */
3239 if (td
[i
].disposition
== TRUNCATE_EXISTING
&& !(td
[i
].access
& GENERIC_WRITE
))
3243 ok(hfile
== INVALID_HANDLE_VALUE
, "%d: CreateFile should fail\n", i
);
3244 ok(GetLastError() == td
[i
].error
, "%d: expected %d, got %d\n", i
, td
[i
].error
, GetLastError());
3250 ok(hfile
== INVALID_HANDLE_VALUE
, "%d: CreateFile should fail\n", i
);
3251 ok(GetLastError() == td
[i
].error
, "%d: expected %d, got %d\n", i
, td
[i
].error
, GetLastError());
3255 if (td
[i
].clean_up
) DeleteFile(file_name
);
3258 DeleteFile(file_name
);
3263 InitFunctionPointers();
3273 test_GetTempFileNameA();
3283 test_FindFirstFileA();
3284 test_FindNextFileA();
3285 test_FindFirstFileExA(0);
3286 /* FindExLimitToDirectories is ignored if the file system doesn't support directory filtering */
3287 test_FindFirstFileExA(FindExSearchLimitToDirectories
);
3289 test_file_sharing();
3290 test_offset_in_overlapped_structure();
3293 test_async_file_errors();
3297 test_RemoveDirectory();
3298 test_ReplaceFileA();
3299 test_ReplaceFileW();