From: Rémi Bernon rbernon@codeweavers.com
--- dlls/imm32/tests/imm32.c | 109 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-)
diff --git a/dlls/imm32/tests/imm32.c b/dlls/imm32/tests/imm32.c index 111adcf290c..5a1f3000b12 100644 --- a/dlls/imm32/tests/imm32.c +++ b/dlls/imm32/tests/imm32.c @@ -2915,8 +2915,7 @@ static BOOL WINAPI ime_ImeSelect( HIMC himc, BOOL select ) static BOOL WINAPI ime_ImeSetActiveContext( HIMC himc, BOOL flag ) { ime_trace( "himc %p, flag %#x\n", himc, flag ); - ok( 0, "unexpected call\n" ); - return FALSE; + return TRUE; }
static BOOL WINAPI ime_ImeSetCompositionString( HIMC himc, DWORD index, const void *comp, DWORD comp_len, @@ -3950,6 +3949,84 @@ static void test_ImmProcessKey(void) ime_call_count = 0; }
+struct ime_windows +{ + HWND ime_hwnd; + HWND ime_ui_hwnd; +}; + +static BOOL CALLBACK enum_thread_ime_windows( HWND hwnd, LPARAM lparam ) +{ + struct ime_windows *params = (void *)lparam; + WCHAR buffer[256]; + UINT ret; + + ime_trace( "hwnd %p, lparam %#Ix\n", hwnd, lparam ); + + ret = RealGetWindowClassW( hwnd, buffer, ARRAY_SIZE(buffer) ); + ok( ret, "RealGetWindowClassW returned %#x\n", ret ); + + if (!wcscmp( buffer, L"IME" )) + { + ok( !params->ime_hwnd, "Found extra IME window %p\n", hwnd ); + params->ime_hwnd = hwnd; + } + if (!wcscmp( buffer, ime_ui_class.lpszClassName )) + { + ok( !params->ime_ui_hwnd, "Found extra IME UI window %p\n", hwnd ); + params->ime_ui_hwnd = hwnd; + } + + return TRUE; +} + +struct test_activate_layout_params +{ + HKL hkl; + struct ime_windows *ime_windows; +}; + +static DWORD CALLBACK test_activate_layout_thread( void *arg ) +{ + struct test_activate_layout_params *params = arg; + struct ime_windows *ime_windows = params->ime_windows; + HKL hkl = GetKeyboardLayout( 0 ); + HWND hwnd; + + todo_wine ok( hkl == params->hkl || broken(hkl == default_hkl) /* win7 */, "got HKL %p\n", hkl ); + + hwnd = CreateWindowW( L"static", NULL, WS_VISIBLE | WS_POPUP, + 100, 100, 100, 100, 0, NULL, NULL, NULL ); + ok( !!hwnd, "CreateWindow failed, error %lu\n", GetLastError() ); + process_messages(); + + if (hkl == default_hkl) + { + ok_eq( default_hkl, ActivateKeyboardLayout( params->hkl, 0 ), HKL, "%p" ); + ok_eq( params->hkl, GetKeyboardLayout( 0 ), HKL, "%p" ); + } + + ok_ret( 1, EnumThreadWindows( GetCurrentThreadId(), enum_thread_ime_windows, (LPARAM)ime_windows ) ); + ok( !!ime_windows->ime_hwnd, "missing IME window\n" ); + todo_wine ok( !!ime_windows->ime_ui_hwnd, "missing IME UI window\n" ); + todo_wine ok_ret( (UINT_PTR)ime_windows->ime_hwnd, (UINT_PTR)GetParent( ime_windows->ime_ui_hwnd ) ); + + if (hkl == default_hkl) + { + ok_eq( params->hkl, ActivateKeyboardLayout( default_hkl, 0 ), HKL, "%p" ); + ok_eq( default_hkl, GetKeyboardLayout( 0 ), HKL, "%p" ); + } + + ShowWindow( hwnd, SW_HIDE ); + process_messages(); + + DestroyWindow( hwnd ); + memset( ime_calls, 0, sizeof(ime_calls) ); + ime_call_count = 0; + + return 0; +} + static void test_ImmActivateLayout(void) { const struct ime_call activate_seq[] = @@ -4042,6 +4119,9 @@ static void test_ImmActivateLayout(void) {0}, }; HKL hkl, old_hkl = GetKeyboardLayout( 0 ); + struct ime_windows ime_windows = {0}, other_ime_windows = {0}; + struct test_activate_layout_params thread_params = {.ime_windows = &other_ime_windows}; + HANDLE thread; HIMC himc; UINT ret;
@@ -4131,6 +4211,31 @@ static void test_ImmActivateLayout(void)
ok_eq( old_hkl, GetKeyboardLayout( 0 ), HKL, "%p" );
+ + ok_eq( old_hkl, ActivateKeyboardLayout( hkl, 0 ), HKL, "%p" ); + ok_eq( hkl, GetKeyboardLayout( 0 ), HKL, "%p" ); + + ok_ret( 1, EnumThreadWindows( GetCurrentThreadId(), enum_thread_ime_windows, (LPARAM)&ime_windows ) ); + ok( !!ime_windows.ime_hwnd, "missing IME window\n" ); + todo_wine ok( !!ime_windows.ime_ui_hwnd, "missing IME UI window\n" ); + todo_wine ok_ret( (UINT_PTR)ime_windows.ime_hwnd, (UINT_PTR)GetParent( ime_windows.ime_ui_hwnd ) ); + + thread_params.hkl = hkl; + thread = CreateThread( NULL, 0, test_activate_layout_thread, &thread_params, 0, NULL ); + ok( !!thread, "CreateThread failed, error %lu\n", GetLastError() ); + ok_ret( 0, WaitForSingleObject( thread, 30000 ) ); + ok_ret( 1, CloseHandle( thread ) ); + + ok_ne( other_ime_windows.ime_hwnd, ime_windows.ime_hwnd, HWND, "%p" ); + todo_wine ok_ne( other_ime_windows.ime_ui_hwnd, ime_windows.ime_ui_hwnd, HWND, "%p" ); + + ok_eq( hkl, ActivateKeyboardLayout( old_hkl, 0 ), HKL, "%p" ); + ok_eq( old_hkl, GetKeyboardLayout( 0 ), HKL, "%p" ); + process_messages(); + memset( ime_calls, 0, sizeof(ime_calls) ); + ime_call_count = 0; + + ok_ret( 1, ImmDestroyContext( himc ) ); ok_seq( empty_sequence );