~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/imm32/tests/imm32.c

Version: ~ [ wine-1.1.9 ] ~ [ wine-1.1.8 ] ~ [ wine-1.1.7 ] ~ [ wine-1.0.1 ] ~ [ wine-1.1.6 ] ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Unit tests for imm32
  3  *
  4  * Copyright (c) 2008 Michael Jung
  5  *
  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.
 10  *
 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.
 15  *
 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
 19  */
 20 
 21 #include <stdio.h>
 22 
 23 #include "wine/test.h"
 24 #include "winuser.h"
 25 #include "imm.h"
 26 
 27 #define NUMELEMS(array) (sizeof((array))/sizeof((array)[0]))
 28 
 29 /*
 30  * msgspy - record and analyse message traces sent to a certain window
 31  */
 32 static struct _msg_spy {
 33     HWND         hwnd;
 34     HHOOK        get_msg_hook;
 35     HHOOK        call_wnd_proc_hook;
 36     CWPSTRUCT    msgs[32];
 37     unsigned int i_msg;
 38 } msg_spy;
 39 
 40 static LRESULT CALLBACK get_msg_filter(int nCode, WPARAM wParam, LPARAM lParam)
 41 {
 42     if (HC_ACTION == nCode) {
 43         MSG *msg = (MSG*)lParam;
 44 
 45         if ((msg->hwnd == msg_spy.hwnd) &&
 46             (msg_spy.i_msg < NUMELEMS(msg_spy.msgs)))
 47         {
 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;
 52             msg_spy.i_msg++;
 53         }
 54     }
 55 
 56     return CallNextHookEx(msg_spy.get_msg_hook, nCode, wParam, lParam);
 57 }
 58 
 59 static LRESULT CALLBACK call_wnd_proc_filter(int nCode, WPARAM wParam,
 60                                              LPARAM lParam)
 61 {
 62     if (HC_ACTION == nCode) {
 63         CWPSTRUCT *cwp = (CWPSTRUCT*)lParam;
 64 
 65         if ((cwp->hwnd == msg_spy.hwnd) &&
 66             (msg_spy.i_msg < NUMELEMS(msg_spy.msgs)))
 67         {
 68             memcpy(&msg_spy.msgs[msg_spy.i_msg], cwp, sizeof(msg_spy.msgs[0]));
 69             msg_spy.i_msg++;
 70         }
 71     }
 72 
 73     return CallNextHookEx(msg_spy.call_wnd_proc_hook, nCode, wParam, lParam);
 74 }
 75 
 76 static void msg_spy_pump_msg_queue(void) {
 77     MSG msg;
 78 
 79     while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
 80         TranslateMessage(&msg);
 81         DispatchMessage(&msg);
 82     }
 83 
 84     return;
 85 }
 86 
 87 static void msg_spy_flush_msgs(void) {
 88     msg_spy_pump_msg_queue();
 89     msg_spy.i_msg = 0;
 90 }
 91 
 92 static CWPSTRUCT* msg_spy_find_msg(UINT message) {
 93     int i;
 94 
 95     msg_spy_pump_msg_queue();
 96 
 97     if (msg_spy.i_msg >= NUMELEMS(msg_spy.msgs))
 98         fprintf(stdout, "%s:%d: msg_spy: message buffer overflow!\n",
 99                 __FILE__, __LINE__);
100 
101     for (i = 0; i < msg_spy.i_msg; i++)
102         if (msg_spy.msgs[i].message == message)
103             return &msg_spy.msgs[i];
104 
105     return NULL;
106 }
107 
108 static void msg_spy_init(HWND hwnd) {
109     msg_spy.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());
116     msg_spy.i_msg = 0;
117 
118     msg_spy_flush_msgs();
119 }
120 
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));
127 }
128 
129 /*
130  * imm32 test cases - Issue some IMM commands on a dummy window and analyse the
131  * messages being sent to this window in response.
132  */
133 static const char wndcls[] = "winetest_imm32_wndcls";
134 static HWND hwnd;
135 
136 static int init(void) {
137     WNDCLASSEX wc;
138     HIMC imc;
139 
140     wc.cbSize        = sizeof(WNDCLASSEX);
141     wc.style         = 0;
142     wc.lpfnWndProc   = DefWindowProc;
143     wc.cbClsExtra    = 0;
144     wc.cbWndExtra    = 0;
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);
152 
153     if (!RegisterClassExA(&wc))
154         return 0;
155 
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);
159     if (!hwnd)
160         return 0;
161 
162     imc = ImmGetContext(hwnd);
163     if (!imc)
164     {
165         skip("IME support not implemented\n");
166         return 0;
167     }
168     ImmReleaseContext(hwnd, imc);
169 
170     ShowWindow(hwnd, SW_SHOWNORMAL);
171     UpdateWindow(hwnd);
172 
173     msg_spy_init(hwnd);
174 
175     return 1;
176 }
177 
178 static void cleanup(void) {
179     msg_spy_cleanup();
180     if (hwnd)
181         DestroyWindow(hwnd);
182     UnregisterClass(wndcls, GetModuleHandle(0));
183 }
184 
185 static int test_ImmNotifyIME(void) {
186     static const char string[] = "wine";
187     char resstr[16] = "";
188     HIMC imc;
189     BOOL ret;
190 
191     imc = ImmGetContext(hwnd);
192     msg_spy_flush_msgs();
193 
194     todo_wine
195     {
196         ok(!ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0), "Canceling an "
197            "empty composition string should fail.\n");
198     }
199     ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
200        "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
201        "the composition string being canceled is empty.\n");
202 
203     ImmSetCompositionString(imc, SCS_SETSTR, string, sizeof(string), NULL, 0);
204     msg_spy_flush_msgs();
205 
206     ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0);
207     ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
208        "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
209        "the composition string being canceled is non empty.\n");
210 
211     /* behavior differs between win9x and NT */
212     ret = ImmGetCompositionString(imc, GCS_COMPSTR, resstr, sizeof(resstr));
213     ok(ret || !ret, "You'll never read this.\n");
214 
215     msg_spy_flush_msgs();
216 
217     todo_wine
218     {
219         ok(!ImmNotifyIME(imc, NI_COMPOSITIONSTR, CPS_CANCEL, 0), "Canceling an "
220            "empty composition string should fail.\n");
221     }
222     ok(!msg_spy_find_msg(WM_IME_COMPOSITION), "Windows does not post "
223        "WM_IME_COMPOSITION in response to NI_COMPOSITIONSTR / CPS_CANCEL, if "
224        "the composition string being canceled is empty.\n");
225 
226     msg_spy_flush_msgs();
227     ImmReleaseContext(hwnd, imc);
228 
229     return 0;
230 }
231 
232 static int test_ImmGetCompositionString(void)
233 {
234     HIMC imc;
235     static const WCHAR string[] = {'w','i','n','e',0x65e5,0x672c,0x8a9e};
236     char cstring[20];
237     WCHAR wstring[20];
238     DWORD len;
239     DWORD alen,wlen;
240 
241     imc = ImmGetContext(hwnd);
242     ImmSetCompositionStringW(imc, SCS_SETSTR, string, sizeof(string), NULL,0);
243     alen = ImmGetCompositionStringA(imc, GCS_COMPSTR, cstring, 20);
244     wlen = ImmGetCompositionStringW(imc, GCS_COMPSTR, wstring, 20);
245     /* windows machines without any IME installed just return 0 above */
246     if( alen && wlen)
247     {
248         len = ImmGetCompositionStringW(imc, GCS_COMPATTR, NULL, 0);
249         ok(len*sizeof(WCHAR)==wlen,"GCS_COMPATTR(W) not returning correct count\n");
250         len = ImmGetCompositionStringA(imc, GCS_COMPATTR, NULL, 0);
251         ok(len==alen,"GCS_COMPATTR(A) not returning correct count\n");
252     }
253     ImmReleaseContext(hwnd, imc);
254     return 0;
255 }
256 
257 static int test_ImmIME(void)
258 {
259     HIMC imc;
260 
261     imc = ImmGetContext(hwnd);
262     if (imc)
263     {
264         BOOL rc;
265         rc = ImmConfigureIMEA(imc, NULL, IME_CONFIG_REGISTERWORD, NULL);
266         ok (rc == 0, "ImmConfigureIMEA did not fail\n");
267         rc = ImmConfigureIMEW(imc, NULL, IME_CONFIG_REGISTERWORD, NULL);
268         ok (rc == 0, "ImmConfigureIMEW did not fail\n");
269     }
270     ImmReleaseContext(hwnd,imc);
271     return 0;
272 }
273 
274 START_TEST(imm32) {
275     if (init())
276     {
277         test_ImmNotifyIME();
278         test_ImmGetCompositionString();
279         test_ImmIME();
280     }
281     cleanup();
282 }
283 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.