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;
68 /**********************************************************************
70 **********************************************************************/
71 typedef struct tagTextStoreACP
73 const ITextStoreACPVtbl *TextStoreACPVtbl;
78 static void TextStoreACP_Destructor(TextStoreACP *This)
80 HeapFree(GetProcessHeap(),0,This);
83 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
85 TextStoreACP *This = (TextStoreACP *)iface;
88 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
95 IUnknown_AddRef(iface);
102 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
104 TextStoreACP *This = (TextStoreACP *)iface;
105 return InterlockedIncrement(&This->refCount);
108 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
110 TextStoreACP *This = (TextStoreACP *)iface;
113 ret = InterlockedDecrement(&This->refCount);
115 TextStoreACP_Destructor(This);
119 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
120 REFIID riid, IUnknown *punk, DWORD dwMask)
124 ok(test_ACP_AdviseSink == SINK_EXPECTED, "Unexpected TextStoreACP_AdviseSink sink\n");
125 test_ACP_AdviseSink = SINK_FIRED;
127 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&ACPSink));
128 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
132 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
139 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
140 DWORD dwLockFlags, HRESULT *phrSession)
142 ok(test_ACP_RequestLock == SINK_EXPECTED,"Unexpected TextStoreACP_RequestLock\n");
143 test_ACP_RequestLock = SINK_FIRED;
144 *phrSession = ITextStoreACPSink_OnLockGranted(ACPSink, dwLockFlags);
147 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
150 ok(test_ACP_GetStatus == SINK_EXPECTED, "Unexpected TextStoreACP_GetStatus\n");
151 test_ACP_GetStatus = SINK_FIRED;
152 pdcs->dwDynamicFlags = documentStatus;
155 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
156 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
162 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
163 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
165 ok(test_ACP_GetSelection == SINK_EXPECTED, "Unexpected TextStoreACP_GetSelection\n");
166 test_ACP_GetSelection = SINK_FIRED;
168 pSelection->acpStart = 10;
169 pSelection->acpEnd = 20;
170 pSelection->style.fInterimChar = 0;
171 pSelection->style.ase = TS_AE_NONE;
176 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
177 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
182 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
183 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
184 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
185 ULONG *pcRunInfoRet, LONG *pacpNext)
190 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
191 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
192 ULONG cch, TS_TEXTCHANGE *pChange)
197 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
198 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
203 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
204 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
209 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
210 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
215 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
216 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
217 TS_TEXTCHANGE *pChange)
222 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
223 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
224 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
229 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
230 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
231 TS_TEXTCHANGE *pChange)
236 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
237 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
242 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
243 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
249 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
250 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
256 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
257 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
258 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
263 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
264 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
269 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
272 ok(test_ACP_GetEndACP == SINK_EXPECTED,"Unexpected TextStoreACP_GetEndACP\n");
273 test_ACP_GetEndACP = SINK_FIRED;
276 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
277 TsViewCookie *pvcView)
282 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
283 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
289 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
290 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
296 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
297 TsViewCookie vcView, RECT *prc)
302 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
303 TsViewCookie vcView, HWND *phwnd)
309 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
311 TextStoreACP_QueryInterface,
313 TextStoreACP_Release,
315 TextStoreACP_AdviseSink,
316 TextStoreACP_UnadviseSink,
317 TextStoreACP_RequestLock,
318 TextStoreACP_GetStatus,
319 TextStoreACP_QueryInsert,
320 TextStoreACP_GetSelection,
321 TextStoreACP_SetSelection,
322 TextStoreACP_GetText,
323 TextStoreACP_SetText,
324 TextStoreACP_GetFormattedText,
325 TextStoreACP_GetEmbedded,
326 TextStoreACP_QueryInsertEmbedded,
327 TextStoreACP_InsertEmbedded,
328 TextStoreACP_InsertTextAtSelection,
329 TextStoreACP_InsertEmbeddedAtSelection,
330 TextStoreACP_RequestSupportedAttrs,
331 TextStoreACP_RequestAttrsAtPosition,
332 TextStoreACP_RequestAttrsTransitioningAtPosition,
333 TextStoreACP_FindNextAttrTransition,
334 TextStoreACP_RetrieveRequestedAttrs,
335 TextStoreACP_GetEndACP,
336 TextStoreACP_GetActiveView,
337 TextStoreACP_GetACPFromPoint,
338 TextStoreACP_GetTextExt,
339 TextStoreACP_GetScreenExt,
343 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
347 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
349 return E_OUTOFMEMORY;
351 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
354 *ppOut = (IUnknown *)This;
358 /**********************************************************************
359 * ITfThreadMgrEventSink
360 **********************************************************************/
361 typedef struct tagThreadMgrEventSink
363 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
365 } ThreadMgrEventSink;
367 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
369 HeapFree(GetProcessHeap(),0,This);
372 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
374 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
377 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
384 IUnknown_AddRef(iface);
388 return E_NOINTERFACE;
391 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
393 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
394 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
395 return InterlockedIncrement(&This->refCount);
398 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
400 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
403 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
404 ret = InterlockedDecrement(&This->refCount);
406 ThreadMgrEventSink_Destructor(This);
410 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
411 ITfDocumentMgr *pdim)
413 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
414 test_OnInitDocumentMgr = SINK_FIRED;
418 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
419 ITfDocumentMgr *pdim)
425 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
426 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
428 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
429 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
430 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
431 test_OnSetFocus = SINK_FIRED;
435 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
438 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
439 test_OnPushContext = SINK_FIRED;
443 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
446 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
447 test_OnPopContext = SINK_FIRED;
451 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
453 ThreadMgrEventSink_QueryInterface,
454 ThreadMgrEventSink_AddRef,
455 ThreadMgrEventSink_Release,
457 ThreadMgrEventSink_OnInitDocumentMgr,
458 ThreadMgrEventSink_OnUninitDocumentMgr,
459 ThreadMgrEventSink_OnSetFocus,
460 ThreadMgrEventSink_OnPushContext,
461 ThreadMgrEventSink_OnPopContext
464 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
466 ThreadMgrEventSink *This;
468 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
470 return E_OUTOFMEMORY;
472 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
475 *ppOut = (IUnknown *)This;
480 /********************************************************************************************
481 * Stub text service for testing
482 ********************************************************************************************/
484 static LONG TS_refCount;
485 static IClassFactory *cf;
488 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
490 typedef struct tagClassFactory
492 const IClassFactoryVtbl *vtbl;
494 LPFNCONSTRUCTOR ctor;
497 typedef struct tagTextService
499 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
503 static void ClassFactory_Destructor(ClassFactory *This)
505 HeapFree(GetProcessHeap(),0,This);
509 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
512 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
514 IClassFactory_AddRef(iface);
519 return E_NOINTERFACE;
522 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
524 ClassFactory *This = (ClassFactory *)iface;
525 return InterlockedIncrement(&This->ref);
528 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
530 ClassFactory *This = (ClassFactory *)iface;
531 ULONG ret = InterlockedDecrement(&This->ref);
534 ClassFactory_Destructor(This);
538 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
540 ClassFactory *This = (ClassFactory *)iface;
544 ret = This->ctor(punkOuter, &obj);
547 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
548 IUnknown_Release(obj);
552 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
555 InterlockedIncrement(&TS_refCount);
557 InterlockedDecrement(&TS_refCount);
562 static const IClassFactoryVtbl ClassFactoryVtbl = {
564 ClassFactory_QueryInterface,
566 ClassFactory_Release,
569 ClassFactory_CreateInstance,
570 ClassFactory_LockServer
573 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
575 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
576 This->vtbl = &ClassFactoryVtbl;
579 *ppvOut = (LPVOID)This;
584 static void TextService_Destructor(TextService *This)
586 HeapFree(GetProcessHeap(),0,This);
589 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
591 TextService *This = (TextService *)iface;
594 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
601 IUnknown_AddRef(iface);
605 return E_NOINTERFACE;
608 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
610 TextService *This = (TextService *)iface;
611 return InterlockedIncrement(&This->refCount);
614 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
616 TextService *This = (TextService *)iface;
619 ret = InterlockedDecrement(&This->refCount);
621 TextService_Destructor(This);
625 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
626 ITfThreadMgr *ptim, TfClientId id)
628 trace("TextService_Activate\n");
629 ok(test_ShouldActivate,"Activation came unexpectedly\n");
634 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
636 trace("TextService_Deactivate\n");
637 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
641 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
643 TextService_QueryInterface,
647 TextService_Activate,
648 TextService_Deactivate
651 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
655 return CLASS_E_NOAGGREGATION;
657 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
659 return E_OUTOFMEMORY;
661 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
664 *ppOut = (IUnknown *)This;
668 static HRESULT RegisterTextService(REFCLSID rclsid)
670 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
671 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
674 static HRESULT UnregisterTextService()
676 return CoRevokeClassObject(regid);
683 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
684 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
685 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
686 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
687 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
688 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
689 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
690 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
691 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
692 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
695 static HRESULT initialize(void)
699 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
700 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
702 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
703 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
705 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
706 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
710 static void cleanup(void)
713 ITfInputProcessorProfiles_Release(g_ipp);
715 ITfCategoryMgr_Release(g_cm);
717 ITfThreadMgr_Release(g_tm);
721 static void test_Register(void)
725 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
726 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
728 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
729 ok(SUCCEEDED(hr),"Unable to get current language id\n");
730 trace("Current Language %x\n",gLangid);
732 hr = RegisterTextService(&CLSID_FakeService);
733 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
734 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
735 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
736 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
737 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
740 static void test_Unregister(void)
743 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
744 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
745 UnregisterTextService();
748 static void test_EnumInputProcessorInfo(void)
753 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
757 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
759 if(IsEqualGUID(&g,&CLSID_FakeService))
763 ok(found,"Did not find registered text service\n");
766 static void test_EnumLanguageProfiles(void)
769 IEnumTfLanguageProfiles *ppEnum;
770 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
772 TF_LANGUAGEPROFILE profile;
773 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
775 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
778 ok(profile.langid == gLangid, "LangId Incorrect\n");
779 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
780 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
784 ok(found,"Registered text service not found\n");
787 static void test_RegisterCategory(void)
790 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
791 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
792 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
793 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
796 static void test_UnregisterCategory(void)
799 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
800 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
801 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
802 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
805 static void test_FindClosestCategory(void)
809 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
811 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
812 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
813 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
815 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
816 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
817 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
819 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
820 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
821 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
824 static void test_Enable(void)
827 BOOL enabled = FALSE;
829 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
830 ok(SUCCEEDED(hr),"Failed to enable text service\n");
831 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
832 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
833 ok(enabled == TRUE,"enabled state incorrect\n");
836 static void test_Disable(void)
840 trace("Disabling\n");
841 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
842 ok(SUCCEEDED(hr),"Failed to disable text service\n");
845 static void test_ThreadMgrAdviseSinks(void)
847 ITfSource *source = NULL;
851 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
852 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
856 hr = ThreadMgrEventSink_Constructor(&sink);
857 ok(hr == S_OK, "got %08x\n", hr);
858 if(FAILED(hr)) return;
862 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
863 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
864 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
866 /* Advising the sink adds a ref, Relesing here lets the object be deleted
869 IUnknown_Release(sink);
870 ITfSource_Release(source);
873 static void test_ThreadMgrUnadviseSinks(void)
875 ITfSource *source = NULL;
878 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
879 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
884 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
885 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
886 ITfSource_Release(source);
889 /**********************************************************************
891 **********************************************************************/
892 typedef struct tagKeyEventSink
894 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
898 static void KeyEventSink_Destructor(KeyEventSink *This)
900 HeapFree(GetProcessHeap(),0,This);
903 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
905 KeyEventSink *This = (KeyEventSink *)iface;
908 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
915 IUnknown_AddRef(iface);
919 return E_NOINTERFACE;
922 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
924 KeyEventSink *This = (KeyEventSink *)iface;
925 return InterlockedIncrement(&This->refCount);
928 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
930 KeyEventSink *This = (KeyEventSink *)iface;
933 ret = InterlockedDecrement(&This->refCount);
935 KeyEventSink_Destructor(This);
939 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
942 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
943 test_KEV_OnSetFocus = SINK_FIRED;
947 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
948 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
954 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
955 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
961 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
962 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
968 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
969 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
975 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
976 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
982 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
984 KeyEventSink_QueryInterface,
986 KeyEventSink_Release,
988 KeyEventSink_OnSetFocus,
989 KeyEventSink_OnTestKeyDown,
990 KeyEventSink_OnTestKeyUp,
991 KeyEventSink_OnKeyDown,
992 KeyEventSink_OnKeyUp,
993 KeyEventSink_OnPreservedKey
996 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1000 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1002 return E_OUTOFMEMORY;
1004 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1007 *ppOut = (ITfKeyEventSink*)This;
1012 static void test_KeystrokeMgr(void)
1014 ITfKeystrokeMgr *keymgr= NULL;
1016 TF_PRESERVEDKEY tfpk;
1018 ITfKeyEventSink *sink = NULL;
1020 KeyEventSink_Constructor(&sink);
1022 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1023 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1026 tfpk.uModifiers = TF_MOD_SHIFT;
1028 test_KEV_OnSetFocus = SINK_EXPECTED;
1029 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1030 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1031 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1032 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1033 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1034 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1035 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1037 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1038 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1040 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1041 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1043 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1044 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1047 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1048 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1049 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1051 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1052 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1054 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1055 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1056 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1058 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1059 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1061 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1062 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1064 ITfKeystrokeMgr_Release(keymgr);
1065 ITfKeyEventSink_Release(sink);
1068 static void test_Activate(void)
1072 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1073 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1076 static inline int check_context_refcount(ITfContext *iface)
1078 IUnknown_AddRef(iface);
1079 return IUnknown_Release(iface);
1082 static void test_startSession(void)
1087 ITfDocumentMgr *dmtest;
1088 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1090 TfClientId cid2 = 0;
1092 hr = ITfThreadMgr_Deactivate(g_tm);
1093 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1095 test_ShouldActivate = TRUE;
1096 hr = ITfThreadMgr_Activate(g_tm,&cid);
1097 ok(SUCCEEDED(hr),"Failed to Activate\n");
1098 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1100 test_ShouldActivate = FALSE;
1101 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1102 ok(SUCCEEDED(hr),"Failed to Activate\n");
1103 ok (cid == cid2, "Second activate client ID does not match\n");
1105 hr = ITfThreadMgr_Deactivate(g_tm);
1106 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1108 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1109 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1111 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1112 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1113 ok(dmtest == NULL,"Initial focus not null\n");
1115 test_CurrentFocus = g_dm;
1116 test_PrevFocus = NULL;
1117 test_OnSetFocus = SINK_EXPECTED;
1118 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1119 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1120 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1121 test_OnSetFocus = SINK_UNEXPECTED;
1123 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1124 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1125 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1127 cnt = ITfDocumentMgr_Release(g_dm);
1128 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1130 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1131 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1132 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1134 TextStoreACP_Constructor((IUnknown**)&ts);
1136 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1137 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1139 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1140 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1142 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1143 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1145 cnt = check_context_refcount(cxt);
1146 test_OnPushContext = SINK_EXPECTED;
1147 test_ACP_AdviseSink = SINK_EXPECTED;
1148 test_OnInitDocumentMgr = SINK_EXPECTED;
1149 hr = ITfDocumentMgr_Push(g_dm, cxt);
1150 ok(SUCCEEDED(hr),"Push Failed\n");
1151 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1152 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1153 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1154 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1156 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1157 ok(SUCCEEDED(hr),"GetTop Failed\n");
1158 ok(cxtTest == cxt, "Wrong context on top\n");
1159 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1160 cnt = ITfContext_Release(cxtTest);
1162 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1163 ok(SUCCEEDED(hr),"GetBase Failed\n");
1164 ok(cxtTest == cxt, "Wrong context on Base\n");
1165 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1166 ITfContext_Release(cxtTest);
1168 check_context_refcount(cxt2);
1169 test_OnPushContext = SINK_EXPECTED;
1170 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1171 ok(SUCCEEDED(hr),"Push Failed\n");
1172 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1174 cnt = check_context_refcount(cxt2);
1175 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1176 ok(SUCCEEDED(hr),"GetTop Failed\n");
1177 ok(cxtTest == cxt2, "Wrong context on top\n");
1178 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1179 ITfContext_Release(cxtTest);
1181 cnt = check_context_refcount(cxt);
1182 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1183 ok(SUCCEEDED(hr),"GetBase Failed\n");
1184 ok(cxtTest == cxt, "Wrong context on Base\n");
1185 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1186 ITfContext_Release(cxtTest);
1188 cnt = check_context_refcount(cxt3);
1189 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1190 ok(FAILED(hr),"Push Succeeded\n");
1191 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1193 cnt = check_context_refcount(cxt2);
1194 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1195 ok(SUCCEEDED(hr),"GetTop Failed\n");
1196 ok(cxtTest == cxt2, "Wrong context on top\n");
1197 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1198 ITfContext_Release(cxtTest);
1200 cnt = check_context_refcount(cxt);
1201 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1202 ok(SUCCEEDED(hr),"GetBase Failed\n");
1203 ok(cxtTest == cxt, "Wrong context on Base\n");
1204 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1205 ITfContext_Release(cxtTest);
1207 cnt = check_context_refcount(cxt2);
1208 test_OnPopContext = SINK_EXPECTED;
1209 hr = ITfDocumentMgr_Pop(g_dm, 0);
1210 ok(SUCCEEDED(hr),"Pop Failed\n");
1211 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1212 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1214 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1215 ok(SUCCEEDED(hr),"GetTop Failed\n");
1216 ok(cxtTest == cxt, "Wrong context on top\n");
1217 ITfContext_Release(cxtTest);
1219 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1220 ok(SUCCEEDED(hr),"GetBase Failed\n");
1221 ok(cxtTest == cxt, "Wrong context on base\n");
1222 ITfContext_Release(cxtTest);
1224 hr = ITfDocumentMgr_Pop(g_dm, 0);
1225 ok(FAILED(hr),"Pop Succeeded\n");
1227 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1228 ok(SUCCEEDED(hr),"GetTop Failed\n");
1229 ok(cxtTest == cxt, "Wrong context on top\n");
1230 ITfContext_Release(cxtTest);
1232 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1233 ok(SUCCEEDED(hr),"GetBase Failed\n");
1234 ok(cxtTest == cxt, "Wrong context on base\n");
1235 ITfContext_Release(cxtTest);
1237 ITfContext_Release(cxt);
1238 ITfContext_Release(cxt2);
1239 ITfContext_Release(cxt3);
1242 static void test_endSession(void)
1245 test_ShouldDeactivate = TRUE;
1246 test_CurrentFocus = NULL;
1247 test_PrevFocus = g_dm;
1248 test_OnSetFocus = SINK_EXPECTED;
1249 hr = ITfThreadMgr_Deactivate(g_tm);
1250 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1251 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1252 test_OnSetFocus = SINK_UNEXPECTED;
1255 static void test_TfGuidAtom(void)
1259 TfGuidAtom atom1,atom2;
1262 CoCreateGuid(>est);
1264 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1266 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1267 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1269 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1270 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1271 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1272 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1273 ok(atom1 == atom2,"atoms do not match\n");
1274 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1275 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1276 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1277 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1278 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1279 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1280 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1281 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1282 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1283 ok(equal == TRUE,"Equal value invalid\n");
1285 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1286 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1287 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1288 ok(equal == TRUE,"Equal value invalid\n");
1289 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1290 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1291 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1294 static void test_ClientId(void)
1301 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1302 ok(SUCCEEDED(hr),"Unable to aquire ITfClientId interface\n");
1306 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1307 ok(SUCCEEDED(hr),"GetClientId failed\n");
1308 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1309 ok(SUCCEEDED(hr),"GetClientId failed\n");
1310 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1311 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1312 ok(SUCCEEDED(hr),"GetClientId failed\n");
1313 ok(id2!=id1,"Id matches GUID_NULL\n");
1314 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1315 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1316 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1317 ok(SUCCEEDED(hr),"GetClientId failed\n");
1318 ok(id2!=id1,"Id matches GUID_NULL\n");
1319 ok(id2!=tid,"Id for random guid matching tid\n");
1320 ok(id2!=cid,"Id for random guid matching cid\n");
1321 ITfClientId_Release(pcid);
1324 /**********************************************************************
1326 **********************************************************************/
1327 typedef struct tagEditSession
1329 const ITfEditSessionVtbl *EditSessionVtbl;
1333 static void EditSession_Destructor(EditSession *This)
1335 HeapFree(GetProcessHeap(),0,This);
1338 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1340 EditSession *This = (EditSession *)iface;
1343 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1350 IUnknown_AddRef(iface);
1354 return E_NOINTERFACE;
1357 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1359 EditSession *This = (EditSession *)iface;
1360 return InterlockedIncrement(&This->refCount);
1363 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1365 EditSession *This = (EditSession *)iface;
1368 ret = InterlockedDecrement(&This->refCount);
1370 EditSession_Destructor(This);
1374 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1380 TF_SELECTION selection;
1384 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1385 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1386 test_DoEditSession = SINK_FIRED;
1388 ITfThreadMgr_GetFocus(g_tm, &dm);
1389 ITfDocumentMgr_GetTop(dm,&cxt);
1391 hr = ITfContext_GetStart(cxt,ec,NULL);
1392 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1394 range = (ITfRange*)0xdeaddead;
1395 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1396 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1397 ok(range == NULL,"Range not set to NULL\n");
1399 hr = ITfContext_GetStart(cxt,ec,&range);
1400 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1401 ok(range != NULL,"Range set to NULL\n");
1403 ITfRange_Release(range);
1405 hr = ITfContext_GetEnd(cxt,ec,NULL);
1406 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1408 range = (ITfRange*)0xdeaddead;
1409 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1410 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1411 ok(range == NULL,"Range not set to NULL\n");
1413 test_ACP_GetEndACP = SINK_EXPECTED;
1414 hr = ITfContext_GetEnd(cxt,ec,&range);
1415 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1416 ok(range != NULL,"Range set to NULL\n");
1417 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1419 ITfRange_Release(range);
1421 selection.range = NULL;
1422 test_ACP_GetSelection = SINK_EXPECTED;
1423 hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1424 ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1425 ok(fetched == 1,"fetched incorrect\n");
1426 ok(selection.range != NULL,"NULL range\n");
1427 ok(test_ACP_GetSelection == SINK_FIRED," expected ACP_GetSepection not fired\n");
1428 ITfRange_Release(selection.range);
1430 ITfContext_Release(cxt);
1431 ITfDocumentMgr_Release(dm);
1435 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1437 EditSession_QueryInterface,
1439 EditSession_Release,
1441 EditSession_DoEditSession
1444 HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1448 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1450 return E_OUTOFMEMORY;
1452 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1455 *ppOut = (ITfEditSession*)This;
1459 static void test_TStoApplicationText(void)
1461 HRESULT hr, hrSession;
1466 ITfThreadMgr_GetFocus(g_tm, &dm);
1467 EditSession_Constructor(&es);
1468 ITfDocumentMgr_GetTop(dm,&cxt);
1470 hrSession = 0xfeedface;
1471 /* Test no premissions flags */
1472 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1473 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1474 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1476 documentStatus = TS_SD_READONLY;
1477 hrSession = 0xfeedface;
1478 test_ACP_GetStatus = SINK_EXPECTED;
1479 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1480 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1481 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1482 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1484 /* signal a change to allow readwrite sessions */
1486 test_ACP_RequestLock = SINK_EXPECTED;
1487 ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1488 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1490 test_ACP_GetStatus = SINK_EXPECTED;
1491 test_ACP_RequestLock = SINK_EXPECTED;
1492 test_DoEditSession = SINK_EXPECTED;
1493 hrSession = 0xfeedface;
1494 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1495 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1496 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1497 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1498 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1499 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1501 ITfContext_Release(cxt);
1502 ITfDocumentMgr_Release(dm);
1503 ITfEditSession_Release(es);
1506 START_TEST(inputprocessor)
1508 if (SUCCEEDED(initialize()))
1511 test_RegisterCategory();
1512 test_EnumInputProcessorInfo();
1514 test_ThreadMgrAdviseSinks();
1516 test_startSession();
1519 test_KeystrokeMgr();
1520 test_TStoApplicationText();
1522 test_EnumLanguageProfiles();
1523 test_FindClosestCategory();
1525 test_ThreadMgrUnadviseSinks();
1526 test_UnregisterCategory();
1530 skip("Unable to create InputProcessor\n");