From 2b205a6d8c2226c13b3fbec5aa63fc6d5342398b Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 10 Nov 2020 16:31:34 +0100 Subject: [PATCH] kernel32/tests: Add more console waiting tests. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/kernel32/tests/console.c | 72 ++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/dlls/kernel32/tests/console.c b/dlls/kernel32/tests/console.c index 495fa1b9e57..5064cfe5c6d 100644 --- a/dlls/kernel32/tests/console.c +++ b/dlls/kernel32/tests/console.c @@ -19,11 +19,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "wine/test.h" +#include +#define WIN32_NO_STATUS #include #include #include +#include "wine/test.h" + static void (WINAPI *pClosePseudoConsole)(HPCON); static HRESULT (WINAPI *pCreatePseudoConsole)(COORD,HANDLE,HANDLE,DWORD,HPCON*); static BOOL (WINAPI *pGetConsoleInputExeNameA)(DWORD, LPSTR); @@ -988,6 +991,72 @@ static void testWaitForConsoleInput(HANDLE input_handle) CloseHandle(complete_event); } +static void test_wait(HANDLE input, HANDLE orig_output) +{ + LARGE_INTEGER zero; + INPUT_RECORD ir; + HANDLE output; + DWORD res, count; + NTSTATUS status; + BOOL ret; + + if (skip_nt) return; + + memset(&ir, 0, sizeof(ir)); + ir.EventType = MOUSE_EVENT; + ir.Event.MouseEvent.dwEventFlags = MOUSE_MOVED; + zero.QuadPart = 0; + + output = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, + CONSOLE_TEXTMODE_BUFFER, NULL); + ok(output != INVALID_HANDLE_VALUE, "CreateConsoleScreenBuffer failed: %u\n", GetLastError()); + + ret = SetConsoleActiveScreenBuffer(output); + ok(ret, "SetConsoleActiveScreenBuffer failed: %u\n", GetLastError()); + FlushConsoleInputBuffer(input); + + res = WaitForSingleObject(input, 0); + ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %x\n", res); + res = WaitForSingleObject(output, 0); + todo_wine + ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %x\n", res); + res = WaitForSingleObject(orig_output, 0); + ok(res == WAIT_TIMEOUT, "WaitForSingleObject returned %x\n", res); + status = NtWaitForSingleObject(input, FALSE, &zero); + todo_wine + ok(status == STATUS_TIMEOUT || broken(status == STATUS_ACCESS_DENIED /* win2k8 */), + "NtWaitForSingleObject returned %x\n", status); + status = NtWaitForSingleObject(output, FALSE, &zero); + todo_wine + ok(status == STATUS_TIMEOUT || broken(status == STATUS_ACCESS_DENIED /* win2k8 */), + "NtWaitForSingleObject returned %x\n", status); + + ret = WriteConsoleInputW(input, &ir, 1, &count); + ok(ret, "WriteConsoleInputW failed: %u\n", GetLastError()); + + res = WaitForSingleObject(input, 0); + ok(!res, "WaitForSingleObject returned %x\n", res); + res = WaitForSingleObject(output, 0); + todo_wine + ok(!res, "WaitForSingleObject returned %x\n", res); + res = WaitForSingleObject(orig_output, 0); + ok(!res, "WaitForSingleObject returned %x\n", res); + status = NtWaitForSingleObject(input, FALSE, &zero); + todo_wine + ok(!status || broken(status == STATUS_ACCESS_DENIED /* win2k8 */), + "NtWaitForSingleObject returned %x\n", status); + status = NtWaitForSingleObject(output, FALSE, &zero); + todo_wine + ok(!status || broken(status == STATUS_ACCESS_DENIED /* win2k8 */), + "NtWaitForSingleObject returned %x\n", status); + + ret = SetConsoleActiveScreenBuffer(orig_output); + ok(ret, "SetConsoleActiveScreenBuffer failed: %u\n", GetLastError()); + + CloseHandle(output); +} + static void test_GetSetConsoleInputExeName(void) { BOOL ret; @@ -4295,6 +4364,7 @@ START_TEST(console) if (!test_current) testScreenBuffer(hConOut); /* Test waiting for a console handle */ testWaitForConsoleInput(hConIn); + test_wait(hConIn, hConOut); if (!test_current) {