2 * Unit tests for ITfInputProcessor
4 * Copyright 2009 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
33 static ITfInputProcessorProfiles* g_ipp;
34 static LANGID gLangid;
35 static ITfCategoryMgr * g_cm = NULL;
36 static ITfThreadMgr* g_tm = NULL;
37 static ITfDocumentMgr *g_dm = NULL;
38 static TfClientId cid = 0;
39 static TfClientId tid = 0;
41 static ITextStoreACPSink *ACPSink;
43 #define SINK_UNEXPECTED 0
44 #define SINK_EXPECTED 1
47 static BOOL test_ShouldActivate = FALSE;
48 static BOOL test_ShouldDeactivate = FALSE;
50 static DWORD tmSinkCookie;
51 static DWORD tmSinkRefCount;
52 static DWORD documentStatus;
53 static ITfDocumentMgr *test_CurrentFocus = NULL;
54 static ITfDocumentMgr *test_PrevFocus = NULL;
55 static INT test_OnSetFocus = SINK_UNEXPECTED;
56 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
57 static INT test_OnPushContext = SINK_UNEXPECTED;
58 static INT test_OnPopContext = SINK_UNEXPECTED;
59 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
60 static INT test_ACP_AdviseSink = SINK_UNEXPECTED;
61 static INT test_ACP_GetStatus = SINK_UNEXPECTED;
62 static INT test_ACP_RequestLock = SINK_UNEXPECTED;
63 static INT test_ACP_GetEndACP = SINK_UNEXPECTED;
64 static INT test_ACP_GetSelection = SINK_UNEXPECTED;
65 static INT test_DoEditSession = SINK_UNEXPECTED;
66 static INT test_ACP_InsertTextAtSelection = SINK_UNEXPECTED;
67 static INT test_ACP_SetSelection = SINK_UNEXPECTED;
70 /**********************************************************************
72 **********************************************************************/
73 typedef struct tagTextStoreACP
75 const ITextStoreACPVtbl *TextStoreACPVtbl;
80 static void TextStoreACP_Destructor(TextStoreACP *This)
82 HeapFree(GetProcessHeap(),0,This);
85 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
87 TextStoreACP *This = (TextStoreACP *)iface;
90 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
97 IUnknown_AddRef(iface);
101 return E_NOINTERFACE;
104 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
106 TextStoreACP *This = (TextStoreACP *)iface;
107 return InterlockedIncrement(&This->refCount);
110 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
112 TextStoreACP *This = (TextStoreACP *)iface;
115 ret = InterlockedDecrement(&This->refCount);
117 TextStoreACP_Destructor(This);
121 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
122 REFIID riid, IUnknown *punk, DWORD dwMask)
126 ok(test_ACP_AdviseSink == SINK_EXPECTED, "Unexpected TextStoreACP_AdviseSink sink\n");
127 test_ACP_AdviseSink = SINK_FIRED;
129 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&ACPSink));
130 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
134 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
141 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
142 DWORD dwLockFlags, HRESULT *phrSession)
144 ok(test_ACP_RequestLock == SINK_EXPECTED,"Unexpected TextStoreACP_RequestLock\n");
145 test_ACP_RequestLock = SINK_FIRED;
146 *phrSession = ITextStoreACPSink_OnLockGranted(ACPSink, dwLockFlags);
149 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
152 ok(test_ACP_GetStatus == SINK_EXPECTED, "Unexpected TextStoreACP_GetStatus\n");
153 test_ACP_GetStatus = SINK_FIRED;
154 pdcs->dwDynamicFlags = documentStatus;
157 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
158 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
164 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
165 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
167 ok(test_ACP_GetSelection == SINK_EXPECTED, "Unexpected TextStoreACP_GetSelection\n");
168 test_ACP_GetSelection = SINK_FIRED;
170 pSelection->acpStart = 10;
171 pSelection->acpEnd = 20;
172 pSelection->style.fInterimChar = 0;
173 pSelection->style.ase = TS_AE_NONE;
178 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
179 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
181 ok(test_ACP_SetSelection == SINK_EXPECTED,"Unexpected TextStoreACP_SetSelection\n");
182 test_ACP_SetSelection = SINK_FIRED;
185 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
186 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
187 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
188 ULONG *pcRunInfoRet, LONG *pacpNext)
193 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
194 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
195 ULONG cch, TS_TEXTCHANGE *pChange)
200 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
201 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
206 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
207 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
212 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
213 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
218 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
219 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
220 TS_TEXTCHANGE *pChange)
225 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
226 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
227 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
229 ok(test_ACP_InsertTextAtSelection == SINK_EXPECTED,"Unexpected TextStoreACP_InsertTextAtSelection\n");
230 test_ACP_InsertTextAtSelection = SINK_FIRED;
233 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
234 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
235 TS_TEXTCHANGE *pChange)
240 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
241 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
246 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
247 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
253 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
254 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
260 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
261 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
262 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
267 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
268 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
273 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
276 ok(test_ACP_GetEndACP == SINK_EXPECTED,"Unexpected TextStoreACP_GetEndACP\n");
277 test_ACP_GetEndACP = SINK_FIRED;
280 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
281 TsViewCookie *pvcView)
286 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
287 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
293 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
294 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
300 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
301 TsViewCookie vcView, RECT *prc)
306 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
307 TsViewCookie vcView, HWND *phwnd)
313 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
315 TextStoreACP_QueryInterface,
317 TextStoreACP_Release,
319 TextStoreACP_AdviseSink,
320 TextStoreACP_UnadviseSink,
321 TextStoreACP_RequestLock,
322 TextStoreACP_GetStatus,
323 TextStoreACP_QueryInsert,
324 TextStoreACP_GetSelection,
325 TextStoreACP_SetSelection,
326 TextStoreACP_GetText,
327 TextStoreACP_SetText,
328 TextStoreACP_GetFormattedText,
329 TextStoreACP_GetEmbedded,
330 TextStoreACP_QueryInsertEmbedded,
331 TextStoreACP_InsertEmbedded,
332 TextStoreACP_InsertTextAtSelection,
333 TextStoreACP_InsertEmbeddedAtSelection,
334 TextStoreACP_RequestSupportedAttrs,
335 TextStoreACP_RequestAttrsAtPosition,
336 TextStoreACP_RequestAttrsTransitioningAtPosition,
337 TextStoreACP_FindNextAttrTransition,
338 TextStoreACP_RetrieveRequestedAttrs,
339 TextStoreACP_GetEndACP,
340 TextStoreACP_GetActiveView,
341 TextStoreACP_GetACPFromPoint,
342 TextStoreACP_GetTextExt,
343 TextStoreACP_GetScreenExt,
347 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
351 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
353 return E_OUTOFMEMORY;
355 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
358 *ppOut = (IUnknown *)This;
362 /**********************************************************************
363 * ITfThreadMgrEventSink
364 **********************************************************************/
365 typedef struct tagThreadMgrEventSink
367 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
369 } ThreadMgrEventSink;
371 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
373 HeapFree(GetProcessHeap(),0,This);
376 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
378 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
381 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
388 IUnknown_AddRef(iface);
392 return E_NOINTERFACE;
395 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
397 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
398 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
399 return InterlockedIncrement(&This->refCount);
402 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
404 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
407 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
408 ret = InterlockedDecrement(&This->refCount);
410 ThreadMgrEventSink_Destructor(This);
414 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
415 ITfDocumentMgr *pdim)
417 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
418 test_OnInitDocumentMgr = SINK_FIRED;
422 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
423 ITfDocumentMgr *pdim)
429 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
430 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
432 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
433 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
434 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
435 test_OnSetFocus = SINK_FIRED;
439 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
442 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
443 test_OnPushContext = SINK_FIRED;
447 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
450 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
451 test_OnPopContext = SINK_FIRED;
455 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
457 ThreadMgrEventSink_QueryInterface,
458 ThreadMgrEventSink_AddRef,
459 ThreadMgrEventSink_Release,
461 ThreadMgrEventSink_OnInitDocumentMgr,
462 ThreadMgrEventSink_OnUninitDocumentMgr,
463 ThreadMgrEventSink_OnSetFocus,
464 ThreadMgrEventSink_OnPushContext,
465 ThreadMgrEventSink_OnPopContext
468 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
470 ThreadMgrEventSink *This;
472 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
474 return E_OUTOFMEMORY;
476 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
479 *ppOut = (IUnknown *)This;
484 /********************************************************************************************
485 * Stub text service for testing
486 ********************************************************************************************/
488 static LONG TS_refCount;
489 static IClassFactory *cf;
492 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
494 typedef struct tagClassFactory
496 const IClassFactoryVtbl *vtbl;
498 LPFNCONSTRUCTOR ctor;
501 typedef struct tagTextService
503 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
507 static void ClassFactory_Destructor(ClassFactory *This)
509 HeapFree(GetProcessHeap(),0,This);
513 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
516 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
518 IClassFactory_AddRef(iface);
523 return E_NOINTERFACE;
526 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
528 ClassFactory *This = (ClassFactory *)iface;
529 return InterlockedIncrement(&This->ref);
532 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
534 ClassFactory *This = (ClassFactory *)iface;
535 ULONG ret = InterlockedDecrement(&This->ref);
538 ClassFactory_Destructor(This);
542 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
544 ClassFactory *This = (ClassFactory *)iface;
548 ret = This->ctor(punkOuter, &obj);
551 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
552 IUnknown_Release(obj);
556 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
559 InterlockedIncrement(&TS_refCount);
561 InterlockedDecrement(&TS_refCount);
566 static const IClassFactoryVtbl ClassFactoryVtbl = {
568 ClassFactory_QueryInterface,
570 ClassFactory_Release,
573 ClassFactory_CreateInstance,
574 ClassFactory_LockServer
577 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
579 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
580 This->vtbl = &ClassFactoryVtbl;
583 *ppvOut = (LPVOID)This;
588 static void TextService_Destructor(TextService *This)
590 HeapFree(GetProcessHeap(),0,This);
593 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
595 TextService *This = (TextService *)iface;
598 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
605 IUnknown_AddRef(iface);
609 return E_NOINTERFACE;
612 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
614 TextService *This = (TextService *)iface;
615 return InterlockedIncrement(&This->refCount);
618 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
620 TextService *This = (TextService *)iface;
623 ret = InterlockedDecrement(&This->refCount);
625 TextService_Destructor(This);
629 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
630 ITfThreadMgr *ptim, TfClientId id)
632 trace("TextService_Activate\n");
633 ok(test_ShouldActivate,"Activation came unexpectedly\n");
638 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
640 trace("TextService_Deactivate\n");
641 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
645 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
647 TextService_QueryInterface,
651 TextService_Activate,
652 TextService_Deactivate
655 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
659 return CLASS_E_NOAGGREGATION;
661 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
663 return E_OUTOFMEMORY;
665 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
668 *ppOut = (IUnknown *)This;
672 static HRESULT RegisterTextService(REFCLSID rclsid)
674 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
675 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
678 static HRESULT UnregisterTextService()
680 return CoRevokeClassObject(regid);
687 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
688 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
689 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
690 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
691 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
692 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
693 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
694 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
695 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
696 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
697 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_DISABLED, 0x71a5b253,0x1951,0x466b,0x9f,0xbc,0x9c,0x88,0x08,0xfa,0x84,0xf2);
698 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, 0x58273aad,0x01bb,0x4164,0x95,0xc6,0x75,0x5b,0xa0,0xb5,0x16,0x2d);
699 DEFINE_GUID(GUID_COMPARTMENT_HANDWRITING_OPENCLOSE, 0xf9ae2c6b,0x1866,0x4361,0xaf,0x72,0x7a,0xa3,0x09,0x48,0x89,0x0e);
700 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_DISABLED, 0x56c5c607,0x0703,0x4e59,0x8e,0x52,0xcb,0xc8,0x4e,0x8b,0xbe,0x35);
701 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE, 0x544d6a63,0xe2e8,0x4752,0xbb,0xd1,0x00,0x09,0x60,0xbc,0xa0,0x83);
702 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_GLOBALSTATE, 0x2a54fe8e,0x0d08,0x460c,0xa7,0x5d,0x87,0x03,0x5f,0xf4,0x36,0xc5);
703 DEFINE_GUID(GUID_COMPARTMENT_PERSISTMENUENABLED, 0x575f3783,0x70c8,0x47c8,0xae,0x5d,0x91,0xa0,0x1a,0x1f,0x75,0x92);
704 DEFINE_GUID(GUID_COMPARTMENT_EMPTYCONTEXT, 0xd7487dbf,0x804e,0x41c5,0x89,0x4d,0xad,0x96,0xfd,0x4e,0xea,0x13);
705 DEFINE_GUID(GUID_COMPARTMENT_TIPUISTATUS, 0x148ca3ec,0x0366,0x401c,0x8d,0x75,0xed,0x97,0x8d,0x85,0xfb,0xc9);
707 static HRESULT initialize(void)
711 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
712 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
714 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
715 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
717 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
718 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
722 static void cleanup(void)
725 ITfInputProcessorProfiles_Release(g_ipp);
727 ITfCategoryMgr_Release(g_cm);
729 ITfThreadMgr_Release(g_tm);
733 static void test_Register(void)
737 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
738 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
740 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
741 ok(SUCCEEDED(hr),"Unable to get current language id\n");
742 trace("Current Language %x\n",gLangid);
744 hr = RegisterTextService(&CLSID_FakeService);
745 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
746 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
747 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
748 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
749 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
752 static void test_Unregister(void)
755 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
756 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
757 UnregisterTextService();
760 static void test_EnumInputProcessorInfo(void)
765 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
769 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
771 if(IsEqualGUID(&g,&CLSID_FakeService))
775 ok(found,"Did not find registered text service\n");
778 static void test_EnumLanguageProfiles(void)
781 IEnumTfLanguageProfiles *ppEnum;
782 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
784 TF_LANGUAGEPROFILE profile;
785 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
787 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
790 ok(profile.langid == gLangid, "LangId Incorrect\n");
791 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
792 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
796 ok(found,"Registered text service not found\n");
799 static void test_RegisterCategory(void)
802 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
803 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
804 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
805 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
808 static void test_UnregisterCategory(void)
811 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
812 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
813 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
814 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
817 static void test_FindClosestCategory(void)
821 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
823 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
824 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
825 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
827 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
828 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
829 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
831 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
832 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
833 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
836 static void test_Enable(void)
839 BOOL enabled = FALSE;
841 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
842 ok(SUCCEEDED(hr),"Failed to enable text service\n");
843 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
844 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
845 ok(enabled == TRUE,"enabled state incorrect\n");
848 static void test_Disable(void)
852 trace("Disabling\n");
853 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
854 ok(SUCCEEDED(hr),"Failed to disable text service\n");
857 static void test_ThreadMgrAdviseSinks(void)
859 ITfSource *source = NULL;
863 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
864 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
868 hr = ThreadMgrEventSink_Constructor(&sink);
869 ok(hr == S_OK, "got %08x\n", hr);
870 if(FAILED(hr)) return;
874 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
875 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
876 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
878 /* Advising the sink adds a ref, Relesing here lets the object be deleted
881 IUnknown_Release(sink);
882 ITfSource_Release(source);
885 static void test_ThreadMgrUnadviseSinks(void)
887 ITfSource *source = NULL;
890 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
891 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
896 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
897 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
898 ITfSource_Release(source);
901 /**********************************************************************
903 **********************************************************************/
904 typedef struct tagKeyEventSink
906 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
910 static void KeyEventSink_Destructor(KeyEventSink *This)
912 HeapFree(GetProcessHeap(),0,This);
915 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
917 KeyEventSink *This = (KeyEventSink *)iface;
920 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
927 IUnknown_AddRef(iface);
931 return E_NOINTERFACE;
934 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
936 KeyEventSink *This = (KeyEventSink *)iface;
937 return InterlockedIncrement(&This->refCount);
940 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
942 KeyEventSink *This = (KeyEventSink *)iface;
945 ret = InterlockedDecrement(&This->refCount);
947 KeyEventSink_Destructor(This);
951 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
954 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
955 test_KEV_OnSetFocus = SINK_FIRED;
959 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
960 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
966 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
967 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
973 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
974 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
980 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
981 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
987 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
988 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
994 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
996 KeyEventSink_QueryInterface,
998 KeyEventSink_Release,
1000 KeyEventSink_OnSetFocus,
1001 KeyEventSink_OnTestKeyDown,
1002 KeyEventSink_OnTestKeyUp,
1003 KeyEventSink_OnKeyDown,
1004 KeyEventSink_OnKeyUp,
1005 KeyEventSink_OnPreservedKey
1008 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1012 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1014 return E_OUTOFMEMORY;
1016 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1019 *ppOut = (ITfKeyEventSink*)This;
1024 static void test_KeystrokeMgr(void)
1026 ITfKeystrokeMgr *keymgr= NULL;
1028 TF_PRESERVEDKEY tfpk;
1030 ITfKeyEventSink *sink = NULL;
1032 KeyEventSink_Constructor(&sink);
1034 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1035 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1038 tfpk.uModifiers = TF_MOD_SHIFT;
1040 test_KEV_OnSetFocus = SINK_EXPECTED;
1041 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1042 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1043 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1044 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1045 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1046 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1047 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1049 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1050 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1052 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1053 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1055 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1056 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1059 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1060 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1061 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1063 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1064 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1066 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1067 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1068 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1070 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1071 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1073 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1074 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1076 ITfKeystrokeMgr_Release(keymgr);
1077 ITfKeyEventSink_Release(sink);
1080 static void test_Activate(void)
1084 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1085 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1088 static inline int check_context_refcount(ITfContext *iface)
1090 IUnknown_AddRef(iface);
1091 return IUnknown_Release(iface);
1094 static void test_startSession(void)
1099 ITfDocumentMgr *dmtest;
1100 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1102 TfClientId cid2 = 0;
1104 hr = ITfThreadMgr_Deactivate(g_tm);
1105 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1107 test_ShouldActivate = TRUE;
1108 hr = ITfThreadMgr_Activate(g_tm,&cid);
1109 ok(SUCCEEDED(hr),"Failed to Activate\n");
1110 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1112 test_ShouldActivate = FALSE;
1113 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1114 ok(SUCCEEDED(hr),"Failed to Activate\n");
1115 ok (cid == cid2, "Second activate client ID does not match\n");
1117 hr = ITfThreadMgr_Deactivate(g_tm);
1118 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1120 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1121 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1123 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1124 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1125 ok(dmtest == NULL,"Initial focus not null\n");
1127 test_CurrentFocus = g_dm;
1128 test_PrevFocus = NULL;
1129 test_OnSetFocus = SINK_EXPECTED;
1130 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1131 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1132 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1133 test_OnSetFocus = SINK_UNEXPECTED;
1135 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1136 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1137 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1139 cnt = ITfDocumentMgr_Release(g_dm);
1140 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1142 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1143 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1144 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1146 TextStoreACP_Constructor((IUnknown**)&ts);
1148 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1149 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1151 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1152 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1154 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1155 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1157 hr = ITfContext_GetDocumentMgr(cxt,&dmtest);
1158 ok(hr == S_OK, "ITfContext_GetDocumentMgr failed with %x\n",hr);
1159 ok(dmtest == g_dm, "Wrong documentmgr\n");
1160 ITfDocumentMgr_Release(dmtest);
1162 cnt = check_context_refcount(cxt);
1163 test_OnPushContext = SINK_EXPECTED;
1164 test_ACP_AdviseSink = SINK_EXPECTED;
1165 test_OnInitDocumentMgr = SINK_EXPECTED;
1166 hr = ITfDocumentMgr_Push(g_dm, cxt);
1167 ok(SUCCEEDED(hr),"Push Failed\n");
1168 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1169 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1170 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1171 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1173 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1174 ok(SUCCEEDED(hr),"GetTop Failed\n");
1175 ok(cxtTest == cxt, "Wrong context on top\n");
1176 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1177 cnt = ITfContext_Release(cxtTest);
1179 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1180 ok(SUCCEEDED(hr),"GetBase Failed\n");
1181 ok(cxtTest == cxt, "Wrong context on Base\n");
1182 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1183 ITfContext_Release(cxtTest);
1185 check_context_refcount(cxt2);
1186 test_OnPushContext = SINK_EXPECTED;
1187 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1188 ok(SUCCEEDED(hr),"Push Failed\n");
1189 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1191 cnt = check_context_refcount(cxt2);
1192 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1193 ok(SUCCEEDED(hr),"GetTop Failed\n");
1194 ok(cxtTest == cxt2, "Wrong context on top\n");
1195 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1196 ITfContext_Release(cxtTest);
1198 cnt = check_context_refcount(cxt);
1199 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1200 ok(SUCCEEDED(hr),"GetBase Failed\n");
1201 ok(cxtTest == cxt, "Wrong context on Base\n");
1202 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1203 ITfContext_Release(cxtTest);
1205 cnt = check_context_refcount(cxt3);
1206 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1207 ok(FAILED(hr),"Push Succeeded\n");
1208 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1210 cnt = check_context_refcount(cxt2);
1211 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1212 ok(SUCCEEDED(hr),"GetTop Failed\n");
1213 ok(cxtTest == cxt2, "Wrong context on top\n");
1214 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1215 ITfContext_Release(cxtTest);
1217 cnt = check_context_refcount(cxt);
1218 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1219 ok(SUCCEEDED(hr),"GetBase Failed\n");
1220 ok(cxtTest == cxt, "Wrong context on Base\n");
1221 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1222 ITfContext_Release(cxtTest);
1224 cnt = check_context_refcount(cxt2);
1225 test_OnPopContext = SINK_EXPECTED;
1226 hr = ITfDocumentMgr_Pop(g_dm, 0);
1227 ok(SUCCEEDED(hr),"Pop Failed\n");
1228 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1229 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1231 dmtest = (void *)0xfeedface;
1232 hr = ITfContext_GetDocumentMgr(cxt2,&dmtest);
1233 ok(hr == S_FALSE, "ITfContext_GetDocumentMgr wrong rc %x\n",hr);
1234 ok(dmtest == NULL,"returned documentmgr should be null\n");
1236 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1237 ok(SUCCEEDED(hr),"GetTop Failed\n");
1238 ok(cxtTest == cxt, "Wrong context on top\n");
1239 ITfContext_Release(cxtTest);
1241 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1242 ok(SUCCEEDED(hr),"GetBase Failed\n");
1243 ok(cxtTest == cxt, "Wrong context on base\n");
1244 ITfContext_Release(cxtTest);
1246 hr = ITfDocumentMgr_Pop(g_dm, 0);
1247 ok(FAILED(hr),"Pop Succeeded\n");
1249 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1250 ok(SUCCEEDED(hr),"GetTop Failed\n");
1251 ok(cxtTest == cxt, "Wrong context on top\n");
1252 ITfContext_Release(cxtTest);
1254 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1255 ok(SUCCEEDED(hr),"GetBase Failed\n");
1256 ok(cxtTest == cxt, "Wrong context on base\n");
1257 ITfContext_Release(cxtTest);
1259 ITfContext_Release(cxt);
1260 ITfContext_Release(cxt2);
1261 ITfContext_Release(cxt3);
1264 static void test_endSession(void)
1267 test_ShouldDeactivate = TRUE;
1268 test_CurrentFocus = NULL;
1269 test_PrevFocus = g_dm;
1270 test_OnSetFocus = SINK_EXPECTED;
1271 hr = ITfThreadMgr_Deactivate(g_tm);
1272 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1273 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1274 test_OnSetFocus = SINK_UNEXPECTED;
1277 static void test_TfGuidAtom(void)
1281 TfGuidAtom atom1,atom2;
1284 CoCreateGuid(>est);
1286 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1288 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1289 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1291 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1292 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1293 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1294 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1295 ok(atom1 == atom2,"atoms do not match\n");
1296 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1297 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1298 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1299 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1300 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1301 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1302 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1303 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1304 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1305 ok(equal == TRUE,"Equal value invalid\n");
1307 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1308 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1309 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1310 ok(equal == TRUE,"Equal value invalid\n");
1311 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1312 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1313 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1316 static void test_ClientId(void)
1323 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1324 ok(SUCCEEDED(hr),"Unable to acquire ITfClientId interface\n");
1328 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1329 ok(SUCCEEDED(hr),"GetClientId failed\n");
1330 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1331 ok(SUCCEEDED(hr),"GetClientId failed\n");
1332 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1333 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1334 ok(SUCCEEDED(hr),"GetClientId failed\n");
1335 ok(id2!=id1,"Id matches GUID_NULL\n");
1336 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1337 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1338 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1339 ok(SUCCEEDED(hr),"GetClientId failed\n");
1340 ok(id2!=id1,"Id matches GUID_NULL\n");
1341 ok(id2!=tid,"Id for random guid matching tid\n");
1342 ok(id2!=cid,"Id for random guid matching cid\n");
1343 ITfClientId_Release(pcid);
1346 /**********************************************************************
1348 **********************************************************************/
1349 typedef struct tagEditSession
1351 const ITfEditSessionVtbl *EditSessionVtbl;
1355 static void EditSession_Destructor(EditSession *This)
1357 HeapFree(GetProcessHeap(),0,This);
1360 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1362 EditSession *This = (EditSession *)iface;
1365 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1372 IUnknown_AddRef(iface);
1376 return E_NOINTERFACE;
1379 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1381 EditSession *This = (EditSession *)iface;
1382 return InterlockedIncrement(&This->refCount);
1385 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1387 EditSession *This = (EditSession *)iface;
1390 ret = InterlockedDecrement(&This->refCount);
1392 EditSession_Destructor(This);
1396 static void test_InsertAtSelection(TfEditCookie ec, ITfContext *cxt)
1399 ITfInsertAtSelection *iis;
1400 ITfRange *range=NULL;
1401 static const WCHAR txt[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1403 hr = ITfContext_QueryInterface(cxt, &IID_ITfInsertAtSelection , (LPVOID*)&iis);
1404 ok(SUCCEEDED(hr),"Failed to get ITfInsertAtSelection interface\n");
1405 test_ACP_InsertTextAtSelection = SINK_EXPECTED;
1406 hr = ITfInsertAtSelection_InsertTextAtSelection(iis, ec, 0, txt, 11, &range);
1407 ok(SUCCEEDED(hr),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr);
1408 ok(test_ACP_InsertTextAtSelection == SINK_FIRED,"expected InsertTextAtSelection not fired\n");
1409 ok(range != NULL,"No range returned\n");
1410 ITfRange_Release(range);
1411 ITfInsertAtSelection_Release(iis);
1414 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1420 TF_SELECTION selection;
1424 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1425 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1426 test_DoEditSession = SINK_FIRED;
1428 ITfThreadMgr_GetFocus(g_tm, &dm);
1429 ITfDocumentMgr_GetTop(dm,&cxt);
1431 hr = ITfContext_GetStart(cxt,ec,NULL);
1432 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1434 range = (ITfRange*)0xdeaddead;
1435 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1436 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1437 ok(range == NULL,"Range not set to NULL\n");
1439 hr = ITfContext_GetStart(cxt,ec,&range);
1440 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1441 ok(range != NULL,"Range set to NULL\n");
1443 ITfRange_Release(range);
1445 hr = ITfContext_GetEnd(cxt,ec,NULL);
1446 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1448 range = (ITfRange*)0xdeaddead;
1449 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1450 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1451 ok(range == NULL,"Range not set to NULL\n");
1453 test_ACP_GetEndACP = SINK_EXPECTED;
1454 hr = ITfContext_GetEnd(cxt,ec,&range);
1455 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1456 ok(range != NULL,"Range set to NULL\n");
1457 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1459 ITfRange_Release(range);
1461 selection.range = NULL;
1462 test_ACP_GetSelection = SINK_EXPECTED;
1463 hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1464 ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1465 ok(fetched == 1,"fetched incorrect\n");
1466 ok(selection.range != NULL,"NULL range\n");
1467 ok(test_ACP_GetSelection == SINK_FIRED," expected ACP_GetSepection not fired\n");
1468 ITfRange_Release(selection.range);
1470 test_InsertAtSelection(ec, cxt);
1472 test_ACP_GetEndACP = SINK_EXPECTED;
1473 hr = ITfContext_GetEnd(cxt,ec,&range);
1474 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1475 ok(range != NULL,"Range set to NULL\n");
1476 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1478 selection.range = range;
1479 selection.style.ase = TF_AE_NONE;
1480 selection.style.fInterimChar = FALSE;
1481 test_ACP_SetSelection = SINK_EXPECTED;
1482 hr = ITfContext_SetSelection(cxt, ec, 1, &selection);
1483 ok(test_ACP_SetSelection == SINK_FIRED, "SetSelection not fired as expected\n");
1484 ITfRange_Release(range);
1486 ITfContext_Release(cxt);
1487 ITfDocumentMgr_Release(dm);
1491 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1493 EditSession_QueryInterface,
1495 EditSession_Release,
1497 EditSession_DoEditSession
1500 static HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1505 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1507 return E_OUTOFMEMORY;
1509 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1512 *ppOut = (ITfEditSession*)This;
1516 static void test_TStoApplicationText(void)
1518 HRESULT hr, hrSession;
1523 ITfThreadMgr_GetFocus(g_tm, &dm);
1524 EditSession_Constructor(&es);
1525 ITfDocumentMgr_GetTop(dm,&cxt);
1527 hrSession = 0xfeedface;
1528 /* Test no premissions flags */
1529 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1530 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1531 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1533 documentStatus = TS_SD_READONLY;
1534 hrSession = 0xfeedface;
1535 test_ACP_GetStatus = SINK_EXPECTED;
1536 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1537 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1538 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1539 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1541 /* signal a change to allow readwrite sessions */
1543 test_ACP_RequestLock = SINK_EXPECTED;
1544 ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1545 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1547 test_ACP_GetStatus = SINK_EXPECTED;
1548 test_ACP_RequestLock = SINK_EXPECTED;
1549 test_DoEditSession = SINK_EXPECTED;
1550 hrSession = 0xfeedface;
1551 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1552 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1553 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1554 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1555 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1556 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1558 ITfContext_Release(cxt);
1559 ITfDocumentMgr_Release(dm);
1560 ITfEditSession_Release(es);
1563 static void enum_compartments(ITfCompartmentMgr *cmpmgr, REFGUID present, REFGUID absent)
1569 if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr, &ppEnum)))
1573 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
1577 StringFromGUID2(&g,str,50);
1578 WideCharToMultiByte(CP_ACP,0,str,50,strA,50,0,0);
1579 trace("found %s\n",strA);
1580 if (present && IsEqualGUID(present,&g))
1582 if (absent && IsEqualGUID(absent, &g))
1585 IEnumGUID_Release(ppEnum);
1588 ok(found,"Did not find compartment\n");
1590 ok(!found2,"Found compartment that should be absent\n");
1593 static void test_Compartments(void)
1597 ITfCompartmentMgr *cmpmgr;
1598 ITfCompartment *cmp;
1601 ITfThreadMgr_GetFocus(g_tm, &dm);
1602 ITfDocumentMgr_GetTop(dm,&cxt);
1605 hr = ITfThreadMgr_GetGlobalCompartment(g_tm, &cmpmgr);
1606 ok(SUCCEEDED(hr),"GetGlobalCompartment failed\n");
1607 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_SPEECH_OPENCLOSE, &cmp);
1608 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1609 ITfCompartment_Release(cmp);
1610 enum_compartments(cmpmgr,&GUID_COMPARTMENT_SPEECH_OPENCLOSE,NULL);
1611 ITfCompartmentMgr_Release(cmpmgr);
1614 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1615 ok(SUCCEEDED(hr),"ThreadMgr QI for IID_ITfCompartmentMgr failed\n");
1616 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &CLSID_FakeService, &cmp);
1617 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1618 enum_compartments(cmpmgr,&CLSID_FakeService,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1619 ITfCompartmentMgr_ClearCompartment(cmpmgr,tid,&CLSID_FakeService);
1620 enum_compartments(cmpmgr,NULL,&CLSID_FakeService);
1621 ITfCompartmentMgr_Release(cmpmgr);
1622 ITfCompartment_Release(cmp);
1625 hr = ITfDocumentMgr_QueryInterface(dm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1626 ok(SUCCEEDED(hr),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1628 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_PERSISTMENUENABLED, &cmp);
1629 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1630 enum_compartments(cmpmgr,&GUID_COMPARTMENT_PERSISTMENUENABLED,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1631 ITfCompartmentMgr_Release(cmpmgr);
1634 hr = ITfContext_QueryInterface(cxt, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1635 ok(SUCCEEDED(hr),"Context QI for IID_ITfCompartmentMgr failed\n");
1636 enum_compartments(cmpmgr,NULL,&GUID_COMPARTMENT_PERSISTMENUENABLED);
1637 ITfCompartmentMgr_Release(cmpmgr);
1639 ITfContext_Release(cxt);
1640 ITfDocumentMgr_Release(dm);
1643 START_TEST(inputprocessor)
1645 if (SUCCEEDED(initialize()))
1648 test_RegisterCategory();
1649 test_EnumInputProcessorInfo();
1651 test_ThreadMgrAdviseSinks();
1653 test_startSession();
1656 test_KeystrokeMgr();
1657 test_TStoApplicationText();
1658 test_Compartments();
1660 test_EnumLanguageProfiles();
1661 test_FindClosestCategory();
1663 test_ThreadMgrUnadviseSinks();
1664 test_UnregisterCategory();
1668 skip("Unable to create InputProcessor\n");