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 static BOOL test_ShouldActivate = FALSE;
56 static BOOL test_ShouldDeactivate = FALSE;
58 static DWORD tmSinkCookie;
59 static DWORD tmSinkRefCount;
60 static DWORD documentStatus;
61 static ITfDocumentMgr *test_CurrentFocus = NULL;
62 static ITfDocumentMgr *test_PrevFocus = NULL;
63 static INT test_OnSetFocus = SINK_UNEXPECTED;
64 static INT test_OnInitDocumentMgr = SINK_UNEXPECTED;
65 static INT test_OnPushContext = SINK_UNEXPECTED;
66 static INT test_OnPopContext = SINK_UNEXPECTED;
67 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
68 static INT test_ACP_AdviseSink = SINK_UNEXPECTED;
69 static INT test_ACP_GetStatus = SINK_UNEXPECTED;
70 static INT test_ACP_RequestLock = SINK_UNEXPECTED;
71 static INT test_ACP_GetEndACP = SINK_UNEXPECTED;
72 static INT test_ACP_GetSelection = SINK_UNEXPECTED;
73 static INT test_DoEditSession = SINK_UNEXPECTED;
74 static INT test_ACP_InsertTextAtSelection = SINK_UNEXPECTED;
75 static INT test_ACP_SetSelection = SINK_UNEXPECTED;
76 static INT test_OnEndEdit = SINK_UNEXPECTED;
79 static inline int expected_count(int *sink)
81 return (*sink & SINK_EXPECTED_COUNT_MASK)>>16;
84 static inline void _sink_fire_ok(INT *sink, const CHAR* name)
87 int todo = *sink & SINK_OPTION_TODO;
88 int action = *sink & SINK_ACTION_MASK;
90 if (winetest_interactive)
91 winetest_trace("firing %s\n",name);
97 count = expected_count(sink);
101 *sink = (*sink & ~SINK_EXPECTED_COUNT_MASK) + (count << 16);
106 winetest_trace("Ignoring %s\n",name);
111 winetest_ok(0, "Unexpected %s sink\n",name);
117 #define sink_fire_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_fire_ok(a,b)
119 /**********************************************************************
121 **********************************************************************/
122 typedef struct tagTextStoreACP
124 const ITextStoreACPVtbl *TextStoreACPVtbl;
129 static void TextStoreACP_Destructor(TextStoreACP *This)
131 HeapFree(GetProcessHeap(),0,This);
134 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
136 TextStoreACP *This = (TextStoreACP *)iface;
139 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
146 IUnknown_AddRef(iface);
150 return E_NOINTERFACE;
153 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
155 TextStoreACP *This = (TextStoreACP *)iface;
156 return InterlockedIncrement(&This->refCount);
159 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
161 TextStoreACP *This = (TextStoreACP *)iface;
164 ret = InterlockedDecrement(&This->refCount);
166 TextStoreACP_Destructor(This);
170 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
171 REFIID riid, IUnknown *punk, DWORD dwMask)
175 sink_fire_ok(&test_ACP_AdviseSink,"TextStoreACP_AdviseSink");
177 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&ACPSink));
178 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
182 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
189 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
190 DWORD dwLockFlags, HRESULT *phrSession)
192 sink_fire_ok(&test_ACP_RequestLock,"TextStoreACP_RequestLock");
193 *phrSession = ITextStoreACPSink_OnLockGranted(ACPSink, dwLockFlags);
196 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
199 sink_fire_ok(&test_ACP_GetStatus,"TextStoreACP_GetStatus");
200 pdcs->dwDynamicFlags = documentStatus;
203 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
204 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
210 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
211 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
213 sink_fire_ok(&test_ACP_GetSelection,"TextStoreACP_GetSelection");
215 pSelection->acpStart = 10;
216 pSelection->acpEnd = 20;
217 pSelection->style.fInterimChar = 0;
218 pSelection->style.ase = TS_AE_NONE;
223 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
224 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
226 sink_fire_ok(&test_ACP_SetSelection,"TextStoreACP_SetSelection");
229 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
230 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
231 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
232 ULONG *pcRunInfoRet, LONG *pacpNext)
237 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
238 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
239 ULONG cch, TS_TEXTCHANGE *pChange)
244 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
245 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
250 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
251 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
256 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
257 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
262 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
263 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
264 TS_TEXTCHANGE *pChange)
269 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
270 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
271 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
273 sink_fire_ok(&test_ACP_InsertTextAtSelection,"TextStoreACP_InsertTextAtSelection");
276 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
277 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
278 TS_TEXTCHANGE *pChange)
283 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
284 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
289 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
290 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
296 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
297 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
303 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
304 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
305 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
310 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
311 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
316 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
319 sink_fire_ok(&test_ACP_GetEndACP,"TextStoreACP_GetEndACP");
322 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
323 TsViewCookie *pvcView)
328 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
329 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
335 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
336 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
342 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
343 TsViewCookie vcView, RECT *prc)
348 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
349 TsViewCookie vcView, HWND *phwnd)
355 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
357 TextStoreACP_QueryInterface,
359 TextStoreACP_Release,
361 TextStoreACP_AdviseSink,
362 TextStoreACP_UnadviseSink,
363 TextStoreACP_RequestLock,
364 TextStoreACP_GetStatus,
365 TextStoreACP_QueryInsert,
366 TextStoreACP_GetSelection,
367 TextStoreACP_SetSelection,
368 TextStoreACP_GetText,
369 TextStoreACP_SetText,
370 TextStoreACP_GetFormattedText,
371 TextStoreACP_GetEmbedded,
372 TextStoreACP_QueryInsertEmbedded,
373 TextStoreACP_InsertEmbedded,
374 TextStoreACP_InsertTextAtSelection,
375 TextStoreACP_InsertEmbeddedAtSelection,
376 TextStoreACP_RequestSupportedAttrs,
377 TextStoreACP_RequestAttrsAtPosition,
378 TextStoreACP_RequestAttrsTransitioningAtPosition,
379 TextStoreACP_FindNextAttrTransition,
380 TextStoreACP_RetrieveRequestedAttrs,
381 TextStoreACP_GetEndACP,
382 TextStoreACP_GetActiveView,
383 TextStoreACP_GetACPFromPoint,
384 TextStoreACP_GetTextExt,
385 TextStoreACP_GetScreenExt,
389 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
393 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
395 return E_OUTOFMEMORY;
397 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
400 *ppOut = (IUnknown *)This;
404 /**********************************************************************
405 * ITfThreadMgrEventSink
406 **********************************************************************/
407 typedef struct tagThreadMgrEventSink
409 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
411 } ThreadMgrEventSink;
413 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
415 HeapFree(GetProcessHeap(),0,This);
418 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
420 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
423 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
430 IUnknown_AddRef(iface);
434 return E_NOINTERFACE;
437 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
439 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
440 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
441 return InterlockedIncrement(&This->refCount);
444 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
446 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
449 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
450 ret = InterlockedDecrement(&This->refCount);
452 ThreadMgrEventSink_Destructor(This);
456 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
457 ITfDocumentMgr *pdim)
459 sink_fire_ok(&test_OnInitDocumentMgr,"ThreadMgrEventSink_OnInitDocumentMgr");
463 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
464 ITfDocumentMgr *pdim)
470 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
471 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
473 sink_fire_ok(&test_OnSetFocus,"ThreadMgrEventSink_OnSetFocus");
474 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
475 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
479 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
483 ITfDocumentMgr *docmgr;
486 hr = ITfContext_GetDocumentMgr(pic,&docmgr);
487 ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
488 test = (ITfContext*)0xdeadbeef;
489 ITfDocumentMgr_Release(docmgr);
490 hr = ITfDocumentMgr_GetTop(docmgr,&test);
491 ok(SUCCEEDED(hr),"GetTop failed\n");
492 ok(test == pic, "Wrong context is on top\n");
494 ITfContext_Release(test);
496 sink_fire_ok(&test_OnPushContext,"ThreadMgrEventSink_OnPushContext");
500 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
504 ITfDocumentMgr *docmgr;
507 hr = ITfContext_GetDocumentMgr(pic,&docmgr);
508 ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
509 ITfDocumentMgr_Release(docmgr);
510 test = (ITfContext*)0xdeadbeef;
511 hr = ITfDocumentMgr_GetTop(docmgr,&test);
512 ok(SUCCEEDED(hr),"GetTop failed\n");
513 ok(test == pic, "Wrong context is on top\n");
515 ITfContext_Release(test);
517 sink_fire_ok(&test_OnPopContext,"ThreadMgrEventSink_OnPopContext");
521 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
523 ThreadMgrEventSink_QueryInterface,
524 ThreadMgrEventSink_AddRef,
525 ThreadMgrEventSink_Release,
527 ThreadMgrEventSink_OnInitDocumentMgr,
528 ThreadMgrEventSink_OnUninitDocumentMgr,
529 ThreadMgrEventSink_OnSetFocus,
530 ThreadMgrEventSink_OnPushContext,
531 ThreadMgrEventSink_OnPopContext
534 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
536 ThreadMgrEventSink *This;
538 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
540 return E_OUTOFMEMORY;
542 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
545 *ppOut = (IUnknown *)This;
550 /********************************************************************************************
551 * Stub text service for testing
552 ********************************************************************************************/
554 static LONG TS_refCount;
555 static IClassFactory *cf;
558 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
560 typedef struct tagClassFactory
562 const IClassFactoryVtbl *vtbl;
564 LPFNCONSTRUCTOR ctor;
567 typedef struct tagTextService
569 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
573 static void ClassFactory_Destructor(ClassFactory *This)
575 HeapFree(GetProcessHeap(),0,This);
579 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
582 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
584 IClassFactory_AddRef(iface);
589 return E_NOINTERFACE;
592 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
594 ClassFactory *This = (ClassFactory *)iface;
595 return InterlockedIncrement(&This->ref);
598 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
600 ClassFactory *This = (ClassFactory *)iface;
601 ULONG ret = InterlockedDecrement(&This->ref);
604 ClassFactory_Destructor(This);
608 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
610 ClassFactory *This = (ClassFactory *)iface;
614 ret = This->ctor(punkOuter, &obj);
617 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
618 IUnknown_Release(obj);
622 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
625 InterlockedIncrement(&TS_refCount);
627 InterlockedDecrement(&TS_refCount);
632 static const IClassFactoryVtbl ClassFactoryVtbl = {
634 ClassFactory_QueryInterface,
636 ClassFactory_Release,
639 ClassFactory_CreateInstance,
640 ClassFactory_LockServer
643 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
645 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
646 This->vtbl = &ClassFactoryVtbl;
649 *ppvOut = (LPVOID)This;
654 static void TextService_Destructor(TextService *This)
656 HeapFree(GetProcessHeap(),0,This);
659 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
661 TextService *This = (TextService *)iface;
664 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
671 IUnknown_AddRef(iface);
675 return E_NOINTERFACE;
678 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
680 TextService *This = (TextService *)iface;
681 return InterlockedIncrement(&This->refCount);
684 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
686 TextService *This = (TextService *)iface;
689 ret = InterlockedDecrement(&This->refCount);
691 TextService_Destructor(This);
695 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
696 ITfThreadMgr *ptim, TfClientId id)
698 trace("TextService_Activate\n");
699 ok(test_ShouldActivate,"Activation came unexpectedly\n");
704 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
706 trace("TextService_Deactivate\n");
707 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
711 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
713 TextService_QueryInterface,
717 TextService_Activate,
718 TextService_Deactivate
721 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
725 return CLASS_E_NOAGGREGATION;
727 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
729 return E_OUTOFMEMORY;
731 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
734 *ppOut = (IUnknown *)This;
738 static HRESULT RegisterTextService(REFCLSID rclsid)
740 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
741 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, ®id);
744 static HRESULT UnregisterTextService()
746 return CoRevokeClassObject(regid);
753 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
754 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
755 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
756 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
757 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
758 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
759 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
760 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
761 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
762 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
763 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_DISABLED, 0x71a5b253,0x1951,0x466b,0x9f,0xbc,0x9c,0x88,0x08,0xfa,0x84,0xf2);
764 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE, 0x58273aad,0x01bb,0x4164,0x95,0xc6,0x75,0x5b,0xa0,0xb5,0x16,0x2d);
765 DEFINE_GUID(GUID_COMPARTMENT_HANDWRITING_OPENCLOSE, 0xf9ae2c6b,0x1866,0x4361,0xaf,0x72,0x7a,0xa3,0x09,0x48,0x89,0x0e);
766 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_DISABLED, 0x56c5c607,0x0703,0x4e59,0x8e,0x52,0xcb,0xc8,0x4e,0x8b,0xbe,0x35);
767 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE, 0x544d6a63,0xe2e8,0x4752,0xbb,0xd1,0x00,0x09,0x60,0xbc,0xa0,0x83);
768 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_GLOBALSTATE, 0x2a54fe8e,0x0d08,0x460c,0xa7,0x5d,0x87,0x03,0x5f,0xf4,0x36,0xc5);
769 DEFINE_GUID(GUID_COMPARTMENT_PERSISTMENUENABLED, 0x575f3783,0x70c8,0x47c8,0xae,0x5d,0x91,0xa0,0x1a,0x1f,0x75,0x92);
770 DEFINE_GUID(GUID_COMPARTMENT_EMPTYCONTEXT, 0xd7487dbf,0x804e,0x41c5,0x89,0x4d,0xad,0x96,0xfd,0x4e,0xea,0x13);
771 DEFINE_GUID(GUID_COMPARTMENT_TIPUISTATUS, 0x148ca3ec,0x0366,0x401c,0x8d,0x75,0xed,0x97,0x8d,0x85,0xfb,0xc9);
773 static HRESULT initialize(void)
777 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
778 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
780 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
781 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
783 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
784 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
788 static void cleanup(void)
791 ITfInputProcessorProfiles_Release(g_ipp);
793 ITfCategoryMgr_Release(g_cm);
795 ITfThreadMgr_Release(g_tm);
799 static void test_Register(void)
803 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
804 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
806 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
807 ok(SUCCEEDED(hr),"Unable to get current language id\n");
808 trace("Current Language %x\n",gLangid);
810 hr = RegisterTextService(&CLSID_FakeService);
811 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
812 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
813 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
814 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
815 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
818 static void test_Unregister(void)
821 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
822 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
823 UnregisterTextService();
826 static void test_EnumInputProcessorInfo(void)
831 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
835 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
837 if(IsEqualGUID(&g,&CLSID_FakeService))
841 ok(found,"Did not find registered text service\n");
844 static void test_EnumLanguageProfiles(void)
847 IEnumTfLanguageProfiles *ppEnum;
848 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
850 TF_LANGUAGEPROFILE profile;
851 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
853 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
856 ok(profile.langid == gLangid, "LangId Incorrect\n");
857 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
858 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
862 ok(found,"Registered text service not found\n");
865 static void test_RegisterCategory(void)
868 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
869 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
870 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
871 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
874 static void test_UnregisterCategory(void)
877 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
878 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
879 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
880 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
883 static void test_FindClosestCategory(void)
887 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
889 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
890 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
891 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
893 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
894 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
895 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
897 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
898 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
899 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
902 static void test_Enable(void)
905 BOOL enabled = FALSE;
907 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
908 ok(SUCCEEDED(hr),"Failed to enable text service\n");
909 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
910 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
911 ok(enabled == TRUE,"enabled state incorrect\n");
914 static void test_Disable(void)
918 trace("Disabling\n");
919 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
920 ok(SUCCEEDED(hr),"Failed to disable text service\n");
923 static void test_ThreadMgrAdviseSinks(void)
925 ITfSource *source = NULL;
929 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
930 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
934 hr = ThreadMgrEventSink_Constructor(&sink);
935 ok(hr == S_OK, "got %08x\n", hr);
936 if(FAILED(hr)) return;
940 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
941 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
942 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
944 /* Advising the sink adds a ref, Relesing here lets the object be deleted
947 IUnknown_Release(sink);
948 ITfSource_Release(source);
951 static void test_ThreadMgrUnadviseSinks(void)
953 ITfSource *source = NULL;
956 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
957 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
962 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
963 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
964 ITfSource_Release(source);
967 /**********************************************************************
969 **********************************************************************/
970 typedef struct tagKeyEventSink
972 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
976 static void KeyEventSink_Destructor(KeyEventSink *This)
978 HeapFree(GetProcessHeap(),0,This);
981 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
983 KeyEventSink *This = (KeyEventSink *)iface;
986 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
993 IUnknown_AddRef(iface);
997 return E_NOINTERFACE;
1000 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
1002 KeyEventSink *This = (KeyEventSink *)iface;
1003 return InterlockedIncrement(&This->refCount);
1006 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
1008 KeyEventSink *This = (KeyEventSink *)iface;
1011 ret = InterlockedDecrement(&This->refCount);
1013 KeyEventSink_Destructor(This);
1017 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
1020 sink_fire_ok(&test_KEV_OnSetFocus,"KeyEventSink_OnSetFocus");
1024 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
1025 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1031 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
1032 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1038 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
1039 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1045 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
1046 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1052 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
1053 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
1059 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
1061 KeyEventSink_QueryInterface,
1062 KeyEventSink_AddRef,
1063 KeyEventSink_Release,
1065 KeyEventSink_OnSetFocus,
1066 KeyEventSink_OnTestKeyDown,
1067 KeyEventSink_OnTestKeyUp,
1068 KeyEventSink_OnKeyDown,
1069 KeyEventSink_OnKeyUp,
1070 KeyEventSink_OnPreservedKey
1073 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1077 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1079 return E_OUTOFMEMORY;
1081 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1084 *ppOut = (ITfKeyEventSink*)This;
1089 static void test_KeystrokeMgr(void)
1091 ITfKeystrokeMgr *keymgr= NULL;
1093 TF_PRESERVEDKEY tfpk;
1095 ITfKeyEventSink *sink = NULL;
1097 KeyEventSink_Constructor(&sink);
1099 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1100 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1103 tfpk.uModifiers = TF_MOD_SHIFT;
1105 test_KEV_OnSetFocus = SINK_EXPECTED;
1106 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1107 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1108 ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
1109 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1110 ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1111 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1112 ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1114 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1115 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1117 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1118 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1120 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1121 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1124 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1125 ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1126 if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1128 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1129 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1131 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1132 ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1133 if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1135 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1136 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1138 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1139 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1141 ITfKeystrokeMgr_Release(keymgr);
1142 ITfKeyEventSink_Release(sink);
1145 static void test_Activate(void)
1149 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1150 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1154 static void test_EnumContexts(ITfDocumentMgr *dm, ITfContext *search)
1157 IEnumTfContexts* pEnum;
1160 hr = ITfDocumentMgr_EnumContexts(dm,&pEnum);
1161 ok(SUCCEEDED(hr),"EnumContexts failed\n");
1166 while (IEnumTfContexts_Next(pEnum, 1, &cxt, &fetched) == S_OK)
1170 else if (search == cxt)
1172 ITfContext_Release(cxt);
1174 IEnumTfContexts_Release(pEnum);
1177 ok(found,"Did not find proper ITfContext\n");
1179 ok(!found,"Found an ITfContext we should should not have\n");
1182 static void test_EnumDocumentMgr(ITfThreadMgr *tm, ITfDocumentMgr *search, ITfDocumentMgr *absent)
1185 IEnumTfDocumentMgrs* pEnum;
1187 BOOL notfound = TRUE;
1189 hr = ITfThreadMgr_EnumDocumentMgrs(tm,&pEnum);
1190 ok(SUCCEEDED(hr),"EnumDocumentMgrs failed\n");
1195 while (IEnumTfDocumentMgrs_Next(pEnum, 1, &dm, &fetched) == S_OK)
1199 else if (search == dm)
1201 if (absent && dm == absent)
1203 ITfDocumentMgr_Release(dm);
1205 IEnumTfDocumentMgrs_Release(pEnum);
1208 ok(found,"Did not find proper ITfDocumentMgr\n");
1210 ok(!found,"Found an ITfDocumentMgr we should should not have\n");
1212 ok(notfound,"Found an ITfDocumentMgr we believe should be absent\n");
1215 static inline int check_context_refcount(ITfContext *iface)
1217 IUnknown_AddRef(iface);
1218 return IUnknown_Release(iface);
1222 /**********************************************************************
1224 **********************************************************************/
1225 typedef struct tagTextEditSink
1227 const ITfTextEditSinkVtbl *TextEditSinkVtbl;
1231 static void TextEditSink_Destructor(TextEditSink *This)
1233 HeapFree(GetProcessHeap(),0,This);
1236 static HRESULT WINAPI TextEditSink_QueryInterface(ITfTextEditSink *iface, REFIID iid, LPVOID *ppvOut)
1238 TextEditSink *This = (TextEditSink *)iface;
1241 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextEditSink))
1248 IUnknown_AddRef(iface);
1252 return E_NOINTERFACE;
1255 static ULONG WINAPI TextEditSink_AddRef(ITfTextEditSink *iface)
1257 TextEditSink *This = (TextEditSink *)iface;
1258 return InterlockedIncrement(&This->refCount);
1261 static ULONG WINAPI TextEditSink_Release(ITfTextEditSink *iface)
1263 TextEditSink *This = (TextEditSink *)iface;
1266 ret = InterlockedDecrement(&This->refCount);
1268 TextEditSink_Destructor(This);
1272 static HRESULT WINAPI TextEditSink_OnEndEdit(ITfTextEditSink *iface,
1273 ITfContext *pic, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
1275 sink_fire_ok(&test_OnEndEdit,"TextEditSink_OnEndEdit");
1279 static const ITfTextEditSinkVtbl TextEditSink_TextEditSinkVtbl =
1281 TextEditSink_QueryInterface,
1282 TextEditSink_AddRef,
1283 TextEditSink_Release,
1285 TextEditSink_OnEndEdit
1288 static HRESULT TextEditSink_Constructor(ITfTextEditSink **ppOut)
1293 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextEditSink));
1295 return E_OUTOFMEMORY;
1297 This->TextEditSinkVtbl = &TextEditSink_TextEditSinkVtbl;
1300 *ppOut = (ITfTextEditSink*)This;
1304 static void test_startSession(void)
1309 ITfDocumentMgr *dmtest;
1310 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1312 TfClientId cid2 = 0;
1314 hr = ITfThreadMgr_Deactivate(g_tm);
1315 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1317 test_ShouldActivate = TRUE;
1318 hr = ITfThreadMgr_Activate(g_tm,&cid);
1319 ok(SUCCEEDED(hr),"Failed to Activate\n");
1320 ok(cid != tid,"TextService id mistakenly matches Client id\n");
1322 test_ShouldActivate = FALSE;
1323 hr = ITfThreadMgr_Activate(g_tm,&cid2);
1324 ok(SUCCEEDED(hr),"Failed to Activate\n");
1325 ok (cid == cid2, "Second activate client ID does not match\n");
1327 hr = ITfThreadMgr_Deactivate(g_tm);
1328 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1330 test_EnumDocumentMgr(g_tm,NULL,NULL);
1332 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1333 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1335 test_EnumDocumentMgr(g_tm,g_dm,NULL);
1337 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dmtest);
1338 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1340 test_EnumDocumentMgr(g_tm,dmtest,NULL);
1342 ITfDocumentMgr_Release(dmtest);
1343 test_EnumDocumentMgr(g_tm,g_dm,dmtest);
1345 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1346 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1347 ok(dmtest == NULL,"Initial focus not null\n");
1349 test_CurrentFocus = g_dm;
1350 test_PrevFocus = NULL;
1351 test_OnSetFocus = SINK_EXPECTED;
1352 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1353 ok(SUCCEEDED(hr),"SetFocus Failed\n");
1354 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1355 test_OnSetFocus = SINK_UNEXPECTED;
1357 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1358 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1359 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1361 cnt = ITfDocumentMgr_Release(g_dm);
1362 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1364 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1365 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1366 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1367 ITfDocumentMgr_Release(dmtest);
1369 TextStoreACP_Constructor((IUnknown**)&ts);
1371 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1372 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1374 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1375 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1377 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1378 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1380 test_EnumContexts(g_dm, NULL);
1382 hr = ITfContext_GetDocumentMgr(cxt,&dmtest);
1383 ok(hr == S_OK, "ITfContext_GetDocumentMgr failed with %x\n",hr);
1384 ok(dmtest == g_dm, "Wrong documentmgr\n");
1385 ITfDocumentMgr_Release(dmtest);
1387 cnt = check_context_refcount(cxt);
1388 test_OnPushContext = SINK_EXPECTED;
1389 test_ACP_AdviseSink = SINK_EXPECTED;
1390 test_OnInitDocumentMgr = SINK_EXPECTED;
1391 hr = ITfDocumentMgr_Push(g_dm, cxt);
1392 ok(SUCCEEDED(hr),"Push Failed\n");
1393 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1394 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1395 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
1396 ok(test_ACP_AdviseSink == SINK_FIRED,"TextStoreACP_AdviseSink not fired\n");
1398 test_EnumContexts(g_dm, cxt);
1400 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1401 ok(SUCCEEDED(hr),"GetTop Failed\n");
1402 ok(cxtTest == cxt, "Wrong context on top\n");
1403 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1404 cnt = ITfContext_Release(cxtTest);
1406 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1407 ok(SUCCEEDED(hr),"GetBase Failed\n");
1408 ok(cxtTest == cxt, "Wrong context on Base\n");
1409 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1410 ITfContext_Release(cxtTest);
1412 check_context_refcount(cxt2);
1413 test_OnPushContext = SINK_EXPECTED;
1414 hr = ITfDocumentMgr_Push(g_dm, cxt2);
1415 ok(SUCCEEDED(hr),"Push Failed\n");
1416 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
1418 cnt = check_context_refcount(cxt2);
1419 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1420 ok(SUCCEEDED(hr),"GetTop Failed\n");
1421 ok(cxtTest == cxt2, "Wrong context on top\n");
1422 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1423 ITfContext_Release(cxtTest);
1425 cnt = check_context_refcount(cxt);
1426 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1427 ok(SUCCEEDED(hr),"GetBase Failed\n");
1428 ok(cxtTest == cxt, "Wrong context on Base\n");
1429 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1430 ITfContext_Release(cxtTest);
1432 cnt = check_context_refcount(cxt3);
1433 hr = ITfDocumentMgr_Push(g_dm, cxt3);
1434 ok(FAILED(hr),"Push Succeeded\n");
1435 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1437 cnt = check_context_refcount(cxt2);
1438 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1439 ok(SUCCEEDED(hr),"GetTop Failed\n");
1440 ok(cxtTest == cxt2, "Wrong context on top\n");
1441 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1442 ITfContext_Release(cxtTest);
1444 cnt = check_context_refcount(cxt);
1445 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1446 ok(SUCCEEDED(hr),"GetBase Failed\n");
1447 ok(cxtTest == cxt, "Wrong context on Base\n");
1448 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1449 ITfContext_Release(cxtTest);
1451 cnt = check_context_refcount(cxt2);
1452 test_OnPopContext = SINK_EXPECTED;
1453 hr = ITfDocumentMgr_Pop(g_dm, 0);
1454 ok(SUCCEEDED(hr),"Pop Failed\n");
1455 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1456 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
1458 dmtest = (void *)0xfeedface;
1459 hr = ITfContext_GetDocumentMgr(cxt2,&dmtest);
1460 ok(hr == S_FALSE, "ITfContext_GetDocumentMgr wrong rc %x\n",hr);
1461 ok(dmtest == NULL,"returned documentmgr should be null\n");
1463 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1464 ok(SUCCEEDED(hr),"GetTop Failed\n");
1465 ok(cxtTest == cxt, "Wrong context on top\n");
1466 ITfContext_Release(cxtTest);
1468 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1469 ok(SUCCEEDED(hr),"GetBase Failed\n");
1470 ok(cxtTest == cxt, "Wrong context on base\n");
1471 ITfContext_Release(cxtTest);
1473 hr = ITfDocumentMgr_Pop(g_dm, 0);
1474 ok(FAILED(hr),"Pop Succeeded\n");
1476 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1477 ok(SUCCEEDED(hr),"GetTop Failed\n");
1478 ok(cxtTest == cxt, "Wrong context on top\n");
1479 ITfContext_Release(cxtTest);
1481 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1482 ok(SUCCEEDED(hr),"GetBase Failed\n");
1483 ok(cxtTest == cxt, "Wrong context on base\n");
1484 ITfContext_Release(cxtTest);
1486 ITfContext_Release(cxt);
1487 ITfContext_Release(cxt2);
1488 ITfContext_Release(cxt3);
1491 static void test_endSession(void)
1494 test_ShouldDeactivate = TRUE;
1495 test_CurrentFocus = NULL;
1496 test_PrevFocus = g_dm;
1497 test_OnSetFocus = SINK_EXPECTED;
1498 hr = ITfThreadMgr_Deactivate(g_tm);
1499 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1500 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
1501 test_OnSetFocus = SINK_UNEXPECTED;
1504 static void test_TfGuidAtom(void)
1508 TfGuidAtom atom1,atom2;
1511 CoCreateGuid(>est);
1513 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1515 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1516 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1518 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom1);
1519 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1520 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,&atom2);
1521 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1522 ok(atom1 == atom2,"atoms do not match\n");
1523 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1524 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1525 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1526 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1527 ok(IsEqualGUID(&g1,>est),"guids do not match\n");
1528 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,NULL);
1529 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1530 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,>est,&equal);
1531 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1532 ok(equal == TRUE,"Equal value invalid\n");
1534 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1535 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1536 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1537 ok(equal == TRUE,"Equal value invalid\n");
1538 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1539 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1540 ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1543 static void test_ClientId(void)
1550 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1551 ok(SUCCEEDED(hr),"Unable to acquire ITfClientId interface\n");
1555 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1556 ok(SUCCEEDED(hr),"GetClientId failed\n");
1557 hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1558 ok(SUCCEEDED(hr),"GetClientId failed\n");
1559 ok(id1==id2,"Id's for GUID_NULL do not match\n");
1560 hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1561 ok(SUCCEEDED(hr),"GetClientId failed\n");
1562 ok(id2!=id1,"Id matches GUID_NULL\n");
1563 ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1564 ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1565 hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1566 ok(SUCCEEDED(hr),"GetClientId failed\n");
1567 ok(id2!=id1,"Id matches GUID_NULL\n");
1568 ok(id2!=tid,"Id for random guid matching tid\n");
1569 ok(id2!=cid,"Id for random guid matching cid\n");
1570 ITfClientId_Release(pcid);
1573 /**********************************************************************
1575 **********************************************************************/
1576 typedef struct tagEditSession
1578 const ITfEditSessionVtbl *EditSessionVtbl;
1582 static void EditSession_Destructor(EditSession *This)
1584 HeapFree(GetProcessHeap(),0,This);
1587 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1589 EditSession *This = (EditSession *)iface;
1592 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1599 IUnknown_AddRef(iface);
1603 return E_NOINTERFACE;
1606 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1608 EditSession *This = (EditSession *)iface;
1609 return InterlockedIncrement(&This->refCount);
1612 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1614 EditSession *This = (EditSession *)iface;
1617 ret = InterlockedDecrement(&This->refCount);
1619 EditSession_Destructor(This);
1623 static void test_InsertAtSelection(TfEditCookie ec, ITfContext *cxt)
1626 ITfInsertAtSelection *iis;
1627 ITfRange *range=NULL;
1628 static const WCHAR txt[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1630 hr = ITfContext_QueryInterface(cxt, &IID_ITfInsertAtSelection , (LPVOID*)&iis);
1631 ok(SUCCEEDED(hr),"Failed to get ITfInsertAtSelection interface\n");
1632 test_ACP_InsertTextAtSelection = SINK_EXPECTED;
1633 hr = ITfInsertAtSelection_InsertTextAtSelection(iis, ec, 0, txt, 11, &range);
1634 ok(SUCCEEDED(hr),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr);
1635 ok(test_ACP_InsertTextAtSelection == SINK_FIRED,"expected InsertTextAtSelection not fired\n");
1636 ok(range != NULL,"No range returned\n");
1637 ITfRange_Release(range);
1638 ITfInsertAtSelection_Release(iis);
1641 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1647 TF_SELECTION selection;
1651 sink_fire_ok(&test_DoEditSession,"EditSession_DoEditSession");
1652 ok(test_ACP_RequestLock == SINK_FIRED,"Expected RequestLock not fired\n");
1654 ITfThreadMgr_GetFocus(g_tm, &dm);
1655 ITfDocumentMgr_GetTop(dm,&cxt);
1657 hr = ITfContext_GetStart(cxt,ec,NULL);
1658 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1660 range = (ITfRange*)0xdeaddead;
1661 hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1662 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1663 ok(range == NULL,"Range not set to NULL\n");
1665 hr = ITfContext_GetStart(cxt,ec,&range);
1666 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1667 ok(range != NULL,"Range set to NULL\n");
1669 ITfRange_Release(range);
1671 hr = ITfContext_GetEnd(cxt,ec,NULL);
1672 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1674 range = (ITfRange*)0xdeaddead;
1675 hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1676 ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1677 ok(range == NULL,"Range not set to NULL\n");
1679 test_ACP_GetEndACP = SINK_EXPECTED;
1680 hr = ITfContext_GetEnd(cxt,ec,&range);
1681 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1682 ok(range != NULL,"Range set to NULL\n");
1683 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1685 ITfRange_Release(range);
1687 selection.range = NULL;
1688 test_ACP_GetSelection = SINK_EXPECTED;
1689 hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1690 ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1691 ok(fetched == 1,"fetched incorrect\n");
1692 ok(selection.range != NULL,"NULL range\n");
1693 ok(test_ACP_GetSelection == SINK_FIRED," expected ACP_GetSepection not fired\n");
1694 ITfRange_Release(selection.range);
1696 test_InsertAtSelection(ec, cxt);
1698 test_ACP_GetEndACP = SINK_EXPECTED;
1699 hr = ITfContext_GetEnd(cxt,ec,&range);
1700 ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1701 ok(range != NULL,"Range set to NULL\n");
1702 ok(test_ACP_GetEndACP == SINK_FIRED, "GetEndACP not fired as expected\n");
1704 selection.range = range;
1705 selection.style.ase = TF_AE_NONE;
1706 selection.style.fInterimChar = FALSE;
1707 test_ACP_SetSelection = SINK_EXPECTED;
1708 hr = ITfContext_SetSelection(cxt, ec, 1, &selection);
1709 ok(test_ACP_SetSelection == SINK_FIRED, "SetSelection not fired as expected\n");
1710 ITfRange_Release(range);
1712 ITfContext_Release(cxt);
1713 ITfDocumentMgr_Release(dm);
1717 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1719 EditSession_QueryInterface,
1721 EditSession_Release,
1723 EditSession_DoEditSession
1726 static HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1731 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1733 return E_OUTOFMEMORY;
1735 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1738 *ppOut = (ITfEditSession*)This;
1742 static void test_TStoApplicationText(void)
1744 HRESULT hr, hrSession;
1748 ITfTextEditSink *sink;
1749 ITfSource *source = NULL;
1750 DWORD editSinkCookie = -1;
1752 ITfThreadMgr_GetFocus(g_tm, &dm);
1753 EditSession_Constructor(&es);
1754 ITfDocumentMgr_GetTop(dm,&cxt);
1756 TextEditSink_Constructor(&sink);
1757 hr = ITfContext_QueryInterface(cxt,&IID_ITfSource,(LPVOID*)&source);
1758 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for Context\n");
1761 hr = ITfSource_AdviseSink(source, &IID_ITfTextEditSink, (LPVOID)sink, &editSinkCookie);
1762 ok(SUCCEEDED(hr),"Failed to advise Sink\n");
1763 ok(editSinkCookie != -1,"Failed to get sink cookie\n");
1766 hrSession = 0xfeedface;
1767 /* Test no premissions flags */
1768 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1769 ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1770 ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1772 documentStatus = TS_SD_READONLY;
1773 hrSession = 0xfeedface;
1774 test_ACP_GetStatus = SINK_EXPECTED;
1775 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1776 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1777 ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1778 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1780 /* signal a change to allow readwrite sessions */
1782 test_ACP_RequestLock = SINK_EXPECTED;
1783 ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1784 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1786 test_ACP_GetStatus = SINK_EXPECTED;
1787 test_ACP_RequestLock = SINK_EXPECTED;
1788 test_DoEditSession = SINK_EXPECTED;
1789 hrSession = 0xfeedface;
1790 test_OnEndEdit = SINK_EXPECTED;
1791 hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1792 ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1793 ok(test_OnEndEdit == SINK_FIRED, "OnEndEdit not fired as expected\n");
1794 ok(test_ACP_RequestLock == SINK_FIRED," expected RequestLock not fired\n");
1795 ok(test_DoEditSession == SINK_FIRED," expected DoEditSession not fired\n");
1796 ok(test_ACP_GetStatus == SINK_FIRED," expected GetStatus not fired\n");
1797 ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1801 hr = ITfSource_UnadviseSink(source, editSinkCookie);
1802 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
1803 ITfTextEditSink_Release(sink);
1804 ITfSource_Release(source);
1807 ITfContext_Release(cxt);
1808 ITfDocumentMgr_Release(dm);
1809 ITfEditSession_Release(es);
1812 static void enum_compartments(ITfCompartmentMgr *cmpmgr, REFGUID present, REFGUID absent)
1818 if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr, &ppEnum)))
1822 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
1826 StringFromGUID2(&g,str,50);
1827 WideCharToMultiByte(CP_ACP,0,str,50,strA,50,0,0);
1828 trace("found %s\n",strA);
1829 if (present && IsEqualGUID(present,&g))
1831 if (absent && IsEqualGUID(absent, &g))
1834 IEnumGUID_Release(ppEnum);
1837 ok(found,"Did not find compartment\n");
1839 ok(!found2,"Found compartment that should be absent\n");
1842 static void test_Compartments(void)
1846 ITfCompartmentMgr *cmpmgr;
1847 ITfCompartment *cmp;
1850 ITfThreadMgr_GetFocus(g_tm, &dm);
1851 ITfDocumentMgr_GetTop(dm,&cxt);
1854 hr = ITfThreadMgr_GetGlobalCompartment(g_tm, &cmpmgr);
1855 ok(SUCCEEDED(hr),"GetGlobalCompartment failed\n");
1856 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_SPEECH_OPENCLOSE, &cmp);
1857 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1858 ITfCompartment_Release(cmp);
1859 enum_compartments(cmpmgr,&GUID_COMPARTMENT_SPEECH_OPENCLOSE,NULL);
1860 ITfCompartmentMgr_Release(cmpmgr);
1863 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1864 ok(SUCCEEDED(hr),"ThreadMgr QI for IID_ITfCompartmentMgr failed\n");
1865 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &CLSID_FakeService, &cmp);
1866 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1867 enum_compartments(cmpmgr,&CLSID_FakeService,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1868 ITfCompartmentMgr_ClearCompartment(cmpmgr,tid,&CLSID_FakeService);
1869 enum_compartments(cmpmgr,NULL,&CLSID_FakeService);
1870 ITfCompartmentMgr_Release(cmpmgr);
1871 ITfCompartment_Release(cmp);
1874 hr = ITfDocumentMgr_QueryInterface(dm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1875 ok(SUCCEEDED(hr),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1877 hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_PERSISTMENUENABLED, &cmp);
1878 ok(SUCCEEDED(hr),"GetCompartment failed\n");
1879 enum_compartments(cmpmgr,&GUID_COMPARTMENT_PERSISTMENUENABLED,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1880 ITfCompartmentMgr_Release(cmpmgr);
1883 hr = ITfContext_QueryInterface(cxt, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1884 ok(SUCCEEDED(hr),"Context QI for IID_ITfCompartmentMgr failed\n");
1885 enum_compartments(cmpmgr,NULL,&GUID_COMPARTMENT_PERSISTMENUENABLED);
1886 ITfCompartmentMgr_Release(cmpmgr);
1888 ITfContext_Release(cxt);
1889 ITfDocumentMgr_Release(dm);
1892 static void processPendingMessages(void)
1895 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1896 TranslateMessage(&msg);
1897 DispatchMessage(&msg);
1901 static void test_AssociateFocus(void)
1903 ITfDocumentMgr *dm1, *dm2, *olddm, *dmcheck, *dmorig;
1904 HWND wnd1, wnd2, wnd3;
1907 ITfThreadMgr_GetFocus(g_tm, &dmorig);
1908 test_CurrentFocus = NULL;
1909 test_PrevFocus = dmorig;
1910 test_OnSetFocus = SINK_EXPECTED;
1911 hr = ITfThreadMgr_SetFocus(g_tm,NULL);
1912 ok(test_OnSetFocus == SINK_FIRED,"OnSetFocus not fired as expected\n");
1913 ITfDocumentMgr_Release(dmorig);
1915 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm1);
1916 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1918 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm2);
1919 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1921 wnd1 = CreateWindow("edit",NULL,WS_POPUP|WS_VISIBLE,0,0,200,60,NULL,NULL,NULL,NULL);
1922 ok(wnd1!=NULL,"Unable to create window 1\n");
1923 wnd2 = CreateWindow("edit",NULL,WS_POPUP|WS_VISIBLE,0,0,200,60,NULL,NULL,NULL,NULL);
1924 ok(wnd2!=NULL,"Unable to create window 2\n");
1925 wnd3 = CreateWindow("edit",NULL,WS_POPUP|WS_VISIBLE,0,0,200,60,NULL,NULL,NULL,NULL);
1926 ok(wnd3!=NULL,"Unable to create window 3\n");
1928 processPendingMessages();
1931 processPendingMessages();
1932 test_CurrentFocus = dm1;
1933 test_PrevFocus = NULL;
1934 test_OnSetFocus = SINK_EXPECTED;
1935 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd1,dm1,&olddm);
1936 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1937 ok(test_OnSetFocus == SINK_FIRED,"OnSetFocus not fired as expected\n");
1938 ok(olddm == NULL, "unexpected old DocumentMgr\n");
1940 processPendingMessages();
1942 ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1943 ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1944 ITfDocumentMgr_Release(dmcheck);
1946 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,dm2,&olddm);
1947 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1948 processPendingMessages();
1949 ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1950 ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1951 ITfDocumentMgr_Release(dmcheck);
1953 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd3,dm2,&olddm);
1954 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1955 processPendingMessages();
1956 ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1957 ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1958 ITfDocumentMgr_Release(dmcheck);
1960 test_CurrentFocus = dm2;
1961 test_PrevFocus = dm1;
1962 test_OnSetFocus = SINK_EXPECTED;
1964 processPendingMessages();
1965 ok(test_OnSetFocus == SINK_FIRED,"OnSetFocus not fired as expected\n");
1968 processPendingMessages();
1970 test_CurrentFocus = dm1;
1971 test_PrevFocus = dm2;
1972 test_OnSetFocus = SINK_EXPECTED;
1974 processPendingMessages();
1975 ok(test_OnSetFocus == SINK_FIRED,"OnSetFocus not fired as expected\n");
1977 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd3,NULL,&olddm);
1978 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1979 ok(olddm == dm2, "incorrect old DocumentMgr returned\n");
1980 ITfDocumentMgr_Release(olddm);
1982 test_CurrentFocus = dmorig;
1983 test_PrevFocus = dm1;
1984 test_OnSetFocus = SINK_EXPECTED;
1985 test_ACP_GetStatus = SINK_EXPECTED;
1986 ITfThreadMgr_SetFocus(g_tm,dmorig);
1987 ok(test_OnSetFocus == SINK_FIRED,"OnSetFocus not fired as expected\n");
1989 test_CurrentFocus = NULL;
1990 test_PrevFocus = dmorig;
1991 test_OnSetFocus = SINK_EXPECTED;
1993 processPendingMessages();
1994 ok(test_OnSetFocus == SINK_FIRED,"OnSetFocus not fired as expected\n");
1996 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,NULL,&olddm);
1997 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1998 ok(olddm == dm2, "incorrect old DocumentMgr returned\n");
1999 ITfDocumentMgr_Release(olddm);
2000 hr = ITfThreadMgr_AssociateFocus(g_tm,wnd1,NULL,&olddm);
2001 ok(SUCCEEDED(hr),"AssociateFocus failed\n");
2002 ok(olddm == dm1, "incorrect old DocumentMgr returned\n");
2003 ITfDocumentMgr_Release(olddm);
2006 processPendingMessages();
2008 processPendingMessages();
2010 ITfDocumentMgr_Release(dm1);
2011 ITfDocumentMgr_Release(dm2);
2012 DestroyWindow(wnd1);
2013 DestroyWindow(wnd2);
2014 DestroyWindow(wnd3);
2016 test_CurrentFocus = dmorig;
2017 test_PrevFocus = NULL;
2018 test_OnSetFocus = SINK_EXPECTED;
2019 test_ACP_GetStatus = SINK_IGNORE;
2020 ITfThreadMgr_SetFocus(g_tm,dmorig);
2021 ok(test_OnSetFocus == SINK_FIRED,"OnSetFocus not fired as expected\n");
2024 START_TEST(inputprocessor)
2026 if (SUCCEEDED(initialize()))
2029 test_RegisterCategory();
2030 test_EnumInputProcessorInfo();
2032 test_ThreadMgrAdviseSinks();
2034 test_startSession();
2037 test_KeystrokeMgr();
2038 test_TStoApplicationText();
2039 test_Compartments();
2040 test_AssociateFocus();
2042 test_EnumLanguageProfiles();
2043 test_FindClosestCategory();
2045 test_ThreadMgrUnadviseSinks();
2046 test_UnregisterCategory();
2050 skip("Unable to create InputProcessor\n");