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"
32 static ITfInputProcessorProfiles* g_ipp;
33 static LANGID gLangid;
34 static ITfCategoryMgr * g_cm = NULL;
35 static ITfThreadMgr* g_tm = NULL;
36 static ITfDocumentMgr *g_dm = NULL;
37 static TfClientId cid = 0;
38 static TfClientId tid = 0;
40 #define SINK_UNEXPECTED 0
41 #define SINK_EXPECTED 1
44 static BOOL test_ShouldActivate = FALSE;
45 static BOOL test_ShouldDeactivate = FALSE;
47 static DWORD tmSinkCookie;
48 static DWORD tmSinkRefCount;
49 static ITfDocumentMgr *test_CurrentFocus = NULL;
50 static ITfDocumentMgr *test_PrevFocus = NULL;
51 static INT test_OnSetFocus = SINK_UNEXPECTED;
52 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
53 static INT test_OnPushContext = SINK_UNEXPECTED;
54 static INT test_OnPopContext = SINK_UNEXPECTED;
56 HRESULT RegisterTextService(REFCLSID rclsid);
57 HRESULT UnregisterTextService();
58 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut);
59 HRESULT TextStoreACP_Constructor(IUnknown **ppOut);
61 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
62 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
63 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
64 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
65 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
66 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
67 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
68 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
69 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
72 static HRESULT initialize(void)
76 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
77 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
79 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
80 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
82 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
83 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
87 static void cleanup(void)
90 ITfInputProcessorProfiles_Release(g_ipp);
92 ITfCategoryMgr_Release(g_cm);
94 ITfThreadMgr_Release(g_tm);
98 static void test_Register(void)
102 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
103 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
105 hr = RegisterTextService(&CLSID_FakeService);
106 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
107 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
108 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
109 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
110 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
113 static void test_Unregister(void)
116 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
117 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
118 UnregisterTextService();
121 static void test_EnumInputProcessorInfo(void)
126 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
130 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
132 if(IsEqualGUID(&g,&CLSID_FakeService))
136 ok(found,"Did not find registered text service\n");
139 static void test_EnumLanguageProfiles(void)
142 IEnumTfLanguageProfiles *ppEnum;
143 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
145 TF_LANGUAGEPROFILE profile;
146 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
148 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
151 ok(profile.langid == gLangid, "LangId Incorrect\n");
152 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
153 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
157 ok(found,"Registered text service not found\n");
160 static void test_RegisterCategory(void)
163 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
164 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
165 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
166 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
169 static void test_UnregisterCategory(void)
172 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
173 todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
174 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
175 todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
178 static void test_FindClosestCategory(void)
182 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
184 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
185 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
186 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
188 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
189 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
190 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
192 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
193 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
194 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
197 static void test_Enable(void)
200 BOOL enabled = FALSE;
202 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
203 ok(SUCCEEDED(hr),"Failed to enable text service\n");
204 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
205 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
206 ok(enabled == TRUE,"enabled state incorrect\n");
209 static void test_Disable(void)
213 trace("Disabling\n");
214 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
215 ok(SUCCEEDED(hr),"Failed to disable text service\n");
218 static void test_ThreadMgrAdviseSinks(void)
220 ITfSource *source = NULL;
224 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
225 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
229 ThreadMgrEventSink_Constructor(&sink);
233 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
234 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
235 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
237 /* Advising the sink adds a ref, Relesing here lets the object be deleted
240 IUnknown_Release(sink);
241 ITfSource_Release(source);
244 static void test_ThreadMgrUnadviseSinks(void)
246 ITfSource *source = NULL;
249 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
250 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
255 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
256 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
257 ITfSource_Release(source);
260 static void test_KeystrokeMgr(void)
262 ITfKeystrokeMgr *keymgr= NULL;
265 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
266 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
267 ITfKeystrokeMgr_Release(keymgr);
270 static void test_Activate(void)
274 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
275 todo_wine ok(SUCCEEDED(hr),"Failed to Activate text service\n");
278 static int inline check_context_refcount(ITfContext *iface)
280 IUnknown_AddRef(iface);
281 return IUnknown_Release(iface);
284 static void test_startSession(void)
289 ITfDocumentMgr *dmtest;
290 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
293 test_ShouldActivate = TRUE;
294 ITfThreadMgr_Activate(g_tm,&cid);
295 todo_wine ok(cid != tid,"TextService id mistakenly matches Client id\n");
297 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
298 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
300 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
301 ok(SUCCEEDED(hr),"GetFocus Failed\n");
302 ok(dmtest == NULL,"Initial focus not null\n");
304 test_CurrentFocus = g_dm;
305 test_PrevFocus = NULL;
306 test_OnSetFocus = SINK_EXPECTED;
307 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
308 ok(SUCCEEDED(hr),"SetFocus Failed\n");
309 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
310 test_OnSetFocus = SINK_UNEXPECTED;
312 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
313 ok(SUCCEEDED(hr),"GetFocus Failed\n");
314 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
316 cnt = ITfDocumentMgr_Release(g_dm);
317 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
319 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
320 ok(SUCCEEDED(hr),"GetFocus Failed\n");
321 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
323 TextStoreACP_Constructor((IUnknown**)&ts);
325 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
326 ok(SUCCEEDED(hr),"CreateContext Failed\n");
328 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
329 ok(SUCCEEDED(hr),"CreateContext Failed\n");
331 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
332 ok(SUCCEEDED(hr),"CreateContext Failed\n");
334 cnt = check_context_refcount(cxt);
335 test_OnPushContext = SINK_EXPECTED;
336 test_OnInitDocumentMgr = SINK_EXPECTED;
337 hr = ITfDocumentMgr_Push(g_dm, cxt);
338 ok(SUCCEEDED(hr),"Push Failed\n");
339 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
340 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
341 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
343 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
344 ok(SUCCEEDED(hr),"GetTop Failed\n");
345 ok(cxtTest == cxt, "Wrong context on top\n");
346 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
347 cnt = ITfContext_Release(cxtTest);
349 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
350 ok(SUCCEEDED(hr),"GetBase Failed\n");
351 ok(cxtTest == cxt, "Wrong context on Base\n");
352 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
353 ITfContext_Release(cxtTest);
355 check_context_refcount(cxt2);
356 test_OnPushContext = SINK_EXPECTED;
357 hr = ITfDocumentMgr_Push(g_dm, cxt2);
358 ok(SUCCEEDED(hr),"Push Failed\n");
359 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
361 cnt = check_context_refcount(cxt2);
362 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
363 ok(SUCCEEDED(hr),"GetTop Failed\n");
364 ok(cxtTest == cxt2, "Wrong context on top\n");
365 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
366 ITfContext_Release(cxtTest);
368 cnt = check_context_refcount(cxt);
369 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
370 ok(SUCCEEDED(hr),"GetBase Failed\n");
371 ok(cxtTest == cxt, "Wrong context on Base\n");
372 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
373 ITfContext_Release(cxtTest);
375 cnt = check_context_refcount(cxt3);
376 hr = ITfDocumentMgr_Push(g_dm, cxt3);
377 ok(!SUCCEEDED(hr),"Push Succeeded\n");
378 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
380 cnt = check_context_refcount(cxt2);
381 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
382 ok(SUCCEEDED(hr),"GetTop Failed\n");
383 ok(cxtTest == cxt2, "Wrong context on top\n");
384 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
385 ITfContext_Release(cxtTest);
387 cnt = check_context_refcount(cxt);
388 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
389 ok(SUCCEEDED(hr),"GetBase Failed\n");
390 ok(cxtTest == cxt, "Wrong context on Base\n");
391 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
392 ITfContext_Release(cxtTest);
394 cnt = check_context_refcount(cxt2);
395 test_OnPopContext = SINK_EXPECTED;
396 hr = ITfDocumentMgr_Pop(g_dm, 0);
397 ok(SUCCEEDED(hr),"Pop Failed\n");
398 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
399 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
401 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
402 ok(SUCCEEDED(hr),"GetTop Failed\n");
403 ok(cxtTest == cxt, "Wrong context on top\n");
404 ITfContext_Release(cxtTest);
406 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
407 ok(SUCCEEDED(hr),"GetBase Failed\n");
408 ok(cxtTest == cxt, "Wrong context on base\n");
409 ITfContext_Release(cxtTest);
411 hr = ITfDocumentMgr_Pop(g_dm, 0);
412 ok(!SUCCEEDED(hr),"Pop Succeeded\n");
414 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
415 ok(SUCCEEDED(hr),"GetTop Failed\n");
416 ok(cxtTest == cxt, "Wrong context on top\n");
417 ITfContext_Release(cxtTest);
419 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
420 ok(SUCCEEDED(hr),"GetBase Failed\n");
421 ok(cxtTest == cxt, "Wrong context on base\n");
422 ITfContext_Release(cxtTest);
424 ITfContext_Release(cxt);
425 ITfContext_Release(cxt2);
426 ITfContext_Release(cxt3);
429 static void test_endSession(void)
431 test_ShouldDeactivate = TRUE;
432 test_CurrentFocus = NULL;
433 test_PrevFocus = g_dm;
434 test_OnSetFocus = SINK_EXPECTED;
435 ITfThreadMgr_Deactivate(g_tm);
436 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
437 test_OnSetFocus = SINK_UNEXPECTED;
440 START_TEST(inputprocessor)
442 if (SUCCEEDED(initialize()))
444 gLangid = GetUserDefaultLCID();
446 test_RegisterCategory();
447 test_EnumInputProcessorInfo();
449 test_ThreadMgrAdviseSinks();
454 test_EnumLanguageProfiles();
455 test_FindClosestCategory();
457 test_ThreadMgrUnadviseSinks();
458 test_UnregisterCategory();
462 skip("Unable to create InputProcessor\n");
466 /**********************************************************************
468 **********************************************************************/
469 typedef struct tagTextStoreACP
471 const ITextStoreACPVtbl *TextStoreACPVtbl;
475 static void TextStoreACP_Destructor(TextStoreACP *This)
477 HeapFree(GetProcessHeap(),0,This);
480 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
482 TextStoreACP *This = (TextStoreACP *)iface;
485 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
492 IUnknown_AddRef(iface);
496 return E_NOINTERFACE;
499 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
501 TextStoreACP *This = (TextStoreACP *)iface;
502 return InterlockedIncrement(&This->refCount);
505 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
507 TextStoreACP *This = (TextStoreACP *)iface;
510 ret = InterlockedDecrement(&This->refCount);
512 TextStoreACP_Destructor(This);
516 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
517 REFIID riid, IUnknown *punk, DWORD dwMask)
523 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
529 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
530 DWORD dwLockFlags, HRESULT *phrSession)
535 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
541 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
542 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
548 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
549 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
554 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
555 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
560 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
561 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
562 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
563 ULONG *pcRunInfoRet, LONG *pacpNext)
568 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
569 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
570 ULONG cch, TS_TEXTCHANGE *pChange)
575 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
576 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
581 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
582 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
587 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
588 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
593 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
594 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
595 TS_TEXTCHANGE *pChange)
600 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
601 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
602 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
607 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
608 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
609 TS_TEXTCHANGE *pChange)
614 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
615 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
620 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
621 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
627 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
628 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
634 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
635 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
636 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
641 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
642 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
647 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
653 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
654 TsViewCookie *pvcView)
659 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
660 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
666 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
667 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
673 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
674 TsViewCookie vcView, RECT *prc)
679 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
680 TsViewCookie vcView, HWND *phwnd)
686 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
688 TextStoreACP_QueryInterface,
690 TextStoreACP_Release,
692 TextStoreACP_AdviseSink,
693 TextStoreACP_UnadviseSink,
694 TextStoreACP_RequestLock,
695 TextStoreACP_GetStatus,
696 TextStoreACP_QueryInsert,
697 TextStoreACP_GetSelection,
698 TextStoreACP_SetSelection,
699 TextStoreACP_GetText,
700 TextStoreACP_SetText,
701 TextStoreACP_GetFormattedText,
702 TextStoreACP_GetEmbedded,
703 TextStoreACP_QueryInsertEmbedded,
704 TextStoreACP_InsertEmbedded,
705 TextStoreACP_InsertTextAtSelection,
706 TextStoreACP_InsertEmbeddedAtSelection,
707 TextStoreACP_RequestSupportedAttrs,
708 TextStoreACP_RequestAttrsAtPosition,
709 TextStoreACP_RequestAttrsTransitioningAtPosition,
710 TextStoreACP_FindNextAttrTransition,
711 TextStoreACP_RetrieveRequestedAttrs,
712 TextStoreACP_GetEndACP,
713 TextStoreACP_GetActiveView,
714 TextStoreACP_GetACPFromPoint,
715 TextStoreACP_GetTextExt,
716 TextStoreACP_GetScreenExt,
720 HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
724 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
726 return E_OUTOFMEMORY;
728 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
731 *ppOut = (IUnknown *)This;
735 /**********************************************************************
736 * ITfThreadMgrEventSink
737 **********************************************************************/
738 typedef struct tagThreadMgrEventSink
740 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
742 } ThreadMgrEventSink;
744 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
746 HeapFree(GetProcessHeap(),0,This);
749 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
751 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
754 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
761 IUnknown_AddRef(iface);
765 return E_NOINTERFACE;
768 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
770 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
771 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
772 return InterlockedIncrement(&This->refCount);
775 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
777 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
780 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
781 ret = InterlockedDecrement(&This->refCount);
783 ThreadMgrEventSink_Destructor(This);
787 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
788 ITfDocumentMgr *pdim)
790 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
791 test_OnInitDocumentMgr = SINK_FIRED;
795 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
796 ITfDocumentMgr *pdim)
802 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
803 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
805 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
806 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
807 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
808 test_OnSetFocus = SINK_FIRED;
812 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
815 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
816 test_OnPushContext = SINK_FIRED;
820 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
823 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
824 test_OnPopContext = SINK_FIRED;
828 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
830 ThreadMgrEventSink_QueryInterface,
831 ThreadMgrEventSink_AddRef,
832 ThreadMgrEventSink_Release,
834 ThreadMgrEventSink_OnInitDocumentMgr,
835 ThreadMgrEventSink_OnUninitDocumentMgr,
836 ThreadMgrEventSink_OnSetFocus,
837 ThreadMgrEventSink_OnPushContext,
838 ThreadMgrEventSink_OnPopContext
841 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
843 ThreadMgrEventSink *This;
845 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
847 return E_OUTOFMEMORY;
849 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
852 *ppOut = (IUnknown *)This;
857 /********************************************************************************************
858 * Stub text service for testing
859 ********************************************************************************************/
861 static LONG TS_refCount;
862 static IClassFactory *cf;
865 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
867 typedef struct tagClassFactory
869 const IClassFactoryVtbl *vtbl;
871 LPFNCONSTRUCTOR ctor;
874 typedef struct tagTextService
876 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
880 static void ClassFactory_Destructor(ClassFactory *This)
882 HeapFree(GetProcessHeap(),0,This);
886 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
889 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
891 IClassFactory_AddRef(iface);
896 return E_NOINTERFACE;
899 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
901 ClassFactory *This = (ClassFactory *)iface;
902 return InterlockedIncrement(&This->ref);
905 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
907 ClassFactory *This = (ClassFactory *)iface;
908 ULONG ret = InterlockedDecrement(&This->ref);
911 ClassFactory_Destructor(This);
915 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
917 ClassFactory *This = (ClassFactory *)iface;
921 ret = This->ctor(punkOuter, &obj);
924 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
925 IUnknown_Release(obj);
929 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
932 InterlockedIncrement(&TS_refCount);
934 InterlockedDecrement(&TS_refCount);
939 static const IClassFactoryVtbl ClassFactoryVtbl = {
941 ClassFactory_QueryInterface,
943 ClassFactory_Release,
946 ClassFactory_CreateInstance,
947 ClassFactory_LockServer
950 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
952 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
953 This->vtbl = &ClassFactoryVtbl;
956 *ppvOut = (LPVOID)This;
961 static void TextService_Destructor(TextService *This)
963 HeapFree(GetProcessHeap(),0,This);
966 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
968 TextService *This = (TextService *)iface;
971 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
978 IUnknown_AddRef(iface);
982 return E_NOINTERFACE;
985 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
987 TextService *This = (TextService *)iface;
988 return InterlockedIncrement(&This->refCount);
991 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
993 TextService *This = (TextService *)iface;
996 ret = InterlockedDecrement(&This->refCount);
998 TextService_Destructor(This);
1002 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
1003 ITfThreadMgr *ptim, TfClientId id)
1005 trace("TextService_Activate\n");
1006 ok(test_ShouldActivate,"Activation came unexpectedly\n");
1011 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
1013 trace("TextService_Deactivate\n");
1014 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
1018 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
1020 TextService_QueryInterface,
1022 TextService_Release,
1024 TextService_Activate,
1025 TextService_Deactivate
1028 HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
1032 return CLASS_E_NOAGGREGATION;
1034 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
1036 return E_OUTOFMEMORY;
1038 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
1041 *ppOut = (IUnknown *)This;
1045 HRESULT RegisterTextService(REFCLSID rclsid)
1047 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
1048 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
1051 HRESULT UnregisterTextService()
1053 return CoRevokeClassObject(regid);