1 /* Unit test suite for Ntdll NamedPipe API functions
3 * Copyright 2011 Bernhard Loos
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define WIN32_NO_STATUS
30 #include "wine/test.h"
31 #include "wine/winternl.h"
34 #ifndef __WINE_WINTERNL_H
39 } FILE_PIPE_INFORMATION
;
43 ULONG NamedPipeConfiguration
;
44 ULONG MaximumInstances
;
45 ULONG CurrentInstances
;
47 ULONG ReadDataAvailable
;
49 ULONG WriteQuotaAvailable
;
52 } FILE_PIPE_LOCAL_INFORMATION
;
54 #ifndef FILE_SYNCHRONOUS_IO_ALERT
55 #define FILE_SYNCHRONOUS_IO_ALERT 0x10
58 #ifndef FILE_SYNCHRONOUS_IO_NONALERT
59 #define FILE_SYNCHRONOUS_IO_NONALERT 0x20
62 #ifndef FSCTL_PIPE_LISTEN
63 #define FSCTL_PIPE_LISTEN CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
67 static NTSTATUS (WINAPI
*pNtFsControlFile
) (HANDLE handle
, HANDLE event
, PIO_APC_ROUTINE apc
, PVOID apc_context
, PIO_STATUS_BLOCK io
, ULONG code
, PVOID in_buffer
, ULONG in_size
, PVOID out_buffer
, ULONG out_size
);
68 static NTSTATUS (WINAPI
*pNtCreateNamedPipeFile
) (PHANDLE handle
, ULONG access
,
69 POBJECT_ATTRIBUTES attr
, PIO_STATUS_BLOCK iosb
,
70 ULONG sharing
, ULONG dispo
, ULONG options
,
71 ULONG pipe_type
, ULONG read_mode
,
72 ULONG completion_mode
, ULONG max_inst
,
73 ULONG inbound_quota
, ULONG outbound_quota
,
74 PLARGE_INTEGER timeout
);
75 static NTSTATUS (WINAPI
*pNtQueryInformationFile
) (IN HANDLE FileHandle
, OUT PIO_STATUS_BLOCK IoStatusBlock
, OUT PVOID FileInformation
, IN ULONG Length
, IN FILE_INFORMATION_CLASS FileInformationClass
);
76 static NTSTATUS (WINAPI
*pNtSetInformationFile
) (HANDLE handle
, PIO_STATUS_BLOCK io
, PVOID ptr
, ULONG len
, FILE_INFORMATION_CLASS
class);
77 static NTSTATUS (WINAPI
*pNtCancelIoFile
) (HANDLE hFile
, PIO_STATUS_BLOCK io_status
);
78 static void (WINAPI
*pRtlInitUnicodeString
) (PUNICODE_STRING target
, PCWSTR source
);
80 static HANDLE (WINAPI
*pOpenThread
)(DWORD dwDesiredAccess
, BOOL bInheritHandle
, DWORD dwThreadId
);
81 static DWORD (WINAPI
*pQueueUserAPC
)(PAPCFUNC pfnAPC
, HANDLE hThread
, ULONG_PTR dwData
);
84 static BOOL
init_func_ptrs(void)
86 HMODULE module
= GetModuleHandleA("ntdll.dll");
88 #define loadfunc(name) if (!(p##name = (void *)GetProcAddress(module, #name))) { \
89 trace("GetProcAddress(%s) failed\n", #name); \
93 loadfunc(NtFsControlFile
)
94 loadfunc(NtCreateNamedPipeFile
)
95 loadfunc(NtQueryInformationFile
)
96 loadfunc(NtSetInformationFile
)
97 loadfunc(NtCancelIoFile
)
98 loadfunc(RtlInitUnicodeString
)
101 module
= GetModuleHandleA("kernel32.dll");
102 pOpenThread
= (void *)GetProcAddress(module
, "OpenThread");
103 pQueueUserAPC
= (void *)GetProcAddress(module
, "QueueUserAPC");
107 static const WCHAR testpipe
[] = { '\\', '\\', '.', '\\', 'p', 'i', 'p', 'e', '\\',
108 't', 'e', 's', 't', 'p', 'i', 'p', 'e', 0 };
109 static const WCHAR testpipe_nt
[] = { '\\', '?', '?', '\\', 'p', 'i', 'p', 'e', '\\',
110 't', 'e', 's', 't', 'p', 'i', 'p', 'e', 0 };
112 static NTSTATUS
create_pipe(PHANDLE handle
, ULONG sharing
, ULONG options
)
114 IO_STATUS_BLOCK iosb
;
115 OBJECT_ATTRIBUTES attr
;
117 LARGE_INTEGER timeout
;
120 pRtlInitUnicodeString(&name
, testpipe_nt
);
122 attr
.Length
= sizeof(attr
);
123 attr
.RootDirectory
= 0;
124 attr
.ObjectName
= &name
;
125 attr
.Attributes
= 0x40; /*case insensitive */
126 attr
.SecurityDescriptor
= NULL
;
127 attr
.SecurityQualityOfService
= NULL
;
129 timeout
.QuadPart
= -100000000000ll;
131 res
= pNtCreateNamedPipeFile(handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, sharing
, 2 /*FILE_CREATE*/,
132 options
, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
136 static void test_create_invalid(void)
138 IO_STATUS_BLOCK iosb
;
139 OBJECT_ATTRIBUTES attr
;
141 LARGE_INTEGER timeout
;
143 HANDLE handle
, handle2
;
144 FILE_PIPE_LOCAL_INFORMATION info
;
146 pRtlInitUnicodeString(&name
, testpipe_nt
);
148 attr
.Length
= sizeof(attr
);
149 attr
.RootDirectory
= 0;
150 attr
.ObjectName
= &name
;
151 attr
.Attributes
= 0x40; /*case insensitive */
152 attr
.SecurityDescriptor
= NULL
;
153 attr
.SecurityQualityOfService
= NULL
;
155 timeout
.QuadPart
= -100000000000ll;
157 /* create a pipe with FILE_OVERWRITE */
158 res
= pNtCreateNamedPipeFile(&handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
, 4 /*FILE_OVERWRITE*/,
159 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
160 todo_wine
ok(res
== STATUS_INVALID_PARAMETER
, "NtCreateNamedPipeFile returned %x\n", res
);
164 /* create a pipe with FILE_OVERWRITE_IF */
165 res
= pNtCreateNamedPipeFile(&handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
, 5 /*FILE_OVERWRITE_IF*/,
166 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
167 todo_wine
ok(res
== STATUS_INVALID_PARAMETER
, "NtCreateNamedPipeFile returned %x\n", res
);
171 /* create a pipe with sharing = 0 */
172 res
= pNtCreateNamedPipeFile(&handle
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
, 0, 2 /*FILE_CREATE*/,
173 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
174 ok(res
== STATUS_INVALID_PARAMETER
, "NtCreateNamedPipeFile returned %x\n", res
);
178 /* create a pipe without r/w access */
179 res
= pNtCreateNamedPipeFile(&handle
, SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /*FILE_CREATE*/,
180 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
181 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
183 res
= pNtQueryInformationFile(handle
, &iosb
, &info
, sizeof(info
), (FILE_INFORMATION_CLASS
)24);
184 ok(res
== STATUS_ACCESS_DENIED
, "NtQueryInformationFile returned %x\n", res
);
186 /* test FILE_CREATE creation disposition */
187 res
= pNtCreateNamedPipeFile(&handle2
, SYNCHRONIZE
, &attr
, &iosb
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /*FILE_CREATE*/,
188 0, 1, 0, 0, 0xFFFFFFFF, 500, 500, &timeout
);
189 todo_wine
ok(res
== STATUS_ACCESS_DENIED
, "NtCreateNamedPipeFile returned %x\n", res
);
191 CloseHandle(handle2
);
196 static void test_create(void)
201 FILE_PIPE_LOCAL_INFORMATION info
;
202 IO_STATUS_BLOCK iosb
;
204 static const DWORD access
[] = { 0, GENERIC_READ
, GENERIC_WRITE
, GENERIC_READ
| GENERIC_WRITE
};
205 static const DWORD sharing
[] = { FILE_SHARE_READ
, FILE_SHARE_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
};
206 static const DWORD pipe_config
[]= { 1, 0, 2 };
208 for (j
= 0; j
< sizeof(sharing
) / sizeof(DWORD
); j
++) {
209 for (k
= 0; k
< sizeof(access
) / sizeof(DWORD
); k
++) {
211 BOOL should_succeed
= TRUE
;
213 res
= create_pipe(&hserver
, sharing
[j
], FILE_SYNCHRONOUS_IO_NONALERT
);
215 ok(0, "NtCreateNamedPipeFile returned %x, sharing: %x\n", res
, sharing
[j
]);
219 res
= pNtQueryInformationFile(hserver
, &iosb
, &info
, sizeof(info
), (FILE_INFORMATION_CLASS
)24);
220 ok(!res
, "NtQueryInformationFile for server returned %x, sharing: %x\n", res
, sharing
[j
]);
221 ok(info
.NamedPipeConfiguration
== pipe_config
[j
], "wrong duplex status for pipe: %d, expected %d\n",
222 info
.NamedPipeConfiguration
, pipe_config
[j
]);
224 hclient
= CreateFileW(testpipe
, access
[k
], 0, 0, OPEN_EXISTING
, 0, 0);
225 if (hclient
!= INVALID_HANDLE_VALUE
) {
226 res
= pNtQueryInformationFile(hclient
, &iosb
, &info
, sizeof(info
), (FILE_INFORMATION_CLASS
)24);
227 ok(!res
, "NtQueryInformationFile for client returned %x, access: %x, sharing: %x\n",
228 res
, access
[k
], sharing
[j
]);
229 ok(info
.NamedPipeConfiguration
== pipe_config
[j
], "wrong duplex status for pipe: %d, expected %d\n",
230 info
.NamedPipeConfiguration
, pipe_config
[j
]);
231 CloseHandle(hclient
);
234 if (access
[k
] & GENERIC_WRITE
)
235 should_succeed
&= !!(sharing
[j
] & FILE_SHARE_WRITE
);
236 if (access
[k
] & GENERIC_READ
)
237 should_succeed
&= !!(sharing
[j
] & FILE_SHARE_READ
);
240 ok(hclient
!= INVALID_HANDLE_VALUE
, "CreateFile failed for sharing %x, access: %x, GetLastError: %d\n",
241 sharing
[j
], access
[k
], GetLastError());
243 ok(hclient
== INVALID_HANDLE_VALUE
, "CreateFile succeeded for sharing %x, access: %x\n", sharing
[j
], access
[k
]);
245 CloseHandle(hserver
);
250 static BOOL ioapc_called
;
251 static void CALLBACK
ioapc(void *arg
, PIO_STATUS_BLOCK io
, ULONG reserved
)
256 static NTSTATUS
listen_pipe(HANDLE hPipe
, HANDLE hEvent
, PIO_STATUS_BLOCK iosb
, BOOL use_apc
)
260 ioapc_called
= FALSE
;
262 return pNtFsControlFile(hPipe
, hEvent
, use_apc
? &ioapc
: NULL
, use_apc
? &dummy
: NULL
, iosb
, FSCTL_PIPE_LISTEN
, 0, 0, 0, 0);
265 static void test_overlapped(void)
267 IO_STATUS_BLOCK iosb
;
273 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
274 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
276 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0 /* OVERLAPPED */);
277 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
279 memset(&iosb
, 0x55, sizeof(iosb
));
281 /* try with event and apc */
282 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
283 ok(res
== STATUS_PENDING
, "NtFsControlFile returned %x\n", res
);
285 hClient
= CreateFileW(testpipe
, GENERIC_READ
| GENERIC_WRITE
, 0, 0, OPEN_EXISTING
, 0, 0);
286 ok(hClient
!= INVALID_HANDLE_VALUE
, "can't open pipe, GetLastError: %x\n", GetLastError());
288 ok(U(iosb
).Status
== 0, "Wrong iostatus %x\n", U(iosb
).Status
);
289 ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
291 ok(!ioapc_called
, "IOAPC ran too early\n");
293 SleepEx(0, TRUE
); /* alertable wait state */
295 ok(ioapc_called
, "IOAPC didn't run\n");
299 CloseHandle(hClient
);
302 static BOOL userapc_called
;
303 static void CALLBACK
userapc(ULONG_PTR dwParam
)
305 userapc_called
= TRUE
;
308 static BOOL open_succeeded
;
309 static DWORD WINAPI
thread(PVOID main_thread
)
317 userapc_called
= FALSE
;
318 ret
= pQueueUserAPC(&userapc
, main_thread
, 0);
319 ok(ret
, "can't queue user apc, GetLastError: %x\n", GetLastError());
320 CloseHandle(main_thread
);
325 h
= CreateFileW(testpipe
, GENERIC_WRITE
| GENERIC_READ
, 0, 0, OPEN_EXISTING
, 0, 0);
327 if (h
!= INVALID_HANDLE_VALUE
) {
328 open_succeeded
= TRUE
;
332 open_succeeded
= FALSE
;
337 static void test_alertable(void)
339 IO_STATUS_BLOCK iosb
;
346 memset(&iosb
, 0x55, sizeof(iosb
));
348 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
349 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
351 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_SYNCHRONOUS_IO_ALERT
);
352 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
354 /* queue an user apc before calling listen */
355 userapc_called
= FALSE
;
356 ret
= pQueueUserAPC(&userapc
, GetCurrentThread(), 0);
357 ok(ret
, "can't queue user apc, GetLastError: %x\n", GetLastError());
359 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
360 todo_wine
ok(res
== STATUS_CANCELLED
, "NtFsControlFile returned %x\n", res
);
362 todo_wine
ok(userapc_called
, "user apc didn't run\n");
363 ok(U(iosb
).Status
== 0x55555555, "iosb.Status got changed to %x\n", U(iosb
).Status
);
364 todo_wine
ok(WaitForSingleObjectEx(hEvent
, 0, TRUE
) == WAIT_TIMEOUT
, "hEvent signaled\n");
365 ok(!ioapc_called
, "IOAPC ran\n");
367 /* queue an user apc from a different thread */
368 hThread
= CreateThread(NULL
, 0, &thread
, pOpenThread(MAXIMUM_ALLOWED
, FALSE
, GetCurrentThreadId()), 0, 0);
369 ok(hThread
!= INVALID_HANDLE_VALUE
, "can't create thread, GetLastError: %x\n", GetLastError());
371 /* wine_todo: the earlier NtFsControlFile call gets cancelled after the pipe gets set into listen state
372 instead of before, so this NtFsControlFile will fail STATUS_INVALID_HANDLE */
373 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
374 todo_wine
ok(res
== STATUS_CANCELLED
, "NtFsControlFile returned %x\n", res
);
376 ok(userapc_called
, "user apc didn't run\n");
377 todo_wine
ok(U(iosb
).Status
== 0x55555555, "iosb.Status got changed to %x\n", U(iosb
).Status
);
378 ok(WaitForSingleObjectEx(hEvent
, 0, TRUE
) == WAIT_TIMEOUT
, "hEvent signaled\n");
379 ok(!ioapc_called
, "IOAPC ran\n");
381 WaitForSingleObject(hThread
, INFINITE
);
383 SleepEx(0, TRUE
); /* get rid of the userapc, if NtFsControlFile failed */
385 ok(open_succeeded
, "couldn't open client side pipe\n");
387 CloseHandle(hThread
);
388 DisconnectNamedPipe(hPipe
);
390 /* finally try without an apc */
391 hThread
= CreateThread(NULL
, 0, &thread
, 0, 0, 0);
392 ok(hThread
!= INVALID_HANDLE_VALUE
, "can't create thread, GetLastError: %x\n", GetLastError());
394 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
395 todo_wine
ok(!res
, "NtFsControlFile returned %x\n", res
);
397 ok(open_succeeded
, "couldn't open client side pipe\n");
398 ok(!U(iosb
).Status
, "Wrong iostatus %x\n", U(iosb
).Status
);
399 todo_wine
ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
401 WaitForSingleObject(hThread
, INFINITE
);
402 CloseHandle(hThread
);
407 static void test_nonalertable(void)
409 IO_STATUS_BLOCK iosb
;
416 memset(&iosb
, 0x55, sizeof(iosb
));
418 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
419 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
421 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, FILE_SYNCHRONOUS_IO_NONALERT
);
422 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
424 hThread
= CreateThread(NULL
, 0, &thread
, 0, 0, 0);
425 ok(hThread
!= INVALID_HANDLE_VALUE
, "can't create thread, GetLastError: %x\n", GetLastError());
427 userapc_called
= FALSE
;
428 ret
= pQueueUserAPC(&userapc
, GetCurrentThread(), 0);
429 ok(ret
, "can't queue user apc, GetLastError: %x\n", GetLastError());
431 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
432 todo_wine
ok(!res
, "NtFsControlFile returned %x\n", res
);
434 ok(open_succeeded
, "couldn't open client side pipe\n");
435 todo_wine
ok(!U(iosb
).Status
, "Wrong iostatus %x\n", U(iosb
).Status
);
436 todo_wine
ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
438 ok(!ioapc_called
, "IOAPC ran too early\n");
439 ok(!userapc_called
, "user apc ran too early\n");
441 SleepEx(0, TRUE
); /* alertable wait state */
443 ok(ioapc_called
, "IOAPC didn't run\n");
444 ok(userapc_called
, "user apc didn't run\n");
446 WaitForSingleObject(hThread
, INFINITE
);
447 CloseHandle(hThread
);
452 static void test_cancelio(void)
454 IO_STATUS_BLOCK iosb
;
455 IO_STATUS_BLOCK cancel_sb
;
460 hEvent
= CreateEventW(NULL
, TRUE
, FALSE
, NULL
);
461 ok(hEvent
!= INVALID_HANDLE_VALUE
, "can't create event, GetLastError: %x\n", GetLastError());
463 res
= create_pipe(&hPipe
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, 0 /* OVERLAPPED */);
464 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
466 memset(&iosb
, 0x55, sizeof(iosb
));
468 res
= listen_pipe(hPipe
, hEvent
, &iosb
, TRUE
);
469 ok(res
== STATUS_PENDING
, "NtFsControlFile returned %x\n", res
);
471 res
= pNtCancelIoFile(hPipe
, &cancel_sb
);
472 ok(!res
, "NtCancelIoFile returned %x\n", res
);
474 ok(U(iosb
).Status
== STATUS_CANCELLED
, "Wrong iostatus %x\n", U(iosb
).Status
);
475 ok(WaitForSingleObject(hEvent
, 0) == 0, "hEvent not signaled\n");
477 ok(!ioapc_called
, "IOAPC ran too early\n");
479 SleepEx(0, TRUE
); /* alertable wait state */
481 ok(ioapc_called
, "IOAPC didn't run\n");
487 static void _check_pipe_handle_state(int line
, HANDLE handle
, ULONG read
, ULONG completion
)
489 IO_STATUS_BLOCK iosb
;
490 FILE_PIPE_INFORMATION fpi
;
492 if (handle
!= INVALID_HANDLE_VALUE
)
494 memset(&fpi
, 0x55, sizeof(fpi
));
495 res
= pNtQueryInformationFile(handle
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
496 ok_(__FILE__
, line
)(!res
, "NtQueryInformationFile returned %x\n", res
);
497 ok_(__FILE__
, line
)(fpi
.ReadMode
== read
, "Unexpected ReadMode, expected %x, got %x\n",
499 ok_(__FILE__
, line
)(fpi
.CompletionMode
== completion
, "Unexpected CompletionMode, expected %x, got %x\n",
500 completion
, fpi
.CompletionMode
);
503 #define check_pipe_handle_state(handle, r, c) _check_pipe_handle_state(__LINE__, handle, r, c)
505 static void test_filepipeinfo(void)
507 IO_STATUS_BLOCK iosb
;
508 OBJECT_ATTRIBUTES attr
;
510 LARGE_INTEGER timeout
;
511 HANDLE hServer
, hClient
;
512 FILE_PIPE_INFORMATION fpi
;
515 pRtlInitUnicodeString(&name
, testpipe_nt
);
517 attr
.Length
= sizeof(attr
);
518 attr
.RootDirectory
= 0;
519 attr
.ObjectName
= &name
;
520 attr
.Attributes
= 0x40; /* case insensitive */
521 attr
.SecurityDescriptor
= NULL
;
522 attr
.SecurityQualityOfService
= NULL
;
524 timeout
.QuadPart
= -100000000000ll;
526 /* test with INVALID_HANDLE_VALUE */
527 res
= pNtQueryInformationFile(INVALID_HANDLE_VALUE
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
528 ok(res
== STATUS_OBJECT_TYPE_MISMATCH
, "NtQueryInformationFile returned %x\n", res
);
531 fpi
.CompletionMode
= 0;
532 res
= pNtSetInformationFile(INVALID_HANDLE_VALUE
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
533 ok(res
== STATUS_OBJECT_TYPE_MISMATCH
, "NtSetInformationFile returned %x\n", res
);
535 /* server end with read-only attributes */
536 res
= pNtCreateNamedPipeFile(&hServer
, FILE_READ_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
,
537 FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /* FILE_CREATE */,
538 0, 0, 0, 1, 0xFFFFFFFF, 500, 500, &timeout
);
539 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
541 check_pipe_handle_state(hServer
, 0, 1);
543 hClient
= CreateFileW(testpipe
, GENERIC_READ
| GENERIC_WRITE
, 0, 0, OPEN_EXISTING
, 0, 0);
544 ok(hClient
!= INVALID_HANDLE_VALUE
, "can't open pipe, GetLastError: %x\n", GetLastError());
546 check_pipe_handle_state(hServer
, 0, 1);
547 check_pipe_handle_state(hClient
, 0, 0);
550 fpi
.CompletionMode
= 0;
551 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
552 ok(res
== STATUS_ACCESS_DENIED
, "NtSetInformationFile returned %x\n", res
);
554 check_pipe_handle_state(hServer
, 0, 1);
555 check_pipe_handle_state(hClient
, 0, 0);
557 fpi
.ReadMode
= 1; /* invalid on a byte stream pipe */
558 fpi
.CompletionMode
= 1;
559 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
560 ok(res
== STATUS_ACCESS_DENIED
, "NtSetInformationFile returned %x\n", res
);
562 check_pipe_handle_state(hServer
, 0, 1);
563 check_pipe_handle_state(hClient
, 0, 0);
565 if (hClient
!= INVALID_HANDLE_VALUE
)
567 fpi
.ReadMode
= 1; /* invalid on a byte stream pipe */
568 fpi
.CompletionMode
= 1;
569 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
570 ok(res
== STATUS_INVALID_PARAMETER
, "NtSetInformationFile returned %x\n", res
);
573 check_pipe_handle_state(hServer
, 0, 1);
574 check_pipe_handle_state(hClient
, 0, 0);
576 if (hClient
!= INVALID_HANDLE_VALUE
)
579 fpi
.CompletionMode
= 1;
580 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
581 ok(!res
, "NtSetInformationFile returned %x\n", res
);
584 check_pipe_handle_state(hServer
, 0, 1);
585 check_pipe_handle_state(hClient
, 0, 1);
587 if (hClient
!= INVALID_HANDLE_VALUE
)
590 fpi
.CompletionMode
= 2; /* not in range 0-1 */
591 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
592 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
594 fpi
.ReadMode
= 2; /* not in range 0-1 */
595 fpi
.CompletionMode
= 0;
596 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
597 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
600 CloseHandle(hClient
);
602 check_pipe_handle_state(hServer
, 0, 1);
605 fpi
.CompletionMode
= 0;
606 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
607 ok(res
== STATUS_ACCESS_DENIED
, "NtSetInformationFile returned %x\n", res
);
609 CloseHandle(hServer
);
611 /* message mode server with read/write attributes */
612 res
= pNtCreateNamedPipeFile(&hServer
, FILE_READ_ATTRIBUTES
| FILE_WRITE_ATTRIBUTES
| SYNCHRONIZE
, &attr
, &iosb
,
613 FILE_SHARE_READ
| FILE_SHARE_WRITE
, 2 /* FILE_CREATE */,
614 0, 1, 1, 0, 0xFFFFFFFF, 500, 500, &timeout
);
615 ok(!res
, "NtCreateNamedPipeFile returned %x\n", res
);
617 check_pipe_handle_state(hServer
, 1, 0);
619 hClient
= CreateFileW(testpipe
, GENERIC_READ
| GENERIC_WRITE
, 0, 0, OPEN_EXISTING
, 0, 0);
620 ok(hClient
!= INVALID_HANDLE_VALUE
, "can't open pipe, GetLastError: %x\n", GetLastError());
622 check_pipe_handle_state(hServer
, 1, 0);
623 check_pipe_handle_state(hClient
, 0, 0);
625 if (hClient
!= INVALID_HANDLE_VALUE
)
628 fpi
.CompletionMode
= 1;
629 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
630 ok(!res
, "NtSetInformationFile returned %x\n", res
);
633 check_pipe_handle_state(hServer
, 1, 0);
634 check_pipe_handle_state(hClient
, 1, 1);
637 fpi
.CompletionMode
= 1;
638 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
639 ok(!res
, "NtSetInformationFile returned %x\n", res
);
641 check_pipe_handle_state(hServer
, 0, 1);
642 check_pipe_handle_state(hClient
, 1, 1);
644 if (hClient
!= INVALID_HANDLE_VALUE
)
647 fpi
.CompletionMode
= 2; /* not in range 0-1 */
648 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
649 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
651 fpi
.ReadMode
= 2; /* not in range 0-1 */
652 fpi
.CompletionMode
= 0;
653 res
= pNtSetInformationFile(hClient
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
654 ok(res
== STATUS_INVALID_PARAMETER
|| broken(!res
) /* < Vista */, "NtSetInformationFile returned %x\n", res
);
657 CloseHandle(hClient
);
659 check_pipe_handle_state(hServer
, 0, 1);
662 fpi
.CompletionMode
= 0;
663 res
= pNtSetInformationFile(hServer
, &iosb
, &fpi
, sizeof(fpi
), (FILE_INFORMATION_CLASS
)23);
664 ok(!res
, "NtSetInformationFile returned %x\n", res
);
666 check_pipe_handle_state(hServer
, 1, 0);
668 CloseHandle(hServer
);
673 if (!init_func_ptrs())
676 trace("starting invalid create tests\n");
677 test_create_invalid();
679 trace("starting create tests\n");
682 trace("starting overlapped tests\n");
685 trace("starting FILE_PIPE_INFORMATION tests\n");
688 if (!pOpenThread
|| !pQueueUserAPC
)
691 trace("starting alertable tests\n");
694 trace("starting nonalertable tests\n");
697 trace("starting cancelio tests\n");