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
;
124 int todo
= *sink
& SINK_OPTION_TODO
;
129 if (winetest_interactive
)
130 winetest_trace("optional sink %s not fired\n",name
);
137 todo_wine
winetest_ok(0, "%s not fired as expected, in state %x\n",name
,*sink
);
139 winetest_ok(0, "%s not fired as expected, in state %x\n",name
,*sink
);
141 *sink
= SINK_UNEXPECTED
;
144 #define sink_check_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_ok(a,b)
146 /**********************************************************************
148 **********************************************************************/
149 typedef struct tagTextStoreACP
151 const ITextStoreACPVtbl
*TextStoreACPVtbl
;
156 static void TextStoreACP_Destructor(TextStoreACP
*This
)
158 HeapFree(GetProcessHeap(),0,This
);
161 static HRESULT WINAPI
TextStoreACP_QueryInterface(ITextStoreACP
*iface
, REFIID iid
, LPVOID
*ppvOut
)
163 TextStoreACP
*This
= (TextStoreACP
*)iface
;
166 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITextStoreACP
))
173 IUnknown_AddRef(iface
);
177 return E_NOINTERFACE
;
180 static ULONG WINAPI
TextStoreACP_AddRef(ITextStoreACP
*iface
)
182 TextStoreACP
*This
= (TextStoreACP
*)iface
;
183 return InterlockedIncrement(&This
->refCount
);
186 static ULONG WINAPI
TextStoreACP_Release(ITextStoreACP
*iface
)
188 TextStoreACP
*This
= (TextStoreACP
*)iface
;
191 ret
= InterlockedDecrement(&This
->refCount
);
193 TextStoreACP_Destructor(This
);
197 static HRESULT WINAPI
TextStoreACP_AdviseSink(ITextStoreACP
*iface
,
198 REFIID riid
, IUnknown
*punk
, DWORD dwMask
)
202 sink_fire_ok(&test_ACP_AdviseSink
,"TextStoreACP_AdviseSink");
204 hr
= IUnknown_QueryInterface(punk
, &IID_ITextStoreACPSink
,(LPVOID
*)(&ACPSink
));
205 ok(SUCCEEDED(hr
),"Unable to QueryInterface on sink\n");
209 static HRESULT WINAPI
TextStoreACP_UnadviseSink(ITextStoreACP
*iface
,
216 static HRESULT WINAPI
TextStoreACP_RequestLock(ITextStoreACP
*iface
,
217 DWORD dwLockFlags
, HRESULT
*phrSession
)
219 sink_fire_ok(&test_ACP_RequestLock
,"TextStoreACP_RequestLock");
220 *phrSession
= ITextStoreACPSink_OnLockGranted(ACPSink
, dwLockFlags
);
223 static HRESULT WINAPI
TextStoreACP_GetStatus(ITextStoreACP
*iface
,
226 sink_fire_ok(&test_ACP_GetStatus
,"TextStoreACP_GetStatus");
227 pdcs
->dwDynamicFlags
= documentStatus
;
230 static HRESULT WINAPI
TextStoreACP_QueryInsert(ITextStoreACP
*iface
,
231 LONG acpTestStart
, LONG acpTestEnd
, ULONG cch
, LONG
*pacpResultStart
,
237 static HRESULT WINAPI
TextStoreACP_GetSelection(ITextStoreACP
*iface
,
238 ULONG ulIndex
, ULONG ulCount
, TS_SELECTION_ACP
*pSelection
, ULONG
*pcFetched
)
240 sink_fire_ok(&test_ACP_GetSelection
,"TextStoreACP_GetSelection");
242 pSelection
->acpStart
= 10;
243 pSelection
->acpEnd
= 20;
244 pSelection
->style
.fInterimChar
= 0;
245 pSelection
->style
.ase
= TS_AE_NONE
;
250 static HRESULT WINAPI
TextStoreACP_SetSelection(ITextStoreACP
*iface
,
251 ULONG ulCount
, const TS_SELECTION_ACP
*pSelection
)
253 sink_fire_ok(&test_ACP_SetSelection
,"TextStoreACP_SetSelection");
256 static HRESULT WINAPI
TextStoreACP_GetText(ITextStoreACP
*iface
,
257 LONG acpStart
, LONG acpEnd
, WCHAR
*pchPlain
, ULONG cchPlainReq
,
258 ULONG
*pcchPlainRet
, TS_RUNINFO
*prgRunInfo
, ULONG cRunInfoReq
,
259 ULONG
*pcRunInfoRet
, LONG
*pacpNext
)
264 static HRESULT WINAPI
TextStoreACP_SetText(ITextStoreACP
*iface
,
265 DWORD dwFlags
, LONG acpStart
, LONG acpEnd
, const WCHAR
*pchText
,
266 ULONG cch
, TS_TEXTCHANGE
*pChange
)
271 static HRESULT WINAPI
TextStoreACP_GetFormattedText(ITextStoreACP
*iface
,
272 LONG acpStart
, LONG acpEnd
, IDataObject
**ppDataObject
)
277 static HRESULT WINAPI
TextStoreACP_GetEmbedded(ITextStoreACP
*iface
,
278 LONG acpPos
, REFGUID rguidService
, REFIID riid
, IUnknown
**ppunk
)
283 static HRESULT WINAPI
TextStoreACP_QueryInsertEmbedded(ITextStoreACP
*iface
,
284 const GUID
*pguidService
, const FORMATETC
*pFormatEtc
, BOOL
*pfInsertable
)
289 static HRESULT WINAPI
TextStoreACP_InsertEmbedded(ITextStoreACP
*iface
,
290 DWORD dwFlags
, LONG acpStart
, LONG acpEnd
, IDataObject
*pDataObject
,
291 TS_TEXTCHANGE
*pChange
)
296 static HRESULT WINAPI
TextStoreACP_InsertTextAtSelection(ITextStoreACP
*iface
,
297 DWORD dwFlags
, const WCHAR
*pchText
, ULONG cch
, LONG
*pacpStart
,
298 LONG
*pacpEnd
, TS_TEXTCHANGE
*pChange
)
300 sink_fire_ok(&test_ACP_InsertTextAtSelection
,"TextStoreACP_InsertTextAtSelection");
303 static HRESULT WINAPI
TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP
*iface
,
304 DWORD dwFlags
, IDataObject
*pDataObject
, LONG
*pacpStart
, LONG
*pacpEnd
,
305 TS_TEXTCHANGE
*pChange
)
310 static HRESULT WINAPI
TextStoreACP_RequestSupportedAttrs(ITextStoreACP
*iface
,
311 DWORD dwFlags
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
)
316 static HRESULT WINAPI
TextStoreACP_RequestAttrsAtPosition(ITextStoreACP
*iface
,
317 LONG acpPos
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
,
323 static HRESULT WINAPI
TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP
*iface
,
324 LONG acpPos
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
,
330 static HRESULT WINAPI
TextStoreACP_FindNextAttrTransition(ITextStoreACP
*iface
,
331 LONG acpStart
, LONG acpHalt
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
,
332 DWORD dwFlags
, LONG
*pacpNext
, BOOL
*pfFound
, LONG
*plFoundOffset
)
337 static HRESULT WINAPI
TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP
*iface
,
338 ULONG ulCount
, TS_ATTRVAL
*paAttrVals
, ULONG
*pcFetched
)
343 static HRESULT WINAPI
TextStoreACP_GetEndACP(ITextStoreACP
*iface
,
346 sink_fire_ok(&test_ACP_GetEndACP
,"TextStoreACP_GetEndACP");
349 static HRESULT WINAPI
TextStoreACP_GetActiveView(ITextStoreACP
*iface
,
350 TsViewCookie
*pvcView
)
355 static HRESULT WINAPI
TextStoreACP_GetACPFromPoint(ITextStoreACP
*iface
,
356 TsViewCookie vcView
, const POINT
*ptScreen
, DWORD dwFlags
,
362 static HRESULT WINAPI
TextStoreACP_GetTextExt(ITextStoreACP
*iface
,
363 TsViewCookie vcView
, LONG acpStart
, LONG acpEnd
, RECT
*prc
,
369 static HRESULT WINAPI
TextStoreACP_GetScreenExt(ITextStoreACP
*iface
,
370 TsViewCookie vcView
, RECT
*prc
)
375 static HRESULT WINAPI
TextStoreACP_GetWnd(ITextStoreACP
*iface
,
376 TsViewCookie vcView
, HWND
*phwnd
)
382 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl
=
384 TextStoreACP_QueryInterface
,
386 TextStoreACP_Release
,
388 TextStoreACP_AdviseSink
,
389 TextStoreACP_UnadviseSink
,
390 TextStoreACP_RequestLock
,
391 TextStoreACP_GetStatus
,
392 TextStoreACP_QueryInsert
,
393 TextStoreACP_GetSelection
,
394 TextStoreACP_SetSelection
,
395 TextStoreACP_GetText
,
396 TextStoreACP_SetText
,
397 TextStoreACP_GetFormattedText
,
398 TextStoreACP_GetEmbedded
,
399 TextStoreACP_QueryInsertEmbedded
,
400 TextStoreACP_InsertEmbedded
,
401 TextStoreACP_InsertTextAtSelection
,
402 TextStoreACP_InsertEmbeddedAtSelection
,
403 TextStoreACP_RequestSupportedAttrs
,
404 TextStoreACP_RequestAttrsAtPosition
,
405 TextStoreACP_RequestAttrsTransitioningAtPosition
,
406 TextStoreACP_FindNextAttrTransition
,
407 TextStoreACP_RetrieveRequestedAttrs
,
408 TextStoreACP_GetEndACP
,
409 TextStoreACP_GetActiveView
,
410 TextStoreACP_GetACPFromPoint
,
411 TextStoreACP_GetTextExt
,
412 TextStoreACP_GetScreenExt
,
416 static HRESULT
TextStoreACP_Constructor(IUnknown
**ppOut
)
420 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextStoreACP
));
422 return E_OUTOFMEMORY
;
424 This
->TextStoreACPVtbl
= &TextStoreACP_TextStoreACPVtbl
;
427 *ppOut
= (IUnknown
*)This
;
431 /**********************************************************************
432 * ITfThreadMgrEventSink
433 **********************************************************************/
434 typedef struct tagThreadMgrEventSink
436 const ITfThreadMgrEventSinkVtbl
*ThreadMgrEventSinkVtbl
;
438 } ThreadMgrEventSink
;
440 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink
*This
)
442 HeapFree(GetProcessHeap(),0,This
);
445 static HRESULT WINAPI
ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink
*iface
, REFIID iid
, LPVOID
*ppvOut
)
447 ThreadMgrEventSink
*This
= (ThreadMgrEventSink
*)iface
;
450 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfThreadMgrEventSink
))
457 IUnknown_AddRef(iface
);
461 return E_NOINTERFACE
;
464 static ULONG WINAPI
ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink
*iface
)
466 ThreadMgrEventSink
*This
= (ThreadMgrEventSink
*)iface
;
467 ok (tmSinkRefCount
== This
->refCount
,"ThreadMgrEventSink refcount off %i vs %i\n",This
->refCount
,tmSinkRefCount
);
468 return InterlockedIncrement(&This
->refCount
);
471 static ULONG WINAPI
ThreadMgrEventSink_Release(ITfThreadMgrEventSink
*iface
)
473 ThreadMgrEventSink
*This
= (ThreadMgrEventSink
*)iface
;
476 ok (tmSinkRefCount
== This
->refCount
,"ThreadMgrEventSink refcount off %i vs %i\n",This
->refCount
,tmSinkRefCount
);
477 ret
= InterlockedDecrement(&This
->refCount
);
479 ThreadMgrEventSink_Destructor(This
);
483 static HRESULT WINAPI
ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink
*iface
,
484 ITfDocumentMgr
*pdim
)
486 sink_fire_ok(&test_OnInitDocumentMgr
,"ThreadMgrEventSink_OnInitDocumentMgr");
490 static HRESULT WINAPI
ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink
*iface
,
491 ITfDocumentMgr
*pdim
)
497 static HRESULT WINAPI
ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink
*iface
,
498 ITfDocumentMgr
*pdimFocus
, ITfDocumentMgr
*pdimPrevFocus
)
500 sink_fire_ok(&test_OnSetFocus
,"ThreadMgrEventSink_OnSetFocus");
501 if (test_CurrentFocus
!= FOCUS_IGNORE
)
502 ok(pdimFocus
== test_CurrentFocus
,"Sink reports wrong focus\n");
503 if (test_PrevFocus
!= FOCUS_IGNORE
)
504 ok(pdimPrevFocus
== test_PrevFocus
,"Sink reports wrong previous focus\n");
508 static HRESULT WINAPI
ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink
*iface
,
512 ITfDocumentMgr
*docmgr
;
515 hr
= ITfContext_GetDocumentMgr(pic
,&docmgr
);
516 ok(SUCCEEDED(hr
),"GetDocumenMgr failed\n");
517 test
= (ITfContext
*)0xdeadbeef;
518 ITfDocumentMgr_Release(docmgr
);
519 hr
= ITfDocumentMgr_GetTop(docmgr
,&test
);
520 ok(SUCCEEDED(hr
),"GetTop failed\n");
521 ok(test
== pic
, "Wrong context is on top\n");
523 ITfContext_Release(test
);
525 sink_fire_ok(&test_OnPushContext
,"ThreadMgrEventSink_OnPushContext");
529 static HRESULT WINAPI
ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink
*iface
,
533 ITfDocumentMgr
*docmgr
;
536 hr
= ITfContext_GetDocumentMgr(pic
,&docmgr
);
537 ok(SUCCEEDED(hr
),"GetDocumenMgr failed\n");
538 ITfDocumentMgr_Release(docmgr
);
539 test
= (ITfContext
*)0xdeadbeef;
540 hr
= ITfDocumentMgr_GetTop(docmgr
,&test
);
541 ok(SUCCEEDED(hr
),"GetTop failed\n");
542 ok(test
== pic
, "Wrong context is on top\n");
544 ITfContext_Release(test
);
546 sink_fire_ok(&test_OnPopContext
,"ThreadMgrEventSink_OnPopContext");
550 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl
=
552 ThreadMgrEventSink_QueryInterface
,
553 ThreadMgrEventSink_AddRef
,
554 ThreadMgrEventSink_Release
,
556 ThreadMgrEventSink_OnInitDocumentMgr
,
557 ThreadMgrEventSink_OnUninitDocumentMgr
,
558 ThreadMgrEventSink_OnSetFocus
,
559 ThreadMgrEventSink_OnPushContext
,
560 ThreadMgrEventSink_OnPopContext
563 static HRESULT
ThreadMgrEventSink_Constructor(IUnknown
**ppOut
)
565 ThreadMgrEventSink
*This
;
567 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ThreadMgrEventSink
));
569 return E_OUTOFMEMORY
;
571 This
->ThreadMgrEventSinkVtbl
= &ThreadMgrEventSink_ThreadMgrEventSinkVtbl
;
574 *ppOut
= (IUnknown
*)This
;
579 /********************************************************************************************
580 * Stub text service for testing
581 ********************************************************************************************/
583 static LONG TS_refCount
;
584 static IClassFactory
*cf
;
587 typedef HRESULT (*LPFNCONSTRUCTOR
)(IUnknown
*pUnkOuter
, IUnknown
**ppvOut
);
589 typedef struct tagClassFactory
591 const IClassFactoryVtbl
*vtbl
;
593 LPFNCONSTRUCTOR ctor
;
596 typedef struct tagTextService
598 const ITfTextInputProcessorVtbl
*TextInputProcessorVtbl
;
602 static void ClassFactory_Destructor(ClassFactory
*This
)
604 HeapFree(GetProcessHeap(),0,This
);
608 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppvOut
)
611 if (IsEqualIID(riid
, &IID_IClassFactory
) || IsEqualIID(riid
, &IID_IUnknown
))
613 IClassFactory_AddRef(iface
);
618 return E_NOINTERFACE
;
621 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
623 ClassFactory
*This
= (ClassFactory
*)iface
;
624 return InterlockedIncrement(&This
->ref
);
627 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
629 ClassFactory
*This
= (ClassFactory
*)iface
;
630 ULONG ret
= InterlockedDecrement(&This
->ref
);
633 ClassFactory_Destructor(This
);
637 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*punkOuter
, REFIID iid
, LPVOID
*ppvOut
)
639 ClassFactory
*This
= (ClassFactory
*)iface
;
643 ret
= This
->ctor(punkOuter
, &obj
);
646 ret
= IUnknown_QueryInterface(obj
, iid
, ppvOut
);
647 IUnknown_Release(obj
);
651 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
654 InterlockedIncrement(&TS_refCount
);
656 InterlockedDecrement(&TS_refCount
);
661 static const IClassFactoryVtbl ClassFactoryVtbl
= {
663 ClassFactory_QueryInterface
,
665 ClassFactory_Release
,
668 ClassFactory_CreateInstance
,
669 ClassFactory_LockServer
672 static HRESULT
ClassFactory_Constructor(LPFNCONSTRUCTOR ctor
, LPVOID
*ppvOut
)
674 ClassFactory
*This
= HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory
));
675 This
->vtbl
= &ClassFactoryVtbl
;
678 *ppvOut
= (LPVOID
)This
;
683 static void TextService_Destructor(TextService
*This
)
685 HeapFree(GetProcessHeap(),0,This
);
688 static HRESULT WINAPI
TextService_QueryInterface(ITfTextInputProcessor
*iface
, REFIID iid
, LPVOID
*ppvOut
)
690 TextService
*This
= (TextService
*)iface
;
693 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfTextInputProcessor
))
700 IUnknown_AddRef(iface
);
704 return E_NOINTERFACE
;
707 static ULONG WINAPI
TextService_AddRef(ITfTextInputProcessor
*iface
)
709 TextService
*This
= (TextService
*)iface
;
710 return InterlockedIncrement(&This
->refCount
);
713 static ULONG WINAPI
TextService_Release(ITfTextInputProcessor
*iface
)
715 TextService
*This
= (TextService
*)iface
;
718 ret
= InterlockedDecrement(&This
->refCount
);
720 TextService_Destructor(This
);
724 static HRESULT WINAPI
TextService_Activate(ITfTextInputProcessor
*iface
,
725 ITfThreadMgr
*ptim
, TfClientId id
)
727 trace("TextService_Activate\n");
728 ok(test_ShouldActivate
,"Activation came unexpectedly\n");
733 static HRESULT WINAPI
TextService_Deactivate(ITfTextInputProcessor
*iface
)
735 trace("TextService_Deactivate\n");
736 ok(test_ShouldDeactivate
,"Deactivation came unexpectedly\n");
740 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl
=
742 TextService_QueryInterface
,
746 TextService_Activate
,
747 TextService_Deactivate
750 static HRESULT
TextService_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
754 return CLASS_E_NOAGGREGATION
;
756 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextService
));
758 return E_OUTOFMEMORY
;
760 This
->TextInputProcessorVtbl
= &TextService_TextInputProcessorVtbl
;
763 *ppOut
= (IUnknown
*)This
;
767 static HRESULT
RegisterTextService(REFCLSID rclsid
)
769 ClassFactory_Constructor( TextService_Constructor
,(LPVOID
*)&cf
);
770 return CoRegisterClassObject(rclsid
, (IUnknown
*) cf
, CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
773 static HRESULT
UnregisterTextService(void)
775 return CoRevokeClassObject(regid
);
782 DEFINE_GUID(CLSID_FakeService
, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
783 DEFINE_GUID(CLSID_TF_InputProcessorProfiles
, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
784 DEFINE_GUID(CLSID_TF_CategoryMgr
, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
785 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD
, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
786 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH
, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
787 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING
, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
788 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
789 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
790 DEFINE_GUID(CLSID_TF_ThreadMgr
, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
791 DEFINE_GUID(CLSID_PreservedKey
, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
792 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_DISABLED
, 0x71a5b253,0x1951,0x466b,0x9f,0xbc,0x9c,0x88,0x08,0xfa,0x84,0xf2);
793 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE
, 0x58273aad,0x01bb,0x4164,0x95,0xc6,0x75,0x5b,0xa0,0xb5,0x16,0x2d);
794 DEFINE_GUID(GUID_COMPARTMENT_HANDWRITING_OPENCLOSE
, 0xf9ae2c6b,0x1866,0x4361,0xaf,0x72,0x7a,0xa3,0x09,0x48,0x89,0x0e);
795 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_DISABLED
, 0x56c5c607,0x0703,0x4e59,0x8e,0x52,0xcb,0xc8,0x4e,0x8b,0xbe,0x35);
796 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE
, 0x544d6a63,0xe2e8,0x4752,0xbb,0xd1,0x00,0x09,0x60,0xbc,0xa0,0x83);
797 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_GLOBALSTATE
, 0x2a54fe8e,0x0d08,0x460c,0xa7,0x5d,0x87,0x03,0x5f,0xf4,0x36,0xc5);
798 DEFINE_GUID(GUID_COMPARTMENT_PERSISTMENUENABLED
, 0x575f3783,0x70c8,0x47c8,0xae,0x5d,0x91,0xa0,0x1a,0x1f,0x75,0x92);
799 DEFINE_GUID(GUID_COMPARTMENT_EMPTYCONTEXT
, 0xd7487dbf,0x804e,0x41c5,0x89,0x4d,0xad,0x96,0xfd,0x4e,0xea,0x13);
800 DEFINE_GUID(GUID_COMPARTMENT_TIPUISTATUS
, 0x148ca3ec,0x0366,0x401c,0x8d,0x75,0xed,0x97,0x8d,0x85,0xfb,0xc9);
802 static HRESULT
initialize(void)
806 hr
= CoCreateInstance (&CLSID_TF_InputProcessorProfiles
, NULL
,
807 CLSCTX_INPROC_SERVER
, &IID_ITfInputProcessorProfiles
, (void**)&g_ipp
);
809 hr
= CoCreateInstance (&CLSID_TF_CategoryMgr
, NULL
,
810 CLSCTX_INPROC_SERVER
, &IID_ITfCategoryMgr
, (void**)&g_cm
);
812 hr
= CoCreateInstance (&CLSID_TF_ThreadMgr
, NULL
,
813 CLSCTX_INPROC_SERVER
, &IID_ITfThreadMgr
, (void**)&g_tm
);
817 static void cleanup(void)
820 ITfInputProcessorProfiles_Release(g_ipp
);
822 ITfCategoryMgr_Release(g_cm
);
824 ITfThreadMgr_Release(g_tm
);
828 static void test_Register(void)
832 static const WCHAR szDesc
[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
833 static const WCHAR szFile
[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
835 hr
= ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp
,&gLangid
);
836 ok(SUCCEEDED(hr
),"Unable to get current language id\n");
837 trace("Current Language %x\n",gLangid
);
839 hr
= RegisterTextService(&CLSID_FakeService
);
840 ok(SUCCEEDED(hr
),"Unable to register COM for TextService\n");
841 hr
= ITfInputProcessorProfiles_Register(g_ipp
, &CLSID_FakeService
);
842 ok(SUCCEEDED(hr
),"Unable to register text service(%x)\n",hr
);
843 hr
= ITfInputProcessorProfiles_AddLanguageProfile(g_ipp
, &CLSID_FakeService
, gLangid
, &CLSID_FakeService
, szDesc
, sizeof(szDesc
)/sizeof(WCHAR
), szFile
, sizeof(szFile
)/sizeof(WCHAR
), 1);
844 ok(SUCCEEDED(hr
),"Unable to add Language Profile (%x)\n",hr
);
847 static void test_Unregister(void)
850 hr
= ITfInputProcessorProfiles_Unregister(g_ipp
, &CLSID_FakeService
);
851 ok(SUCCEEDED(hr
),"Unable to unregister text service(%x)\n",hr
);
852 UnregisterTextService();
855 static void test_EnumInputProcessorInfo(void)
860 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp
, &ppEnum
)))
864 while (IEnumGUID_Next(ppEnum
, 1, &g
, &fetched
) == S_OK
)
866 if(IsEqualGUID(&g
,&CLSID_FakeService
))
870 ok(found
,"Did not find registered text service\n");
873 static void test_EnumLanguageProfiles(void)
876 IEnumTfLanguageProfiles
*ppEnum
;
877 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp
,gLangid
,&ppEnum
)))
879 TF_LANGUAGEPROFILE profile
;
880 while (IEnumTfLanguageProfiles_Next(ppEnum
,1,&profile
,NULL
)==S_OK
)
882 if (IsEqualGUID(&profile
.clsid
,&CLSID_FakeService
))
885 ok(profile
.langid
== gLangid
, "LangId Incorrect\n");
886 ok(IsEqualGUID(&profile
.catid
,&GUID_TFCAT_TIP_KEYBOARD
), "CatId Incorrect\n");
887 ok(IsEqualGUID(&profile
.guidProfile
,&CLSID_FakeService
), "guidProfile Incorrect\n");
891 ok(found
,"Registered text service not found\n");
894 static void test_RegisterCategory(void)
897 hr
= ITfCategoryMgr_RegisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_TIP_KEYBOARD
, &CLSID_FakeService
);
898 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterCategory failed\n");
899 hr
= ITfCategoryMgr_RegisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, &CLSID_FakeService
);
900 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterCategory failed\n");
903 static void test_UnregisterCategory(void)
906 hr
= ITfCategoryMgr_UnregisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_TIP_KEYBOARD
, &CLSID_FakeService
);
907 ok(SUCCEEDED(hr
),"ITfCategoryMgr_UnregisterCategory failed\n");
908 hr
= ITfCategoryMgr_UnregisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, &CLSID_FakeService
);
909 ok(SUCCEEDED(hr
),"ITfCategoryMgr_UnregisterCategory failed\n");
912 static void test_FindClosestCategory(void)
916 const GUID
*list
[3] = {&GUID_TFCAT_TIP_SPEECH
, &GUID_TFCAT_TIP_KEYBOARD
, &GUID_TFCAT_TIP_HANDWRITING
};
918 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, NULL
, 0);
919 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
920 ok(IsEqualGUID(&output
,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
),"Wrong GUID\n");
922 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, list
, 1);
923 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
924 ok(IsEqualGUID(&output
,&GUID_NULL
),"Wrong GUID\n");
926 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, list
, 3);
927 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
928 ok(IsEqualGUID(&output
,&GUID_TFCAT_TIP_KEYBOARD
),"Wrong GUID\n");
931 static void test_Enable(void)
934 BOOL enabled
= FALSE
;
936 hr
= ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, TRUE
);
937 ok(SUCCEEDED(hr
),"Failed to enable text service\n");
938 hr
= ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, &enabled
);
939 ok(SUCCEEDED(hr
),"Failed to get enabled state\n");
940 ok(enabled
== TRUE
,"enabled state incorrect\n");
943 static void test_Disable(void)
947 trace("Disabling\n");
948 hr
= ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, FALSE
);
949 ok(SUCCEEDED(hr
),"Failed to disable text service\n");
952 static void test_ThreadMgrAdviseSinks(void)
954 ITfSource
*source
= NULL
;
958 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfSource
, (LPVOID
*)&source
);
959 ok(SUCCEEDED(hr
),"Failed to get IID_ITfSource for ThreadMgr\n");
963 hr
= ThreadMgrEventSink_Constructor(&sink
);
964 ok(hr
== S_OK
, "got %08x\n", hr
);
965 if(FAILED(hr
)) return;
969 hr
= ITfSource_AdviseSink(source
,&IID_ITfThreadMgrEventSink
, sink
, &tmSinkCookie
);
970 ok(SUCCEEDED(hr
),"Failed to Advise Sink\n");
971 ok(tmSinkCookie
!=0,"Failed to get sink cookie\n");
973 /* Advising the sink adds a ref, Relesing here lets the object be deleted
976 IUnknown_Release(sink
);
977 ITfSource_Release(source
);
980 static void test_ThreadMgrUnadviseSinks(void)
982 ITfSource
*source
= NULL
;
985 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfSource
, (LPVOID
*)&source
);
986 ok(SUCCEEDED(hr
),"Failed to get IID_ITfSource for ThreadMgr\n");
991 hr
= ITfSource_UnadviseSink(source
, tmSinkCookie
);
992 ok(SUCCEEDED(hr
),"Failed to unadvise Sink\n");
993 ITfSource_Release(source
);
996 /**********************************************************************
998 **********************************************************************/
999 typedef struct tagKeyEventSink
1001 const ITfKeyEventSinkVtbl
*KeyEventSinkVtbl
;
1005 static void KeyEventSink_Destructor(KeyEventSink
*This
)
1007 HeapFree(GetProcessHeap(),0,This
);
1010 static HRESULT WINAPI
KeyEventSink_QueryInterface(ITfKeyEventSink
*iface
, REFIID iid
, LPVOID
*ppvOut
)
1012 KeyEventSink
*This
= (KeyEventSink
*)iface
;
1015 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfKeyEventSink
))
1022 IUnknown_AddRef(iface
);
1026 return E_NOINTERFACE
;
1029 static ULONG WINAPI
KeyEventSink_AddRef(ITfKeyEventSink
*iface
)
1031 KeyEventSink
*This
= (KeyEventSink
*)iface
;
1032 return InterlockedIncrement(&This
->refCount
);
1035 static ULONG WINAPI
KeyEventSink_Release(ITfKeyEventSink
*iface
)
1037 KeyEventSink
*This
= (KeyEventSink
*)iface
;
1040 ret
= InterlockedDecrement(&This
->refCount
);
1042 KeyEventSink_Destructor(This
);
1046 static HRESULT WINAPI
KeyEventSink_OnSetFocus(ITfKeyEventSink
*iface
,
1049 sink_fire_ok(&test_KEV_OnSetFocus
,"KeyEventSink_OnSetFocus");
1053 static HRESULT WINAPI
KeyEventSink_OnTestKeyDown(ITfKeyEventSink
*iface
,
1054 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1060 static HRESULT WINAPI
KeyEventSink_OnTestKeyUp(ITfKeyEventSink
*iface
,
1061 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1067 static HRESULT WINAPI
KeyEventSink_OnKeyDown(ITfKeyEventSink
*iface
,
1068 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1074 static HRESULT WINAPI
KeyEventSink_OnKeyUp(ITfKeyEventSink
*iface
,
1075 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1081 static HRESULT WINAPI
KeyEventSink_OnPreservedKey(ITfKeyEventSink
*iface
,
1082 ITfContext
*pic
, REFGUID rguid
, BOOL
*pfEaten
)
1088 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl
=
1090 KeyEventSink_QueryInterface
,
1091 KeyEventSink_AddRef
,
1092 KeyEventSink_Release
,
1094 KeyEventSink_OnSetFocus
,
1095 KeyEventSink_OnTestKeyDown
,
1096 KeyEventSink_OnTestKeyUp
,
1097 KeyEventSink_OnKeyDown
,
1098 KeyEventSink_OnKeyUp
,
1099 KeyEventSink_OnPreservedKey
1102 static HRESULT
KeyEventSink_Constructor(ITfKeyEventSink
**ppOut
)
1106 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(KeyEventSink
));
1108 return E_OUTOFMEMORY
;
1110 This
->KeyEventSinkVtbl
= &KeyEventSink_KeyEventSinkVtbl
;
1113 *ppOut
= (ITfKeyEventSink
*)This
;
1118 static void test_KeystrokeMgr(void)
1120 ITfKeystrokeMgr
*keymgr
= NULL
;
1122 TF_PRESERVEDKEY tfpk
;
1124 ITfKeyEventSink
*sink
= NULL
;
1126 KeyEventSink_Constructor(&sink
);
1128 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfKeystrokeMgr
, (LPVOID
*)&keymgr
);
1129 ok(SUCCEEDED(hr
),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1132 tfpk
.uModifiers
= TF_MOD_SHIFT
;
1134 test_KEV_OnSetFocus
= SINK_EXPECTED
;
1135 hr
= ITfKeystrokeMgr_AdviseKeyEventSink(keymgr
,tid
,sink
,TRUE
);
1136 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1137 sink_check_ok(&test_KEV_OnSetFocus
,"KeyEventSink_OnSetFocus");
1138 hr
= ITfKeystrokeMgr_AdviseKeyEventSink(keymgr
,tid
,sink
,TRUE
);
1139 ok(hr
== CONNECT_E_ADVISELIMIT
,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1140 hr
= ITfKeystrokeMgr_AdviseKeyEventSink(keymgr
,cid
,sink
,TRUE
);
1141 ok(hr
== E_INVALIDARG
,"Wrong return, expected E_INVALIDARG\n");
1143 hr
=ITfKeystrokeMgr_PreserveKey(keymgr
, 0, &CLSID_PreservedKey
, &tfpk
, NULL
, 0);
1144 ok(hr
==E_INVALIDARG
,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1146 hr
=ITfKeystrokeMgr_PreserveKey(keymgr
, tid
, &CLSID_PreservedKey
, &tfpk
, NULL
, 0);
1147 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_PreserveKey failed\n");
1149 hr
=ITfKeystrokeMgr_PreserveKey(keymgr
, tid
, &CLSID_PreservedKey
, &tfpk
, NULL
, 0);
1150 ok(hr
== TF_E_ALREADY_EXISTS
,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1153 hr
= ITfKeystrokeMgr_IsPreservedKey(keymgr
, &CLSID_PreservedKey
, &tfpk
, &preserved
);
1154 ok(hr
== S_OK
, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1155 if (hr
== S_OK
) ok(preserved
== TRUE
,"misreporting preserved key\n");
1157 hr
= ITfKeystrokeMgr_UnpreserveKey(keymgr
, &CLSID_PreservedKey
,&tfpk
);
1158 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1160 hr
= ITfKeystrokeMgr_IsPreservedKey(keymgr
, &CLSID_PreservedKey
, &tfpk
, &preserved
);
1161 ok(hr
== S_FALSE
, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1162 if (hr
== S_FALSE
) ok(preserved
== FALSE
,"misreporting preserved key\n");
1164 hr
= ITfKeystrokeMgr_UnpreserveKey(keymgr
, &CLSID_PreservedKey
,&tfpk
);
1165 ok(hr
==CONNECT_E_NOCONNECTION
,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1167 hr
= ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr
,tid
);
1168 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1170 ITfKeystrokeMgr_Release(keymgr
);
1171 ITfKeyEventSink_Release(sink
);
1174 static void test_Activate(void)
1178 hr
= ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp
,&CLSID_FakeService
,gLangid
,&CLSID_FakeService
);
1179 ok(SUCCEEDED(hr
),"Failed to Activate text service\n");
1183 static void test_EnumContexts(ITfDocumentMgr
*dm
, ITfContext
*search
)
1186 IEnumTfContexts
* pEnum
;
1189 hr
= ITfDocumentMgr_EnumContexts(dm
,&pEnum
);
1190 ok(SUCCEEDED(hr
),"EnumContexts failed\n");
1195 while (IEnumTfContexts_Next(pEnum
, 1, &cxt
, &fetched
) == S_OK
)
1199 else if (search
== cxt
)
1201 ITfContext_Release(cxt
);
1203 IEnumTfContexts_Release(pEnum
);
1206 ok(found
,"Did not find proper ITfContext\n");
1208 ok(!found
,"Found an ITfContext we should should not have\n");
1211 static void test_EnumDocumentMgr(ITfThreadMgr
*tm
, ITfDocumentMgr
*search
, ITfDocumentMgr
*absent
)
1214 IEnumTfDocumentMgrs
* pEnum
;
1216 BOOL notfound
= TRUE
;
1218 hr
= ITfThreadMgr_EnumDocumentMgrs(tm
,&pEnum
);
1219 ok(SUCCEEDED(hr
),"EnumDocumentMgrs failed\n");
1224 while (IEnumTfDocumentMgrs_Next(pEnum
, 1, &dm
, &fetched
) == S_OK
)
1228 else if (search
== dm
)
1230 if (absent
&& dm
== absent
)
1232 ITfDocumentMgr_Release(dm
);
1234 IEnumTfDocumentMgrs_Release(pEnum
);
1237 ok(found
,"Did not find proper ITfDocumentMgr\n");
1239 ok(!found
,"Found an ITfDocumentMgr we should should not have\n");
1241 ok(notfound
,"Found an ITfDocumentMgr we believe should be absent\n");
1244 static inline int check_context_refcount(ITfContext
*iface
)
1246 IUnknown_AddRef(iface
);
1247 return IUnknown_Release(iface
);
1251 /**********************************************************************
1253 **********************************************************************/
1254 typedef struct tagTextEditSink
1256 const ITfTextEditSinkVtbl
*TextEditSinkVtbl
;
1260 static void TextEditSink_Destructor(TextEditSink
*This
)
1262 HeapFree(GetProcessHeap(),0,This
);
1265 static HRESULT WINAPI
TextEditSink_QueryInterface(ITfTextEditSink
*iface
, REFIID iid
, LPVOID
*ppvOut
)
1267 TextEditSink
*This
= (TextEditSink
*)iface
;
1270 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfTextEditSink
))
1277 IUnknown_AddRef(iface
);
1281 return E_NOINTERFACE
;
1284 static ULONG WINAPI
TextEditSink_AddRef(ITfTextEditSink
*iface
)
1286 TextEditSink
*This
= (TextEditSink
*)iface
;
1287 return InterlockedIncrement(&This
->refCount
);
1290 static ULONG WINAPI
TextEditSink_Release(ITfTextEditSink
*iface
)
1292 TextEditSink
*This
= (TextEditSink
*)iface
;
1295 ret
= InterlockedDecrement(&This
->refCount
);
1297 TextEditSink_Destructor(This
);
1301 static HRESULT WINAPI
TextEditSink_OnEndEdit(ITfTextEditSink
*iface
,
1302 ITfContext
*pic
, TfEditCookie ecReadOnly
, ITfEditRecord
*pEditRecord
)
1304 sink_fire_ok(&test_OnEndEdit
,"TextEditSink_OnEndEdit");
1308 static const ITfTextEditSinkVtbl TextEditSink_TextEditSinkVtbl
=
1310 TextEditSink_QueryInterface
,
1311 TextEditSink_AddRef
,
1312 TextEditSink_Release
,
1314 TextEditSink_OnEndEdit
1317 static HRESULT
TextEditSink_Constructor(ITfTextEditSink
**ppOut
)
1322 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextEditSink
));
1324 return E_OUTOFMEMORY
;
1326 This
->TextEditSinkVtbl
= &TextEditSink_TextEditSinkVtbl
;
1329 *ppOut
= (ITfTextEditSink
*)This
;
1333 static void test_startSession(void)
1338 ITfDocumentMgr
*dmtest
;
1339 ITfContext
*cxt
,*cxt2
,*cxt3
,*cxtTest
;
1341 TfClientId cid2
= 0;
1343 hr
= ITfThreadMgr_Deactivate(g_tm
);
1344 ok(hr
== E_UNEXPECTED
,"Deactivate should have failed with E_UNEXPECTED\n");
1346 test_ShouldActivate
= TRUE
;
1347 hr
= ITfThreadMgr_Activate(g_tm
,&cid
);
1348 ok(SUCCEEDED(hr
),"Failed to Activate\n");
1349 ok(cid
!= tid
,"TextService id mistakenly matches Client id\n");
1351 test_ShouldActivate
= FALSE
;
1352 hr
= ITfThreadMgr_Activate(g_tm
,&cid2
);
1353 ok(SUCCEEDED(hr
),"Failed to Activate\n");
1354 ok (cid
== cid2
, "Second activate client ID does not match\n");
1356 hr
= ITfThreadMgr_Deactivate(g_tm
);
1357 ok(SUCCEEDED(hr
),"Failed to Deactivate\n");
1359 test_EnumDocumentMgr(g_tm
,NULL
,NULL
);
1361 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&g_dm
);
1362 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
1364 test_EnumDocumentMgr(g_tm
,g_dm
,NULL
);
1366 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&dmtest
);
1367 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
1369 test_EnumDocumentMgr(g_tm
,dmtest
,NULL
);
1371 ITfDocumentMgr_Release(dmtest
);
1372 test_EnumDocumentMgr(g_tm
,g_dm
,dmtest
);
1374 hr
= ITfThreadMgr_GetFocus(g_tm
,&dmtest
);
1375 ok(SUCCEEDED(hr
),"GetFocus Failed\n");
1376 ok(dmtest
== NULL
,"Initial focus not null\n");
1378 test_CurrentFocus
= g_dm
;
1379 test_PrevFocus
= NULL
;
1380 test_OnSetFocus
= SINK_EXPECTED
;
1381 hr
= ITfThreadMgr_SetFocus(g_tm
,g_dm
);
1382 ok(SUCCEEDED(hr
),"SetFocus Failed\n");
1383 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
1385 hr
= ITfThreadMgr_GetFocus(g_tm
,&dmtest
);
1386 ok(SUCCEEDED(hr
),"GetFocus Failed\n");
1387 ok(g_dm
== dmtest
,"Expected DocumentMgr not focused\n");
1389 cnt
= ITfDocumentMgr_Release(g_dm
);
1390 ok(cnt
== 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt
);
1392 hr
= ITfThreadMgr_GetFocus(g_tm
,&dmtest
);
1393 ok(SUCCEEDED(hr
),"GetFocus Failed\n");
1394 ok(g_dm
== dmtest
,"Expected DocumentMgr not focused\n");
1395 ITfDocumentMgr_Release(dmtest
);
1397 TextStoreACP_Constructor((IUnknown
**)&ts
);
1399 hr
= ITfDocumentMgr_CreateContext(g_dm
, cid
, 0, (IUnknown
*)ts
, &cxt
, &editCookie
);
1400 ok(SUCCEEDED(hr
),"CreateContext Failed\n");
1402 hr
= ITfDocumentMgr_CreateContext(g_dm
, cid
, 0, NULL
, &cxt2
, &editCookie
);
1403 ok(SUCCEEDED(hr
),"CreateContext Failed\n");
1405 hr
= ITfDocumentMgr_CreateContext(g_dm
, cid
, 0, NULL
, &cxt3
, &editCookie
);
1406 ok(SUCCEEDED(hr
),"CreateContext Failed\n");
1408 test_EnumContexts(g_dm
, NULL
);
1410 hr
= ITfContext_GetDocumentMgr(cxt
,&dmtest
);
1411 ok(hr
== S_OK
, "ITfContext_GetDocumentMgr failed with %x\n",hr
);
1412 ok(dmtest
== g_dm
, "Wrong documentmgr\n");
1413 ITfDocumentMgr_Release(dmtest
);
1415 cnt
= check_context_refcount(cxt
);
1416 test_OnPushContext
= SINK_EXPECTED
;
1417 test_ACP_AdviseSink
= SINK_EXPECTED
;
1418 test_OnInitDocumentMgr
= SINK_EXPECTED
;
1419 hr
= ITfDocumentMgr_Push(g_dm
, cxt
);
1420 ok(SUCCEEDED(hr
),"Push Failed\n");
1421 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1422 sink_check_ok(&test_OnPushContext
,"OnPushContext");
1423 sink_check_ok(&test_OnInitDocumentMgr
,"OnInitDocumentMgr");
1424 sink_check_ok(&test_ACP_AdviseSink
,"TextStoreACP_AdviseSink");
1426 test_EnumContexts(g_dm
, cxt
);
1428 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1429 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1430 ok(cxtTest
== cxt
, "Wrong context on top\n");
1431 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1432 cnt
= ITfContext_Release(cxtTest
);
1434 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1435 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1436 ok(cxtTest
== cxt
, "Wrong context on Base\n");
1437 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1438 ITfContext_Release(cxtTest
);
1440 check_context_refcount(cxt2
);
1441 test_OnPushContext
= SINK_EXPECTED
;
1442 hr
= ITfDocumentMgr_Push(g_dm
, cxt2
);
1443 ok(SUCCEEDED(hr
),"Push Failed\n");
1444 sink_check_ok(&test_OnPushContext
,"OnPushContext");
1446 cnt
= check_context_refcount(cxt2
);
1447 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1448 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1449 ok(cxtTest
== cxt2
, "Wrong context on top\n");
1450 ok(check_context_refcount(cxt2
) > cnt
, "Ref count did not increase\n");
1451 ITfContext_Release(cxtTest
);
1453 cnt
= check_context_refcount(cxt
);
1454 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1455 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1456 ok(cxtTest
== cxt
, "Wrong context on Base\n");
1457 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1458 ITfContext_Release(cxtTest
);
1460 cnt
= check_context_refcount(cxt3
);
1461 hr
= ITfDocumentMgr_Push(g_dm
, cxt3
);
1462 ok(FAILED(hr
),"Push Succeeded\n");
1463 ok(check_context_refcount(cxt3
) == cnt
, "Ref changed\n");
1465 cnt
= check_context_refcount(cxt2
);
1466 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1467 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1468 ok(cxtTest
== cxt2
, "Wrong context on top\n");
1469 ok(check_context_refcount(cxt2
) > cnt
, "Ref count did not increase\n");
1470 ITfContext_Release(cxtTest
);
1472 cnt
= check_context_refcount(cxt
);
1473 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1474 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1475 ok(cxtTest
== cxt
, "Wrong context on Base\n");
1476 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1477 ITfContext_Release(cxtTest
);
1479 cnt
= check_context_refcount(cxt2
);
1480 test_OnPopContext
= SINK_EXPECTED
;
1481 hr
= ITfDocumentMgr_Pop(g_dm
, 0);
1482 ok(SUCCEEDED(hr
),"Pop Failed\n");
1483 ok(check_context_refcount(cxt2
) < cnt
, "Ref count did not decrease\n");
1484 sink_check_ok(&test_OnPopContext
,"OnPopContext");
1486 dmtest
= (void *)0xfeedface;
1487 hr
= ITfContext_GetDocumentMgr(cxt2
,&dmtest
);
1488 ok(hr
== S_FALSE
, "ITfContext_GetDocumentMgr wrong rc %x\n",hr
);
1489 ok(dmtest
== NULL
,"returned documentmgr should be null\n");
1491 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1492 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1493 ok(cxtTest
== cxt
, "Wrong context on top\n");
1494 ITfContext_Release(cxtTest
);
1496 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1497 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1498 ok(cxtTest
== cxt
, "Wrong context on base\n");
1499 ITfContext_Release(cxtTest
);
1501 hr
= ITfDocumentMgr_Pop(g_dm
, 0);
1502 ok(FAILED(hr
),"Pop Succeeded\n");
1504 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1505 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1506 ok(cxtTest
== cxt
, "Wrong context on top\n");
1507 ITfContext_Release(cxtTest
);
1509 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1510 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1511 ok(cxtTest
== cxt
, "Wrong context on base\n");
1512 ITfContext_Release(cxtTest
);
1514 ITfContext_Release(cxt
);
1515 ITfContext_Release(cxt2
);
1516 ITfContext_Release(cxt3
);
1519 static void test_endSession(void)
1522 test_ShouldDeactivate
= TRUE
;
1523 test_CurrentFocus
= NULL
;
1524 test_PrevFocus
= g_dm
;
1525 test_OnSetFocus
= SINK_EXPECTED
;
1526 hr
= ITfThreadMgr_Deactivate(g_tm
);
1527 ok(SUCCEEDED(hr
),"Failed to Deactivate\n");
1528 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
1529 test_OnSetFocus
= SINK_UNEXPECTED
;
1532 static void test_TfGuidAtom(void)
1536 TfGuidAtom atom1
,atom2
;
1539 CoCreateGuid(>est
);
1541 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1543 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1544 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1546 hr
= ITfCategoryMgr_RegisterGUID(g_cm
,>est
,&atom1
);
1547 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterGUID failed\n");
1548 hr
= ITfCategoryMgr_RegisterGUID(g_cm
,>est
,&atom2
);
1549 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterGUID failed\n");
1550 ok(atom1
== atom2
,"atoms do not match\n");
1551 hr
= ITfCategoryMgr_GetGUID(g_cm
,atom2
,NULL
);
1552 ok(hr
==E_INVALIDARG
,"ITfCategoryMgr_GetGUID should have failed\n");
1553 hr
= ITfCategoryMgr_GetGUID(g_cm
,atom2
,&g1
);
1554 ok(SUCCEEDED(hr
),"ITfCategoryMgr_GetGUID failed\n");
1555 ok(IsEqualGUID(&g1
,>est
),"guids do not match\n");
1556 hr
= ITfCategoryMgr_IsEqualTfGuidAtom(g_cm
,atom1
,>est
,NULL
);
1557 ok(hr
==E_INVALIDARG
,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1558 hr
= ITfCategoryMgr_IsEqualTfGuidAtom(g_cm
,atom1
,>est
,&equal
);
1559 ok(SUCCEEDED(hr
),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1560 ok(equal
== TRUE
,"Equal value invalid\n");
1562 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1563 hr
= ITfCategoryMgr_IsEqualTfGuidAtom(g_cm
,tid
,&CLSID_FakeService
,&equal
);
1564 ok(SUCCEEDED(hr
),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1565 ok(equal
== TRUE
,"Equal value invalid\n");
1566 hr
= ITfCategoryMgr_GetGUID(g_cm
,cid
,&g1
);
1567 ok(SUCCEEDED(hr
),"ITfCategoryMgr_GetGUID failed\n");
1568 ok(!IsEqualGUID(&g1
,&GUID_NULL
),"guid should not be NULL\n");
1571 static void test_ClientId(void)
1578 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfClientId
, (LPVOID
*)&pcid
);
1579 ok(SUCCEEDED(hr
),"Unable to acquire ITfClientId interface\n");
1583 hr
= ITfClientId_GetClientId(pcid
,&GUID_NULL
,&id1
);
1584 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1585 hr
= ITfClientId_GetClientId(pcid
,&GUID_NULL
,&id2
);
1586 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1587 ok(id1
==id2
,"Id's for GUID_NULL do not match\n");
1588 hr
= ITfClientId_GetClientId(pcid
,&CLSID_FakeService
,&id2
);
1589 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1590 ok(id2
!=id1
,"Id matches GUID_NULL\n");
1591 ok(id2
==tid
,"Id for CLSID_FakeService not matching tid\n");
1592 ok(id2
!=cid
,"Id for CLSID_FakeService matching cid\n");
1593 hr
= ITfClientId_GetClientId(pcid
,&g2
,&id2
);
1594 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1595 ok(id2
!=id1
,"Id matches GUID_NULL\n");
1596 ok(id2
!=tid
,"Id for random guid matching tid\n");
1597 ok(id2
!=cid
,"Id for random guid matching cid\n");
1598 ITfClientId_Release(pcid
);
1601 /**********************************************************************
1603 **********************************************************************/
1604 typedef struct tagEditSession
1606 const ITfEditSessionVtbl
*EditSessionVtbl
;
1610 static void EditSession_Destructor(EditSession
*This
)
1612 HeapFree(GetProcessHeap(),0,This
);
1615 static HRESULT WINAPI
EditSession_QueryInterface(ITfEditSession
*iface
, REFIID iid
, LPVOID
*ppvOut
)
1617 EditSession
*This
= (EditSession
*)iface
;
1620 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfEditSession
))
1627 IUnknown_AddRef(iface
);
1631 return E_NOINTERFACE
;
1634 static ULONG WINAPI
EditSession_AddRef(ITfEditSession
*iface
)
1636 EditSession
*This
= (EditSession
*)iface
;
1637 return InterlockedIncrement(&This
->refCount
);
1640 static ULONG WINAPI
EditSession_Release(ITfEditSession
*iface
)
1642 EditSession
*This
= (EditSession
*)iface
;
1645 ret
= InterlockedDecrement(&This
->refCount
);
1647 EditSession_Destructor(This
);
1651 static void test_InsertAtSelection(TfEditCookie ec
, ITfContext
*cxt
)
1654 ITfInsertAtSelection
*iis
;
1655 ITfRange
*range
=NULL
;
1656 static const WCHAR txt
[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1658 hr
= ITfContext_QueryInterface(cxt
, &IID_ITfInsertAtSelection
, (LPVOID
*)&iis
);
1659 ok(SUCCEEDED(hr
),"Failed to get ITfInsertAtSelection interface\n");
1660 test_ACP_InsertTextAtSelection
= SINK_EXPECTED
;
1661 hr
= ITfInsertAtSelection_InsertTextAtSelection(iis
, ec
, 0, txt
, 11, &range
);
1662 ok(SUCCEEDED(hr
),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr
);
1663 sink_check_ok(&test_ACP_InsertTextAtSelection
,"InsertTextAtSelection");
1664 ok(range
!= NULL
,"No range returned\n");
1665 ITfRange_Release(range
);
1666 ITfInsertAtSelection_Release(iis
);
1669 static HRESULT WINAPI
EditSession_DoEditSession(ITfEditSession
*iface
,
1675 TF_SELECTION selection
;
1679 sink_fire_ok(&test_DoEditSession
,"EditSession_DoEditSession");
1680 sink_check_ok(&test_ACP_RequestLock
,"RequestLock");
1682 ITfThreadMgr_GetFocus(g_tm
, &dm
);
1683 ITfDocumentMgr_GetTop(dm
,&cxt
);
1685 hr
= ITfContext_GetStart(cxt
,ec
,NULL
);
1686 ok(hr
== E_INVALIDARG
,"Unexpected return code %x\n",hr
);
1688 range
= (ITfRange
*)0xdeaddead;
1689 hr
= ITfContext_GetStart(cxt
,0xdeadcafe,&range
);
1690 ok(hr
== TF_E_NOLOCK
,"Unexpected return code %x\n",hr
);
1691 ok(range
== NULL
,"Range not set to NULL\n");
1693 hr
= ITfContext_GetStart(cxt
,ec
,&range
);
1694 ok(SUCCEEDED(hr
),"Unexpected return code %x\n",hr
);
1695 ok(range
!= NULL
,"Range set to NULL\n");
1697 ITfRange_Release(range
);
1699 hr
= ITfContext_GetEnd(cxt
,ec
,NULL
);
1700 ok(hr
== E_INVALIDARG
,"Unexpected return code %x\n",hr
);
1702 range
= (ITfRange
*)0xdeaddead;
1703 hr
= ITfContext_GetEnd(cxt
,0xdeadcafe,&range
);
1704 ok(hr
== TF_E_NOLOCK
,"Unexpected return code %x\n",hr
);
1705 ok(range
== NULL
,"Range not set to NULL\n");
1707 test_ACP_GetEndACP
= SINK_EXPECTED
;
1708 hr
= ITfContext_GetEnd(cxt
,ec
,&range
);
1709 ok(SUCCEEDED(hr
),"Unexpected return code %x\n",hr
);
1710 ok(range
!= NULL
,"Range set to NULL\n");
1711 sink_check_ok(&test_ACP_GetEndACP
,"GetEndACP");
1713 ITfRange_Release(range
);
1715 selection
.range
= NULL
;
1716 test_ACP_GetSelection
= SINK_EXPECTED
;
1717 hr
= ITfContext_GetSelection(cxt
, ec
, TF_DEFAULT_SELECTION
, 1, &selection
, &fetched
);
1718 ok(SUCCEEDED(hr
),"ITfContext_GetSelection failed\n");
1719 ok(fetched
== 1,"fetched incorrect\n");
1720 ok(selection
.range
!= NULL
,"NULL range\n");
1721 sink_check_ok(&test_ACP_GetSelection
,"ACP_GetSepection");
1722 ITfRange_Release(selection
.range
);
1724 test_InsertAtSelection(ec
, cxt
);
1726 test_ACP_GetEndACP
= SINK_EXPECTED
;
1727 hr
= ITfContext_GetEnd(cxt
,ec
,&range
);
1728 ok(SUCCEEDED(hr
),"Unexpected return code %x\n",hr
);
1729 ok(range
!= NULL
,"Range set to NULL\n");
1730 sink_check_ok(&test_ACP_GetEndACP
,"GetEndACP");
1732 selection
.range
= range
;
1733 selection
.style
.ase
= TF_AE_NONE
;
1734 selection
.style
.fInterimChar
= FALSE
;
1735 test_ACP_SetSelection
= SINK_EXPECTED
;
1736 hr
= ITfContext_SetSelection(cxt
, ec
, 1, &selection
);
1737 sink_check_ok(&test_ACP_SetSelection
,"SetSelection");
1738 ITfRange_Release(range
);
1740 ITfContext_Release(cxt
);
1741 ITfDocumentMgr_Release(dm
);
1745 static const ITfEditSessionVtbl EditSession_EditSessionVtbl
=
1747 EditSession_QueryInterface
,
1749 EditSession_Release
,
1751 EditSession_DoEditSession
1754 static HRESULT
EditSession_Constructor(ITfEditSession
**ppOut
)
1759 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(EditSession
));
1761 return E_OUTOFMEMORY
;
1763 This
->EditSessionVtbl
= &EditSession_EditSessionVtbl
;
1766 *ppOut
= (ITfEditSession
*)This
;
1770 static void test_TStoApplicationText(void)
1772 HRESULT hr
, hrSession
;
1776 ITfTextEditSink
*sink
;
1777 ITfSource
*source
= NULL
;
1778 DWORD editSinkCookie
= -1;
1780 ITfThreadMgr_GetFocus(g_tm
, &dm
);
1781 EditSession_Constructor(&es
);
1782 ITfDocumentMgr_GetTop(dm
,&cxt
);
1784 TextEditSink_Constructor(&sink
);
1785 hr
= ITfContext_QueryInterface(cxt
,&IID_ITfSource
,(LPVOID
*)&source
);
1786 ok(SUCCEEDED(hr
),"Failed to get IID_ITfSource for Context\n");
1789 hr
= ITfSource_AdviseSink(source
, &IID_ITfTextEditSink
, (LPVOID
)sink
, &editSinkCookie
);
1790 ok(SUCCEEDED(hr
),"Failed to advise Sink\n");
1791 ok(editSinkCookie
!= -1,"Failed to get sink cookie\n");
1794 hrSession
= 0xfeedface;
1795 /* Test no premissions flags */
1796 hr
= ITfContext_RequestEditSession(cxt
, tid
, es
, TF_ES_SYNC
, &hrSession
);
1797 ok(hr
== E_INVALIDARG
,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG
,hr
);
1798 ok(hrSession
== E_FAIL
,"hrSession should be %x not %x\n",E_FAIL
,hrSession
);
1800 documentStatus
= TS_SD_READONLY
;
1801 hrSession
= 0xfeedface;
1802 test_ACP_GetStatus
= SINK_EXPECTED
;
1803 hr
= ITfContext_RequestEditSession(cxt
, tid
, es
, TF_ES_SYNC
|TF_ES_READWRITE
, &hrSession
);
1804 ok(SUCCEEDED(hr
),"ITfContext_RequestEditSession failed\n");
1805 ok(hrSession
== TS_E_READONLY
,"Unexpected hrSession (%x)\n",hrSession
);
1806 sink_check_ok(&test_ACP_GetStatus
,"GetStatus");
1808 /* signal a change to allow readwrite sessions */
1810 test_ACP_RequestLock
= SINK_EXPECTED
;
1811 ITextStoreACPSink_OnStatusChange(ACPSink
,documentStatus
);
1812 sink_check_ok(&test_ACP_RequestLock
,"RequestLock");
1814 test_ACP_GetStatus
= SINK_EXPECTED
;
1815 test_ACP_RequestLock
= SINK_EXPECTED
;
1816 test_DoEditSession
= SINK_EXPECTED
;
1817 hrSession
= 0xfeedface;
1818 test_OnEndEdit
= SINK_EXPECTED
;
1819 hr
= ITfContext_RequestEditSession(cxt
, tid
, es
, TF_ES_SYNC
|TF_ES_READWRITE
, &hrSession
);
1820 ok(SUCCEEDED(hr
),"ITfContext_RequestEditSession failed\n");
1821 sink_check_ok(&test_OnEndEdit
,"OnEndEdit");
1822 sink_check_ok(&test_DoEditSession
,"DoEditSession");
1823 sink_check_ok(&test_ACP_GetStatus
,"GetStatus");
1824 ok(hrSession
== 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession
);
1828 hr
= ITfSource_UnadviseSink(source
, editSinkCookie
);
1829 ok(SUCCEEDED(hr
),"Failed to unadvise Sink\n");
1830 ITfTextEditSink_Release(sink
);
1831 ITfSource_Release(source
);
1834 ITfContext_Release(cxt
);
1835 ITfDocumentMgr_Release(dm
);
1836 ITfEditSession_Release(es
);
1839 static void enum_compartments(ITfCompartmentMgr
*cmpmgr
, REFGUID present
, REFGUID absent
)
1845 if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr
, &ppEnum
)))
1849 while (IEnumGUID_Next(ppEnum
, 1, &g
, &fetched
) == S_OK
)
1853 StringFromGUID2(&g
,str
,sizeof(str
)/sizeof(str
[0]));
1854 WideCharToMultiByte(CP_ACP
,0,str
,-1,strA
,sizeof(strA
),0,0);
1855 trace("found %s\n",strA
);
1856 if (present
&& IsEqualGUID(present
,&g
))
1858 if (absent
&& IsEqualGUID(absent
, &g
))
1861 IEnumGUID_Release(ppEnum
);
1864 ok(found
,"Did not find compartment\n");
1866 ok(!found2
,"Found compartment that should be absent\n");
1869 static void test_Compartments(void)
1873 ITfCompartmentMgr
*cmpmgr
;
1874 ITfCompartment
*cmp
;
1877 ITfThreadMgr_GetFocus(g_tm
, &dm
);
1878 ITfDocumentMgr_GetTop(dm
,&cxt
);
1881 hr
= ITfThreadMgr_GetGlobalCompartment(g_tm
, &cmpmgr
);
1882 ok(SUCCEEDED(hr
),"GetGlobalCompartment failed\n");
1883 hr
= ITfCompartmentMgr_GetCompartment(cmpmgr
, &GUID_COMPARTMENT_SPEECH_OPENCLOSE
, &cmp
);
1884 ok(SUCCEEDED(hr
),"GetCompartment failed\n");
1885 ITfCompartment_Release(cmp
);
1886 enum_compartments(cmpmgr
,&GUID_COMPARTMENT_SPEECH_OPENCLOSE
,NULL
);
1887 ITfCompartmentMgr_Release(cmpmgr
);
1890 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfCompartmentMgr
, (LPVOID
*)&cmpmgr
);
1891 ok(SUCCEEDED(hr
),"ThreadMgr QI for IID_ITfCompartmentMgr failed\n");
1892 hr
= ITfCompartmentMgr_GetCompartment(cmpmgr
, &CLSID_FakeService
, &cmp
);
1893 ok(SUCCEEDED(hr
),"GetCompartment failed\n");
1894 enum_compartments(cmpmgr
,&CLSID_FakeService
,&GUID_COMPARTMENT_SPEECH_OPENCLOSE
);
1895 ITfCompartmentMgr_ClearCompartment(cmpmgr
,tid
,&CLSID_FakeService
);
1896 enum_compartments(cmpmgr
,NULL
,&CLSID_FakeService
);
1897 ITfCompartmentMgr_Release(cmpmgr
);
1898 ITfCompartment_Release(cmp
);
1901 hr
= ITfDocumentMgr_QueryInterface(dm
, &IID_ITfCompartmentMgr
, (LPVOID
*)&cmpmgr
);
1902 ok(SUCCEEDED(hr
),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1904 hr
= ITfCompartmentMgr_GetCompartment(cmpmgr
, &GUID_COMPARTMENT_PERSISTMENUENABLED
, &cmp
);
1905 ok(SUCCEEDED(hr
),"GetCompartment failed\n");
1906 enum_compartments(cmpmgr
,&GUID_COMPARTMENT_PERSISTMENUENABLED
,&GUID_COMPARTMENT_SPEECH_OPENCLOSE
);
1907 ITfCompartmentMgr_Release(cmpmgr
);
1910 hr
= ITfContext_QueryInterface(cxt
, &IID_ITfCompartmentMgr
, (LPVOID
*)&cmpmgr
);
1911 ok(SUCCEEDED(hr
),"Context QI for IID_ITfCompartmentMgr failed\n");
1912 enum_compartments(cmpmgr
,NULL
,&GUID_COMPARTMENT_PERSISTMENUENABLED
);
1913 ITfCompartmentMgr_Release(cmpmgr
);
1915 ITfContext_Release(cxt
);
1916 ITfDocumentMgr_Release(dm
);
1919 static void processPendingMessages(void)
1922 while (PeekMessage(&msg
, NULL
, 0, 0, PM_REMOVE
)) {
1923 TranslateMessage(&msg
);
1924 DispatchMessage(&msg
);
1928 static void test_AssociateFocus(void)
1930 ITfDocumentMgr
*dm1
, *dm2
, *olddm
, *dmcheck
, *dmorig
;
1931 HWND wnd1
, wnd2
, wnd3
;
1934 ITfThreadMgr_GetFocus(g_tm
, &dmorig
);
1935 test_CurrentFocus
= NULL
;
1936 test_PrevFocus
= dmorig
;
1937 test_OnSetFocus
= SINK_EXPECTED
;
1938 hr
= ITfThreadMgr_SetFocus(g_tm
,NULL
);
1939 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
1940 ITfDocumentMgr_Release(dmorig
);
1942 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&dm1
);
1943 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
1945 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&dm2
);
1946 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
1948 wnd1
= CreateWindow("edit",NULL
,WS_POPUP
,0,0,200,60,NULL
,NULL
,NULL
,NULL
);
1949 ok(wnd1
!=NULL
,"Unable to create window 1\n");
1950 wnd2
= CreateWindow("edit",NULL
,WS_POPUP
,0,65,200,60,NULL
,NULL
,NULL
,NULL
);
1951 ok(wnd2
!=NULL
,"Unable to create window 2\n");
1952 wnd3
= CreateWindow("edit",NULL
,WS_POPUP
,0,130,200,60,NULL
,NULL
,NULL
,NULL
);
1953 ok(wnd3
!=NULL
,"Unable to create window 3\n");
1955 processPendingMessages();
1957 test_OnInitDocumentMgr
= SINK_OPTIONAL
; /* Vista and greater */
1958 test_OnPushContext
= SINK_OPTIONAL
; /* Vista and greater */
1960 ShowWindow(wnd1
,SW_SHOWNORMAL
);
1962 sink_check_ok(&test_OnInitDocumentMgr
,"OnInitDocumentMgr");
1963 sink_check_ok(&test_OnPushContext
,"OnPushContext");
1965 test_OnSetFocus
= SINK_OPTIONAL
; /* Vista and greater */
1966 ITfThreadMgr_GetFocus(g_tm
, &test_PrevFocus
);
1967 test_CurrentFocus
= FOCUS_IGNORE
; /* This is a default system context */
1968 processPendingMessages();
1969 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
1971 test_CurrentFocus
= dm1
;
1972 test_PrevFocus
= FOCUS_IGNORE
;
1973 test_OnSetFocus
= SINK_EXPECTED
;
1974 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd1
,dm1
,&olddm
);
1975 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
1976 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
1978 processPendingMessages();
1980 ITfThreadMgr_GetFocus(g_tm
, &dmcheck
);
1981 ok(dmcheck
== dm1
, "Expected DocumentMgr not focused\n");
1982 ITfDocumentMgr_Release(dmcheck
);
1984 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd2
,dm2
,&olddm
);
1985 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
1986 processPendingMessages();
1987 ITfThreadMgr_GetFocus(g_tm
, &dmcheck
);
1988 ok(dmcheck
== dm1
, "Expected DocumentMgr not focused\n");
1989 ITfDocumentMgr_Release(dmcheck
);
1991 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd3
,dm2
,&olddm
);
1992 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
1993 processPendingMessages();
1994 ITfThreadMgr_GetFocus(g_tm
, &dmcheck
);
1995 ok(dmcheck
== dm1
, "Expected DocumentMgr not focused\n");
1996 ITfDocumentMgr_Release(dmcheck
);
1998 test_CurrentFocus
= dm2
;
1999 test_PrevFocus
= dm1
;
2000 test_OnSetFocus
= SINK_OPTIONAL
; /* wine and Winxp */
2001 ShowWindow(wnd2
,SW_SHOWNORMAL
);
2003 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2004 test_CurrentFocus
= FOCUS_IGNORE
; /* occasional wine race */
2005 test_PrevFocus
= FOCUS_IGNORE
; /* occasional wine race */
2006 test_OnSetFocus
= SINK_IGNORE
; /* occasional wine race */
2007 processPendingMessages();
2009 ShowWindow(wnd3
,SW_SHOWNORMAL
);
2011 processPendingMessages();
2013 test_CurrentFocus
= dm1
;
2014 test_PrevFocus
= dm2
;
2015 test_OnSetFocus
= SINK_EXPECTED
;
2017 processPendingMessages();
2018 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2020 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd3
,NULL
,&olddm
);
2021 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2022 ok(olddm
== dm2
, "incorrect old DocumentMgr returned\n");
2023 ITfDocumentMgr_Release(olddm
);
2025 test_CurrentFocus
= dmorig
;
2026 test_PrevFocus
= dm1
;
2027 test_OnSetFocus
= SINK_EXPECTED
;
2028 test_ACP_GetStatus
= SINK_EXPECTED
;
2029 ITfThreadMgr_SetFocus(g_tm
,dmorig
);
2030 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2032 test_CurrentFocus
= FOCUS_IGNORE
; /* NULL on XP, system default on Vista */
2033 test_PrevFocus
= dmorig
;
2034 test_OnSetFocus
= SINK_EXPECTED
;
2036 processPendingMessages();
2037 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2039 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd2
,NULL
,&olddm
);
2040 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2041 ok(olddm
== dm2
, "incorrect old DocumentMgr returned\n");
2042 ITfDocumentMgr_Release(olddm
);
2043 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd1
,NULL
,&olddm
);
2044 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2045 ok(olddm
== dm1
, "incorrect old DocumentMgr returned\n");
2046 ITfDocumentMgr_Release(olddm
);
2049 processPendingMessages();
2051 processPendingMessages();
2053 ITfDocumentMgr_Release(dm1
);
2054 ITfDocumentMgr_Release(dm2
);
2056 test_CurrentFocus
= dmorig
;
2057 test_PrevFocus
= FOCUS_IGNORE
;
2058 test_OnSetFocus
= SINK_EXPECTED
;
2059 test_ACP_GetStatus
= SINK_IGNORE
;
2060 ITfThreadMgr_SetFocus(g_tm
,dmorig
);
2061 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2063 DestroyWindow(wnd1
);
2064 DestroyWindow(wnd2
);
2065 test_OnPopContext
= SINK_OPTIONAL
; /* Vista and greater */
2066 test_OnSetFocus
= SINK_OPTIONAL
; /* Vista and greater */
2067 ITfThreadMgr_GetFocus(g_tm
, &test_PrevFocus
);
2068 test_CurrentFocus
= NULL
;
2069 DestroyWindow(wnd3
);
2070 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2071 sink_check_ok(&test_OnPopContext
,"OnPopContext");
2074 START_TEST(inputprocessor
)
2076 if (SUCCEEDED(initialize()))
2079 test_RegisterCategory();
2080 test_EnumLanguageProfiles();
2081 test_EnumInputProcessorInfo();
2083 test_ThreadMgrAdviseSinks();
2085 test_startSession();
2088 test_KeystrokeMgr();
2089 test_TStoApplicationText();
2090 test_Compartments();
2091 test_AssociateFocus();
2093 test_FindClosestCategory();
2095 test_ThreadMgrUnadviseSinks();
2096 test_UnregisterCategory();
2100 skip("Unable to create InputProcessor\n");