Signed-off-by: Daniel Lehman <dlehman25(a)gmail.com>
---
dlls/kernel32/tests/pipe.c | 93 ++++++++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/dlls/kernel32/tests/pipe.c b/dlls/kernel32/tests/pipe.c
index 7fa3c313d47..50dda0bcc80 100644
--- a/dlls/kernel32/tests/pipe.c
+++ b/dlls/kernel32/tests/pipe.c
@@ -37,6 +37,7 @@ static HANDLE alarm_event;
static BOOL (WINAPI *pDuplicateTokenEx)(HANDLE,DWORD,LPSECURITY_ATTRIBUTES,
SECURITY_IMPERSONATION_LEVEL,TOKEN_TYPE,PHANDLE);
static BOOL (WINAPI *pCancelIoEx)(HANDLE handle, LPOVERLAPPED lpOverlapped);
+static BOOL (WINAPI *pCancelSynchronousIo)(HANDLE handle);
static BOOL (WINAPI *pGetNamedPipeClientProcessId)(HANDLE,ULONG*);
static BOOL (WINAPI *pGetNamedPipeServerProcessId)(HANDLE,ULONG*);
static BOOL (WINAPI *pGetNamedPipeClientSessionId)(HANDLE,ULONG*);
@@ -4202,6 +4203,96 @@ static void test_exit_process_async(void)
CloseHandle(server);
}
+static DWORD CALLBACK synchronousIoThreadMain(void *arg)
+{
+ HANDLE pipe;
+ BOOL ret;
+
+ pipe = arg;
+ SetLastError(0xdeadbeef);
+ ret = ConnectNamedPipe(pipe, NULL);
+ ok(!ret, "expected failure\n");
+ todo_wine
+ ok(GetLastError() == ERROR_OPERATION_ABORTED, "got error %lu\n", GetLastError());
+ return 0;
+}
+
+static DWORD CALLBACK synchronousIoThreadMain2(void *arg)
+{
+ OVERLAPPED ov;
+ HANDLE pipe;
+ BOOL ret;
+
+ pipe = arg;
+ memset(&ov, 0, sizeof(ov));
+ ov.hEvent = CreateEventW(NULL, TRUE, FALSE, NULL);
+ SetLastError(0xdeadbeef);
+ ret = ConnectNamedPipe(pipe, &ov);
+ ok(!ret, "expected failure\n");
+ ok(GetLastError() == ERROR_IO_PENDING, "got error %lu\n", GetLastError());
+ ret = WaitForSingleObject(ov.hEvent, 1000);
+ ok(ret == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", ret);
+ CloseHandle(ov.hEvent);
+ return 0;
+}
+
+static void test_CancelSynchronousIo(void)
+{
+ BOOL res;
+ HANDLE file;
+ HANDLE pipe;
+ HANDLE thread;
+
+ /* bogus values */
+ SetLastError(0xdeadbeef);
+ res = pCancelSynchronousIo((HANDLE)0xdeadbeef);
+ ok(!res, "CancelSynchronousIo succeeded unexpectedly\n");
+ todo_wine
+ ok(GetLastError() == ERROR_INVALID_HANDLE,
+ "In CancelSynchronousIo failure, expected ERROR_INVALID_HANDLE, got %ld\n", GetLastError());
+
+ SetLastError(0xdeadbeef);
+ res = pCancelSynchronousIo(GetCurrentThread());
+ ok(!res, "CancelSynchronousIo succeeded unexpectedly\n");
+ todo_wine
+ ok(GetLastError() == ERROR_NOT_FOUND,
+ "In CancelSynchronousIo failure, expected ERROR_NOT_FOUND, got %ld\n", GetLastError());
+
+ /* synchronous i/o */
+ pipe = CreateNamedPipeA(PIPENAME, PIPE_ACCESS_DUPLEX,
+ PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
+ 1, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL);
+ ok(pipe != INVALID_HANDLE_VALUE, "CreateNamedPipe failed with %lu\n", GetLastError());
+ thread = CreateThread(NULL, 0, synchronousIoThreadMain, pipe, 0, NULL);
+ /* wait for thread to start listening */
+ Sleep(100);
+ res = pCancelSynchronousIo(thread);
+ todo_wine
+ ok(res, "CancelSynchronousIo failed with error %ld\n", GetLastError());
+ CloseHandle(pipe);
+ WaitForSingleObject(thread, INFINITE);
+ CloseHandle(thread);
+
+ /* asynchronous i/o */
+ pipe = CreateNamedPipeA(PIPENAME, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
+ PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
+ 1, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL);
+ ok(pipe != INVALID_HANDLE_VALUE, "CreateNamedPipe failed with %lu\n", GetLastError());
+ thread = CreateThread(NULL, 0, synchronousIoThreadMain2, pipe, 0, NULL);
+ Sleep(100);
+ res = pCancelSynchronousIo(thread);
+ ok(!res, "CancelSynchronousIo succeeded unexpectedly\n");
+ todo_wine
+ ok(GetLastError() == ERROR_NOT_FOUND,
+ "In CancelSynchronousIo failure, expected ERROR_NOT_FOUND, got %ld\n", GetLastError());
+ file = CreateFileA(PIPENAME, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
+ ok(file != INVALID_HANDLE_VALUE, "CreateFile failed (%ld)\n", GetLastError());
+ WaitForSingleObject(thread, INFINITE);
+ CloseHandle(thread);
+ CloseHandle(file);
+ CloseHandle(pipe);
+}
+
START_TEST(pipe)
{
char **argv;
@@ -4212,6 +4303,7 @@ START_TEST(pipe)
pDuplicateTokenEx = (void *) GetProcAddress(hmod, "DuplicateTokenEx");
hmod = GetModuleHandleA("kernel32.dll");
pCancelIoEx = (void *) GetProcAddress(hmod, "CancelIoEx");
+ pCancelSynchronousIo = (void *) GetProcAddress(hmod, "CancelSynchronousIo");
pGetNamedPipeClientProcessId = (void *) GetProcAddress(hmod, "GetNamedPipeClientProcessId");
pGetNamedPipeServerProcessId = (void *) GetProcAddress(hmod, "GetNamedPipeServerProcessId");
pGetNamedPipeClientSessionId = (void *) GetProcAddress(hmod, "GetNamedPipeClientSessionId");
@@ -4282,4 +4374,5 @@ START_TEST(pipe)
test_nowait(PIPE_TYPE_MESSAGE);
test_GetOverlappedResultEx();
test_exit_process_async();
+ test_CancelSynchronousIo();
}
--
2.25.1