2 * Unit tests for ITfInputProcessor
4 * Copyright 2009 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
33 static ITfInputProcessorProfiles* g_ipp;
34 static LANGID gLangid;
35 static ITfCategoryMgr * g_cm = NULL;
36 static ITfThreadMgr* g_tm = NULL;
37 static ITfDocumentMgr *g_dm = NULL;
38 static TfClientId cid = 0;
39 static TfClientId tid = 0;
41 #define SINK_UNEXPECTED 0
42 #define SINK_EXPECTED 1
45 static BOOL test_ShouldActivate = FALSE;
46 static BOOL test_ShouldDeactivate = FALSE;
48 static DWORD tmSinkCookie;
49 static DWORD tmSinkRefCount;
50 static ITfDocumentMgr *test_CurrentFocus = NULL;
51 static ITfDocumentMgr *test_PrevFocus = NULL;
52 static INT test_OnSetFocus = SINK_UNEXPECTED;
53 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
54 static INT test_OnPushContext = SINK_UNEXPECTED;
55 static INT test_OnPopContext = SINK_UNEXPECTED;
56 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
57 static INT test_ACP_AdviseSink = SINK_UNEXPECTED;
58 static INT test_ACP_GetStatus = SINK_UNEXPECTED;
59 static INT test_ACP_RequestLock = SINK_UNEXPECTED;
60 static INT test_ACP_GetEndACP = SINK_UNEXPECTED;
61 static INT test_DoEditSession = SINK_UNEXPECTED;
64 /**********************************************************************
66 **********************************************************************/
67 typedef struct tagTextStoreACP
69 const ITextStoreACPVtbl *TextStoreACPVtbl;
72 ITextStoreACPSink *sink;
75 static void TextStoreACP_Destructor(TextStoreACP *This)
77 HeapFree(GetProcessHeap(),0,This);
80 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
82 TextStoreACP *This = (TextStoreACP *)iface;
85 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
92 IUnknown_AddRef(iface);
99 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
101 TextStoreACP *This = (TextStoreACP *)iface;
102 return InterlockedIncrement(&This->refCount);
105 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
107 TextStoreACP *This = (TextStoreACP *)iface;
110 ret = InterlockedDecrement(&This->refCount);
112 TextStoreACP_Destructor(This);
116 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
117 REFIID riid, IUnknown *punk, DWORD dwMask)
119 TextStoreACP *This = (TextStoreACP *)iface;
122 ok(test_ACP_AdviseSink == SINK_EXPECTED, "Unexpected TextStoreACP_AdviseSink sink\n");
123 test_ACP_AdviseSink = SINK_FIRED;
125 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&This->sink));
126 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
130 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
137 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
138 DWORD dwLockFlags, HRESULT *phrSession)
140 TextStoreACP *This = (TextStoreACP *)iface;
142 ok(test_ACP_RequestLock == SINK_EXPECTED,"Unexpected TextStoreACP_RequestLock\n");
143 test_ACP_RequestLock = SINK_FIRED;
144 test_DoEditSession = SINK_EXPECTED;
145 *phrSession = ITextStoreACPSink_OnLockGranted(This->sink, TS_LF_READWRITE);
146 ok(test_DoEditSession = SINK_FIRED,"expected DoEditSession not fired\n");
147 ok(*phrSession == 0xdeadcafe,"Unexpected return from ITextStoreACPSink_OnLockGranted\n");
150 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
153 static UINT count = 0;
157 ok(test_ACP_GetStatus == SINK_EXPECTED, "Unexpected TextStoreACP_GetStatus\n");
159 todo_wine ok(count == 1,"GetStatus called too many times\n");
160 test_ACP_GetStatus = SINK_FIRED;
161 pdcs->dwDynamicFlags = TS_SD_READONLY;
164 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
165 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
171 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
172 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
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)
230 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
231 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
232 TS_TEXTCHANGE *pChange)
237 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
238 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
243 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
244 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
250 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
251 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
257 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
258 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
259 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
264 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
265 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
270 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
273 ok(test_ACP_GetEndACP == SINK_EXPECTED,"Unexpected TextStoreACP_GetEndACP\n");
274 test_ACP_GetEndACP = SINK_FIRED;
277 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
278 TsViewCookie *pvcView)
283 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
284 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
290 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
291 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
297 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
298 TsViewCookie vcView, RECT *prc)
303 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
304 TsViewCookie vcView, HWND *phwnd)
310 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
312 TextStoreACP_QueryInterface,
314 TextStoreACP_Release,
316 TextStoreACP_AdviseSink,
317 TextStoreACP_UnadviseSink,
318 TextStoreACP_RequestLock,
319 TextStoreACP_GetStatus,
320 TextStoreACP_QueryInsert,
321 TextStoreACP_GetSelection,
322 TextStoreACP_SetSelection,
323 TextStoreACP_GetText,
324 TextStoreACP_SetText,
325 TextStoreACP_GetFormattedText,
326 TextStoreACP_GetEmbedded,
327 TextStoreACP_QueryInsertEmbedded,
328 TextStoreACP_InsertEmbedded,
329 TextStoreACP_InsertTextAtSelection,
330 TextStoreACP_InsertEmbeddedAtSelection,
331 TextStoreACP_RequestSupportedAttrs,
332 TextStoreACP_RequestAttrsAtPosition,
333 TextStoreACP_RequestAttrsTransitioningAtPosition,
334 TextStoreACP_FindNextAttrTransition,
335 TextStoreACP_RetrieveRequestedAttrs,
336 TextStoreACP_GetEndACP,
337 TextStoreACP_GetActiveView,
338 TextStoreACP_GetACPFromPoint,
339 TextStoreACP_GetTextExt,
340 TextStoreACP_GetScreenExt,
344 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
348 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
350 return E_OUTOFMEMORY;
352 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
355 *ppOut = (IUnknown *)This;
359 /**********************************************************************
360 * ITfThreadMgrEventSink
361 **********************************************************************/
362 typedef struct tagThreadMgrEventSink
364 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
366 } ThreadMgrEventSink;
368 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
370 HeapFree(GetProcessHeap(),0,This);
373 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
375 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
378 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
385 IUnknown_AddRef(iface);
389 return E_NOINTERFACE;
392 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
394 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
395 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
396 return InterlockedIncrement(&This->refCount);
399 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
401 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
404 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
405 ret = InterlockedDecrement(&This->refCount);
407 ThreadMgrEventSink_Destructor(This);
411 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
412 ITfDocumentMgr *pdim)
414 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
415 test_OnInitDocumentMgr = SINK_FIRED;
419 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
420 ITfDocumentMgr *pdim)
426 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
427 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
429 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
430 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
431 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
432 test_OnSetFocus = SINK_FIRED;
436 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
439 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
440 test_OnPushContext = SINK_FIRED;
444 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
447 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
448 test_OnPopContext = SINK_FIRED;
452 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
454 ThreadMgrEventSink_QueryInterface,
455 ThreadMgrEventSink_AddRef,
456 ThreadMgrEventSink_Release,
458 ThreadMgrEventSink_OnInitDocumentMgr,
459 ThreadMgrEventSink_OnUninitDocumentMgr,
460 ThreadMgrEventSink_OnSetFocus,
461 ThreadMgrEventSink_OnPushContext,
462 ThreadMgrEventSink_OnPopContext
465 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
467 ThreadMgrEventSink *This;
469 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
471 return E_OUTOFMEMORY;
473 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
476 *ppOut = (IUnknown *)This;
481 /********************************************************************************************
482 * Stub text service for testing
483 ********************************************************************************************/
485 static LONG TS_refCount;
486 static IClassFactory *cf;
489 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
491 typedef struct tagClassFactory
493 const IClassFactoryVtbl *vtbl;
495 LPFNCONSTRUCTOR ctor;
498 typedef struct tagTextService
500 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
504 static void ClassFactory_Destructor(ClassFactory *This)
506 HeapFree(GetProcessHeap(),0,This);
510 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
513 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
515 IClassFactory_AddRef(iface);
520 return E_NOINTERFACE;
523 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
525 ClassFactory *This = (ClassFactory *)iface;
526 return InterlockedIncrement(&This->ref);
529 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
531 ClassFactory *This = (ClassFactory *)iface;
532 ULONG ret = InterlockedDecrement(&This->ref);
535 ClassFactory_Destructor(This);
539 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
541 ClassFactory *This = (ClassFactory *)iface;
545 ret = This->ctor(punkOuter, &obj);
548 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
549 IUnknown_Release(obj);
553 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
556 InterlockedIncrement(&TS_refCount);
558 InterlockedDecrement(&TS_refCount);
563 static const IClassFactoryVtbl ClassFactoryVtbl = {
565 ClassFactory_QueryInterface,
567 ClassFactory_Release,
570 ClassFactory_CreateInstance,
571 ClassFactory_LockServer
574 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
576 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
577 This->vtbl = &ClassFactoryVtbl;
580 *ppvOut = (LPVOID)This;
585 static void TextService_Destructor(TextService *This)
587 HeapFree(GetProcessHeap(),0,This);
590 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
592 TextService *This = (TextService *)iface;
595 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
602 IUnknown_AddRef(iface);
606 return E_NOINTERFACE;
609 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
611 TextService *This = (TextService *)iface;
612 return InterlockedIncrement(&This->refCount);
615 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
617 TextService *This = (TextService *)iface;
620 ret = InterlockedDecrement(&This->refCount);
622 TextService_Destructor(This);
626 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
627 ITfThreadMgr *ptim, TfClientId id)
629 trace("TextService_Activate\n");
630 ok(test_ShouldActivate,"Activation came unexpectedly\n");
635 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
637 trace("TextService_Deactivate\n");
638 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
642 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
644 TextService_QueryInterface,
648 TextService_Activate,
649 TextService_Deactivate
652 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
656 return CLASS_E_NOAGGREGATION;
658 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
660 return E_OUTOFMEMORY;
662 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
665 *ppOut = (IUnknown *)This;
669 static HRESULT RegisterTextService(REFCLSID rclsid)
671 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
672 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
675 static HRESULT UnregisterTextService()
677 return CoRevokeClassObject(regid);
684 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
685 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
686 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
687 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
688 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
689 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
690 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
691 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
692 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
693 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
696 static HRESULT initialize(void)
700 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
701 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
703 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
704 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
706 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
707 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
711 static void cleanup(void)
714 ITfInputProcessorProfiles_Release(g_ipp);
716 ITfCategoryMgr_Release(g_cm);
718 ITfThreadMgr_Release(g_tm);
722 static void test_Register(void)
726 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
727 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
729 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
730 ok(SUCCEEDED(hr),"Unable to get current language id\n");
731 trace("Current Language %x\n",gLangid);
733 hr = RegisterTextService(&CLSID_FakeService);
734 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
735 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
736 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
737 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
738 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
741 static void test_Unregister(void)
744 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
745 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
746 UnregisterTextService();
749 static void test_EnumInputProcessorInfo(void)
754 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
758 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
760 if(IsEqualGUID(&g,&CLSID_FakeService))
764 ok(found,"Did not find registered text service\n");
767 static void test_EnumLanguageProfiles(void)
770 IEnumTfLanguageProfiles *ppEnum;
771 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
773 TF_LANGUAGEPROFILE profile;
774 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
776 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
779 ok(profile.langid == gLangid, "LangId Incorrect\n");
780 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
781 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
785 ok(found,"Registered text service not found\n");
788 static void test_RegisterCategory(void)
791 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
792 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
793 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
794 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
797 static void test_UnregisterCategory(void)
800 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
801 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
802 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
803 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
806 static void test_FindClosestCategory(void)
810 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
812 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
813 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
814 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
816 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
817 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
818 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
820 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
821 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
822 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
825 static void test_Enable(void)
828 BOOL enabled = FALSE;
830 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
831 ok(SUCCEEDED(hr),"Failed to enable text service\n");
832 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
833 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
834 ok(enabled == TRUE,"enabled state incorrect\n");
837 static void test_Disable(void)
841 trace("Disabling\n");
842 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
843 ok(SUCCEEDED(hr),"Failed to disable text service\n");
846 static void test_ThreadMgrAdviseSinks(void)
848 ITfSource *source = NULL;
852 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
853 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
857 hr = ThreadMgrEventSink_Constructor(&sink);
858 ok(hr == S_OK, "got %08x\n", hr);
859 if(FAILED(hr)) return;
863 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
864 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
865 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
867 /* Advising the sink adds a ref, Relesing here lets the object be deleted
870 IUnknown_Release(sink);
871 ITfSource_Release(source);
874 static void test_ThreadMgrUnadviseSinks(void)
876 ITfSource *source = NULL;
879 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
880 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
885 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
886 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
887 ITfSource_Release(source);
890 /**********************************************************************
892 **********************************************************************/
893 typedef struct tagKeyEventSink
895 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
899 static void KeyEventSink_Destructor(KeyEventSink *This)
901 HeapFree(GetProcessHeap(),0,This);
904 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
906 KeyEventSink *This = (KeyEventSink *)iface;
909 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
916 IUnknown_AddRef(iface);
920 return E_NOINTERFACE;
923 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
925 KeyEventSink *This = (KeyEventSink *)iface;
926 return InterlockedIncrement(&This->refCount);
929 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
931 KeyEventSink *This = (KeyEventSink *)iface;
934 ret = InterlockedDecrement(&This->refCount);
936 KeyEventSink_Destructor(This);
940 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
943 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
944 test_KEV_OnSetFocus = SINK_FIRED;
948 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
949 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
955 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
956 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
962 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
963 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
969 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
970 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
976 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
977 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
983 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
985 KeyEventSink_QueryInterface,
987 KeyEventSink_Release,
989 KeyEventSink_OnSetFocus,
990 KeyEventSink_OnTestKeyDown,
991 KeyEventSink_OnTestKeyUp,
992 KeyEventSink_OnKeyDown,
993 KeyEventSink_OnKeyUp,
994 KeyEventSink_OnPreservedKey
997 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1001 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1003 return E_OUTOFMEMORY;
1005 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1008 *ppOut = (ITfKeyEventSink*)This;
1013 static void test_KeystrokeMgr(void)
1015 ITfKeystrokeMgr *keymgr= NULL;
1017 TF_PRESERVEDKEY tfpk;
1019 ITfKeyEventSink *sink = NULL;
1021 KeyEventSink_Constructor(&sink);
1023 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1024 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1027 tfpk.uModifiers = TF_MOD_SHIFT;
1029 test_KEV_OnSetFocus = SINK_EXPECTED;
1030 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1031 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1032 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1033 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1034 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1035 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1036 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1038 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1039 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1041 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1042 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1044 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1045 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1048 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1049 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1050 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1052 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1053 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1055 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1056 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1057 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1059 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1060 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1062 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1063 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1065 ITfKeystrokeMgr_Release(keymgr);
1066 ITfKeyEventSink_Release(sink);
1069 static void test_Activate(void)
1073 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1074 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1077 static inline int check_context_refcount(ITfContext *iface)
1079 IUnknown_AddRef(iface);
1080 return IUnknown_Release(iface);
1083 static void test_startSession(void)
1088 ITfDocumentMgr *dmtest;
1089 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1091 TfClientId cid2 = 0;
1093 hr = ITfThreadMgr_Deactivate(g_tm);
1094 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1096 test_ShouldActivate = TRUE;
1097 hr = ITfThreadMgr_Activate(g_tm,&cid);
1098 ok(SUCCEEDED(hr),"Failed to Activate\n");
1099 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1101 test_ShouldActivate = FALSE;
1102 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1103 ok(SUCCEEDED(hr),"Failed to Activate\n");
1104 ok (cid == cid2, "Second activate client ID does not match\n");
1106 hr = ITfThreadMgr_Deactivate(g_tm);
1107 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1109 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1110 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1112 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1113 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1114 ok(dmtest == NULL,"Initial focus not null\n");
1116 test_CurrentFocus = g_dm;
1117 test_PrevFocus = NULL;
1118 test_OnSetFocus = SINK_EXPECTED;
1119 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1120 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1121 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1122 test_OnSetFocus = SINK_UNEXPECTED;
1124 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1125 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1126 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1128 cnt = ITfDocumentMgr_Release(g_dm);
1129 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1131 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1132 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1133 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1135 TextStoreACP_Constructor((IUnknown**)&ts);
1137 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1138 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1140 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1141 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1143 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1144 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1146 cnt = check_context_refcount(cxt);
1147 test_OnPushContext = SINK_EXPECTED;
1148 test_ACP_AdviseSink = SINK_EXPECTED;
1149 test_OnInitDocumentMgr = SINK_EXPECTED;
1150 hr = ITfDocumentMgr_Push(g_dm, cxt);
1151 ok(SUCCEEDED(hr),"Push Failed\n");
1152 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1153 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1154 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1155 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1157 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1158 ok(SUCCEEDED(hr),"GetTop Failed\n");
1159 ok(cxtTest == cxt, "Wrong context on top\n");
1160 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1161 cnt = ITfContext_Release(cxtTest);
1163 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1164 ok(SUCCEEDED(hr),"GetBase Failed\n");
1165 ok(cxtTest == cxt, "Wrong context on Base\n");
1166 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1167 ITfContext_Release(cxtTest);
1169 check_context_refcount(cxt2);
1170 test_OnPushContext = SINK_EXPECTED;
1171 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1172 ok(SUCCEEDED(hr),"Push Failed\n");
1173 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1175 cnt = check_context_refcount(cxt2);
1176 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1177 ok(SUCCEEDED(hr),"GetTop Failed\n");
1178 ok(cxtTest == cxt2, "Wrong context on top\n");
1179 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1180 ITfContext_Release(cxtTest);
1182 cnt = check_context_refcount(cxt);
1183 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1184 ok(SUCCEEDED(hr),"GetBase Failed\n");
1185 ok(cxtTest == cxt, "Wrong context on Base\n");
1186 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1187 ITfContext_Release(cxtTest);
1189 cnt = check_context_refcount(cxt3);
1190 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1191 ok(FAILED(hr),"Push Succeeded\n");
1192 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1194 cnt = check_context_refcount(cxt2);
1195 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1196 ok(SUCCEEDED(hr),"GetTop Failed\n");
1197 ok(cxtTest == cxt2, "Wrong context on top\n");
1198 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1199 ITfContext_Release(cxtTest);
1201 cnt = check_context_refcount(cxt);
1202 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1203 ok(SUCCEEDED(hr),"GetBase Failed\n");
1204 ok(cxtTest == cxt, "Wrong context on Base\n");
1205 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1206 ITfContext_Release(cxtTest);
1208 cnt = check_context_refcount(cxt2);
1209 test_OnPopContext = SINK_EXPECTED;
1210 hr = ITfDocumentMgr_Pop(g_dm, 0);
1211 ok(SUCCEEDED(hr),"Pop Failed\n");
1212 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1213 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1215 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1216 ok(SUCCEEDED(hr),"GetTop Failed\n");
1217 ok(cxtTest == cxt, "Wrong context on top\n");
1218 ITfContext_Release(cxtTest);
1220 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1221 ok(SUCCEEDED(hr),"GetBase Failed\n");
1222 ok(cxtTest == cxt, "Wrong context on base\n");
1223 ITfContext_Release(cxtTest);
1225 hr = ITfDocumentMgr_Pop(g_dm, 0);
1226 ok(FAILED(hr),"Pop Succeeded\n");
1228 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1229 ok(SUCCEEDED(hr),"GetTop Failed\n");
1230 ok(cxtTest == cxt, "Wrong context on top\n");
1231 ITfContext_Release(cxtTest);
1233 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1234 ok(SUCCEEDED(hr),"GetBase Failed\n");
1235 ok(cxtTest == cxt, "Wrong context on base\n");
1236 ITfContext_Release(cxtTest);
1238 ITfContext_Release(cxt);
1239 ITfContext_Release(cxt2);
1240 ITfContext_Release(cxt3);
1243 static void test_endSession(void)
1246 test_ShouldDeactivate = TRUE;
1247 test_CurrentFocus = NULL;
1248 test_PrevFocus = g_dm;
1249 test_OnSetFocus = SINK_EXPECTED;
1250 hr = ITfThreadMgr_Deactivate(g_tm);
1251 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1252 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1253 test_OnSetFocus = SINK_UNEXPECTED;
1256 static void test_TfGuidAtom(void)
1260 TfGuidAtom atom1,atom2;
1263 CoCreateGuid(>est);
1265 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1267 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1268 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1270 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1271 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1272 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1273 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1274 ok(atom1 == atom2,"atoms do not match\n");
1275 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1276 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1277 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1278 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1279 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1280 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1281 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1282 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1283 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1284 ok(equal == TRUE,"Equal value invalid\n");
1286 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1287 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1288 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1289 ok(equal == TRUE,"Equal value invalid\n");
1290 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1291 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1292 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1295 static void test_ClientId(void)
1302 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1303 ok(SUCCEEDED(hr),"Unable to aquire ITfClientId interface\n");
1307 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1308 ok(SUCCEEDED(hr),"GetClientId failed\n");
1309 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1310 ok(SUCCEEDED(hr),"GetClientId failed\n");
1311 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1312 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1313 ok(SUCCEEDED(hr),"GetClientId failed\n");
1314 ok(id2!=id1,"Id matches GUID_NULL\n");
1315 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1316 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1317 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1318 ok(SUCCEEDED(hr),"GetClientId failed\n");
1319 ok(id2!=id1,"Id matches GUID_NULL\n");
1320 ok(id2!=tid,"Id for random guid matching tid\n");
1321 ok(id2!=cid,"Id for random guid matching cid\n");
1322 ITfClientId_Release(pcid);
1325 /**********************************************************************
1327 **********************************************************************/
1328 typedef struct tagEditSession
1330 const ITfEditSessionVtbl *EditSessionVtbl;
1334 static void EditSession_Destructor(EditSession *This)
1336 HeapFree(GetProcessHeap(),0,This);
1339 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1341 EditSession *This = (EditSession *)iface;
1344 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1351 IUnknown_AddRef(iface);
1355 return E_NOINTERFACE;
1358 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1360 EditSession *This = (EditSession *)iface;
1361 return InterlockedIncrement(&This->refCount);
1364 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1366 EditSession *This = (EditSession *)iface;
1369 ret = InterlockedDecrement(&This->refCount);
1371 EditSession_Destructor(This);
1375 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1383 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1384 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1385 test_DoEditSession = SINK_FIRED;
1387 ITfThreadMgr_GetFocus(g_tm, &dm);
1388 ITfDocumentMgr_GetTop(dm,&cxt);
1390 hr = ITfContext_GetStart(cxt,ec,NULL);
1391 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1393 range = (ITfRange*)0xdeaddead;
1394 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1395 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1396 ok(range == NULL,"Range not set to NULL\n");
1398 hr = ITfContext_GetStart(cxt,ec,&range);
1399 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1400 ok(range != NULL,"Range set to NULL\n");
1402 ITfRange_Release(range);
1404 hr = ITfContext_GetEnd(cxt,ec,NULL);
1405 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1407 range = (ITfRange*)0xdeaddead;
1408 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1409 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1410 ok(range == NULL,"Range not set to NULL\n");
1412 test_ACP_GetEndACP = SINK_EXPECTED;
1413 hr = ITfContext_GetEnd(cxt,ec,&range);
1414 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1415 ok(range != NULL,"Range set to NULL\n");
1416 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1418 ITfRange_Release(range);
1419 ITfContext_Release(cxt);
1420 ITfDocumentMgr_Release(dm);
1424 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1426 EditSession_QueryInterface,
1428 EditSession_Release,
1430 EditSession_DoEditSession
1433 HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1437 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1439 return E_OUTOFMEMORY;
1441 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1444 *ppOut = (ITfEditSession*)This;
1448 static void test_TStoApplicationText(void)
1450 HRESULT hr, hrSession;
1455 ITfThreadMgr_GetFocus(g_tm, &dm);
1456 EditSession_Constructor(&es);
1457 ITfDocumentMgr_GetTop(dm,&cxt);
1459 hrSession = 0xfeedface;
1460 /* Test no premissions flags */
1461 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1462 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1463 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1465 hrSession = 0xfeedface;
1466 test_ACP_GetStatus = SINK_EXPECTED;
1467 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1468 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1469 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1470 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1472 test_ACP_GetStatus = SINK_UNEXPECTED;
1473 test_ACP_RequestLock = SINK_EXPECTED;
1474 hrSession = 0xfeedface;
1475 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READ, &hrSession);
1476 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1477 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1478 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1479 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1481 ITfContext_Release(cxt);
1482 ITfDocumentMgr_Release(dm);
1483 ITfEditSession_Release(es);
1486 START_TEST(inputprocessor)
1488 if (SUCCEEDED(initialize()))
1491 test_RegisterCategory();
1492 test_EnumInputProcessorInfo();
1494 test_ThreadMgrAdviseSinks();
1496 test_startSession();
1499 test_KeystrokeMgr();
1500 test_TStoApplicationText();
1502 test_EnumLanguageProfiles();
1503 test_FindClosestCategory();
1505 test_ThreadMgrUnadviseSinks();
1506 test_UnregisterCategory();
1510 skip("Unable to create InputProcessor\n");