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;
57 HRESULT RegisterTextService(REFCLSID rclsid);
58 HRESULT UnregisterTextService();
59 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut);
60 HRESULT TextStoreACP_Constructor(IUnknown **ppOut);
62 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
63 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
64 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
65 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
66 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
67 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
68 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
69 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
70 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
71 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
74 static HRESULT initialize(void)
78 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
79 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
81 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
82 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
84 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
85 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
89 static void cleanup(void)
92 ITfInputProcessorProfiles_Release(g_ipp);
94 ITfCategoryMgr_Release(g_cm);
96 ITfThreadMgr_Release(g_tm);
100 static void test_Register(void)
104 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
105 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
107 hr = RegisterTextService(&CLSID_FakeService);
108 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
109 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
110 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
111 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
112 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
115 static void test_Unregister(void)
118 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
119 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
120 UnregisterTextService();
123 static void test_EnumInputProcessorInfo(void)
128 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
132 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
134 if(IsEqualGUID(&g,&CLSID_FakeService))
138 ok(found,"Did not find registered text service\n");
141 static void test_EnumLanguageProfiles(void)
144 IEnumTfLanguageProfiles *ppEnum;
145 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
147 TF_LANGUAGEPROFILE profile;
148 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
150 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
153 ok(profile.langid == gLangid, "LangId Incorrect\n");
154 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
155 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
159 ok(found,"Registered text service not found\n");
162 static void test_RegisterCategory(void)
165 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
166 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
167 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
168 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
171 static void test_UnregisterCategory(void)
174 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
175 todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
176 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
177 todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
180 static void test_FindClosestCategory(void)
184 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
186 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
187 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
188 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
190 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
191 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
192 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
194 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
195 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
196 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
199 static void test_Enable(void)
202 BOOL enabled = FALSE;
204 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
205 ok(SUCCEEDED(hr),"Failed to enable text service\n");
206 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
207 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
208 ok(enabled == TRUE,"enabled state incorrect\n");
211 static void test_Disable(void)
215 trace("Disabling\n");
216 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
217 ok(SUCCEEDED(hr),"Failed to disable text service\n");
220 static void test_ThreadMgrAdviseSinks(void)
222 ITfSource *source = NULL;
226 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
227 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
231 ThreadMgrEventSink_Constructor(&sink);
235 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
236 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
237 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
239 /* Advising the sink adds a ref, Relesing here lets the object be deleted
242 IUnknown_Release(sink);
243 ITfSource_Release(source);
246 static void test_ThreadMgrUnadviseSinks(void)
248 ITfSource *source = NULL;
251 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
252 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
257 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
258 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
259 ITfSource_Release(source);
262 static void test_KeystrokeMgr(void)
264 ITfKeystrokeMgr *keymgr= NULL;
266 TF_PRESERVEDKEY tfpk;
268 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
269 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
272 tfpk.uModifiers = TF_MOD_SHIFT;
274 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
275 todo_wine ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
277 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
278 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
280 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
281 todo_wine ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded \n");
283 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
284 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
286 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
287 todo_wine ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
289 ITfKeystrokeMgr_Release(keymgr);
292 static void test_Activate(void)
296 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
297 todo_wine ok(SUCCEEDED(hr),"Failed to Activate text service\n");
300 static int inline check_context_refcount(ITfContext *iface)
302 IUnknown_AddRef(iface);
303 return IUnknown_Release(iface);
306 static void test_startSession(void)
311 ITfDocumentMgr *dmtest;
312 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
315 test_ShouldActivate = TRUE;
316 ITfThreadMgr_Activate(g_tm,&cid);
317 todo_wine ok(cid != tid,"TextService id mistakenly matches Client id\n");
319 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
320 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
322 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
323 ok(SUCCEEDED(hr),"GetFocus Failed\n");
324 ok(dmtest == NULL,"Initial focus not null\n");
326 test_CurrentFocus = g_dm;
327 test_PrevFocus = NULL;
328 test_OnSetFocus = SINK_EXPECTED;
329 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
330 ok(SUCCEEDED(hr),"SetFocus Failed\n");
331 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
332 test_OnSetFocus = SINK_UNEXPECTED;
334 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
335 ok(SUCCEEDED(hr),"GetFocus Failed\n");
336 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
338 cnt = ITfDocumentMgr_Release(g_dm);
339 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
341 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
342 ok(SUCCEEDED(hr),"GetFocus Failed\n");
343 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
345 TextStoreACP_Constructor((IUnknown**)&ts);
347 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
348 ok(SUCCEEDED(hr),"CreateContext Failed\n");
350 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
351 ok(SUCCEEDED(hr),"CreateContext Failed\n");
353 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
354 ok(SUCCEEDED(hr),"CreateContext Failed\n");
356 cnt = check_context_refcount(cxt);
357 test_OnPushContext = SINK_EXPECTED;
358 test_OnInitDocumentMgr = SINK_EXPECTED;
359 hr = ITfDocumentMgr_Push(g_dm, cxt);
360 ok(SUCCEEDED(hr),"Push Failed\n");
361 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
362 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
363 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
365 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
366 ok(SUCCEEDED(hr),"GetTop Failed\n");
367 ok(cxtTest == cxt, "Wrong context on top\n");
368 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
369 cnt = ITfContext_Release(cxtTest);
371 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
372 ok(SUCCEEDED(hr),"GetBase Failed\n");
373 ok(cxtTest == cxt, "Wrong context on Base\n");
374 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
375 ITfContext_Release(cxtTest);
377 check_context_refcount(cxt2);
378 test_OnPushContext = SINK_EXPECTED;
379 hr = ITfDocumentMgr_Push(g_dm, cxt2);
380 ok(SUCCEEDED(hr),"Push Failed\n");
381 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
383 cnt = check_context_refcount(cxt2);
384 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
385 ok(SUCCEEDED(hr),"GetTop Failed\n");
386 ok(cxtTest == cxt2, "Wrong context on top\n");
387 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
388 ITfContext_Release(cxtTest);
390 cnt = check_context_refcount(cxt);
391 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
392 ok(SUCCEEDED(hr),"GetBase Failed\n");
393 ok(cxtTest == cxt, "Wrong context on Base\n");
394 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
395 ITfContext_Release(cxtTest);
397 cnt = check_context_refcount(cxt3);
398 hr = ITfDocumentMgr_Push(g_dm, cxt3);
399 ok(!SUCCEEDED(hr),"Push Succeeded\n");
400 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
402 cnt = check_context_refcount(cxt2);
403 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
404 ok(SUCCEEDED(hr),"GetTop Failed\n");
405 ok(cxtTest == cxt2, "Wrong context on top\n");
406 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
407 ITfContext_Release(cxtTest);
409 cnt = check_context_refcount(cxt);
410 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
411 ok(SUCCEEDED(hr),"GetBase Failed\n");
412 ok(cxtTest == cxt, "Wrong context on Base\n");
413 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
414 ITfContext_Release(cxtTest);
416 cnt = check_context_refcount(cxt2);
417 test_OnPopContext = SINK_EXPECTED;
418 hr = ITfDocumentMgr_Pop(g_dm, 0);
419 ok(SUCCEEDED(hr),"Pop Failed\n");
420 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
421 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
423 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
424 ok(SUCCEEDED(hr),"GetTop Failed\n");
425 ok(cxtTest == cxt, "Wrong context on top\n");
426 ITfContext_Release(cxtTest);
428 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
429 ok(SUCCEEDED(hr),"GetBase Failed\n");
430 ok(cxtTest == cxt, "Wrong context on base\n");
431 ITfContext_Release(cxtTest);
433 hr = ITfDocumentMgr_Pop(g_dm, 0);
434 ok(!SUCCEEDED(hr),"Pop Succeeded\n");
436 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
437 ok(SUCCEEDED(hr),"GetTop Failed\n");
438 ok(cxtTest == cxt, "Wrong context on top\n");
439 ITfContext_Release(cxtTest);
441 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
442 ok(SUCCEEDED(hr),"GetBase Failed\n");
443 ok(cxtTest == cxt, "Wrong context on base\n");
444 ITfContext_Release(cxtTest);
446 ITfContext_Release(cxt);
447 ITfContext_Release(cxt2);
448 ITfContext_Release(cxt3);
451 static void test_endSession(void)
453 test_ShouldDeactivate = TRUE;
454 test_CurrentFocus = NULL;
455 test_PrevFocus = g_dm;
456 test_OnSetFocus = SINK_EXPECTED;
457 ITfThreadMgr_Deactivate(g_tm);
458 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
459 test_OnSetFocus = SINK_UNEXPECTED;
462 START_TEST(inputprocessor)
464 if (SUCCEEDED(initialize()))
466 gLangid = GetUserDefaultLCID();
468 test_RegisterCategory();
469 test_EnumInputProcessorInfo();
471 test_ThreadMgrAdviseSinks();
476 test_EnumLanguageProfiles();
477 test_FindClosestCategory();
479 test_ThreadMgrUnadviseSinks();
480 test_UnregisterCategory();
484 skip("Unable to create InputProcessor\n");
488 /**********************************************************************
490 **********************************************************************/
491 typedef struct tagTextStoreACP
493 const ITextStoreACPVtbl *TextStoreACPVtbl;
497 static void TextStoreACP_Destructor(TextStoreACP *This)
499 HeapFree(GetProcessHeap(),0,This);
502 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
504 TextStoreACP *This = (TextStoreACP *)iface;
507 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
514 IUnknown_AddRef(iface);
518 return E_NOINTERFACE;
521 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
523 TextStoreACP *This = (TextStoreACP *)iface;
524 return InterlockedIncrement(&This->refCount);
527 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
529 TextStoreACP *This = (TextStoreACP *)iface;
532 ret = InterlockedDecrement(&This->refCount);
534 TextStoreACP_Destructor(This);
538 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
539 REFIID riid, IUnknown *punk, DWORD dwMask)
545 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
551 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
552 DWORD dwLockFlags, HRESULT *phrSession)
557 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
563 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
564 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
570 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
571 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
576 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
577 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
582 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
583 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
584 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
585 ULONG *pcRunInfoRet, LONG *pacpNext)
590 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
591 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
592 ULONG cch, TS_TEXTCHANGE *pChange)
597 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
598 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
603 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
604 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
609 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
610 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
615 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
616 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
617 TS_TEXTCHANGE *pChange)
622 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
623 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
624 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
629 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
630 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
631 TS_TEXTCHANGE *pChange)
636 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
637 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
642 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
643 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
649 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
650 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
656 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
657 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
658 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
663 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
664 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
669 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
675 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
676 TsViewCookie *pvcView)
681 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
682 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
688 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
689 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
695 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
696 TsViewCookie vcView, RECT *prc)
701 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
702 TsViewCookie vcView, HWND *phwnd)
708 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
710 TextStoreACP_QueryInterface,
712 TextStoreACP_Release,
714 TextStoreACP_AdviseSink,
715 TextStoreACP_UnadviseSink,
716 TextStoreACP_RequestLock,
717 TextStoreACP_GetStatus,
718 TextStoreACP_QueryInsert,
719 TextStoreACP_GetSelection,
720 TextStoreACP_SetSelection,
721 TextStoreACP_GetText,
722 TextStoreACP_SetText,
723 TextStoreACP_GetFormattedText,
724 TextStoreACP_GetEmbedded,
725 TextStoreACP_QueryInsertEmbedded,
726 TextStoreACP_InsertEmbedded,
727 TextStoreACP_InsertTextAtSelection,
728 TextStoreACP_InsertEmbeddedAtSelection,
729 TextStoreACP_RequestSupportedAttrs,
730 TextStoreACP_RequestAttrsAtPosition,
731 TextStoreACP_RequestAttrsTransitioningAtPosition,
732 TextStoreACP_FindNextAttrTransition,
733 TextStoreACP_RetrieveRequestedAttrs,
734 TextStoreACP_GetEndACP,
735 TextStoreACP_GetActiveView,
736 TextStoreACP_GetACPFromPoint,
737 TextStoreACP_GetTextExt,
738 TextStoreACP_GetScreenExt,
742 HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
746 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
748 return E_OUTOFMEMORY;
750 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
753 *ppOut = (IUnknown *)This;
757 /**********************************************************************
758 * ITfThreadMgrEventSink
759 **********************************************************************/
760 typedef struct tagThreadMgrEventSink
762 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
764 } ThreadMgrEventSink;
766 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
768 HeapFree(GetProcessHeap(),0,This);
771 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
773 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
776 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
783 IUnknown_AddRef(iface);
787 return E_NOINTERFACE;
790 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
792 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
793 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
794 return InterlockedIncrement(&This->refCount);
797 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
799 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
802 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
803 ret = InterlockedDecrement(&This->refCount);
805 ThreadMgrEventSink_Destructor(This);
809 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
810 ITfDocumentMgr *pdim)
812 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
813 test_OnInitDocumentMgr = SINK_FIRED;
817 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
818 ITfDocumentMgr *pdim)
824 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
825 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
827 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
828 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
829 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
830 test_OnSetFocus = SINK_FIRED;
834 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
837 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
838 test_OnPushContext = SINK_FIRED;
842 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
845 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
846 test_OnPopContext = SINK_FIRED;
850 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
852 ThreadMgrEventSink_QueryInterface,
853 ThreadMgrEventSink_AddRef,
854 ThreadMgrEventSink_Release,
856 ThreadMgrEventSink_OnInitDocumentMgr,
857 ThreadMgrEventSink_OnUninitDocumentMgr,
858 ThreadMgrEventSink_OnSetFocus,
859 ThreadMgrEventSink_OnPushContext,
860 ThreadMgrEventSink_OnPopContext
863 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
865 ThreadMgrEventSink *This;
867 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
869 return E_OUTOFMEMORY;
871 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
874 *ppOut = (IUnknown *)This;
879 /********************************************************************************************
880 * Stub text service for testing
881 ********************************************************************************************/
883 static LONG TS_refCount;
884 static IClassFactory *cf;
887 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
889 typedef struct tagClassFactory
891 const IClassFactoryVtbl *vtbl;
893 LPFNCONSTRUCTOR ctor;
896 typedef struct tagTextService
898 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
902 static void ClassFactory_Destructor(ClassFactory *This)
904 HeapFree(GetProcessHeap(),0,This);
908 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
911 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
913 IClassFactory_AddRef(iface);
918 return E_NOINTERFACE;
921 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
923 ClassFactory *This = (ClassFactory *)iface;
924 return InterlockedIncrement(&This->ref);
927 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
929 ClassFactory *This = (ClassFactory *)iface;
930 ULONG ret = InterlockedDecrement(&This->ref);
933 ClassFactory_Destructor(This);
937 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
939 ClassFactory *This = (ClassFactory *)iface;
943 ret = This->ctor(punkOuter, &obj);
946 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
947 IUnknown_Release(obj);
951 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
954 InterlockedIncrement(&TS_refCount);
956 InterlockedDecrement(&TS_refCount);
961 static const IClassFactoryVtbl ClassFactoryVtbl = {
963 ClassFactory_QueryInterface,
965 ClassFactory_Release,
968 ClassFactory_CreateInstance,
969 ClassFactory_LockServer
972 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
974 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
975 This->vtbl = &ClassFactoryVtbl;
978 *ppvOut = (LPVOID)This;
983 static void TextService_Destructor(TextService *This)
985 HeapFree(GetProcessHeap(),0,This);
988 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
990 TextService *This = (TextService *)iface;
993 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
1000 IUnknown_AddRef(iface);
1004 return E_NOINTERFACE;
1007 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
1009 TextService *This = (TextService *)iface;
1010 return InterlockedIncrement(&This->refCount);
1013 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
1015 TextService *This = (TextService *)iface;
1018 ret = InterlockedDecrement(&This->refCount);
1020 TextService_Destructor(This);
1024 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
1025 ITfThreadMgr *ptim, TfClientId id)
1027 trace("TextService_Activate\n");
1028 ok(test_ShouldActivate,"Activation came unexpectedly\n");
1033 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
1035 trace("TextService_Deactivate\n");
1036 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
1040 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
1042 TextService_QueryInterface,
1044 TextService_Release,
1046 TextService_Activate,
1047 TextService_Deactivate
1050 HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
1054 return CLASS_E_NOAGGREGATION;
1056 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
1058 return E_OUTOFMEMORY;
1060 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
1063 *ppOut = (IUnknown *)This;
1067 HRESULT RegisterTextService(REFCLSID rclsid)
1069 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
1070 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1073 HRESULT UnregisterTextService()
1075 return CoRevokeClassObject(regid);