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, (PVOID)&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, "wrong status %x\n", status );
381 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
382 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
383 ok( is_signaled( event ), "event is signaled\n" );
384 ok( !apc_count, "apc was called\n" );
385 SleepEx( 1, TRUE ); /* alertable sleep */
386 ok( apc_count == 1, "apc was not called\n" );
388 /* read beyond eof */
390 U(iosb).Status = 0xdeadbabe;
391 iosb.Information = 0xdeadbeef;
392 offset.QuadPart = strlen(text) + 2;
393 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
394 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
395 ok( U(iosb).Status == 0xdeadbabe, "wrong status %x\n", U(iosb).Status );
396 ok( iosb.Information == 0xdeadbeef, "wrong info %lu\n", iosb.Information );
397 ok( !is_signaled( event ), "event is signaled\n" );
398 ok( !apc_count, "apc was called\n" );
399 SleepEx( 1, TRUE ); /* alertable sleep */
400 ok( !apc_count, "apc was called\n" );
401 CloseHandle( handle );
403 /* now a non-overlapped file */
404 if (!(handle = create_temp_file(0))) return;
406 U(iosb).Status = 0xdeadbabe;
407 iosb.Information = 0xdeadbeef;
409 pNtWriteFile( handle, event, apc, &apc_count, &iosb, text, strlen(text), &offset, NULL );
410 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
411 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
412 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
413 ok( is_signaled( event ), "event is signaled\n" );
414 ok( !apc_count, "apc was called\n" );
415 SleepEx( 1, TRUE ); /* alertable sleep */
416 ok( apc_count == 1, "apc was not called\n" );
419 U(iosb).Status = 0xdeadbabe;
420 iosb.Information = 0xdeadbeef;
423 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, strlen(text) + 10, &offset, NULL );
424 ok( status == STATUS_SUCCESS, "wrong status %x\n", status );
425 ok( U(iosb).Status == STATUS_SUCCESS, "wrong status %x\n", U(iosb).Status );
426 ok( iosb.Information == strlen(text), "wrong info %lu\n", iosb.Information );
427 ok( is_signaled( event ), "event is signaled\n" );
428 ok( !apc_count, "apc was called\n" );
429 SleepEx( 1, TRUE ); /* alertable sleep */
430 todo_wine ok( !apc_count, "apc was called\n" );
432 /* read beyond eof */
434 U(iosb).Status = 0xdeadbabe;
435 iosb.Information = 0xdeadbeef;
436 offset.QuadPart = strlen(text) + 2;
438 status = pNtReadFile( handle, event, apc, &apc_count, &iosb, buffer, 2, &offset, NULL );
439 ok( status == STATUS_END_OF_FILE, "wrong status %x\n", status );
440 todo_wine ok( U(iosb).Status == STATUS_END_OF_FILE, "wrong status %x\n", U(iosb).Status );
441 todo_wine ok( iosb.Information == 0, "wrong info %lu\n", iosb.Information );
442 todo_wine ok( is_signaled( event ), "event is not signaled\n" );
443 ok( !apc_count, "apc was called\n" );
444 SleepEx( 1, TRUE ); /* alertable sleep */
445 ok( !apc_count, "apc was called\n" );
447 CloseHandle( handle );
449 CloseHandle( event );
452 static void nt_mailslot_test(void)
455 ACCESS_MASK DesiredAccess;
456 OBJECT_ATTRIBUTES attr;
460 ULONG MaxMessageSize;
461 LARGE_INTEGER TimeOut;
462 IO_STATUS_BLOCK IoStatusBlock;
465 WCHAR buffer1[] = { '\\','?','?','\\','M','A','I','L','S','L','O','T','\\',
466 'R',':','\\','F','R','E','D','\0' };
468 TimeOut.QuadPart = -1;
470 pRtlInitUnicodeString(&str, buffer1);
471 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
472 CreateOptions = MailslotQuota = MaxMessageSize = 0;
473 DesiredAccess = GENERIC_READ;
476 * Check for NULL pointer handling
478 rc = pNtCreateMailslotFile(NULL, DesiredAccess,
479 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
481 ok( rc == STATUS_ACCESS_VIOLATION ||
482 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
483 "rc = %x not STATUS_ACCESS_VIOLATION or STATUS_INVALID_PARAMETER\n", rc);
486 * Test to see if the Timeout can be NULL
488 hslot = (HANDLE)0xdeadbeef;
489 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
490 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
492 ok( rc == STATUS_SUCCESS ||
493 rc == STATUS_INVALID_PARAMETER, /* win2k3 */
494 "rc = %x not STATUS_SUCCESS or STATUS_INVALID_PARAMETER\n", rc);
495 ok( hslot != 0, "Handle is invalid\n");
497 if ( rc == STATUS_SUCCESS ) rc = pNtClose(hslot);
500 * Test that the length field is checked properly
503 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
504 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
506 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
508 if (rc == STATUS_SUCCESS) pNtClose(hslot);
510 attr.Length = sizeof(OBJECT_ATTRIBUTES)+1;
511 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
512 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
514 todo_wine ok( rc == STATUS_INVALID_PARAMETER, "rc = %x not c000000d STATUS_INVALID_PARAMETER\n", rc);
516 if (rc == STATUS_SUCCESS) pNtClose(hslot);
519 * Test handling of a NULL unicode string in ObjectName
521 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
522 attr.ObjectName = NULL;
523 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
524 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
526 ok( rc == STATUS_OBJECT_PATH_SYNTAX_BAD ||
527 rc == STATUS_INVALID_PARAMETER,
528 "rc = %x not STATUS_OBJECT_PATH_SYNTAX_BAD or STATUS_INVALID_PARAMETER\n", rc);
530 if (rc == STATUS_SUCCESS) pNtClose(hslot);
535 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, 0, NULL);
536 rc = pNtCreateMailslotFile(&hslot, DesiredAccess,
537 &attr, &IoStatusBlock, CreateOptions, MailslotQuota, MaxMessageSize,
539 ok( rc == STATUS_SUCCESS, "Create MailslotFile failed rc = %x\n", rc);
540 ok( hslot != 0, "Handle is invalid\n");
542 rc = pNtClose(hslot);
543 ok( rc == STATUS_SUCCESS, "NtClose failed\n");
546 static void test_iocp_setcompletion(HANDLE h)
551 res = pNtSetIoCompletion( h, CKEY_FIRST, CVALUE_FIRST, STATUS_INVALID_DEVICE_REQUEST, 3 );
552 ok( res == STATUS_SUCCESS, "NtSetIoCompletion failed: %x\n", res );
554 count = get_pending_msgs(h);
555 ok( count == 1, "Unexpected msg count: %ld\n", count );
559 ok( completionKey == CKEY_FIRST, "Invalid completion key: %lx\n", completionKey );
560 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
561 ok( U(ioSb).Status == STATUS_INVALID_DEVICE_REQUEST, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
562 ok( completionValue == CVALUE_FIRST, "Invalid completion value: %lx\n", completionValue );
565 count = get_pending_msgs(h);
566 ok( !count, "Unexpected msg count: %ld\n", count );
569 static void test_iocp_fileio(HANDLE h)
571 static const char pipe_name[] = "\\\\.\\pipe\\iocompletiontestnamedpipe";
573 IO_STATUS_BLOCK iosb;
574 FILE_COMPLETION_INFORMATION fci = {h, CKEY_SECOND};
575 HANDLE hPipeSrv, hPipeClt;
578 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
579 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
580 if (hPipeSrv != INVALID_HANDLE_VALUE )
582 hPipeClt = CreateFileA( pipe_name, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_NO_BUFFERING | FILE_FLAG_OVERLAPPED, NULL );
583 ok( hPipeClt != INVALID_HANDLE_VALUE, "Cannot connect to pipe\n" );
584 if (hPipeClt != INVALID_HANDLE_VALUE)
586 res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
587 ok( res == STATUS_INVALID_PARAMETER, "Unexpected NtSetInformationFile on non-overlapped handle: %x\n", res );
588 CloseHandle(hPipeClt);
590 CloseHandle( hPipeSrv );
593 hPipeSrv = CreateNamedPipeA( pipe_name, PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 4, 1024, 1024, 1000, NULL );
594 ok( hPipeSrv != INVALID_HANDLE_VALUE, "Cannot create named pipe\n" );
595 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)
603 BYTE send_buf[TEST_BUF_LEN], recv_buf[TEST_BUF_LEN];
607 NTSTATUS res = pNtSetInformationFile( hPipeSrv, &iosb, &fci, sizeof(fci), FileCompletionInformation );
608 ok( res == STATUS_SUCCESS, "NtSetInformationFile failed: %x\n", res );
609 ok( U(iosb).Status == STATUS_SUCCESS, "iosb.Status invalid: %x\n", U(iosb).Status );
611 memset( send_buf, 0, TEST_BUF_LEN );
612 memset( recv_buf, 0xde, TEST_BUF_LEN );
613 count = get_pending_msgs(h);
614 ok( !count, "Unexpected msg count: %ld\n", count );
615 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
616 count = get_pending_msgs(h);
617 ok( !count, "Unexpected msg count: %ld\n", count );
618 WriteFile( hPipeClt, send_buf, TEST_BUF_LEN, &read, NULL );
622 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
623 ok( ioSb.Information == 3, "Invalid ioSb.Information: %ld\n", ioSb.Information );
624 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
625 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
626 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] );
628 count = get_pending_msgs(h);
629 ok( !count, "Unexpected msg count: %ld\n", count );
631 memset( send_buf, 0, TEST_BUF_LEN );
632 memset( recv_buf, 0xde, TEST_BUF_LEN );
633 WriteFile( hPipeClt, send_buf, 2, &read, NULL );
634 count = get_pending_msgs(h);
635 ok( !count, "Unexpected msg count: %ld\n", count );
636 ReadFile( hPipeSrv, recv_buf, 2, &read, &o);
637 count = get_pending_msgs(h);
638 ok( count == 1, "Unexpected msg count: %ld\n", count );
641 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
642 ok( ioSb.Information == 2, "Invalid ioSb.Information: %ld\n", ioSb.Information );
643 ok( U(ioSb).Status == STATUS_SUCCESS, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
644 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
645 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] );
648 ReadFile( hPipeSrv, recv_buf, TEST_BUF_LEN, &read, &o);
649 CloseHandle( hPipeSrv );
650 count = get_pending_msgs(h);
651 ok( count == 1, "Unexpected msg count: %ld\n", count );
654 ok( completionKey == CKEY_SECOND, "Invalid completion key: %lx\n", completionKey );
655 ok( ioSb.Information == 0, "Invalid ioSb.Information: %ld\n", ioSb.Information );
656 /* wine sends wrong status here */
657 todo_wine ok( U(ioSb).Status == STATUS_PIPE_BROKEN, "Invalid ioSb.Status: %x\n", U(ioSb).Status);
658 ok( completionValue == (ULONG_PTR)&o, "Invalid completion value: %lx\n", completionValue );
662 CloseHandle( hPipeClt );
665 static void test_iocompletion(void)
667 HANDLE h = INVALID_HANDLE_VALUE;
670 res = pNtCreateIoCompletion( &h, IO_COMPLETION_ALL_ACCESS, NULL, 0);
672 ok( res == 0, "NtCreateIoCompletion anonymous failed: %x\n", res );
673 ok( h && h != INVALID_HANDLE_VALUE, "Invalid handle returned\n" );
675 if ( h && h != INVALID_HANDLE_VALUE)
677 test_iocp_setcompletion(h);
685 HMODULE hntdll = GetModuleHandleA("ntdll.dll");
688 skip("not running on NT, skipping test\n");
692 pRtlFreeUnicodeString = (void *)GetProcAddress(hntdll, "RtlFreeUnicodeString");
693 pRtlInitUnicodeString = (void *)GetProcAddress(hntdll, "RtlInitUnicodeString");
694 pRtlDosPathNameToNtPathName_U = (void *)GetProcAddress(hntdll, "RtlDosPathNameToNtPathName_U");
695 pNtCreateMailslotFile = (void *)GetProcAddress(hntdll, "NtCreateMailslotFile");
696 pNtDeleteFile = (void *)GetProcAddress(hntdll, "NtDeleteFile");
697 pNtReadFile = (void *)GetProcAddress(hntdll, "NtReadFile");
698 pNtWriteFile = (void *)GetProcAddress(hntdll, "NtWriteFile");
699 pNtClose = (void *)GetProcAddress(hntdll, "NtClose");
700 pNtCreateIoCompletion = (void *)GetProcAddress(hntdll, "NtCreateIoCompletion");
701 pNtOpenIoCompletion = (void *)GetProcAddress(hntdll, "NtOpenIoCompletion");
702 pNtQueryIoCompletion = (void *)GetProcAddress(hntdll, "NtQueryIoCompletion");
703 pNtRemoveIoCompletion = (void *)GetProcAddress(hntdll, "NtRemoveIoCompletion");
704 pNtSetIoCompletion = (void *)GetProcAddress(hntdll, "NtSetIoCompletion");
705 pNtSetInformationFile = (void *)GetProcAddress(hntdll, "NtSetInformationFile");