@@ -908,6 +908,58 @@ static void testScreenBuffer(HANDLE hConOut)
908
908
SetConsoleOutputCP (oldcp );
909
909
}
910
910
911
+ static void CALLBACK signaled_function (void * p , BOOLEAN timeout )
912
+ {
913
+ HANDLE event = p ;
914
+ SetEvent (event );
915
+ ok (!timeout , "wait shouldn't have timed out\n" );
916
+ }
917
+
918
+ static void testWaitForConsoleInput (HANDLE input_handle )
919
+ {
920
+ HANDLE wait_handle ;
921
+ HANDLE complete_event ;
922
+ INPUT_RECORD record ;
923
+ DWORD events_written ;
924
+ DWORD wait_ret ;
925
+ BOOL ret ;
926
+
927
+ complete_event = CreateEventW (NULL , FALSE, FALSE, NULL );
928
+
929
+ /* Test success case */
930
+ ret = RegisterWaitForSingleObject (& wait_handle , input_handle , signaled_function , complete_event , INFINITE , WT_EXECUTEONLYONCE );
931
+ ok (ret == TRUE, "Expected RegisterWaitForSingleObject to return TRUE, got %d\n" , ret );
932
+ /* give worker thread a chance to start up */
933
+ Sleep (100 );
934
+ record .EventType = KEY_EVENT ;
935
+ record .Event .KeyEvent .bKeyDown = 1 ;
936
+ record .Event .KeyEvent .wRepeatCount = 1 ;
937
+ record .Event .KeyEvent .wVirtualKeyCode = VK_RETURN ;
938
+ record .Event .KeyEvent .wVirtualScanCode = VK_RETURN ;
939
+ record .Event .KeyEvent .uChar .UnicodeChar = '\r' ;
940
+ record .Event .KeyEvent .dwControlKeyState = 0 ;
941
+ ret = WriteConsoleInputW (input_handle , & record , 1 , & events_written );
942
+ ok (ret == TRUE, "Expected WriteConsoleInputW to return TRUE, got %d\n" , ret );
943
+ wait_ret = WaitForSingleObject (complete_event , INFINITE );
944
+ ok (wait_ret == WAIT_OBJECT_0 , "Expected the handle to be signaled\n" );
945
+ ret = UnregisterWait (wait_handle );
946
+ /* If the callback is still running, this fails with ERROR_IO_PENDING, but
947
+ that's ok and expected. */
948
+ ok (ret != 0 || GetLastError () == ERROR_IO_PENDING ,
949
+ "UnregisterWait failed with error %d\n" , GetLastError ());
950
+
951
+ /* Test timeout case */
952
+ FlushConsoleInputBuffer (input_handle );
953
+ ret = RegisterWaitForSingleObject (& wait_handle , input_handle , signaled_function , complete_event , INFINITE , WT_EXECUTEONLYONCE );
954
+ wait_ret = WaitForSingleObject (complete_event , 100 );
955
+ ok (wait_ret == WAIT_TIMEOUT , "Expected the wait to time out\n" );
956
+ ret = UnregisterWait (wait_handle );
957
+ ok (ret , "UnregisterWait failed with error %d\n" , GetLastError ());
958
+
959
+ /* Clean up */
960
+ ok (CloseHandle (complete_event ), "Failed to close event handle, last error %d\n" , GetLastError ());
961
+ }
962
+
911
963
static void test_GetSetConsoleInputExeName (void )
912
964
{
913
965
BOOL ret ;
@@ -2938,6 +2990,55 @@ static void test_SetConsoleFont(HANDLE std_output)
2938
2990
todo_wine ok (GetLastError () == ERROR_INVALID_PARAMETER , "got %u, expected 87\n" , GetLastError ());
2939
2991
}
2940
2992
2993
+ static void test_GetConsoleScreenBufferInfoEx (HANDLE std_output )
2994
+ {
2995
+ HANDLE hmod ;
2996
+ BOOL (WINAPI * pGetConsoleScreenBufferInfoEx )(HANDLE , CONSOLE_SCREEN_BUFFER_INFOEX * );
2997
+ CONSOLE_SCREEN_BUFFER_INFOEX csbix ;
2998
+ BOOL ret ;
2999
+ HANDLE std_input = GetStdHandle (STD_INPUT_HANDLE );
3000
+
3001
+ hmod = GetModuleHandleA ("kernel32.dll" );
3002
+ pGetConsoleScreenBufferInfoEx = (void * )GetProcAddress (hmod , "GetConsoleScreenBufferInfoEx" );
3003
+ if (!pGetConsoleScreenBufferInfoEx )
3004
+ {
3005
+ win_skip ("GetConsoleScreenBufferInfoEx is not available\n" );
3006
+ return ;
3007
+ }
3008
+
3009
+ SetLastError (0xdeadbeef );
3010
+ ret = pGetConsoleScreenBufferInfoEx (NULL , & csbix );
3011
+ ok (!ret , "got %d, expected zero\n" , ret );
3012
+ ok (GetLastError () == ERROR_INVALID_PARAMETER , "got %u, expected 87\n" , GetLastError ());
3013
+
3014
+ SetLastError (0xdeadbeef );
3015
+ ret = pGetConsoleScreenBufferInfoEx (std_input , & csbix );
3016
+ ok (!ret , "got %d, expected zero\n" , ret );
3017
+ ok (GetLastError () == ERROR_INVALID_PARAMETER , "got %u, expected 87\n" , GetLastError ());
3018
+
3019
+ SetLastError (0xdeadbeef );
3020
+ ret = pGetConsoleScreenBufferInfoEx (std_output , & csbix );
3021
+ ok (!ret , "got %d, expected zero\n" , ret );
3022
+ ok (GetLastError () == ERROR_INVALID_PARAMETER , "got %u, expected 87\n" , GetLastError ());
3023
+
3024
+ csbix .cbSize = sizeof (CONSOLE_SCREEN_BUFFER_INFOEX );
3025
+
3026
+ SetLastError (0xdeadbeef );
3027
+ ret = pGetConsoleScreenBufferInfoEx (NULL , & csbix );
3028
+ ok (!ret , "got %d, expected zero\n" , ret );
3029
+ ok (GetLastError () == ERROR_INVALID_HANDLE , "got %u, expected 6\n" , GetLastError ());
3030
+
3031
+ SetLastError (0xdeadbeef );
3032
+ ret = pGetConsoleScreenBufferInfoEx (std_input , & csbix );
3033
+ ok (!ret , "got %d, expected zero\n" , ret );
3034
+ ok (GetLastError () == ERROR_INVALID_HANDLE , "got %u, expected 6\n" , GetLastError ());
3035
+
3036
+ SetLastError (0xdeadbeef );
3037
+ ret = pGetConsoleScreenBufferInfoEx (std_output , & csbix );
3038
+ ok (ret , "got %d, expected non-zero\n" , ret );
3039
+ ok (GetLastError () == 0xdeadbeef , "got %u, expected 0xdeadbeef\n" , GetLastError ());
3040
+ }
3041
+
2941
3042
START_TEST (console )
2942
3043
{
2943
3044
static const char font_name [] = "Lucida Console" ;
@@ -3044,6 +3145,8 @@ START_TEST(console)
3044
3145
testScroll (hConOut , sbi .dwSize );
3045
3146
/* will test sb creation / modification / codepage handling */
3046
3147
testScreenBuffer (hConOut );
3148
+ /* Test waiting for a console handle */
3149
+ testWaitForConsoleInput (hConIn );
3047
3150
3048
3151
/* clear duplicated console font table */
3049
3152
CloseHandle (hConIn );
@@ -3086,4 +3189,5 @@ START_TEST(console)
3086
3189
test_GetLargestConsoleWindowSize (hConOut );
3087
3190
test_GetConsoleFontInfo (hConOut );
3088
3191
test_SetConsoleFont (hConOut );
3192
+ test_GetConsoleScreenBufferInfoEx (hConOut );
3089
3193
}
0 commit comments