1 /* Unit test suite for Ntdll file functions
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
5 * Copyright 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
22 * We use function pointers here as there is no import library for NTDLL on
30 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
31 * definition errors when we get to winnt.h
33 #define WIN32_NO_STATUS
35 #include "wine/test.h"
39 #ifndef IO_COMPLETION_ALL_ACCESS
40 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
43 static BOOL (WINAPI
* pGetVolumePathNameW
)(LPCWSTR
, LPWSTR
, DWORD
);
44 static UINT (WINAPI
*pGetSystemWow64DirectoryW
)( LPWSTR
, UINT
);
46 static VOID (WINAPI
*pRtlFreeUnicodeString
)( PUNICODE_STRING
);
47 static VOID (WINAPI
*pRtlInitUnicodeString
)( PUNICODE_STRING
, LPCWSTR
);
48 static BOOL (WINAPI
*pRtlDosPathNameToNtPathName_U
)( LPCWSTR
, PUNICODE_STRING
, PWSTR
*, CURDIR
* );
49 static NTSTATUS (WINAPI
*pRtlWow64EnableFsRedirectionEx
)( ULONG
, ULONG
* );
51 static NTSTATUS (WINAPI
*pNtCreateMailslotFile
)( PHANDLE
, ULONG
, POBJECT_ATTRIBUTES
, PIO_STATUS_BLOCK
,
52 ULONG
, ULONG
, ULONG
, PLARGE_INTEGER
);
53 static NTSTATUS (WINAPI
*pNtCreateFile
)(PHANDLE
,ACCESS_MASK
,POBJECT_ATTRIBUTES
,PIO_STATUS_BLOCK
,PLARGE_INTEGER
,ULONG
,ULONG
,ULONG
,ULONG
,PVOID
,ULONG
);
54 static NTSTATUS (WINAPI
*pNtOpenFile
)(PHANDLE
,ACCESS_MASK
,POBJECT_ATTRIBUTES
,PIO_STATUS_BLOCK
,ULONG
,ULONG
);
55 static NTSTATUS (WINAPI
*pNtDeleteFile
)(POBJECT_ATTRIBUTES ObjectAttributes
);
56 static NTSTATUS (WINAPI
*pNtReadFile
)(HANDLE hFile
, HANDLE hEvent
,
57 PIO_APC_ROUTINE apc
, void* apc_user
,
58 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
59 PLARGE_INTEGER offset
, PULONG key
);
60 static NTSTATUS (WINAPI
*pNtWriteFile
)(HANDLE hFile
, HANDLE hEvent
,
61 PIO_APC_ROUTINE apc
, void* apc_user
,
62 PIO_STATUS_BLOCK io_status
,
63 const void* buffer
, ULONG length
,
64 PLARGE_INTEGER offset
, PULONG key
);
65 static NTSTATUS (WINAPI
*pNtCancelIoFile
)(HANDLE hFile
, PIO_STATUS_BLOCK io_status
);
66 static NTSTATUS (WINAPI
*pNtCancelIoFileEx
)(HANDLE hFile
, PIO_STATUS_BLOCK iosb
, PIO_STATUS_BLOCK io_status
);
67 static NTSTATUS (WINAPI
*pNtClose
)( PHANDLE
);
69 static NTSTATUS (WINAPI
*pNtCreateIoCompletion
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
, ULONG
);
70 static NTSTATUS (WINAPI
*pNtOpenIoCompletion
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
71 static NTSTATUS (WINAPI
*pNtQueryIoCompletion
)(HANDLE
, IO_COMPLETION_INFORMATION_CLASS
, PVOID
, ULONG
, PULONG
);
72 static NTSTATUS (WINAPI
*pNtRemoveIoCompletion
)(HANDLE
, PULONG_PTR
, PULONG_PTR
, PIO_STATUS_BLOCK
, PLARGE_INTEGER
);
73 static NTSTATUS (WINAPI
*pNtSetIoCompletion
)(HANDLE
, ULONG_PTR
, ULONG_PTR
, NTSTATUS
, ULONG
);
74 static NTSTATUS (WINAPI
*pNtSetInformationFile
)(HANDLE
, PIO_STATUS_BLOCK
, PVOID
, ULONG
, FILE_INFORMATION_CLASS
);
75 static NTSTATUS (WINAPI
*pNtQueryInformationFile
)(HANDLE
, PIO_STATUS_BLOCK
, PVOID
, ULONG
, FILE_INFORMATION_CLASS
);
76 static NTSTATUS (WINAPI
*pNtQueryDirectoryFile
)(HANDLE
,HANDLE
,PIO_APC_ROUTINE
,PVOID
,PIO_STATUS_BLOCK
,
77 PVOID
,ULONG
,FILE_INFORMATION_CLASS
,BOOLEAN
,PUNICODE_STRING
,BOOLEAN
);
79 static inline BOOL
is_signaled( HANDLE obj
)
81 return WaitForSingleObject( obj
, 0 ) == 0;
84 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
85 #define TEST_BUF_LEN 3
87 static BOOL
create_pipe( HANDLE
*read
, HANDLE
*write
, ULONG flags
, ULONG size
)
89 *read
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_INBOUND
| flags
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
90 1, size
, size
, NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
91 ok(*read
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
93 *write
= CreateFileA(PIPENAME
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
94 ok(*write
!= INVALID_HANDLE_VALUE
, "CreateFile failed (%d)\n", GetLastError());
99 static HANDLE
create_temp_file( ULONG flags
)
101 char buffer
[MAX_PATH
];
104 GetTempFileNameA( ".", "foo", 0, buffer
);
105 handle
= CreateFileA(buffer
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
106 flags
| FILE_FLAG_DELETE_ON_CLOSE
, 0);
107 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
108 return (handle
== INVALID_HANDLE_VALUE
) ? 0 : handle
;
111 #define CVALUE_FIRST 0xfffabbcc
112 #define CKEY_FIRST 0x1030341
113 #define CKEY_SECOND 0x132E46
115 ULONG_PTR completionKey
;
116 IO_STATUS_BLOCK ioSb
;
117 ULONG_PTR completionValue
;
119 static long get_pending_msgs(HANDLE h
)
124 res
= pNtQueryIoCompletion( h
, IoCompletionBasicInformation
, &a
, sizeof(a
), &req
);
125 ok( res
== STATUS_SUCCESS
, "NtQueryIoCompletion failed: %x\n", res
);
126 if (res
!= STATUS_SUCCESS
) return -1;
127 ok( req
== sizeof(a
), "Unexpected response size: %x\n", req
);
131 static BOOL
get_msg(HANDLE h
)
133 LARGE_INTEGER timeout
= {{-10000000*3}};
134 DWORD res
= pNtRemoveIoCompletion( h
, &completionKey
, &completionValue
, &ioSb
, &timeout
);
135 ok( res
== STATUS_SUCCESS
, "NtRemoveIoCompletion failed: %x\n", res
);
136 if (res
!= STATUS_SUCCESS
)
138 completionKey
= completionValue
= 0;
139 memset(&ioSb
, 0, sizeof(ioSb
));
146 static void WINAPI
apc( void *arg
, IO_STATUS_BLOCK
*iosb
, ULONG reserved
)
150 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
151 iosb
, U(*iosb
).Status
, iosb
->Information
);
153 ok( !reserved
, "reserved is not 0: %x\n", reserved
);
156 static void create_file_test(void)
160 WCHAR path
[MAX_PATH
];
161 OBJECT_ATTRIBUTES attr
;
163 UNICODE_STRING nameW
;
166 len
= GetCurrentDirectoryW( MAX_PATH
, path
);
167 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
168 attr
.Length
= sizeof(attr
);
169 attr
.RootDirectory
= 0;
170 attr
.ObjectName
= &nameW
;
171 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
172 attr
.SecurityDescriptor
= NULL
;
173 attr
.SecurityQualityOfService
= NULL
;
175 /* try various open modes and options on directories */
176 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
177 FILE_OPEN
, FILE_DIRECTORY_FILE
, NULL
, 0 );
178 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
181 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
182 FILE_CREATE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
183 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
184 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
186 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
187 FILE_OPEN_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
188 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
191 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
192 FILE_SUPERSEDE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
193 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
195 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
196 FILE_OVERWRITE
, FILE_DIRECTORY_FILE
, NULL
, 0 );
197 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
199 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
200 FILE_OVERWRITE_IF
, FILE_DIRECTORY_FILE
, NULL
, 0 );
201 ok( status
== STATUS_INVALID_PARAMETER
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
203 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
204 FILE_OPEN
, 0, NULL
, 0 );
205 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
208 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
209 FILE_CREATE
, 0, NULL
, 0 );
210 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
211 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
213 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
214 FILE_OPEN_IF
, 0, NULL
, 0 );
215 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
218 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
219 FILE_SUPERSEDE
, 0, NULL
, 0 );
220 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
221 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
223 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
224 FILE_OVERWRITE
, 0, NULL
, 0 );
225 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
226 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
228 status
= pNtCreateFile( &dir
, GENERIC_READ
, &attr
, &io
, NULL
, 0, FILE_SHARE_READ
|FILE_SHARE_WRITE
,
229 FILE_OVERWRITE_IF
, 0, NULL
, 0 );
230 ok( status
== STATUS_OBJECT_NAME_COLLISION
|| status
== STATUS_ACCESS_DENIED
,
231 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
234 static void open_file_test(void)
238 WCHAR path
[MAX_PATH
];
240 OBJECT_ATTRIBUTES attr
;
242 UNICODE_STRING nameW
;
246 len
= GetWindowsDirectoryW( path
, MAX_PATH
);
247 pRtlDosPathNameToNtPathName_U( path
, &nameW
, NULL
, NULL
);
248 attr
.Length
= sizeof(attr
);
249 attr
.RootDirectory
= 0;
250 attr
.ObjectName
= &nameW
;
251 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
252 attr
.SecurityDescriptor
= NULL
;
253 attr
.SecurityQualityOfService
= NULL
;
254 status
= pNtOpenFile( &dir
, GENERIC_READ
, &attr
, &io
,
255 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
256 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
258 /* test opening system dir with RootDirectory set to windows dir */
259 GetSystemDirectoryW( path
, MAX_PATH
);
260 while (path
[len
] == '\\') len
++;
261 nameW
.Buffer
= path
+ len
;
262 nameW
.Length
= lstrlenW(path
+ len
) * sizeof(WCHAR
);
263 attr
.RootDirectory
= dir
;
264 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
265 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
266 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
267 CloseHandle( handle
);
269 /* try uppercase name */
270 for (i
= len
; path
[i
]; i
++) if (path
[i
] >= 'a' && path
[i
] <= 'z') path
[i
] -= 'a' - 'A';
271 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
272 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
273 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
274 CloseHandle( handle
);
276 /* try with leading backslash */
278 nameW
.Length
+= sizeof(WCHAR
);
279 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
280 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
281 ok( status
== STATUS_INVALID_PARAMETER
||
282 status
== STATUS_OBJECT_NAME_INVALID
||
283 status
== STATUS_OBJECT_PATH_SYNTAX_BAD
,
284 "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
285 if (!status
) CloseHandle( handle
);
287 /* try with empty name */
289 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
290 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_DIRECTORY_FILE
);
291 ok( !status
, "open %s failed %x\n", wine_dbgstr_w(nameW
.Buffer
), status
);
292 CloseHandle( handle
);
294 /* try open by file id */
296 while (!pNtQueryDirectoryFile( dir
, NULL
, NULL
, NULL
, &io
, data
, sizeof(data
),
297 FileIdBothDirectoryInformation
, FALSE
, NULL
, restart
))
299 FILE_ID_BOTH_DIRECTORY_INFORMATION
*info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)data
;
304 if (!info
->FileId
.QuadPart
) goto next
;
305 nameW
.Buffer
= (WCHAR
*)&info
->FileId
;
306 nameW
.Length
= sizeof(info
->FileId
);
307 info
->FileName
[info
->FileNameLength
/sizeof(WCHAR
)] = 0;
308 status
= pNtOpenFile( &handle
, GENERIC_READ
, &attr
, &io
,
309 FILE_SHARE_READ
|FILE_SHARE_WRITE
,
310 FILE_OPEN_BY_FILE_ID
|
311 ((info
->FileAttributes
& FILE_ATTRIBUTE_DIRECTORY
) ? FILE_DIRECTORY_FILE
: 0) );
312 ok( status
== STATUS_SUCCESS
|| status
== STATUS_ACCESS_DENIED
|| status
== STATUS_NOT_IMPLEMENTED
,
313 "open %s failed %x\n", wine_dbgstr_w(info
->FileName
), status
);
314 if (status
== STATUS_NOT_IMPLEMENTED
)
316 win_skip( "FILE_OPEN_BY_FILE_ID not supported\n" );
321 FILE_ALL_INFORMATION all_info
;
323 if (!pNtQueryInformationFile( handle
, &io
, &all_info
, sizeof(all_info
), FileAllInformation
))
325 /* check that it's the same file */
326 ok( info
->EndOfFile
.QuadPart
== all_info
.StandardInformation
.EndOfFile
.QuadPart
,
327 "mismatched file size for %s\n", wine_dbgstr_w(info
->FileName
));
328 ok( info
->LastWriteTime
.QuadPart
== all_info
.BasicInformation
.LastWriteTime
.QuadPart
,
329 "mismatched write time for %s\n", wine_dbgstr_w(info
->FileName
));
331 CloseHandle( handle
);
334 if (!info
->NextEntryOffset
) break;
335 info
= (FILE_ID_BOTH_DIRECTORY_INFORMATION
*)((char *)info
+ info
->NextEntryOffset
);
340 pRtlFreeUnicodeString( &nameW
);
343 static void delete_file_test(void)
346 OBJECT_ATTRIBUTES attr
;
347 UNICODE_STRING nameW
;
348 WCHAR pathW
[MAX_PATH
];
349 WCHAR pathsubW
[MAX_PATH
];
350 static const WCHAR testdirW
[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
351 static const WCHAR subdirW
[] = {'\\','s','u','b',0};
353 ret
= GetTempPathW(MAX_PATH
, pathW
);
356 ok(0, "couldn't get temp dir\n");
359 if (ret
+ sizeof(testdirW
)/sizeof(WCHAR
)-1 + sizeof(subdirW
)/sizeof(WCHAR
)-1 >= MAX_PATH
)
361 ok(0, "MAX_PATH exceeded in constructing paths\n");
365 lstrcatW(pathW
, testdirW
);
366 lstrcpyW(pathsubW
, pathW
);
367 lstrcatW(pathsubW
, subdirW
);
369 ret
= CreateDirectoryW(pathW
, NULL
);
370 ok(ret
== TRUE
, "couldn't create directory ntdeletefile\n");
371 if (!pRtlDosPathNameToNtPathName_U(pathW
, &nameW
, NULL
, NULL
))
373 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
377 attr
.Length
= sizeof(attr
);
378 attr
.RootDirectory
= 0;
379 attr
.Attributes
= OBJ_CASE_INSENSITIVE
;
380 attr
.ObjectName
= &nameW
;
381 attr
.SecurityDescriptor
= NULL
;
382 attr
.SecurityQualityOfService
= NULL
;
384 /* test NtDeleteFile on an empty directory */
385 ret
= pNtDeleteFile(&attr
);
386 ok(ret
== STATUS_SUCCESS
, "NtDeleteFile should succeed in removing an empty directory\n");
387 ret
= RemoveDirectoryW(pathW
);
388 ok(ret
== FALSE
, "expected to fail removing directory, NtDeleteFile should have removed it\n");
390 /* test NtDeleteFile on a non-empty directory */
391 ret
= CreateDirectoryW(pathW
, NULL
);
392 ok(ret
== TRUE
, "couldn't create directory ntdeletefile ?!\n");
393 ret
= CreateDirectoryW(pathsubW
, NULL
);
394 ok(ret
== TRUE
, "couldn't create directory subdir\n");
395 ret
= pNtDeleteFile(&attr
);
396 ok(ret
== STATUS_SUCCESS
, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
397 ret
= RemoveDirectoryW(pathsubW
);
398 ok(ret
== TRUE
, "expected to remove directory ntdeletefile\\sub\n");
399 ret
= RemoveDirectoryW(pathW
);
400 ok(ret
== TRUE
, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
402 pRtlFreeUnicodeString( &nameW
);
405 static void read_file_test(void)
407 const char text
[] = "foobar";
408 HANDLE handle
, read
, write
;
410 IO_STATUS_BLOCK iosb
, iosb2
;
414 LARGE_INTEGER offset
;
415 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
419 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
421 /* try read with no data */
422 U(iosb
).Status
= 0xdeadbabe;
423 iosb
.Information
= 0xdeadbeef;
424 ok( is_signaled( read
), "read handle is not signaled\n" );
425 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
426 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
427 ok( !is_signaled( read
), "read handle is signaled\n" );
428 ok( !is_signaled( event
), "event is signaled\n" );
429 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
430 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
431 ok( !apc_count
, "apc was called\n" );
432 WriteFile( write
, buffer
, 1, &written
, NULL
);
433 /* iosb updated here by async i/o */
434 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
435 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
436 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
437 ok( !is_signaled( read
), "read handle is signaled\n" );
438 ok( is_signaled( event
), "event is not signaled\n" );
439 ok( !apc_count
, "apc was called\n" );
441 SleepEx( 1, FALSE
); /* non-alertable sleep */
442 ok( !apc_count
, "apc was called\n" );
443 SleepEx( 1, TRUE
); /* alertable sleep */
444 ok( apc_count
== 1, "apc not called\n" );
446 /* with no event, the pipe handle itself gets signaled */
448 U(iosb
).Status
= 0xdeadbabe;
449 iosb
.Information
= 0xdeadbeef;
450 ok( !is_signaled( read
), "read handle is not signaled\n" );
451 status
= pNtReadFile( read
, 0, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
452 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
453 ok( !is_signaled( read
), "read handle is signaled\n" );
454 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
455 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
456 ok( !apc_count
, "apc was called\n" );
457 WriteFile( write
, buffer
, 1, &written
, NULL
);
458 /* iosb updated here by async i/o */
459 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
460 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
461 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
462 ok( is_signaled( read
), "read handle is signaled\n" );
463 ok( !apc_count
, "apc was called\n" );
465 SleepEx( 1, FALSE
); /* non-alertable sleep */
466 ok( !apc_count
, "apc was called\n" );
467 SleepEx( 1, TRUE
); /* alertable sleep */
468 ok( apc_count
== 1, "apc not called\n" );
470 /* now read with data ready */
472 U(iosb
).Status
= 0xdeadbabe;
473 iosb
.Information
= 0xdeadbeef;
475 WriteFile( write
, buffer
, 1, &written
, NULL
);
476 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
477 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
478 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
479 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
480 ok( is_signaled( event
), "event is not signaled\n" );
481 ok( !apc_count
, "apc was called\n" );
482 SleepEx( 1, FALSE
); /* non-alertable sleep */
483 ok( !apc_count
, "apc was called\n" );
484 SleepEx( 1, TRUE
); /* alertable sleep */
485 ok( apc_count
== 1, "apc not called\n" );
487 /* try read with no data */
489 U(iosb
).Status
= 0xdeadbabe;
490 iosb
.Information
= 0xdeadbeef;
491 ok( is_signaled( event
), "event is not signaled\n" ); /* check that read resets the event */
492 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
493 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
494 ok( !is_signaled( event
), "event is signaled\n" );
495 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
496 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
497 ok( !apc_count
, "apc was called\n" );
498 WriteFile( write
, buffer
, 1, &written
, NULL
);
499 /* partial read is good enough */
500 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
501 ok( is_signaled( event
), "event is signaled\n" );
502 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
503 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
504 ok( !apc_count
, "apc was called\n" );
505 SleepEx( 1, TRUE
); /* alertable sleep */
506 ok( apc_count
== 1, "apc was not called\n" );
508 /* read from disconnected pipe */
510 U(iosb
).Status
= 0xdeadbabe;
511 iosb
.Information
= 0xdeadbeef;
512 CloseHandle( write
);
513 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
514 ok( status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", status
);
515 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
516 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
517 ok( !is_signaled( event
), "event is signaled\n" );
518 ok( !apc_count
, "apc was called\n" );
519 SleepEx( 1, TRUE
); /* alertable sleep */
520 ok( !apc_count
, "apc was called\n" );
523 /* read from closed handle */
525 U(iosb
).Status
= 0xdeadbabe;
526 iosb
.Information
= 0xdeadbeef;
528 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
529 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
530 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
531 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
532 ok( is_signaled( event
), "event is signaled\n" ); /* not reset on invalid handle */
533 ok( !apc_count
, "apc was called\n" );
534 SleepEx( 1, TRUE
); /* alertable sleep */
535 ok( !apc_count
, "apc was called\n" );
537 /* disconnect while async read is in progress */
538 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
540 U(iosb
).Status
= 0xdeadbabe;
541 iosb
.Information
= 0xdeadbeef;
542 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
543 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
544 ok( !is_signaled( event
), "event is signaled\n" );
545 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
546 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
547 ok( !apc_count
, "apc was called\n" );
548 CloseHandle( write
);
549 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
550 ok( U(iosb
).Status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", U(iosb
).Status
);
551 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
552 ok( is_signaled( event
), "event is signaled\n" );
553 ok( !apc_count
, "apc was called\n" );
554 SleepEx( 1, TRUE
); /* alertable sleep */
555 ok( apc_count
== 1, "apc was not called\n" );
558 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
559 ok(DuplicateHandle(GetCurrentProcess(), read
, GetCurrentProcess(), &handle
, 0, TRUE
, DUPLICATE_SAME_ACCESS
),
560 "Failed to duplicate handle: %d\n", GetLastError());
563 U(iosb
).Status
= 0xdeadbabe;
564 iosb
.Information
= 0xdeadbeef;
565 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
566 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
567 ok( !is_signaled( event
), "event is signaled\n" );
568 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
569 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
570 ok( !apc_count
, "apc was called\n" );
571 /* Cancel by other handle */
572 status
= pNtCancelIoFile( read
, &iosb2
);
573 ok(status
== STATUS_SUCCESS
, "failed to cancel by different handle: %x\n", status
);
574 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
575 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
576 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
577 ok( is_signaled( event
), "event is signaled\n" );
578 todo_wine
ok( !apc_count
, "apc was called\n" );
579 SleepEx( 1, TRUE
); /* alertable sleep */
580 ok( apc_count
== 1, "apc was not called\n" );
583 U(iosb
).Status
= 0xdeadbabe;
584 iosb
.Information
= 0xdeadbeef;
585 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
586 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
587 ok( !is_signaled( event
), "event is signaled\n" );
588 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
589 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
590 ok( !apc_count
, "apc was called\n" );
591 /* Close queued handle */
593 SleepEx( 1, TRUE
); /* alertable sleep */
594 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
595 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
596 status
= pNtCancelIoFile( read
, &iosb2
);
597 ok(status
== STATUS_INVALID_HANDLE
, "cancelled by closed handle?\n");
598 status
= pNtCancelIoFile( handle
, &iosb2
);
599 ok(status
== STATUS_SUCCESS
, "failed to cancel: %x\n", status
);
600 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
601 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
602 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
603 ok( is_signaled( event
), "event is signaled\n" );
604 todo_wine
ok( !apc_count
, "apc was called\n" );
605 SleepEx( 1, TRUE
); /* alertable sleep */
606 ok( apc_count
== 1, "apc was not called\n" );
607 CloseHandle( handle
);
608 CloseHandle( write
);
610 if (pNtCancelIoFileEx
)
612 /* Basic Cancel Ex */
613 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
616 U(iosb
).Status
= 0xdeadbabe;
617 iosb
.Information
= 0xdeadbeef;
618 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
619 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
620 ok( !is_signaled( event
), "event is signaled\n" );
621 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
622 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
623 ok( !apc_count
, "apc was called\n" );
624 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
625 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
626 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
627 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
628 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
629 ok( is_signaled( event
), "event is signaled\n" );
630 todo_wine
ok( !apc_count
, "apc was called\n" );
631 SleepEx( 1, TRUE
); /* alertable sleep */
632 ok( apc_count
== 1, "apc was not called\n" );
636 U(iosb
).Status
= 0xdeadbabe;
637 iosb
.Information
= 0xdeadbeef;
638 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
639 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
640 ok( !is_signaled( event
), "event is signaled\n" );
641 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
642 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
643 ok( !apc_count
, "apc was called\n" );
644 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
645 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
646 ok( !is_signaled( event
), "event is signaled\n" );
647 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
648 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
649 ok( !apc_count
, "apc was called\n" );
650 status
= pNtCancelIoFileEx( read
, &iosb
, &iosb2
);
651 ok(status
== STATUS_SUCCESS
, "Failed to cancel I/O\n");
652 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
653 ok( U(iosb
).Status
== STATUS_CANCELLED
, "wrong status %x\n", U(iosb
).Status
);
654 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
655 ok( is_signaled( event
), "event is signaled\n" );
656 todo_wine
ok( !apc_count
, "apc was called\n" );
657 SleepEx( 1, TRUE
); /* alertable sleep */
658 ok( apc_count
== 2, "apc was not called\n" );
661 CloseHandle( write
);
664 /* now try a real file */
665 if (!(handle
= create_temp_file( FILE_FLAG_OVERLAPPED
))) return;
667 U(iosb
).Status
= 0xdeadbabe;
668 iosb
.Information
= 0xdeadbeef;
671 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
672 ok( status
== STATUS_SUCCESS
|| status
== STATUS_PENDING
, "wrong status %x\n", status
);
673 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
674 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
675 ok( is_signaled( event
), "event is signaled\n" );
676 ok( !apc_count
, "apc was called\n" );
677 SleepEx( 1, TRUE
); /* alertable sleep */
678 ok( apc_count
== 1, "apc was not called\n" );
681 U(iosb
).Status
= 0xdeadbabe;
682 iosb
.Information
= 0xdeadbeef;
685 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
686 ok( status
== STATUS_SUCCESS
||
687 status
== STATUS_PENDING
, /* vista */
688 "wrong status %x\n", status
);
689 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
690 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
691 ok( is_signaled( event
), "event is signaled\n" );
692 ok( !apc_count
, "apc was called\n" );
693 SleepEx( 1, TRUE
); /* alertable sleep */
694 ok( apc_count
== 1, "apc was not called\n" );
696 /* read beyond eof */
698 U(iosb
).Status
= 0xdeadbabe;
699 iosb
.Information
= 0xdeadbeef;
700 offset
.QuadPart
= strlen(text
) + 2;
701 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
702 if (status
== STATUS_PENDING
) /* vista */
704 ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
705 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
706 ok( is_signaled( event
), "event is signaled\n" );
707 ok( !apc_count
, "apc was called\n" );
708 SleepEx( 1, TRUE
); /* alertable sleep */
709 ok( apc_count
== 1, "apc was not called\n" );
713 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
714 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
715 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
716 ok( !is_signaled( event
), "event is signaled\n" );
717 ok( !apc_count
, "apc was called\n" );
718 SleepEx( 1, TRUE
); /* alertable sleep */
719 ok( !apc_count
, "apc was called\n" );
721 CloseHandle( handle
);
723 /* now a non-overlapped file */
724 if (!(handle
= create_temp_file(0))) return;
726 U(iosb
).Status
= 0xdeadbabe;
727 iosb
.Information
= 0xdeadbeef;
729 status
= pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
730 ok( status
== STATUS_END_OF_FILE
||
731 status
== STATUS_SUCCESS
||
732 status
== STATUS_PENDING
, /* vista */
733 "wrong status %x\n", status
);
734 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
735 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
736 ok( is_signaled( event
), "event is signaled\n" );
737 ok( !apc_count
, "apc was called\n" );
738 SleepEx( 1, TRUE
); /* alertable sleep */
739 ok( apc_count
== 1, "apc was not called\n" );
742 U(iosb
).Status
= 0xdeadbabe;
743 iosb
.Information
= 0xdeadbeef;
746 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
747 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
748 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
749 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
750 ok( is_signaled( event
), "event is signaled\n" );
751 ok( !apc_count
, "apc was called\n" );
752 SleepEx( 1, TRUE
); /* alertable sleep */
753 todo_wine
ok( !apc_count
, "apc was called\n" );
755 /* read beyond eof */
757 U(iosb
).Status
= 0xdeadbabe;
758 iosb
.Information
= 0xdeadbeef;
759 offset
.QuadPart
= strlen(text
) + 2;
761 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
762 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
763 todo_wine
ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
764 todo_wine
ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
765 todo_wine
ok( is_signaled( event
), "event is not signaled\n" );
766 ok( !apc_count
, "apc was called\n" );
767 SleepEx( 1, TRUE
); /* alertable sleep */
768 ok( !apc_count
, "apc was called\n" );
770 CloseHandle( handle
);
772 CloseHandle( event
);
775 static void nt_mailslot_test(void)
778 ACCESS_MASK DesiredAccess
;
779 OBJECT_ATTRIBUTES attr
;
783 ULONG MaxMessageSize
;
784 LARGE_INTEGER TimeOut
;
785 IO_STATUS_BLOCK IoStatusBlock
;
788 WCHAR buffer1
[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
789 'R',':','\\','F','R','E','D','\0' };
791 TimeOut
.QuadPart
= -1;
793 pRtlInitUnicodeString(&str
, buffer1
);
794 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
795 CreateOptions
= MailslotQuota
= MaxMessageSize
= 0;
796 DesiredAccess
= GENERIC_READ
;
799 * Check for NULL pointer handling
801 rc
= pNtCreateMailslotFile(NULL
, DesiredAccess
,
802 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
804 ok( rc
== STATUS_ACCESS_VIOLATION
||
805 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
806 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc
);
809 * Test to see if the Timeout can be NULL
811 hslot
= (HANDLE
)0xdeadbeef;
812 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
813 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
815 ok( rc
== STATUS_SUCCESS
||
816 rc
== STATUS_INVALID_PARAMETER
, /* win2k3 */
817 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc
);
818 ok( hslot
!= 0, "Handle is invalid\n");
820 if ( rc
== STATUS_SUCCESS
) rc
= pNtClose(hslot
);
823 * Test that the length field is checked properly
826 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
827 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
829 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
831 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
833 attr
.Length
= sizeof(OBJECT_ATTRIBUTES
)+1;
834 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
835 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
837 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
839 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
842 * Test handling of a NULL unicode string in ObjectName
844 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
845 attr
.ObjectName
= NULL
;
846 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
847 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
849 ok( rc
== STATUS_OBJECT_PATH_SYNTAX_BAD
||
850 rc
== STATUS_INVALID_PARAMETER
,
851 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc
);
853 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
858 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
859 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
860 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
862 ok( rc
== STATUS_SUCCESS
, "Create MailslotFile failed rc = %x\n", rc
);
863 ok( hslot
!= 0, "Handle is invalid\n");
865 rc
= pNtClose(hslot
);
866 ok( rc
== STATUS_SUCCESS
, "NtClose failed\n");
869 static void test_iocp_setcompletion(HANDLE h
)
874 res
= pNtSetIoCompletion( h
, CKEY_FIRST
, CVALUE_FIRST
, STATUS_INVALID_DEVICE_REQUEST
, 3 );
875 ok( res
== STATUS_SUCCESS
, "NtSetIoCompletion failed: %x\n", res
);
877 count
= get_pending_msgs(h
);
878 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
882 ok( completionKey
== CKEY_FIRST
, "Invalid completion key: %lx\n", completionKey
);
883 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
884 ok( U(ioSb
).Status
== STATUS_INVALID_DEVICE_REQUEST
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
885 ok( completionValue
== CVALUE_FIRST
, "Invalid completion value: %lx\n", completionValue
);
888 count
= get_pending_msgs(h
);
889 ok( !count
, "Unexpected msg count: %ld\n", count
);
892 static void test_iocp_fileio(HANDLE h
)
894 static const char pipe_name
[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
896 IO_STATUS_BLOCK iosb
;
897 FILE_COMPLETION_INFORMATION fci
= {h
, CKEY_SECOND
};
898 HANDLE hPipeSrv
, hPipeClt
;
901 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
902 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
903 if (hPipeSrv
!= INVALID_HANDLE_VALUE
)
905 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
906 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
907 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
909 res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
910 ok( res
== STATUS_INVALID_PARAMETER
, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res
);
911 CloseHandle(hPipeClt
);
913 CloseHandle( hPipeSrv
);
916 hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
| FILE_FLAG_OVERLAPPED
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
917 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
, "Cannot create named pipe\n" );
918 if (hPipeSrv
== INVALID_HANDLE_VALUE
)
921 hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
922 ok( hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot connect to pipe\n" );
923 if (hPipeClt
!= INVALID_HANDLE_VALUE
)
926 BYTE send_buf
[TEST_BUF_LEN
], recv_buf
[TEST_BUF_LEN
];
930 NTSTATUS res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
931 ok( res
== STATUS_SUCCESS
, "NtSetInformationFile failed: %x\n", res
);
932 ok( U(iosb
).Status
== STATUS_SUCCESS
, "iosb.Status invalid: %x\n", U(iosb
).Status
);
934 memset( send_buf
, 0, TEST_BUF_LEN
);
935 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
936 count
= get_pending_msgs(h
);
937 ok( !count
, "Unexpected msg count: %ld\n", count
);
938 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
939 count
= get_pending_msgs(h
);
940 ok( !count
, "Unexpected msg count: %ld\n", count
);
941 WriteFile( hPipeClt
, send_buf
, TEST_BUF_LEN
, &read
, NULL
);
945 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
946 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
947 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
948 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
949 ok( !memcmp( send_buf
, recv_buf
, TEST_BUF_LEN
), "Receive buffer (%x %x %x) did not match send buffer (%x %x %x)\n", recv_buf
[0], recv_buf
[1], recv_buf
[2], send_buf
[0], send_buf
[1], send_buf
[2] );
951 count
= get_pending_msgs(h
);
952 ok( !count
, "Unexpected msg count: %ld\n", count
);
954 memset( send_buf
, 0, TEST_BUF_LEN
);
955 memset( recv_buf
, 0xde, TEST_BUF_LEN
);
956 WriteFile( hPipeClt
, send_buf
, 2, &read
, NULL
);
957 count
= get_pending_msgs(h
);
958 ok( !count
, "Unexpected msg count: %ld\n", count
);
959 ReadFile( hPipeSrv
, recv_buf
, 2, &read
, &o
);
960 count
= get_pending_msgs(h
);
961 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
964 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
965 ok( ioSb
.Information
== 2, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
966 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
967 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
968 ok( !memcmp( send_buf
, recv_buf
, 2 ), "Receive buffer (%x %x) did not match send buffer (%x %x)\n", recv_buf
[0], recv_buf
[1], send_buf
[0], send_buf
[1] );
971 ReadFile( hPipeSrv
, recv_buf
, TEST_BUF_LEN
, &read
, &o
);
972 CloseHandle( hPipeSrv
);
973 count
= get_pending_msgs(h
);
974 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
977 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
978 ok( ioSb
.Information
== 0, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
979 /* wine sends wrong status here */
980 todo_wine
ok( U(ioSb
).Status
== STATUS_PIPE_BROKEN
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
981 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
985 CloseHandle( hPipeClt
);
988 static void test_file_basic_information(void)
991 FILE_BASIC_INFORMATION fbi
;
994 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
996 if (!(h
= create_temp_file(0))) return;
998 /* Check default first */
999 memset(&fbi
, 0, sizeof(fbi
));
1000 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1001 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1002 ok ( (fbi
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1003 "attribute %x not expected\n", fbi
.FileAttributes
);
1006 /* Clear fbi to avoid setting times */
1007 memset(&fbi
, 0, sizeof(fbi
));
1008 fbi
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1009 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1010 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1012 memset(&fbi
, 0, sizeof(fbi
));
1013 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1014 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1015 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_SYSTEM
, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fbi
.FileAttributes
);
1018 memset(&fbi
, 0, sizeof(fbi
));
1019 fbi
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1020 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1021 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1023 memset(&fbi
, 0, sizeof(fbi
));
1024 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1025 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1026 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_HIDDEN
, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fbi
.FileAttributes
);
1028 /* Check NORMAL last of all (to make sure we can clear attributes) */
1029 memset(&fbi
, 0, sizeof(fbi
));
1030 fbi
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1031 res
= pNtSetInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1032 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1034 memset(&fbi
, 0, sizeof(fbi
));
1035 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBasicInformation
);
1036 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1037 todo_wine
ok ( (fbi
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_NORMAL
, "attribute %x not 0\n", fbi
.FileAttributes
);
1042 static void test_file_all_information(void)
1045 /* FileAllInformation, like FileNameInformation, has a variable-length pathname
1046 * buffer at the end. Vista objects with STATUS_BUFFER_OVERFLOW if you
1047 * don't leave enough room there.
1050 FILE_ALL_INFORMATION fai
;
1055 int attrib_mask
= FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_NORMAL
;
1057 if (!(h
= create_temp_file(0))) return;
1059 /* Check default first */
1060 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1061 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1062 ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& FILE_ATTRIBUTE_ARCHIVE
) == FILE_ATTRIBUTE_ARCHIVE
,
1063 "attribute %x not expected\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1066 /* Clear fbi to avoid setting times */
1067 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1068 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_SYSTEM
;
1069 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1070 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to set FileAllInformation, res %x\n", res
);
1071 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1072 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1074 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1075 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1076 ok ( res
== STATUS_SUCCESS
, "can't get attributes, res %x\n", res
);
1077 todo_wine
ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_SYSTEM
, "attribute %x not FILE_ATTRIBUTE_SYSTEM\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1080 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1081 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_HIDDEN
;
1082 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1083 ok ( res
== STATUS_SUCCESS
, "can't set system attribute\n");
1085 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1086 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1087 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1088 todo_wine
ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_HIDDEN
, "attribute %x not FILE_ATTRIBUTE_HIDDEN\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1090 /* Check NORMAL last of all (to make sure we can clear attributes) */
1091 memset(&fai_buf
.fai
.BasicInformation
, 0, sizeof(fai_buf
.fai
.BasicInformation
));
1092 fai_buf
.fai
.BasicInformation
.FileAttributes
= FILE_ATTRIBUTE_NORMAL
;
1093 res
= pNtSetInformationFile(h
, &io
, &fai_buf
.fai
.BasicInformation
, sizeof fai_buf
.fai
.BasicInformation
, FileBasicInformation
);
1094 ok ( res
== STATUS_SUCCESS
, "can't set normal attribute\n");
1096 memset(&fai_buf
.fai
, 0, sizeof(fai_buf
.fai
));
1097 res
= pNtQueryInformationFile(h
, &io
, &fai_buf
.fai
, sizeof fai_buf
, FileAllInformation
);
1098 ok ( res
== STATUS_SUCCESS
, "can't get attributes\n");
1099 todo_wine
ok ( (fai_buf
.fai
.BasicInformation
.FileAttributes
& attrib_mask
) == FILE_ATTRIBUTE_NORMAL
, "attribute %x not FILE_ATTRIBUTE_NORMAL\n", fai_buf
.fai
.BasicInformation
.FileAttributes
);
1104 static void test_file_both_information(void)
1107 FILE_BOTH_DIR_INFORMATION fbi
;
1111 if (!(h
= create_temp_file(0))) return;
1113 memset(&fbi
, 0, sizeof(fbi
));
1114 res
= pNtQueryInformationFile(h
, &io
, &fbi
, sizeof fbi
, FileBothDirectoryInformation
);
1115 ok ( res
== STATUS_INVALID_INFO_CLASS
|| res
== STATUS_NOT_IMPLEMENTED
, "shouldn't be able to query FileBothDirectoryInformation, res %x\n", res
);
1120 static void test_iocompletion(void)
1122 HANDLE h
= INVALID_HANDLE_VALUE
;
1125 res
= pNtCreateIoCompletion( &h
, IO_COMPLETION_ALL_ACCESS
, NULL
, 0);
1127 ok( res
== 0, "NtCreateIoCompletion anonymous failed: %x\n", res
);
1128 ok( h
&& h
!= INVALID_HANDLE_VALUE
, "Invalid handle returned\n" );
1130 if ( h
&& h
!= INVALID_HANDLE_VALUE
)
1132 test_iocp_setcompletion(h
);
1133 test_iocp_fileio(h
);
1138 static void test_file_name_information(void)
1140 WCHAR
*file_name
, *volume_prefix
, *expected
;
1141 FILE_NAME_INFORMATION
*info
;
1142 ULONG old_redir
= 1, tmp
;
1143 UINT file_name_size
;
1150 /* GetVolumePathName is not present before w2k */
1151 if (!pGetVolumePathNameW
) {
1152 win_skip("GetVolumePathNameW not found\n");
1156 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1157 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1158 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1159 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1161 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1162 ok(len
== file_name_size
- 1,
1163 "GetSystemDirectoryW returned %u, expected %u.\n",
1164 len
, file_name_size
- 1);
1166 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1167 ok(len
, "GetVolumePathNameW failed.\n");
1169 len
= lstrlenW( volume_prefix
);
1170 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1171 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1172 expected
[file_name_size
- len
- 1] = '\0';
1174 /* A bit more than we actually need, but it keeps the calculation simple. */
1175 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1176 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1178 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1179 h
= CreateFileW( file_name
, GENERIC_READ
,
1180 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1181 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1182 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1183 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1185 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileNameInformation
);
1186 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x.\n", hr
);
1188 memset( info
, 0xcc, info_size
);
1189 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileNameInformation
);
1190 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1191 hr
, STATUS_BUFFER_OVERFLOW
);
1192 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1193 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1194 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u, expected %u.\n",
1195 info
->FileNameLength
, lstrlenW( expected
) * sizeof(WCHAR
));
1196 ok(info
->FileName
[2] == 0xcccc, "info->FileName[2] is %#x, expected 0xcccc.\n", info
->FileName
[2]);
1197 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1198 "info->FileName[1] is %p, expected %p.\n",
1199 CharLowerW((LPWSTR
)(UINT_PTR
)info
->FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1200 ok(io
.Information
== sizeof(*info
), "io.Information is %lu, expected %u.\n", io
.Information
, sizeof(*info
));
1202 memset( info
, 0xcc, info_size
);
1203 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1204 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1205 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1206 ok(info
->FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
), "info->FileNameLength is %u, expected %u.\n",
1207 info
->FileNameLength
, lstrlenW( expected
) * sizeof(WCHAR
));
1208 ok(info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] == 0xcccc, "info->FileName[%u] is %#x, expected 0xcccc.\n",
1209 info
->FileNameLength
/ sizeof(WCHAR
), info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)]);
1210 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1211 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1212 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1213 ok(io
.Information
== FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
,
1214 "io.Information is %lu, expected %u.\n",
1215 io
.Information
, FIELD_OFFSET(FILE_NAME_INFORMATION
, FileName
) + info
->FileNameLength
);
1218 HeapFree( GetProcessHeap(), 0, info
);
1219 HeapFree( GetProcessHeap(), 0, expected
);
1220 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1222 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1224 skip("Not running on WoW64, skipping test.\n");
1225 HeapFree( GetProcessHeap(), 0, file_name
);
1229 h
= CreateFileW( file_name
, GENERIC_READ
,
1230 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1231 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1232 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1233 HeapFree( GetProcessHeap(), 0, file_name
);
1235 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1236 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1237 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1239 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1240 ok(len
== file_name_size
- 1,
1241 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1242 len
, file_name_size
- 1);
1244 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1245 ok(len
, "GetVolumePathNameW failed.\n");
1247 len
= lstrlenW( volume_prefix
);
1248 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1249 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1250 expected
[file_name_size
- len
- 1] = '\0';
1252 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1253 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1255 memset( info
, 0xcc, info_size
);
1256 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileNameInformation
);
1257 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1258 info
->FileName
[info
->FileNameLength
/ sizeof(WCHAR
)] = '\0';
1259 ok(!lstrcmpiW( info
->FileName
, expected
), "info->FileName is %s, expected %s.\n",
1260 wine_dbgstr_w( info
->FileName
), wine_dbgstr_w( expected
));
1263 HeapFree( GetProcessHeap(), 0, info
);
1264 HeapFree( GetProcessHeap(), 0, expected
);
1265 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1266 HeapFree( GetProcessHeap(), 0, file_name
);
1269 static void test_file_all_name_information(void)
1271 WCHAR
*file_name
, *volume_prefix
, *expected
;
1272 FILE_ALL_INFORMATION
*info
;
1273 ULONG old_redir
= 1, tmp
;
1274 UINT file_name_size
;
1281 /* GetVolumePathName is not present before w2k */
1282 if (!pGetVolumePathNameW
) {
1283 win_skip("GetVolumePathNameW not found\n");
1287 file_name_size
= GetSystemDirectoryW( NULL
, 0 );
1288 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1289 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1290 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1292 len
= GetSystemDirectoryW( file_name
, file_name_size
);
1293 ok(len
== file_name_size
- 1,
1294 "GetSystemDirectoryW returned %u, expected %u.\n",
1295 len
, file_name_size
- 1);
1297 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1298 ok(len
, "GetVolumePathNameW failed.\n");
1300 len
= lstrlenW( volume_prefix
);
1301 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1302 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1303 expected
[file_name_size
- len
- 1] = '\0';
1305 /* A bit more than we actually need, but it keeps the calculation simple. */
1306 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1307 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1309 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( TRUE
, &old_redir
);
1310 h
= CreateFileW( file_name
, GENERIC_READ
,
1311 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1312 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1313 if (pRtlWow64EnableFsRedirectionEx
) pRtlWow64EnableFsRedirectionEx( old_redir
, &tmp
);
1314 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1316 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
) - 1, FileAllInformation
);
1317 ok(hr
== STATUS_INFO_LENGTH_MISMATCH
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1318 hr
, STATUS_INFO_LENGTH_MISMATCH
);
1320 memset( info
, 0xcc, info_size
);
1321 hr
= pNtQueryInformationFile( h
, &io
, info
, sizeof(*info
), FileAllInformation
);
1322 ok(hr
== STATUS_BUFFER_OVERFLOW
, "NtQueryInformationFile returned %#x, expected %#x.\n",
1323 hr
, STATUS_BUFFER_OVERFLOW
);
1324 ok(U(io
).Status
== STATUS_BUFFER_OVERFLOW
, "io.Status is %#x, expected %#x.\n",
1325 U(io
).Status
, STATUS_BUFFER_OVERFLOW
);
1326 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1327 "info->NameInformation.FileNameLength is %u, expected %u.\n",
1328 info
->NameInformation
.FileNameLength
, lstrlenW( expected
) * sizeof(WCHAR
));
1329 ok(info
->NameInformation
.FileName
[2] == 0xcccc,
1330 "info->NameInformation.FileName[2] is %#x, expected 0xcccc.\n", info
->NameInformation
.FileName
[2]);
1331 ok(CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]) == CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]),
1332 "info->NameInformation.FileName[1] is %p, expected %p.\n",
1333 CharLowerW((LPWSTR
)(UINT_PTR
)info
->NameInformation
.FileName
[1]), CharLowerW((LPWSTR
)(UINT_PTR
)expected
[1]));
1334 ok(io
.Information
== sizeof(*info
), "io.Information is %lu, expected %u.\n", io
.Information
, sizeof(*info
));
1336 memset( info
, 0xcc, info_size
);
1337 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1338 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1339 ok(U(io
).Status
== STATUS_SUCCESS
, "io.Status is %#x, expected %#x.\n", U(io
).Status
, STATUS_SUCCESS
);
1340 ok(info
->NameInformation
.FileNameLength
== lstrlenW( expected
) * sizeof(WCHAR
),
1341 "info->NameInformation.FileNameLength is %u, expected %u.\n",
1342 info
->NameInformation
.FileNameLength
, lstrlenW( expected
) * sizeof(WCHAR
));
1343 ok(info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] == 0xcccc,
1344 "info->NameInformation.FileName[%u] is %#x, expected 0xcccc.\n",
1345 info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
),
1346 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)]);
1347 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1348 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
),
1349 "info->NameInformation.FileName is %s, expected %s.\n",
1350 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1351 ok(io
.Information
== FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
)
1352 + info
->NameInformation
.FileNameLength
,
1353 "io.Information is %lu, expected %u.\n",
1355 FIELD_OFFSET(FILE_ALL_INFORMATION
, NameInformation
.FileName
) + info
->NameInformation
.FileNameLength
);
1358 HeapFree( GetProcessHeap(), 0, info
);
1359 HeapFree( GetProcessHeap(), 0, expected
);
1360 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1362 if (old_redir
|| !pGetSystemWow64DirectoryW
|| !(file_name_size
= pGetSystemWow64DirectoryW( NULL
, 0 )))
1364 skip("Not running on WoW64, skipping test.\n");
1365 HeapFree( GetProcessHeap(), 0, file_name
);
1369 h
= CreateFileW( file_name
, GENERIC_READ
,
1370 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
1371 NULL
, OPEN_EXISTING
, FILE_FLAG_BACKUP_SEMANTICS
, 0 );
1372 ok(h
!= INVALID_HANDLE_VALUE
, "Failed to open file.\n");
1373 HeapFree( GetProcessHeap(), 0, file_name
);
1375 file_name
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*file_name
) );
1376 volume_prefix
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*volume_prefix
) );
1377 expected
= HeapAlloc( GetProcessHeap(), 0, file_name_size
* sizeof(*expected
) );
1379 len
= pGetSystemWow64DirectoryW( file_name
, file_name_size
);
1380 ok(len
== file_name_size
- 1,
1381 "GetSystemWow64DirectoryW returned %u, expected %u.\n",
1382 len
, file_name_size
- 1);
1384 len
= pGetVolumePathNameW( file_name
, volume_prefix
, file_name_size
);
1385 ok(len
, "GetVolumePathNameW failed.\n");
1387 len
= lstrlenW( volume_prefix
);
1388 if (len
&& volume_prefix
[len
- 1] == '\\') --len
;
1389 memcpy( expected
, file_name
+ len
, (file_name_size
- len
- 1) * sizeof(WCHAR
) );
1390 expected
[file_name_size
- len
- 1] = '\0';
1392 info_size
= sizeof(*info
) + (file_name_size
* sizeof(WCHAR
));
1393 info
= HeapAlloc( GetProcessHeap(), 0, info_size
);
1395 memset( info
, 0xcc, info_size
);
1396 hr
= pNtQueryInformationFile( h
, &io
, info
, info_size
, FileAllInformation
);
1397 ok(hr
== STATUS_SUCCESS
, "NtQueryInformationFile returned %#x, expected %#x.\n", hr
, STATUS_SUCCESS
);
1398 info
->NameInformation
.FileName
[info
->NameInformation
.FileNameLength
/ sizeof(WCHAR
)] = '\0';
1399 ok(!lstrcmpiW( info
->NameInformation
.FileName
, expected
), "info->NameInformation.FileName is %s, expected %s.\n",
1400 wine_dbgstr_w( info
->NameInformation
.FileName
), wine_dbgstr_w( expected
));
1403 HeapFree( GetProcessHeap(), 0, info
);
1404 HeapFree( GetProcessHeap(), 0, expected
);
1405 HeapFree( GetProcessHeap(), 0, volume_prefix
);
1406 HeapFree( GetProcessHeap(), 0, file_name
);
1411 HMODULE hkernel32
= GetModuleHandleA("kernel32.dll");
1412 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
1415 skip("not running on NT, skipping test\n");
1419 pGetVolumePathNameW
= (void *)GetProcAddress(hkernel32
, "GetVolumePathNameW");
1420 pGetSystemWow64DirectoryW
= (void *)GetProcAddress(hkernel32
, "GetSystemWow64DirectoryW");
1422 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
1423 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
1424 pRtlDosPathNameToNtPathName_U
= (void *)GetProcAddress(hntdll
, "RtlDosPathNameToNtPathName_U");
1425 pRtlWow64EnableFsRedirectionEx
= (void *)GetProcAddress(hntdll
, "RtlWow64EnableFsRedirectionEx");
1426 pNtCreateMailslotFile
= (void *)GetProcAddress(hntdll
, "NtCreateMailslotFile");
1427 pNtCreateFile
= (void *)GetProcAddress(hntdll
, "NtCreateFile");
1428 pNtOpenFile
= (void *)GetProcAddress(hntdll
, "NtOpenFile");
1429 pNtDeleteFile
= (void *)GetProcAddress(hntdll
, "NtDeleteFile");
1430 pNtReadFile
= (void *)GetProcAddress(hntdll
, "NtReadFile");
1431 pNtWriteFile
= (void *)GetProcAddress(hntdll
, "NtWriteFile");
1432 pNtCancelIoFile
= (void *)GetProcAddress(hntdll
, "NtCancelIoFile");
1433 pNtCancelIoFileEx
= (void *)GetProcAddress(hntdll
, "NtCancelIoFileEx");
1434 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
1435 pNtCreateIoCompletion
= (void *)GetProcAddress(hntdll
, "NtCreateIoCompletion");
1436 pNtOpenIoCompletion
= (void *)GetProcAddress(hntdll
, "NtOpenIoCompletion");
1437 pNtQueryIoCompletion
= (void *)GetProcAddress(hntdll
, "NtQueryIoCompletion");
1438 pNtRemoveIoCompletion
= (void *)GetProcAddress(hntdll
, "NtRemoveIoCompletion");
1439 pNtSetIoCompletion
= (void *)GetProcAddress(hntdll
, "NtSetIoCompletion");
1440 pNtSetInformationFile
= (void *)GetProcAddress(hntdll
, "NtSetInformationFile");
1441 pNtQueryInformationFile
= (void *)GetProcAddress(hntdll
, "NtQueryInformationFile");
1442 pNtQueryDirectoryFile
= (void *)GetProcAddress(hntdll
, "NtQueryDirectoryFile");
1449 test_iocompletion();
1450 test_file_basic_information();
1451 test_file_all_information();
1452 test_file_both_information();
1453 test_file_name_information();
1454 test_file_all_name_information();