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 #define SINK_OPTIONAL 4
49 #define SINK_ACTION_MASK 0xff
50 #define SINK_OPTION_MASK 0xff00
51 #define SINK_EXPECTED_COUNT_MASK 0xff0000
53 #define SINK_OPTION_TODO 0x0100
55 #define FOCUS_IGNORE (ITfDocumentMgr*)0xffffffff
57 static BOOL test_ShouldActivate = FALSE;
58 static BOOL test_ShouldDeactivate = FALSE;
60 static DWORD tmSinkCookie;
61 static DWORD tmSinkRefCount;
62 static DWORD documentStatus;
63 static ITfDocumentMgr *test_CurrentFocus = NULL;
64 static ITfDocumentMgr *test_PrevFocus = NULL;
65 static INT test_OnSetFocus = SINK_UNEXPECTED;
66 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
67 static INT test_OnPushContext = SINK_UNEXPECTED;
68 static INT test_OnPopContext = SINK_UNEXPECTED;
69 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
70 static INT test_ACP_AdviseSink = SINK_UNEXPECTED;
71 static INT test_ACP_GetStatus = SINK_UNEXPECTED;
72 static INT test_ACP_RequestLock = SINK_UNEXPECTED;
73 static INT test_ACP_GetEndACP = SINK_UNEXPECTED;
74 static INT test_ACP_GetSelection = SINK_UNEXPECTED;
75 static INT test_DoEditSession = SINK_UNEXPECTED;
76 static INT test_ACP_InsertTextAtSelection = SINK_UNEXPECTED;
77 static INT test_ACP_SetSelection = SINK_UNEXPECTED;
78 static INT test_OnEndEdit = SINK_UNEXPECTED;
81 static inline int expected_count(int *sink)
83 return (*sink & SINK_EXPECTED_COUNT_MASK)>>16;
86 static inline void _sink_fire_ok(INT *sink, const CHAR* name)
89 int todo = *sink & SINK_OPTION_TODO;
90 int action = *sink & SINK_ACTION_MASK;
92 if (winetest_interactive)
93 winetest_trace("firing %s\n",name);
99 count = expected_count(sink);
103 *sink = (*sink & ~SINK_EXPECTED_COUNT_MASK) + (count << 16);
108 winetest_trace("Ignoring %s\n",name);
112 todo_wine winetest_ok(0, "Unexpected %s sink\n",name);
114 winetest_ok(0, "Unexpected %s sink\n",name);
119 #define sink_fire_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_fire_ok(a,b)
121 static inline void _sink_check_ok(INT *sink, const CHAR* name)
123 int action = *sink & SINK_ACTION_MASK;
128 if (winetest_interactive)
129 winetest_trace("optional sink %s not fired\n",name);
135 winetest_ok(0, "%s not fired as expected, in state %x\n",name,*sink);
137 *sink = SINK_UNEXPECTED;
140 #define sink_check_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_ok(a,b)
142 /**********************************************************************
144 **********************************************************************/
145 typedef struct tagTextStoreACP
147 const ITextStoreACPVtbl *TextStoreACPVtbl;
152 static void TextStoreACP_Destructor(TextStoreACP *This)
154 HeapFree(GetProcessHeap(),0,This);
157 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
159 TextStoreACP *This = (TextStoreACP *)iface;
162 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
169 IUnknown_AddRef(iface);
173 return E_NOINTERFACE;
176 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
178 TextStoreACP *This = (TextStoreACP *)iface;
179 return InterlockedIncrement(&This->refCount);
182 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
184 TextStoreACP *This = (TextStoreACP *)iface;
187 ret = InterlockedDecrement(&This->refCount);
189 TextStoreACP_Destructor(This);
193 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
194 REFIID riid, IUnknown *punk, DWORD dwMask)
198 sink_fire_ok(&test_ACP_AdviseSink,"TextStoreACP_AdviseSink");
200 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&ACPSink));
201 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
205 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
212 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
213 DWORD dwLockFlags, HRESULT *phrSession)
215 sink_fire_ok(&test_ACP_RequestLock,"TextStoreACP_RequestLock");
216 *phrSession = ITextStoreACPSink_OnLockGranted(ACPSink, dwLockFlags);
219 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
222 sink_fire_ok(&test_ACP_GetStatus,"TextStoreACP_GetStatus");
223 pdcs->dwDynamicFlags = documentStatus;
226 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
227 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
233 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
234 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
236 sink_fire_ok(&test_ACP_GetSelection,"TextStoreACP_GetSelection");
238 pSelection->acpStart = 10;
239 pSelection->acpEnd = 20;
240 pSelection->style.fInterimChar = 0;
241 pSelection->style.ase = TS_AE_NONE;
246 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
247 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
249 sink_fire_ok(&test_ACP_SetSelection,"TextStoreACP_SetSelection");
252 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
253 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
254 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
255 ULONG *pcRunInfoRet, LONG *pacpNext)
260 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
261 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
262 ULONG cch, TS_TEXTCHANGE *pChange)
267 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
268 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
273 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
274 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
279 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
280 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
285 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
286 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
287 TS_TEXTCHANGE *pChange)
292 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
293 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
294 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
296 sink_fire_ok(&test_ACP_InsertTextAtSelection,"TextStoreACP_InsertTextAtSelection");
299 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
300 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
301 TS_TEXTCHANGE *pChange)
306 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
307 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
312 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
313 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
319 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
320 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
326 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
327 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
328 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
333 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
334 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
339 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
342 sink_fire_ok(&test_ACP_GetEndACP,"TextStoreACP_GetEndACP");
345 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
346 TsViewCookie *pvcView)
351 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
352 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
358 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
359 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
365 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
366 TsViewCookie vcView, RECT *prc)
371 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
372 TsViewCookie vcView, HWND *phwnd)
378 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
380 TextStoreACP_QueryInterface,
382 TextStoreACP_Release,
384 TextStoreACP_AdviseSink,
385 TextStoreACP_UnadviseSink,
386 TextStoreACP_RequestLock,
387 TextStoreACP_GetStatus,
388 TextStoreACP_QueryInsert,
389 TextStoreACP_GetSelection,
390 TextStoreACP_SetSelection,
391 TextStoreACP_GetText,
392 TextStoreACP_SetText,
393 TextStoreACP_GetFormattedText,
394 TextStoreACP_GetEmbedded,
395 TextStoreACP_QueryInsertEmbedded,
396 TextStoreACP_InsertEmbedded,
397 TextStoreACP_InsertTextAtSelection,
398 TextStoreACP_InsertEmbeddedAtSelection,
399 TextStoreACP_RequestSupportedAttrs,
400 TextStoreACP_RequestAttrsAtPosition,
401 TextStoreACP_RequestAttrsTransitioningAtPosition,
402 TextStoreACP_FindNextAttrTransition,
403 TextStoreACP_RetrieveRequestedAttrs,
404 TextStoreACP_GetEndACP,
405 TextStoreACP_GetActiveView,
406 TextStoreACP_GetACPFromPoint,
407 TextStoreACP_GetTextExt,
408 TextStoreACP_GetScreenExt,
412 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
416 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
418 return E_OUTOFMEMORY;
420 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
423 *ppOut = (IUnknown *)This;
427 /**********************************************************************
428 * ITfThreadMgrEventSink
429 **********************************************************************/
430 typedef struct tagThreadMgrEventSink
432 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
434 } ThreadMgrEventSink;
436 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
438 HeapFree(GetProcessHeap(),0,This);
441 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
443 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
446 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
453 IUnknown_AddRef(iface);
457 return E_NOINTERFACE;
460 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
462 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
463 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
464 return InterlockedIncrement(&This->refCount);
467 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
469 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
472 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
473 ret = InterlockedDecrement(&This->refCount);
475 ThreadMgrEventSink_Destructor(This);
479 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
480 ITfDocumentMgr *pdim)
482 sink_fire_ok(&test_OnInitDocumentMgr,"ThreadMgrEventSink_OnInitDocumentMgr");
486 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
487 ITfDocumentMgr *pdim)
493 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
494 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
496 sink_fire_ok(&test_OnSetFocus,"ThreadMgrEventSink_OnSetFocus");
497 if (test_CurrentFocus != FOCUS_IGNORE)
498 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
499 if (test_PrevFocus != FOCUS_IGNORE)
500 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
504 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
508 ITfDocumentMgr *docmgr;
511 hr = ITfContext_GetDocumentMgr(pic,&docmgr);
512 ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
513 test = (ITfContext*)0xdeadbeef;
514 ITfDocumentMgr_Release(docmgr);
515 hr = ITfDocumentMgr_GetTop(docmgr,&test);
516 ok(SUCCEEDED(hr),"GetTop failed\n");
517 ok(test == pic, "Wrong context is on top\n");
519 ITfContext_Release(test);
521 sink_fire_ok(&test_OnPushContext,"ThreadMgrEventSink_OnPushContext");
525 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
529 ITfDocumentMgr *docmgr;
532 hr = ITfContext_GetDocumentMgr(pic,&docmgr);
533 ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
534 ITfDocumentMgr_Release(docmgr);
535 test = (ITfContext*)0xdeadbeef;
536 hr = ITfDocumentMgr_GetTop(docmgr,&test);
537 ok(SUCCEEDED(hr),"GetTop failed\n");
538 ok(test == pic, "Wrong context is on top\n");
540 ITfContext_Release(test);
542 sink_fire_ok(&test_OnPopContext,"ThreadMgrEventSink_OnPopContext");
546 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
548 ThreadMgrEventSink_QueryInterface,
549 ThreadMgrEventSink_AddRef,
550 ThreadMgrEventSink_Release,
552 ThreadMgrEventSink_OnInitDocumentMgr,
553 ThreadMgrEventSink_OnUninitDocumentMgr,
554 ThreadMgrEventSink_OnSetFocus,
555 ThreadMgrEventSink_OnPushContext,
556 ThreadMgrEventSink_OnPopContext
559 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
561 ThreadMgrEventSink *This;
563 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
565 return E_OUTOFMEMORY;
567 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
570 *ppOut = (IUnknown *)This;
575 /********************************************************************************************
576 * Stub text service for testing
577 ********************************************************************************************/
579 static LONG TS_refCount;
580 static IClassFactory *cf;
583 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
585 typedef struct tagClassFactory
587 const IClassFactoryVtbl *vtbl;
589 LPFNCONSTRUCTOR ctor;
592 typedef struct tagTextService
594 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
598 static void ClassFactory_Destructor(ClassFactory *This)
600 HeapFree(GetProcessHeap(),0,This);
604 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
607 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
609 IClassFactory_AddRef(iface);
614 return E_NOINTERFACE;
617 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
619 ClassFactory *This = (ClassFactory *)iface;
620 return InterlockedIncrement(&This->ref);
623 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
625 ClassFactory *This = (ClassFactory *)iface;
626 ULONG ret = InterlockedDecrement(&This->ref);
629 ClassFactory_Destructor(This);
633 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
635 ClassFactory *This = (ClassFactory *)iface;
639 ret = This->ctor(punkOuter, &obj);
642 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
643 IUnknown_Release(obj);
647 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
650 InterlockedIncrement(&TS_refCount);
652 InterlockedDecrement(&TS_refCount);
657 static const IClassFactoryVtbl ClassFactoryVtbl = {
659 ClassFactory_QueryInterface,
661 ClassFactory_Release,
664 ClassFactory_CreateInstance,
665 ClassFactory_LockServer
668 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
670 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
671 This->vtbl = &ClassFactoryVtbl;
674 *ppvOut = (LPVOID)This;
679 static void TextService_Destructor(TextService *This)
681 HeapFree(GetProcessHeap(),0,This);
684 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
686 TextService *This = (TextService *)iface;
689 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
696 IUnknown_AddRef(iface);
700 return E_NOINTERFACE;
703 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
705 TextService *This = (TextService *)iface;
706 return InterlockedIncrement(&This->refCount);
709 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
711 TextService *This = (TextService *)iface;
714 ret = InterlockedDecrement(&This->refCount);
716 TextService_Destructor(This);
720 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
721 ITfThreadMgr *ptim, TfClientId id)
723 trace("TextService_Activate\n");
724 ok(test_ShouldActivate,"Activation came unexpectedly\n");
729 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
731 trace("TextService_Deactivate\n");
732 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
736 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
738 TextService_QueryInterface,
742 TextService_Activate,
743 TextService_Deactivate
746 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
750 return CLASS_E_NOAGGREGATION;
752 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
754 return E_OUTOFMEMORY;
756 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
759 *ppOut = (IUnknown *)This;
763 static HRESULT RegisterTextService(REFCLSID rclsid)
765 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
766 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
769 static HRESULT UnregisterTextService()
771 return CoRevokeClassObject(regid);
778 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
779 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
780 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
781 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
782 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
783 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
784 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
785 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
786 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
787 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
788 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_DISABLED, 0x71a5b253,0x1951,0x466b,0x9f,0xbc,0x9c,0x88,0x08,0xfa,0x84,0xf2);
789 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, 0x58273aad,0x01bb,0x4164,0x95,0xc6,0x75,0x5b,0xa0,0xb5,0x16,0x2d);
790 DEFINE_GUID(GUID_COMPARTMENT_HANDWRITING_OPENCLOSE, 0xf9ae2c6b,0x1866,0x4361,0xaf,0x72,0x7a,0xa3,0x09,0x48,0x89,0x0e);
791 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_DISABLED, 0x56c5c607,0x0703,0x4e59,0x8e,0x52,0xcb,0xc8,0x4e,0x8b,0xbe,0x35);
792 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE, 0x544d6a63,0xe2e8,0x4752,0xbb,0xd1,0x00,0x09,0x60,0xbc,0xa0,0x83);
793 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_GLOBALSTATE, 0x2a54fe8e,0x0d08,0x460c,0xa7,0x5d,0x87,0x03,0x5f,0xf4,0x36,0xc5);
794 DEFINE_GUID(GUID_COMPARTMENT_PERSISTMENUENABLED, 0x575f3783,0x70c8,0x47c8,0xae,0x5d,0x91,0xa0,0x1a,0x1f,0x75,0x92);
795 DEFINE_GUID(GUID_COMPARTMENT_EMPTYCONTEXT, 0xd7487dbf,0x804e,0x41c5,0x89,0x4d,0xad,0x96,0xfd,0x4e,0xea,0x13);
796 DEFINE_GUID(GUID_COMPARTMENT_TIPUISTATUS, 0x148ca3ec,0x0366,0x401c,0x8d,0x75,0xed,0x97,0x8d,0x85,0xfb,0xc9);
798 static HRESULT initialize(void)
802 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
803 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
805 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
806 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
808 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
809 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
813 static void cleanup(void)
816 ITfInputProcessorProfiles_Release(g_ipp);
818 ITfCategoryMgr_Release(g_cm);
820 ITfThreadMgr_Release(g_tm);
824 static void test_Register(void)
828 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
829 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
831 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
832 ok(SUCCEEDED(hr),"Unable to get current language id\n");
833 trace("Current Language %x\n",gLangid);
835 hr = RegisterTextService(&CLSID_FakeService);
836 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
837 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
838 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
839 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
840 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
843 static void test_Unregister(void)
846 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
847 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
848 UnregisterTextService();
851 static void test_EnumInputProcessorInfo(void)
856 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
860 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
862 if(IsEqualGUID(&g,&CLSID_FakeService))
866 ok(found,"Did not find registered text service\n");
869 static void test_EnumLanguageProfiles(void)
872 IEnumTfLanguageProfiles *ppEnum;
873 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
875 TF_LANGUAGEPROFILE profile;
876 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
878 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
881 ok(profile.langid == gLangid, "LangId Incorrect\n");
882 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
883 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
887 ok(found,"Registered text service not found\n");
890 static void test_RegisterCategory(void)
893 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
894 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
895 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
896 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
899 static void test_UnregisterCategory(void)
902 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
903 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
904 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
905 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
908 static void test_FindClosestCategory(void)
912 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
914 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
915 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
916 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
918 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
919 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
920 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
922 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
923 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
924 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
927 static void test_Enable(void)
930 BOOL enabled = FALSE;
932 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
933 ok(SUCCEEDED(hr),"Failed to enable text service\n");
934 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
935 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
936 ok(enabled == TRUE,"enabled state incorrect\n");
939 static void test_Disable(void)
943 trace("Disabling\n");
944 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
945 ok(SUCCEEDED(hr),"Failed to disable text service\n");
948 static void test_ThreadMgrAdviseSinks(void)
950 ITfSource *source = NULL;
954 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
955 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
959 hr = ThreadMgrEventSink_Constructor(&sink);
960 ok(hr == S_OK, "got %08x\n", hr);
961 if(FAILED(hr)) return;
965 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
966 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
967 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
969 /* Advising the sink adds a ref, Relesing here lets the object be deleted
972 IUnknown_Release(sink);
973 ITfSource_Release(source);
976 static void test_ThreadMgrUnadviseSinks(void)
978 ITfSource *source = NULL;
981 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
982 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
987 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
988 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
989 ITfSource_Release(source);
992 /**********************************************************************
994 **********************************************************************/
995 typedef struct tagKeyEventSink
997 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
1001 static void KeyEventSink_Destructor(KeyEventSink *This)
1003 HeapFree(GetProcessHeap(),0,This);
1006 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
1008 KeyEventSink *This = (KeyEventSink *)iface;
1011 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
1018 IUnknown_AddRef(iface);
1022 return E_NOINTERFACE;
1025 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
1027 KeyEventSink *This = (KeyEventSink *)iface;
1028 return InterlockedIncrement(&This->refCount);
1031 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
1033 KeyEventSink *This = (KeyEventSink *)iface;
1036 ret = InterlockedDecrement(&This->refCount);
1038 KeyEventSink_Destructor(This);
1042 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
1045 sink_fire_ok(&test_KEV_OnSetFocus,"KeyEventSink_OnSetFocus");
1049 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
1050 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1056 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
1057 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1063 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
1064 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1070 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
1071 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1077 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
1078 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
1084 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
1086 KeyEventSink_QueryInterface,
1087 KeyEventSink_AddRef,
1088 KeyEventSink_Release,
1090 KeyEventSink_OnSetFocus,
1091 KeyEventSink_OnTestKeyDown,
1092 KeyEventSink_OnTestKeyUp,
1093 KeyEventSink_OnKeyDown,
1094 KeyEventSink_OnKeyUp,
1095 KeyEventSink_OnPreservedKey
1098 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1102 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1104 return E_OUTOFMEMORY;
1106 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1109 *ppOut = (ITfKeyEventSink*)This;
1114 static void test_KeystrokeMgr(void)
1116 ITfKeystrokeMgr *keymgr= NULL;
1118 TF_PRESERVEDKEY tfpk;
1120 ITfKeyEventSink *sink = NULL;
1122 KeyEventSink_Constructor(&sink);
1124 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1125 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1128 tfpk.uModifiers = TF_MOD_SHIFT;
1130 test_KEV_OnSetFocus = SINK_EXPECTED;
1131 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1132 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1133 sink_check_ok(&test_KEV_OnSetFocus,"KeyEventSink_OnSetFocus");
1134 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1135 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1136 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1137 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1139 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1140 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1142 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1143 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1145 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1146 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1149 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1150 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1151 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1153 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1154 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1156 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1157 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1158 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1160 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1161 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1163 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1164 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1166 ITfKeystrokeMgr_Release(keymgr);
1167 ITfKeyEventSink_Release(sink);
1170 static void test_Activate(void)
1174 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1175 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1179 static void test_EnumContexts(ITfDocumentMgr *dm, ITfContext *search)
1182 IEnumTfContexts* pEnum;
1185 hr = ITfDocumentMgr_EnumContexts(dm,&pEnum);
1186 ok(SUCCEEDED(hr),"EnumContexts failed\n");
1191 while (IEnumTfContexts_Next(pEnum, 1, &cxt, &fetched) == S_OK)
1195 else if (search == cxt)
1197 ITfContext_Release(cxt);
1199 IEnumTfContexts_Release(pEnum);
1202 ok(found,"Did not find proper ITfContext\n");
1204 ok(!found,"Found an ITfContext we should should not have\n");
1207 static void test_EnumDocumentMgr(ITfThreadMgr *tm, ITfDocumentMgr *search, ITfDocumentMgr *absent)
1210 IEnumTfDocumentMgrs* pEnum;
1212 BOOL notfound = TRUE;
1214 hr = ITfThreadMgr_EnumDocumentMgrs(tm,&pEnum);
1215 ok(SUCCEEDED(hr),"EnumDocumentMgrs failed\n");
1220 while (IEnumTfDocumentMgrs_Next(pEnum, 1, &dm, &fetched) == S_OK)
1224 else if (search == dm)
1226 if (absent && dm == absent)
1228 ITfDocumentMgr_Release(dm);
1230 IEnumTfDocumentMgrs_Release(pEnum);
1233 ok(found,"Did not find proper ITfDocumentMgr\n");
1235 ok(!found,"Found an ITfDocumentMgr we should should not have\n");
1237 ok(notfound,"Found an ITfDocumentMgr we believe should be absent\n");
1240 static inline int check_context_refcount(ITfContext *iface)
1242 IUnknown_AddRef(iface);
1243 return IUnknown_Release(iface);
1247 /**********************************************************************
1249 **********************************************************************/
1250 typedef struct tagTextEditSink
1252 const ITfTextEditSinkVtbl *TextEditSinkVtbl;
1256 static void TextEditSink_Destructor(TextEditSink *This)
1258 HeapFree(GetProcessHeap(),0,This);
1261 static HRESULT WINAPI TextEditSink_QueryInterface(ITfTextEditSink *iface, REFIID iid, LPVOID *ppvOut)
1263 TextEditSink *This = (TextEditSink *)iface;
1266 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextEditSink))
1273 IUnknown_AddRef(iface);
1277 return E_NOINTERFACE;
1280 static ULONG WINAPI TextEditSink_AddRef(ITfTextEditSink *iface)
1282 TextEditSink *This = (TextEditSink *)iface;
1283 return InterlockedIncrement(&This->refCount);
1286 static ULONG WINAPI TextEditSink_Release(ITfTextEditSink *iface)
1288 TextEditSink *This = (TextEditSink *)iface;
1291 ret = InterlockedDecrement(&This->refCount);
1293 TextEditSink_Destructor(This);
1297 static HRESULT WINAPI TextEditSink_OnEndEdit(ITfTextEditSink *iface,
1298 ITfContext *pic, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
1300 sink_fire_ok(&test_OnEndEdit,"TextEditSink_OnEndEdit");
1304 static const ITfTextEditSinkVtbl TextEditSink_TextEditSinkVtbl =
1306 TextEditSink_QueryInterface,
1307 TextEditSink_AddRef,
1308 TextEditSink_Release,
1310 TextEditSink_OnEndEdit
1313 static HRESULT TextEditSink_Constructor(ITfTextEditSink **ppOut)
1318 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextEditSink));
1320 return E_OUTOFMEMORY;
1322 This->TextEditSinkVtbl = &TextEditSink_TextEditSinkVtbl;
1325 *ppOut = (ITfTextEditSink*)This;
1329 static void test_startSession(void)
1334 ITfDocumentMgr *dmtest;
1335 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1337 TfClientId cid2 = 0;
1339 hr = ITfThreadMgr_Deactivate(g_tm);
1340 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1342 test_ShouldActivate = TRUE;
1343 hr = ITfThreadMgr_Activate(g_tm,&cid);
1344 ok(SUCCEEDED(hr),"Failed to Activate\n");
1345 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1347 test_ShouldActivate = FALSE;
1348 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1349 ok(SUCCEEDED(hr),"Failed to Activate\n");
1350 ok (cid == cid2, "Second activate client ID does not match\n");
1352 hr = ITfThreadMgr_Deactivate(g_tm);
1353 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1355 test_EnumDocumentMgr(g_tm,NULL,NULL);
1357 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1358 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1360 test_EnumDocumentMgr(g_tm,g_dm,NULL);
1362 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dmtest);
1363 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1365 test_EnumDocumentMgr(g_tm,dmtest,NULL);
1367 ITfDocumentMgr_Release(dmtest);
1368 test_EnumDocumentMgr(g_tm,g_dm,dmtest);
1370 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1371 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1372 ok(dmtest == NULL,"Initial focus not null\n");
1374 test_CurrentFocus = g_dm;
1375 test_PrevFocus = NULL;
1376 test_OnSetFocus = SINK_EXPECTED;
1377 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1378 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1379 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1381 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1382 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1383 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1385 cnt = ITfDocumentMgr_Release(g_dm);
1386 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1388 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1389 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1390 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1391 ITfDocumentMgr_Release(dmtest);
1393 TextStoreACP_Constructor((IUnknown**)&ts);
1395 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1396 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1398 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1399 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1401 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1402 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1404 test_EnumContexts(g_dm, NULL);
1406 hr = ITfContext_GetDocumentMgr(cxt,&dmtest);
1407 ok(hr == S_OK, "ITfContext_GetDocumentMgr failed with %x\n",hr);
1408 ok(dmtest == g_dm, "Wrong documentmgr\n");
1409 ITfDocumentMgr_Release(dmtest);
1411 cnt = check_context_refcount(cxt);
1412 test_OnPushContext = SINK_EXPECTED;
1413 test_ACP_AdviseSink = SINK_EXPECTED;
1414 test_OnInitDocumentMgr = SINK_EXPECTED;
1415 hr = ITfDocumentMgr_Push(g_dm, cxt);
1416 ok(SUCCEEDED(hr),"Push Failed\n");
1417 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1418 sink_check_ok(&test_OnPushContext,"OnPushContext");
1419 sink_check_ok(&test_OnInitDocumentMgr,"OnInitDocumentMgr");
1420 sink_check_ok(&test_ACP_AdviseSink,"TextStoreACP_AdviseSink");
1422 test_EnumContexts(g_dm, cxt);
1424 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1425 ok(SUCCEEDED(hr),"GetTop Failed\n");
1426 ok(cxtTest == cxt, "Wrong context on top\n");
1427 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1428 cnt = ITfContext_Release(cxtTest);
1430 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1431 ok(SUCCEEDED(hr),"GetBase Failed\n");
1432 ok(cxtTest == cxt, "Wrong context on Base\n");
1433 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1434 ITfContext_Release(cxtTest);
1436 check_context_refcount(cxt2);
1437 test_OnPushContext = SINK_EXPECTED;
1438 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1439 ok(SUCCEEDED(hr),"Push Failed\n");
1440 sink_check_ok(&test_OnPushContext,"OnPushContext");
1442 cnt = check_context_refcount(cxt2);
1443 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1444 ok(SUCCEEDED(hr),"GetTop Failed\n");
1445 ok(cxtTest == cxt2, "Wrong context on top\n");
1446 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1447 ITfContext_Release(cxtTest);
1449 cnt = check_context_refcount(cxt);
1450 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1451 ok(SUCCEEDED(hr),"GetBase Failed\n");
1452 ok(cxtTest == cxt, "Wrong context on Base\n");
1453 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1454 ITfContext_Release(cxtTest);
1456 cnt = check_context_refcount(cxt3);
1457 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1458 ok(FAILED(hr),"Push Succeeded\n");
1459 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1461 cnt = check_context_refcount(cxt2);
1462 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1463 ok(SUCCEEDED(hr),"GetTop Failed\n");
1464 ok(cxtTest == cxt2, "Wrong context on top\n");
1465 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1466 ITfContext_Release(cxtTest);
1468 cnt = check_context_refcount(cxt);
1469 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1470 ok(SUCCEEDED(hr),"GetBase Failed\n");
1471 ok(cxtTest == cxt, "Wrong context on Base\n");
1472 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1473 ITfContext_Release(cxtTest);
1475 cnt = check_context_refcount(cxt2);
1476 test_OnPopContext = SINK_EXPECTED;
1477 hr = ITfDocumentMgr_Pop(g_dm, 0);
1478 ok(SUCCEEDED(hr),"Pop Failed\n");
1479 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1480 sink_check_ok(&test_OnPopContext,"OnPopContext");
1482 dmtest = (void *)0xfeedface;
1483 hr = ITfContext_GetDocumentMgr(cxt2,&dmtest);
1484 ok(hr == S_FALSE, "ITfContext_GetDocumentMgr wrong rc %x\n",hr);
1485 ok(dmtest == NULL,"returned documentmgr should be null\n");
1487 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1488 ok(SUCCEEDED(hr),"GetTop Failed\n");
1489 ok(cxtTest == cxt, "Wrong context on top\n");
1490 ITfContext_Release(cxtTest);
1492 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1493 ok(SUCCEEDED(hr),"GetBase Failed\n");
1494 ok(cxtTest == cxt, "Wrong context on base\n");
1495 ITfContext_Release(cxtTest);
1497 hr = ITfDocumentMgr_Pop(g_dm, 0);
1498 ok(FAILED(hr),"Pop Succeeded\n");
1500 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1501 ok(SUCCEEDED(hr),"GetTop Failed\n");
1502 ok(cxtTest == cxt, "Wrong context on top\n");
1503 ITfContext_Release(cxtTest);
1505 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1506 ok(SUCCEEDED(hr),"GetBase Failed\n");
1507 ok(cxtTest == cxt, "Wrong context on base\n");
1508 ITfContext_Release(cxtTest);
1510 ITfContext_Release(cxt);
1511 ITfContext_Release(cxt2);
1512 ITfContext_Release(cxt3);
1515 static void test_endSession(void)
1518 test_ShouldDeactivate = TRUE;
1519 test_CurrentFocus = NULL;
1520 test_PrevFocus = g_dm;
1521 test_OnSetFocus = SINK_EXPECTED;
1522 hr = ITfThreadMgr_Deactivate(g_tm);
1523 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1524 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1525 test_OnSetFocus = SINK_UNEXPECTED;
1528 static void test_TfGuidAtom(void)
1532 TfGuidAtom atom1,atom2;
1535 CoCreateGuid(>est);
1537 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1539 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1540 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1542 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1543 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1544 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1545 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1546 ok(atom1 == atom2,"atoms do not match\n");
1547 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1548 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1549 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1550 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1551 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1552 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1553 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1554 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1555 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1556 ok(equal == TRUE,"Equal value invalid\n");
1558 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1559 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1560 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1561 ok(equal == TRUE,"Equal value invalid\n");
1562 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1563 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1564 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1567 static void test_ClientId(void)
1574 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1575 ok(SUCCEEDED(hr),"Unable to acquire ITfClientId interface\n");
1579 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1580 ok(SUCCEEDED(hr),"GetClientId failed\n");
1581 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1582 ok(SUCCEEDED(hr),"GetClientId failed\n");
1583 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1584 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1585 ok(SUCCEEDED(hr),"GetClientId failed\n");
1586 ok(id2!=id1,"Id matches GUID_NULL\n");
1587 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1588 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1589 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1590 ok(SUCCEEDED(hr),"GetClientId failed\n");
1591 ok(id2!=id1,"Id matches GUID_NULL\n");
1592 ok(id2!=tid,"Id for random guid matching tid\n");
1593 ok(id2!=cid,"Id for random guid matching cid\n");
1594 ITfClientId_Release(pcid);
1597 /**********************************************************************
1599 **********************************************************************/
1600 typedef struct tagEditSession
1602 const ITfEditSessionVtbl *EditSessionVtbl;
1606 static void EditSession_Destructor(EditSession *This)
1608 HeapFree(GetProcessHeap(),0,This);
1611 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1613 EditSession *This = (EditSession *)iface;
1616 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1623 IUnknown_AddRef(iface);
1627 return E_NOINTERFACE;
1630 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1632 EditSession *This = (EditSession *)iface;
1633 return InterlockedIncrement(&This->refCount);
1636 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1638 EditSession *This = (EditSession *)iface;
1641 ret = InterlockedDecrement(&This->refCount);
1643 EditSession_Destructor(This);
1647 static void test_InsertAtSelection(TfEditCookie ec, ITfContext *cxt)
1650 ITfInsertAtSelection *iis;
1651 ITfRange *range=NULL;
1652 static const WCHAR txt[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1654 hr = ITfContext_QueryInterface(cxt, &IID_ITfInsertAtSelection , (LPVOID*)&iis);
1655 ok(SUCCEEDED(hr),"Failed to get ITfInsertAtSelection interface\n");
1656 test_ACP_InsertTextAtSelection = SINK_EXPECTED;
1657 hr = ITfInsertAtSelection_InsertTextAtSelection(iis, ec, 0, txt, 11, &range);
1658 ok(SUCCEEDED(hr),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr);
1659 sink_check_ok(&test_ACP_InsertTextAtSelection,"InsertTextAtSelection");
1660 ok(range != NULL,"No range returned\n");
1661 ITfRange_Release(range);
1662 ITfInsertAtSelection_Release(iis);
1665 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1671 TF_SELECTION selection;
1675 sink_fire_ok(&test_DoEditSession,"EditSession_DoEditSession");
1676 sink_check_ok(&test_ACP_RequestLock,"RequestLock");
1678 ITfThreadMgr_GetFocus(g_tm, &dm);
1679 ITfDocumentMgr_GetTop(dm,&cxt);
1681 hr = ITfContext_GetStart(cxt,ec,NULL);
1682 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1684 range = (ITfRange*)0xdeaddead;
1685 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1686 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1687 ok(range == NULL,"Range not set to NULL\n");
1689 hr = ITfContext_GetStart(cxt,ec,&range);
1690 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1691 ok(range != NULL,"Range set to NULL\n");
1693 ITfRange_Release(range);
1695 hr = ITfContext_GetEnd(cxt,ec,NULL);
1696 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1698 range = (ITfRange*)0xdeaddead;
1699 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1700 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1701 ok(range == NULL,"Range not set to NULL\n");
1703 test_ACP_GetEndACP = SINK_EXPECTED;
1704 hr = ITfContext_GetEnd(cxt,ec,&range);
1705 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1706 ok(range != NULL,"Range set to NULL\n");
1707 sink_check_ok(&test_ACP_GetEndACP,"GetEndACP");
1709 ITfRange_Release(range);
1711 selection.range = NULL;
1712 test_ACP_GetSelection = SINK_EXPECTED;
1713 hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1714 ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1715 ok(fetched == 1,"fetched incorrect\n");
1716 ok(selection.range != NULL,"NULL range\n");
1717 sink_check_ok(&test_ACP_GetSelection,"ACP_GetSepection");
1718 ITfRange_Release(selection.range);
1720 test_InsertAtSelection(ec, cxt);
1722 test_ACP_GetEndACP = SINK_EXPECTED;
1723 hr = ITfContext_GetEnd(cxt,ec,&range);
1724 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1725 ok(range != NULL,"Range set to NULL\n");
1726 sink_check_ok(&test_ACP_GetEndACP,"GetEndACP");
1728 selection.range = range;
1729 selection.style.ase = TF_AE_NONE;
1730 selection.style.fInterimChar = FALSE;
1731 test_ACP_SetSelection = SINK_EXPECTED;
1732 hr = ITfContext_SetSelection(cxt, ec, 1, &selection);
1733 sink_check_ok(&test_ACP_SetSelection,"SetSelection");
1734 ITfRange_Release(range);
1736 ITfContext_Release(cxt);
1737 ITfDocumentMgr_Release(dm);
1741 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1743 EditSession_QueryInterface,
1745 EditSession_Release,
1747 EditSession_DoEditSession
1750 static HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1755 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1757 return E_OUTOFMEMORY;
1759 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1762 *ppOut = (ITfEditSession*)This;
1766 static void test_TStoApplicationText(void)
1768 HRESULT hr, hrSession;
1772 ITfTextEditSink *sink;
1773 ITfSource *source = NULL;
1774 DWORD editSinkCookie = -1;
1776 ITfThreadMgr_GetFocus(g_tm, &dm);
1777 EditSession_Constructor(&es);
1778 ITfDocumentMgr_GetTop(dm,&cxt);
1780 TextEditSink_Constructor(&sink);
1781 hr = ITfContext_QueryInterface(cxt,&IID_ITfSource,(LPVOID*)&source);
1782 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for Context\n");
1785 hr = ITfSource_AdviseSink(source, &IID_ITfTextEditSink, (LPVOID)sink, &editSinkCookie);
1786 ok(SUCCEEDED(hr),"Failed to advise Sink\n");
1787 ok(editSinkCookie != -1,"Failed to get sink cookie\n");
1790 hrSession = 0xfeedface;
1791 /* Test no premissions flags */
1792 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1793 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1794 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1796 documentStatus = TS_SD_READONLY;
1797 hrSession = 0xfeedface;
1798 test_ACP_GetStatus = SINK_EXPECTED;
1799 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1800 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1801 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1802 sink_check_ok(&test_ACP_GetStatus,"GetStatus");
1804 /* signal a change to allow readwrite sessions */
1806 test_ACP_RequestLock = SINK_EXPECTED;
1807 ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1808 sink_check_ok(&test_ACP_RequestLock,"RequestLock");
1810 test_ACP_GetStatus = SINK_EXPECTED;
1811 test_ACP_RequestLock = SINK_EXPECTED;
1812 test_DoEditSession = SINK_EXPECTED;
1813 hrSession = 0xfeedface;
1814 test_OnEndEdit = SINK_EXPECTED;
1815 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1816 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1817 sink_check_ok(&test_OnEndEdit,"OnEndEdit");
1818 sink_check_ok(&test_DoEditSession,"DoEditSession");
1819 sink_check_ok(&test_ACP_GetStatus,"GetStatus");
1820 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1824 hr = ITfSource_UnadviseSink(source, editSinkCookie);
1825 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
1826 ITfTextEditSink_Release(sink);
1827 ITfSource_Release(source);
1830 ITfContext_Release(cxt);
1831 ITfDocumentMgr_Release(dm);
1832 ITfEditSession_Release(es);
1835 static void enum_compartments(ITfCompartmentMgr *cmpmgr, REFGUID present, REFGUID absent)
1841 if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr, &ppEnum)))
1845 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
1849 StringFromGUID2(&g,str,50);
1850 WideCharToMultiByte(CP_ACP,0,str,50,strA,50,0,0);
1851 trace("found %s\n",strA);
1852 if (present && IsEqualGUID(present,&g))
1854 if (absent && IsEqualGUID(absent, &g))
1857 IEnumGUID_Release(ppEnum);
1860 ok(found,"Did not find compartment\n");
1862 ok(!found2,"Found compartment that should be absent\n");
1865 static void test_Compartments(void)
1869 ITfCompartmentMgr *cmpmgr;
1870 ITfCompartment *cmp;
1873 ITfThreadMgr_GetFocus(g_tm, &dm);
1874 ITfDocumentMgr_GetTop(dm,&cxt);
1877 hr = ITfThreadMgr_GetGlobalCompartment(g_tm, &cmpmgr);
1878 ok(SUCCEEDED(hr),"GetGlobalCompartment failed\n");
1879 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_SPEECH_OPENCLOSE, &cmp);
1880 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1881 ITfCompartment_Release(cmp);
1882 enum_compartments(cmpmgr,&GUID_COMPARTMENT_SPEECH_OPENCLOSE,NULL);
1883 ITfCompartmentMgr_Release(cmpmgr);
1886 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1887 ok(SUCCEEDED(hr),"ThreadMgr QI for IID_ITfCompartmentMgr failed\n");
1888 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &CLSID_FakeService, &cmp);
1889 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1890 enum_compartments(cmpmgr,&CLSID_FakeService,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1891 ITfCompartmentMgr_ClearCompartment(cmpmgr,tid,&CLSID_FakeService);
1892 enum_compartments(cmpmgr,NULL,&CLSID_FakeService);
1893 ITfCompartmentMgr_Release(cmpmgr);
1894 ITfCompartment_Release(cmp);
1897 hr = ITfDocumentMgr_QueryInterface(dm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1898 ok(SUCCEEDED(hr),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1900 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_PERSISTMENUENABLED, &cmp);
1901 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1902 enum_compartments(cmpmgr,&GUID_COMPARTMENT_PERSISTMENUENABLED,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1903 ITfCompartmentMgr_Release(cmpmgr);
1906 hr = ITfContext_QueryInterface(cxt, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1907 ok(SUCCEEDED(hr),"Context QI for IID_ITfCompartmentMgr failed\n");
1908 enum_compartments(cmpmgr,NULL,&GUID_COMPARTMENT_PERSISTMENUENABLED);
1909 ITfCompartmentMgr_Release(cmpmgr);
1911 ITfContext_Release(cxt);
1912 ITfDocumentMgr_Release(dm);
1915 static void processPendingMessages(void)
1918 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1919 TranslateMessage(&msg);
1920 DispatchMessage(&msg);
1924 static void test_AssociateFocus(void)
1926 ITfDocumentMgr *dm1, *dm2, *olddm, *dmcheck, *dmorig;
1927 HWND wnd1, wnd2, wnd3;
1930 ITfThreadMgr_GetFocus(g_tm, &dmorig);
1931 test_CurrentFocus = NULL;
1932 test_PrevFocus = dmorig;
1933 test_OnSetFocus = SINK_EXPECTED;
1934 hr = ITfThreadMgr_SetFocus(g_tm,NULL);
1935 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1936 ITfDocumentMgr_Release(dmorig);
1938 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm1);
1939 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1941 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm2);
1942 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1944 wnd1 = CreateWindow("edit",NULL,WS_POPUP,0,0,200,60,NULL,NULL,NULL,NULL);
1945 ok(wnd1!=NULL,"Unable to create window 1\n");
1946 wnd2 = CreateWindow("edit",NULL,WS_POPUP,0,65,200,60,NULL,NULL,NULL,NULL);
1947 ok(wnd2!=NULL,"Unable to create window 2\n");
1948 wnd3 = CreateWindow("edit",NULL,WS_POPUP,0,130,200,60,NULL,NULL,NULL,NULL);
1949 ok(wnd3!=NULL,"Unable to create window 3\n");
1951 processPendingMessages();
1953 test_OnInitDocumentMgr = SINK_OPTIONAL; /* Vista and greater */
1954 test_OnPushContext = SINK_OPTIONAL; /* Vista and greater */
1956 ShowWindow(wnd1,SW_SHOWNORMAL);
1958 sink_check_ok(&test_OnInitDocumentMgr,"OnInitDocumentMgr");
1959 sink_check_ok(&test_OnPushContext,"OnPushContext");
1961 test_OnSetFocus = SINK_OPTIONAL; /* Vista and greater */
1962 ITfThreadMgr_GetFocus(g_tm, &test_PrevFocus);
1963 test_CurrentFocus = FOCUS_IGNORE; /* This is a default system context */
1964 processPendingMessages();
1965 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1967 test_CurrentFocus = dm1;
1968 test_PrevFocus = FOCUS_IGNORE;
1969 test_OnSetFocus = SINK_EXPECTED;
1970 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd1,dm1,&olddm);
1971 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1972 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1974 processPendingMessages();
1976 ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1977 ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1978 ITfDocumentMgr_Release(dmcheck);
1980 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,dm2,&olddm);
1981 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1982 processPendingMessages();
1983 ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1984 ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1985 ITfDocumentMgr_Release(dmcheck);
1987 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd3,dm2,&olddm);
1988 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1989 processPendingMessages();
1990 ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1991 ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1992 ITfDocumentMgr_Release(dmcheck);
1994 test_CurrentFocus = dm2;
1995 test_PrevFocus = dm1;
1996 test_OnSetFocus = SINK_EXPECTED;
1997 ShowWindow(wnd2,SW_SHOWNORMAL);
1999 processPendingMessages();
2000 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2002 ShowWindow(wnd3,SW_SHOWNORMAL);
2004 processPendingMessages();
2006 test_CurrentFocus = dm1;
2007 test_PrevFocus = dm2;
2008 test_OnSetFocus = SINK_EXPECTED;
2010 processPendingMessages();
2011 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2013 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd3,NULL,&olddm);
2014 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
2015 ok(olddm == dm2, "incorrect old DocumentMgr returned\n");
2016 ITfDocumentMgr_Release(olddm);
2018 test_CurrentFocus = dmorig;
2019 test_PrevFocus = dm1;
2020 test_OnSetFocus = SINK_EXPECTED;
2021 test_ACP_GetStatus = SINK_EXPECTED;
2022 ITfThreadMgr_SetFocus(g_tm,dmorig);
2023 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2025 test_CurrentFocus = FOCUS_IGNORE; /* NULL on XP, system default on Vista */
2026 test_PrevFocus = dmorig;
2027 test_OnSetFocus = SINK_EXPECTED;
2029 processPendingMessages();
2030 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2032 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,NULL,&olddm);
2033 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
2034 ok(olddm == dm2, "incorrect old DocumentMgr returned\n");
2035 ITfDocumentMgr_Release(olddm);
2036 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd1,NULL,&olddm);
2037 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
2038 ok(olddm == dm1, "incorrect old DocumentMgr returned\n");
2039 ITfDocumentMgr_Release(olddm);
2042 processPendingMessages();
2044 processPendingMessages();
2046 ITfDocumentMgr_Release(dm1);
2047 ITfDocumentMgr_Release(dm2);
2049 test_CurrentFocus = dmorig;
2050 test_PrevFocus = FOCUS_IGNORE;
2051 test_OnSetFocus = SINK_EXPECTED;
2052 test_ACP_GetStatus = SINK_IGNORE;
2053 ITfThreadMgr_SetFocus(g_tm,dmorig);
2054 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2056 DestroyWindow(wnd1);
2057 DestroyWindow(wnd2);
2058 test_OnPopContext = SINK_OPTIONAL; /* Vista and greater */
2059 test_OnSetFocus = SINK_OPTIONAL; /* Vista and greater */
2060 ITfThreadMgr_GetFocus(g_tm, &test_PrevFocus);
2061 test_CurrentFocus = NULL;
2062 DestroyWindow(wnd3);
2063 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2064 sink_check_ok(&test_OnPopContext,"OnPopContext");
2067 START_TEST(inputprocessor)
2069 if (SUCCEEDED(initialize()))
2072 test_RegisterCategory();
2073 test_EnumLanguageProfiles();
2074 test_EnumInputProcessorInfo();
2076 test_ThreadMgrAdviseSinks();
2078 test_startSession();
2081 test_KeystrokeMgr();
2082 test_TStoApplicationText();
2083 test_Compartments();
2084 test_AssociateFocus();
2086 test_FindClosestCategory();
2088 test_ThreadMgrUnadviseSinks();
2089 test_UnregisterCategory();
2093 skip("Unable to create InputProcessor\n");