To keep the testcase similar to the original code thats probably fine, however I would like to point out that you do not really need an asynchronous wait here. You could basically test the same with WaitForSingleObject(input_handle, INFINITE).
I wanted to make sure to keep the ordering of events the same as in the original, which is WaitForSingleEvent->WriteConsoleInput. It seems like reversing the order here might go down a different code path, though perhaps here's not the place to test that, since that's handled in the generic waiting code.
+ /* give worker thread a chance to start up */ + Sleep(100); + record.EventType = KEY_EVENT; + record.Event.KeyEvent.bKeyDown = 1; + record.Event.KeyEvent.wRepeatCount = 1; + record.Event.KeyEvent.wVirtualKeyCode = VK_RETURN; + record.Event.KeyEvent.wVirtualScanCode = VK_RETURN; + record.Event.KeyEvent.uChar.AsciiChar = '\r';
If I don't miss anything this does not initialize the upper byte of the union.
Yes you're correct, since I'm calling WriteConsoleInputW, I should be using the unicode variant.
+ record.Event.KeyEvent.dwControlKeyState = 0; + ret = WriteConsoleInputW(input_handle, &record, 1, &events_written); + ok(ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n", ret); + wait_ret = WaitForSingleObject(complete_event, INFINITE); + ok(wait_ret == WAIT_OBJECT_0, "Expected the handle to be signaled");
There is a linebreak missing in the line above. For completeness, it also wouldn't hurt to add another test after calling FlushConsoleInputBuffer() to make sure it times out as expected.
Sounds good.