Jacek Caban : imm32/tests: Add NtUserAssociateInputContext tests.

Alexandre Julliard julliard at winehq.org
Tue Jul 12 16:45:37 CDT 2022


Module: wine
Branch: master
Commit: 9c1ecf997108bf8ef06d156590f5cb10f2d2f9f5
URL:    https://gitlab.winehq.org/wine/wine/-/commit/9c1ecf997108bf8ef06d156590f5cb10f2d2f9f5

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Jul 11 18:17:47 2022 +0200

imm32/tests: Add NtUserAssociateInputContext tests.

---

 dlls/imm32/tests/imm32.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/dlls/imm32/tests/imm32.c b/dlls/imm32/tests/imm32.c
index 3f2e503b5e5..5bb51d90456 100644
--- a/dlls/imm32/tests/imm32.c
+++ b/dlls/imm32/tests/imm32.c
@@ -30,6 +30,7 @@
 BOOL WINAPI ImmSetActiveContext(HWND, HIMC, BOOL);
 
 static BOOL (WINAPI *pImmAssociateContextEx)(HWND,HIMC,DWORD);
+static UINT (WINAPI *pNtUserAssociateInputContext)(HWND,HIMC,ULONG);
 static BOOL (WINAPI *pImmIsUIMessageA)(HWND,UINT,WPARAM,LPARAM);
 static UINT (WINAPI *pSendInput) (UINT, INPUT*, size_t);
 
@@ -303,6 +304,8 @@ static BOOL init(void) {
     pImmAssociateContextEx = (void*)GetProcAddress(hmod, "ImmAssociateContextEx");
     pImmIsUIMessageA = (void*)GetProcAddress(hmod, "ImmIsUIMessageA");
     pSendInput = (void*)GetProcAddress(huser, "SendInput");
+    pNtUserAssociateInputContext = (void*)GetProcAddress(GetModuleHandleW(L"win32u.dll"),
+                                                         "NtUserAssociateInputContext");
 
     wc.cbSize        = sizeof(WNDCLASSEXA);
     wc.style         = 0;
@@ -753,6 +756,81 @@ static void test_ImmAssociateContextEx(void)
     ImmReleaseContext(hwnd,imc);
 }
 
+/* similar to above, but using NtUserAssociateInputContext */
+static void test_NtUserAssociateInputContext(void)
+{
+    HIMC imc;
+    UINT rc;
+
+    if (!pNtUserAssociateInputContext)
+    {
+        win_skip("NtUserAssociateInputContext not available\n");
+        return;
+    }
+
+    imc = ImmGetContext(hwnd);
+    if (imc)
+    {
+        HIMC retimc, newimc;
+        HWND focus;
+
+        SET_ENABLE(WM_IME_SETCONTEXT_ACTIVATE, TRUE);
+        SET_ENABLE(WM_IME_SETCONTEXT_DEACTIVATE, TRUE);
+
+        ok(GetActiveWindow() == hwnd, "hwnd is not active\n");
+        newimc = ImmCreateContext();
+        ok(newimc != imc, "handles should not be the same\n");
+        rc = pNtUserAssociateInputContext(NULL, NULL, 0);
+        ok(rc == 2, "NtUserAssociateInputContext returned %x\n", rc);
+        rc = pNtUserAssociateInputContext(hwnd, NULL, 0);
+        ok(rc == 1, "NtUserAssociateInputContext returned %x\n", rc);
+        rc = pNtUserAssociateInputContext(NULL, imc, 0);
+        ok(rc == 2, "NtUserAssociateInputContext returned %x\n", rc);
+
+        rc = pNtUserAssociateInputContext(hwnd, imc, 0);
+        ok(rc == 1, "NtUserAssociateInputContext returned %x\n", rc);
+        retimc = ImmGetContext(hwnd);
+        ok(retimc == imc, "handles should be the same\n");
+        ImmReleaseContext(hwnd,retimc);
+
+        rc = pNtUserAssociateInputContext(hwnd, imc, 0);
+        ok(rc == 0, "NtUserAssociateInputContext returned %x\n", rc);
+
+        rc = pNtUserAssociateInputContext(hwnd, newimc, 0);
+        ok(rc == 1, "NtUserAssociateInputContext returned %x\n", rc);
+        retimc = ImmGetContext(hwnd);
+        ok(retimc == newimc, "handles should be the same\n");
+        ImmReleaseContext(hwnd,retimc);
+
+        focus = CreateWindowA("button", "button", 0, 0, 0, 0, 0, 0, 0, 0, 0);
+        ok(focus != NULL, "CreateWindow failed\n");
+        SET_EXPECT(WM_IME_SETCONTEXT_DEACTIVATE);
+        SetFocus(focus);
+        CHECK_CALLED(WM_IME_SETCONTEXT_DEACTIVATE);
+        rc = pNtUserAssociateInputContext(hwnd, imc, 0);
+        ok(rc == 0, "NtUserAssociateInputContext returned %x\n", rc);
+        SET_EXPECT(WM_IME_SETCONTEXT_ACTIVATE);
+        DestroyWindow(focus);
+        CHECK_CALLED(WM_IME_SETCONTEXT_ACTIVATE);
+
+        SET_EXPECT(WM_IME_SETCONTEXT_DEACTIVATE);
+        SetFocus(child);
+        CHECK_CALLED(WM_IME_SETCONTEXT_DEACTIVATE);
+        rc = pNtUserAssociateInputContext(hwnd, newimc, 0);
+        ok(rc == 0, "NtUserAssociateInputContext returned %x\n", rc);
+        SET_EXPECT(WM_IME_SETCONTEXT_ACTIVATE);
+        SetFocus(hwnd);
+        CHECK_CALLED(WM_IME_SETCONTEXT_ACTIVATE);
+
+        rc = pNtUserAssociateInputContext(hwnd, NULL, IACE_DEFAULT);
+        ok(rc == 1, "NtUserAssociateInputContext returned %x\n", rc);
+
+        SET_ENABLE(WM_IME_SETCONTEXT_ACTIVATE, FALSE);
+        SET_ENABLE(WM_IME_SETCONTEXT_DEACTIVATE, FALSE);
+    }
+    ImmReleaseContext(hwnd,imc);
+}
+
 typedef struct _igc_threadinfo {
     HWND hwnd;
     HANDLE event;
@@ -2331,6 +2409,7 @@ START_TEST(imm32) {
         test_ImmSetCompositionString();
         test_ImmIME();
         test_ImmAssociateContextEx();
+        test_NtUserAssociateInputContext();
         test_ImmThreads();
         test_ImmIsUIMessage();
         test_ImmGetContext();




More information about the wine-cvs mailing list