4 * Copyright (c) 2008 Michael Jung
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/test.h"
27 #define NUMELEMS(array) (sizeof((array))/sizeof((array)[0]))
30 * msgspy - record and analyse message traces sent to a certain window
32 static struct _msg_spy {
35 HHOOK call_wnd_proc_hook;
40 static LRESULT CALLBACK get_msg_filter(int nCode, WPARAM wParam, LPARAM lParam)
42 if (HC_ACTION == nCode) {
43 MSG *msg = (MSG*)lParam;
45 if ((msg->hwnd == msg_spy.hwnd) &&
46 (msg_spy.i_msg < NUMELEMS(msg_spy.msgs)))
48 msg_spy.msgs[msg_spy.i_msg].hwnd = msg->hwnd;
49 msg_spy.msgs[msg_spy.i_msg].message = msg->message;
50 msg_spy.msgs[msg_spy.i_msg].wParam = msg->wParam;
51 msg_spy.msgs[msg_spy.i_msg].lParam = msg->lParam;
56 return CallNextHookEx(msg_spy.get_msg_hook, nCode, wParam, lParam);
59 static LRESULT CALLBACK call_wnd_proc_filter(int nCode, WPARAM wParam,
62 if (HC_ACTION == nCode) {
63 CWPSTRUCT *cwp = (CWPSTRUCT*)lParam;
65 if ((cwp->hwnd == msg_spy.hwnd) &&
66 (msg_spy.i_msg < NUMELEMS(msg_spy.msgs)))
68 memcpy(&msg_spy.msgs[msg_spy.i_msg], cwp, sizeof(msg_spy.msgs[0]));
73 return CallNextHookEx(msg_spy.call_wnd_proc_hook, nCode, wParam, lParam);
76 static void msg_spy_pump_msg_queue(void) {
79 while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
80 TranslateMessage(&msg);
81 DispatchMessage(&msg);
87 static void msg_spy_flush_msgs(void) {
88 msg_spy_pump_msg_queue();
92 static CWPSTRUCT* msg_spy_find_msg(UINT message) {
95 msg_spy_pump_msg_queue();
97 if (msg_spy.i_msg >= NUMELEMS(msg_spy.msgs))
98 fprintf(stdout, "%s:%d: msg_spy: message buffer overflow!\n",
101 for (i = 0; i < msg_spy.i_msg; i++)
102 if (msg_spy.msgs[i].message == message)
103 return &msg_spy.msgs[i];
108 static void msg_spy_init(HWND hwnd) {
110 msg_spy.get_msg_hook =
111 SetWindowsHookEx(WH_GETMESSAGE, get_msg_filter, GetModuleHandle(0),
112 GetCurrentThreadId());
113 msg_spy.call_wnd_proc_hook =
114 SetWindowsHookEx(WH_CALLWNDPROC, call_wnd_proc_filter,
115 GetModuleHandle(0), GetCurrentThreadId());
118 msg_spy_flush_msgs();
121 static void msg_spy_cleanup() {
122 if (msg_spy.get_msg_hook)
123 UnhookWindowsHookEx(msg_spy.get_msg_hook);
124 if (msg_spy.call_wnd_proc_hook)
125 UnhookWindowsHookEx(msg_spy.call_wnd_proc_hook);
126 memset(&msg_spy, 0, sizeof(msg_spy));
130 * imm32 test cases - Issue some IMM commands on a dummy window and analyse the
131 * messages being sent to this window in response.
133 static const char wndcls[] = "winetest_imm32_wndcls";
136 static int init(void) {
140 wc.cbSize = sizeof(WNDCLASSEX);
142 wc.lpfnWndProc = DefWindowProc;
145 wc.hInstance = GetModuleHandle(0);
146 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
147 wc.hCursor = LoadCursor(NULL, IDC_ARROW);
148 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
149 wc.lpszMenuName = NULL;
150 wc.lpszClassName = wndcls;
151 wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
153 if (!RegisterClassExA(&wc))
156 hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, wndcls, "Wine imm32.dll test",
157 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
158 240, 120, NULL, NULL, GetModuleHandle(0), NULL);
162 imc = ImmGetContext(hwnd);
165 win_skip("IME support not implemented\n");
168 ImmReleaseContext(hwnd, imc);
170 ShowWindow(hwnd, SW_SHOWNORMAL);
178 static void cleanup(void) {
182 UnregisterClass(wndcls, GetModuleHandle(0));
185 static void test_ImmNotifyIME(void) {
186 static const char string[] = "wine";
187 char resstr[16] = "";
191 imc = ImmGetContext(hwnd);
192 msg_spy_flush_msgs();
194 ret = ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
198 broken(ret), /* Vista and W2K8 */
199 "Canceling an empty composition string should fail.\n");
201 ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
202 "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
203 "the composition string being canceled is empty.\n");
205 ImmSetCompositionString(imc, SCS_SETSTR, string, sizeof(string), NULL, 0);
206 msg_spy_flush_msgs();
208 ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
209 ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
210 "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
211 "the composition string being canceled is non empty.\n");
213 /* behavior differs between win9x and NT */
214 ret = ImmGetCompositionString(imc, GCS_COMPSTR, resstr, sizeof(resstr));
215 ok(!ret, "After being cancelled the composition string is empty.\n");
217 msg_spy_flush_msgs();
219 ret = ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
223 broken(ret), /* Vista and W2K8 */
224 "Canceling an empty composition string should fail.\n");
226 ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
227 "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
228 "the composition string being canceled is empty.\n");
230 msg_spy_flush_msgs();
231 ImmReleaseContext(hwnd, imc);
234 static void test_ImmGetCompositionString(void)
237 static const WCHAR string[] = {'w','i','n','e',0x65e5,0x672c,0x8a9e};
243 imc = ImmGetContext(hwnd);
244 ImmSetCompositionStringW(imc, SCS_SETSTR, string, sizeof(string), NULL,0);
245 alen = ImmGetCompositionStringA(imc, GCS_COMPSTR, cstring, 20);
246 wlen = ImmGetCompositionStringW(imc, GCS_COMPSTR, wstring, 20);
247 /* windows machines without any IME installed just return 0 above */
250 len = ImmGetCompositionStringW(imc, GCS_COMPATTR, NULL, 0);
251 ok(len*sizeof(WCHAR)==wlen,"GCS_COMPATTR(W) not returning correct count\n");
252 len = ImmGetCompositionStringA(imc, GCS_COMPATTR, NULL, 0);
253 ok(len==alen,"GCS_COMPATTR(A) not returning correct count\n");
255 ImmReleaseContext(hwnd, imc);
258 static void test_ImmSetCompositionString(void)
263 SetLastError(0xdeadbeef);
264 imc = ImmGetContext(hwnd);
265 ok(imc != 0, "ImmGetContext() failed. Last error: %u\n", GetLastError());
269 ret = ImmSetCompositionStringW(imc, SCS_SETSTR, NULL, 0, NULL, 0);
272 broken(ret), /* Vista and W2K8 */
273 "ImmSetCompositionStringW() succeeded.\n");
275 ret = ImmSetCompositionStringW(imc, SCS_SETSTR | SCS_CHANGEATTR,
278 ok(!ret, "ImmSetCompositionStringW() succeeded.\n");
280 ret = ImmSetCompositionStringW(imc, SCS_SETSTR | SCS_CHANGECLAUSE,
283 ok(!ret, "ImmSetCompositionStringW() succeeded.\n");
285 ret = ImmSetCompositionStringW(imc, SCS_CHANGEATTR | SCS_CHANGECLAUSE,
288 ok(!ret, "ImmSetCompositionStringW() succeeded.\n");
290 ret = ImmSetCompositionStringW(imc, SCS_SETSTR | SCS_CHANGEATTR | SCS_CHANGECLAUSE,
293 ok(!ret, "ImmSetCompositionStringW() succeeded.\n");
295 ImmReleaseContext(hwnd, imc);
298 static void test_ImmIME(void)
302 imc = ImmGetContext(hwnd);
306 rc = ImmConfigureIMEA(imc, NULL, IME_CONFIG_REGISTERWORD, NULL);
307 ok (rc == 0, "ImmConfigureIMEA did not fail\n");
308 rc = ImmConfigureIMEW(imc, NULL, IME_CONFIG_REGISTERWORD, NULL);
309 ok (rc == 0, "ImmConfigureIMEW did not fail\n");
311 ImmReleaseContext(hwnd,imc);
318 test_ImmGetCompositionString();
319 test_ImmSetCompositionString();