ntdll: Add stub for RtlSetHeapInformation.
[wine.git] / dlls / ntdll / tests / pipe.c
blob4bf2ad23f783c8befedaea193f2eb5417e6d1f73
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
20 #include <stdio.h>
21 #include <stdarg.h>
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "winnls.h"
30 #include "wine/test.h"
31 #include "winternl.h"
32 #include "winioctl.h"
34 #ifndef __WINE_WINTERNL_H
36 typedef struct {
37 ULONG ReadMode;
38 ULONG CompletionMode;
39 } FILE_PIPE_INFORMATION;
41 typedef struct {
42 ULONG NamedPipeType;
43 ULONG NamedPipeConfiguration;
44 ULONG MaximumInstances;
45 ULONG CurrentInstances;
46 ULONG InboundQuota;
47 ULONG ReadDataAvailable;
48 ULONG OutboundQuota;
49 ULONG WriteQuotaAvailable;
50 ULONG NamedPipeState;
51 ULONG NamedPipeEnd;
52 } FILE_PIPE_LOCAL_INFORMATION;
54 #ifndef FILE_SYNCHRONOUS_IO_ALERT
55 #define FILE_SYNCHRONOUS_IO_ALERT 0x10
56 #endif
58 #ifndef FILE_SYNCHRONOUS_IO_NONALERT
59 #define FILE_SYNCHRONOUS_IO_NONALERT 0x20
60 #endif
62 #ifndef FSCTL_PIPE_LISTEN
63 #define FSCTL_PIPE_LISTEN CTL_CODE(FILE_DEVICE_NAMED_PIPE, 2, METHOD_BUFFERED, FILE_ANY_ACCESS)
64 #endif
65 #endif
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); \
90 return FALSE; \
93 loadfunc(NtFsControlFile)
94 loadfunc(NtCreateNamedPipeFile)
95 loadfunc(NtQueryInformationFile)
96 loadfunc(NtSetInformationFile)
97 loadfunc(NtCancelIoFile)
98 loadfunc(RtlInitUnicodeString)
100 /* not fatal */
101 module = GetModuleHandleA("kernel32.dll");
102 pOpenThread = (void *)GetProcAddress(module, "OpenThread");
103 pQueueUserAPC = (void *)GetProcAddress(module, "QueueUserAPC");
104 return TRUE;
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;
116 UNICODE_STRING name;
117 LARGE_INTEGER timeout;
118 NTSTATUS res;
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);
133 return res;
136 static void test_create_invalid(void)
138 IO_STATUS_BLOCK iosb;
139 OBJECT_ATTRIBUTES attr;
140 UNICODE_STRING name;
141 LARGE_INTEGER timeout;
142 NTSTATUS res;
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);
161 if (!res)
162 CloseHandle(handle);
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);
168 if (!res)
169 CloseHandle(handle);
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);
175 if (!res)
176 CloseHandle(handle);
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);
190 if (!res)
191 CloseHandle(handle2);
193 CloseHandle(handle);
196 static void test_create(void)
198 HANDLE hserver;
199 NTSTATUS res;
200 int j, k;
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++) {
210 HANDLE hclient;
211 BOOL should_succeed = TRUE;
213 res = create_pipe(&hserver, sharing[j], FILE_SYNCHRONOUS_IO_NONALERT);
214 if (res) {
215 ok(0, "NtCreateNamedPipeFile returned %x, sharing: %x\n", res, sharing[j]);
216 continue;
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);
239 if (should_succeed)
240 ok(hclient != INVALID_HANDLE_VALUE, "CreateFile failed for sharing %x, access: %x, GetLastError: %d\n",
241 sharing[j], access[k], GetLastError());
242 else
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)
253 ioapc_called = TRUE;
256 static NTSTATUS listen_pipe(HANDLE hPipe, HANDLE hEvent, PIO_STATUS_BLOCK iosb, BOOL use_apc)
258 int dummy;
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;
268 HANDLE hEvent;
269 HANDLE hPipe;
270 HANDLE hClient;
271 NTSTATUS res;
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");
297 CloseHandle(hEvent);
298 CloseHandle(hPipe);
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)
311 HANDLE h;
313 Sleep(400);
315 if (main_thread) {
316 DWORD ret;
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);
323 Sleep(400);
325 h = CreateFileW(testpipe, GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
327 if (h != INVALID_HANDLE_VALUE) {
328 open_succeeded = TRUE;
329 Sleep(100);
330 CloseHandle(h);
331 } else
332 open_succeeded = FALSE;
334 return 0;
337 static void test_alertable(void)
339 IO_STATUS_BLOCK iosb;
340 HANDLE hEvent;
341 HANDLE hPipe;
342 NTSTATUS res;
343 HANDLE hThread;
344 DWORD ret;
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);
403 CloseHandle(hEvent);
404 CloseHandle(hPipe);
407 static void test_nonalertable(void)
409 IO_STATUS_BLOCK iosb;
410 HANDLE hEvent;
411 HANDLE hPipe;
412 NTSTATUS res;
413 HANDLE hThread;
414 DWORD ret;
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);
448 CloseHandle(hEvent);
449 CloseHandle(hPipe);
452 static void test_cancelio(void)
454 IO_STATUS_BLOCK iosb;
455 IO_STATUS_BLOCK cancel_sb;
456 HANDLE hEvent;
457 HANDLE hPipe;
458 NTSTATUS res;
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 todo_wine ok(!res, "NtCancelIoFile returned %x\n", res);
474 todo_wine {
475 ok(U(iosb).Status == STATUS_CANCELLED, "Wrong iostatus %x\n", U(iosb).Status);
476 ok(WaitForSingleObject(hEvent, 0) == 0, "hEvent not signaled\n");
479 ok(!ioapc_called, "IOAPC ran too early\n");
481 SleepEx(0, TRUE); /* alertable wait state */
483 ok(ioapc_called, "IOAPC didn't run\n");
485 CloseHandle(hEvent);
486 CloseHandle(hPipe);
489 static void _check_pipe_handle_state(int line, HANDLE handle, ULONG read, ULONG completion)
491 IO_STATUS_BLOCK iosb;
492 FILE_PIPE_INFORMATION fpi;
493 NTSTATUS res;
494 if (handle != INVALID_HANDLE_VALUE)
496 memset(&fpi, 0x55, sizeof(fpi));
497 res = pNtQueryInformationFile(handle, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
498 ok_(__FILE__, line)(!res, "NtQueryInformationFile returned %x\n", res);
499 ok_(__FILE__, line)(fpi.ReadMode == read, "Unexpected ReadMode, expected %x, got %x\n",
500 read, fpi.ReadMode);
501 ok_(__FILE__, line)(fpi.CompletionMode == completion, "Unexpected CompletionMode, expected %x, got %x\n",
502 completion, fpi.CompletionMode);
505 #define check_pipe_handle_state(handle, r, c) _check_pipe_handle_state(__LINE__, handle, r, c)
507 static void test_filepipeinfo(void)
509 IO_STATUS_BLOCK iosb;
510 OBJECT_ATTRIBUTES attr;
511 UNICODE_STRING name;
512 LARGE_INTEGER timeout;
513 HANDLE hServer, hClient;
514 FILE_PIPE_INFORMATION fpi;
515 NTSTATUS res;
517 pRtlInitUnicodeString(&name, testpipe_nt);
519 attr.Length = sizeof(attr);
520 attr.RootDirectory = 0;
521 attr.ObjectName = &name;
522 attr.Attributes = 0x40; /* case insensitive */
523 attr.SecurityDescriptor = NULL;
524 attr.SecurityQualityOfService = NULL;
526 timeout.QuadPart = -100000000000ll;
528 /* test with INVALID_HANDLE_VALUE */
529 res = pNtQueryInformationFile(INVALID_HANDLE_VALUE, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
530 ok(res == STATUS_OBJECT_TYPE_MISMATCH, "NtQueryInformationFile returned %x\n", res);
532 fpi.ReadMode = 0;
533 fpi.CompletionMode = 0;
534 res = pNtSetInformationFile(INVALID_HANDLE_VALUE, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
535 ok(res == STATUS_OBJECT_TYPE_MISMATCH, "NtSetInformationFile returned %x\n", res);
537 /* server end with read-only attributes */
538 res = pNtCreateNamedPipeFile(&hServer, FILE_READ_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb,
539 FILE_SHARE_READ | FILE_SHARE_WRITE, 2 /* FILE_CREATE */,
540 0, 0, 0, 1, 0xFFFFFFFF, 500, 500, &timeout);
541 ok(!res, "NtCreateNamedPipeFile returned %x\n", res);
543 check_pipe_handle_state(hServer, 0, 1);
545 hClient = CreateFileW(testpipe, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
546 ok(hClient != INVALID_HANDLE_VALUE, "can't open pipe, GetLastError: %x\n", GetLastError());
548 check_pipe_handle_state(hServer, 0, 1);
549 check_pipe_handle_state(hClient, 0, 0);
551 fpi.ReadMode = 0;
552 fpi.CompletionMode = 0;
553 res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
554 ok(res == STATUS_ACCESS_DENIED, "NtSetInformationFile returned %x\n", res);
556 check_pipe_handle_state(hServer, 0, 1);
557 check_pipe_handle_state(hClient, 0, 0);
559 fpi.ReadMode = 1; /* invalid on a byte stream pipe */
560 fpi.CompletionMode = 1;
561 res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
562 ok(res == STATUS_ACCESS_DENIED, "NtSetInformationFile returned %x\n", res);
564 check_pipe_handle_state(hServer, 0, 1);
565 check_pipe_handle_state(hClient, 0, 0);
567 if (hClient != INVALID_HANDLE_VALUE)
569 fpi.ReadMode = 1; /* invalid on a byte stream pipe */
570 fpi.CompletionMode = 1;
571 res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
572 ok(res == STATUS_INVALID_PARAMETER, "NtSetInformationFile returned %x\n", res);
575 check_pipe_handle_state(hServer, 0, 1);
576 check_pipe_handle_state(hClient, 0, 0);
578 if (hClient != INVALID_HANDLE_VALUE)
580 fpi.ReadMode = 0;
581 fpi.CompletionMode = 1;
582 res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
583 ok(!res, "NtSetInformationFile returned %x\n", res);
586 check_pipe_handle_state(hServer, 0, 1);
587 check_pipe_handle_state(hClient, 0, 1);
589 if (hClient != INVALID_HANDLE_VALUE)
591 fpi.ReadMode = 0;
592 fpi.CompletionMode = 2; /* not in range 0-1 */
593 res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
594 ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res);
596 fpi.ReadMode = 2; /* not in range 0-1 */
597 fpi.CompletionMode = 0;
598 res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
599 ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res);
602 CloseHandle(hClient);
604 check_pipe_handle_state(hServer, 0, 1);
606 fpi.ReadMode = 0;
607 fpi.CompletionMode = 0;
608 res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
609 ok(res == STATUS_ACCESS_DENIED, "NtSetInformationFile returned %x\n", res);
611 CloseHandle(hServer);
613 /* message mode server with read/write attributes */
614 res = pNtCreateNamedPipeFile(&hServer, FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | SYNCHRONIZE, &attr, &iosb,
615 FILE_SHARE_READ | FILE_SHARE_WRITE, 2 /* FILE_CREATE */,
616 0, 1, 1, 0, 0xFFFFFFFF, 500, 500, &timeout);
617 ok(!res, "NtCreateNamedPipeFile returned %x\n", res);
619 check_pipe_handle_state(hServer, 1, 0);
621 hClient = CreateFileW(testpipe, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
622 ok(hClient != INVALID_HANDLE_VALUE, "can't open pipe, GetLastError: %x\n", GetLastError());
624 check_pipe_handle_state(hServer, 1, 0);
625 check_pipe_handle_state(hClient, 0, 0);
627 if (hClient != INVALID_HANDLE_VALUE)
629 fpi.ReadMode = 1;
630 fpi.CompletionMode = 1;
631 res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
632 ok(!res, "NtSetInformationFile returned %x\n", res);
635 check_pipe_handle_state(hServer, 1, 0);
636 check_pipe_handle_state(hClient, 1, 1);
638 fpi.ReadMode = 0;
639 fpi.CompletionMode = 1;
640 res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
641 ok(!res, "NtSetInformationFile returned %x\n", res);
643 check_pipe_handle_state(hServer, 0, 1);
644 check_pipe_handle_state(hClient, 1, 1);
646 if (hClient != INVALID_HANDLE_VALUE)
648 fpi.ReadMode = 0;
649 fpi.CompletionMode = 2; /* not in range 0-1 */
650 res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
651 ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res);
653 fpi.ReadMode = 2; /* not in range 0-1 */
654 fpi.CompletionMode = 0;
655 res = pNtSetInformationFile(hClient, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
656 ok(res == STATUS_INVALID_PARAMETER || broken(!res) /* < Vista */, "NtSetInformationFile returned %x\n", res);
659 CloseHandle(hClient);
661 check_pipe_handle_state(hServer, 0, 1);
663 fpi.ReadMode = 1;
664 fpi.CompletionMode = 0;
665 res = pNtSetInformationFile(hServer, &iosb, &fpi, sizeof(fpi), (FILE_INFORMATION_CLASS)23);
666 ok(!res, "NtSetInformationFile returned %x\n", res);
668 check_pipe_handle_state(hServer, 1, 0);
670 CloseHandle(hServer);
673 START_TEST(pipe)
675 if (!init_func_ptrs())
676 return;
678 trace("starting invalid create tests\n");
679 test_create_invalid();
681 trace("starting create tests\n");
682 test_create();
684 trace("starting overlapped tests\n");
685 test_overlapped();
687 trace("starting FILE_PIPE_INFORMATION tests\n");
688 test_filepipeinfo();
690 if (!pOpenThread || !pQueueUserAPC)
691 return;
693 trace("starting alertable tests\n");
694 test_alertable();
696 trace("starting nonalertable tests\n");
697 test_nonalertable();
699 trace("starting cancelio tests\n");
700 test_cancelio();