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"
38 #ifndef IO_COMPLETION_ALL_ACCESS
39 #define IO_COMPLETION_ALL_ACCESS 0x001F0003
42 static NTSTATUS (WINAPI *pRtlFreeUnicodeString)( PUNICODE_STRING );
43 static VOID (WINAPI *pRtlInitUnicodeString)( PUNICODE_STRING, LPCWSTR );
44 static BOOL (WINAPI *pRtlDosPathNameToNtPathName_U)( LPCWSTR, PUNICODE_STRING, PWSTR*, CURDIR* );
45 static NTSTATUS (WINAPI *pNtCreateMailslotFile)( PHANDLE, ULONG, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK,
46 ULONG, ULONG, ULONG, PLARGE_INTEGER );
47 static NTSTATUS (WINAPI *pNtDeleteFile)(POBJECT_ATTRIBUTES ObjectAttributes);
48 static NTSTATUS (WINAPI *pNtReadFile)(HANDLE hFile, HANDLE hEvent,
49 PIO_APC_ROUTINE apc, void* apc_user,
50 PIO_STATUS_BLOCK io_status, void* buffer, ULONG length,
51 PLARGE_INTEGER offset, PULONG key);
52 static NTSTATUS (WINAPI *pNtWriteFile)(HANDLE hFile, HANDLE hEvent,
53 PIO_APC_ROUTINE apc, void* apc_user,
54 PIO_STATUS_BLOCK io_status,
55 const void* buffer, ULONG length,
56 PLARGE_INTEGER offset, PULONG key);
57 static NTSTATUS (WINAPI *pNtClose)( PHANDLE );
59 static NTSTATUS (WINAPI *pNtCreateIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, ULONG);
60 static NTSTATUS (WINAPI *pNtOpenIoCompletion)(PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES);
61 static NTSTATUS (WINAPI *pNtQueryIoCompletion)(HANDLE, IO_COMPLETION_INFORMATION_CLASS, PVOID, ULONG, PULONG);
62 static NTSTATUS (WINAPI *pNtRemoveIoCompletion)(HANDLE, PULONG_PTR, PULONG_PTR, PIO_STATUS_BLOCK, PLARGE_INTEGER);
63 static NTSTATUS (WINAPI *pNtSetIoCompletion)(HANDLE, ULONG_PTR, ULONG_PTR, NTSTATUS, ULONG);
64 static NTSTATUS (WINAPI *pNtSetInformationFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS);
66 static inline BOOL is_signaled( HANDLE obj )
68 return WaitForSingleObject( obj, 0 ) == 0;
71 #define PIPENAME "\\\\.\\pipe\\ntdll_tests_file.c"
72 #define TEST_BUF_LEN 3
74 static BOOL create_pipe( HANDLE *read, HANDLE *write, ULONG flags, ULONG size )
76 *read = CreateNamedPipe(PIPENAME, PIPE_ACCESS_INBOUND | flags, PIPE_TYPE_BYTE | PIPE_WAIT,
77 1, size, size, NMPWAIT_USE_DEFAULT_WAIT, NULL);
78 ok(*read != INVALID_HANDLE_VALUE, "CreateNamedPipe failed\n");
80 *write = CreateFileA(PIPENAME, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
81 ok(*write != INVALID_HANDLE_VALUE, "CreateFile failed (%d)\n", GetLastError());
86 static HANDLE create_temp_file( ULONG flags )
88 char buffer[MAX_PATH];
91 GetTempFileNameA( ".", "foo", 0, buffer );
92 handle = CreateFileA(buffer, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS,
93 flags | FILE_FLAG_DELETE_ON_CLOSE, 0);
94 ok( handle != INVALID_HANDLE_VALUE, "failed to create temp file\n" );
95 return (handle == INVALID_HANDLE_VALUE) ? 0 : handle;
98 #define CVALUE_FIRST 0xfffabbcc
99 #define CKEY_FIRST 0x1030341
100 #define CKEY_SECOND 0x132E46
102 ULONG_PTR completionKey;
103 IO_STATUS_BLOCK ioSb;
104 ULONG_PTR completionValue;
106 static long get_pending_msgs(HANDLE h)
111 res = pNtQueryIoCompletion( h, IoCompletionBasicInformation, &a, sizeof(a), &req );
112 ok( res == STATUS_SUCCESS, "NtQueryIoCompletion failed: %x\n", res );
113 if (res != STATUS_SUCCESS) return -1;
114 ok( req == sizeof(a), "Unexpected response size: %x\n", req );
118 static BOOL get_msg(HANDLE h)
120 LARGE_INTEGER timeout = {{-10000000*3}};
121 DWORD res = pNtRemoveIoCompletion( h, &completionKey, &completionValue, &ioSb, &timeout);
122 ok( res == STATUS_SUCCESS, "NtRemoveIoCompletion failed: %x\n", res );
123 if (res != STATUS_SUCCESS)
125 completionKey = completionValue = 0;
126 memset(&ioSb, 0, sizeof(ioSb));
133 static void WINAPI apc( void *arg, IO_STATUS_BLOCK *iosb, ULONG reserved )
137 trace( "apc called block %p iosb.status %x iosb.info %lu\n",
138 iosb, U(*iosb).Status, iosb->Information );
140 ok( !reserved, "reserved is not 0: %x\n", reserved );
143 static void delete_file_test(void)
146 OBJECT_ATTRIBUTES attr;
147 UNICODE_STRING nameW;
148 WCHAR pathW[MAX_PATH];
149 WCHAR pathsubW[MAX_PATH];
150 static const WCHAR testdirW[] = {'n','t','d','e','l','e','t','e','f','i','l','e',0};
151 static const WCHAR subdirW[] = {'\\','s','u','b',0};
153 ret = GetTempPathW(MAX_PATH, pathW);
156 ok(0, "couldn't get temp dir\n");
159 if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
161 ok(0, "MAX_PATH exceeded in constructing paths\n");
165 lstrcatW(pathW, testdirW);
166 lstrcpyW(pathsubW, pathW);
167 lstrcatW(pathsubW, subdirW);
169 ret = CreateDirectoryW(pathW, NULL);
170 ok(ret == TRUE, "couldn't create directory ntdeletefile\n");
171 if (!pRtlDosPathNameToNtPathName_U(pathW, &nameW, NULL, NULL))
173 ok(0,"RtlDosPathNametoNtPathName_U failed\n");
177 attr.Length = sizeof(attr);
178 attr.RootDirectory = 0;
179 attr.Attributes = OBJ_CASE_INSENSITIVE;
180 attr.ObjectName = &nameW;
181 attr.SecurityDescriptor = NULL;
182 attr.SecurityQualityOfService = NULL;
184 /* test NtDeleteFile on an empty directory */
185 ret = pNtDeleteFile(&attr);
186 ok(ret == STATUS_SUCCESS, "NtDeleteFile should succeed in removing an empty directory\n");
187 ret = RemoveDirectoryW(pathW);
188 ok(ret == FALSE, "expected to fail removing directory, NtDeleteFile should have removed it\n");
190 /* test NtDeleteFile on a non-empty directory */
191 ret = CreateDirectoryW(pathW, NULL);
192 ok(ret == TRUE, "couldn't create directory ntdeletefile ?!\n");
193 ret = CreateDirectoryW(pathsubW, NULL);
194 ok(ret == TRUE, "couldn't create directory subdir\n");
195 ret = pNtDeleteFile(&attr);
196 ok(ret == STATUS_SUCCESS, "expected NtDeleteFile to ret STATUS_SUCCESS\n");
197 ret = RemoveDirectoryW(pathsubW);
198 ok(ret == TRUE, "expected to remove directory ntdeletefile\\sub\n");
199 ret = RemoveDirectoryW(pathW);
200 ok(ret == TRUE, "expected to remove directory ntdeletefile, NtDeleteFile failed.\n");
202 pRtlFreeUnicodeString( &nameW );
205 static void read_file_test(void)
207 const char text[] = "foobar";
208 HANDLE handle, read, write;
210 IO_STATUS_BLOCK iosb;
214 LARGE_INTEGER offset;
215 HANDLE event = CreateEventA( NULL, TRUE, FALSE, NULL );
219 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
221 /* try read with no data */
222 U(iosb).Status = 0xdeadbabe;
223 iosb.Information = 0xdeadbeef;
224 ok( is_signaled( read ), "read handle is not signaled\n" );
225 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
226 ok( status == STATUS_PENDING, "wrong status %x\n", status );
227 ok( !is_signaled( read ), "read handle is signaled\n" );
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 /* iosb updated here by async i/o */
234 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
235 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
236 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
237 ok( !is_signaled( read ), "read handle is signaled\n" );
238 ok( is_signaled( event ), "event is not signaled\n" );
239 ok( !apc_count, "apc was called\n" );
241 SleepEx( 1, FALSE ); /* non-alertable sleep */
242 ok( !apc_count, "apc was called\n" );
243 SleepEx( 1, TRUE ); /* alertable sleep */
244 ok( apc_count == 1, "apc not called\n" );
246 /* with no event, the pipe handle itself gets signaled */
248 U(iosb).Status = 0xdeadbabe;
249 iosb.Information = 0xdeadbeef;
250 ok( !is_signaled( read ), "read handle is not signaled\n" );
251 status = pNtReadFile( read, 0, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
252 ok( status == STATUS_PENDING, "wrong status %x\n", status );
253 ok( !is_signaled( read ), "read handle is signaled\n" );
254 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
255 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
256 ok( !apc_count, "apc was called\n" );
257 WriteFile( write, buffer, 1, &written, NULL );
258 /* iosb updated here by async i/o */
259 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
260 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
261 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
262 ok( is_signaled( read ), "read handle is signaled\n" );
263 ok( !apc_count, "apc was called\n" );
265 SleepEx( 1, FALSE ); /* non-alertable sleep */
266 ok( !apc_count, "apc was called\n" );
267 SleepEx( 1, TRUE ); /* alertable sleep */
268 ok( apc_count == 1, "apc not called\n" );
270 /* now read with data ready */
272 U(iosb).Status = 0xdeadbabe;
273 iosb.Information = 0xdeadbeef;
275 WriteFile( write, buffer, 1, &written, NULL );
276 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
277 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
278 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
279 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
280 ok( is_signaled( event ), "event is not signaled\n" );
281 ok( !apc_count, "apc was called\n" );
282 SleepEx( 1, FALSE ); /* non-alertable sleep */
283 ok( !apc_count, "apc was called\n" );
284 SleepEx( 1, TRUE ); /* alertable sleep */
285 ok( apc_count == 1, "apc not called\n" );
287 /* try read with no data */
289 U(iosb).Status = 0xdeadbabe;
290 iosb.Information = 0xdeadbeef;
291 ok( is_signaled( event ), "event is not signaled\n" ); /* check that read resets the event */
292 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
293 ok( status == STATUS_PENDING, "wrong status %x\n", status );
294 ok( !is_signaled( event ), "event is signaled\n" );
295 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
296 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
297 ok( !apc_count, "apc was called\n" );
298 WriteFile( write, buffer, 1, &written, NULL );
299 /* partial read is good enough */
300 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
301 ok( is_signaled( event ), "event is signaled\n" );
302 ok( U(iosb).Status == 0, "wrong status %x\n", U(iosb).Status );
303 ok( iosb.Information == 1, "wrong info %lu\n", iosb.Information );
304 ok( !apc_count, "apc was called\n" );
305 SleepEx( 1, TRUE ); /* alertable sleep */
306 ok( apc_count == 1, "apc was not called\n" );
308 /* read from disconnected pipe */
310 U(iosb).Status = 0xdeadbabe;
311 iosb.Information = 0xdeadbeef;
312 CloseHandle( write );
313 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
314 ok( status == STATUS_PIPE_BROKEN, "wrong status %x\n", status );
315 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
316 ok( iosb.Information == 0xdeadbeef, "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, "apc was called\n" );
323 /* read from closed handle */
325 U(iosb).Status = 0xdeadbabe;
326 iosb.Information = 0xdeadbeef;
328 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 1, NULL, NULL );
329 ok( status == STATUS_INVALID_HANDLE, "wrong status %x\n", status );
330 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
331 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
332 ok( is_signaled( event ), "event is signaled\n" ); /* not reset on invalid handle */
333 ok( !apc_count, "apc was called\n" );
334 SleepEx( 1, TRUE ); /* alertable sleep */
335 ok( !apc_count, "apc was called\n" );
337 /* disconnect while async read is in progress */
338 if (!create_pipe( &read, &write, FILE_FLAG_OVERLAPPED, 4096 )) return;
340 U(iosb).Status = 0xdeadbabe;
341 iosb.Information = 0xdeadbeef;
342 status = pNtReadFile( read, event, apc, &apc_count, &iosb, buffer, 2, NULL, NULL );
343 ok( status == STATUS_PENDING, "wrong status %x\n", status );
344 ok( !is_signaled( event ), "event is signaled\n" );
345 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
346 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
347 ok( !apc_count, "apc was called\n" );
348 CloseHandle( write );
349 Sleep(1); /* FIXME: needed for wine to run the i/o apc */
350 ok( U(iosb).Status == STATUS_PIPE_BROKEN, "wrong status %x\n", U(iosb).Status );
351 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
352 ok( is_signaled( event ), "event is signaled\n" );
353 ok( !apc_count, "apc was called\n" );
354 SleepEx( 1, TRUE ); /* alertable sleep */
355 ok( apc_count == 1, "apc was not called\n" );
358 /* now try a real file */
359 if (!(handle = create_temp_file( FILE_FLAG_OVERLAPPED ))) return;
361 U(iosb).Status = 0xdeadbabe;
362 iosb.Information = 0xdeadbeef;
365 pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
366 ok( status == STATUS_PENDING, "wrong status %x\n", status );
367 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
368 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
369 ok( is_signaled( event ), "event is signaled\n" );
370 ok( !apc_count, "apc was called\n" );
371 SleepEx( 1, TRUE ); /* alertable sleep */
372 ok( apc_count == 1, "apc was not called\n" );
375 U(iosb).Status = 0xdeadbabe;
376 iosb.Information = 0xdeadbeef;
379 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
380 ok( status == STATUS_SUCCESS ||
381 status == STATUS_PENDING, /* vista */
382 "wrong status %x\n", status );
383 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
384 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
385 ok( is_signaled( event ), "event is signaled\n" );
386 ok( !apc_count, "apc was called\n" );
387 SleepEx( 1, TRUE ); /* alertable sleep */
388 ok( apc_count == 1, "apc was not called\n" );
390 /* read beyond eof */
392 U(iosb).Status = 0xdeadbabe;
393 iosb.Information = 0xdeadbeef;
394 offset.QuadPart = strlen(text) + 2;
395 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
396 if (status == STATUS_PENDING) /* vista */
398 ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
399 ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
400 ok( is_signaled( event ), "event is signaled\n" );
401 ok( !apc_count, "apc was called\n" );
402 SleepEx( 1, TRUE ); /* alertable sleep */
403 ok( apc_count == 1, "apc was not called\n" );
407 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
408 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
409 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
410 ok( !is_signaled( event ), "event is signaled\n" );
411 ok( !apc_count, "apc was called\n" );
412 SleepEx( 1, TRUE ); /* alertable sleep */
413 ok( !apc_count, "apc was called\n" );
415 CloseHandle( handle );
417 /* now a non-overlapped file */
418 if (!(handle = create_temp_file(0))) return;
420 U(iosb).Status = 0xdeadbabe;
421 iosb.Information = 0xdeadbeef;
423 pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
424 ok( status == STATUS_END_OF_FILE ||
425 status == STATUS_PENDING, /* vista */
426 "wrong status %x\n", status );
427 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
428 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
429 ok( is_signaled( event ), "event is signaled\n" );
430 ok( !apc_count, "apc was called\n" );
431 SleepEx( 1, TRUE ); /* alertable sleep */
432 ok( apc_count == 1, "apc was not called\n" );
435 U(iosb).Status = 0xdeadbabe;
436 iosb.Information = 0xdeadbeef;
439 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
440 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
441 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
442 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
443 ok( is_signaled( event ), "event is signaled\n" );
444 ok( !apc_count, "apc was called\n" );
445 SleepEx( 1, TRUE ); /* alertable sleep */
446 todo_wine ok( !apc_count, "apc was called\n" );
448 /* read beyond eof */
450 U(iosb).Status = 0xdeadbabe;
451 iosb.Information = 0xdeadbeef;
452 offset.QuadPart = strlen(text) + 2;
454 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
455 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
456 todo_wine ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
457 todo_wine ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
458 todo_wine ok( is_signaled( event ), "event is not signaled\n" );
459 ok( !apc_count, "apc was called\n" );
460 SleepEx( 1, TRUE ); /* alertable sleep */
461 ok( !apc_count, "apc was called\n" );
463 CloseHandle( handle );
465 CloseHandle( event );
468 static void nt_mailslot_test(void)
471 ACCESS_MASK DesiredAccess;
472 OBJECT_ATTRIBUTES attr;
476 ULONG MaxMessageSize;
477 LARGE_INTEGER TimeOut;
478 IO_STATUS_BLOCK IoStatusBlock;
481 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
482 'R',':','\\','F','R','E','D','\0' };
484 TimeOut.QuadPart = -1;
486 pRtlInitUnicodeString(&str, buffer1);
487 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
488 CreateOptions = MailslotQuota = MaxMessageSize = 0;
489 DesiredAccess = GENERIC_READ;
492 * Check for NULL pointer handling
494 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
495 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
497 ok( rc == STATUS_ACCESS_VIOLATION ||
498 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
499 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
502 * Test to see if the Timeout can be NULL
504 hslot = (HANDLE)0xdeadbeef;
505 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
506 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
508 ok( rc == STATUS_SUCCESS ||
509 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
510 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
511 ok( hslot != 0, "Handle is invalid\n");
513 if ( rc == STATUS_SUCCESS ) rc = pNtClose(hslot);
516 * Test that the length field is checked properly
519 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
520 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
522 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
524 if (rc == STATUS_SUCCESS) pNtClose(hslot);
526 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
527 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
528 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
530 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
532 if (rc == STATUS_SUCCESS) pNtClose(hslot);
535 * Test handling of a NULL unicode string in ObjectName
537 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
538 attr.ObjectName = NULL;
539 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
540 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
542 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
543 rc == STATUS_INVALID_PARAMETER,
544 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
546 if (rc == STATUS_SUCCESS) pNtClose(hslot);
551 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
552 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
553 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
555 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
556 ok( hslot != 0, "Handle is invalid\n");
558 rc = pNtClose(hslot);
559 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
562 static void test_iocp_setcompletion(HANDLE h)
567 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, 3 );
568 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
570 count = get_pending_msgs(h);
571 ok( count == 1, "Unexpected msg count: %ld\n", count );
575 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
576 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
577 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
578 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
581 count = get_pending_msgs(h);
582 ok( !count, "Unexpected msg count: %ld\n", count );
585 static void test_iocp_fileio(HANDLE h)
587 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
589 IO_STATUS_BLOCK iosb;
590 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
591 HANDLE hPipeSrv, hPipeClt;
594 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
595 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
596 if (hPipeSrv != INVALID_HANDLE_VALUE )
598 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
599 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
600 if (hPipeClt != INVALID_HANDLE_VALUE)
602 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
603 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
604 CloseHandle(hPipeClt);
606 CloseHandle( hPipeSrv );
609 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
610 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
611 if (hPipeSrv == INVALID_HANDLE_VALUE )
614 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
615 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
616 if (hPipeClt != INVALID_HANDLE_VALUE)
619 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
623 NTSTATUS res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
624 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
625 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
627 memset( send_buf, 0, TEST_BUF_LEN );
628 memset( recv_buf, 0xde, TEST_BUF_LEN );
629 count = get_pending_msgs(h);
630 ok( !count, "Unexpected msg count: %ld\n", count );
631 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
632 count = get_pending_msgs(h);
633 ok( !count, "Unexpected msg count: %ld\n", count );
634 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
638 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
639 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
640 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
641 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
642 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] );
644 count = get_pending_msgs(h);
645 ok( !count, "Unexpected msg count: %ld\n", count );
647 memset( send_buf, 0, TEST_BUF_LEN );
648 memset( recv_buf, 0xde, TEST_BUF_LEN );
649 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
650 count = get_pending_msgs(h);
651 ok( !count, "Unexpected msg count: %ld\n", count );
652 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
653 count = get_pending_msgs(h);
654 ok( count == 1, "Unexpected msg count: %ld\n", count );
657 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
658 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
659 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
660 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
661 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] );
664 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
665 CloseHandle( hPipeSrv );
666 count = get_pending_msgs(h);
667 ok( count == 1, "Unexpected msg count: %ld\n", count );
670 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
671 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
672 /* wine sends wrong status here */
673 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
674 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
678 CloseHandle( hPipeClt );
681 static void test_iocompletion(void)
683 HANDLE h = INVALID_HANDLE_VALUE;
686 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
688 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
689 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
691 if ( h && h != INVALID_HANDLE_VALUE)
693 test_iocp_setcompletion(h);
701 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
704 skip("not running on NT, skipping test\n");
708 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
709 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
710 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
711 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
712 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
713 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
714 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
715 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
716 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
717 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
718 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
719 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
720 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
721 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");