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;
57 static INT test_ACP_AdviseSink = SINK_UNEXPECTED;
58 static INT test_ACP_GetStatus = SINK_UNEXPECTED;
59 static INT test_ACP_RequestLock = SINK_UNEXPECTED;
60 static INT test_DoEditSession = SINK_UNEXPECTED;
63 /**********************************************************************
65 **********************************************************************/
66 typedef struct tagTextStoreACP
68 const ITextStoreACPVtbl *TextStoreACPVtbl;
71 ITextStoreACPSink *sink;
74 static void TextStoreACP_Destructor(TextStoreACP *This)
76 HeapFree(GetProcessHeap(),0,This);
79 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
81 TextStoreACP *This = (TextStoreACP *)iface;
84 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
91 IUnknown_AddRef(iface);
98 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
100 TextStoreACP *This = (TextStoreACP *)iface;
101 return InterlockedIncrement(&This->refCount);
104 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
106 TextStoreACP *This = (TextStoreACP *)iface;
109 ret = InterlockedDecrement(&This->refCount);
111 TextStoreACP_Destructor(This);
115 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
116 REFIID riid, IUnknown *punk, DWORD dwMask)
118 TextStoreACP *This = (TextStoreACP *)iface;
121 ok(test_ACP_AdviseSink == SINK_EXPECTED, "Unexpected TextStoreACP_AdviseSink sink\n");
122 test_ACP_AdviseSink = SINK_FIRED;
124 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&This->sink));
125 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
129 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
136 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
137 DWORD dwLockFlags, HRESULT *phrSession)
139 TextStoreACP *This = (TextStoreACP *)iface;
141 ok(test_ACP_RequestLock == SINK_EXPECTED,"Unexpected TextStoreACP_RequestLock\n");
142 test_ACP_RequestLock = SINK_FIRED;
143 test_DoEditSession = SINK_EXPECTED;
144 *phrSession = ITextStoreACPSink_OnLockGranted(This->sink, TS_LF_READWRITE);
145 ok(test_DoEditSession = SINK_FIRED,"expected DoEditSession not fired\n");
146 ok(*phrSession == 0xdeadcafe,"Unexpected return from ITextStoreACPSink_OnLockGranted\n");
149 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
152 ok(test_ACP_GetStatus == SINK_EXPECTED, "Unexpected TextStoreACP_GetStatus\n");
153 test_ACP_GetStatus = SINK_FIRED;
156 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
157 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
163 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
164 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
169 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
170 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
175 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
176 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
177 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
178 ULONG *pcRunInfoRet, LONG *pacpNext)
183 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
184 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
185 ULONG cch, TS_TEXTCHANGE *pChange)
190 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
191 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
196 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
197 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
202 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
203 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
208 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
209 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
210 TS_TEXTCHANGE *pChange)
215 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
216 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
217 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
222 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
223 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
224 TS_TEXTCHANGE *pChange)
229 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
230 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
235 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
236 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
242 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
243 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
249 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
250 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
251 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
256 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
257 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
262 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
268 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
269 TsViewCookie *pvcView)
274 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
275 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
281 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
282 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
288 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
289 TsViewCookie vcView, RECT *prc)
294 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
295 TsViewCookie vcView, HWND *phwnd)
301 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
303 TextStoreACP_QueryInterface,
305 TextStoreACP_Release,
307 TextStoreACP_AdviseSink,
308 TextStoreACP_UnadviseSink,
309 TextStoreACP_RequestLock,
310 TextStoreACP_GetStatus,
311 TextStoreACP_QueryInsert,
312 TextStoreACP_GetSelection,
313 TextStoreACP_SetSelection,
314 TextStoreACP_GetText,
315 TextStoreACP_SetText,
316 TextStoreACP_GetFormattedText,
317 TextStoreACP_GetEmbedded,
318 TextStoreACP_QueryInsertEmbedded,
319 TextStoreACP_InsertEmbedded,
320 TextStoreACP_InsertTextAtSelection,
321 TextStoreACP_InsertEmbeddedAtSelection,
322 TextStoreACP_RequestSupportedAttrs,
323 TextStoreACP_RequestAttrsAtPosition,
324 TextStoreACP_RequestAttrsTransitioningAtPosition,
325 TextStoreACP_FindNextAttrTransition,
326 TextStoreACP_RetrieveRequestedAttrs,
327 TextStoreACP_GetEndACP,
328 TextStoreACP_GetActiveView,
329 TextStoreACP_GetACPFromPoint,
330 TextStoreACP_GetTextExt,
331 TextStoreACP_GetScreenExt,
335 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
339 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
341 return E_OUTOFMEMORY;
343 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
346 *ppOut = (IUnknown *)This;
350 /**********************************************************************
351 * ITfThreadMgrEventSink
352 **********************************************************************/
353 typedef struct tagThreadMgrEventSink
355 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
357 } ThreadMgrEventSink;
359 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
361 HeapFree(GetProcessHeap(),0,This);
364 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
366 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
369 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
376 IUnknown_AddRef(iface);
380 return E_NOINTERFACE;
383 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
385 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
386 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
387 return InterlockedIncrement(&This->refCount);
390 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
392 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
395 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
396 ret = InterlockedDecrement(&This->refCount);
398 ThreadMgrEventSink_Destructor(This);
402 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
403 ITfDocumentMgr *pdim)
405 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
406 test_OnInitDocumentMgr = SINK_FIRED;
410 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
411 ITfDocumentMgr *pdim)
417 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
418 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
420 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
421 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
422 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
423 test_OnSetFocus = SINK_FIRED;
427 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
430 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
431 test_OnPushContext = SINK_FIRED;
435 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
438 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
439 test_OnPopContext = SINK_FIRED;
443 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
445 ThreadMgrEventSink_QueryInterface,
446 ThreadMgrEventSink_AddRef,
447 ThreadMgrEventSink_Release,
449 ThreadMgrEventSink_OnInitDocumentMgr,
450 ThreadMgrEventSink_OnUninitDocumentMgr,
451 ThreadMgrEventSink_OnSetFocus,
452 ThreadMgrEventSink_OnPushContext,
453 ThreadMgrEventSink_OnPopContext
456 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
458 ThreadMgrEventSink *This;
460 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
462 return E_OUTOFMEMORY;
464 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
467 *ppOut = (IUnknown *)This;
472 /********************************************************************************************
473 * Stub text service for testing
474 ********************************************************************************************/
476 static LONG TS_refCount;
477 static IClassFactory *cf;
480 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
482 typedef struct tagClassFactory
484 const IClassFactoryVtbl *vtbl;
486 LPFNCONSTRUCTOR ctor;
489 typedef struct tagTextService
491 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
495 static void ClassFactory_Destructor(ClassFactory *This)
497 HeapFree(GetProcessHeap(),0,This);
501 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
504 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
506 IClassFactory_AddRef(iface);
511 return E_NOINTERFACE;
514 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
516 ClassFactory *This = (ClassFactory *)iface;
517 return InterlockedIncrement(&This->ref);
520 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
522 ClassFactory *This = (ClassFactory *)iface;
523 ULONG ret = InterlockedDecrement(&This->ref);
526 ClassFactory_Destructor(This);
530 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
532 ClassFactory *This = (ClassFactory *)iface;
536 ret = This->ctor(punkOuter, &obj);
539 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
540 IUnknown_Release(obj);
544 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
547 InterlockedIncrement(&TS_refCount);
549 InterlockedDecrement(&TS_refCount);
554 static const IClassFactoryVtbl ClassFactoryVtbl = {
556 ClassFactory_QueryInterface,
558 ClassFactory_Release,
561 ClassFactory_CreateInstance,
562 ClassFactory_LockServer
565 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
567 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
568 This->vtbl = &ClassFactoryVtbl;
571 *ppvOut = (LPVOID)This;
576 static void TextService_Destructor(TextService *This)
578 HeapFree(GetProcessHeap(),0,This);
581 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
583 TextService *This = (TextService *)iface;
586 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
593 IUnknown_AddRef(iface);
597 return E_NOINTERFACE;
600 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
602 TextService *This = (TextService *)iface;
603 return InterlockedIncrement(&This->refCount);
606 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
608 TextService *This = (TextService *)iface;
611 ret = InterlockedDecrement(&This->refCount);
613 TextService_Destructor(This);
617 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
618 ITfThreadMgr *ptim, TfClientId id)
620 trace("TextService_Activate\n");
621 ok(test_ShouldActivate,"Activation came unexpectedly\n");
626 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
628 trace("TextService_Deactivate\n");
629 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
633 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
635 TextService_QueryInterface,
639 TextService_Activate,
640 TextService_Deactivate
643 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
647 return CLASS_E_NOAGGREGATION;
649 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
651 return E_OUTOFMEMORY;
653 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
656 *ppOut = (IUnknown *)This;
660 static HRESULT RegisterTextService(REFCLSID rclsid)
662 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
663 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
666 static HRESULT UnregisterTextService()
668 return CoRevokeClassObject(regid);
675 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
676 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
677 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
678 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
679 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
680 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
681 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
682 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
683 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
684 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
687 static HRESULT initialize(void)
691 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
692 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
694 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
695 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
697 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
698 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
702 static void cleanup(void)
705 ITfInputProcessorProfiles_Release(g_ipp);
707 ITfCategoryMgr_Release(g_cm);
709 ITfThreadMgr_Release(g_tm);
713 static void test_Register(void)
717 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
718 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
720 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
721 ok(SUCCEEDED(hr),"Unable to get current language id\n");
722 trace("Current Language %x\n",gLangid);
724 hr = RegisterTextService(&CLSID_FakeService);
725 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
726 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
727 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
728 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
729 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
732 static void test_Unregister(void)
735 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
736 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
737 UnregisterTextService();
740 static void test_EnumInputProcessorInfo(void)
745 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
749 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
751 if(IsEqualGUID(&g,&CLSID_FakeService))
755 ok(found,"Did not find registered text service\n");
758 static void test_EnumLanguageProfiles(void)
761 IEnumTfLanguageProfiles *ppEnum;
762 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
764 TF_LANGUAGEPROFILE profile;
765 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
767 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
770 ok(profile.langid == gLangid, "LangId Incorrect\n");
771 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
772 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
776 ok(found,"Registered text service not found\n");
779 static void test_RegisterCategory(void)
782 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
783 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
784 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
785 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
788 static void test_UnregisterCategory(void)
791 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
792 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
793 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
794 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
797 static void test_FindClosestCategory(void)
801 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
803 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
804 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
805 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
807 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
808 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
809 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
811 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
812 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
813 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
816 static void test_Enable(void)
819 BOOL enabled = FALSE;
821 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
822 ok(SUCCEEDED(hr),"Failed to enable text service\n");
823 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
824 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
825 ok(enabled == TRUE,"enabled state incorrect\n");
828 static void test_Disable(void)
832 trace("Disabling\n");
833 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
834 ok(SUCCEEDED(hr),"Failed to disable text service\n");
837 static void test_ThreadMgrAdviseSinks(void)
839 ITfSource *source = NULL;
843 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
844 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
848 hr = ThreadMgrEventSink_Constructor(&sink);
849 ok(hr == S_OK, "got %08x\n", hr);
850 if(FAILED(hr)) return;
854 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
855 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
856 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
858 /* Advising the sink adds a ref, Relesing here lets the object be deleted
861 IUnknown_Release(sink);
862 ITfSource_Release(source);
865 static void test_ThreadMgrUnadviseSinks(void)
867 ITfSource *source = NULL;
870 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
871 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
876 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
877 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
878 ITfSource_Release(source);
881 /**********************************************************************
883 **********************************************************************/
884 typedef struct tagKeyEventSink
886 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
890 static void KeyEventSink_Destructor(KeyEventSink *This)
892 HeapFree(GetProcessHeap(),0,This);
895 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
897 KeyEventSink *This = (KeyEventSink *)iface;
900 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
907 IUnknown_AddRef(iface);
911 return E_NOINTERFACE;
914 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
916 KeyEventSink *This = (KeyEventSink *)iface;
917 return InterlockedIncrement(&This->refCount);
920 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
922 KeyEventSink *This = (KeyEventSink *)iface;
925 ret = InterlockedDecrement(&This->refCount);
927 KeyEventSink_Destructor(This);
931 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
934 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
935 test_KEV_OnSetFocus = SINK_FIRED;
939 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
940 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
946 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
947 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
953 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
954 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
960 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
961 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
967 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
968 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
974 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
976 KeyEventSink_QueryInterface,
978 KeyEventSink_Release,
980 KeyEventSink_OnSetFocus,
981 KeyEventSink_OnTestKeyDown,
982 KeyEventSink_OnTestKeyUp,
983 KeyEventSink_OnKeyDown,
984 KeyEventSink_OnKeyUp,
985 KeyEventSink_OnPreservedKey
988 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
992 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
994 return E_OUTOFMEMORY;
996 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
999 *ppOut = (ITfKeyEventSink*)This;
1004 static void test_KeystrokeMgr(void)
1006 ITfKeystrokeMgr *keymgr= NULL;
1008 TF_PRESERVEDKEY tfpk;
1010 ITfKeyEventSink *sink = NULL;
1012 KeyEventSink_Constructor(&sink);
1014 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1015 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1018 tfpk.uModifiers = TF_MOD_SHIFT;
1020 test_KEV_OnSetFocus = SINK_EXPECTED;
1021 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1022 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1023 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1024 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1025 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1026 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1027 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1029 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1030 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1032 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1033 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1035 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1036 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1039 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1040 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1041 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1043 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1044 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1046 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1047 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1048 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1050 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1051 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1053 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1054 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1056 ITfKeystrokeMgr_Release(keymgr);
1057 ITfKeyEventSink_Release(sink);
1060 static void test_Activate(void)
1064 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1065 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1068 static inline int check_context_refcount(ITfContext *iface)
1070 IUnknown_AddRef(iface);
1071 return IUnknown_Release(iface);
1074 static void test_startSession(void)
1079 ITfDocumentMgr *dmtest;
1080 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1082 TfClientId cid2 = 0;
1084 hr = ITfThreadMgr_Deactivate(g_tm);
1085 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1087 test_ShouldActivate = TRUE;
1088 hr = ITfThreadMgr_Activate(g_tm,&cid);
1089 ok(SUCCEEDED(hr),"Failed to Activate\n");
1090 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1092 test_ShouldActivate = FALSE;
1093 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1094 ok(SUCCEEDED(hr),"Failed to Activate\n");
1095 ok (cid == cid2, "Second activate client ID does not match\n");
1097 hr = ITfThreadMgr_Deactivate(g_tm);
1098 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1100 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1101 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1103 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1104 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1105 ok(dmtest == NULL,"Initial focus not null\n");
1107 test_CurrentFocus = g_dm;
1108 test_PrevFocus = NULL;
1109 test_OnSetFocus = SINK_EXPECTED;
1110 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1111 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1112 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1113 test_OnSetFocus = SINK_UNEXPECTED;
1115 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1116 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1117 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1119 cnt = ITfDocumentMgr_Release(g_dm);
1120 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1122 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1123 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1124 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1126 TextStoreACP_Constructor((IUnknown**)&ts);
1128 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1129 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1131 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1132 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1134 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1135 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1137 cnt = check_context_refcount(cxt);
1138 test_OnPushContext = SINK_EXPECTED;
1139 test_ACP_AdviseSink = SINK_EXPECTED;
1140 test_OnInitDocumentMgr = SINK_EXPECTED;
1141 hr = ITfDocumentMgr_Push(g_dm, cxt);
1142 ok(SUCCEEDED(hr),"Push Failed\n");
1143 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1144 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1145 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1146 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1148 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1149 ok(SUCCEEDED(hr),"GetTop Failed\n");
1150 ok(cxtTest == cxt, "Wrong context on top\n");
1151 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1152 cnt = ITfContext_Release(cxtTest);
1154 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1155 ok(SUCCEEDED(hr),"GetBase Failed\n");
1156 ok(cxtTest == cxt, "Wrong context on Base\n");
1157 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1158 ITfContext_Release(cxtTest);
1160 check_context_refcount(cxt2);
1161 test_OnPushContext = SINK_EXPECTED;
1162 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1163 ok(SUCCEEDED(hr),"Push Failed\n");
1164 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1166 cnt = check_context_refcount(cxt2);
1167 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1168 ok(SUCCEEDED(hr),"GetTop Failed\n");
1169 ok(cxtTest == cxt2, "Wrong context on top\n");
1170 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1171 ITfContext_Release(cxtTest);
1173 cnt = check_context_refcount(cxt);
1174 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1175 ok(SUCCEEDED(hr),"GetBase Failed\n");
1176 ok(cxtTest == cxt, "Wrong context on Base\n");
1177 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1178 ITfContext_Release(cxtTest);
1180 cnt = check_context_refcount(cxt3);
1181 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1182 ok(!SUCCEEDED(hr),"Push Succeeded\n");
1183 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1185 cnt = check_context_refcount(cxt2);
1186 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1187 ok(SUCCEEDED(hr),"GetTop Failed\n");
1188 ok(cxtTest == cxt2, "Wrong context on top\n");
1189 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1190 ITfContext_Release(cxtTest);
1192 cnt = check_context_refcount(cxt);
1193 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1194 ok(SUCCEEDED(hr),"GetBase Failed\n");
1195 ok(cxtTest == cxt, "Wrong context on Base\n");
1196 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1197 ITfContext_Release(cxtTest);
1199 cnt = check_context_refcount(cxt2);
1200 test_OnPopContext = SINK_EXPECTED;
1201 hr = ITfDocumentMgr_Pop(g_dm, 0);
1202 ok(SUCCEEDED(hr),"Pop Failed\n");
1203 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1204 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1206 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1207 ok(SUCCEEDED(hr),"GetTop Failed\n");
1208 ok(cxtTest == cxt, "Wrong context on top\n");
1209 ITfContext_Release(cxtTest);
1211 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1212 ok(SUCCEEDED(hr),"GetBase Failed\n");
1213 ok(cxtTest == cxt, "Wrong context on base\n");
1214 ITfContext_Release(cxtTest);
1216 hr = ITfDocumentMgr_Pop(g_dm, 0);
1217 ok(!SUCCEEDED(hr),"Pop Succeeded\n");
1219 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1220 ok(SUCCEEDED(hr),"GetTop Failed\n");
1221 ok(cxtTest == cxt, "Wrong context on top\n");
1222 ITfContext_Release(cxtTest);
1224 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1225 ok(SUCCEEDED(hr),"GetBase Failed\n");
1226 ok(cxtTest == cxt, "Wrong context on base\n");
1227 ITfContext_Release(cxtTest);
1229 ITfContext_Release(cxt);
1230 ITfContext_Release(cxt2);
1231 ITfContext_Release(cxt3);
1234 static void test_endSession(void)
1237 test_ShouldDeactivate = TRUE;
1238 test_CurrentFocus = NULL;
1239 test_PrevFocus = g_dm;
1240 test_OnSetFocus = SINK_EXPECTED;
1241 hr = ITfThreadMgr_Deactivate(g_tm);
1242 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1243 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1244 test_OnSetFocus = SINK_UNEXPECTED;
1247 static void test_TfGuidAtom(void)
1251 TfGuidAtom atom1,atom2;
1254 CoCreateGuid(>est);
1256 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1258 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1259 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1261 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1262 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1263 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1264 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1265 ok(atom1 == atom2,"atoms do not match\n");
1266 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1267 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1268 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1269 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1270 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1271 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1272 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1273 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1274 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1275 ok(equal == TRUE,"Equal value invalid\n");
1277 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1278 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1279 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1280 ok(equal == TRUE,"Equal value invalid\n");
1281 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1282 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1283 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1286 static void test_ClientId(void)
1293 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1294 ok(SUCCEEDED(hr),"Unable to aquire ITfClientId interface\n");
1298 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1299 ok(SUCCEEDED(hr),"GetClientId failed\n");
1300 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1301 ok(SUCCEEDED(hr),"GetClientId failed\n");
1302 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1303 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1304 ok(SUCCEEDED(hr),"GetClientId failed\n");
1305 ok(id2!=id1,"Id matches GUID_NULL\n");
1306 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1307 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1308 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1309 ok(SUCCEEDED(hr),"GetClientId failed\n");
1310 ok(id2!=id1,"Id matches GUID_NULL\n");
1311 ok(id2!=tid,"Id for random guid matching tid\n");
1312 ok(id2!=cid,"Id for random guid matching cid\n");
1313 ITfClientId_Release(pcid);
1316 /**********************************************************************
1318 **********************************************************************/
1319 typedef struct tagEditSession
1321 const ITfEditSessionVtbl *EditSessionVtbl;
1325 static void EditSession_Destructor(EditSession *This)
1327 HeapFree(GetProcessHeap(),0,This);
1330 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1332 EditSession *This = (EditSession *)iface;
1335 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1342 IUnknown_AddRef(iface);
1346 return E_NOINTERFACE;
1349 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1351 EditSession *This = (EditSession *)iface;
1352 return InterlockedIncrement(&This->refCount);
1355 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1357 EditSession *This = (EditSession *)iface;
1360 ret = InterlockedDecrement(&This->refCount);
1362 EditSession_Destructor(This);
1366 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1369 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1370 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1371 test_DoEditSession = SINK_FIRED;
1375 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1377 EditSession_QueryInterface,
1379 EditSession_Release,
1381 EditSession_DoEditSession
1384 HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1388 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1390 return E_OUTOFMEMORY;
1392 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1395 *ppOut = (ITfEditSession*)This;
1399 static void test_TStoApplicationText(void)
1401 HRESULT hr, hrSession;
1406 ITfThreadMgr_GetFocus(g_tm, &dm);
1407 EditSession_Constructor(&es);
1408 ITfDocumentMgr_GetTop(dm,&cxt);
1410 hrSession = 0xfeedface;
1411 /* Test no premissions flags */
1412 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1413 todo_wine ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1414 todo_wine ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1416 hrSession = 0xfeedface;
1417 test_ACP_GetStatus = SINK_EXPECTED;
1418 test_ACP_RequestLock = SINK_EXPECTED;
1419 hrSession = 0xfeedface;
1420 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1421 todo_wine ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1422 todo_wine ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1423 todo_wine ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1424 todo_wine ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1425 todo_wine ok(hrSession == 0xdeadcafe,"Unexpected hrSession\n");
1427 ITfContext_Release(cxt);
1428 ITfDocumentMgr_Release(dm);
1429 ITfEditSession_Release(es);
1432 START_TEST(inputprocessor)
1434 if (SUCCEEDED(initialize()))
1437 test_RegisterCategory();
1438 test_EnumInputProcessorInfo();
1440 test_ThreadMgrAdviseSinks();
1442 test_startSession();
1445 test_KeystrokeMgr();
1446 test_TStoApplicationText();
1448 test_EnumLanguageProfiles();
1449 test_FindClosestCategory();
1451 test_ThreadMgrUnadviseSinks();
1452 test_UnregisterCategory();
1456 skip("Unable to create InputProcessor\n");