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_ACP_GetEndACP = SINK_UNEXPECTED;
61 static INT test_ACP_GetSelection = SINK_UNEXPECTED;
62 static INT test_DoEditSession = SINK_UNEXPECTED;
65 /**********************************************************************
67 **********************************************************************/
68 typedef struct tagTextStoreACP
70 const ITextStoreACPVtbl *TextStoreACPVtbl;
73 ITextStoreACPSink *sink;
76 static void TextStoreACP_Destructor(TextStoreACP *This)
78 HeapFree(GetProcessHeap(),0,This);
81 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
83 TextStoreACP *This = (TextStoreACP *)iface;
86 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
93 IUnknown_AddRef(iface);
100 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
102 TextStoreACP *This = (TextStoreACP *)iface;
103 return InterlockedIncrement(&This->refCount);
106 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
108 TextStoreACP *This = (TextStoreACP *)iface;
111 ret = InterlockedDecrement(&This->refCount);
113 TextStoreACP_Destructor(This);
117 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
118 REFIID riid, IUnknown *punk, DWORD dwMask)
120 TextStoreACP *This = (TextStoreACP *)iface;
123 ok(test_ACP_AdviseSink == SINK_EXPECTED, "Unexpected TextStoreACP_AdviseSink sink\n");
124 test_ACP_AdviseSink = SINK_FIRED;
126 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&This->sink));
127 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
131 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
138 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
139 DWORD dwLockFlags, HRESULT *phrSession)
141 TextStoreACP *This = (TextStoreACP *)iface;
143 ok(test_ACP_RequestLock == SINK_EXPECTED,"Unexpected TextStoreACP_RequestLock\n");
144 test_ACP_RequestLock = SINK_FIRED;
145 test_DoEditSession = SINK_EXPECTED;
146 *phrSession = ITextStoreACPSink_OnLockGranted(This->sink, TS_LF_READWRITE);
147 ok(test_DoEditSession = SINK_FIRED,"expected DoEditSession not fired\n");
148 ok(*phrSession == 0xdeadcafe,"Unexpected return from ITextStoreACPSink_OnLockGranted\n");
151 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
154 static UINT count = 0;
158 ok(test_ACP_GetStatus == SINK_EXPECTED, "Unexpected TextStoreACP_GetStatus\n");
160 todo_wine ok(count == 1,"GetStatus called too many times\n");
161 test_ACP_GetStatus = SINK_FIRED;
162 pdcs->dwDynamicFlags = TS_SD_READONLY;
165 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
166 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
172 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
173 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
175 ok(test_ACP_GetSelection == SINK_EXPECTED, "Unexpected TextStoreACP_GetSelection\n");
176 test_ACP_GetSelection = SINK_FIRED;
178 pSelection->acpStart = 10;
179 pSelection->acpEnd = 20;
180 pSelection->style.fInterimChar = 0;
181 pSelection->style.ase = TS_AE_NONE;
186 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
187 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
192 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
193 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
194 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
195 ULONG *pcRunInfoRet, LONG *pacpNext)
200 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
201 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
202 ULONG cch, TS_TEXTCHANGE *pChange)
207 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
208 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
213 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
214 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
219 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
220 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
225 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
226 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
227 TS_TEXTCHANGE *pChange)
232 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
233 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
234 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
239 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
240 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
241 TS_TEXTCHANGE *pChange)
246 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
247 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
252 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
253 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
259 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
260 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
266 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
267 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
268 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
273 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
274 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
279 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
282 ok(test_ACP_GetEndACP == SINK_EXPECTED,"Unexpected TextStoreACP_GetEndACP\n");
283 test_ACP_GetEndACP = SINK_FIRED;
286 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
287 TsViewCookie *pvcView)
292 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
293 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
299 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
300 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
306 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
307 TsViewCookie vcView, RECT *prc)
312 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
313 TsViewCookie vcView, HWND *phwnd)
319 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
321 TextStoreACP_QueryInterface,
323 TextStoreACP_Release,
325 TextStoreACP_AdviseSink,
326 TextStoreACP_UnadviseSink,
327 TextStoreACP_RequestLock,
328 TextStoreACP_GetStatus,
329 TextStoreACP_QueryInsert,
330 TextStoreACP_GetSelection,
331 TextStoreACP_SetSelection,
332 TextStoreACP_GetText,
333 TextStoreACP_SetText,
334 TextStoreACP_GetFormattedText,
335 TextStoreACP_GetEmbedded,
336 TextStoreACP_QueryInsertEmbedded,
337 TextStoreACP_InsertEmbedded,
338 TextStoreACP_InsertTextAtSelection,
339 TextStoreACP_InsertEmbeddedAtSelection,
340 TextStoreACP_RequestSupportedAttrs,
341 TextStoreACP_RequestAttrsAtPosition,
342 TextStoreACP_RequestAttrsTransitioningAtPosition,
343 TextStoreACP_FindNextAttrTransition,
344 TextStoreACP_RetrieveRequestedAttrs,
345 TextStoreACP_GetEndACP,
346 TextStoreACP_GetActiveView,
347 TextStoreACP_GetACPFromPoint,
348 TextStoreACP_GetTextExt,
349 TextStoreACP_GetScreenExt,
353 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
357 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
359 return E_OUTOFMEMORY;
361 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
364 *ppOut = (IUnknown *)This;
368 /**********************************************************************
369 * ITfThreadMgrEventSink
370 **********************************************************************/
371 typedef struct tagThreadMgrEventSink
373 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
375 } ThreadMgrEventSink;
377 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
379 HeapFree(GetProcessHeap(),0,This);
382 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
384 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
387 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
394 IUnknown_AddRef(iface);
398 return E_NOINTERFACE;
401 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
403 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
404 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
405 return InterlockedIncrement(&This->refCount);
408 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
410 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
413 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
414 ret = InterlockedDecrement(&This->refCount);
416 ThreadMgrEventSink_Destructor(This);
420 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
421 ITfDocumentMgr *pdim)
423 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
424 test_OnInitDocumentMgr = SINK_FIRED;
428 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
429 ITfDocumentMgr *pdim)
435 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
436 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
438 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
439 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
440 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
441 test_OnSetFocus = SINK_FIRED;
445 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
448 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
449 test_OnPushContext = SINK_FIRED;
453 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
456 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
457 test_OnPopContext = SINK_FIRED;
461 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
463 ThreadMgrEventSink_QueryInterface,
464 ThreadMgrEventSink_AddRef,
465 ThreadMgrEventSink_Release,
467 ThreadMgrEventSink_OnInitDocumentMgr,
468 ThreadMgrEventSink_OnUninitDocumentMgr,
469 ThreadMgrEventSink_OnSetFocus,
470 ThreadMgrEventSink_OnPushContext,
471 ThreadMgrEventSink_OnPopContext
474 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
476 ThreadMgrEventSink *This;
478 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
480 return E_OUTOFMEMORY;
482 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
485 *ppOut = (IUnknown *)This;
490 /********************************************************************************************
491 * Stub text service for testing
492 ********************************************************************************************/
494 static LONG TS_refCount;
495 static IClassFactory *cf;
498 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
500 typedef struct tagClassFactory
502 const IClassFactoryVtbl *vtbl;
504 LPFNCONSTRUCTOR ctor;
507 typedef struct tagTextService
509 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
513 static void ClassFactory_Destructor(ClassFactory *This)
515 HeapFree(GetProcessHeap(),0,This);
519 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
522 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
524 IClassFactory_AddRef(iface);
529 return E_NOINTERFACE;
532 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
534 ClassFactory *This = (ClassFactory *)iface;
535 return InterlockedIncrement(&This->ref);
538 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
540 ClassFactory *This = (ClassFactory *)iface;
541 ULONG ret = InterlockedDecrement(&This->ref);
544 ClassFactory_Destructor(This);
548 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
550 ClassFactory *This = (ClassFactory *)iface;
554 ret = This->ctor(punkOuter, &obj);
557 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
558 IUnknown_Release(obj);
562 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
565 InterlockedIncrement(&TS_refCount);
567 InterlockedDecrement(&TS_refCount);
572 static const IClassFactoryVtbl ClassFactoryVtbl = {
574 ClassFactory_QueryInterface,
576 ClassFactory_Release,
579 ClassFactory_CreateInstance,
580 ClassFactory_LockServer
583 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
585 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
586 This->vtbl = &ClassFactoryVtbl;
589 *ppvOut = (LPVOID)This;
594 static void TextService_Destructor(TextService *This)
596 HeapFree(GetProcessHeap(),0,This);
599 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
601 TextService *This = (TextService *)iface;
604 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
611 IUnknown_AddRef(iface);
615 return E_NOINTERFACE;
618 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
620 TextService *This = (TextService *)iface;
621 return InterlockedIncrement(&This->refCount);
624 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
626 TextService *This = (TextService *)iface;
629 ret = InterlockedDecrement(&This->refCount);
631 TextService_Destructor(This);
635 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
636 ITfThreadMgr *ptim, TfClientId id)
638 trace("TextService_Activate\n");
639 ok(test_ShouldActivate,"Activation came unexpectedly\n");
644 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
646 trace("TextService_Deactivate\n");
647 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
651 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
653 TextService_QueryInterface,
657 TextService_Activate,
658 TextService_Deactivate
661 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
665 return CLASS_E_NOAGGREGATION;
667 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
669 return E_OUTOFMEMORY;
671 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
674 *ppOut = (IUnknown *)This;
678 static HRESULT RegisterTextService(REFCLSID rclsid)
680 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
681 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
684 static HRESULT UnregisterTextService()
686 return CoRevokeClassObject(regid);
693 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
694 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
695 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
696 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
697 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
698 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
699 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
700 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
701 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
702 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
705 static HRESULT initialize(void)
709 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
710 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
712 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
713 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
715 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
716 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
720 static void cleanup(void)
723 ITfInputProcessorProfiles_Release(g_ipp);
725 ITfCategoryMgr_Release(g_cm);
727 ITfThreadMgr_Release(g_tm);
731 static void test_Register(void)
735 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
736 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
738 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
739 ok(SUCCEEDED(hr),"Unable to get current language id\n");
740 trace("Current Language %x\n",gLangid);
742 hr = RegisterTextService(&CLSID_FakeService);
743 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
744 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
745 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
746 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
747 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
750 static void test_Unregister(void)
753 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
754 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
755 UnregisterTextService();
758 static void test_EnumInputProcessorInfo(void)
763 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
767 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
769 if(IsEqualGUID(&g,&CLSID_FakeService))
773 ok(found,"Did not find registered text service\n");
776 static void test_EnumLanguageProfiles(void)
779 IEnumTfLanguageProfiles *ppEnum;
780 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
782 TF_LANGUAGEPROFILE profile;
783 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
785 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
788 ok(profile.langid == gLangid, "LangId Incorrect\n");
789 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
790 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
794 ok(found,"Registered text service not found\n");
797 static void test_RegisterCategory(void)
800 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
801 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
802 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
803 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
806 static void test_UnregisterCategory(void)
809 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
810 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
811 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
812 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
815 static void test_FindClosestCategory(void)
819 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
821 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
822 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
823 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
825 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
826 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
827 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
829 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
830 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
831 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
834 static void test_Enable(void)
837 BOOL enabled = FALSE;
839 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
840 ok(SUCCEEDED(hr),"Failed to enable text service\n");
841 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
842 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
843 ok(enabled == TRUE,"enabled state incorrect\n");
846 static void test_Disable(void)
850 trace("Disabling\n");
851 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
852 ok(SUCCEEDED(hr),"Failed to disable text service\n");
855 static void test_ThreadMgrAdviseSinks(void)
857 ITfSource *source = NULL;
861 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
862 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
866 hr = ThreadMgrEventSink_Constructor(&sink);
867 ok(hr == S_OK, "got %08x\n", hr);
868 if(FAILED(hr)) return;
872 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
873 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
874 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
876 /* Advising the sink adds a ref, Relesing here lets the object be deleted
879 IUnknown_Release(sink);
880 ITfSource_Release(source);
883 static void test_ThreadMgrUnadviseSinks(void)
885 ITfSource *source = NULL;
888 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
889 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
894 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
895 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
896 ITfSource_Release(source);
899 /**********************************************************************
901 **********************************************************************/
902 typedef struct tagKeyEventSink
904 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
908 static void KeyEventSink_Destructor(KeyEventSink *This)
910 HeapFree(GetProcessHeap(),0,This);
913 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
915 KeyEventSink *This = (KeyEventSink *)iface;
918 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
925 IUnknown_AddRef(iface);
929 return E_NOINTERFACE;
932 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
934 KeyEventSink *This = (KeyEventSink *)iface;
935 return InterlockedIncrement(&This->refCount);
938 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
940 KeyEventSink *This = (KeyEventSink *)iface;
943 ret = InterlockedDecrement(&This->refCount);
945 KeyEventSink_Destructor(This);
949 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
952 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
953 test_KEV_OnSetFocus = SINK_FIRED;
957 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
958 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
964 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
965 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
971 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
972 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
978 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
979 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
985 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
986 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
992 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
994 KeyEventSink_QueryInterface,
996 KeyEventSink_Release,
998 KeyEventSink_OnSetFocus,
999 KeyEventSink_OnTestKeyDown,
1000 KeyEventSink_OnTestKeyUp,
1001 KeyEventSink_OnKeyDown,
1002 KeyEventSink_OnKeyUp,
1003 KeyEventSink_OnPreservedKey
1006 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1010 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1012 return E_OUTOFMEMORY;
1014 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1017 *ppOut = (ITfKeyEventSink*)This;
1022 static void test_KeystrokeMgr(void)
1024 ITfKeystrokeMgr *keymgr= NULL;
1026 TF_PRESERVEDKEY tfpk;
1028 ITfKeyEventSink *sink = NULL;
1030 KeyEventSink_Constructor(&sink);
1032 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1033 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1036 tfpk.uModifiers = TF_MOD_SHIFT;
1038 test_KEV_OnSetFocus = SINK_EXPECTED;
1039 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1040 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1041 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1042 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1043 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1044 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1045 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1047 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1048 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1050 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1051 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1053 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1054 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1057 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1058 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1059 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1061 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1062 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1064 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1065 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1066 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1068 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1069 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1071 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1072 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1074 ITfKeystrokeMgr_Release(keymgr);
1075 ITfKeyEventSink_Release(sink);
1078 static void test_Activate(void)
1082 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1083 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1086 static inline int check_context_refcount(ITfContext *iface)
1088 IUnknown_AddRef(iface);
1089 return IUnknown_Release(iface);
1092 static void test_startSession(void)
1097 ITfDocumentMgr *dmtest;
1098 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1100 TfClientId cid2 = 0;
1102 hr = ITfThreadMgr_Deactivate(g_tm);
1103 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1105 test_ShouldActivate = TRUE;
1106 hr = ITfThreadMgr_Activate(g_tm,&cid);
1107 ok(SUCCEEDED(hr),"Failed to Activate\n");
1108 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1110 test_ShouldActivate = FALSE;
1111 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1112 ok(SUCCEEDED(hr),"Failed to Activate\n");
1113 ok (cid == cid2, "Second activate client ID does not match\n");
1115 hr = ITfThreadMgr_Deactivate(g_tm);
1116 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1118 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1119 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1121 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1122 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1123 ok(dmtest == NULL,"Initial focus not null\n");
1125 test_CurrentFocus = g_dm;
1126 test_PrevFocus = NULL;
1127 test_OnSetFocus = SINK_EXPECTED;
1128 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1129 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1130 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1131 test_OnSetFocus = SINK_UNEXPECTED;
1133 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1134 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1135 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1137 cnt = ITfDocumentMgr_Release(g_dm);
1138 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1140 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1141 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1142 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1144 TextStoreACP_Constructor((IUnknown**)&ts);
1146 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1147 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1149 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1150 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1152 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1153 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1155 cnt = check_context_refcount(cxt);
1156 test_OnPushContext = SINK_EXPECTED;
1157 test_ACP_AdviseSink = SINK_EXPECTED;
1158 test_OnInitDocumentMgr = SINK_EXPECTED;
1159 hr = ITfDocumentMgr_Push(g_dm, cxt);
1160 ok(SUCCEEDED(hr),"Push Failed\n");
1161 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1162 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1163 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1164 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1166 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1167 ok(SUCCEEDED(hr),"GetTop Failed\n");
1168 ok(cxtTest == cxt, "Wrong context on top\n");
1169 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1170 cnt = ITfContext_Release(cxtTest);
1172 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1173 ok(SUCCEEDED(hr),"GetBase Failed\n");
1174 ok(cxtTest == cxt, "Wrong context on Base\n");
1175 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1176 ITfContext_Release(cxtTest);
1178 check_context_refcount(cxt2);
1179 test_OnPushContext = SINK_EXPECTED;
1180 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1181 ok(SUCCEEDED(hr),"Push Failed\n");
1182 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1184 cnt = check_context_refcount(cxt2);
1185 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1186 ok(SUCCEEDED(hr),"GetTop Failed\n");
1187 ok(cxtTest == cxt2, "Wrong context on top\n");
1188 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1189 ITfContext_Release(cxtTest);
1191 cnt = check_context_refcount(cxt);
1192 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1193 ok(SUCCEEDED(hr),"GetBase Failed\n");
1194 ok(cxtTest == cxt, "Wrong context on Base\n");
1195 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1196 ITfContext_Release(cxtTest);
1198 cnt = check_context_refcount(cxt3);
1199 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1200 ok(FAILED(hr),"Push Succeeded\n");
1201 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1203 cnt = check_context_refcount(cxt2);
1204 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1205 ok(SUCCEEDED(hr),"GetTop Failed\n");
1206 ok(cxtTest == cxt2, "Wrong context on top\n");
1207 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1208 ITfContext_Release(cxtTest);
1210 cnt = check_context_refcount(cxt);
1211 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1212 ok(SUCCEEDED(hr),"GetBase Failed\n");
1213 ok(cxtTest == cxt, "Wrong context on Base\n");
1214 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1215 ITfContext_Release(cxtTest);
1217 cnt = check_context_refcount(cxt2);
1218 test_OnPopContext = SINK_EXPECTED;
1219 hr = ITfDocumentMgr_Pop(g_dm, 0);
1220 ok(SUCCEEDED(hr),"Pop Failed\n");
1221 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1222 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1224 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1225 ok(SUCCEEDED(hr),"GetTop Failed\n");
1226 ok(cxtTest == cxt, "Wrong context on top\n");
1227 ITfContext_Release(cxtTest);
1229 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1230 ok(SUCCEEDED(hr),"GetBase Failed\n");
1231 ok(cxtTest == cxt, "Wrong context on base\n");
1232 ITfContext_Release(cxtTest);
1234 hr = ITfDocumentMgr_Pop(g_dm, 0);
1235 ok(FAILED(hr),"Pop Succeeded\n");
1237 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1238 ok(SUCCEEDED(hr),"GetTop Failed\n");
1239 ok(cxtTest == cxt, "Wrong context on top\n");
1240 ITfContext_Release(cxtTest);
1242 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1243 ok(SUCCEEDED(hr),"GetBase Failed\n");
1244 ok(cxtTest == cxt, "Wrong context on base\n");
1245 ITfContext_Release(cxtTest);
1247 ITfContext_Release(cxt);
1248 ITfContext_Release(cxt2);
1249 ITfContext_Release(cxt3);
1252 static void test_endSession(void)
1255 test_ShouldDeactivate = TRUE;
1256 test_CurrentFocus = NULL;
1257 test_PrevFocus = g_dm;
1258 test_OnSetFocus = SINK_EXPECTED;
1259 hr = ITfThreadMgr_Deactivate(g_tm);
1260 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1261 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1262 test_OnSetFocus = SINK_UNEXPECTED;
1265 static void test_TfGuidAtom(void)
1269 TfGuidAtom atom1,atom2;
1272 CoCreateGuid(>est);
1274 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1276 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1277 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1279 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1280 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1281 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1282 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1283 ok(atom1 == atom2,"atoms do not match\n");
1284 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1285 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1286 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1287 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1288 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1289 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1290 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1291 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1292 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1293 ok(equal == TRUE,"Equal value invalid\n");
1295 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1296 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1297 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1298 ok(equal == TRUE,"Equal value invalid\n");
1299 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1300 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1301 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1304 static void test_ClientId(void)
1311 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1312 ok(SUCCEEDED(hr),"Unable to aquire ITfClientId interface\n");
1316 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1317 ok(SUCCEEDED(hr),"GetClientId failed\n");
1318 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1319 ok(SUCCEEDED(hr),"GetClientId failed\n");
1320 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1321 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1322 ok(SUCCEEDED(hr),"GetClientId failed\n");
1323 ok(id2!=id1,"Id matches GUID_NULL\n");
1324 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1325 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1326 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1327 ok(SUCCEEDED(hr),"GetClientId failed\n");
1328 ok(id2!=id1,"Id matches GUID_NULL\n");
1329 ok(id2!=tid,"Id for random guid matching tid\n");
1330 ok(id2!=cid,"Id for random guid matching cid\n");
1331 ITfClientId_Release(pcid);
1334 /**********************************************************************
1336 **********************************************************************/
1337 typedef struct tagEditSession
1339 const ITfEditSessionVtbl *EditSessionVtbl;
1343 static void EditSession_Destructor(EditSession *This)
1345 HeapFree(GetProcessHeap(),0,This);
1348 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1350 EditSession *This = (EditSession *)iface;
1353 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1360 IUnknown_AddRef(iface);
1364 return E_NOINTERFACE;
1367 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1369 EditSession *This = (EditSession *)iface;
1370 return InterlockedIncrement(&This->refCount);
1373 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1375 EditSession *This = (EditSession *)iface;
1378 ret = InterlockedDecrement(&This->refCount);
1380 EditSession_Destructor(This);
1384 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1390 TF_SELECTION selection;
1394 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1395 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1396 test_DoEditSession = SINK_FIRED;
1398 ITfThreadMgr_GetFocus(g_tm, &dm);
1399 ITfDocumentMgr_GetTop(dm,&cxt);
1401 hr = ITfContext_GetStart(cxt,ec,NULL);
1402 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1404 range = (ITfRange*)0xdeaddead;
1405 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1406 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1407 ok(range == NULL,"Range not set to NULL\n");
1409 hr = ITfContext_GetStart(cxt,ec,&range);
1410 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1411 ok(range != NULL,"Range set to NULL\n");
1413 ITfRange_Release(range);
1415 hr = ITfContext_GetEnd(cxt,ec,NULL);
1416 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1418 range = (ITfRange*)0xdeaddead;
1419 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1420 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1421 ok(range == NULL,"Range not set to NULL\n");
1423 test_ACP_GetEndACP = SINK_EXPECTED;
1424 hr = ITfContext_GetEnd(cxt,ec,&range);
1425 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1426 ok(range != NULL,"Range set to NULL\n");
1427 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1429 ITfRange_Release(range);
1431 selection.range = NULL;
1432 test_ACP_GetSelection = SINK_EXPECTED;
1433 hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1434 ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1435 ok(fetched == 1,"fetched incorrect\n");
1436 ok(selection.range != NULL,"NULL range\n");
1437 ok(test_ACP_GetSelection == SINK_FIRED," expected ACP_GetSepection not fired\n");
1438 ITfRange_Release(selection.range);
1440 ITfContext_Release(cxt);
1441 ITfDocumentMgr_Release(dm);
1445 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1447 EditSession_QueryInterface,
1449 EditSession_Release,
1451 EditSession_DoEditSession
1454 HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1458 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1460 return E_OUTOFMEMORY;
1462 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1465 *ppOut = (ITfEditSession*)This;
1469 static void test_TStoApplicationText(void)
1471 HRESULT hr, hrSession;
1476 ITfThreadMgr_GetFocus(g_tm, &dm);
1477 EditSession_Constructor(&es);
1478 ITfDocumentMgr_GetTop(dm,&cxt);
1480 hrSession = 0xfeedface;
1481 /* Test no premissions flags */
1482 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1483 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1484 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1486 hrSession = 0xfeedface;
1487 test_ACP_GetStatus = SINK_EXPECTED;
1488 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1489 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1490 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1491 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1493 test_ACP_GetStatus = SINK_UNEXPECTED;
1494 test_ACP_RequestLock = SINK_EXPECTED;
1495 hrSession = 0xfeedface;
1496 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READ, &hrSession);
1497 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1498 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1499 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1500 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1502 ITfContext_Release(cxt);
1503 ITfDocumentMgr_Release(dm);
1504 ITfEditSession_Release(es);
1507 START_TEST(inputprocessor)
1509 if (SUCCEEDED(initialize()))
1512 test_RegisterCategory();
1513 test_EnumInputProcessorInfo();
1515 test_ThreadMgrAdviseSinks();
1517 test_startSession();
1520 test_KeystrokeMgr();
1521 test_TStoApplicationText();
1523 test_EnumLanguageProfiles();
1524 test_FindClosestCategory();
1526 test_ThreadMgrUnadviseSinks();
1527 test_UnregisterCategory();
1531 skip("Unable to create InputProcessor\n");