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;
269 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
270 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
273 tfpk.uModifiers = TF_MOD_SHIFT;
275 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
276 todo_wine ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
278 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
279 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
281 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
282 todo_wine ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded \n");
285 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
286 todo_wine ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
287 if (hr == S_OK) todo_wine ok(preserved == TRUE,"misreporting preserved key\n");
289 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
290 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
292 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
293 todo_wine ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
294 if (hr == S_FALSE) todo_wine ok(preserved == FALSE,"misreporting preserved key\n");
296 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
297 todo_wine ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
299 ITfKeystrokeMgr_Release(keymgr);
302 static void test_Activate(void)
306 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
307 todo_wine ok(SUCCEEDED(hr),"Failed to Activate text service\n");
310 static int inline check_context_refcount(ITfContext *iface)
312 IUnknown_AddRef(iface);
313 return IUnknown_Release(iface);
316 static void test_startSession(void)
321 ITfDocumentMgr *dmtest;
322 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
325 test_ShouldActivate = TRUE;
326 ITfThreadMgr_Activate(g_tm,&cid);
327 todo_wine ok(cid != tid,"TextService id mistakenly matches Client id\n");
329 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
330 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
332 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
333 ok(SUCCEEDED(hr),"GetFocus Failed\n");
334 ok(dmtest == NULL,"Initial focus not null\n");
336 test_CurrentFocus = g_dm;
337 test_PrevFocus = NULL;
338 test_OnSetFocus = SINK_EXPECTED;
339 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
340 ok(SUCCEEDED(hr),"SetFocus Failed\n");
341 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
342 test_OnSetFocus = SINK_UNEXPECTED;
344 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
345 ok(SUCCEEDED(hr),"GetFocus Failed\n");
346 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
348 cnt = ITfDocumentMgr_Release(g_dm);
349 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
351 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
352 ok(SUCCEEDED(hr),"GetFocus Failed\n");
353 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
355 TextStoreACP_Constructor((IUnknown**)&ts);
357 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
358 ok(SUCCEEDED(hr),"CreateContext Failed\n");
360 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
361 ok(SUCCEEDED(hr),"CreateContext Failed\n");
363 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
364 ok(SUCCEEDED(hr),"CreateContext Failed\n");
366 cnt = check_context_refcount(cxt);
367 test_OnPushContext = SINK_EXPECTED;
368 test_OnInitDocumentMgr = SINK_EXPECTED;
369 hr = ITfDocumentMgr_Push(g_dm, cxt);
370 ok(SUCCEEDED(hr),"Push Failed\n");
371 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
372 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
373 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
375 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
376 ok(SUCCEEDED(hr),"GetTop Failed\n");
377 ok(cxtTest == cxt, "Wrong context on top\n");
378 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
379 cnt = ITfContext_Release(cxtTest);
381 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
382 ok(SUCCEEDED(hr),"GetBase Failed\n");
383 ok(cxtTest == cxt, "Wrong context on Base\n");
384 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
385 ITfContext_Release(cxtTest);
387 check_context_refcount(cxt2);
388 test_OnPushContext = SINK_EXPECTED;
389 hr = ITfDocumentMgr_Push(g_dm, cxt2);
390 ok(SUCCEEDED(hr),"Push Failed\n");
391 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
393 cnt = check_context_refcount(cxt2);
394 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
395 ok(SUCCEEDED(hr),"GetTop Failed\n");
396 ok(cxtTest == cxt2, "Wrong context on top\n");
397 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
398 ITfContext_Release(cxtTest);
400 cnt = check_context_refcount(cxt);
401 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
402 ok(SUCCEEDED(hr),"GetBase Failed\n");
403 ok(cxtTest == cxt, "Wrong context on Base\n");
404 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
405 ITfContext_Release(cxtTest);
407 cnt = check_context_refcount(cxt3);
408 hr = ITfDocumentMgr_Push(g_dm, cxt3);
409 ok(!SUCCEEDED(hr),"Push Succeeded\n");
410 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
412 cnt = check_context_refcount(cxt2);
413 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
414 ok(SUCCEEDED(hr),"GetTop Failed\n");
415 ok(cxtTest == cxt2, "Wrong context on top\n");
416 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
417 ITfContext_Release(cxtTest);
419 cnt = check_context_refcount(cxt);
420 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
421 ok(SUCCEEDED(hr),"GetBase Failed\n");
422 ok(cxtTest == cxt, "Wrong context on Base\n");
423 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
424 ITfContext_Release(cxtTest);
426 cnt = check_context_refcount(cxt2);
427 test_OnPopContext = SINK_EXPECTED;
428 hr = ITfDocumentMgr_Pop(g_dm, 0);
429 ok(SUCCEEDED(hr),"Pop Failed\n");
430 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
431 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
433 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
434 ok(SUCCEEDED(hr),"GetTop Failed\n");
435 ok(cxtTest == cxt, "Wrong context on top\n");
436 ITfContext_Release(cxtTest);
438 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
439 ok(SUCCEEDED(hr),"GetBase Failed\n");
440 ok(cxtTest == cxt, "Wrong context on base\n");
441 ITfContext_Release(cxtTest);
443 hr = ITfDocumentMgr_Pop(g_dm, 0);
444 ok(!SUCCEEDED(hr),"Pop Succeeded\n");
446 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
447 ok(SUCCEEDED(hr),"GetTop Failed\n");
448 ok(cxtTest == cxt, "Wrong context on top\n");
449 ITfContext_Release(cxtTest);
451 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
452 ok(SUCCEEDED(hr),"GetBase Failed\n");
453 ok(cxtTest == cxt, "Wrong context on base\n");
454 ITfContext_Release(cxtTest);
456 ITfContext_Release(cxt);
457 ITfContext_Release(cxt2);
458 ITfContext_Release(cxt3);
461 static void test_endSession(void)
463 test_ShouldDeactivate = TRUE;
464 test_CurrentFocus = NULL;
465 test_PrevFocus = g_dm;
466 test_OnSetFocus = SINK_EXPECTED;
467 ITfThreadMgr_Deactivate(g_tm);
468 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
469 test_OnSetFocus = SINK_UNEXPECTED;
472 START_TEST(inputprocessor)
474 if (SUCCEEDED(initialize()))
476 gLangid = GetUserDefaultLCID();
478 test_RegisterCategory();
479 test_EnumInputProcessorInfo();
481 test_ThreadMgrAdviseSinks();
486 test_EnumLanguageProfiles();
487 test_FindClosestCategory();
489 test_ThreadMgrUnadviseSinks();
490 test_UnregisterCategory();
494 skip("Unable to create InputProcessor\n");
498 /**********************************************************************
500 **********************************************************************/
501 typedef struct tagTextStoreACP
503 const ITextStoreACPVtbl *TextStoreACPVtbl;
507 static void TextStoreACP_Destructor(TextStoreACP *This)
509 HeapFree(GetProcessHeap(),0,This);
512 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
514 TextStoreACP *This = (TextStoreACP *)iface;
517 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
524 IUnknown_AddRef(iface);
528 return E_NOINTERFACE;
531 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
533 TextStoreACP *This = (TextStoreACP *)iface;
534 return InterlockedIncrement(&This->refCount);
537 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
539 TextStoreACP *This = (TextStoreACP *)iface;
542 ret = InterlockedDecrement(&This->refCount);
544 TextStoreACP_Destructor(This);
548 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
549 REFIID riid, IUnknown *punk, DWORD dwMask)
555 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
561 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
562 DWORD dwLockFlags, HRESULT *phrSession)
567 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
573 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
574 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
580 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
581 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
586 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
587 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
592 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
593 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
594 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
595 ULONG *pcRunInfoRet, LONG *pacpNext)
600 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
601 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
602 ULONG cch, TS_TEXTCHANGE *pChange)
607 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
608 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
613 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
614 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
619 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
620 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
625 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
626 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
627 TS_TEXTCHANGE *pChange)
632 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
633 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
634 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
639 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
640 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
641 TS_TEXTCHANGE *pChange)
646 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
647 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
652 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
653 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
659 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
660 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
666 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
667 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
668 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
673 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
674 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
679 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
685 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
686 TsViewCookie *pvcView)
691 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
692 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
698 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
699 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
705 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
706 TsViewCookie vcView, RECT *prc)
711 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
712 TsViewCookie vcView, HWND *phwnd)
718 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
720 TextStoreACP_QueryInterface,
722 TextStoreACP_Release,
724 TextStoreACP_AdviseSink,
725 TextStoreACP_UnadviseSink,
726 TextStoreACP_RequestLock,
727 TextStoreACP_GetStatus,
728 TextStoreACP_QueryInsert,
729 TextStoreACP_GetSelection,
730 TextStoreACP_SetSelection,
731 TextStoreACP_GetText,
732 TextStoreACP_SetText,
733 TextStoreACP_GetFormattedText,
734 TextStoreACP_GetEmbedded,
735 TextStoreACP_QueryInsertEmbedded,
736 TextStoreACP_InsertEmbedded,
737 TextStoreACP_InsertTextAtSelection,
738 TextStoreACP_InsertEmbeddedAtSelection,
739 TextStoreACP_RequestSupportedAttrs,
740 TextStoreACP_RequestAttrsAtPosition,
741 TextStoreACP_RequestAttrsTransitioningAtPosition,
742 TextStoreACP_FindNextAttrTransition,
743 TextStoreACP_RetrieveRequestedAttrs,
744 TextStoreACP_GetEndACP,
745 TextStoreACP_GetActiveView,
746 TextStoreACP_GetACPFromPoint,
747 TextStoreACP_GetTextExt,
748 TextStoreACP_GetScreenExt,
752 HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
756 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
758 return E_OUTOFMEMORY;
760 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
763 *ppOut = (IUnknown *)This;
767 /**********************************************************************
768 * ITfThreadMgrEventSink
769 **********************************************************************/
770 typedef struct tagThreadMgrEventSink
772 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
774 } ThreadMgrEventSink;
776 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
778 HeapFree(GetProcessHeap(),0,This);
781 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
783 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
786 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
793 IUnknown_AddRef(iface);
797 return E_NOINTERFACE;
800 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
802 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
803 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
804 return InterlockedIncrement(&This->refCount);
807 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
809 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
812 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
813 ret = InterlockedDecrement(&This->refCount);
815 ThreadMgrEventSink_Destructor(This);
819 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
820 ITfDocumentMgr *pdim)
822 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
823 test_OnInitDocumentMgr = SINK_FIRED;
827 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
828 ITfDocumentMgr *pdim)
834 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
835 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
837 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
838 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
839 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
840 test_OnSetFocus = SINK_FIRED;
844 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
847 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
848 test_OnPushContext = SINK_FIRED;
852 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
855 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
856 test_OnPopContext = SINK_FIRED;
860 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
862 ThreadMgrEventSink_QueryInterface,
863 ThreadMgrEventSink_AddRef,
864 ThreadMgrEventSink_Release,
866 ThreadMgrEventSink_OnInitDocumentMgr,
867 ThreadMgrEventSink_OnUninitDocumentMgr,
868 ThreadMgrEventSink_OnSetFocus,
869 ThreadMgrEventSink_OnPushContext,
870 ThreadMgrEventSink_OnPopContext
873 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
875 ThreadMgrEventSink *This;
877 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
879 return E_OUTOFMEMORY;
881 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
884 *ppOut = (IUnknown *)This;
889 /********************************************************************************************
890 * Stub text service for testing
891 ********************************************************************************************/
893 static LONG TS_refCount;
894 static IClassFactory *cf;
897 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
899 typedef struct tagClassFactory
901 const IClassFactoryVtbl *vtbl;
903 LPFNCONSTRUCTOR ctor;
906 typedef struct tagTextService
908 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
912 static void ClassFactory_Destructor(ClassFactory *This)
914 HeapFree(GetProcessHeap(),0,This);
918 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
921 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
923 IClassFactory_AddRef(iface);
928 return E_NOINTERFACE;
931 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
933 ClassFactory *This = (ClassFactory *)iface;
934 return InterlockedIncrement(&This->ref);
937 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
939 ClassFactory *This = (ClassFactory *)iface;
940 ULONG ret = InterlockedDecrement(&This->ref);
943 ClassFactory_Destructor(This);
947 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
949 ClassFactory *This = (ClassFactory *)iface;
953 ret = This->ctor(punkOuter, &obj);
956 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
957 IUnknown_Release(obj);
961 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
964 InterlockedIncrement(&TS_refCount);
966 InterlockedDecrement(&TS_refCount);
971 static const IClassFactoryVtbl ClassFactoryVtbl = {
973 ClassFactory_QueryInterface,
975 ClassFactory_Release,
978 ClassFactory_CreateInstance,
979 ClassFactory_LockServer
982 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
984 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
985 This->vtbl = &ClassFactoryVtbl;
988 *ppvOut = (LPVOID)This;
993 static void TextService_Destructor(TextService *This)
995 HeapFree(GetProcessHeap(),0,This);
998 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
1000 TextService *This = (TextService *)iface;
1003 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
1010 IUnknown_AddRef(iface);
1014 return E_NOINTERFACE;
1017 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
1019 TextService *This = (TextService *)iface;
1020 return InterlockedIncrement(&This->refCount);
1023 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
1025 TextService *This = (TextService *)iface;
1028 ret = InterlockedDecrement(&This->refCount);
1030 TextService_Destructor(This);
1034 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
1035 ITfThreadMgr *ptim, TfClientId id)
1037 trace("TextService_Activate\n");
1038 ok(test_ShouldActivate,"Activation came unexpectedly\n");
1043 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
1045 trace("TextService_Deactivate\n");
1046 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
1050 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
1052 TextService_QueryInterface,
1054 TextService_Release,
1056 TextService_Activate,
1057 TextService_Deactivate
1060 HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
1064 return CLASS_E_NOAGGREGATION;
1066 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
1068 return E_OUTOFMEMORY;
1070 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
1073 *ppOut = (IUnknown *)This;
1077 HRESULT RegisterTextService(REFCLSID rclsid)
1079 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
1080 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1083 HRESULT UnregisterTextService()
1085 return CoRevokeClassObject(regid);