2 * Unit tests for ITfInputProcessor
4 * Copyright 2009 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
33 static ITfInputProcessorProfiles* g_ipp;
34 static LANGID gLangid;
35 static ITfCategoryMgr * g_cm = NULL;
36 static ITfThreadMgr* g_tm = NULL;
37 static ITfDocumentMgr *g_dm = NULL;
38 static TfClientId cid = 0;
39 static TfClientId tid = 0;
41 #define SINK_UNEXPECTED 0
42 #define SINK_EXPECTED 1
45 static BOOL test_ShouldActivate = FALSE;
46 static BOOL test_ShouldDeactivate = FALSE;
48 static DWORD tmSinkCookie;
49 static DWORD tmSinkRefCount;
50 static ITfDocumentMgr *test_CurrentFocus = NULL;
51 static ITfDocumentMgr *test_PrevFocus = NULL;
52 static INT test_OnSetFocus = SINK_UNEXPECTED;
53 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
54 static INT test_OnPushContext = SINK_UNEXPECTED;
55 static INT test_OnPopContext = SINK_UNEXPECTED;
56 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
57 static INT test_ACP_AdviseSink = SINK_UNEXPECTED;
58 static INT test_ACP_GetStatus = SINK_UNEXPECTED;
59 static INT test_ACP_RequestLock = SINK_UNEXPECTED;
60 static INT test_DoEditSession = SINK_UNEXPECTED;
63 /**********************************************************************
65 **********************************************************************/
66 typedef struct tagTextStoreACP
68 const ITextStoreACPVtbl *TextStoreACPVtbl;
71 ITextStoreACPSink *sink;
74 static void TextStoreACP_Destructor(TextStoreACP *This)
76 HeapFree(GetProcessHeap(),0,This);
79 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
81 TextStoreACP *This = (TextStoreACP *)iface;
84 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
91 IUnknown_AddRef(iface);
98 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
100 TextStoreACP *This = (TextStoreACP *)iface;
101 return InterlockedIncrement(&This->refCount);
104 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
106 TextStoreACP *This = (TextStoreACP *)iface;
109 ret = InterlockedDecrement(&This->refCount);
111 TextStoreACP_Destructor(This);
115 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
116 REFIID riid, IUnknown *punk, DWORD dwMask)
118 TextStoreACP *This = (TextStoreACP *)iface;
121 ok(test_ACP_AdviseSink == SINK_EXPECTED, "Unexpected TextStoreACP_AdviseSink sink\n");
122 test_ACP_AdviseSink = SINK_FIRED;
124 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&This->sink));
125 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
129 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
136 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
137 DWORD dwLockFlags, HRESULT *phrSession)
139 TextStoreACP *This = (TextStoreACP *)iface;
141 ok(test_ACP_RequestLock == SINK_EXPECTED,"Unexpected TextStoreACP_RequestLock\n");
142 test_ACP_RequestLock = SINK_FIRED;
143 test_DoEditSession = SINK_EXPECTED;
144 *phrSession = ITextStoreACPSink_OnLockGranted(This->sink, TS_LF_READWRITE);
145 ok(test_DoEditSession = SINK_FIRED,"expected DoEditSession not fired\n");
146 ok(*phrSession == 0xdeadcafe,"Unexpected return from ITextStoreACPSink_OnLockGranted\n");
149 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
152 static UINT count = 0;
156 ok(test_ACP_GetStatus == SINK_EXPECTED, "Unexpected TextStoreACP_GetStatus\n");
158 todo_wine ok(count == 1,"GetStatus called too many times\n");
159 test_ACP_GetStatus = SINK_FIRED;
160 pdcs->dwDynamicFlags = TS_SD_READONLY;
163 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
164 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
170 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
171 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
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,
275 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
276 TsViewCookie *pvcView)
281 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
282 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
288 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
289 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
295 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
296 TsViewCookie vcView, RECT *prc)
301 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
302 TsViewCookie vcView, HWND *phwnd)
308 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
310 TextStoreACP_QueryInterface,
312 TextStoreACP_Release,
314 TextStoreACP_AdviseSink,
315 TextStoreACP_UnadviseSink,
316 TextStoreACP_RequestLock,
317 TextStoreACP_GetStatus,
318 TextStoreACP_QueryInsert,
319 TextStoreACP_GetSelection,
320 TextStoreACP_SetSelection,
321 TextStoreACP_GetText,
322 TextStoreACP_SetText,
323 TextStoreACP_GetFormattedText,
324 TextStoreACP_GetEmbedded,
325 TextStoreACP_QueryInsertEmbedded,
326 TextStoreACP_InsertEmbedded,
327 TextStoreACP_InsertTextAtSelection,
328 TextStoreACP_InsertEmbeddedAtSelection,
329 TextStoreACP_RequestSupportedAttrs,
330 TextStoreACP_RequestAttrsAtPosition,
331 TextStoreACP_RequestAttrsTransitioningAtPosition,
332 TextStoreACP_FindNextAttrTransition,
333 TextStoreACP_RetrieveRequestedAttrs,
334 TextStoreACP_GetEndACP,
335 TextStoreACP_GetActiveView,
336 TextStoreACP_GetACPFromPoint,
337 TextStoreACP_GetTextExt,
338 TextStoreACP_GetScreenExt,
342 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
346 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
348 return E_OUTOFMEMORY;
350 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
353 *ppOut = (IUnknown *)This;
357 /**********************************************************************
358 * ITfThreadMgrEventSink
359 **********************************************************************/
360 typedef struct tagThreadMgrEventSink
362 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
364 } ThreadMgrEventSink;
366 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
368 HeapFree(GetProcessHeap(),0,This);
371 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
373 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
376 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
383 IUnknown_AddRef(iface);
387 return E_NOINTERFACE;
390 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
392 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
393 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
394 return InterlockedIncrement(&This->refCount);
397 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
399 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
402 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
403 ret = InterlockedDecrement(&This->refCount);
405 ThreadMgrEventSink_Destructor(This);
409 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
410 ITfDocumentMgr *pdim)
412 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
413 test_OnInitDocumentMgr = SINK_FIRED;
417 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
418 ITfDocumentMgr *pdim)
424 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
425 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
427 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
428 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
429 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
430 test_OnSetFocus = SINK_FIRED;
434 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
437 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
438 test_OnPushContext = SINK_FIRED;
442 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
445 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
446 test_OnPopContext = SINK_FIRED;
450 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
452 ThreadMgrEventSink_QueryInterface,
453 ThreadMgrEventSink_AddRef,
454 ThreadMgrEventSink_Release,
456 ThreadMgrEventSink_OnInitDocumentMgr,
457 ThreadMgrEventSink_OnUninitDocumentMgr,
458 ThreadMgrEventSink_OnSetFocus,
459 ThreadMgrEventSink_OnPushContext,
460 ThreadMgrEventSink_OnPopContext
463 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
465 ThreadMgrEventSink *This;
467 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
469 return E_OUTOFMEMORY;
471 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
474 *ppOut = (IUnknown *)This;
479 /********************************************************************************************
480 * Stub text service for testing
481 ********************************************************************************************/
483 static LONG TS_refCount;
484 static IClassFactory *cf;
487 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
489 typedef struct tagClassFactory
491 const IClassFactoryVtbl *vtbl;
493 LPFNCONSTRUCTOR ctor;
496 typedef struct tagTextService
498 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
502 static void ClassFactory_Destructor(ClassFactory *This)
504 HeapFree(GetProcessHeap(),0,This);
508 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
511 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
513 IClassFactory_AddRef(iface);
518 return E_NOINTERFACE;
521 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
523 ClassFactory *This = (ClassFactory *)iface;
524 return InterlockedIncrement(&This->ref);
527 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
529 ClassFactory *This = (ClassFactory *)iface;
530 ULONG ret = InterlockedDecrement(&This->ref);
533 ClassFactory_Destructor(This);
537 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
539 ClassFactory *This = (ClassFactory *)iface;
543 ret = This->ctor(punkOuter, &obj);
546 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
547 IUnknown_Release(obj);
551 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
554 InterlockedIncrement(&TS_refCount);
556 InterlockedDecrement(&TS_refCount);
561 static const IClassFactoryVtbl ClassFactoryVtbl = {
563 ClassFactory_QueryInterface,
565 ClassFactory_Release,
568 ClassFactory_CreateInstance,
569 ClassFactory_LockServer
572 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
574 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
575 This->vtbl = &ClassFactoryVtbl;
578 *ppvOut = (LPVOID)This;
583 static void TextService_Destructor(TextService *This)
585 HeapFree(GetProcessHeap(),0,This);
588 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
590 TextService *This = (TextService *)iface;
593 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
600 IUnknown_AddRef(iface);
604 return E_NOINTERFACE;
607 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
609 TextService *This = (TextService *)iface;
610 return InterlockedIncrement(&This->refCount);
613 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
615 TextService *This = (TextService *)iface;
618 ret = InterlockedDecrement(&This->refCount);
620 TextService_Destructor(This);
624 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
625 ITfThreadMgr *ptim, TfClientId id)
627 trace("TextService_Activate\n");
628 ok(test_ShouldActivate,"Activation came unexpectedly\n");
633 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
635 trace("TextService_Deactivate\n");
636 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
640 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
642 TextService_QueryInterface,
646 TextService_Activate,
647 TextService_Deactivate
650 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
654 return CLASS_E_NOAGGREGATION;
656 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
658 return E_OUTOFMEMORY;
660 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
663 *ppOut = (IUnknown *)This;
667 static HRESULT RegisterTextService(REFCLSID rclsid)
669 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
670 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
673 static HRESULT UnregisterTextService()
675 return CoRevokeClassObject(regid);
682 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
683 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
684 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
685 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
686 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
687 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
688 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
689 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
690 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
691 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
694 static HRESULT initialize(void)
698 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
699 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
701 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
702 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
704 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
705 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
709 static void cleanup(void)
712 ITfInputProcessorProfiles_Release(g_ipp);
714 ITfCategoryMgr_Release(g_cm);
716 ITfThreadMgr_Release(g_tm);
720 static void test_Register(void)
724 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
725 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
727 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
728 ok(SUCCEEDED(hr),"Unable to get current language id\n");
729 trace("Current Language %x\n",gLangid);
731 hr = RegisterTextService(&CLSID_FakeService);
732 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
733 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
734 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
735 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
736 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
739 static void test_Unregister(void)
742 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
743 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
744 UnregisterTextService();
747 static void test_EnumInputProcessorInfo(void)
752 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
756 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
758 if(IsEqualGUID(&g,&CLSID_FakeService))
762 ok(found,"Did not find registered text service\n");
765 static void test_EnumLanguageProfiles(void)
768 IEnumTfLanguageProfiles *ppEnum;
769 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
771 TF_LANGUAGEPROFILE profile;
772 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
774 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
777 ok(profile.langid == gLangid, "LangId Incorrect\n");
778 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
779 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
783 ok(found,"Registered text service not found\n");
786 static void test_RegisterCategory(void)
789 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
790 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
791 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
792 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
795 static void test_UnregisterCategory(void)
798 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
799 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
800 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
801 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
804 static void test_FindClosestCategory(void)
808 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
810 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
811 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
812 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
814 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
815 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
816 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
818 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
819 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
820 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
823 static void test_Enable(void)
826 BOOL enabled = FALSE;
828 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
829 ok(SUCCEEDED(hr),"Failed to enable text service\n");
830 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
831 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
832 ok(enabled == TRUE,"enabled state incorrect\n");
835 static void test_Disable(void)
839 trace("Disabling\n");
840 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
841 ok(SUCCEEDED(hr),"Failed to disable text service\n");
844 static void test_ThreadMgrAdviseSinks(void)
846 ITfSource *source = NULL;
850 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
851 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
855 hr = ThreadMgrEventSink_Constructor(&sink);
856 ok(hr == S_OK, "got %08x\n", hr);
857 if(FAILED(hr)) return;
861 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
862 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
863 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
865 /* Advising the sink adds a ref, Relesing here lets the object be deleted
868 IUnknown_Release(sink);
869 ITfSource_Release(source);
872 static void test_ThreadMgrUnadviseSinks(void)
874 ITfSource *source = NULL;
877 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
878 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
883 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
884 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
885 ITfSource_Release(source);
888 /**********************************************************************
890 **********************************************************************/
891 typedef struct tagKeyEventSink
893 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
897 static void KeyEventSink_Destructor(KeyEventSink *This)
899 HeapFree(GetProcessHeap(),0,This);
902 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
904 KeyEventSink *This = (KeyEventSink *)iface;
907 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
914 IUnknown_AddRef(iface);
918 return E_NOINTERFACE;
921 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
923 KeyEventSink *This = (KeyEventSink *)iface;
924 return InterlockedIncrement(&This->refCount);
927 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
929 KeyEventSink *This = (KeyEventSink *)iface;
932 ret = InterlockedDecrement(&This->refCount);
934 KeyEventSink_Destructor(This);
938 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
941 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
942 test_KEV_OnSetFocus = SINK_FIRED;
946 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
947 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
953 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
954 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
960 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
961 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
967 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
968 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
974 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
975 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
981 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
983 KeyEventSink_QueryInterface,
985 KeyEventSink_Release,
987 KeyEventSink_OnSetFocus,
988 KeyEventSink_OnTestKeyDown,
989 KeyEventSink_OnTestKeyUp,
990 KeyEventSink_OnKeyDown,
991 KeyEventSink_OnKeyUp,
992 KeyEventSink_OnPreservedKey
995 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
999 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1001 return E_OUTOFMEMORY;
1003 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1006 *ppOut = (ITfKeyEventSink*)This;
1011 static void test_KeystrokeMgr(void)
1013 ITfKeystrokeMgr *keymgr= NULL;
1015 TF_PRESERVEDKEY tfpk;
1017 ITfKeyEventSink *sink = NULL;
1019 KeyEventSink_Constructor(&sink);
1021 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1022 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1025 tfpk.uModifiers = TF_MOD_SHIFT;
1027 test_KEV_OnSetFocus = SINK_EXPECTED;
1028 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1029 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1030 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1031 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1032 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1033 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1034 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1036 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1037 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1039 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1040 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1042 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1043 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1046 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1047 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1048 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1050 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1051 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1053 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1054 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1055 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1057 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1058 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1060 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1061 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1063 ITfKeystrokeMgr_Release(keymgr);
1064 ITfKeyEventSink_Release(sink);
1067 static void test_Activate(void)
1071 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1072 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1075 static inline int check_context_refcount(ITfContext *iface)
1077 IUnknown_AddRef(iface);
1078 return IUnknown_Release(iface);
1081 static void test_startSession(void)
1086 ITfDocumentMgr *dmtest;
1087 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1089 TfClientId cid2 = 0;
1091 hr = ITfThreadMgr_Deactivate(g_tm);
1092 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1094 test_ShouldActivate = TRUE;
1095 hr = ITfThreadMgr_Activate(g_tm,&cid);
1096 ok(SUCCEEDED(hr),"Failed to Activate\n");
1097 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1099 test_ShouldActivate = FALSE;
1100 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1101 ok(SUCCEEDED(hr),"Failed to Activate\n");
1102 ok (cid == cid2, "Second activate client ID does not match\n");
1104 hr = ITfThreadMgr_Deactivate(g_tm);
1105 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1107 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1108 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1110 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1111 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1112 ok(dmtest == NULL,"Initial focus not null\n");
1114 test_CurrentFocus = g_dm;
1115 test_PrevFocus = NULL;
1116 test_OnSetFocus = SINK_EXPECTED;
1117 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1118 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1119 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1120 test_OnSetFocus = SINK_UNEXPECTED;
1122 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1123 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1124 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1126 cnt = ITfDocumentMgr_Release(g_dm);
1127 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1129 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1130 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1131 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1133 TextStoreACP_Constructor((IUnknown**)&ts);
1135 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1136 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1138 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1139 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1141 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1142 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1144 cnt = check_context_refcount(cxt);
1145 test_OnPushContext = SINK_EXPECTED;
1146 test_ACP_AdviseSink = SINK_EXPECTED;
1147 test_OnInitDocumentMgr = SINK_EXPECTED;
1148 hr = ITfDocumentMgr_Push(g_dm, cxt);
1149 ok(SUCCEEDED(hr),"Push Failed\n");
1150 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1151 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1152 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1153 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1155 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1156 ok(SUCCEEDED(hr),"GetTop Failed\n");
1157 ok(cxtTest == cxt, "Wrong context on top\n");
1158 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1159 cnt = ITfContext_Release(cxtTest);
1161 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1162 ok(SUCCEEDED(hr),"GetBase Failed\n");
1163 ok(cxtTest == cxt, "Wrong context on Base\n");
1164 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1165 ITfContext_Release(cxtTest);
1167 check_context_refcount(cxt2);
1168 test_OnPushContext = SINK_EXPECTED;
1169 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1170 ok(SUCCEEDED(hr),"Push Failed\n");
1171 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1173 cnt = check_context_refcount(cxt2);
1174 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1175 ok(SUCCEEDED(hr),"GetTop Failed\n");
1176 ok(cxtTest == cxt2, "Wrong context on top\n");
1177 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1178 ITfContext_Release(cxtTest);
1180 cnt = check_context_refcount(cxt);
1181 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1182 ok(SUCCEEDED(hr),"GetBase Failed\n");
1183 ok(cxtTest == cxt, "Wrong context on Base\n");
1184 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1185 ITfContext_Release(cxtTest);
1187 cnt = check_context_refcount(cxt3);
1188 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1189 ok(FAILED(hr),"Push Succeeded\n");
1190 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1192 cnt = check_context_refcount(cxt2);
1193 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1194 ok(SUCCEEDED(hr),"GetTop Failed\n");
1195 ok(cxtTest == cxt2, "Wrong context on top\n");
1196 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1197 ITfContext_Release(cxtTest);
1199 cnt = check_context_refcount(cxt);
1200 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1201 ok(SUCCEEDED(hr),"GetBase Failed\n");
1202 ok(cxtTest == cxt, "Wrong context on Base\n");
1203 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1204 ITfContext_Release(cxtTest);
1206 cnt = check_context_refcount(cxt2);
1207 test_OnPopContext = SINK_EXPECTED;
1208 hr = ITfDocumentMgr_Pop(g_dm, 0);
1209 ok(SUCCEEDED(hr),"Pop Failed\n");
1210 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1211 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1213 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1214 ok(SUCCEEDED(hr),"GetTop Failed\n");
1215 ok(cxtTest == cxt, "Wrong context on top\n");
1216 ITfContext_Release(cxtTest);
1218 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1219 ok(SUCCEEDED(hr),"GetBase Failed\n");
1220 ok(cxtTest == cxt, "Wrong context on base\n");
1221 ITfContext_Release(cxtTest);
1223 hr = ITfDocumentMgr_Pop(g_dm, 0);
1224 ok(FAILED(hr),"Pop Succeeded\n");
1226 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1227 ok(SUCCEEDED(hr),"GetTop Failed\n");
1228 ok(cxtTest == cxt, "Wrong context on top\n");
1229 ITfContext_Release(cxtTest);
1231 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1232 ok(SUCCEEDED(hr),"GetBase Failed\n");
1233 ok(cxtTest == cxt, "Wrong context on base\n");
1234 ITfContext_Release(cxtTest);
1236 ITfContext_Release(cxt);
1237 ITfContext_Release(cxt2);
1238 ITfContext_Release(cxt3);
1241 static void test_endSession(void)
1244 test_ShouldDeactivate = TRUE;
1245 test_CurrentFocus = NULL;
1246 test_PrevFocus = g_dm;
1247 test_OnSetFocus = SINK_EXPECTED;
1248 hr = ITfThreadMgr_Deactivate(g_tm);
1249 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1250 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1251 test_OnSetFocus = SINK_UNEXPECTED;
1254 static void test_TfGuidAtom(void)
1258 TfGuidAtom atom1,atom2;
1261 CoCreateGuid(>est);
1263 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1265 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1266 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1268 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1269 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1270 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1271 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1272 ok(atom1 == atom2,"atoms do not match\n");
1273 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1274 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1275 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1276 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1277 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1278 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1279 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1280 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1281 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1282 ok(equal == TRUE,"Equal value invalid\n");
1284 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1285 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1286 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1287 ok(equal == TRUE,"Equal value invalid\n");
1288 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1289 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1290 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1293 static void test_ClientId(void)
1300 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1301 ok(SUCCEEDED(hr),"Unable to aquire ITfClientId interface\n");
1305 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1306 ok(SUCCEEDED(hr),"GetClientId failed\n");
1307 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1308 ok(SUCCEEDED(hr),"GetClientId failed\n");
1309 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1310 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1311 ok(SUCCEEDED(hr),"GetClientId failed\n");
1312 ok(id2!=id1,"Id matches GUID_NULL\n");
1313 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1314 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1315 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1316 ok(SUCCEEDED(hr),"GetClientId failed\n");
1317 ok(id2!=id1,"Id matches GUID_NULL\n");
1318 ok(id2!=tid,"Id for random guid matching tid\n");
1319 ok(id2!=cid,"Id for random guid matching cid\n");
1320 ITfClientId_Release(pcid);
1323 /**********************************************************************
1325 **********************************************************************/
1326 typedef struct tagEditSession
1328 const ITfEditSessionVtbl *EditSessionVtbl;
1332 static void EditSession_Destructor(EditSession *This)
1334 HeapFree(GetProcessHeap(),0,This);
1337 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1339 EditSession *This = (EditSession *)iface;
1342 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1349 IUnknown_AddRef(iface);
1353 return E_NOINTERFACE;
1356 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1358 EditSession *This = (EditSession *)iface;
1359 return InterlockedIncrement(&This->refCount);
1362 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1364 EditSession *This = (EditSession *)iface;
1367 ret = InterlockedDecrement(&This->refCount);
1369 EditSession_Destructor(This);
1373 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1376 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1377 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1378 test_DoEditSession = SINK_FIRED;
1382 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1384 EditSession_QueryInterface,
1386 EditSession_Release,
1388 EditSession_DoEditSession
1391 HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1395 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1397 return E_OUTOFMEMORY;
1399 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1402 *ppOut = (ITfEditSession*)This;
1406 static void test_TStoApplicationText(void)
1408 HRESULT hr, hrSession;
1413 ITfThreadMgr_GetFocus(g_tm, &dm);
1414 EditSession_Constructor(&es);
1415 ITfDocumentMgr_GetTop(dm,&cxt);
1417 hrSession = 0xfeedface;
1418 /* Test no premissions flags */
1419 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1420 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1421 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1423 hrSession = 0xfeedface;
1424 test_ACP_GetStatus = SINK_EXPECTED;
1425 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1426 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1427 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1428 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1430 test_ACP_GetStatus = SINK_UNEXPECTED;
1431 test_ACP_RequestLock = SINK_EXPECTED;
1432 hrSession = 0xfeedface;
1433 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READ, &hrSession);
1434 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1435 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1436 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1437 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1439 ITfContext_Release(cxt);
1440 ITfDocumentMgr_Release(dm);
1441 ITfEditSession_Release(es);
1444 START_TEST(inputprocessor)
1446 if (SUCCEEDED(initialize()))
1449 test_RegisterCategory();
1450 test_EnumInputProcessorInfo();
1452 test_ThreadMgrAdviseSinks();
1454 test_startSession();
1457 test_KeystrokeMgr();
1458 test_TStoApplicationText();
1460 test_EnumLanguageProfiles();
1461 test_FindClosestCategory();
1463 test_ThreadMgrUnadviseSinks();
1464 test_UnregisterCategory();
1468 skip("Unable to create InputProcessor\n");