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 static ITextStoreACPSink *ACPSink;
43 #define SINK_UNEXPECTED 0
44 #define SINK_EXPECTED 1
47 static BOOL test_ShouldActivate = FALSE;
48 static BOOL test_ShouldDeactivate = FALSE;
50 static DWORD tmSinkCookie;
51 static DWORD tmSinkRefCount;
52 static DWORD documentStatus;
53 static ITfDocumentMgr *test_CurrentFocus = NULL;
54 static ITfDocumentMgr *test_PrevFocus = NULL;
55 static INT test_OnSetFocus = SINK_UNEXPECTED;
56 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
57 static INT test_OnPushContext = SINK_UNEXPECTED;
58 static INT test_OnPopContext = SINK_UNEXPECTED;
59 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
60 static INT test_ACP_AdviseSink = SINK_UNEXPECTED;
61 static INT test_ACP_GetStatus = SINK_UNEXPECTED;
62 static INT test_ACP_RequestLock = SINK_UNEXPECTED;
63 static INT test_ACP_GetEndACP = SINK_UNEXPECTED;
64 static INT test_ACP_GetSelection = SINK_UNEXPECTED;
65 static INT test_DoEditSession = SINK_UNEXPECTED;
66 static INT test_ACP_InsertTextAtSelection = SINK_UNEXPECTED;
69 /**********************************************************************
71 **********************************************************************/
72 typedef struct tagTextStoreACP
74 const ITextStoreACPVtbl *TextStoreACPVtbl;
79 static void TextStoreACP_Destructor(TextStoreACP *This)
81 HeapFree(GetProcessHeap(),0,This);
84 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
86 TextStoreACP *This = (TextStoreACP *)iface;
89 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
96 IUnknown_AddRef(iface);
100 return E_NOINTERFACE;
103 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
105 TextStoreACP *This = (TextStoreACP *)iface;
106 return InterlockedIncrement(&This->refCount);
109 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
111 TextStoreACP *This = (TextStoreACP *)iface;
114 ret = InterlockedDecrement(&This->refCount);
116 TextStoreACP_Destructor(This);
120 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
121 REFIID riid, IUnknown *punk, DWORD dwMask)
125 ok(test_ACP_AdviseSink == SINK_EXPECTED, "Unexpected TextStoreACP_AdviseSink sink\n");
126 test_ACP_AdviseSink = SINK_FIRED;
128 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&ACPSink));
129 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
133 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
140 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
141 DWORD dwLockFlags, HRESULT *phrSession)
143 ok(test_ACP_RequestLock == SINK_EXPECTED,"Unexpected TextStoreACP_RequestLock\n");
144 test_ACP_RequestLock = SINK_FIRED;
145 *phrSession = ITextStoreACPSink_OnLockGranted(ACPSink, dwLockFlags);
148 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
151 ok(test_ACP_GetStatus == SINK_EXPECTED, "Unexpected TextStoreACP_GetStatus\n");
152 test_ACP_GetStatus = SINK_FIRED;
153 pdcs->dwDynamicFlags = documentStatus;
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)
166 ok(test_ACP_GetSelection == SINK_EXPECTED, "Unexpected TextStoreACP_GetSelection\n");
167 test_ACP_GetSelection = SINK_FIRED;
169 pSelection->acpStart = 10;
170 pSelection->acpEnd = 20;
171 pSelection->style.fInterimChar = 0;
172 pSelection->style.ase = TS_AE_NONE;
177 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
178 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
183 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
184 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
185 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
186 ULONG *pcRunInfoRet, LONG *pacpNext)
191 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
192 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
193 ULONG cch, TS_TEXTCHANGE *pChange)
198 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
199 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
204 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
205 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
210 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
211 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
216 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
217 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
218 TS_TEXTCHANGE *pChange)
223 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
224 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
225 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
227 ok(test_ACP_InsertTextAtSelection == SINK_EXPECTED,"Unexpected TextStoreACP_InsertTextAtSelection\n");
228 test_ACP_InsertTextAtSelection = SINK_FIRED;
231 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
232 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
233 TS_TEXTCHANGE *pChange)
238 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
239 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
244 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
245 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
251 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
252 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
258 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
259 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
260 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
265 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
266 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
271 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
274 ok(test_ACP_GetEndACP == SINK_EXPECTED,"Unexpected TextStoreACP_GetEndACP\n");
275 test_ACP_GetEndACP = SINK_FIRED;
278 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
279 TsViewCookie *pvcView)
284 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
285 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
291 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
292 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
298 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
299 TsViewCookie vcView, RECT *prc)
304 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
305 TsViewCookie vcView, HWND *phwnd)
311 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
313 TextStoreACP_QueryInterface,
315 TextStoreACP_Release,
317 TextStoreACP_AdviseSink,
318 TextStoreACP_UnadviseSink,
319 TextStoreACP_RequestLock,
320 TextStoreACP_GetStatus,
321 TextStoreACP_QueryInsert,
322 TextStoreACP_GetSelection,
323 TextStoreACP_SetSelection,
324 TextStoreACP_GetText,
325 TextStoreACP_SetText,
326 TextStoreACP_GetFormattedText,
327 TextStoreACP_GetEmbedded,
328 TextStoreACP_QueryInsertEmbedded,
329 TextStoreACP_InsertEmbedded,
330 TextStoreACP_InsertTextAtSelection,
331 TextStoreACP_InsertEmbeddedAtSelection,
332 TextStoreACP_RequestSupportedAttrs,
333 TextStoreACP_RequestAttrsAtPosition,
334 TextStoreACP_RequestAttrsTransitioningAtPosition,
335 TextStoreACP_FindNextAttrTransition,
336 TextStoreACP_RetrieveRequestedAttrs,
337 TextStoreACP_GetEndACP,
338 TextStoreACP_GetActiveView,
339 TextStoreACP_GetACPFromPoint,
340 TextStoreACP_GetTextExt,
341 TextStoreACP_GetScreenExt,
345 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
349 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
351 return E_OUTOFMEMORY;
353 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
356 *ppOut = (IUnknown *)This;
360 /**********************************************************************
361 * ITfThreadMgrEventSink
362 **********************************************************************/
363 typedef struct tagThreadMgrEventSink
365 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
367 } ThreadMgrEventSink;
369 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
371 HeapFree(GetProcessHeap(),0,This);
374 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
376 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
379 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
386 IUnknown_AddRef(iface);
390 return E_NOINTERFACE;
393 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
395 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
396 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
397 return InterlockedIncrement(&This->refCount);
400 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
402 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
405 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
406 ret = InterlockedDecrement(&This->refCount);
408 ThreadMgrEventSink_Destructor(This);
412 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
413 ITfDocumentMgr *pdim)
415 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
416 test_OnInitDocumentMgr = SINK_FIRED;
420 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
421 ITfDocumentMgr *pdim)
427 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
428 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
430 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
431 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
432 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
433 test_OnSetFocus = SINK_FIRED;
437 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
440 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
441 test_OnPushContext = SINK_FIRED;
445 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
448 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
449 test_OnPopContext = SINK_FIRED;
453 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
455 ThreadMgrEventSink_QueryInterface,
456 ThreadMgrEventSink_AddRef,
457 ThreadMgrEventSink_Release,
459 ThreadMgrEventSink_OnInitDocumentMgr,
460 ThreadMgrEventSink_OnUninitDocumentMgr,
461 ThreadMgrEventSink_OnSetFocus,
462 ThreadMgrEventSink_OnPushContext,
463 ThreadMgrEventSink_OnPopContext
466 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
468 ThreadMgrEventSink *This;
470 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
472 return E_OUTOFMEMORY;
474 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
477 *ppOut = (IUnknown *)This;
482 /********************************************************************************************
483 * Stub text service for testing
484 ********************************************************************************************/
486 static LONG TS_refCount;
487 static IClassFactory *cf;
490 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
492 typedef struct tagClassFactory
494 const IClassFactoryVtbl *vtbl;
496 LPFNCONSTRUCTOR ctor;
499 typedef struct tagTextService
501 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
505 static void ClassFactory_Destructor(ClassFactory *This)
507 HeapFree(GetProcessHeap(),0,This);
511 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
514 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
516 IClassFactory_AddRef(iface);
521 return E_NOINTERFACE;
524 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
526 ClassFactory *This = (ClassFactory *)iface;
527 return InterlockedIncrement(&This->ref);
530 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
532 ClassFactory *This = (ClassFactory *)iface;
533 ULONG ret = InterlockedDecrement(&This->ref);
536 ClassFactory_Destructor(This);
540 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
542 ClassFactory *This = (ClassFactory *)iface;
546 ret = This->ctor(punkOuter, &obj);
549 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
550 IUnknown_Release(obj);
554 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
557 InterlockedIncrement(&TS_refCount);
559 InterlockedDecrement(&TS_refCount);
564 static const IClassFactoryVtbl ClassFactoryVtbl = {
566 ClassFactory_QueryInterface,
568 ClassFactory_Release,
571 ClassFactory_CreateInstance,
572 ClassFactory_LockServer
575 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
577 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
578 This->vtbl = &ClassFactoryVtbl;
581 *ppvOut = (LPVOID)This;
586 static void TextService_Destructor(TextService *This)
588 HeapFree(GetProcessHeap(),0,This);
591 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
593 TextService *This = (TextService *)iface;
596 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
603 IUnknown_AddRef(iface);
607 return E_NOINTERFACE;
610 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
612 TextService *This = (TextService *)iface;
613 return InterlockedIncrement(&This->refCount);
616 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
618 TextService *This = (TextService *)iface;
621 ret = InterlockedDecrement(&This->refCount);
623 TextService_Destructor(This);
627 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
628 ITfThreadMgr *ptim, TfClientId id)
630 trace("TextService_Activate\n");
631 ok(test_ShouldActivate,"Activation came unexpectedly\n");
636 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
638 trace("TextService_Deactivate\n");
639 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
643 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
645 TextService_QueryInterface,
649 TextService_Activate,
650 TextService_Deactivate
653 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
657 return CLASS_E_NOAGGREGATION;
659 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
661 return E_OUTOFMEMORY;
663 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
666 *ppOut = (IUnknown *)This;
670 static HRESULT RegisterTextService(REFCLSID rclsid)
672 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
673 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
676 static HRESULT UnregisterTextService()
678 return CoRevokeClassObject(regid);
685 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
686 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
687 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
688 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
689 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
690 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
691 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
692 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
693 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
694 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
697 static HRESULT initialize(void)
701 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
702 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
704 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
705 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
707 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
708 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
712 static void cleanup(void)
715 ITfInputProcessorProfiles_Release(g_ipp);
717 ITfCategoryMgr_Release(g_cm);
719 ITfThreadMgr_Release(g_tm);
723 static void test_Register(void)
727 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
728 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
730 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
731 ok(SUCCEEDED(hr),"Unable to get current language id\n");
732 trace("Current Language %x\n",gLangid);
734 hr = RegisterTextService(&CLSID_FakeService);
735 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
736 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
737 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
738 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
739 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
742 static void test_Unregister(void)
745 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
746 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
747 UnregisterTextService();
750 static void test_EnumInputProcessorInfo(void)
755 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
759 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
761 if(IsEqualGUID(&g,&CLSID_FakeService))
765 ok(found,"Did not find registered text service\n");
768 static void test_EnumLanguageProfiles(void)
771 IEnumTfLanguageProfiles *ppEnum;
772 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
774 TF_LANGUAGEPROFILE profile;
775 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
777 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
780 ok(profile.langid == gLangid, "LangId Incorrect\n");
781 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
782 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
786 ok(found,"Registered text service not found\n");
789 static void test_RegisterCategory(void)
792 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
793 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
794 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
795 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
798 static void test_UnregisterCategory(void)
801 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
802 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
803 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
804 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
807 static void test_FindClosestCategory(void)
811 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
813 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
814 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
815 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
817 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
818 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
819 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
821 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
822 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
823 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
826 static void test_Enable(void)
829 BOOL enabled = FALSE;
831 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
832 ok(SUCCEEDED(hr),"Failed to enable text service\n");
833 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
834 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
835 ok(enabled == TRUE,"enabled state incorrect\n");
838 static void test_Disable(void)
842 trace("Disabling\n");
843 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
844 ok(SUCCEEDED(hr),"Failed to disable text service\n");
847 static void test_ThreadMgrAdviseSinks(void)
849 ITfSource *source = NULL;
853 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
854 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
858 hr = ThreadMgrEventSink_Constructor(&sink);
859 ok(hr == S_OK, "got %08x\n", hr);
860 if(FAILED(hr)) return;
864 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
865 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
866 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
868 /* Advising the sink adds a ref, Relesing here lets the object be deleted
871 IUnknown_Release(sink);
872 ITfSource_Release(source);
875 static void test_ThreadMgrUnadviseSinks(void)
877 ITfSource *source = NULL;
880 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
881 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
886 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
887 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
888 ITfSource_Release(source);
891 /**********************************************************************
893 **********************************************************************/
894 typedef struct tagKeyEventSink
896 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
900 static void KeyEventSink_Destructor(KeyEventSink *This)
902 HeapFree(GetProcessHeap(),0,This);
905 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
907 KeyEventSink *This = (KeyEventSink *)iface;
910 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
917 IUnknown_AddRef(iface);
921 return E_NOINTERFACE;
924 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
926 KeyEventSink *This = (KeyEventSink *)iface;
927 return InterlockedIncrement(&This->refCount);
930 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
932 KeyEventSink *This = (KeyEventSink *)iface;
935 ret = InterlockedDecrement(&This->refCount);
937 KeyEventSink_Destructor(This);
941 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
944 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
945 test_KEV_OnSetFocus = SINK_FIRED;
949 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
950 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
956 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
957 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
963 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
964 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
970 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
971 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
977 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
978 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
984 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
986 KeyEventSink_QueryInterface,
988 KeyEventSink_Release,
990 KeyEventSink_OnSetFocus,
991 KeyEventSink_OnTestKeyDown,
992 KeyEventSink_OnTestKeyUp,
993 KeyEventSink_OnKeyDown,
994 KeyEventSink_OnKeyUp,
995 KeyEventSink_OnPreservedKey
998 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1002 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1004 return E_OUTOFMEMORY;
1006 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1009 *ppOut = (ITfKeyEventSink*)This;
1014 static void test_KeystrokeMgr(void)
1016 ITfKeystrokeMgr *keymgr= NULL;
1018 TF_PRESERVEDKEY tfpk;
1020 ITfKeyEventSink *sink = NULL;
1022 KeyEventSink_Constructor(&sink);
1024 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1025 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1028 tfpk.uModifiers = TF_MOD_SHIFT;
1030 test_KEV_OnSetFocus = SINK_EXPECTED;
1031 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1032 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1033 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1034 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1035 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1036 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1037 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1039 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1040 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1042 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1043 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1045 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1046 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1049 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1050 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1051 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1053 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1054 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1056 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1057 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1058 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1060 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1061 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1063 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1064 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1066 ITfKeystrokeMgr_Release(keymgr);
1067 ITfKeyEventSink_Release(sink);
1070 static void test_Activate(void)
1074 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1075 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1078 static inline int check_context_refcount(ITfContext *iface)
1080 IUnknown_AddRef(iface);
1081 return IUnknown_Release(iface);
1084 static void test_startSession(void)
1089 ITfDocumentMgr *dmtest;
1090 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1092 TfClientId cid2 = 0;
1094 hr = ITfThreadMgr_Deactivate(g_tm);
1095 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1097 test_ShouldActivate = TRUE;
1098 hr = ITfThreadMgr_Activate(g_tm,&cid);
1099 ok(SUCCEEDED(hr),"Failed to Activate\n");
1100 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1102 test_ShouldActivate = FALSE;
1103 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1104 ok(SUCCEEDED(hr),"Failed to Activate\n");
1105 ok (cid == cid2, "Second activate client ID does not match\n");
1107 hr = ITfThreadMgr_Deactivate(g_tm);
1108 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1110 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1111 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1113 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1114 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1115 ok(dmtest == NULL,"Initial focus not null\n");
1117 test_CurrentFocus = g_dm;
1118 test_PrevFocus = NULL;
1119 test_OnSetFocus = SINK_EXPECTED;
1120 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1121 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1122 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1123 test_OnSetFocus = SINK_UNEXPECTED;
1125 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1126 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1127 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1129 cnt = ITfDocumentMgr_Release(g_dm);
1130 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1132 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1133 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1134 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1136 TextStoreACP_Constructor((IUnknown**)&ts);
1138 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1139 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1141 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1142 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1144 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1145 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1147 cnt = check_context_refcount(cxt);
1148 test_OnPushContext = SINK_EXPECTED;
1149 test_ACP_AdviseSink = SINK_EXPECTED;
1150 test_OnInitDocumentMgr = SINK_EXPECTED;
1151 hr = ITfDocumentMgr_Push(g_dm, cxt);
1152 ok(SUCCEEDED(hr),"Push Failed\n");
1153 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1154 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1155 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1156 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1158 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1159 ok(SUCCEEDED(hr),"GetTop Failed\n");
1160 ok(cxtTest == cxt, "Wrong context on top\n");
1161 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1162 cnt = ITfContext_Release(cxtTest);
1164 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1165 ok(SUCCEEDED(hr),"GetBase Failed\n");
1166 ok(cxtTest == cxt, "Wrong context on Base\n");
1167 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1168 ITfContext_Release(cxtTest);
1170 check_context_refcount(cxt2);
1171 test_OnPushContext = SINK_EXPECTED;
1172 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1173 ok(SUCCEEDED(hr),"Push Failed\n");
1174 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1176 cnt = check_context_refcount(cxt2);
1177 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1178 ok(SUCCEEDED(hr),"GetTop Failed\n");
1179 ok(cxtTest == cxt2, "Wrong context on top\n");
1180 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1181 ITfContext_Release(cxtTest);
1183 cnt = check_context_refcount(cxt);
1184 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1185 ok(SUCCEEDED(hr),"GetBase Failed\n");
1186 ok(cxtTest == cxt, "Wrong context on Base\n");
1187 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1188 ITfContext_Release(cxtTest);
1190 cnt = check_context_refcount(cxt3);
1191 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1192 ok(FAILED(hr),"Push Succeeded\n");
1193 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1195 cnt = check_context_refcount(cxt2);
1196 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1197 ok(SUCCEEDED(hr),"GetTop Failed\n");
1198 ok(cxtTest == cxt2, "Wrong context on top\n");
1199 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1200 ITfContext_Release(cxtTest);
1202 cnt = check_context_refcount(cxt);
1203 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1204 ok(SUCCEEDED(hr),"GetBase Failed\n");
1205 ok(cxtTest == cxt, "Wrong context on Base\n");
1206 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1207 ITfContext_Release(cxtTest);
1209 cnt = check_context_refcount(cxt2);
1210 test_OnPopContext = SINK_EXPECTED;
1211 hr = ITfDocumentMgr_Pop(g_dm, 0);
1212 ok(SUCCEEDED(hr),"Pop Failed\n");
1213 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1214 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1216 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1217 ok(SUCCEEDED(hr),"GetTop Failed\n");
1218 ok(cxtTest == cxt, "Wrong context on top\n");
1219 ITfContext_Release(cxtTest);
1221 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1222 ok(SUCCEEDED(hr),"GetBase Failed\n");
1223 ok(cxtTest == cxt, "Wrong context on base\n");
1224 ITfContext_Release(cxtTest);
1226 hr = ITfDocumentMgr_Pop(g_dm, 0);
1227 ok(FAILED(hr),"Pop Succeeded\n");
1229 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1230 ok(SUCCEEDED(hr),"GetTop Failed\n");
1231 ok(cxtTest == cxt, "Wrong context on top\n");
1232 ITfContext_Release(cxtTest);
1234 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1235 ok(SUCCEEDED(hr),"GetBase Failed\n");
1236 ok(cxtTest == cxt, "Wrong context on base\n");
1237 ITfContext_Release(cxtTest);
1239 ITfContext_Release(cxt);
1240 ITfContext_Release(cxt2);
1241 ITfContext_Release(cxt3);
1244 static void test_endSession(void)
1247 test_ShouldDeactivate = TRUE;
1248 test_CurrentFocus = NULL;
1249 test_PrevFocus = g_dm;
1250 test_OnSetFocus = SINK_EXPECTED;
1251 hr = ITfThreadMgr_Deactivate(g_tm);
1252 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1253 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1254 test_OnSetFocus = SINK_UNEXPECTED;
1257 static void test_TfGuidAtom(void)
1261 TfGuidAtom atom1,atom2;
1264 CoCreateGuid(>est);
1266 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1268 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1269 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1271 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1272 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1273 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1274 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1275 ok(atom1 == atom2,"atoms do not match\n");
1276 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1277 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1278 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1279 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1280 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1281 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1282 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1283 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1284 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1285 ok(equal == TRUE,"Equal value invalid\n");
1287 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1288 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1289 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1290 ok(equal == TRUE,"Equal value invalid\n");
1291 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1292 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1293 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1296 static void test_ClientId(void)
1303 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1304 ok(SUCCEEDED(hr),"Unable to aquire ITfClientId interface\n");
1308 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1309 ok(SUCCEEDED(hr),"GetClientId failed\n");
1310 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1311 ok(SUCCEEDED(hr),"GetClientId failed\n");
1312 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1313 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1314 ok(SUCCEEDED(hr),"GetClientId failed\n");
1315 ok(id2!=id1,"Id matches GUID_NULL\n");
1316 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1317 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1318 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1319 ok(SUCCEEDED(hr),"GetClientId failed\n");
1320 ok(id2!=id1,"Id matches GUID_NULL\n");
1321 ok(id2!=tid,"Id for random guid matching tid\n");
1322 ok(id2!=cid,"Id for random guid matching cid\n");
1323 ITfClientId_Release(pcid);
1326 /**********************************************************************
1328 **********************************************************************/
1329 typedef struct tagEditSession
1331 const ITfEditSessionVtbl *EditSessionVtbl;
1335 static void EditSession_Destructor(EditSession *This)
1337 HeapFree(GetProcessHeap(),0,This);
1340 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1342 EditSession *This = (EditSession *)iface;
1345 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1352 IUnknown_AddRef(iface);
1356 return E_NOINTERFACE;
1359 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1361 EditSession *This = (EditSession *)iface;
1362 return InterlockedIncrement(&This->refCount);
1365 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1367 EditSession *This = (EditSession *)iface;
1370 ret = InterlockedDecrement(&This->refCount);
1372 EditSession_Destructor(This);
1376 static void test_InsertAtSelection(TfEditCookie ec, ITfContext *cxt)
1379 ITfInsertAtSelection *iis;
1380 ITfRange *range=NULL;
1381 static const WCHAR txt[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1383 hr = ITfContext_QueryInterface(cxt, &IID_ITfInsertAtSelection , (LPVOID*)&iis);
1384 ok(SUCCEEDED(hr),"Failed to get ITfInsertAtSelection interface\n");
1385 test_ACP_InsertTextAtSelection = SINK_EXPECTED;
1386 hr = ITfInsertAtSelection_InsertTextAtSelection(iis, ec, 0, txt, 11, &range);
1387 ok(SUCCEEDED(hr),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr);
1388 ok(test_ACP_InsertTextAtSelection == SINK_FIRED,"expected InsertTextAtSelection not fired\n");
1389 ok(range != NULL,"No range returned\n");
1390 ITfRange_Release(range);
1391 ITfInsertAtSelection_Release(iis);
1394 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1400 TF_SELECTION selection;
1404 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1405 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1406 test_DoEditSession = SINK_FIRED;
1408 ITfThreadMgr_GetFocus(g_tm, &dm);
1409 ITfDocumentMgr_GetTop(dm,&cxt);
1411 hr = ITfContext_GetStart(cxt,ec,NULL);
1412 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1414 range = (ITfRange*)0xdeaddead;
1415 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1416 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1417 ok(range == NULL,"Range not set to NULL\n");
1419 hr = ITfContext_GetStart(cxt,ec,&range);
1420 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1421 ok(range != NULL,"Range set to NULL\n");
1423 ITfRange_Release(range);
1425 hr = ITfContext_GetEnd(cxt,ec,NULL);
1426 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1428 range = (ITfRange*)0xdeaddead;
1429 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1430 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1431 ok(range == NULL,"Range not set to NULL\n");
1433 test_ACP_GetEndACP = SINK_EXPECTED;
1434 hr = ITfContext_GetEnd(cxt,ec,&range);
1435 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1436 ok(range != NULL,"Range set to NULL\n");
1437 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1439 ITfRange_Release(range);
1441 selection.range = NULL;
1442 test_ACP_GetSelection = SINK_EXPECTED;
1443 hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1444 ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1445 ok(fetched == 1,"fetched incorrect\n");
1446 ok(selection.range != NULL,"NULL range\n");
1447 ok(test_ACP_GetSelection == SINK_FIRED," expected ACP_GetSepection not fired\n");
1448 ITfRange_Release(selection.range);
1450 test_InsertAtSelection(ec, cxt);
1452 ITfContext_Release(cxt);
1453 ITfDocumentMgr_Release(dm);
1457 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1459 EditSession_QueryInterface,
1461 EditSession_Release,
1463 EditSession_DoEditSession
1466 HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1470 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1472 return E_OUTOFMEMORY;
1474 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1477 *ppOut = (ITfEditSession*)This;
1481 static void test_TStoApplicationText(void)
1483 HRESULT hr, hrSession;
1488 ITfThreadMgr_GetFocus(g_tm, &dm);
1489 EditSession_Constructor(&es);
1490 ITfDocumentMgr_GetTop(dm,&cxt);
1492 hrSession = 0xfeedface;
1493 /* Test no premissions flags */
1494 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1495 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1496 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1498 documentStatus = TS_SD_READONLY;
1499 hrSession = 0xfeedface;
1500 test_ACP_GetStatus = SINK_EXPECTED;
1501 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1502 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1503 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1504 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1506 /* signal a change to allow readwrite sessions */
1508 test_ACP_RequestLock = SINK_EXPECTED;
1509 ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1510 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1512 test_ACP_GetStatus = SINK_EXPECTED;
1513 test_ACP_RequestLock = SINK_EXPECTED;
1514 test_DoEditSession = SINK_EXPECTED;
1515 hrSession = 0xfeedface;
1516 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1517 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1518 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1519 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1520 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1521 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1523 ITfContext_Release(cxt);
1524 ITfDocumentMgr_Release(dm);
1525 ITfEditSession_Release(es);
1528 START_TEST(inputprocessor)
1530 if (SUCCEEDED(initialize()))
1533 test_RegisterCategory();
1534 test_EnumInputProcessorInfo();
1536 test_ThreadMgrAdviseSinks();
1538 test_startSession();
1541 test_KeystrokeMgr();
1542 test_TStoApplicationText();
1544 test_EnumLanguageProfiles();
1545 test_FindClosestCategory();
1547 test_ThreadMgrUnadviseSinks();
1548 test_UnregisterCategory();
1552 skip("Unable to create InputProcessor\n");