1 /* Unit test suite for Ntdll file functions
3 * Copyright 2007 Jeff Latimer
4 * Copyright 2007 Andrey Turkin
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * We use function pointers here as there is no import library for NTDLL on
29 /* Define WIN32_NO_STATUS so MSVC does not give us duplicate macro
30 * definition errors when we get to winnt.h
32 #define WIN32_NO_STATUS
34 #include "wine/test.h"
37 #ifndef IO_COMPLETION_ALL_ACCESS
38 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
41 static VOID (WINAPI
*pRtlInitUnicodeString
)( PUNICODE_STRING
, LPCWSTR
);
42 static VOID (WINAPI
*pRtlFreeUnicodeString
)(PUNICODE_STRING
);
43 static NTSTATUS (WINAPI
*pNtCreateMailslotFile
)( PHANDLE
, ULONG
, POBJECT_ATTRIBUTES
, PIO_STATUS_BLOCK
,
44 ULONG
, ULONG
, ULONG
, PLARGE_INTEGER
);
45 static NTSTATUS (WINAPI
*pNtReadFile
)(HANDLE hFile
, HANDLE hEvent
,
46 PIO_APC_ROUTINE apc
, void* apc_user
,
47 PIO_STATUS_BLOCK io_status
, void* buffer
, ULONG length
,
48 PLARGE_INTEGER offset
, PULONG key
);
49 static NTSTATUS (WINAPI
*pNtWriteFile
)(HANDLE hFile
, HANDLE hEvent
,
50 PIO_APC_ROUTINE apc
, void* apc_user
,
51 PIO_STATUS_BLOCK io_status
,
52 const void* buffer
, ULONG length
,
53 PLARGE_INTEGER offset
, PULONG key
);
54 static NTSTATUS (WINAPI
*pNtClose
)( PHANDLE
);
56 static NTSTATUS (WINAPI
*pNtCreateIoCompletion
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
, ULONG
);
57 static NTSTATUS (WINAPI
*pNtOpenIoCompletion
)(PHANDLE
, ACCESS_MASK
, POBJECT_ATTRIBUTES
);
58 static NTSTATUS (WINAPI
*pNtQueryIoCompletion
)(HANDLE
, IO_COMPLETION_INFORMATION_CLASS
, PVOID
, ULONG
, PULONG
);
59 static NTSTATUS (WINAPI
*pNtRemoveIoCompletion
)(HANDLE
, PULONG_PTR
, PULONG_PTR
, PIO_STATUS_BLOCK
, PLARGE_INTEGER
);
60 static NTSTATUS (WINAPI
*pNtSetIoCompletion
)(HANDLE
, ULONG_PTR
, ULONG_PTR
, NTSTATUS
, ULONG
);
61 static NTSTATUS (WINAPI
*pNtSetInformationFile
)(HANDLE
, PIO_STATUS_BLOCK
, PVOID
, ULONG
, FILE_INFORMATION_CLASS
);
63 static inline BOOL
is_signaled( HANDLE obj
)
65 return WaitForSingleObject( obj
, 0 ) == 0;
68 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
70 static BOOL
create_pipe( HANDLE
*read
, HANDLE
*write
, ULONG flags
, ULONG size
)
72 *read
= CreateNamedPipe(PIPENAME
, PIPE_ACCESS_INBOUND
| flags
, PIPE_TYPE_BYTE
| PIPE_WAIT
,
73 1, size
, size
, NMPWAIT_USE_DEFAULT_WAIT
, NULL
);
74 ok(*read
!= INVALID_HANDLE_VALUE
, "CreateNamedPipe failed\n");
76 *write
= CreateFileA(PIPENAME
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, 0, 0);
77 ok(*write
!= INVALID_HANDLE_VALUE
, "CreateFile failed (%d)\n", GetLastError());
82 static HANDLE
create_temp_file( ULONG flags
)
84 char buffer
[MAX_PATH
];
87 GetTempFileNameA( ".", "foo", 0, buffer
);
88 handle
= CreateFileA(buffer
, GENERIC_READ
| GENERIC_WRITE
, 0, NULL
, CREATE_ALWAYS
,
89 flags
| FILE_FLAG_DELETE_ON_CLOSE
, 0);
90 ok( handle
!= INVALID_HANDLE_VALUE
, "failed to create temp file\n" );
91 return (handle
== INVALID_HANDLE_VALUE
) ? 0 : handle
;
94 #define CVALUE_FIRST 0xfffabbcc
95 #define CKEY_FIRST 0x1030341
96 #define CKEY_SECOND 0x132E46
98 ULONG_PTR completionKey
;
100 ULONG_PTR completionValue
;
102 static long get_pending_msgs(HANDLE h
)
107 res
= pNtQueryIoCompletion( h
, IoCompletionBasicInformation
, (PVOID
)&a
, sizeof(a
), &req
);
108 ok( res
== STATUS_SUCCESS
, "NtQueryIoCompletion failed: %x\n", res
);
109 if (res
!= STATUS_SUCCESS
) return -1;
110 ok( req
== sizeof(a
), "Unexpected response size: %x\n", req
);
114 static BOOL
get_msg(HANDLE h
)
116 LARGE_INTEGER timeout
= {{-10000000*3}};
117 DWORD res
= pNtRemoveIoCompletion( h
, &completionKey
, &completionValue
, &ioSb
, &timeout
);
118 ok( res
== STATUS_SUCCESS
, "NtRemoveIoCompletion failed: %x\n", res
);
119 if (res
!= STATUS_SUCCESS
)
121 completionKey
= completionValue
= 0;
122 memset(&ioSb
, 0, sizeof(ioSb
));
129 static void WINAPI
apc( void *arg
, IO_STATUS_BLOCK
*iosb
, ULONG reserved
)
133 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
134 iosb
, U(*iosb
).Status
, iosb
->Information
);
136 ok( !reserved
, "reserved is not 0: %x\n", reserved
);
139 static void read_file_test(void)
141 const char text
[] = "foobar";
142 HANDLE handle
, read
, write
;
144 IO_STATUS_BLOCK iosb
;
148 LARGE_INTEGER offset
;
149 HANDLE event
= CreateEventA( NULL
, TRUE
, FALSE
, NULL
);
153 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
155 /* try read with no data */
156 U(iosb
).Status
= 0xdeadbabe;
157 iosb
.Information
= 0xdeadbeef;
158 ok( is_signaled( read
), "read handle is not signaled\n" );
159 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
160 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
161 ok( !is_signaled( read
), "read handle is signaled\n" );
162 ok( !is_signaled( event
), "event is signaled\n" );
163 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
164 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
165 ok( !apc_count
, "apc was called\n" );
166 WriteFile( write
, buffer
, 1, &written
, NULL
);
167 /* iosb updated here by async i/o */
168 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
169 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
170 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
171 ok( !is_signaled( read
), "read handle is signaled\n" );
172 ok( is_signaled( event
), "event is not signaled\n" );
173 ok( !apc_count
, "apc was called\n" );
175 SleepEx( 1, FALSE
); /* non-alertable sleep */
176 ok( !apc_count
, "apc was called\n" );
177 SleepEx( 1, TRUE
); /* alertable sleep */
178 ok( apc_count
== 1, "apc not called\n" );
180 /* with no event, the pipe handle itself gets signaled */
182 U(iosb
).Status
= 0xdeadbabe;
183 iosb
.Information
= 0xdeadbeef;
184 ok( !is_signaled( read
), "read handle is not signaled\n" );
185 status
= pNtReadFile( read
, 0, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
186 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
187 ok( !is_signaled( read
), "read handle is signaled\n" );
188 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
189 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
190 ok( !apc_count
, "apc was called\n" );
191 WriteFile( write
, buffer
, 1, &written
, NULL
);
192 /* iosb updated here by async i/o */
193 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
194 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
195 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
196 ok( is_signaled( read
), "read handle is signaled\n" );
197 ok( !apc_count
, "apc was called\n" );
199 SleepEx( 1, FALSE
); /* non-alertable sleep */
200 ok( !apc_count
, "apc was called\n" );
201 SleepEx( 1, TRUE
); /* alertable sleep */
202 ok( apc_count
== 1, "apc not called\n" );
204 /* now read with data ready */
206 U(iosb
).Status
= 0xdeadbabe;
207 iosb
.Information
= 0xdeadbeef;
209 WriteFile( write
, buffer
, 1, &written
, NULL
);
210 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
211 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
212 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
213 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
214 ok( is_signaled( event
), "event is not signaled\n" );
215 ok( !apc_count
, "apc was called\n" );
216 SleepEx( 1, FALSE
); /* non-alertable sleep */
217 ok( !apc_count
, "apc was called\n" );
218 SleepEx( 1, TRUE
); /* alertable sleep */
219 ok( apc_count
== 1, "apc not called\n" );
221 /* try read with no data */
223 U(iosb
).Status
= 0xdeadbabe;
224 iosb
.Information
= 0xdeadbeef;
225 ok( is_signaled( event
), "event is not signaled\n" ); /* check that read resets the event */
226 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
227 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
228 ok( !is_signaled( event
), "event is signaled\n" );
229 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
230 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
231 ok( !apc_count
, "apc was called\n" );
232 WriteFile( write
, buffer
, 1, &written
, NULL
);
233 /* partial read is good enough */
234 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
235 ok( is_signaled( event
), "event is signaled\n" );
236 ok( U(iosb
).Status
== 0, "wrong status %x\n", U(iosb
).Status
);
237 ok( iosb
.Information
== 1, "wrong info %lu\n", iosb
.Information
);
238 ok( !apc_count
, "apc was called\n" );
239 SleepEx( 1, TRUE
); /* alertable sleep */
240 ok( apc_count
== 1, "apc was not called\n" );
242 /* read from disconnected pipe */
244 U(iosb
).Status
= 0xdeadbabe;
245 iosb
.Information
= 0xdeadbeef;
246 CloseHandle( write
);
247 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
248 ok( status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", status
);
249 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
250 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
251 ok( !is_signaled( event
), "event is signaled\n" );
252 ok( !apc_count
, "apc was called\n" );
253 SleepEx( 1, TRUE
); /* alertable sleep */
254 ok( !apc_count
, "apc was called\n" );
257 /* read from closed handle */
259 U(iosb
).Status
= 0xdeadbabe;
260 iosb
.Information
= 0xdeadbeef;
262 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 1, NULL
, NULL
);
263 ok( status
== STATUS_INVALID_HANDLE
, "wrong status %x\n", status
);
264 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
265 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
266 ok( is_signaled( event
), "event is signaled\n" ); /* not reset on invalid handle */
267 ok( !apc_count
, "apc was called\n" );
268 SleepEx( 1, TRUE
); /* alertable sleep */
269 ok( !apc_count
, "apc was called\n" );
271 /* disconnect while async read is in progress */
272 if (!create_pipe( &read
, &write
, FILE_FLAG_OVERLAPPED
, 4096 )) return;
274 U(iosb
).Status
= 0xdeadbabe;
275 iosb
.Information
= 0xdeadbeef;
276 status
= pNtReadFile( read
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, NULL
, NULL
);
277 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
278 ok( !is_signaled( event
), "event is signaled\n" );
279 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
280 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
281 ok( !apc_count
, "apc was called\n" );
282 CloseHandle( write
);
283 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
284 ok( U(iosb
).Status
== STATUS_PIPE_BROKEN
, "wrong status %x\n", U(iosb
).Status
);
285 ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
286 ok( is_signaled( event
), "event is signaled\n" );
287 ok( !apc_count
, "apc was called\n" );
288 SleepEx( 1, TRUE
); /* alertable sleep */
289 ok( apc_count
== 1, "apc was not called\n" );
292 /* now try a real file */
293 if (!(handle
= create_temp_file( FILE_FLAG_OVERLAPPED
))) return;
295 U(iosb
).Status
= 0xdeadbabe;
296 iosb
.Information
= 0xdeadbeef;
299 pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
300 ok( status
== STATUS_PENDING
, "wrong status %x\n", status
);
301 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
302 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
303 ok( is_signaled( event
), "event is signaled\n" );
304 ok( !apc_count
, "apc was called\n" );
305 SleepEx( 1, TRUE
); /* alertable sleep */
306 ok( apc_count
== 1, "apc was not called\n" );
309 U(iosb
).Status
= 0xdeadbabe;
310 iosb
.Information
= 0xdeadbeef;
313 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
314 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
315 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
316 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
317 ok( is_signaled( event
), "event is signaled\n" );
318 ok( !apc_count
, "apc was called\n" );
319 SleepEx( 1, TRUE
); /* alertable sleep */
320 ok( apc_count
== 1, "apc was not called\n" );
322 /* read beyond eof */
324 U(iosb
).Status
= 0xdeadbabe;
325 iosb
.Information
= 0xdeadbeef;
326 offset
.QuadPart
= strlen(text
) + 2;
327 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
328 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
329 ok( U(iosb
).Status
== 0xdeadbabe, "wrong status %x\n", U(iosb
).Status
);
330 ok( iosb
.Information
== 0xdeadbeef, "wrong info %lu\n", iosb
.Information
);
331 ok( !is_signaled( event
), "event is signaled\n" );
332 ok( !apc_count
, "apc was called\n" );
333 SleepEx( 1, TRUE
); /* alertable sleep */
334 ok( !apc_count
, "apc was called\n" );
335 CloseHandle( handle
);
337 /* now a non-overlapped file */
338 if (!(handle
= create_temp_file(0))) return;
340 U(iosb
).Status
= 0xdeadbabe;
341 iosb
.Information
= 0xdeadbeef;
343 pNtWriteFile( handle
, event
, apc
, &apc_count
, &iosb
, text
, strlen(text
), &offset
, NULL
);
344 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
345 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
346 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
347 ok( is_signaled( event
), "event is signaled\n" );
348 ok( !apc_count
, "apc was called\n" );
349 SleepEx( 1, TRUE
); /* alertable sleep */
350 ok( apc_count
== 1, "apc was not called\n" );
353 U(iosb
).Status
= 0xdeadbabe;
354 iosb
.Information
= 0xdeadbeef;
357 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, strlen(text
) + 10, &offset
, NULL
);
358 ok( status
== STATUS_SUCCESS
, "wrong status %x\n", status
);
359 ok( U(iosb
).Status
== STATUS_SUCCESS
, "wrong status %x\n", U(iosb
).Status
);
360 ok( iosb
.Information
== strlen(text
), "wrong info %lu\n", iosb
.Information
);
361 ok( is_signaled( event
), "event is signaled\n" );
362 ok( !apc_count
, "apc was called\n" );
363 SleepEx( 1, TRUE
); /* alertable sleep */
364 todo_wine
ok( !apc_count
, "apc was called\n" );
366 /* read beyond eof */
368 U(iosb
).Status
= 0xdeadbabe;
369 iosb
.Information
= 0xdeadbeef;
370 offset
.QuadPart
= strlen(text
) + 2;
372 status
= pNtReadFile( handle
, event
, apc
, &apc_count
, &iosb
, buffer
, 2, &offset
, NULL
);
373 ok( status
== STATUS_END_OF_FILE
, "wrong status %x\n", status
);
374 todo_wine
ok( U(iosb
).Status
== STATUS_END_OF_FILE
, "wrong status %x\n", U(iosb
).Status
);
375 todo_wine
ok( iosb
.Information
== 0, "wrong info %lu\n", iosb
.Information
);
376 todo_wine
ok( is_signaled( event
), "event is not signaled\n" );
377 ok( !apc_count
, "apc was called\n" );
378 SleepEx( 1, TRUE
); /* alertable sleep */
379 ok( !apc_count
, "apc was called\n" );
381 CloseHandle( handle
);
383 CloseHandle( event
);
386 static void nt_mailslot_test(void)
389 ACCESS_MASK DesiredAccess
;
390 OBJECT_ATTRIBUTES attr
;
394 ULONG MaxMessageSize
;
395 LARGE_INTEGER TimeOut
;
396 IO_STATUS_BLOCK IoStatusBlock
;
399 WCHAR buffer1
[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
400 'R',':','\\','F','R','E','D','\0' };
402 TimeOut
.QuadPart
= -1;
404 pRtlInitUnicodeString(&str
, buffer1
);
405 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
406 DesiredAccess
= CreateOptions
= MailslotQuota
= MaxMessageSize
= 0;
409 * Check for NULL pointer handling
411 rc
= pNtCreateMailslotFile(NULL
, DesiredAccess
,
412 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
414 ok( rc
== STATUS_ACCESS_VIOLATION
, "rc = %x not c0000005 STATUS_ACCESS_VIOLATION\n", rc
);
417 * Test to see if the Timeout can be NULL
419 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
420 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
422 ok( rc
== STATUS_SUCCESS
, "rc = %x not STATUS_SUCCESS\n", rc
);
423 ok( hslot
!= 0, "Handle is invalid\n");
425 if ( rc
== STATUS_SUCCESS
) rc
= pNtClose(hslot
);
428 * Test that the length field is checked properly
431 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
432 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
434 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
436 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
438 attr
.Length
= sizeof(OBJECT_ATTRIBUTES
)+1;
439 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
440 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
442 todo_wine
ok( rc
== STATUS_INVALID_PARAMETER
, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc
);
444 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
447 * Test handling of a NULL unicode string in ObjectName
449 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
450 attr
.ObjectName
= NULL
;
451 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
452 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
454 ok( rc
== STATUS_OBJECT_PATH_SYNTAX_BAD
, "rc = %x not c000003b STATUS_OBJECT_PATH_SYNTAX_BAD\n", rc
);
456 if (rc
== STATUS_SUCCESS
) pNtClose(hslot
);
461 InitializeObjectAttributes(&attr
, &str
, OBJ_CASE_INSENSITIVE
, 0, NULL
);
462 rc
= pNtCreateMailslotFile(&hslot
, DesiredAccess
,
463 &attr
, &IoStatusBlock
, CreateOptions
, MailslotQuota
, MaxMessageSize
,
465 ok( rc
== STATUS_SUCCESS
, "Create MailslotFile failed rc = %x %u\n", rc
, GetLastError());
466 ok( hslot
!= 0, "Handle is invalid\n");
468 rc
= pNtClose(hslot
);
469 ok( rc
== STATUS_SUCCESS
, "NtClose failed\n");
471 pRtlFreeUnicodeString(&str
);
474 static void test_iocp_setcompletion(HANDLE h
)
479 res
= pNtSetIoCompletion( h
, CKEY_FIRST
, CVALUE_FIRST
, STATUS_INVALID_DEVICE_REQUEST
, 3 );
480 ok( res
== STATUS_SUCCESS
, "NtSetIoCompletion failed: %x\n", res
);
482 count
= get_pending_msgs(h
);
483 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
487 ok( completionKey
== CKEY_FIRST
, "Invalid completion key: %lx\n", completionKey
);
488 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
489 ok( U(ioSb
).Status
== STATUS_INVALID_DEVICE_REQUEST
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
490 ok( completionValue
== CVALUE_FIRST
, "Invalid completion value: %lx\n", completionValue
);
493 count
= get_pending_msgs(h
);
494 ok( !count
, "Unexpected msg count: %ld\n", count
);
497 static void test_iocp_fileio(HANDLE h
)
499 static const char pipe_name
[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
501 HANDLE hPipeSrv
= CreateNamedPipeA( pipe_name
, PIPE_ACCESS_INBOUND
| FILE_FLAG_OVERLAPPED
, PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
, 4, 1024, 1024, 1000, NULL
);
502 HANDLE hPipeClt
= CreateFileA( pipe_name
, GENERIC_WRITE
, 0, NULL
, OPEN_EXISTING
, FILE_FLAG_NO_BUFFERING
| FILE_FLAG_OVERLAPPED
, NULL
);
503 ok( hPipeSrv
!= INVALID_HANDLE_VALUE
&& hPipeClt
!= INVALID_HANDLE_VALUE
, "Cannot create or connect to pipe\n" );
504 if (hPipeSrv
!= INVALID_HANDLE_VALUE
&& hPipeClt
!= INVALID_HANDLE_VALUE
)
510 FILE_COMPLETION_INFORMATION fci
= {h
, CKEY_SECOND
};
511 IO_STATUS_BLOCK iosb
;
513 NTSTATUS res
= pNtSetInformationFile( hPipeSrv
, &iosb
, &fci
, sizeof(fci
), FileCompletionInformation
);
514 ok( res
== STATUS_SUCCESS
, "NtSetInformationFile failed: %x\n", res
);
515 ok( iosb
.Status
== STATUS_SUCCESS
, "iosb.Status invalid: %x\n", iosb
.Status
);
517 count
= get_pending_msgs(h
);
518 ok( !count
, "Unexpected msg count: %ld\n", count
);
519 ReadFile( hPipeSrv
, buf
, 3, &read
, &o
);
520 count
= get_pending_msgs(h
);
521 ok( !count
, "Unexpected msg count: %ld\n", count
);
522 WriteFile( hPipeClt
, buf
, 3, &read
, NULL
);
526 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
528 ok( ioSb
.Information
== 3, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
530 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
531 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
533 count
= get_pending_msgs(h
);
534 ok( !count
, "Unexpected msg count: %ld\n", count
);
536 WriteFile( hPipeClt
, buf
, 2, &read
, NULL
);
537 count
= get_pending_msgs(h
);
538 ok( !count
, "Unexpected msg count: %ld\n", count
);
539 ReadFile( hPipeSrv
, buf
, 2, &read
, &o
);
540 count
= get_pending_msgs(h
);
541 ok( count
== 1, "Unexpected msg count: %ld\n", count
);
544 ok( completionKey
== CKEY_SECOND
, "Invalid completion key: %lx\n", completionKey
);
545 ok( ioSb
.Information
== 2, "Invalid ioSb.Information: %ld\n", ioSb
.Information
);
546 ok( U(ioSb
).Status
== STATUS_SUCCESS
, "Invalid ioSb.Status: %x\n", U(ioSb
).Status
);
547 ok( completionValue
== (ULONG_PTR
)&o
, "Invalid completion value: %lx\n", completionValue
);
551 CloseHandle( hPipeSrv
);
552 CloseHandle( hPipeClt
);
555 static void test_iocompletion(void)
557 HANDLE h
= INVALID_HANDLE_VALUE
;
560 res
= pNtCreateIoCompletion( &h
, IO_COMPLETION_ALL_ACCESS
, NULL
, 0);
562 ok( res
== 0, "NtCreateIoCompletion anonymous failed: %x\n", res
);
563 ok( h
&& h
!= INVALID_HANDLE_VALUE
, "Invalid handle returned\n" );
565 if ( h
&& h
!= INVALID_HANDLE_VALUE
)
567 test_iocp_setcompletion(h
);
575 HMODULE hntdll
= GetModuleHandleA("ntdll.dll");
578 skip("not running on NT, skipping test\n");
582 pRtlFreeUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlFreeUnicodeString");
583 pRtlInitUnicodeString
= (void *)GetProcAddress(hntdll
, "RtlInitUnicodeString");
584 pNtCreateMailslotFile
= (void *)GetProcAddress(hntdll
, "NtCreateMailslotFile");
585 pNtReadFile
= (void *)GetProcAddress(hntdll
, "NtReadFile");
586 pNtWriteFile
= (void *)GetProcAddress(hntdll
, "NtWriteFile");
587 pNtClose
= (void *)GetProcAddress(hntdll
, "NtClose");
588 pNtCreateIoCompletion
= (void *)GetProcAddress(hntdll
, "NtCreateIoCompletion");
589 pNtOpenIoCompletion
= (void *)GetProcAddress(hntdll
, "NtOpenIoCompletion");
590 pNtQueryIoCompletion
= (void *)GetProcAddress(hntdll
, "NtQueryIoCompletion");
591 pNtRemoveIoCompletion
= (void *)GetProcAddress(hntdll
, "NtRemoveIoCompletion");
592 pNtSetIoCompletion
= (void *)GetProcAddress(hntdll
, "NtSetIoCompletion");
593 pNtSetInformationFile
= (void *)GetProcAddress(hntdll
, "NtSetInformationFile");