1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) 4 * PURPOSE: Test for imm32 HIMC 5 * COPYRIGHT: Copyright 2021 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com) 6 */ 7 8 #include "precomp.h" 9 10 static void Test1(void) 11 { 12 DWORD style; 13 HWND hwndEdit, hwndStatic; 14 HIMC hNewIMC, hOldIMC, hIMC, hIMC1, hIMC2; 15 LPINPUTCONTEXT pIC; 16 17 /* ImmCreateContext/ImmDestroyContext and ImmLockIMC/ImmUnlockIMC */ 18 hNewIMC = ImmCreateContext(); 19 ok(hNewIMC != NULL, "ImmCreateContext failed\n"); 20 pIC = ImmLockIMC(hNewIMC); 21 ok(pIC == NULL, "ImmLockIMC succeeded unexpectedly\n"); 22 ImmUnlockIMC(hNewIMC); 23 ok(ImmDestroyContext(hNewIMC), "ImmDestroyContext failed\n"); 24 25 /* ImmGetContext against NULL */ 26 hIMC = ImmGetContext(NULL); 27 ok(hIMC == NULL, "ImmGetContext failed\n"); 28 29 /* Create EDIT control */ 30 style = ES_MULTILINE | ES_LEFT; 31 hwndEdit = CreateWindowW(L"EDIT", NULL, style, 0, 0, 100, 20, NULL, NULL, 32 GetModuleHandleW(NULL), NULL); 33 ok(hwndEdit != NULL, "CreateWindowW failed\n"); 34 35 /* Create STATIC control */ 36 style = SS_LEFT; 37 hwndStatic = CreateWindowW(L"STATIC", NULL, style, 0, 30, 100, 20, NULL, NULL, 38 GetModuleHandleW(NULL), NULL); 39 ok(hwndStatic != NULL, "CreateWindowW failed\n"); 40 41 /* ImmGetContext/ImmReleaseContext and ImmLockIMC/ImmUnlockIMC */ 42 hIMC1 = hIMC = ImmGetContext(hwndEdit); 43 ok(hIMC != NULL, "ImmGetContext failed\n"); 44 pIC = ImmLockIMC(hIMC); 45 ok(pIC != NULL, "ImmLockIMC failed\n"); 46 if (pIC != NULL) 47 { 48 ok(pIC->hWnd == NULL, "pIC->hWnd = %p\n", pIC->hWnd); 49 ok(!pIC->fOpen, "pIC->fOpen = %d\n", pIC->fOpen); 50 ok(ImmGetIMCCSize(pIC->hCompStr) != 0, "hCompStr size is 0\n"); 51 ok(ImmGetIMCCSize(pIC->hCandInfo) != 0, "hCandInfo size is 0\n"); 52 ok(ImmGetIMCCSize(pIC->hGuideLine) != 0, "hGuideLine size is 0\n"); 53 ok(ImmGetIMCCSize(pIC->hPrivate) != 0, "hPrivate size is 0\n"); 54 ok(ImmGetIMCCSize(pIC->hMsgBuf) != 0, "hMsgBuf size is 0\n"); 55 } 56 else 57 { 58 skip("No pIC\n"); 59 } 60 ImmUnlockIMC(hNewIMC); 61 SetFocus(hwndEdit); 62 pIC = ImmLockIMC(hIMC); 63 ok(pIC != NULL, "ImmLockIMC failed\n"); 64 if (pIC != NULL) 65 { 66 ok(pIC->hWnd == hwndEdit, "pIC->hWnd = %p, expected %p\n", pIC->hWnd, hwndEdit); 67 ok(!pIC->fOpen, "pIC->fOpen = %d\n", pIC->fOpen); 68 } 69 else 70 { 71 skip("No pIC\n"); 72 } 73 ImmUnlockIMC(hNewIMC); 74 SetFocus(NULL); 75 pIC = ImmLockIMC(hIMC); 76 ok(pIC != NULL, "ImmLockIMC failed\n"); 77 if (pIC != NULL) 78 { 79 ok(pIC->hWnd == hwndEdit, "pIC->hWnd = %p, expected %p\n", pIC->hWnd, hwndEdit); 80 } 81 else 82 { 83 skip("No pIC\n"); 84 } 85 ImmUnlockIMC(hNewIMC); 86 ok(ImmSetOpenStatus(hIMC, TRUE), "ImmSetOpenStatus failed\n"); 87 pIC = ImmLockIMC(hIMC); 88 ok(pIC != NULL, "ImmLockIMC failed\n"); 89 if (pIC != NULL) 90 { 91 ok(pIC->fOpen, "pIC->fOpen = %d\n", pIC->fOpen); 92 } 93 else 94 { 95 skip("No pIC\n"); 96 } 97 ImmUnlockIMC(hNewIMC); 98 ok(ImmReleaseContext(hwndEdit, hIMC), "ImmReleaseContext failed\n"); 99 100 hIMC2 = hIMC = ImmGetContext(hwndStatic); 101 ok(hIMC != NULL, "ImmGetContext failed\n"); 102 pIC = ImmLockIMC(hIMC); 103 ok(pIC != NULL, "ImmLockIMC failed\n"); 104 if (pIC != NULL) 105 { 106 ok(pIC->hWnd == hwndEdit, "pIC->hWnd = %p, expected %p\n", pIC->hWnd, hwndEdit); 107 ok(ImmGetIMCCSize(pIC->hCompStr) != 0, "hCompStr size is 0\n"); 108 ok(ImmGetIMCCSize(pIC->hCandInfo) != 0, "hCandInfo size is 0\n"); 109 ok(ImmGetIMCCSize(pIC->hGuideLine) != 0, "hGuideLine size is 0\n"); 110 ok(ImmGetIMCCSize(pIC->hPrivate) != 0, "hPrivate size is 0\n"); 111 ok(ImmGetIMCCSize(pIC->hMsgBuf) != 0, "hMsgBuf size is 0\n"); 112 } 113 else 114 { 115 skip("No pIC\n"); 116 } 117 ImmUnlockIMC(hNewIMC); 118 ok(ImmReleaseContext(hwndEdit, hIMC), "ImmReleaseContext failed\n"); 119 120 ok(hIMC1 == hIMC2, "hIMC1 = %p, expected %p\n", hIMC1, hIMC2); 121 122 /* ImmAssociateContext */ 123 hNewIMC = ImmCreateContext(); 124 ok(hNewIMC != NULL, "ImmCreateContext failed \n"); 125 pIC = ImmLockIMC(hNewIMC); 126 ok(pIC != NULL, "ImmLockIMC failed\n"); 127 ImmUnlockIMC(hNewIMC); 128 hOldIMC = ImmAssociateContext(hwndEdit, hNewIMC); 129 ok(hNewIMC != hOldIMC, "hNewIMC = %p, expected not %p\n", hNewIMC, hOldIMC); 130 hIMC = ImmGetContext(hwndEdit); 131 ok(hIMC == hNewIMC, "hIMC = %p, expected %p\n", hIMC, hNewIMC); 132 ok(hIMC != hOldIMC, "hIMC = %p, expected not %p\n", hIMC, hOldIMC); 133 pIC = ImmLockIMC(hNewIMC); 134 ok(pIC != NULL, "ImmLockIMC failed\n"); 135 if (pIC != NULL) 136 { 137 ok(pIC->hWnd == NULL, "pIC->hWnd = %p\n", pIC->hWnd); 138 ok(ImmGetIMCCSize(pIC->hCompStr) != 0, "hCompStr size is 0\n"); 139 ok(ImmGetIMCCSize(pIC->hCandInfo) != 0, "hCandInfo size is 0\n"); 140 ok(ImmGetIMCCSize(pIC->hGuideLine) != 0, "hGuideLine size is 0\n"); 141 ok(ImmGetIMCCSize(pIC->hPrivate) != 0, "hPrivate size is 0\n"); 142 ok(ImmGetIMCCSize(pIC->hMsgBuf) != 0, "hMsgBuf size is 0\n"); 143 } 144 else 145 { 146 skip("No pIC\n"); 147 } 148 ImmUnlockIMC(hNewIMC); 149 ok(ImmReleaseContext(hwndEdit, hIMC), "ImmReleaseContext failed\n"); 150 ok(ImmDestroyContext(hNewIMC), "ImmDestroyContext failed\n"); 151 152 DestroyWindow(hwndEdit); 153 DestroyWindow(hwndStatic); 154 } 155 156 static void Test2(void) 157 { 158 static const LPCSTR apszClasses[] = 159 { 160 "BUTTON", 161 "COMBOBOX", 162 "EDIT", 163 "LISTBOX", 164 "SCROLLBAR", 165 "STATIC" 166 }; 167 size_t i; 168 HIMC hIMC; 169 HWND hwnd; 170 171 for (i = 0; i < _countof(apszClasses); ++i) 172 { 173 LPCSTR pszClass = apszClasses[i]; 174 hwnd = CreateWindowA(pszClass, NULL, WS_VISIBLE, 0, 0, 0, 0, NULL, NULL, 175 GetModuleHandle(NULL), NULL); 176 ok(hwnd != NULL, "CreateWindow(%s) failed\n", pszClass); 177 178 hIMC = ImmGetContext(hwnd); 179 180 if (lstrcmpiA(pszClass, "BUTTON") == 0) 181 ok(hIMC == NULL, "hIMC was %p\n", hIMC); 182 else 183 ok(hIMC != NULL, "hIMC was NULL\n"); 184 185 ImmReleaseContext(hwnd, hIMC); 186 187 DestroyWindow(hwnd); 188 } 189 } 190 191 START_TEST(himc) 192 { 193 Test1(); 194 Test2(); 195 } 196