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,
443 ITfDocumentMgr *docmgr;
446 hr = ITfContext_GetDocumentMgr(pic,&docmgr);
447 ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
448 test = (ITfContext*)0xdeadbeef;
449 ITfDocumentMgr_Release(docmgr);
450 hr = ITfDocumentMgr_GetTop(docmgr,&test);
451 ok(SUCCEEDED(hr),"GetTop failed\n");
452 ok(test == pic, "Wrong context is on top\n");
454 ITfContext_Release(test);
456 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
457 test_OnPushContext = SINK_FIRED;
461 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
465 ITfDocumentMgr *docmgr;
468 hr = ITfContext_GetDocumentMgr(pic,&docmgr);
469 ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
470 ITfDocumentMgr_Release(docmgr);
471 test = (ITfContext*)0xdeadbeef;
472 hr = ITfDocumentMgr_GetTop(docmgr,&test);
473 ok(SUCCEEDED(hr),"GetTop failed\n");
474 ok(test == pic, "Wrong context is on top\n");
476 ITfContext_Release(test);
478 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
479 test_OnPopContext = SINK_FIRED;
483 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
485 ThreadMgrEventSink_QueryInterface,
486 ThreadMgrEventSink_AddRef,
487 ThreadMgrEventSink_Release,
489 ThreadMgrEventSink_OnInitDocumentMgr,
490 ThreadMgrEventSink_OnUninitDocumentMgr,
491 ThreadMgrEventSink_OnSetFocus,
492 ThreadMgrEventSink_OnPushContext,
493 ThreadMgrEventSink_OnPopContext
496 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
498 ThreadMgrEventSink *This;
500 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
502 return E_OUTOFMEMORY;
504 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
507 *ppOut = (IUnknown *)This;
512 /********************************************************************************************
513 * Stub text service for testing
514 ********************************************************************************************/
516 static LONG TS_refCount;
517 static IClassFactory *cf;
520 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
522 typedef struct tagClassFactory
524 const IClassFactoryVtbl *vtbl;
526 LPFNCONSTRUCTOR ctor;
529 typedef struct tagTextService
531 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
535 static void ClassFactory_Destructor(ClassFactory *This)
537 HeapFree(GetProcessHeap(),0,This);
541 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
544 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
546 IClassFactory_AddRef(iface);
551 return E_NOINTERFACE;
554 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
556 ClassFactory *This = (ClassFactory *)iface;
557 return InterlockedIncrement(&This->ref);
560 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
562 ClassFactory *This = (ClassFactory *)iface;
563 ULONG ret = InterlockedDecrement(&This->ref);
566 ClassFactory_Destructor(This);
570 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
572 ClassFactory *This = (ClassFactory *)iface;
576 ret = This->ctor(punkOuter, &obj);
579 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
580 IUnknown_Release(obj);
584 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
587 InterlockedIncrement(&TS_refCount);
589 InterlockedDecrement(&TS_refCount);
594 static const IClassFactoryVtbl ClassFactoryVtbl = {
596 ClassFactory_QueryInterface,
598 ClassFactory_Release,
601 ClassFactory_CreateInstance,
602 ClassFactory_LockServer
605 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
607 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
608 This->vtbl = &ClassFactoryVtbl;
611 *ppvOut = (LPVOID)This;
616 static void TextService_Destructor(TextService *This)
618 HeapFree(GetProcessHeap(),0,This);
621 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
623 TextService *This = (TextService *)iface;
626 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
633 IUnknown_AddRef(iface);
637 return E_NOINTERFACE;
640 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
642 TextService *This = (TextService *)iface;
643 return InterlockedIncrement(&This->refCount);
646 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
648 TextService *This = (TextService *)iface;
651 ret = InterlockedDecrement(&This->refCount);
653 TextService_Destructor(This);
657 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
658 ITfThreadMgr *ptim, TfClientId id)
660 trace("TextService_Activate\n");
661 ok(test_ShouldActivate,"Activation came unexpectedly\n");
666 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
668 trace("TextService_Deactivate\n");
669 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
673 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
675 TextService_QueryInterface,
679 TextService_Activate,
680 TextService_Deactivate
683 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
687 return CLASS_E_NOAGGREGATION;
689 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
691 return E_OUTOFMEMORY;
693 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
696 *ppOut = (IUnknown *)This;
700 static HRESULT RegisterTextService(REFCLSID rclsid)
702 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
703 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
706 static HRESULT UnregisterTextService()
708 return CoRevokeClassObject(regid);
715 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
716 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
717 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
718 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
719 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
720 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
721 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
722 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
723 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
724 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
725 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_DISABLED, 0x71a5b253,0x1951,0x466b,0x9f,0xbc,0x9c,0x88,0x08,0xfa,0x84,0xf2);
726 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, 0x58273aad,0x01bb,0x4164,0x95,0xc6,0x75,0x5b,0xa0,0xb5,0x16,0x2d);
727 DEFINE_GUID(GUID_COMPARTMENT_HANDWRITING_OPENCLOSE, 0xf9ae2c6b,0x1866,0x4361,0xaf,0x72,0x7a,0xa3,0x09,0x48,0x89,0x0e);
728 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_DISABLED, 0x56c5c607,0x0703,0x4e59,0x8e,0x52,0xcb,0xc8,0x4e,0x8b,0xbe,0x35);
729 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE, 0x544d6a63,0xe2e8,0x4752,0xbb,0xd1,0x00,0x09,0x60,0xbc,0xa0,0x83);
730 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_GLOBALSTATE, 0x2a54fe8e,0x0d08,0x460c,0xa7,0x5d,0x87,0x03,0x5f,0xf4,0x36,0xc5);
731 DEFINE_GUID(GUID_COMPARTMENT_PERSISTMENUENABLED, 0x575f3783,0x70c8,0x47c8,0xae,0x5d,0x91,0xa0,0x1a,0x1f,0x75,0x92);
732 DEFINE_GUID(GUID_COMPARTMENT_EMPTYCONTEXT, 0xd7487dbf,0x804e,0x41c5,0x89,0x4d,0xad,0x96,0xfd,0x4e,0xea,0x13);
733 DEFINE_GUID(GUID_COMPARTMENT_TIPUISTATUS, 0x148ca3ec,0x0366,0x401c,0x8d,0x75,0xed,0x97,0x8d,0x85,0xfb,0xc9);
735 static HRESULT initialize(void)
739 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
740 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
742 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
743 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
745 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
746 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
750 static void cleanup(void)
753 ITfInputProcessorProfiles_Release(g_ipp);
755 ITfCategoryMgr_Release(g_cm);
757 ITfThreadMgr_Release(g_tm);
761 static void test_Register(void)
765 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
766 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
768 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
769 ok(SUCCEEDED(hr),"Unable to get current language id\n");
770 trace("Current Language %x\n",gLangid);
772 hr = RegisterTextService(&CLSID_FakeService);
773 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
774 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
775 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
776 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
777 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
780 static void test_Unregister(void)
783 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
784 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
785 UnregisterTextService();
788 static void test_EnumInputProcessorInfo(void)
793 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
797 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
799 if(IsEqualGUID(&g,&CLSID_FakeService))
803 ok(found,"Did not find registered text service\n");
806 static void test_EnumLanguageProfiles(void)
809 IEnumTfLanguageProfiles *ppEnum;
810 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
812 TF_LANGUAGEPROFILE profile;
813 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
815 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
818 ok(profile.langid == gLangid, "LangId Incorrect\n");
819 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
820 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
824 ok(found,"Registered text service not found\n");
827 static void test_RegisterCategory(void)
830 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
831 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
832 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
833 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
836 static void test_UnregisterCategory(void)
839 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
840 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
841 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
842 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
845 static void test_FindClosestCategory(void)
849 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
851 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
852 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
853 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
855 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
856 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
857 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
859 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
860 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
861 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
864 static void test_Enable(void)
867 BOOL enabled = FALSE;
869 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
870 ok(SUCCEEDED(hr),"Failed to enable text service\n");
871 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
872 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
873 ok(enabled == TRUE,"enabled state incorrect\n");
876 static void test_Disable(void)
880 trace("Disabling\n");
881 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
882 ok(SUCCEEDED(hr),"Failed to disable text service\n");
885 static void test_ThreadMgrAdviseSinks(void)
887 ITfSource *source = NULL;
891 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
892 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
896 hr = ThreadMgrEventSink_Constructor(&sink);
897 ok(hr == S_OK, "got %08x\n", hr);
898 if(FAILED(hr)) return;
902 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
903 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
904 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
906 /* Advising the sink adds a ref, Relesing here lets the object be deleted
909 IUnknown_Release(sink);
910 ITfSource_Release(source);
913 static void test_ThreadMgrUnadviseSinks(void)
915 ITfSource *source = NULL;
918 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
919 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
924 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
925 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
926 ITfSource_Release(source);
929 /**********************************************************************
931 **********************************************************************/
932 typedef struct tagKeyEventSink
934 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
938 static void KeyEventSink_Destructor(KeyEventSink *This)
940 HeapFree(GetProcessHeap(),0,This);
943 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
945 KeyEventSink *This = (KeyEventSink *)iface;
948 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
955 IUnknown_AddRef(iface);
959 return E_NOINTERFACE;
962 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
964 KeyEventSink *This = (KeyEventSink *)iface;
965 return InterlockedIncrement(&This->refCount);
968 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
970 KeyEventSink *This = (KeyEventSink *)iface;
973 ret = InterlockedDecrement(&This->refCount);
975 KeyEventSink_Destructor(This);
979 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
982 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
983 test_KEV_OnSetFocus = SINK_FIRED;
987 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
988 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
994 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
995 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1001 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
1002 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1008 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
1009 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1015 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
1016 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
1022 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
1024 KeyEventSink_QueryInterface,
1025 KeyEventSink_AddRef,
1026 KeyEventSink_Release,
1028 KeyEventSink_OnSetFocus,
1029 KeyEventSink_OnTestKeyDown,
1030 KeyEventSink_OnTestKeyUp,
1031 KeyEventSink_OnKeyDown,
1032 KeyEventSink_OnKeyUp,
1033 KeyEventSink_OnPreservedKey
1036 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1040 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1042 return E_OUTOFMEMORY;
1044 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1047 *ppOut = (ITfKeyEventSink*)This;
1052 static void test_KeystrokeMgr(void)
1054 ITfKeystrokeMgr *keymgr= NULL;
1056 TF_PRESERVEDKEY tfpk;
1058 ITfKeyEventSink *sink = NULL;
1060 KeyEventSink_Constructor(&sink);
1062 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1063 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1066 tfpk.uModifiers = TF_MOD_SHIFT;
1068 test_KEV_OnSetFocus = SINK_EXPECTED;
1069 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1070 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1071 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1072 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1073 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1074 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1075 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1077 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1078 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1080 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1081 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1083 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1084 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1087 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1088 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1089 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1091 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1092 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1094 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1095 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1096 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1098 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1099 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1101 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1102 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1104 ITfKeystrokeMgr_Release(keymgr);
1105 ITfKeyEventSink_Release(sink);
1108 static void test_Activate(void)
1112 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1113 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1116 static inline int check_context_refcount(ITfContext *iface)
1118 IUnknown_AddRef(iface);
1119 return IUnknown_Release(iface);
1122 static void test_startSession(void)
1127 ITfDocumentMgr *dmtest;
1128 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1130 TfClientId cid2 = 0;
1132 hr = ITfThreadMgr_Deactivate(g_tm);
1133 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1135 test_ShouldActivate = TRUE;
1136 hr = ITfThreadMgr_Activate(g_tm,&cid);
1137 ok(SUCCEEDED(hr),"Failed to Activate\n");
1138 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1140 test_ShouldActivate = FALSE;
1141 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1142 ok(SUCCEEDED(hr),"Failed to Activate\n");
1143 ok (cid == cid2, "Second activate client ID does not match\n");
1145 hr = ITfThreadMgr_Deactivate(g_tm);
1146 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1148 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1149 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1151 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1152 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1153 ok(dmtest == NULL,"Initial focus not null\n");
1155 test_CurrentFocus = g_dm;
1156 test_PrevFocus = NULL;
1157 test_OnSetFocus = SINK_EXPECTED;
1158 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1159 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1160 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1161 test_OnSetFocus = SINK_UNEXPECTED;
1163 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1164 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1165 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1167 cnt = ITfDocumentMgr_Release(g_dm);
1168 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1170 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1171 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1172 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1173 ITfDocumentMgr_Release(dmtest);
1175 TextStoreACP_Constructor((IUnknown**)&ts);
1177 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1178 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1180 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1181 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1183 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1184 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1186 hr = ITfContext_GetDocumentMgr(cxt,&dmtest);
1187 ok(hr == S_OK, "ITfContext_GetDocumentMgr failed with %x\n",hr);
1188 ok(dmtest == g_dm, "Wrong documentmgr\n");
1189 ITfDocumentMgr_Release(dmtest);
1191 cnt = check_context_refcount(cxt);
1192 test_OnPushContext = SINK_EXPECTED;
1193 test_ACP_AdviseSink = SINK_EXPECTED;
1194 test_OnInitDocumentMgr = SINK_EXPECTED;
1195 hr = ITfDocumentMgr_Push(g_dm, cxt);
1196 ok(SUCCEEDED(hr),"Push Failed\n");
1197 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1198 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1199 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1200 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1202 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1203 ok(SUCCEEDED(hr),"GetTop Failed\n");
1204 ok(cxtTest == cxt, "Wrong context on top\n");
1205 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1206 cnt = ITfContext_Release(cxtTest);
1208 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1209 ok(SUCCEEDED(hr),"GetBase Failed\n");
1210 ok(cxtTest == cxt, "Wrong context on Base\n");
1211 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1212 ITfContext_Release(cxtTest);
1214 check_context_refcount(cxt2);
1215 test_OnPushContext = SINK_EXPECTED;
1216 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1217 ok(SUCCEEDED(hr),"Push Failed\n");
1218 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1220 cnt = check_context_refcount(cxt2);
1221 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1222 ok(SUCCEEDED(hr),"GetTop Failed\n");
1223 ok(cxtTest == cxt2, "Wrong context on top\n");
1224 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1225 ITfContext_Release(cxtTest);
1227 cnt = check_context_refcount(cxt);
1228 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1229 ok(SUCCEEDED(hr),"GetBase Failed\n");
1230 ok(cxtTest == cxt, "Wrong context on Base\n");
1231 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1232 ITfContext_Release(cxtTest);
1234 cnt = check_context_refcount(cxt3);
1235 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1236 ok(FAILED(hr),"Push Succeeded\n");
1237 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1239 cnt = check_context_refcount(cxt2);
1240 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1241 ok(SUCCEEDED(hr),"GetTop Failed\n");
1242 ok(cxtTest == cxt2, "Wrong context on top\n");
1243 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1244 ITfContext_Release(cxtTest);
1246 cnt = check_context_refcount(cxt);
1247 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1248 ok(SUCCEEDED(hr),"GetBase Failed\n");
1249 ok(cxtTest == cxt, "Wrong context on Base\n");
1250 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1251 ITfContext_Release(cxtTest);
1253 cnt = check_context_refcount(cxt2);
1254 test_OnPopContext = SINK_EXPECTED;
1255 hr = ITfDocumentMgr_Pop(g_dm, 0);
1256 ok(SUCCEEDED(hr),"Pop Failed\n");
1257 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1258 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1260 dmtest = (void *)0xfeedface;
1261 hr = ITfContext_GetDocumentMgr(cxt2,&dmtest);
1262 ok(hr == S_FALSE, "ITfContext_GetDocumentMgr wrong rc %x\n",hr);
1263 ok(dmtest == NULL,"returned documentmgr should be null\n");
1265 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1266 ok(SUCCEEDED(hr),"GetTop Failed\n");
1267 ok(cxtTest == cxt, "Wrong context on top\n");
1268 ITfContext_Release(cxtTest);
1270 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1271 ok(SUCCEEDED(hr),"GetBase Failed\n");
1272 ok(cxtTest == cxt, "Wrong context on base\n");
1273 ITfContext_Release(cxtTest);
1275 hr = ITfDocumentMgr_Pop(g_dm, 0);
1276 ok(FAILED(hr),"Pop Succeeded\n");
1278 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1279 ok(SUCCEEDED(hr),"GetTop Failed\n");
1280 ok(cxtTest == cxt, "Wrong context on top\n");
1281 ITfContext_Release(cxtTest);
1283 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1284 ok(SUCCEEDED(hr),"GetBase Failed\n");
1285 ok(cxtTest == cxt, "Wrong context on base\n");
1286 ITfContext_Release(cxtTest);
1288 ITfContext_Release(cxt);
1289 ITfContext_Release(cxt2);
1290 ITfContext_Release(cxt3);
1293 static void test_endSession(void)
1296 test_ShouldDeactivate = TRUE;
1297 test_CurrentFocus = NULL;
1298 test_PrevFocus = g_dm;
1299 test_OnSetFocus = SINK_EXPECTED;
1300 hr = ITfThreadMgr_Deactivate(g_tm);
1301 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1302 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1303 test_OnSetFocus = SINK_UNEXPECTED;
1306 static void test_TfGuidAtom(void)
1310 TfGuidAtom atom1,atom2;
1313 CoCreateGuid(>est);
1315 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1317 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1318 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1320 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1321 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1322 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1323 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1324 ok(atom1 == atom2,"atoms do not match\n");
1325 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1326 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1327 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1328 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1329 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1330 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1331 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1332 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1333 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1334 ok(equal == TRUE,"Equal value invalid\n");
1336 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1337 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1338 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1339 ok(equal == TRUE,"Equal value invalid\n");
1340 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1341 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1342 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1345 static void test_ClientId(void)
1352 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1353 ok(SUCCEEDED(hr),"Unable to acquire ITfClientId interface\n");
1357 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1358 ok(SUCCEEDED(hr),"GetClientId failed\n");
1359 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1360 ok(SUCCEEDED(hr),"GetClientId failed\n");
1361 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1362 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1363 ok(SUCCEEDED(hr),"GetClientId failed\n");
1364 ok(id2!=id1,"Id matches GUID_NULL\n");
1365 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1366 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1367 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1368 ok(SUCCEEDED(hr),"GetClientId failed\n");
1369 ok(id2!=id1,"Id matches GUID_NULL\n");
1370 ok(id2!=tid,"Id for random guid matching tid\n");
1371 ok(id2!=cid,"Id for random guid matching cid\n");
1372 ITfClientId_Release(pcid);
1375 /**********************************************************************
1377 **********************************************************************/
1378 typedef struct tagEditSession
1380 const ITfEditSessionVtbl *EditSessionVtbl;
1384 static void EditSession_Destructor(EditSession *This)
1386 HeapFree(GetProcessHeap(),0,This);
1389 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1391 EditSession *This = (EditSession *)iface;
1394 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1401 IUnknown_AddRef(iface);
1405 return E_NOINTERFACE;
1408 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1410 EditSession *This = (EditSession *)iface;
1411 return InterlockedIncrement(&This->refCount);
1414 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1416 EditSession *This = (EditSession *)iface;
1419 ret = InterlockedDecrement(&This->refCount);
1421 EditSession_Destructor(This);
1425 static void test_InsertAtSelection(TfEditCookie ec, ITfContext *cxt)
1428 ITfInsertAtSelection *iis;
1429 ITfRange *range=NULL;
1430 static const WCHAR txt[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1432 hr = ITfContext_QueryInterface(cxt, &IID_ITfInsertAtSelection , (LPVOID*)&iis);
1433 ok(SUCCEEDED(hr),"Failed to get ITfInsertAtSelection interface\n");
1434 test_ACP_InsertTextAtSelection = SINK_EXPECTED;
1435 hr = ITfInsertAtSelection_InsertTextAtSelection(iis, ec, 0, txt, 11, &range);
1436 ok(SUCCEEDED(hr),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr);
1437 ok(test_ACP_InsertTextAtSelection == SINK_FIRED,"expected InsertTextAtSelection not fired\n");
1438 ok(range != NULL,"No range returned\n");
1439 ITfRange_Release(range);
1440 ITfInsertAtSelection_Release(iis);
1443 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1449 TF_SELECTION selection;
1453 ok(test_DoEditSession == SINK_EXPECTED, "Unexpected DoEditSession\n");
1454 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1455 test_DoEditSession = SINK_FIRED;
1457 ITfThreadMgr_GetFocus(g_tm, &dm);
1458 ITfDocumentMgr_GetTop(dm,&cxt);
1460 hr = ITfContext_GetStart(cxt,ec,NULL);
1461 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1463 range = (ITfRange*)0xdeaddead;
1464 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1465 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1466 ok(range == NULL,"Range not set to NULL\n");
1468 hr = ITfContext_GetStart(cxt,ec,&range);
1469 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1470 ok(range != NULL,"Range set to NULL\n");
1472 ITfRange_Release(range);
1474 hr = ITfContext_GetEnd(cxt,ec,NULL);
1475 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1477 range = (ITfRange*)0xdeaddead;
1478 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1479 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1480 ok(range == NULL,"Range not set to NULL\n");
1482 test_ACP_GetEndACP = SINK_EXPECTED;
1483 hr = ITfContext_GetEnd(cxt,ec,&range);
1484 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1485 ok(range != NULL,"Range set to NULL\n");
1486 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1488 ITfRange_Release(range);
1490 selection.range = NULL;
1491 test_ACP_GetSelection = SINK_EXPECTED;
1492 hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1493 ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1494 ok(fetched == 1,"fetched incorrect\n");
1495 ok(selection.range != NULL,"NULL range\n");
1496 ok(test_ACP_GetSelection == SINK_FIRED," expected ACP_GetSepection not fired\n");
1497 ITfRange_Release(selection.range);
1499 test_InsertAtSelection(ec, cxt);
1501 test_ACP_GetEndACP = SINK_EXPECTED;
1502 hr = ITfContext_GetEnd(cxt,ec,&range);
1503 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1504 ok(range != NULL,"Range set to NULL\n");
1505 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1507 selection.range = range;
1508 selection.style.ase = TF_AE_NONE;
1509 selection.style.fInterimChar = FALSE;
1510 test_ACP_SetSelection = SINK_EXPECTED;
1511 hr = ITfContext_SetSelection(cxt, ec, 1, &selection);
1512 ok(test_ACP_SetSelection == SINK_FIRED, "SetSelection not fired as expected\n");
1513 ITfRange_Release(range);
1515 ITfContext_Release(cxt);
1516 ITfDocumentMgr_Release(dm);
1520 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1522 EditSession_QueryInterface,
1524 EditSession_Release,
1526 EditSession_DoEditSession
1529 static HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1534 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1536 return E_OUTOFMEMORY;
1538 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1541 *ppOut = (ITfEditSession*)This;
1545 static void test_TStoApplicationText(void)
1547 HRESULT hr, hrSession;
1552 ITfThreadMgr_GetFocus(g_tm, &dm);
1553 EditSession_Constructor(&es);
1554 ITfDocumentMgr_GetTop(dm,&cxt);
1556 hrSession = 0xfeedface;
1557 /* Test no premissions flags */
1558 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1559 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1560 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1562 documentStatus = TS_SD_READONLY;
1563 hrSession = 0xfeedface;
1564 test_ACP_GetStatus = SINK_EXPECTED;
1565 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1566 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1567 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1568 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1570 /* signal a change to allow readwrite sessions */
1572 test_ACP_RequestLock = SINK_EXPECTED;
1573 ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1574 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1576 test_ACP_GetStatus = SINK_EXPECTED;
1577 test_ACP_RequestLock = SINK_EXPECTED;
1578 test_DoEditSession = SINK_EXPECTED;
1579 hrSession = 0xfeedface;
1580 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1581 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1582 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1583 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1584 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1585 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1587 ITfContext_Release(cxt);
1588 ITfDocumentMgr_Release(dm);
1589 ITfEditSession_Release(es);
1592 static void enum_compartments(ITfCompartmentMgr *cmpmgr, REFGUID present, REFGUID absent)
1598 if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr, &ppEnum)))
1602 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
1606 StringFromGUID2(&g,str,50);
1607 WideCharToMultiByte(CP_ACP,0,str,50,strA,50,0,0);
1608 trace("found %s\n",strA);
1609 if (present && IsEqualGUID(present,&g))
1611 if (absent && IsEqualGUID(absent, &g))
1614 IEnumGUID_Release(ppEnum);
1617 ok(found,"Did not find compartment\n");
1619 ok(!found2,"Found compartment that should be absent\n");
1622 static void test_Compartments(void)
1626 ITfCompartmentMgr *cmpmgr;
1627 ITfCompartment *cmp;
1630 ITfThreadMgr_GetFocus(g_tm, &dm);
1631 ITfDocumentMgr_GetTop(dm,&cxt);
1634 hr = ITfThreadMgr_GetGlobalCompartment(g_tm, &cmpmgr);
1635 ok(SUCCEEDED(hr),"GetGlobalCompartment failed\n");
1636 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_SPEECH_OPENCLOSE, &cmp);
1637 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1638 ITfCompartment_Release(cmp);
1639 enum_compartments(cmpmgr,&GUID_COMPARTMENT_SPEECH_OPENCLOSE,NULL);
1640 ITfCompartmentMgr_Release(cmpmgr);
1643 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1644 ok(SUCCEEDED(hr),"ThreadMgr QI for IID_ITfCompartmentMgr failed\n");
1645 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &CLSID_FakeService, &cmp);
1646 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1647 enum_compartments(cmpmgr,&CLSID_FakeService,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1648 ITfCompartmentMgr_ClearCompartment(cmpmgr,tid,&CLSID_FakeService);
1649 enum_compartments(cmpmgr,NULL,&CLSID_FakeService);
1650 ITfCompartmentMgr_Release(cmpmgr);
1651 ITfCompartment_Release(cmp);
1654 hr = ITfDocumentMgr_QueryInterface(dm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1655 ok(SUCCEEDED(hr),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1657 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_PERSISTMENUENABLED, &cmp);
1658 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1659 enum_compartments(cmpmgr,&GUID_COMPARTMENT_PERSISTMENUENABLED,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1660 ITfCompartmentMgr_Release(cmpmgr);
1663 hr = ITfContext_QueryInterface(cxt, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1664 ok(SUCCEEDED(hr),"Context QI for IID_ITfCompartmentMgr failed\n");
1665 enum_compartments(cmpmgr,NULL,&GUID_COMPARTMENT_PERSISTMENUENABLED);
1666 ITfCompartmentMgr_Release(cmpmgr);
1668 ITfContext_Release(cxt);
1669 ITfDocumentMgr_Release(dm);
1672 START_TEST(inputprocessor)
1674 if (SUCCEEDED(initialize()))
1677 test_RegisterCategory();
1678 test_EnumInputProcessorInfo();
1680 test_ThreadMgrAdviseSinks();
1682 test_startSession();
1685 test_KeystrokeMgr();
1686 test_TStoApplicationText();
1687 test_Compartments();
1689 test_EnumLanguageProfiles();
1690 test_FindClosestCategory();
1692 test_ThreadMgrUnadviseSinks();
1693 test_UnregisterCategory();
1697 skip("Unable to create InputProcessor\n");