2 * Unit tests for ITfInputProcessor
4 * Copyright 2009 Aric Stewart, CodeWeavers
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
24 #include "wine/test.h"
33 static ITfInputProcessorProfiles* g_ipp;
34 static LANGID gLangid;
35 static ITfCategoryMgr * g_cm = NULL;
36 static ITfThreadMgr* g_tm = NULL;
37 static ITfDocumentMgr *g_dm = NULL;
38 static TfClientId cid = 0;
39 static TfClientId tid = 0;
41 #define SINK_UNEXPECTED 0
42 #define SINK_EXPECTED 1
45 static BOOL test_ShouldActivate = FALSE;
46 static BOOL test_ShouldDeactivate = FALSE;
48 static DWORD tmSinkCookie;
49 static DWORD tmSinkRefCount;
50 static ITfDocumentMgr *test_CurrentFocus = NULL;
51 static ITfDocumentMgr *test_PrevFocus = NULL;
52 static INT test_OnSetFocus = SINK_UNEXPECTED;
53 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
54 static INT test_OnPushContext = SINK_UNEXPECTED;
55 static INT test_OnPopContext = SINK_UNEXPECTED;
56 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
58 HRESULT RegisterTextService(REFCLSID rclsid);
59 HRESULT UnregisterTextService();
60 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut);
61 HRESULT TextStoreACP_Constructor(IUnknown **ppOut);
63 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
64 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
65 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
66 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
67 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
68 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
69 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
70 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
71 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
72 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
75 static HRESULT initialize(void)
79 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
80 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
82 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
83 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
85 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
86 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
90 static void cleanup(void)
93 ITfInputProcessorProfiles_Release(g_ipp);
95 ITfCategoryMgr_Release(g_cm);
97 ITfThreadMgr_Release(g_tm);
101 static void test_Register(void)
105 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
106 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
108 hr = RegisterTextService(&CLSID_FakeService);
109 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
110 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
111 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
112 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
113 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
116 static void test_Unregister(void)
119 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
120 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
121 UnregisterTextService();
124 static void test_EnumInputProcessorInfo(void)
129 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
133 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
135 if(IsEqualGUID(&g,&CLSID_FakeService))
139 ok(found,"Did not find registered text service\n");
142 static void test_EnumLanguageProfiles(void)
145 IEnumTfLanguageProfiles *ppEnum;
146 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
148 TF_LANGUAGEPROFILE profile;
149 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
151 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
154 ok(profile.langid == gLangid, "LangId Incorrect\n");
155 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
156 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
160 ok(found,"Registered text service not found\n");
163 static void test_RegisterCategory(void)
166 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
167 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
168 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
169 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
172 static void test_UnregisterCategory(void)
175 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
176 todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
177 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
178 todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
181 static void test_FindClosestCategory(void)
185 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
187 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
188 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
189 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
191 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
192 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
193 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
195 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
196 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
197 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
200 static void test_Enable(void)
203 BOOL enabled = FALSE;
205 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
206 ok(SUCCEEDED(hr),"Failed to enable text service\n");
207 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
208 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
209 ok(enabled == TRUE,"enabled state incorrect\n");
212 static void test_Disable(void)
216 trace("Disabling\n");
217 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
218 ok(SUCCEEDED(hr),"Failed to disable text service\n");
221 static void test_ThreadMgrAdviseSinks(void)
223 ITfSource *source = NULL;
227 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
228 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
232 ThreadMgrEventSink_Constructor(&sink);
236 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
237 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
238 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
240 /* Advising the sink adds a ref, Relesing here lets the object be deleted
243 IUnknown_Release(sink);
244 ITfSource_Release(source);
247 static void test_ThreadMgrUnadviseSinks(void)
249 ITfSource *source = NULL;
252 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
253 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
258 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
259 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
260 ITfSource_Release(source);
263 /**********************************************************************
265 **********************************************************************/
266 typedef struct tagKeyEventSink
268 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
272 static void KeyEventSink_Destructor(KeyEventSink *This)
274 HeapFree(GetProcessHeap(),0,This);
277 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
279 KeyEventSink *This = (KeyEventSink *)iface;
282 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
289 IUnknown_AddRef(iface);
293 return E_NOINTERFACE;
296 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
298 KeyEventSink *This = (KeyEventSink *)iface;
299 return InterlockedIncrement(&This->refCount);
302 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
304 KeyEventSink *This = (KeyEventSink *)iface;
307 ret = InterlockedDecrement(&This->refCount);
309 KeyEventSink_Destructor(This);
313 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
316 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
317 test_KEV_OnSetFocus = SINK_FIRED;
321 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
322 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
328 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
329 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
335 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
336 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
342 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
343 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
349 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
350 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
356 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
358 KeyEventSink_QueryInterface,
360 KeyEventSink_Release,
362 KeyEventSink_OnSetFocus,
363 KeyEventSink_OnTestKeyDown,
364 KeyEventSink_OnTestKeyUp,
365 KeyEventSink_OnKeyDown,
366 KeyEventSink_OnKeyUp,
367 KeyEventSink_OnPreservedKey
370 HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
374 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
376 return E_OUTOFMEMORY;
378 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
381 *ppOut = (ITfKeyEventSink*)This;
386 static void test_KeystrokeMgr(void)
388 ITfKeystrokeMgr *keymgr= NULL;
390 TF_PRESERVEDKEY tfpk;
392 ITfKeyEventSink *sink;
394 KeyEventSink_Constructor(&sink);
396 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
397 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
400 tfpk.uModifiers = TF_MOD_SHIFT;
402 test_KEV_OnSetFocus = SINK_EXPECTED;
403 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
404 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
405 todo_wine ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
407 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
408 todo_wine ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
410 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
411 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
413 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
414 todo_wine ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded \n");
417 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
418 todo_wine ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
419 if (hr == S_OK) todo_wine ok(preserved == TRUE,"misreporting preserved key\n");
421 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
422 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
424 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
425 todo_wine ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
426 if (hr == S_FALSE) todo_wine ok(preserved == FALSE,"misreporting preserved key\n");
428 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
429 todo_wine ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
431 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
432 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
434 ITfKeystrokeMgr_Release(keymgr);
435 ITfKeyEventSink_Release(sink);
438 static void test_Activate(void)
442 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
443 todo_wine ok(SUCCEEDED(hr),"Failed to Activate text service\n");
446 static int inline check_context_refcount(ITfContext *iface)
448 IUnknown_AddRef(iface);
449 return IUnknown_Release(iface);
452 static void test_startSession(void)
457 ITfDocumentMgr *dmtest;
458 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
461 test_ShouldActivate = TRUE;
462 ITfThreadMgr_Activate(g_tm,&cid);
463 todo_wine ok(cid != tid,"TextService id mistakenly matches Client id\n");
465 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
466 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
468 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
469 ok(SUCCEEDED(hr),"GetFocus Failed\n");
470 ok(dmtest == NULL,"Initial focus not null\n");
472 test_CurrentFocus = g_dm;
473 test_PrevFocus = NULL;
474 test_OnSetFocus = SINK_EXPECTED;
475 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
476 ok(SUCCEEDED(hr),"SetFocus Failed\n");
477 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
478 test_OnSetFocus = SINK_UNEXPECTED;
480 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
481 ok(SUCCEEDED(hr),"GetFocus Failed\n");
482 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
484 cnt = ITfDocumentMgr_Release(g_dm);
485 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
487 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
488 ok(SUCCEEDED(hr),"GetFocus Failed\n");
489 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
491 TextStoreACP_Constructor((IUnknown**)&ts);
493 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
494 ok(SUCCEEDED(hr),"CreateContext Failed\n");
496 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
497 ok(SUCCEEDED(hr),"CreateContext Failed\n");
499 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
500 ok(SUCCEEDED(hr),"CreateContext Failed\n");
502 cnt = check_context_refcount(cxt);
503 test_OnPushContext = SINK_EXPECTED;
504 test_OnInitDocumentMgr = SINK_EXPECTED;
505 hr = ITfDocumentMgr_Push(g_dm, cxt);
506 ok(SUCCEEDED(hr),"Push Failed\n");
507 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
508 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
509 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
511 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
512 ok(SUCCEEDED(hr),"GetTop Failed\n");
513 ok(cxtTest == cxt, "Wrong context on top\n");
514 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
515 cnt = ITfContext_Release(cxtTest);
517 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
518 ok(SUCCEEDED(hr),"GetBase Failed\n");
519 ok(cxtTest == cxt, "Wrong context on Base\n");
520 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
521 ITfContext_Release(cxtTest);
523 check_context_refcount(cxt2);
524 test_OnPushContext = SINK_EXPECTED;
525 hr = ITfDocumentMgr_Push(g_dm, cxt2);
526 ok(SUCCEEDED(hr),"Push Failed\n");
527 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
529 cnt = check_context_refcount(cxt2);
530 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
531 ok(SUCCEEDED(hr),"GetTop Failed\n");
532 ok(cxtTest == cxt2, "Wrong context on top\n");
533 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
534 ITfContext_Release(cxtTest);
536 cnt = check_context_refcount(cxt);
537 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
538 ok(SUCCEEDED(hr),"GetBase Failed\n");
539 ok(cxtTest == cxt, "Wrong context on Base\n");
540 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
541 ITfContext_Release(cxtTest);
543 cnt = check_context_refcount(cxt3);
544 hr = ITfDocumentMgr_Push(g_dm, cxt3);
545 ok(!SUCCEEDED(hr),"Push Succeeded\n");
546 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
548 cnt = check_context_refcount(cxt2);
549 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
550 ok(SUCCEEDED(hr),"GetTop Failed\n");
551 ok(cxtTest == cxt2, "Wrong context on top\n");
552 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
553 ITfContext_Release(cxtTest);
555 cnt = check_context_refcount(cxt);
556 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
557 ok(SUCCEEDED(hr),"GetBase Failed\n");
558 ok(cxtTest == cxt, "Wrong context on Base\n");
559 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
560 ITfContext_Release(cxtTest);
562 cnt = check_context_refcount(cxt2);
563 test_OnPopContext = SINK_EXPECTED;
564 hr = ITfDocumentMgr_Pop(g_dm, 0);
565 ok(SUCCEEDED(hr),"Pop Failed\n");
566 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
567 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
569 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
570 ok(SUCCEEDED(hr),"GetTop Failed\n");
571 ok(cxtTest == cxt, "Wrong context on top\n");
572 ITfContext_Release(cxtTest);
574 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
575 ok(SUCCEEDED(hr),"GetBase Failed\n");
576 ok(cxtTest == cxt, "Wrong context on base\n");
577 ITfContext_Release(cxtTest);
579 hr = ITfDocumentMgr_Pop(g_dm, 0);
580 ok(!SUCCEEDED(hr),"Pop Succeeded\n");
582 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
583 ok(SUCCEEDED(hr),"GetTop Failed\n");
584 ok(cxtTest == cxt, "Wrong context on top\n");
585 ITfContext_Release(cxtTest);
587 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
588 ok(SUCCEEDED(hr),"GetBase Failed\n");
589 ok(cxtTest == cxt, "Wrong context on base\n");
590 ITfContext_Release(cxtTest);
592 ITfContext_Release(cxt);
593 ITfContext_Release(cxt2);
594 ITfContext_Release(cxt3);
597 static void test_endSession(void)
599 test_ShouldDeactivate = TRUE;
600 test_CurrentFocus = NULL;
601 test_PrevFocus = g_dm;
602 test_OnSetFocus = SINK_EXPECTED;
603 ITfThreadMgr_Deactivate(g_tm);
604 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
605 test_OnSetFocus = SINK_UNEXPECTED;
608 START_TEST(inputprocessor)
610 if (SUCCEEDED(initialize()))
612 gLangid = GetUserDefaultLCID();
614 test_RegisterCategory();
615 test_EnumInputProcessorInfo();
617 test_ThreadMgrAdviseSinks();
622 test_EnumLanguageProfiles();
623 test_FindClosestCategory();
625 test_ThreadMgrUnadviseSinks();
626 test_UnregisterCategory();
630 skip("Unable to create InputProcessor\n");
634 /**********************************************************************
636 **********************************************************************/
637 typedef struct tagTextStoreACP
639 const ITextStoreACPVtbl *TextStoreACPVtbl;
643 static void TextStoreACP_Destructor(TextStoreACP *This)
645 HeapFree(GetProcessHeap(),0,This);
648 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
650 TextStoreACP *This = (TextStoreACP *)iface;
653 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
660 IUnknown_AddRef(iface);
664 return E_NOINTERFACE;
667 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
669 TextStoreACP *This = (TextStoreACP *)iface;
670 return InterlockedIncrement(&This->refCount);
673 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
675 TextStoreACP *This = (TextStoreACP *)iface;
678 ret = InterlockedDecrement(&This->refCount);
680 TextStoreACP_Destructor(This);
684 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
685 REFIID riid, IUnknown *punk, DWORD dwMask)
691 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
697 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
698 DWORD dwLockFlags, HRESULT *phrSession)
703 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
709 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
710 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
716 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
717 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
722 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
723 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
728 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
729 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
730 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
731 ULONG *pcRunInfoRet, LONG *pacpNext)
736 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
737 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
738 ULONG cch, TS_TEXTCHANGE *pChange)
743 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
744 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
749 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
750 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
755 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
756 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
761 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
762 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
763 TS_TEXTCHANGE *pChange)
768 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
769 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
770 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
775 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
776 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
777 TS_TEXTCHANGE *pChange)
782 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
783 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
788 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
789 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
795 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
796 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
802 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
803 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
804 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
809 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
810 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
815 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
821 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
822 TsViewCookie *pvcView)
827 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
828 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
834 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
835 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
841 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
842 TsViewCookie vcView, RECT *prc)
847 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
848 TsViewCookie vcView, HWND *phwnd)
854 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
856 TextStoreACP_QueryInterface,
858 TextStoreACP_Release,
860 TextStoreACP_AdviseSink,
861 TextStoreACP_UnadviseSink,
862 TextStoreACP_RequestLock,
863 TextStoreACP_GetStatus,
864 TextStoreACP_QueryInsert,
865 TextStoreACP_GetSelection,
866 TextStoreACP_SetSelection,
867 TextStoreACP_GetText,
868 TextStoreACP_SetText,
869 TextStoreACP_GetFormattedText,
870 TextStoreACP_GetEmbedded,
871 TextStoreACP_QueryInsertEmbedded,
872 TextStoreACP_InsertEmbedded,
873 TextStoreACP_InsertTextAtSelection,
874 TextStoreACP_InsertEmbeddedAtSelection,
875 TextStoreACP_RequestSupportedAttrs,
876 TextStoreACP_RequestAttrsAtPosition,
877 TextStoreACP_RequestAttrsTransitioningAtPosition,
878 TextStoreACP_FindNextAttrTransition,
879 TextStoreACP_RetrieveRequestedAttrs,
880 TextStoreACP_GetEndACP,
881 TextStoreACP_GetActiveView,
882 TextStoreACP_GetACPFromPoint,
883 TextStoreACP_GetTextExt,
884 TextStoreACP_GetScreenExt,
888 HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
892 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
894 return E_OUTOFMEMORY;
896 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
899 *ppOut = (IUnknown *)This;
903 /**********************************************************************
904 * ITfThreadMgrEventSink
905 **********************************************************************/
906 typedef struct tagThreadMgrEventSink
908 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
910 } ThreadMgrEventSink;
912 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
914 HeapFree(GetProcessHeap(),0,This);
917 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
919 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
922 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
929 IUnknown_AddRef(iface);
933 return E_NOINTERFACE;
936 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
938 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
939 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
940 return InterlockedIncrement(&This->refCount);
943 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
945 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
948 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
949 ret = InterlockedDecrement(&This->refCount);
951 ThreadMgrEventSink_Destructor(This);
955 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
956 ITfDocumentMgr *pdim)
958 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
959 test_OnInitDocumentMgr = SINK_FIRED;
963 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
964 ITfDocumentMgr *pdim)
970 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
971 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
973 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
974 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
975 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
976 test_OnSetFocus = SINK_FIRED;
980 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
983 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
984 test_OnPushContext = SINK_FIRED;
988 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
991 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
992 test_OnPopContext = SINK_FIRED;
996 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
998 ThreadMgrEventSink_QueryInterface,
999 ThreadMgrEventSink_AddRef,
1000 ThreadMgrEventSink_Release,
1002 ThreadMgrEventSink_OnInitDocumentMgr,
1003 ThreadMgrEventSink_OnUninitDocumentMgr,
1004 ThreadMgrEventSink_OnSetFocus,
1005 ThreadMgrEventSink_OnPushContext,
1006 ThreadMgrEventSink_OnPopContext
1009 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
1011 ThreadMgrEventSink *This;
1013 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
1015 return E_OUTOFMEMORY;
1017 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
1020 *ppOut = (IUnknown *)This;
1025 /********************************************************************************************
1026 * Stub text service for testing
1027 ********************************************************************************************/
1029 static LONG TS_refCount;
1030 static IClassFactory *cf;
1033 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
1035 typedef struct tagClassFactory
1037 const IClassFactoryVtbl *vtbl;
1039 LPFNCONSTRUCTOR ctor;
1042 typedef struct tagTextService
1044 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
1048 static void ClassFactory_Destructor(ClassFactory *This)
1050 HeapFree(GetProcessHeap(),0,This);
1054 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
1057 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
1059 IClassFactory_AddRef(iface);
1064 return E_NOINTERFACE;
1067 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1069 ClassFactory *This = (ClassFactory *)iface;
1070 return InterlockedIncrement(&This->ref);
1073 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1075 ClassFactory *This = (ClassFactory *)iface;
1076 ULONG ret = InterlockedDecrement(&This->ref);
1079 ClassFactory_Destructor(This);
1083 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
1085 ClassFactory *This = (ClassFactory *)iface;
1089 ret = This->ctor(punkOuter, &obj);
1092 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
1093 IUnknown_Release(obj);
1097 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
1100 InterlockedIncrement(&TS_refCount);
1102 InterlockedDecrement(&TS_refCount);
1107 static const IClassFactoryVtbl ClassFactoryVtbl = {
1109 ClassFactory_QueryInterface,
1110 ClassFactory_AddRef,
1111 ClassFactory_Release,
1114 ClassFactory_CreateInstance,
1115 ClassFactory_LockServer
1118 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
1120 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
1121 This->vtbl = &ClassFactoryVtbl;
1124 *ppvOut = (LPVOID)This;
1129 static void TextService_Destructor(TextService *This)
1131 HeapFree(GetProcessHeap(),0,This);
1134 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
1136 TextService *This = (TextService *)iface;
1139 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
1146 IUnknown_AddRef(iface);
1150 return E_NOINTERFACE;
1153 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
1155 TextService *This = (TextService *)iface;
1156 return InterlockedIncrement(&This->refCount);
1159 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
1161 TextService *This = (TextService *)iface;
1164 ret = InterlockedDecrement(&This->refCount);
1166 TextService_Destructor(This);
1170 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
1171 ITfThreadMgr *ptim, TfClientId id)
1173 trace("TextService_Activate\n");
1174 ok(test_ShouldActivate,"Activation came unexpectedly\n");
1179 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
1181 trace("TextService_Deactivate\n");
1182 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
1186 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
1188 TextService_QueryInterface,
1190 TextService_Release,
1192 TextService_Activate,
1193 TextService_Deactivate
1196 HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
1200 return CLASS_E_NOAGGREGATION;
1202 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
1204 return E_OUTOFMEMORY;
1206 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
1209 *ppOut = (IUnknown *)This;
1213 HRESULT RegisterTextService(REFCLSID rclsid)
1215 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
1216 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1219 HRESULT UnregisterTextService()
1221 return CoRevokeClassObject(regid);