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
25 #include "wine/test.h"
34 static ITfInputProcessorProfiles
* g_ipp
;
35 static LANGID gLangid
;
36 static ITfCategoryMgr
* g_cm
= NULL
;
37 static ITfThreadMgr
* g_tm
= NULL
;
38 static ITfDocumentMgr
*g_dm
= NULL
;
39 static TfClientId cid
= 0;
40 static TfClientId tid
= 0;
42 static ITextStoreACPSink
*ACPSink
;
44 #define SINK_UNEXPECTED 0
45 #define SINK_EXPECTED 1
48 #define SINK_OPTIONAL 4
51 #define SINK_ACTION_MASK 0xff
52 #define SINK_OPTION_MASK 0xff00
53 #define SINK_EXPECTED_COUNT_MASK 0xff0000
55 #define SINK_OPTION_TODO 0x0100
57 #define FOCUS_IGNORE (ITfDocumentMgr*)0xffffffff
58 #define FOCUS_SAVE (ITfDocumentMgr*)0xfffffffe
60 static BOOL test_ShouldActivate
= FALSE
;
61 static BOOL test_ShouldDeactivate
= FALSE
;
63 static DWORD tmSinkCookie
;
64 static DWORD tmSinkRefCount
;
65 static DWORD documentStatus
;
66 static ITfDocumentMgr
*test_CurrentFocus
= NULL
;
67 static ITfDocumentMgr
*test_PrevFocus
= NULL
;
68 static ITfDocumentMgr
*test_LastCurrentFocus
= FOCUS_SAVE
;
69 static ITfDocumentMgr
*test_FirstPrevFocus
= FOCUS_SAVE
;
70 static INT test_OnSetFocus
= SINK_UNEXPECTED
;
71 static INT test_OnInitDocumentMgr
= SINK_UNEXPECTED
;
72 static INT test_OnPushContext
= SINK_UNEXPECTED
;
73 static INT test_OnPopContext
= SINK_UNEXPECTED
;
74 static INT test_KEV_OnSetFocus
= SINK_UNEXPECTED
;
75 static INT test_ACP_AdviseSink
= SINK_UNEXPECTED
;
76 static INT test_ACP_GetStatus
= SINK_UNEXPECTED
;
77 static INT test_ACP_RequestLock
= SINK_UNEXPECTED
;
78 static INT test_ACP_GetEndACP
= SINK_UNEXPECTED
;
79 static INT test_ACP_GetSelection
= SINK_UNEXPECTED
;
80 static INT test_DoEditSession
= SINK_UNEXPECTED
;
81 static INT test_ACP_InsertTextAtSelection
= SINK_UNEXPECTED
;
82 static INT test_ACP_SetSelection
= SINK_UNEXPECTED
;
83 static INT test_OnEndEdit
= SINK_UNEXPECTED
;
86 static inline int expected_count(int *sink
)
88 return (*sink
& SINK_EXPECTED_COUNT_MASK
)>>16;
91 static inline void _sink_fire_ok(INT
*sink
, const CHAR
* name
)
94 int todo
= *sink
& SINK_OPTION_TODO
;
95 int action
= *sink
& SINK_ACTION_MASK
;
97 if (winetest_interactive
)
98 winetest_trace("firing %s\n",name
);
104 count
= expected_count(sink
);
108 *sink
= (*sink
& ~SINK_EXPECTED_COUNT_MASK
) + (count
<< 16);
113 winetest_trace("Ignoring %s\n",name
);
116 count
= expected_count(sink
) + 1;
117 *sink
= (*sink
& ~SINK_EXPECTED_COUNT_MASK
) + (count
<< 16);
121 todo_wine
winetest_ok(0, "Unexpected %s sink\n",name
);
123 winetest_ok(0, "Unexpected %s sink\n",name
);
128 #define sink_fire_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_fire_ok(a,b)
130 static inline void _sink_check_ok(INT
*sink
, const CHAR
* name
)
132 int action
= *sink
& SINK_ACTION_MASK
;
133 int todo
= *sink
& SINK_OPTION_TODO
;
134 int count
= expected_count(sink
);
139 if (winetest_interactive
)
140 winetest_trace("optional sink %s not fired\n",name
);
146 if (count
== 0 && winetest_interactive
)
147 winetest_trace("optional sink %s not fired\n",name
);
151 todo_wine
winetest_ok(0, "%s not fired as expected, in state %x\n",name
,*sink
);
153 winetest_ok(0, "%s not fired as expected, in state %x\n",name
,*sink
);
155 *sink
= SINK_UNEXPECTED
;
158 #define sink_check_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_ok(a,b)
160 static inline void _sink_check_saved(INT
*sink
, ITfDocumentMgr
*PrevFocus
, ITfDocumentMgr
*CurrentFocus
, const CHAR
* name
)
162 int count
= expected_count(sink
);
163 _sink_check_ok(sink
, name
);
164 if (PrevFocus
!= FOCUS_IGNORE
&& count
!= 0)
165 winetest_ok(PrevFocus
== test_FirstPrevFocus
, "%s expected prev focus %p got %p\n", name
, PrevFocus
, test_FirstPrevFocus
);
166 if (CurrentFocus
!= FOCUS_IGNORE
&& count
!= 0)
167 winetest_ok(CurrentFocus
== test_LastCurrentFocus
, "%s expected current focus %p got %p\n", name
, CurrentFocus
, test_LastCurrentFocus
);
168 test_FirstPrevFocus
= FOCUS_SAVE
;
169 test_LastCurrentFocus
= FOCUS_SAVE
;
172 #define sink_check_saved(s,p,c,n) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_saved(s,p,c,n)
174 /**********************************************************************
176 **********************************************************************/
177 typedef struct tagTextStoreACP
179 ITextStoreACP ITextStoreACP_iface
;
184 static inline TextStoreACP
*impl_from_ITextStoreACP(ITextStoreACP
*iface
)
186 return CONTAINING_RECORD(iface
, TextStoreACP
, ITextStoreACP_iface
);
189 static void TextStoreACP_Destructor(TextStoreACP
*This
)
191 HeapFree(GetProcessHeap(),0,This
);
194 static HRESULT WINAPI
TextStoreACP_QueryInterface(ITextStoreACP
*iface
, REFIID iid
, LPVOID
*ppvOut
)
196 TextStoreACP
*This
= impl_from_ITextStoreACP(iface
);
199 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITextStoreACP
))
206 ITextStoreACP_AddRef(iface
);
210 return E_NOINTERFACE
;
213 static ULONG WINAPI
TextStoreACP_AddRef(ITextStoreACP
*iface
)
215 TextStoreACP
*This
= impl_from_ITextStoreACP(iface
);
216 return InterlockedIncrement(&This
->refCount
);
219 static ULONG WINAPI
TextStoreACP_Release(ITextStoreACP
*iface
)
221 TextStoreACP
*This
= impl_from_ITextStoreACP(iface
);
224 ret
= InterlockedDecrement(&This
->refCount
);
226 TextStoreACP_Destructor(This
);
230 static HRESULT WINAPI
TextStoreACP_AdviseSink(ITextStoreACP
*iface
,
231 REFIID riid
, IUnknown
*punk
, DWORD dwMask
)
235 sink_fire_ok(&test_ACP_AdviseSink
,"TextStoreACP_AdviseSink");
237 hr
= IUnknown_QueryInterface(punk
, &IID_ITextStoreACPSink
,(LPVOID
*)(&ACPSink
));
238 ok(SUCCEEDED(hr
),"Unable to QueryInterface on sink\n");
242 static HRESULT WINAPI
TextStoreACP_UnadviseSink(ITextStoreACP
*iface
,
249 static HRESULT WINAPI
TextStoreACP_RequestLock(ITextStoreACP
*iface
,
250 DWORD dwLockFlags
, HRESULT
*phrSession
)
252 sink_fire_ok(&test_ACP_RequestLock
,"TextStoreACP_RequestLock");
253 *phrSession
= ITextStoreACPSink_OnLockGranted(ACPSink
, dwLockFlags
);
256 static HRESULT WINAPI
TextStoreACP_GetStatus(ITextStoreACP
*iface
,
259 sink_fire_ok(&test_ACP_GetStatus
,"TextStoreACP_GetStatus");
260 pdcs
->dwDynamicFlags
= documentStatus
;
263 static HRESULT WINAPI
TextStoreACP_QueryInsert(ITextStoreACP
*iface
,
264 LONG acpTestStart
, LONG acpTestEnd
, ULONG cch
, LONG
*pacpResultStart
,
270 static HRESULT WINAPI
TextStoreACP_GetSelection(ITextStoreACP
*iface
,
271 ULONG ulIndex
, ULONG ulCount
, TS_SELECTION_ACP
*pSelection
, ULONG
*pcFetched
)
273 sink_fire_ok(&test_ACP_GetSelection
,"TextStoreACP_GetSelection");
275 pSelection
->acpStart
= 10;
276 pSelection
->acpEnd
= 20;
277 pSelection
->style
.fInterimChar
= 0;
278 pSelection
->style
.ase
= TS_AE_NONE
;
283 static HRESULT WINAPI
TextStoreACP_SetSelection(ITextStoreACP
*iface
,
284 ULONG ulCount
, const TS_SELECTION_ACP
*pSelection
)
286 sink_fire_ok(&test_ACP_SetSelection
,"TextStoreACP_SetSelection");
289 static HRESULT WINAPI
TextStoreACP_GetText(ITextStoreACP
*iface
,
290 LONG acpStart
, LONG acpEnd
, WCHAR
*pchPlain
, ULONG cchPlainReq
,
291 ULONG
*pcchPlainRet
, TS_RUNINFO
*prgRunInfo
, ULONG cRunInfoReq
,
292 ULONG
*pcRunInfoRet
, LONG
*pacpNext
)
297 static HRESULT WINAPI
TextStoreACP_SetText(ITextStoreACP
*iface
,
298 DWORD dwFlags
, LONG acpStart
, LONG acpEnd
, const WCHAR
*pchText
,
299 ULONG cch
, TS_TEXTCHANGE
*pChange
)
304 static HRESULT WINAPI
TextStoreACP_GetFormattedText(ITextStoreACP
*iface
,
305 LONG acpStart
, LONG acpEnd
, IDataObject
**ppDataObject
)
310 static HRESULT WINAPI
TextStoreACP_GetEmbedded(ITextStoreACP
*iface
,
311 LONG acpPos
, REFGUID rguidService
, REFIID riid
, IUnknown
**ppunk
)
316 static HRESULT WINAPI
TextStoreACP_QueryInsertEmbedded(ITextStoreACP
*iface
,
317 const GUID
*pguidService
, const FORMATETC
*pFormatEtc
, BOOL
*pfInsertable
)
322 static HRESULT WINAPI
TextStoreACP_InsertEmbedded(ITextStoreACP
*iface
,
323 DWORD dwFlags
, LONG acpStart
, LONG acpEnd
, IDataObject
*pDataObject
,
324 TS_TEXTCHANGE
*pChange
)
329 static HRESULT WINAPI
TextStoreACP_InsertTextAtSelection(ITextStoreACP
*iface
,
330 DWORD dwFlags
, const WCHAR
*pchText
, ULONG cch
, LONG
*pacpStart
,
331 LONG
*pacpEnd
, TS_TEXTCHANGE
*pChange
)
333 sink_fire_ok(&test_ACP_InsertTextAtSelection
,"TextStoreACP_InsertTextAtSelection");
336 static HRESULT WINAPI
TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP
*iface
,
337 DWORD dwFlags
, IDataObject
*pDataObject
, LONG
*pacpStart
, LONG
*pacpEnd
,
338 TS_TEXTCHANGE
*pChange
)
343 static HRESULT WINAPI
TextStoreACP_RequestSupportedAttrs(ITextStoreACP
*iface
,
344 DWORD dwFlags
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
)
349 static HRESULT WINAPI
TextStoreACP_RequestAttrsAtPosition(ITextStoreACP
*iface
,
350 LONG acpPos
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
,
356 static HRESULT WINAPI
TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP
*iface
,
357 LONG acpPos
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
,
363 static HRESULT WINAPI
TextStoreACP_FindNextAttrTransition(ITextStoreACP
*iface
,
364 LONG acpStart
, LONG acpHalt
, ULONG cFilterAttrs
, const TS_ATTRID
*paFilterAttrs
,
365 DWORD dwFlags
, LONG
*pacpNext
, BOOL
*pfFound
, LONG
*plFoundOffset
)
370 static HRESULT WINAPI
TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP
*iface
,
371 ULONG ulCount
, TS_ATTRVAL
*paAttrVals
, ULONG
*pcFetched
)
376 static HRESULT WINAPI
TextStoreACP_GetEndACP(ITextStoreACP
*iface
,
379 sink_fire_ok(&test_ACP_GetEndACP
,"TextStoreACP_GetEndACP");
382 static HRESULT WINAPI
TextStoreACP_GetActiveView(ITextStoreACP
*iface
,
383 TsViewCookie
*pvcView
)
388 static HRESULT WINAPI
TextStoreACP_GetACPFromPoint(ITextStoreACP
*iface
,
389 TsViewCookie vcView
, const POINT
*ptScreen
, DWORD dwFlags
,
395 static HRESULT WINAPI
TextStoreACP_GetTextExt(ITextStoreACP
*iface
,
396 TsViewCookie vcView
, LONG acpStart
, LONG acpEnd
, RECT
*prc
,
402 static HRESULT WINAPI
TextStoreACP_GetScreenExt(ITextStoreACP
*iface
,
403 TsViewCookie vcView
, RECT
*prc
)
408 static HRESULT WINAPI
TextStoreACP_GetWnd(ITextStoreACP
*iface
,
409 TsViewCookie vcView
, HWND
*phwnd
)
415 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl
=
417 TextStoreACP_QueryInterface
,
419 TextStoreACP_Release
,
421 TextStoreACP_AdviseSink
,
422 TextStoreACP_UnadviseSink
,
423 TextStoreACP_RequestLock
,
424 TextStoreACP_GetStatus
,
425 TextStoreACP_QueryInsert
,
426 TextStoreACP_GetSelection
,
427 TextStoreACP_SetSelection
,
428 TextStoreACP_GetText
,
429 TextStoreACP_SetText
,
430 TextStoreACP_GetFormattedText
,
431 TextStoreACP_GetEmbedded
,
432 TextStoreACP_QueryInsertEmbedded
,
433 TextStoreACP_InsertEmbedded
,
434 TextStoreACP_InsertTextAtSelection
,
435 TextStoreACP_InsertEmbeddedAtSelection
,
436 TextStoreACP_RequestSupportedAttrs
,
437 TextStoreACP_RequestAttrsAtPosition
,
438 TextStoreACP_RequestAttrsTransitioningAtPosition
,
439 TextStoreACP_FindNextAttrTransition
,
440 TextStoreACP_RetrieveRequestedAttrs
,
441 TextStoreACP_GetEndACP
,
442 TextStoreACP_GetActiveView
,
443 TextStoreACP_GetACPFromPoint
,
444 TextStoreACP_GetTextExt
,
445 TextStoreACP_GetScreenExt
,
449 static HRESULT
TextStoreACP_Constructor(IUnknown
**ppOut
)
453 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextStoreACP
));
455 return E_OUTOFMEMORY
;
457 This
->ITextStoreACP_iface
.lpVtbl
= &TextStoreACP_TextStoreACPVtbl
;
460 *ppOut
= (IUnknown
*)This
;
464 /**********************************************************************
465 * ITfThreadMgrEventSink
466 **********************************************************************/
467 typedef struct tagThreadMgrEventSink
469 ITfThreadMgrEventSink ITfThreadMgrEventSink_iface
;
471 } ThreadMgrEventSink
;
473 static inline ThreadMgrEventSink
*impl_from_ITfThreadMgrEventSink(ITfThreadMgrEventSink
*iface
)
475 return CONTAINING_RECORD(iface
, ThreadMgrEventSink
, ITfThreadMgrEventSink_iface
);
478 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink
*This
)
480 HeapFree(GetProcessHeap(),0,This
);
483 static HRESULT WINAPI
ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink
*iface
, REFIID iid
, LPVOID
*ppvOut
)
485 ThreadMgrEventSink
*This
= impl_from_ITfThreadMgrEventSink(iface
);
488 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfThreadMgrEventSink
))
495 ITfThreadMgrEventSink_AddRef(iface
);
499 return E_NOINTERFACE
;
502 static ULONG WINAPI
ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink
*iface
)
504 ThreadMgrEventSink
*This
= impl_from_ITfThreadMgrEventSink(iface
);
505 ok (tmSinkRefCount
== This
->refCount
,"ThreadMgrEventSink refcount off %i vs %i\n",This
->refCount
,tmSinkRefCount
);
506 return InterlockedIncrement(&This
->refCount
);
509 static ULONG WINAPI
ThreadMgrEventSink_Release(ITfThreadMgrEventSink
*iface
)
511 ThreadMgrEventSink
*This
= impl_from_ITfThreadMgrEventSink(iface
);
514 ok (tmSinkRefCount
== This
->refCount
,"ThreadMgrEventSink refcount off %i vs %i\n",This
->refCount
,tmSinkRefCount
);
515 ret
= InterlockedDecrement(&This
->refCount
);
517 ThreadMgrEventSink_Destructor(This
);
521 static HRESULT WINAPI
ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink
*iface
,
522 ITfDocumentMgr
*pdim
)
524 sink_fire_ok(&test_OnInitDocumentMgr
,"ThreadMgrEventSink_OnInitDocumentMgr");
528 static HRESULT WINAPI
ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink
*iface
,
529 ITfDocumentMgr
*pdim
)
535 static HRESULT WINAPI
ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink
*iface
,
536 ITfDocumentMgr
*pdimFocus
, ITfDocumentMgr
*pdimPrevFocus
)
538 sink_fire_ok(&test_OnSetFocus
,"ThreadMgrEventSink_OnSetFocus");
539 if (test_CurrentFocus
== FOCUS_SAVE
)
540 test_LastCurrentFocus
= pdimFocus
;
541 else if (test_CurrentFocus
!= FOCUS_IGNORE
)
542 ok(pdimFocus
== test_CurrentFocus
,"Sink reports wrong focus\n");
543 if (test_PrevFocus
== FOCUS_SAVE
)
545 if (test_FirstPrevFocus
== FOCUS_SAVE
)
546 test_FirstPrevFocus
= pdimPrevFocus
;
548 else if (test_PrevFocus
!= FOCUS_IGNORE
)
549 ok(pdimPrevFocus
== test_PrevFocus
,"Sink reports wrong previous focus\n");
553 static HRESULT WINAPI
ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink
*iface
,
557 ITfDocumentMgr
*docmgr
;
560 hr
= ITfContext_GetDocumentMgr(pic
,&docmgr
);
561 ok(SUCCEEDED(hr
),"GetDocumentMgr failed\n");
562 test
= (ITfContext
*)0xdeadbeef;
563 ITfDocumentMgr_Release(docmgr
);
564 hr
= ITfDocumentMgr_GetTop(docmgr
,&test
);
565 ok(SUCCEEDED(hr
),"GetTop failed\n");
566 ok(test
== pic
, "Wrong context is on top\n");
568 ITfContext_Release(test
);
570 sink_fire_ok(&test_OnPushContext
,"ThreadMgrEventSink_OnPushContext");
574 static HRESULT WINAPI
ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink
*iface
,
578 ITfDocumentMgr
*docmgr
;
581 hr
= ITfContext_GetDocumentMgr(pic
,&docmgr
);
582 ok(SUCCEEDED(hr
),"GetDocumentMgr failed\n");
583 ITfDocumentMgr_Release(docmgr
);
584 test
= (ITfContext
*)0xdeadbeef;
585 hr
= ITfDocumentMgr_GetTop(docmgr
,&test
);
586 ok(SUCCEEDED(hr
),"GetTop failed\n");
587 ok(test
== pic
, "Wrong context is on top\n");
589 ITfContext_Release(test
);
591 sink_fire_ok(&test_OnPopContext
,"ThreadMgrEventSink_OnPopContext");
595 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl
=
597 ThreadMgrEventSink_QueryInterface
,
598 ThreadMgrEventSink_AddRef
,
599 ThreadMgrEventSink_Release
,
601 ThreadMgrEventSink_OnInitDocumentMgr
,
602 ThreadMgrEventSink_OnUninitDocumentMgr
,
603 ThreadMgrEventSink_OnSetFocus
,
604 ThreadMgrEventSink_OnPushContext
,
605 ThreadMgrEventSink_OnPopContext
608 static HRESULT
ThreadMgrEventSink_Constructor(IUnknown
**ppOut
)
610 ThreadMgrEventSink
*This
;
612 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ThreadMgrEventSink
));
614 return E_OUTOFMEMORY
;
616 This
->ITfThreadMgrEventSink_iface
.lpVtbl
= &ThreadMgrEventSink_ThreadMgrEventSinkVtbl
;
619 *ppOut
= (IUnknown
*)This
;
624 /********************************************************************************************
625 * Stub text service for testing
626 ********************************************************************************************/
628 static LONG TS_refCount
;
629 static IClassFactory
*cf
;
632 typedef HRESULT (*LPFNCONSTRUCTOR
)(IUnknown
*pUnkOuter
, IUnknown
**ppvOut
);
634 typedef struct tagClassFactory
636 IClassFactory IClassFactory_iface
;
638 LPFNCONSTRUCTOR ctor
;
641 static inline ClassFactory
*impl_from_IClassFactory(IClassFactory
*iface
)
643 return CONTAINING_RECORD(iface
, ClassFactory
, IClassFactory_iface
);
646 typedef struct tagTextService
648 ITfTextInputProcessor ITfTextInputProcessor_iface
;
652 static inline TextService
*impl_from_ITfTextInputProcessor(ITfTextInputProcessor
*iface
)
654 return CONTAINING_RECORD(iface
, TextService
, ITfTextInputProcessor_iface
);
657 static void ClassFactory_Destructor(ClassFactory
*This
)
659 HeapFree(GetProcessHeap(),0,This
);
663 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppvOut
)
666 if (IsEqualIID(riid
, &IID_IClassFactory
) || IsEqualIID(riid
, &IID_IUnknown
))
668 IClassFactory_AddRef(iface
);
673 return E_NOINTERFACE
;
676 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
678 ClassFactory
*This
= impl_from_IClassFactory(iface
);
679 return InterlockedIncrement(&This
->ref
);
682 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
684 ClassFactory
*This
= impl_from_IClassFactory(iface
);
685 ULONG ret
= InterlockedDecrement(&This
->ref
);
688 ClassFactory_Destructor(This
);
692 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*punkOuter
, REFIID iid
, LPVOID
*ppvOut
)
694 ClassFactory
*This
= impl_from_IClassFactory(iface
);
698 ret
= This
->ctor(punkOuter
, &obj
);
701 ret
= IUnknown_QueryInterface(obj
, iid
, ppvOut
);
702 IUnknown_Release(obj
);
706 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
709 InterlockedIncrement(&TS_refCount
);
711 InterlockedDecrement(&TS_refCount
);
716 static const IClassFactoryVtbl ClassFactoryVtbl
= {
718 ClassFactory_QueryInterface
,
720 ClassFactory_Release
,
723 ClassFactory_CreateInstance
,
724 ClassFactory_LockServer
727 static HRESULT
ClassFactory_Constructor(LPFNCONSTRUCTOR ctor
, LPVOID
*ppvOut
)
729 ClassFactory
*This
= HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory
));
730 This
->IClassFactory_iface
.lpVtbl
= &ClassFactoryVtbl
;
733 *ppvOut
= (LPVOID
)This
;
738 static void TextService_Destructor(TextService
*This
)
740 HeapFree(GetProcessHeap(),0,This
);
743 static HRESULT WINAPI
TextService_QueryInterface(ITfTextInputProcessor
*iface
, REFIID iid
, LPVOID
*ppvOut
)
745 TextService
*This
= impl_from_ITfTextInputProcessor(iface
);
748 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfTextInputProcessor
))
755 ITfTextInputProcessor_AddRef(iface
);
759 return E_NOINTERFACE
;
762 static ULONG WINAPI
TextService_AddRef(ITfTextInputProcessor
*iface
)
764 TextService
*This
= impl_from_ITfTextInputProcessor(iface
);
765 return InterlockedIncrement(&This
->refCount
);
768 static ULONG WINAPI
TextService_Release(ITfTextInputProcessor
*iface
)
770 TextService
*This
= impl_from_ITfTextInputProcessor(iface
);
773 ret
= InterlockedDecrement(&This
->refCount
);
775 TextService_Destructor(This
);
779 static HRESULT WINAPI
TextService_Activate(ITfTextInputProcessor
*iface
,
780 ITfThreadMgr
*ptim
, TfClientId id
)
782 trace("TextService_Activate\n");
783 ok(test_ShouldActivate
,"Activation came unexpectedly\n");
788 static HRESULT WINAPI
TextService_Deactivate(ITfTextInputProcessor
*iface
)
790 trace("TextService_Deactivate\n");
791 ok(test_ShouldDeactivate
,"Deactivation came unexpectedly\n");
795 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl
=
797 TextService_QueryInterface
,
801 TextService_Activate
,
802 TextService_Deactivate
805 static HRESULT
TextService_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
809 return CLASS_E_NOAGGREGATION
;
811 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextService
));
813 return E_OUTOFMEMORY
;
815 This
->ITfTextInputProcessor_iface
.lpVtbl
= &TextService_TextInputProcessorVtbl
;
818 *ppOut
= (IUnknown
*)This
;
822 static HRESULT
RegisterTextService(REFCLSID rclsid
)
824 ClassFactory_Constructor( TextService_Constructor
,(LPVOID
*)&cf
);
825 return CoRegisterClassObject(rclsid
, (IUnknown
*) cf
, CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
828 static HRESULT
UnregisterTextService(void)
830 return CoRevokeClassObject(regid
);
837 DEFINE_GUID(CLSID_FakeService
, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
838 DEFINE_GUID(CLSID_TF_InputProcessorProfiles
, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
839 DEFINE_GUID(CLSID_TF_CategoryMgr
, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
840 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD
, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
841 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH
, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
842 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING
, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
843 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
844 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
845 DEFINE_GUID(CLSID_TF_ThreadMgr
, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
846 DEFINE_GUID(CLSID_PreservedKey
, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
847 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_DISABLED
, 0x71a5b253,0x1951,0x466b,0x9f,0xbc,0x9c,0x88,0x08,0xfa,0x84,0xf2);
848 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE
, 0x58273aad,0x01bb,0x4164,0x95,0xc6,0x75,0x5b,0xa0,0xb5,0x16,0x2d);
849 DEFINE_GUID(GUID_COMPARTMENT_HANDWRITING_OPENCLOSE
, 0xf9ae2c6b,0x1866,0x4361,0xaf,0x72,0x7a,0xa3,0x09,0x48,0x89,0x0e);
850 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_DISABLED
, 0x56c5c607,0x0703,0x4e59,0x8e,0x52,0xcb,0xc8,0x4e,0x8b,0xbe,0x35);
851 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE
, 0x544d6a63,0xe2e8,0x4752,0xbb,0xd1,0x00,0x09,0x60,0xbc,0xa0,0x83);
852 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_GLOBALSTATE
, 0x2a54fe8e,0x0d08,0x460c,0xa7,0x5d,0x87,0x03,0x5f,0xf4,0x36,0xc5);
853 DEFINE_GUID(GUID_COMPARTMENT_PERSISTMENUENABLED
, 0x575f3783,0x70c8,0x47c8,0xae,0x5d,0x91,0xa0,0x1a,0x1f,0x75,0x92);
854 DEFINE_GUID(GUID_COMPARTMENT_EMPTYCONTEXT
, 0xd7487dbf,0x804e,0x41c5,0x89,0x4d,0xad,0x96,0xfd,0x4e,0xea,0x13);
855 DEFINE_GUID(GUID_COMPARTMENT_TIPUISTATUS
, 0x148ca3ec,0x0366,0x401c,0x8d,0x75,0xed,0x97,0x8d,0x85,0xfb,0xc9);
857 static HRESULT
initialize(void)
861 hr
= CoCreateInstance (&CLSID_TF_InputProcessorProfiles
, NULL
,
862 CLSCTX_INPROC_SERVER
, &IID_ITfInputProcessorProfiles
, (void**)&g_ipp
);
864 hr
= CoCreateInstance (&CLSID_TF_CategoryMgr
, NULL
,
865 CLSCTX_INPROC_SERVER
, &IID_ITfCategoryMgr
, (void**)&g_cm
);
867 hr
= CoCreateInstance (&CLSID_TF_ThreadMgr
, NULL
,
868 CLSCTX_INPROC_SERVER
, &IID_ITfThreadMgr
, (void**)&g_tm
);
872 static void cleanup(void)
875 ITfInputProcessorProfiles_Release(g_ipp
);
877 ITfCategoryMgr_Release(g_cm
);
879 ITfThreadMgr_Release(g_tm
);
883 static void test_Register(void)
887 static const WCHAR szDesc
[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
888 static const WCHAR szFile
[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
890 hr
= ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp
,&gLangid
);
891 ok(SUCCEEDED(hr
),"Unable to get current language id\n");
892 trace("Current Language %x\n",gLangid
);
894 hr
= RegisterTextService(&CLSID_FakeService
);
895 ok(SUCCEEDED(hr
),"Unable to register COM for TextService\n");
896 hr
= ITfInputProcessorProfiles_Register(g_ipp
, &CLSID_FakeService
);
897 ok(SUCCEEDED(hr
),"Unable to register text service(%x)\n",hr
);
898 hr
= ITfInputProcessorProfiles_AddLanguageProfile(g_ipp
, &CLSID_FakeService
, gLangid
, &CLSID_FakeService
, szDesc
, sizeof(szDesc
)/sizeof(WCHAR
), szFile
, sizeof(szFile
)/sizeof(WCHAR
), 1);
899 ok(SUCCEEDED(hr
),"Unable to add Language Profile (%x)\n",hr
);
902 static void test_Unregister(void)
905 hr
= ITfInputProcessorProfiles_Unregister(g_ipp
, &CLSID_FakeService
);
906 ok(SUCCEEDED(hr
),"Unable to unregister text service(%x)\n",hr
);
907 UnregisterTextService();
910 static void test_EnumInputProcessorInfo(void)
915 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp
, &ppEnum
)))
919 while (IEnumGUID_Next(ppEnum
, 1, &g
, &fetched
) == S_OK
)
921 if(IsEqualGUID(&g
,&CLSID_FakeService
))
925 ok(found
,"Did not find registered text service\n");
928 static void test_EnumLanguageProfiles(void)
931 IEnumTfLanguageProfiles
*ppEnum
;
932 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp
,gLangid
,&ppEnum
)))
934 TF_LANGUAGEPROFILE profile
;
935 while (IEnumTfLanguageProfiles_Next(ppEnum
,1,&profile
,NULL
)==S_OK
)
937 if (IsEqualGUID(&profile
.clsid
,&CLSID_FakeService
))
940 ok(profile
.langid
== gLangid
, "LangId Incorrect\n");
941 ok(IsEqualGUID(&profile
.catid
,&GUID_TFCAT_TIP_KEYBOARD
) ||
942 broken(IsEqualGUID(&profile
.catid
,&GUID_NULL
) /* Win8 */), "CatId Incorrect\n");
943 ok(IsEqualGUID(&profile
.guidProfile
,&CLSID_FakeService
), "guidProfile Incorrect\n");
947 ok(found
,"Registered text service not found\n");
950 static void test_RegisterCategory(void)
953 hr
= ITfCategoryMgr_RegisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_TIP_KEYBOARD
, &CLSID_FakeService
);
954 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterCategory failed\n");
955 hr
= ITfCategoryMgr_RegisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, &CLSID_FakeService
);
956 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterCategory failed\n");
959 static void test_UnregisterCategory(void)
962 hr
= ITfCategoryMgr_UnregisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_TIP_KEYBOARD
, &CLSID_FakeService
);
963 ok(SUCCEEDED(hr
),"ITfCategoryMgr_UnregisterCategory failed\n");
964 hr
= ITfCategoryMgr_UnregisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, &CLSID_FakeService
);
965 ok(SUCCEEDED(hr
),"ITfCategoryMgr_UnregisterCategory failed\n");
968 static void test_FindClosestCategory(void)
972 const GUID
*list
[3] = {&GUID_TFCAT_TIP_SPEECH
, &GUID_TFCAT_TIP_KEYBOARD
, &GUID_TFCAT_TIP_HANDWRITING
};
974 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, NULL
, 0);
975 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
976 ok(IsEqualGUID(&output
,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
),"Wrong GUID\n");
978 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, list
, 1);
979 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
980 ok(IsEqualGUID(&output
,&GUID_NULL
),"Wrong GUID\n");
982 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, list
, 3);
983 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
984 ok(IsEqualGUID(&output
,&GUID_TFCAT_TIP_KEYBOARD
),"Wrong GUID\n");
987 static void test_Enable(void)
990 BOOL enabled
= FALSE
;
992 hr
= ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, TRUE
);
993 ok(SUCCEEDED(hr
),"Failed to enable text service\n");
994 hr
= ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, &enabled
);
995 ok(SUCCEEDED(hr
),"Failed to get enabled state\n");
996 ok(enabled
== TRUE
,"enabled state incorrect\n");
999 static void test_Disable(void)
1003 trace("Disabling\n");
1004 hr
= ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, FALSE
);
1005 ok(SUCCEEDED(hr
),"Failed to disable text service\n");
1008 static void test_ThreadMgrAdviseSinks(void)
1010 ITfSource
*source
= NULL
;
1014 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfSource
, (LPVOID
*)&source
);
1015 ok(SUCCEEDED(hr
),"Failed to get IID_ITfSource for ThreadMgr\n");
1019 hr
= ThreadMgrEventSink_Constructor(&sink
);
1020 ok(hr
== S_OK
, "got %08x\n", hr
);
1021 if(FAILED(hr
)) return;
1025 hr
= ITfSource_AdviseSink(source
,&IID_ITfThreadMgrEventSink
, sink
, &tmSinkCookie
);
1026 ok(SUCCEEDED(hr
),"Failed to Advise Sink\n");
1027 ok(tmSinkCookie
!=0,"Failed to get sink cookie\n");
1029 /* Advising the sink adds a ref, Releasing here lets the object be deleted
1032 IUnknown_Release(sink
);
1033 ITfSource_Release(source
);
1036 static void test_ThreadMgrUnadviseSinks(void)
1038 ITfSource
*source
= NULL
;
1041 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfSource
, (LPVOID
*)&source
);
1042 ok(SUCCEEDED(hr
),"Failed to get IID_ITfSource for ThreadMgr\n");
1047 hr
= ITfSource_UnadviseSink(source
, tmSinkCookie
);
1048 ok(SUCCEEDED(hr
),"Failed to unadvise Sink\n");
1049 ITfSource_Release(source
);
1052 /**********************************************************************
1054 **********************************************************************/
1055 typedef struct tagKeyEventSink
1057 ITfKeyEventSink ITfKeyEventSink_iface
;
1061 static inline KeyEventSink
*impl_from_ITfKeyEventSink(ITfKeyEventSink
*iface
)
1063 return CONTAINING_RECORD(iface
, KeyEventSink
, ITfKeyEventSink_iface
);
1066 static void KeyEventSink_Destructor(KeyEventSink
*This
)
1068 HeapFree(GetProcessHeap(),0,This
);
1071 static HRESULT WINAPI
KeyEventSink_QueryInterface(ITfKeyEventSink
*iface
, REFIID iid
, LPVOID
*ppvOut
)
1073 KeyEventSink
*This
= impl_from_ITfKeyEventSink(iface
);
1076 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfKeyEventSink
))
1083 ITfKeyEventSink_AddRef(iface
);
1087 return E_NOINTERFACE
;
1090 static ULONG WINAPI
KeyEventSink_AddRef(ITfKeyEventSink
*iface
)
1092 KeyEventSink
*This
= impl_from_ITfKeyEventSink(iface
);
1093 return InterlockedIncrement(&This
->refCount
);
1096 static ULONG WINAPI
KeyEventSink_Release(ITfKeyEventSink
*iface
)
1098 KeyEventSink
*This
= impl_from_ITfKeyEventSink(iface
);
1101 ret
= InterlockedDecrement(&This
->refCount
);
1103 KeyEventSink_Destructor(This
);
1107 static HRESULT WINAPI
KeyEventSink_OnSetFocus(ITfKeyEventSink
*iface
,
1110 sink_fire_ok(&test_KEV_OnSetFocus
,"KeyEventSink_OnSetFocus");
1114 static HRESULT WINAPI
KeyEventSink_OnTestKeyDown(ITfKeyEventSink
*iface
,
1115 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1121 static HRESULT WINAPI
KeyEventSink_OnTestKeyUp(ITfKeyEventSink
*iface
,
1122 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1128 static HRESULT WINAPI
KeyEventSink_OnKeyDown(ITfKeyEventSink
*iface
,
1129 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1135 static HRESULT WINAPI
KeyEventSink_OnKeyUp(ITfKeyEventSink
*iface
,
1136 ITfContext
*pic
, WPARAM wParam
, LPARAM lParam
, BOOL
*pfEaten
)
1142 static HRESULT WINAPI
KeyEventSink_OnPreservedKey(ITfKeyEventSink
*iface
,
1143 ITfContext
*pic
, REFGUID rguid
, BOOL
*pfEaten
)
1149 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl
=
1151 KeyEventSink_QueryInterface
,
1152 KeyEventSink_AddRef
,
1153 KeyEventSink_Release
,
1155 KeyEventSink_OnSetFocus
,
1156 KeyEventSink_OnTestKeyDown
,
1157 KeyEventSink_OnTestKeyUp
,
1158 KeyEventSink_OnKeyDown
,
1159 KeyEventSink_OnKeyUp
,
1160 KeyEventSink_OnPreservedKey
1163 static HRESULT
KeyEventSink_Constructor(ITfKeyEventSink
**ppOut
)
1167 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(KeyEventSink
));
1169 return E_OUTOFMEMORY
;
1171 This
->ITfKeyEventSink_iface
.lpVtbl
= &KeyEventSink_KeyEventSinkVtbl
;
1174 *ppOut
= &This
->ITfKeyEventSink_iface
;
1179 static void test_KeystrokeMgr(void)
1181 ITfKeystrokeMgr
*keymgr
= NULL
;
1183 TF_PRESERVEDKEY tfpk
;
1185 ITfKeyEventSink
*sink
= NULL
;
1187 KeyEventSink_Constructor(&sink
);
1189 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfKeystrokeMgr
, (LPVOID
*)&keymgr
);
1190 ok(SUCCEEDED(hr
),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1193 tfpk
.uModifiers
= TF_MOD_SHIFT
;
1195 test_KEV_OnSetFocus
= SINK_EXPECTED
;
1196 hr
= ITfKeystrokeMgr_AdviseKeyEventSink(keymgr
,tid
,sink
,TRUE
);
1197 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1198 sink_check_ok(&test_KEV_OnSetFocus
,"KeyEventSink_OnSetFocus");
1199 hr
= ITfKeystrokeMgr_AdviseKeyEventSink(keymgr
,tid
,sink
,TRUE
);
1200 ok(hr
== CONNECT_E_ADVISELIMIT
,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1201 hr
= ITfKeystrokeMgr_AdviseKeyEventSink(keymgr
,cid
,sink
,TRUE
);
1202 ok(hr
== E_INVALIDARG
,"Wrong return, expected E_INVALIDARG\n");
1204 hr
=ITfKeystrokeMgr_PreserveKey(keymgr
, 0, &CLSID_PreservedKey
, &tfpk
, NULL
, 0);
1205 ok(hr
==E_INVALIDARG
,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1207 hr
=ITfKeystrokeMgr_PreserveKey(keymgr
, tid
, &CLSID_PreservedKey
, &tfpk
, NULL
, 0);
1208 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_PreserveKey failed\n");
1210 hr
=ITfKeystrokeMgr_PreserveKey(keymgr
, tid
, &CLSID_PreservedKey
, &tfpk
, NULL
, 0);
1211 ok(hr
== TF_E_ALREADY_EXISTS
,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1214 hr
= ITfKeystrokeMgr_IsPreservedKey(keymgr
, &CLSID_PreservedKey
, &tfpk
, &preserved
);
1215 ok(hr
== S_OK
, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1216 if (hr
== S_OK
) ok(preserved
== TRUE
,"misreporting preserved key\n");
1218 hr
= ITfKeystrokeMgr_UnpreserveKey(keymgr
, &CLSID_PreservedKey
,&tfpk
);
1219 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1221 hr
= ITfKeystrokeMgr_IsPreservedKey(keymgr
, &CLSID_PreservedKey
, &tfpk
, &preserved
);
1222 ok(hr
== S_FALSE
, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1223 if (hr
== S_FALSE
) ok(preserved
== FALSE
,"misreporting preserved key\n");
1225 hr
= ITfKeystrokeMgr_UnpreserveKey(keymgr
, &CLSID_PreservedKey
,&tfpk
);
1226 ok(hr
==CONNECT_E_NOCONNECTION
,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1228 hr
= ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr
,tid
);
1229 ok(SUCCEEDED(hr
),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1231 ITfKeystrokeMgr_Release(keymgr
);
1232 ITfKeyEventSink_Release(sink
);
1235 static void test_Activate(void)
1239 test_ShouldActivate
= TRUE
; /* Win7 */
1240 hr
= ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp
,&CLSID_FakeService
,gLangid
,&CLSID_FakeService
);
1241 ok(SUCCEEDED(hr
),"Failed to Activate text service\n");
1242 test_ShouldActivate
= FALSE
;
1246 static void test_EnumContexts(ITfDocumentMgr
*dm
, ITfContext
*search
)
1249 IEnumTfContexts
* pEnum
;
1252 hr
= ITfDocumentMgr_EnumContexts(dm
,&pEnum
);
1253 ok(SUCCEEDED(hr
),"EnumContexts failed\n");
1258 while (IEnumTfContexts_Next(pEnum
, 1, &cxt
, &fetched
) == S_OK
)
1262 else if (search
== cxt
)
1264 ITfContext_Release(cxt
);
1266 IEnumTfContexts_Release(pEnum
);
1269 ok(found
,"Did not find proper ITfContext\n");
1271 ok(!found
,"Found an ITfContext we should should not have\n");
1274 static void test_EnumDocumentMgr(ITfThreadMgr
*tm
, ITfDocumentMgr
*search
, ITfDocumentMgr
*absent
)
1277 IEnumTfDocumentMgrs
* pEnum
;
1279 BOOL notfound
= TRUE
;
1281 hr
= ITfThreadMgr_EnumDocumentMgrs(tm
,&pEnum
);
1282 ok(SUCCEEDED(hr
),"EnumDocumentMgrs failed\n");
1287 while (IEnumTfDocumentMgrs_Next(pEnum
, 1, &dm
, &fetched
) == S_OK
)
1291 else if (search
== dm
)
1293 if (absent
&& dm
== absent
)
1295 ITfDocumentMgr_Release(dm
);
1297 IEnumTfDocumentMgrs_Release(pEnum
);
1300 ok(found
,"Did not find proper ITfDocumentMgr\n");
1302 ok(!found
,"Found an ITfDocumentMgr we should should not have\n");
1304 ok(notfound
,"Found an ITfDocumentMgr we believe should be absent\n");
1307 static inline int check_context_refcount(ITfContext
*iface
)
1309 ITfContext_AddRef(iface
);
1310 return ITfContext_Release(iface
);
1314 /**********************************************************************
1316 **********************************************************************/
1317 typedef struct tagTextEditSink
1319 ITfTextEditSink ITfTextEditSink_iface
;
1323 static inline TextEditSink
*impl_from_ITfTextEditSink(ITfTextEditSink
*iface
)
1325 return CONTAINING_RECORD(iface
, TextEditSink
, ITfTextEditSink_iface
);
1328 static void TextEditSink_Destructor(TextEditSink
*This
)
1330 HeapFree(GetProcessHeap(),0,This
);
1333 static HRESULT WINAPI
TextEditSink_QueryInterface(ITfTextEditSink
*iface
, REFIID iid
, LPVOID
*ppvOut
)
1335 TextEditSink
*This
= impl_from_ITfTextEditSink(iface
);
1338 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfTextEditSink
))
1345 ITfTextEditSink_AddRef(iface
);
1349 return E_NOINTERFACE
;
1352 static ULONG WINAPI
TextEditSink_AddRef(ITfTextEditSink
*iface
)
1354 TextEditSink
*This
= impl_from_ITfTextEditSink(iface
);
1355 return InterlockedIncrement(&This
->refCount
);
1358 static ULONG WINAPI
TextEditSink_Release(ITfTextEditSink
*iface
)
1360 TextEditSink
*This
= impl_from_ITfTextEditSink(iface
);
1363 ret
= InterlockedDecrement(&This
->refCount
);
1365 TextEditSink_Destructor(This
);
1369 static HRESULT WINAPI
TextEditSink_OnEndEdit(ITfTextEditSink
*iface
,
1370 ITfContext
*pic
, TfEditCookie ecReadOnly
, ITfEditRecord
*pEditRecord
)
1372 sink_fire_ok(&test_OnEndEdit
,"TextEditSink_OnEndEdit");
1376 static const ITfTextEditSinkVtbl TextEditSink_TextEditSinkVtbl
=
1378 TextEditSink_QueryInterface
,
1379 TextEditSink_AddRef
,
1380 TextEditSink_Release
,
1382 TextEditSink_OnEndEdit
1385 static HRESULT
TextEditSink_Constructor(ITfTextEditSink
**ppOut
)
1390 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextEditSink
));
1392 return E_OUTOFMEMORY
;
1394 This
->ITfTextEditSink_iface
.lpVtbl
= &TextEditSink_TextEditSinkVtbl
;
1397 *ppOut
= &This
->ITfTextEditSink_iface
;
1401 static void test_startSession(void)
1406 ITfDocumentMgr
*dmtest
;
1407 ITfContext
*cxt
,*cxt2
,*cxt3
,*cxtTest
;
1409 TfClientId cid2
= 0;
1411 hr
= ITfThreadMgr_Deactivate(g_tm
);
1412 ok(hr
== E_UNEXPECTED
,"Deactivate should have failed with E_UNEXPECTED\n");
1414 test_ShouldActivate
= TRUE
;
1415 hr
= ITfThreadMgr_Activate(g_tm
,&cid
);
1416 ok(SUCCEEDED(hr
),"Failed to Activate\n");
1417 ok(cid
!= tid
,"TextService id mistakenly matches Client id\n");
1419 test_ShouldActivate
= FALSE
;
1420 hr
= ITfThreadMgr_Activate(g_tm
,&cid2
);
1421 ok(SUCCEEDED(hr
),"Failed to Activate\n");
1422 ok (cid
== cid2
, "Second activate client ID does not match\n");
1424 hr
= ITfThreadMgr_Deactivate(g_tm
);
1425 ok(SUCCEEDED(hr
),"Failed to Deactivate\n");
1427 test_EnumDocumentMgr(g_tm
,NULL
,NULL
);
1429 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&g_dm
);
1430 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
1432 test_EnumDocumentMgr(g_tm
,g_dm
,NULL
);
1434 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&dmtest
);
1435 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
1437 test_EnumDocumentMgr(g_tm
,dmtest
,NULL
);
1439 ITfDocumentMgr_Release(dmtest
);
1440 test_EnumDocumentMgr(g_tm
,g_dm
,dmtest
);
1442 hr
= ITfThreadMgr_GetFocus(g_tm
,&dmtest
);
1443 ok(SUCCEEDED(hr
),"GetFocus Failed\n");
1444 ok(dmtest
== NULL
,"Initial focus not null\n");
1446 test_CurrentFocus
= g_dm
;
1447 test_PrevFocus
= NULL
;
1448 test_OnSetFocus
= SINK_OPTIONAL
; /* Doesn't always fire on Win7 */
1449 hr
= ITfThreadMgr_SetFocus(g_tm
,g_dm
);
1450 ok(SUCCEEDED(hr
),"SetFocus Failed\n");
1451 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
1453 hr
= ITfThreadMgr_GetFocus(g_tm
,&dmtest
);
1454 ok(SUCCEEDED(hr
),"GetFocus Failed\n");
1455 ok(g_dm
== dmtest
,"Expected DocumentMgr not focused\n");
1457 ITfDocumentMgr_Release(g_dm
);
1459 hr
= ITfThreadMgr_GetFocus(g_tm
,&dmtest
);
1460 ok(SUCCEEDED(hr
),"GetFocus Failed\n");
1461 ok(g_dm
== dmtest
,"Expected DocumentMgr not focused\n");
1462 ITfDocumentMgr_Release(dmtest
);
1464 hr
= TextStoreACP_Constructor((IUnknown
**)&ts
);
1467 hr
= ITfDocumentMgr_CreateContext(g_dm
, cid
, 0, (IUnknown
*)ts
, &cxt
, &editCookie
);
1468 ok(SUCCEEDED(hr
),"CreateContext Failed\n");
1471 hr
= ITfDocumentMgr_CreateContext(g_dm
, cid
, 0, NULL
, &cxt2
, &editCookie
);
1472 ok(SUCCEEDED(hr
),"CreateContext Failed\n");
1474 hr
= ITfDocumentMgr_CreateContext(g_dm
, cid
, 0, NULL
, &cxt3
, &editCookie
);
1475 ok(SUCCEEDED(hr
),"CreateContext Failed\n");
1477 test_EnumContexts(g_dm
, NULL
);
1479 hr
= ITfContext_GetDocumentMgr(cxt
,&dmtest
);
1480 ok(hr
== S_OK
, "ITfContext_GetDocumentMgr failed with %x\n",hr
);
1481 ok(dmtest
== g_dm
, "Wrong documentmgr\n");
1482 ITfDocumentMgr_Release(dmtest
);
1484 cnt
= check_context_refcount(cxt
);
1485 test_OnPushContext
= SINK_EXPECTED
;
1486 test_ACP_AdviseSink
= SINK_EXPECTED
;
1487 test_OnInitDocumentMgr
= SINK_EXPECTED
;
1488 hr
= ITfDocumentMgr_Push(g_dm
, cxt
);
1489 ok(SUCCEEDED(hr
),"Push Failed\n");
1490 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1491 sink_check_ok(&test_OnPushContext
,"OnPushContext");
1492 sink_check_ok(&test_OnInitDocumentMgr
,"OnInitDocumentMgr");
1493 sink_check_ok(&test_ACP_AdviseSink
,"TextStoreACP_AdviseSink");
1495 test_EnumContexts(g_dm
, cxt
);
1497 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1498 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1499 ok(cxtTest
== cxt
, "Wrong context on top\n");
1500 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1501 cnt
= ITfContext_Release(cxtTest
);
1503 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1504 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1505 ok(cxtTest
== cxt
, "Wrong context on Base\n");
1506 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1507 ITfContext_Release(cxtTest
);
1509 check_context_refcount(cxt2
);
1510 test_OnPushContext
= SINK_EXPECTED
;
1511 hr
= ITfDocumentMgr_Push(g_dm
, cxt2
);
1512 ok(SUCCEEDED(hr
),"Push Failed\n");
1513 sink_check_ok(&test_OnPushContext
,"OnPushContext");
1515 cnt
= check_context_refcount(cxt2
);
1516 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1517 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1518 ok(cxtTest
== cxt2
, "Wrong context on top\n");
1519 ok(check_context_refcount(cxt2
) > cnt
, "Ref count did not increase\n");
1520 ITfContext_Release(cxtTest
);
1522 cnt
= check_context_refcount(cxt
);
1523 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1524 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1525 ok(cxtTest
== cxt
, "Wrong context on Base\n");
1526 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1527 ITfContext_Release(cxtTest
);
1529 cnt
= check_context_refcount(cxt3
);
1530 hr
= ITfDocumentMgr_Push(g_dm
, cxt3
);
1531 ok(FAILED(hr
),"Push Succeeded\n");
1532 ok(check_context_refcount(cxt3
) == cnt
, "Ref changed\n");
1534 cnt
= check_context_refcount(cxt2
);
1535 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1536 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1537 ok(cxtTest
== cxt2
, "Wrong context on top\n");
1538 ok(check_context_refcount(cxt2
) > cnt
, "Ref count did not increase\n");
1539 ITfContext_Release(cxtTest
);
1541 cnt
= check_context_refcount(cxt
);
1542 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1543 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1544 ok(cxtTest
== cxt
, "Wrong context on Base\n");
1545 ok(check_context_refcount(cxt
) > cnt
, "Ref count did not increase\n");
1546 ITfContext_Release(cxtTest
);
1548 cnt
= check_context_refcount(cxt2
);
1549 test_OnPopContext
= SINK_EXPECTED
;
1550 hr
= ITfDocumentMgr_Pop(g_dm
, 0);
1551 ok(SUCCEEDED(hr
),"Pop Failed\n");
1552 ok(check_context_refcount(cxt2
) < cnt
, "Ref count did not decrease\n");
1553 sink_check_ok(&test_OnPopContext
,"OnPopContext");
1555 dmtest
= (void *)0xfeedface;
1556 hr
= ITfContext_GetDocumentMgr(cxt2
,&dmtest
);
1557 ok(hr
== S_FALSE
, "ITfContext_GetDocumentMgr wrong rc %x\n",hr
);
1558 ok(dmtest
== NULL
,"returned documentmgr should be null\n");
1560 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1561 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1562 ok(cxtTest
== cxt
, "Wrong context on top\n");
1563 ITfContext_Release(cxtTest
);
1565 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1566 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1567 ok(cxtTest
== cxt
, "Wrong context on base\n");
1568 ITfContext_Release(cxtTest
);
1570 hr
= ITfDocumentMgr_Pop(g_dm
, 0);
1571 ok(FAILED(hr
),"Pop Succeeded\n");
1573 hr
= ITfDocumentMgr_GetTop(g_dm
, &cxtTest
);
1574 ok(SUCCEEDED(hr
),"GetTop Failed\n");
1575 ok(cxtTest
== cxt
, "Wrong context on top\n");
1576 ITfContext_Release(cxtTest
);
1578 hr
= ITfDocumentMgr_GetBase(g_dm
, &cxtTest
);
1579 ok(SUCCEEDED(hr
),"GetBase Failed\n");
1580 ok(cxtTest
== cxt
, "Wrong context on base\n");
1581 ITfContext_Release(cxtTest
);
1583 ITfContext_Release(cxt
);
1584 ITfContext_Release(cxt2
);
1585 ITfContext_Release(cxt3
);
1588 static void test_endSession(void)
1591 test_ShouldDeactivate
= TRUE
;
1592 test_CurrentFocus
= NULL
;
1593 test_PrevFocus
= g_dm
;
1594 test_OnSetFocus
= SINK_OPTIONAL
; /* Doesn't fire on Win7 */
1595 hr
= ITfThreadMgr_Deactivate(g_tm
);
1596 ok(SUCCEEDED(hr
),"Failed to Deactivate\n");
1597 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
1598 test_OnSetFocus
= SINK_UNEXPECTED
;
1601 static void test_TfGuidAtom(void)
1605 TfGuidAtom atom1
,atom2
;
1608 CoCreateGuid(>est
);
1610 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1612 hr = ITfCategoryMgr_RegisterGUID(g_cm,>est,NULL);
1613 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1615 hr
= ITfCategoryMgr_RegisterGUID(g_cm
,>est
,&atom1
);
1616 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterGUID failed\n");
1617 hr
= ITfCategoryMgr_RegisterGUID(g_cm
,>est
,&atom2
);
1618 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterGUID failed\n");
1619 ok(atom1
== atom2
,"atoms do not match\n");
1620 hr
= ITfCategoryMgr_GetGUID(g_cm
,atom2
,NULL
);
1621 ok(hr
==E_INVALIDARG
,"ITfCategoryMgr_GetGUID should have failed\n");
1622 hr
= ITfCategoryMgr_GetGUID(g_cm
,atom2
,&g1
);
1623 ok(SUCCEEDED(hr
),"ITfCategoryMgr_GetGUID failed\n");
1624 ok(IsEqualGUID(&g1
,>est
),"guids do not match\n");
1625 hr
= ITfCategoryMgr_IsEqualTfGuidAtom(g_cm
,atom1
,>est
,NULL
);
1626 ok(hr
==E_INVALIDARG
,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1627 hr
= ITfCategoryMgr_IsEqualTfGuidAtom(g_cm
,atom1
,>est
,&equal
);
1628 ok(SUCCEEDED(hr
),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1629 ok(equal
== TRUE
,"Equal value invalid\n");
1631 /* show that cid and tid TfClientIds are also TfGuidAtoms */
1632 hr
= ITfCategoryMgr_IsEqualTfGuidAtom(g_cm
,tid
,&CLSID_FakeService
,&equal
);
1633 ok(SUCCEEDED(hr
),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1634 ok(equal
== TRUE
,"Equal value invalid\n");
1635 hr
= ITfCategoryMgr_GetGUID(g_cm
,cid
,&g1
);
1636 ok(SUCCEEDED(hr
),"ITfCategoryMgr_GetGUID failed\n");
1637 ok(!IsEqualGUID(&g1
,&GUID_NULL
),"guid should not be NULL\n");
1640 static void test_ClientId(void)
1647 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfClientId
, (LPVOID
*)&pcid
);
1648 ok(SUCCEEDED(hr
),"Unable to acquire ITfClientId interface\n");
1652 hr
= ITfClientId_GetClientId(pcid
,&GUID_NULL
,&id1
);
1653 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1654 hr
= ITfClientId_GetClientId(pcid
,&GUID_NULL
,&id2
);
1655 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1656 ok(id1
==id2
,"Id's for GUID_NULL do not match\n");
1657 hr
= ITfClientId_GetClientId(pcid
,&CLSID_FakeService
,&id2
);
1658 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1659 ok(id2
!=id1
,"Id matches GUID_NULL\n");
1660 ok(id2
==tid
,"Id for CLSID_FakeService not matching tid\n");
1661 ok(id2
!=cid
,"Id for CLSID_FakeService matching cid\n");
1662 hr
= ITfClientId_GetClientId(pcid
,&g2
,&id2
);
1663 ok(SUCCEEDED(hr
),"GetClientId failed\n");
1664 ok(id2
!=id1
,"Id matches GUID_NULL\n");
1665 ok(id2
!=tid
,"Id for random guid matching tid\n");
1666 ok(id2
!=cid
,"Id for random guid matching cid\n");
1667 ITfClientId_Release(pcid
);
1670 /**********************************************************************
1672 **********************************************************************/
1673 typedef struct tagEditSession
1675 ITfEditSession ITfEditSession_iface
;
1679 static inline EditSession
*impl_from_ITfEditSession(ITfEditSession
*iface
)
1681 return CONTAINING_RECORD(iface
, EditSession
, ITfEditSession_iface
);
1684 static void EditSession_Destructor(EditSession
*This
)
1686 HeapFree(GetProcessHeap(),0,This
);
1689 static HRESULT WINAPI
EditSession_QueryInterface(ITfEditSession
*iface
, REFIID iid
, LPVOID
*ppvOut
)
1691 EditSession
*This
= impl_from_ITfEditSession(iface
);
1694 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfEditSession
))
1701 ITfEditSession_AddRef(iface
);
1705 return E_NOINTERFACE
;
1708 static ULONG WINAPI
EditSession_AddRef(ITfEditSession
*iface
)
1710 EditSession
*This
= impl_from_ITfEditSession(iface
);
1711 return InterlockedIncrement(&This
->refCount
);
1714 static ULONG WINAPI
EditSession_Release(ITfEditSession
*iface
)
1716 EditSession
*This
= impl_from_ITfEditSession(iface
);
1719 ret
= InterlockedDecrement(&This
->refCount
);
1721 EditSession_Destructor(This
);
1725 static void test_InsertAtSelection(TfEditCookie ec
, ITfContext
*cxt
)
1728 ITfInsertAtSelection
*iis
;
1729 ITfRange
*range
=NULL
;
1730 static const WCHAR txt
[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1732 hr
= ITfContext_QueryInterface(cxt
, &IID_ITfInsertAtSelection
, (LPVOID
*)&iis
);
1733 ok(SUCCEEDED(hr
),"Failed to get ITfInsertAtSelection interface\n");
1734 test_ACP_InsertTextAtSelection
= SINK_EXPECTED
;
1735 hr
= ITfInsertAtSelection_InsertTextAtSelection(iis
, ec
, 0, txt
, 11, &range
);
1736 ok(SUCCEEDED(hr
),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr
);
1737 sink_check_ok(&test_ACP_InsertTextAtSelection
,"InsertTextAtSelection");
1738 ok(range
!= NULL
,"No range returned\n");
1739 ITfRange_Release(range
);
1740 ITfInsertAtSelection_Release(iis
);
1743 static HRESULT WINAPI
EditSession_DoEditSession(ITfEditSession
*iface
,
1749 TF_SELECTION selection
;
1753 sink_fire_ok(&test_DoEditSession
,"EditSession_DoEditSession");
1754 sink_check_ok(&test_ACP_RequestLock
,"RequestLock");
1756 ITfThreadMgr_GetFocus(g_tm
, &dm
);
1757 ITfDocumentMgr_GetTop(dm
,&cxt
);
1759 hr
= ITfContext_GetStart(cxt
,ec
,NULL
);
1760 ok(hr
== E_INVALIDARG
,"Unexpected return code %x\n",hr
);
1762 range
= (ITfRange
*)0xdeaddead;
1763 hr
= ITfContext_GetStart(cxt
,0xdeadcafe,&range
);
1764 ok(hr
== TF_E_NOLOCK
,"Unexpected return code %x\n",hr
);
1765 ok(range
== NULL
,"Range not set to NULL\n");
1767 hr
= ITfContext_GetStart(cxt
,ec
,&range
);
1768 ok(SUCCEEDED(hr
),"Unexpected return code %x\n",hr
);
1769 ok(range
!= NULL
,"Range set to NULL\n");
1771 ITfRange_Release(range
);
1773 hr
= ITfContext_GetEnd(cxt
,ec
,NULL
);
1774 ok(hr
== E_INVALIDARG
,"Unexpected return code %x\n",hr
);
1776 range
= (ITfRange
*)0xdeaddead;
1777 hr
= ITfContext_GetEnd(cxt
,0xdeadcafe,&range
);
1778 ok(hr
== TF_E_NOLOCK
,"Unexpected return code %x\n",hr
);
1779 ok(range
== NULL
,"Range not set to NULL\n");
1781 test_ACP_GetEndACP
= SINK_EXPECTED
;
1782 hr
= ITfContext_GetEnd(cxt
,ec
,&range
);
1783 ok(SUCCEEDED(hr
),"Unexpected return code %x\n",hr
);
1784 ok(range
!= NULL
,"Range set to NULL\n");
1785 sink_check_ok(&test_ACP_GetEndACP
,"GetEndACP");
1787 ITfRange_Release(range
);
1789 selection
.range
= NULL
;
1790 test_ACP_GetSelection
= SINK_EXPECTED
;
1791 hr
= ITfContext_GetSelection(cxt
, ec
, TF_DEFAULT_SELECTION
, 1, &selection
, &fetched
);
1792 ok(SUCCEEDED(hr
),"ITfContext_GetSelection failed\n");
1793 ok(fetched
== 1,"fetched incorrect\n");
1794 ok(selection
.range
!= NULL
,"NULL range\n");
1795 sink_check_ok(&test_ACP_GetSelection
,"ACP_GetSepection");
1796 ITfRange_Release(selection
.range
);
1798 test_InsertAtSelection(ec
, cxt
);
1800 test_ACP_GetEndACP
= SINK_EXPECTED
;
1801 hr
= ITfContext_GetEnd(cxt
,ec
,&range
);
1802 ok(SUCCEEDED(hr
),"Unexpected return code %x\n",hr
);
1803 ok(range
!= NULL
,"Range set to NULL\n");
1804 sink_check_ok(&test_ACP_GetEndACP
,"GetEndACP");
1806 selection
.range
= range
;
1807 selection
.style
.ase
= TF_AE_NONE
;
1808 selection
.style
.fInterimChar
= FALSE
;
1809 test_ACP_SetSelection
= SINK_EXPECTED
;
1810 hr
= ITfContext_SetSelection(cxt
, ec
, 1, &selection
);
1811 ok(SUCCEEDED(hr
),"ITfContext_SetSelection failed\n");
1812 sink_check_ok(&test_ACP_SetSelection
,"SetSelection");
1813 ITfRange_Release(range
);
1815 ITfContext_Release(cxt
);
1816 ITfDocumentMgr_Release(dm
);
1820 static const ITfEditSessionVtbl EditSession_EditSessionVtbl
=
1822 EditSession_QueryInterface
,
1824 EditSession_Release
,
1826 EditSession_DoEditSession
1829 static HRESULT
EditSession_Constructor(ITfEditSession
**ppOut
)
1834 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(EditSession
));
1836 return E_OUTOFMEMORY
;
1838 This
->ITfEditSession_iface
.lpVtbl
= &EditSession_EditSessionVtbl
;
1841 *ppOut
= &This
->ITfEditSession_iface
;
1845 static void test_TStoApplicationText(void)
1847 HRESULT hr
, hrSession
;
1851 ITfTextEditSink
*sink
;
1852 ITfSource
*source
= NULL
;
1853 DWORD editSinkCookie
= -1;
1855 ITfThreadMgr_GetFocus(g_tm
, &dm
);
1856 EditSession_Constructor(&es
);
1857 ITfDocumentMgr_GetTop(dm
,&cxt
);
1859 TextEditSink_Constructor(&sink
);
1860 hr
= ITfContext_QueryInterface(cxt
,&IID_ITfSource
,(LPVOID
*)&source
);
1861 ok(SUCCEEDED(hr
),"Failed to get IID_ITfSource for Context\n");
1864 hr
= ITfSource_AdviseSink(source
, &IID_ITfTextEditSink
, (LPVOID
)sink
, &editSinkCookie
);
1865 ok(SUCCEEDED(hr
),"Failed to advise Sink\n");
1866 ok(editSinkCookie
!= -1,"Failed to get sink cookie\n");
1869 hrSession
= 0xfeedface;
1870 /* Test no permissions flags */
1871 hr
= ITfContext_RequestEditSession(cxt
, tid
, es
, TF_ES_SYNC
, &hrSession
);
1872 ok(hr
== E_INVALIDARG
,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG
,hr
);
1873 ok(hrSession
== E_FAIL
,"hrSession should be %x not %x\n",E_FAIL
,hrSession
);
1875 documentStatus
= TS_SD_READONLY
;
1876 hrSession
= 0xfeedface;
1877 test_ACP_GetStatus
= SINK_EXPECTED
;
1878 hr
= ITfContext_RequestEditSession(cxt
, tid
, es
, TF_ES_SYNC
|TF_ES_READWRITE
, &hrSession
);
1879 ok(SUCCEEDED(hr
),"ITfContext_RequestEditSession failed\n");
1880 ok(hrSession
== TS_E_READONLY
,"Unexpected hrSession (%x)\n",hrSession
);
1881 sink_check_ok(&test_ACP_GetStatus
,"GetStatus");
1883 /* signal a change to allow readwrite sessions */
1885 test_ACP_RequestLock
= SINK_EXPECTED
;
1886 ITextStoreACPSink_OnStatusChange(ACPSink
,documentStatus
);
1887 sink_check_ok(&test_ACP_RequestLock
,"RequestLock");
1889 test_ACP_GetStatus
= SINK_EXPECTED
;
1890 test_ACP_RequestLock
= SINK_EXPECTED
;
1891 test_DoEditSession
= SINK_EXPECTED
;
1892 hrSession
= 0xfeedface;
1893 test_OnEndEdit
= SINK_EXPECTED
;
1894 hr
= ITfContext_RequestEditSession(cxt
, tid
, es
, TF_ES_SYNC
|TF_ES_READWRITE
, &hrSession
);
1895 ok(SUCCEEDED(hr
),"ITfContext_RequestEditSession failed\n");
1896 sink_check_ok(&test_OnEndEdit
,"OnEndEdit");
1897 sink_check_ok(&test_DoEditSession
,"DoEditSession");
1898 sink_check_ok(&test_ACP_GetStatus
,"GetStatus");
1899 ok(hrSession
== 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession
);
1903 hr
= ITfSource_UnadviseSink(source
, editSinkCookie
);
1904 ok(SUCCEEDED(hr
),"Failed to unadvise Sink\n");
1905 ITfSource_Release(source
);
1907 ITfTextEditSink_Release(sink
);
1908 ITfContext_Release(cxt
);
1909 ITfDocumentMgr_Release(dm
);
1910 ITfEditSession_Release(es
);
1913 static void enum_compartments(ITfCompartmentMgr
*cmpmgr
, REFGUID present
, REFGUID absent
)
1919 if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr
, &ppEnum
)))
1923 while (IEnumGUID_Next(ppEnum
, 1, &g
, &fetched
) == S_OK
)
1927 StringFromGUID2(&g
,str
,sizeof(str
)/sizeof(str
[0]));
1928 WideCharToMultiByte(CP_ACP
,0,str
,-1,strA
,sizeof(strA
),0,0);
1929 trace("found %s\n",strA
);
1930 if (present
&& IsEqualGUID(present
,&g
))
1932 if (absent
&& IsEqualGUID(absent
, &g
))
1935 IEnumGUID_Release(ppEnum
);
1938 ok(found
,"Did not find compartment\n");
1940 ok(!found2
,"Found compartment that should be absent\n");
1943 static void test_Compartments(void)
1947 ITfCompartmentMgr
*cmpmgr
;
1948 ITfCompartment
*cmp
;
1951 ITfThreadMgr_GetFocus(g_tm
, &dm
);
1952 ITfDocumentMgr_GetTop(dm
,&cxt
);
1955 hr
= ITfThreadMgr_GetGlobalCompartment(g_tm
, &cmpmgr
);
1956 ok(SUCCEEDED(hr
),"GetGlobalCompartment failed\n");
1957 hr
= ITfCompartmentMgr_GetCompartment(cmpmgr
, &GUID_COMPARTMENT_SPEECH_OPENCLOSE
, &cmp
);
1958 ok(SUCCEEDED(hr
),"GetCompartment failed\n");
1959 ITfCompartment_Release(cmp
);
1960 enum_compartments(cmpmgr
,&GUID_COMPARTMENT_SPEECH_OPENCLOSE
,NULL
);
1961 ITfCompartmentMgr_Release(cmpmgr
);
1964 hr
= ITfThreadMgr_QueryInterface(g_tm
, &IID_ITfCompartmentMgr
, (LPVOID
*)&cmpmgr
);
1965 ok(SUCCEEDED(hr
),"ThreadMgr QI for IID_ITfCompartmentMgr failed\n");
1966 hr
= ITfCompartmentMgr_GetCompartment(cmpmgr
, &CLSID_FakeService
, &cmp
);
1967 ok(SUCCEEDED(hr
),"GetCompartment failed\n");
1968 enum_compartments(cmpmgr
,&CLSID_FakeService
,&GUID_COMPARTMENT_SPEECH_OPENCLOSE
);
1969 ITfCompartmentMgr_ClearCompartment(cmpmgr
,tid
,&CLSID_FakeService
);
1970 enum_compartments(cmpmgr
,NULL
,&CLSID_FakeService
);
1971 ITfCompartmentMgr_Release(cmpmgr
);
1972 ITfCompartment_Release(cmp
);
1975 hr
= ITfDocumentMgr_QueryInterface(dm
, &IID_ITfCompartmentMgr
, (LPVOID
*)&cmpmgr
);
1976 ok(SUCCEEDED(hr
),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1978 hr
= ITfCompartmentMgr_GetCompartment(cmpmgr
, &GUID_COMPARTMENT_PERSISTMENUENABLED
, &cmp
);
1979 ok(SUCCEEDED(hr
),"GetCompartment failed\n");
1980 enum_compartments(cmpmgr
,&GUID_COMPARTMENT_PERSISTMENUENABLED
,&GUID_COMPARTMENT_SPEECH_OPENCLOSE
);
1981 ITfCompartmentMgr_Release(cmpmgr
);
1984 hr
= ITfContext_QueryInterface(cxt
, &IID_ITfCompartmentMgr
, (LPVOID
*)&cmpmgr
);
1985 ok(SUCCEEDED(hr
),"Context QI for IID_ITfCompartmentMgr failed\n");
1986 enum_compartments(cmpmgr
,NULL
,&GUID_COMPARTMENT_PERSISTMENUENABLED
);
1987 ITfCompartmentMgr_Release(cmpmgr
);
1989 ITfContext_Release(cxt
);
1990 ITfDocumentMgr_Release(dm
);
1993 static void processPendingMessages(void)
1997 int min_timeout
= 100;
1998 DWORD time
= GetTickCount() + diff
;
2002 if (MsgWaitForMultipleObjects(0, NULL
, FALSE
, min_timeout
, QS_ALLINPUT
) == WAIT_TIMEOUT
)
2004 while (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
))
2006 TranslateMessage(&msg
);
2007 DispatchMessageW(&msg
);
2009 diff
= time
- GetTickCount();
2013 static void test_AssociateFocus(void)
2015 ITfDocumentMgr
*dm1
, *dm2
, *olddm
, *dmcheck
, *dmorig
;
2016 HWND wnd1
, wnd2
, wnd3
;
2019 ITfThreadMgr_GetFocus(g_tm
, &dmorig
);
2020 test_CurrentFocus
= NULL
;
2021 test_PrevFocus
= dmorig
;
2022 test_OnSetFocus
= SINK_OPTIONAL
; /* Doesn't always fire on Win7 */
2023 test_ACP_GetStatus
= SINK_OPTIONAL
;
2024 hr
= ITfThreadMgr_SetFocus(g_tm
,NULL
);
2025 ok(SUCCEEDED(hr
),"ITfThreadMgr_SetFocus failed\n");
2026 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2027 test_ACP_GetStatus
= SINK_UNEXPECTED
;
2028 ITfDocumentMgr_Release(dmorig
);
2030 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&dm1
);
2031 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
2033 hr
= ITfThreadMgr_CreateDocumentMgr(g_tm
,&dm2
);
2034 ok(SUCCEEDED(hr
),"CreateDocumentMgr failed\n");
2036 wnd1
= CreateWindowA("edit",NULL
,WS_POPUP
,0,0,200,60,NULL
,NULL
,NULL
,NULL
);
2037 ok(wnd1
!=NULL
,"Unable to create window 1\n");
2038 wnd2
= CreateWindowA("edit",NULL
,WS_POPUP
,0,65,200,60,NULL
,NULL
,NULL
,NULL
);
2039 ok(wnd2
!=NULL
,"Unable to create window 2\n");
2040 wnd3
= CreateWindowA("edit",NULL
,WS_POPUP
,0,130,200,60,NULL
,NULL
,NULL
,NULL
);
2041 ok(wnd3
!=NULL
,"Unable to create window 3\n");
2043 processPendingMessages();
2045 test_OnInitDocumentMgr
= SINK_OPTIONAL
; /* Vista and greater */
2046 test_OnPushContext
= SINK_OPTIONAL
; /* Vista and greater */
2047 test_OnSetFocus
= SINK_OPTIONAL
; /* Win7 */
2048 test_PrevFocus
= NULL
;
2049 test_CurrentFocus
= FOCUS_IGNORE
;
2051 ShowWindow(wnd1
,SW_SHOWNORMAL
);
2052 test_OnSetFocus
= SINK_UNEXPECTED
;
2054 sink_check_ok(&test_OnInitDocumentMgr
,"OnInitDocumentMgr");
2055 sink_check_ok(&test_OnPushContext
,"OnPushContext");
2057 test_OnSetFocus
= SINK_OPTIONAL
; /* Vista and greater */
2058 test_ACP_RequestLock
= SINK_OPTIONAL
; /* Win7 x64 */
2059 test_ACP_GetSelection
= SINK_OPTIONAL
; /* Win7 x64 */
2060 ITfThreadMgr_GetFocus(g_tm
, &test_PrevFocus
);
2061 test_CurrentFocus
= FOCUS_IGNORE
; /* This is a default system context */
2062 processPendingMessages();
2063 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2064 test_ACP_RequestLock
= SINK_UNEXPECTED
;
2065 test_ACP_GetSelection
= SINK_UNEXPECTED
;
2067 test_CurrentFocus
= dm1
;
2068 test_PrevFocus
= FOCUS_IGNORE
;
2069 test_OnSetFocus
= SINK_OPTIONAL
;
2070 test_ShouldDeactivate
= SINK_OPTIONAL
;
2071 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd1
,dm1
,&olddm
);
2072 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2073 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2074 test_ShouldDeactivate
= SINK_UNEXPECTED
;
2076 processPendingMessages();
2078 ITfThreadMgr_GetFocus(g_tm
, &dmcheck
);
2079 ok(dmcheck
== dm1
|| broken(dmcheck
== dmorig
/* Win7+ */), "Expected DocumentMgr not focused\n");
2080 ITfDocumentMgr_Release(dmcheck
);
2082 /* We need to explicitly set focus on Win7+ */
2083 test_CurrentFocus
= dm1
;
2084 test_PrevFocus
= FOCUS_IGNORE
;
2085 test_OnSetFocus
= SINK_OPTIONAL
; /* Doesn't always fire on Win7+ */
2086 ITfThreadMgr_SetFocus(g_tm
, dm1
);
2087 sink_check_ok(&test_OnSetFocus
, "OnSetFocus");
2089 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd2
,dm2
,&olddm
);
2090 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2091 processPendingMessages();
2092 ITfThreadMgr_GetFocus(g_tm
, &dmcheck
);
2093 ok(dmcheck
== dm1
, "Expected DocumentMgr not focused\n");
2094 ITfDocumentMgr_Release(dmcheck
);
2096 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd3
,dm2
,&olddm
);
2097 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2098 processPendingMessages();
2099 ITfThreadMgr_GetFocus(g_tm
, &dmcheck
);
2100 ok(dmcheck
== dm1
, "Expected DocumentMgr not focused\n");
2101 ITfDocumentMgr_Release(dmcheck
);
2103 test_CurrentFocus
= FOCUS_SAVE
;
2104 test_PrevFocus
= FOCUS_SAVE
;
2105 test_OnSetFocus
= SINK_SAVE
;
2106 ShowWindow(wnd2
,SW_SHOWNORMAL
);
2108 sink_check_saved(&test_OnSetFocus
,dm1
,dm2
,"OnSetFocus");
2109 test_CurrentFocus
= FOCUS_IGNORE
; /* occasional wine race */
2110 test_PrevFocus
= FOCUS_IGNORE
; /* occasional wine race */
2111 test_OnSetFocus
= SINK_IGNORE
; /* occasional wine race */
2112 processPendingMessages();
2114 ShowWindow(wnd3
,SW_SHOWNORMAL
);
2116 processPendingMessages();
2118 test_CurrentFocus
= FOCUS_SAVE
;
2119 test_PrevFocus
= FOCUS_SAVE
;
2120 test_OnSetFocus
= SINK_SAVE
;
2122 processPendingMessages();
2123 sink_check_saved(&test_OnSetFocus
,dm2
,dm1
,"OnSetFocus");
2125 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd3
,NULL
,&olddm
);
2126 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2127 ok(olddm
== dm2
, "incorrect old DocumentMgr returned\n");
2128 ITfDocumentMgr_Release(olddm
);
2130 test_CurrentFocus
= dmorig
;
2131 test_PrevFocus
= dm1
;
2132 test_OnSetFocus
= SINK_OPTIONAL
; /* Doesn't always fire on Win7+ */
2133 test_ACP_GetStatus
= SINK_IGNORE
;
2134 ITfThreadMgr_SetFocus(g_tm
,dmorig
);
2135 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2137 test_CurrentFocus
= FOCUS_SAVE
;
2138 test_PrevFocus
= FOCUS_SAVE
;
2139 test_OnSetFocus
= SINK_SAVE
;
2141 processPendingMessages();
2142 sink_check_saved(&test_OnSetFocus
,dmorig
,FOCUS_IGNORE
,"OnSetFocus"); /* CurrentFocus NULL on XP, system default on Vista */
2144 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd2
,NULL
,&olddm
);
2145 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2146 ok(olddm
== dm2
, "incorrect old DocumentMgr returned\n");
2147 ITfDocumentMgr_Release(olddm
);
2148 hr
= ITfThreadMgr_AssociateFocus(g_tm
,wnd1
,NULL
,&olddm
);
2149 ok(SUCCEEDED(hr
),"AssociateFocus failed\n");
2150 ok(olddm
== dm1
, "incorrect old DocumentMgr returned\n");
2151 ITfDocumentMgr_Release(olddm
);
2153 test_OnSetFocus
= SINK_IGNORE
; /* OnSetFocus fires a couple of times on Win7 */
2154 test_CurrentFocus
= FOCUS_IGNORE
;
2155 test_PrevFocus
= FOCUS_IGNORE
;
2157 processPendingMessages();
2159 processPendingMessages();
2160 test_OnSetFocus
= SINK_UNEXPECTED
;
2162 ITfDocumentMgr_Release(dm1
);
2163 ITfDocumentMgr_Release(dm2
);
2165 test_CurrentFocus
= dmorig
;
2166 test_PrevFocus
= FOCUS_IGNORE
;
2167 test_OnSetFocus
= SINK_OPTIONAL
;
2168 test_ACP_GetStatus
= SINK_IGNORE
;
2169 ITfThreadMgr_SetFocus(g_tm
,dmorig
);
2170 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2172 test_OnSetFocus
= SINK_IGNORE
; /* OnSetFocus fires a couple of times on Win7 */
2173 test_CurrentFocus
= FOCUS_IGNORE
;
2174 test_PrevFocus
= FOCUS_IGNORE
;
2175 DestroyWindow(wnd1
);
2176 DestroyWindow(wnd2
);
2177 test_OnPopContext
= SINK_OPTIONAL
; /* Vista and greater */
2178 test_OnSetFocus
= SINK_OPTIONAL
; /* Vista and greater */
2179 ITfThreadMgr_GetFocus(g_tm
, &test_PrevFocus
);
2180 test_CurrentFocus
= NULL
;
2181 test_ShouldDeactivate
= TRUE
; /* Win7 */
2182 DestroyWindow(wnd3
);
2183 test_ShouldDeactivate
= FALSE
;
2184 sink_check_ok(&test_OnSetFocus
,"OnSetFocus");
2185 sink_check_ok(&test_OnPopContext
,"OnPopContext");
2188 static void test_profile_mgr(void)
2190 IEnumTfInputProcessorProfiles
*enum_profiles
;
2191 ITfInputProcessorProfileMgr
*ipp_mgr
;
2194 hres
= ITfInputProcessorProfiles_QueryInterface(g_ipp
, &IID_ITfInputProcessorProfileMgr
, (void**)&ipp_mgr
);
2197 win_skip("ITfInputProcessorProfileMgr is not supported.\n");
2200 ok(hres
== S_OK
, "Could not get ITfInputProcessorProfileMgr iface: %08x\n", hres
);
2202 hres
= ITfInputProcessorProfileMgr_EnumProfiles(ipp_mgr
, 0, &enum_profiles
);
2203 ok(hres
== S_OK
, "EnumProfiles failed: %08x\n", hres
);
2205 IEnumTfInputProcessorProfiles_Release(enum_profiles
);
2207 ITfInputProcessorProfileMgr_Release(ipp_mgr
);
2210 START_TEST(inputprocessor
)
2212 if (SUCCEEDED(initialize()))
2215 test_RegisterCategory();
2216 Sleep(2000); /* Win7 needs some time before the registrations become active */
2217 processPendingMessages();
2218 test_EnumLanguageProfiles();
2219 test_EnumInputProcessorInfo();
2221 test_ThreadMgrAdviseSinks();
2223 test_startSession();
2226 test_KeystrokeMgr();
2227 test_TStoApplicationText();
2228 test_Compartments();
2229 test_AssociateFocus();
2231 test_FindClosestCategory();
2233 test_ThreadMgrUnadviseSinks();
2234 test_UnregisterCategory();
2239 skip("Unable to create InputProcessor\n");