[WINESYNC]
[reactos.git] / rostests / winetests / msctf / inputprocessor.c
1 /*
2 * Unit tests for ITfInputProcessor
3 *
4 * Copyright 2009 Aric Stewart, CodeWeavers
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include <stdio.h>
22
23 #define COBJMACROS
24 #include "wine/test.h"
25 #include "winuser.h"
26 #include "initguid.h"
27 #include "shlwapi.h"
28 #include "shlguid.h"
29 #include "comcat.h"
30 #include "msctf.h"
31 #include "olectl.h"
32
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;
40
41 static ITextStoreACPSink *ACPSink;
42
43 #define SINK_UNEXPECTED 0
44 #define SINK_EXPECTED 1
45 #define SINK_FIRED 2
46 #define SINK_IGNORE 3
47 #define SINK_OPTIONAL 4
48
49 #define SINK_ACTION_MASK 0xff
50 #define SINK_OPTION_MASK 0xff00
51 #define SINK_EXPECTED_COUNT_MASK 0xff0000
52
53 #define SINK_OPTION_TODO 0x0100
54
55 #define FOCUS_IGNORE (ITfDocumentMgr*)0xffffffff
56
57 static BOOL test_ShouldActivate = FALSE;
58 static BOOL test_ShouldDeactivate = FALSE;
59
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;
79
80
81 static inline int expected_count(int *sink)
82 {
83 return (*sink & SINK_EXPECTED_COUNT_MASK)>>16;
84 }
85
86 static inline void _sink_fire_ok(INT *sink, const CHAR* name)
87 {
88 int count;
89 int todo = *sink & SINK_OPTION_TODO;
90 int action = *sink & SINK_ACTION_MASK;
91
92 if (winetest_interactive)
93 winetest_trace("firing %s\n",name);
94
95 switch (action)
96 {
97 case SINK_OPTIONAL:
98 case SINK_EXPECTED:
99 count = expected_count(sink);
100 if (count > 1)
101 {
102 count --;
103 *sink = (*sink & ~SINK_EXPECTED_COUNT_MASK) + (count << 16);
104 return;
105 }
106 break;
107 case SINK_IGNORE:
108 winetest_trace("Ignoring %s\n",name);
109 return;
110 default:
111 if (todo)
112 todo_wine winetest_ok(0, "Unexpected %s sink\n",name);
113 else
114 winetest_ok(0, "Unexpected %s sink\n",name);
115 }
116 *sink = SINK_FIRED;
117 }
118
119 #define sink_fire_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_fire_ok(a,b)
120
121 static inline void _sink_check_ok(INT *sink, const CHAR* name)
122 {
123 int action = *sink & SINK_ACTION_MASK;
124 int todo = *sink & SINK_OPTION_TODO;
125
126 switch (action)
127 {
128 case SINK_OPTIONAL:
129 if (winetest_interactive)
130 winetest_trace("optional sink %s not fired\n",name);
131 case SINK_FIRED:
132 break;
133 case SINK_IGNORE:
134 return;
135 default:
136 if (todo)
137 todo_wine winetest_ok(0, "%s not fired as expected, in state %x\n",name,*sink);
138 else
139 winetest_ok(0, "%s not fired as expected, in state %x\n",name,*sink);
140 }
141 *sink = SINK_UNEXPECTED;
142 }
143
144 #define sink_check_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_ok(a,b)
145
146 /**********************************************************************
147 * ITextStoreACP
148 **********************************************************************/
149 typedef struct tagTextStoreACP
150 {
151 const ITextStoreACPVtbl *TextStoreACPVtbl;
152 LONG refCount;
153
154 } TextStoreACP;
155
156 static void TextStoreACP_Destructor(TextStoreACP *This)
157 {
158 HeapFree(GetProcessHeap(),0,This);
159 }
160
161 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
162 {
163 TextStoreACP *This = (TextStoreACP *)iface;
164 *ppvOut = NULL;
165
166 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
167 {
168 *ppvOut = This;
169 }
170
171 if (*ppvOut)
172 {
173 IUnknown_AddRef(iface);
174 return S_OK;
175 }
176
177 return E_NOINTERFACE;
178 }
179
180 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
181 {
182 TextStoreACP *This = (TextStoreACP *)iface;
183 return InterlockedIncrement(&This->refCount);
184 }
185
186 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
187 {
188 TextStoreACP *This = (TextStoreACP *)iface;
189 ULONG ret;
190
191 ret = InterlockedDecrement(&This->refCount);
192 if (ret == 0)
193 TextStoreACP_Destructor(This);
194 return ret;
195 }
196
197 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
198 REFIID riid, IUnknown *punk, DWORD dwMask)
199 {
200 HRESULT hr;
201
202 sink_fire_ok(&test_ACP_AdviseSink,"TextStoreACP_AdviseSink");
203
204 hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&ACPSink));
205 ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
206 return S_OK;
207 }
208
209 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
210 IUnknown *punk)
211 {
212 trace("\n");
213 return S_OK;
214 }
215
216 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
217 DWORD dwLockFlags, HRESULT *phrSession)
218 {
219 sink_fire_ok(&test_ACP_RequestLock,"TextStoreACP_RequestLock");
220 *phrSession = ITextStoreACPSink_OnLockGranted(ACPSink, dwLockFlags);
221 return S_OK;
222 }
223 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
224 TS_STATUS *pdcs)
225 {
226 sink_fire_ok(&test_ACP_GetStatus,"TextStoreACP_GetStatus");
227 pdcs->dwDynamicFlags = documentStatus;
228 return S_OK;
229 }
230 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
231 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
232 LONG *pacpResultEnd)
233 {
234 trace("\n");
235 return S_OK;
236 }
237 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
238 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
239 {
240 sink_fire_ok(&test_ACP_GetSelection,"TextStoreACP_GetSelection");
241
242 pSelection->acpStart = 10;
243 pSelection->acpEnd = 20;
244 pSelection->style.fInterimChar = 0;
245 pSelection->style.ase = TS_AE_NONE;
246 *pcFetched = 1;
247
248 return S_OK;
249 }
250 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
251 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
252 {
253 sink_fire_ok(&test_ACP_SetSelection,"TextStoreACP_SetSelection");
254 return S_OK;
255 }
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)
260 {
261 trace("\n");
262 return S_OK;
263 }
264 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
265 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
266 ULONG cch, TS_TEXTCHANGE *pChange)
267 {
268 trace("\n");
269 return S_OK;
270 }
271 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
272 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
273 {
274 trace("\n");
275 return S_OK;
276 }
277 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
278 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
279 {
280 trace("\n");
281 return S_OK;
282 }
283 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
284 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
285 {
286 trace("\n");
287 return S_OK;
288 }
289 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
290 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
291 TS_TEXTCHANGE *pChange)
292 {
293 trace("\n");
294 return S_OK;
295 }
296 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
297 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
298 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
299 {
300 sink_fire_ok(&test_ACP_InsertTextAtSelection,"TextStoreACP_InsertTextAtSelection");
301 return S_OK;
302 }
303 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
304 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
305 TS_TEXTCHANGE *pChange)
306 {
307 trace("\n");
308 return S_OK;
309 }
310 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
311 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
312 {
313 trace("\n");
314 return S_OK;
315 }
316 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
317 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
318 DWORD dwFlags)
319 {
320 trace("\n");
321 return S_OK;
322 }
323 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
324 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
325 DWORD dwFlags)
326 {
327 trace("\n");
328 return S_OK;
329 }
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)
333 {
334 trace("\n");
335 return S_OK;
336 }
337 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
338 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
339 {
340 trace("\n");
341 return S_OK;
342 }
343 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
344 LONG *pacp)
345 {
346 sink_fire_ok(&test_ACP_GetEndACP,"TextStoreACP_GetEndACP");
347 return S_OK;
348 }
349 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
350 TsViewCookie *pvcView)
351 {
352 trace("\n");
353 return S_OK;
354 }
355 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
356 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
357 LONG *pacp)
358 {
359 trace("\n");
360 return S_OK;
361 }
362 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
363 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
364 BOOL *pfClipped)
365 {
366 trace("\n");
367 return S_OK;
368 }
369 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
370 TsViewCookie vcView, RECT *prc)
371 {
372 trace("\n");
373 return S_OK;
374 }
375 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
376 TsViewCookie vcView, HWND *phwnd)
377 {
378 trace("\n");
379 return S_OK;
380 }
381
382 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
383 {
384 TextStoreACP_QueryInterface,
385 TextStoreACP_AddRef,
386 TextStoreACP_Release,
387
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,
413 TextStoreACP_GetWnd
414 };
415
416 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
417 {
418 TextStoreACP *This;
419
420 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
421 if (This == NULL)
422 return E_OUTOFMEMORY;
423
424 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
425 This->refCount = 1;
426
427 *ppOut = (IUnknown *)This;
428 return S_OK;
429 }
430
431 /**********************************************************************
432 * ITfThreadMgrEventSink
433 **********************************************************************/
434 typedef struct tagThreadMgrEventSink
435 {
436 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
437 LONG refCount;
438 } ThreadMgrEventSink;
439
440 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
441 {
442 HeapFree(GetProcessHeap(),0,This);
443 }
444
445 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
446 {
447 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
448 *ppvOut = NULL;
449
450 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
451 {
452 *ppvOut = This;
453 }
454
455 if (*ppvOut)
456 {
457 IUnknown_AddRef(iface);
458 return S_OK;
459 }
460
461 return E_NOINTERFACE;
462 }
463
464 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
465 {
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);
469 }
470
471 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
472 {
473 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
474 ULONG ret;
475
476 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
477 ret = InterlockedDecrement(&This->refCount);
478 if (ret == 0)
479 ThreadMgrEventSink_Destructor(This);
480 return ret;
481 }
482
483 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
484 ITfDocumentMgr *pdim)
485 {
486 sink_fire_ok(&test_OnInitDocumentMgr,"ThreadMgrEventSink_OnInitDocumentMgr");
487 return S_OK;
488 }
489
490 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
491 ITfDocumentMgr *pdim)
492 {
493 trace("\n");
494 return S_OK;
495 }
496
497 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
498 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
499 {
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");
505 return S_OK;
506 }
507
508 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
509 ITfContext *pic)
510 {
511 HRESULT hr;
512 ITfDocumentMgr *docmgr;
513 ITfContext *test;
514
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");
522 if (test)
523 ITfContext_Release(test);
524
525 sink_fire_ok(&test_OnPushContext,"ThreadMgrEventSink_OnPushContext");
526 return S_OK;
527 }
528
529 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
530 ITfContext *pic)
531 {
532 HRESULT hr;
533 ITfDocumentMgr *docmgr;
534 ITfContext *test;
535
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");
543 if (test)
544 ITfContext_Release(test);
545
546 sink_fire_ok(&test_OnPopContext,"ThreadMgrEventSink_OnPopContext");
547 return S_OK;
548 }
549
550 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
551 {
552 ThreadMgrEventSink_QueryInterface,
553 ThreadMgrEventSink_AddRef,
554 ThreadMgrEventSink_Release,
555
556 ThreadMgrEventSink_OnInitDocumentMgr,
557 ThreadMgrEventSink_OnUninitDocumentMgr,
558 ThreadMgrEventSink_OnSetFocus,
559 ThreadMgrEventSink_OnPushContext,
560 ThreadMgrEventSink_OnPopContext
561 };
562
563 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
564 {
565 ThreadMgrEventSink *This;
566
567 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
568 if (This == NULL)
569 return E_OUTOFMEMORY;
570
571 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
572 This->refCount = 1;
573
574 *ppOut = (IUnknown *)This;
575 return S_OK;
576 }
577
578
579 /********************************************************************************************
580 * Stub text service for testing
581 ********************************************************************************************/
582
583 static LONG TS_refCount;
584 static IClassFactory *cf;
585 static DWORD regid;
586
587 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
588
589 typedef struct tagClassFactory
590 {
591 const IClassFactoryVtbl *vtbl;
592 LONG ref;
593 LPFNCONSTRUCTOR ctor;
594 } ClassFactory;
595
596 typedef struct tagTextService
597 {
598 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
599 LONG refCount;
600 } TextService;
601
602 static void ClassFactory_Destructor(ClassFactory *This)
603 {
604 HeapFree(GetProcessHeap(),0,This);
605 TS_refCount--;
606 }
607
608 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
609 {
610 *ppvOut = NULL;
611 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
612 {
613 IClassFactory_AddRef(iface);
614 *ppvOut = iface;
615 return S_OK;
616 }
617
618 return E_NOINTERFACE;
619 }
620
621 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
622 {
623 ClassFactory *This = (ClassFactory *)iface;
624 return InterlockedIncrement(&This->ref);
625 }
626
627 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
628 {
629 ClassFactory *This = (ClassFactory *)iface;
630 ULONG ret = InterlockedDecrement(&This->ref);
631
632 if (ret == 0)
633 ClassFactory_Destructor(This);
634 return ret;
635 }
636
637 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
638 {
639 ClassFactory *This = (ClassFactory *)iface;
640 HRESULT ret;
641 IUnknown *obj;
642
643 ret = This->ctor(punkOuter, &obj);
644 if (FAILED(ret))
645 return ret;
646 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
647 IUnknown_Release(obj);
648 return ret;
649 }
650
651 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
652 {
653 if(fLock)
654 InterlockedIncrement(&TS_refCount);
655 else
656 InterlockedDecrement(&TS_refCount);
657
658 return S_OK;
659 }
660
661 static const IClassFactoryVtbl ClassFactoryVtbl = {
662 /* IUnknown */
663 ClassFactory_QueryInterface,
664 ClassFactory_AddRef,
665 ClassFactory_Release,
666
667 /* IClassFactory*/
668 ClassFactory_CreateInstance,
669 ClassFactory_LockServer
670 };
671
672 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
673 {
674 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
675 This->vtbl = &ClassFactoryVtbl;
676 This->ref = 1;
677 This->ctor = ctor;
678 *ppvOut = (LPVOID)This;
679 TS_refCount++;
680 return S_OK;
681 }
682
683 static void TextService_Destructor(TextService *This)
684 {
685 HeapFree(GetProcessHeap(),0,This);
686 }
687
688 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
689 {
690 TextService *This = (TextService *)iface;
691 *ppvOut = NULL;
692
693 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
694 {
695 *ppvOut = This;
696 }
697
698 if (*ppvOut)
699 {
700 IUnknown_AddRef(iface);
701 return S_OK;
702 }
703
704 return E_NOINTERFACE;
705 }
706
707 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
708 {
709 TextService *This = (TextService *)iface;
710 return InterlockedIncrement(&This->refCount);
711 }
712
713 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
714 {
715 TextService *This = (TextService *)iface;
716 ULONG ret;
717
718 ret = InterlockedDecrement(&This->refCount);
719 if (ret == 0)
720 TextService_Destructor(This);
721 return ret;
722 }
723
724 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
725 ITfThreadMgr *ptim, TfClientId id)
726 {
727 trace("TextService_Activate\n");
728 ok(test_ShouldActivate,"Activation came unexpectedly\n");
729 tid = id;
730 return S_OK;
731 }
732
733 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
734 {
735 trace("TextService_Deactivate\n");
736 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
737 return S_OK;
738 }
739
740 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
741 {
742 TextService_QueryInterface,
743 TextService_AddRef,
744 TextService_Release,
745
746 TextService_Activate,
747 TextService_Deactivate
748 };
749
750 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
751 {
752 TextService *This;
753 if (pUnkOuter)
754 return CLASS_E_NOAGGREGATION;
755
756 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
757 if (This == NULL)
758 return E_OUTOFMEMORY;
759
760 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
761 This->refCount = 1;
762
763 *ppOut = (IUnknown *)This;
764 return S_OK;
765 }
766
767 static HRESULT RegisterTextService(REFCLSID rclsid)
768 {
769 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
770 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
771 }
772
773 static HRESULT UnregisterTextService(void)
774 {
775 return CoRevokeClassObject(regid);
776 }
777
778 /*
779 * The tests
780 */
781
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);
801
802 static HRESULT initialize(void)
803 {
804 HRESULT hr;
805 CoInitialize(NULL);
806 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
807 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
808 if (SUCCEEDED(hr))
809 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
810 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
811 if (SUCCEEDED(hr))
812 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
813 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
814 return hr;
815 }
816
817 static void cleanup(void)
818 {
819 if (g_ipp)
820 ITfInputProcessorProfiles_Release(g_ipp);
821 if (g_cm)
822 ITfCategoryMgr_Release(g_cm);
823 if (g_tm)
824 ITfThreadMgr_Release(g_tm);
825 CoUninitialize();
826 }
827
828 static void test_Register(void)
829 {
830 HRESULT hr;
831
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};
834
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);
838
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);
845 }
846
847 static void test_Unregister(void)
848 {
849 HRESULT hr;
850 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
851 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
852 UnregisterTextService();
853 }
854
855 static void test_EnumInputProcessorInfo(void)
856 {
857 IEnumGUID *ppEnum;
858 BOOL found = FALSE;
859
860 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
861 {
862 ULONG fetched;
863 GUID g;
864 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
865 {
866 if(IsEqualGUID(&g,&CLSID_FakeService))
867 found = TRUE;
868 }
869 }
870 ok(found,"Did not find registered text service\n");
871 }
872
873 static void test_EnumLanguageProfiles(void)
874 {
875 BOOL found = FALSE;
876 IEnumTfLanguageProfiles *ppEnum;
877 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
878 {
879 TF_LANGUAGEPROFILE profile;
880 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
881 {
882 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
883 {
884 found = TRUE;
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");
888 }
889 }
890 }
891 ok(found,"Registered text service not found\n");
892 }
893
894 static void test_RegisterCategory(void)
895 {
896 HRESULT hr;
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");
901 }
902
903 static void test_UnregisterCategory(void)
904 {
905 HRESULT hr;
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");
910 }
911
912 static void test_FindClosestCategory(void)
913 {
914 GUID output;
915 HRESULT hr;
916 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
917
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");
921
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");
925
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");
929 }
930
931 static void test_Enable(void)
932 {
933 HRESULT hr;
934 BOOL enabled = FALSE;
935
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");
941 }
942
943 static void test_Disable(void)
944 {
945 HRESULT hr;
946
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");
950 }
951
952 static void test_ThreadMgrAdviseSinks(void)
953 {
954 ITfSource *source = NULL;
955 HRESULT hr;
956 IUnknown *sink;
957
958 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
959 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
960 if (!source)
961 return;
962
963 hr = ThreadMgrEventSink_Constructor(&sink);
964 ok(hr == S_OK, "got %08x\n", hr);
965 if(FAILED(hr)) return;
966
967 tmSinkRefCount = 1;
968 tmSinkCookie = 0;
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");
972
973 /* Advising the sink adds a ref, Relesing here lets the object be deleted
974 when unadvised */
975 tmSinkRefCount = 2;
976 IUnknown_Release(sink);
977 ITfSource_Release(source);
978 }
979
980 static void test_ThreadMgrUnadviseSinks(void)
981 {
982 ITfSource *source = NULL;
983 HRESULT hr;
984
985 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
986 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
987 if (!source)
988 return;
989
990 tmSinkRefCount = 1;
991 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
992 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
993 ITfSource_Release(source);
994 }
995
996 /**********************************************************************
997 * ITfKeyEventSink
998 **********************************************************************/
999 typedef struct tagKeyEventSink
1000 {
1001 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
1002 LONG refCount;
1003 } KeyEventSink;
1004
1005 static void KeyEventSink_Destructor(KeyEventSink *This)
1006 {
1007 HeapFree(GetProcessHeap(),0,This);
1008 }
1009
1010 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
1011 {
1012 KeyEventSink *This = (KeyEventSink *)iface;
1013 *ppvOut = NULL;
1014
1015 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
1016 {
1017 *ppvOut = This;
1018 }
1019
1020 if (*ppvOut)
1021 {
1022 IUnknown_AddRef(iface);
1023 return S_OK;
1024 }
1025
1026 return E_NOINTERFACE;
1027 }
1028
1029 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
1030 {
1031 KeyEventSink *This = (KeyEventSink *)iface;
1032 return InterlockedIncrement(&This->refCount);
1033 }
1034
1035 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
1036 {
1037 KeyEventSink *This = (KeyEventSink *)iface;
1038 ULONG ret;
1039
1040 ret = InterlockedDecrement(&This->refCount);
1041 if (ret == 0)
1042 KeyEventSink_Destructor(This);
1043 return ret;
1044 }
1045
1046 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
1047 BOOL fForeground)
1048 {
1049 sink_fire_ok(&test_KEV_OnSetFocus,"KeyEventSink_OnSetFocus");
1050 return S_OK;
1051 }
1052
1053 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
1054 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1055 {
1056 trace("\n");
1057 return S_OK;
1058 }
1059
1060 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
1061 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1062 {
1063 trace("\n");
1064 return S_OK;
1065 }
1066
1067 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
1068 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1069 {
1070 trace("\n");
1071 return S_OK;
1072 }
1073
1074 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
1075 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1076 {
1077 trace("\n");
1078 return S_OK;
1079 }
1080
1081 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
1082 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
1083 {
1084 trace("\n");
1085 return S_OK;
1086 }
1087
1088 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
1089 {
1090 KeyEventSink_QueryInterface,
1091 KeyEventSink_AddRef,
1092 KeyEventSink_Release,
1093
1094 KeyEventSink_OnSetFocus,
1095 KeyEventSink_OnTestKeyDown,
1096 KeyEventSink_OnTestKeyUp,
1097 KeyEventSink_OnKeyDown,
1098 KeyEventSink_OnKeyUp,
1099 KeyEventSink_OnPreservedKey
1100 };
1101
1102 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1103 {
1104 KeyEventSink *This;
1105
1106 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1107 if (This == NULL)
1108 return E_OUTOFMEMORY;
1109
1110 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1111 This->refCount = 1;
1112
1113 *ppOut = (ITfKeyEventSink*)This;
1114 return S_OK;
1115 }
1116
1117
1118 static void test_KeystrokeMgr(void)
1119 {
1120 ITfKeystrokeMgr *keymgr= NULL;
1121 HRESULT hr;
1122 TF_PRESERVEDKEY tfpk;
1123 BOOL preserved;
1124 ITfKeyEventSink *sink = NULL;
1125
1126 KeyEventSink_Constructor(&sink);
1127
1128 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1129 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1130
1131 tfpk.uVKey = 'A';
1132 tfpk.uModifiers = TF_MOD_SHIFT;
1133
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");
1142
1143 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1144 ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1145
1146 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1147 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1148
1149 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1150 ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1151
1152 preserved = FALSE;
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");
1156
1157 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1158 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1159
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");
1163
1164 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1165 ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1166
1167 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1168 ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1169
1170 ITfKeystrokeMgr_Release(keymgr);
1171 ITfKeyEventSink_Release(sink);
1172 }
1173
1174 static void test_Activate(void)
1175 {
1176 HRESULT hr;
1177
1178 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1179 ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1180 }
1181
1182
1183 static void test_EnumContexts(ITfDocumentMgr *dm, ITfContext *search)
1184 {
1185 HRESULT hr;
1186 IEnumTfContexts* pEnum;
1187 BOOL found = FALSE;
1188
1189 hr = ITfDocumentMgr_EnumContexts(dm,&pEnum);
1190 ok(SUCCEEDED(hr),"EnumContexts failed\n");
1191 if (SUCCEEDED(hr))
1192 {
1193 ULONG fetched;
1194 ITfContext *cxt;
1195 while (IEnumTfContexts_Next(pEnum, 1, &cxt, &fetched) == S_OK)
1196 {
1197 if (!search)
1198 found = TRUE;
1199 else if (search == cxt)
1200 found = TRUE;
1201 ITfContext_Release(cxt);
1202 }
1203 IEnumTfContexts_Release(pEnum);
1204 }
1205 if (search)
1206 ok(found,"Did not find proper ITfContext\n");
1207 else
1208 ok(!found,"Found an ITfContext we should should not have\n");
1209 }
1210
1211 static void test_EnumDocumentMgr(ITfThreadMgr *tm, ITfDocumentMgr *search, ITfDocumentMgr *absent)
1212 {
1213 HRESULT hr;
1214 IEnumTfDocumentMgrs* pEnum;
1215 BOOL found = FALSE;
1216 BOOL notfound = TRUE;
1217
1218 hr = ITfThreadMgr_EnumDocumentMgrs(tm,&pEnum);
1219 ok(SUCCEEDED(hr),"EnumDocumentMgrs failed\n");
1220 if (SUCCEEDED(hr))
1221 {
1222 ULONG fetched;
1223 ITfDocumentMgr *dm;
1224 while (IEnumTfDocumentMgrs_Next(pEnum, 1, &dm, &fetched) == S_OK)
1225 {
1226 if (!search)
1227 found = TRUE;
1228 else if (search == dm)
1229 found = TRUE;
1230 if (absent && dm == absent)
1231 notfound = FALSE;
1232 ITfDocumentMgr_Release(dm);
1233 }
1234 IEnumTfDocumentMgrs_Release(pEnum);
1235 }
1236 if (search)
1237 ok(found,"Did not find proper ITfDocumentMgr\n");
1238 else
1239 ok(!found,"Found an ITfDocumentMgr we should should not have\n");
1240 if (absent)
1241 ok(notfound,"Found an ITfDocumentMgr we believe should be absent\n");
1242 }
1243
1244 static inline int check_context_refcount(ITfContext *iface)
1245 {
1246 IUnknown_AddRef(iface);
1247 return IUnknown_Release(iface);
1248 }
1249
1250
1251 /**********************************************************************
1252 * ITfTextEditSink
1253 **********************************************************************/
1254 typedef struct tagTextEditSink
1255 {
1256 const ITfTextEditSinkVtbl *TextEditSinkVtbl;
1257 LONG refCount;
1258 } TextEditSink;
1259
1260 static void TextEditSink_Destructor(TextEditSink *This)
1261 {
1262 HeapFree(GetProcessHeap(),0,This);
1263 }
1264
1265 static HRESULT WINAPI TextEditSink_QueryInterface(ITfTextEditSink *iface, REFIID iid, LPVOID *ppvOut)
1266 {
1267 TextEditSink *This = (TextEditSink *)iface;
1268 *ppvOut = NULL;
1269
1270 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextEditSink))
1271 {
1272 *ppvOut = This;
1273 }
1274
1275 if (*ppvOut)
1276 {
1277 IUnknown_AddRef(iface);
1278 return S_OK;
1279 }
1280
1281 return E_NOINTERFACE;
1282 }
1283
1284 static ULONG WINAPI TextEditSink_AddRef(ITfTextEditSink *iface)
1285 {
1286 TextEditSink *This = (TextEditSink *)iface;
1287 return InterlockedIncrement(&This->refCount);
1288 }
1289
1290 static ULONG WINAPI TextEditSink_Release(ITfTextEditSink *iface)
1291 {
1292 TextEditSink *This = (TextEditSink *)iface;
1293 ULONG ret;
1294
1295 ret = InterlockedDecrement(&This->refCount);
1296 if (ret == 0)
1297 TextEditSink_Destructor(This);
1298 return ret;
1299 }
1300
1301 static HRESULT WINAPI TextEditSink_OnEndEdit(ITfTextEditSink *iface,
1302 ITfContext *pic, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
1303 {
1304 sink_fire_ok(&test_OnEndEdit,"TextEditSink_OnEndEdit");
1305 return S_OK;
1306 }
1307
1308 static const ITfTextEditSinkVtbl TextEditSink_TextEditSinkVtbl =
1309 {
1310 TextEditSink_QueryInterface,
1311 TextEditSink_AddRef,
1312 TextEditSink_Release,
1313
1314 TextEditSink_OnEndEdit
1315 };
1316
1317 static HRESULT TextEditSink_Constructor(ITfTextEditSink **ppOut)
1318 {
1319 TextEditSink *This;
1320
1321 *ppOut = NULL;
1322 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextEditSink));
1323 if (This == NULL)
1324 return E_OUTOFMEMORY;
1325
1326 This->TextEditSinkVtbl = &TextEditSink_TextEditSinkVtbl;
1327 This->refCount = 1;
1328
1329 *ppOut = (ITfTextEditSink*)This;
1330 return S_OK;
1331 }
1332
1333 static void test_startSession(void)
1334 {
1335 HRESULT hr;
1336 DWORD cnt;
1337 DWORD editCookie;
1338 ITfDocumentMgr *dmtest;
1339 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1340 ITextStoreACP *ts;
1341 TfClientId cid2 = 0;
1342
1343 hr = ITfThreadMgr_Deactivate(g_tm);
1344 ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1345
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");
1350
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");
1355
1356 hr = ITfThreadMgr_Deactivate(g_tm);
1357 ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1358
1359 test_EnumDocumentMgr(g_tm,NULL,NULL);
1360
1361 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1362 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1363
1364 test_EnumDocumentMgr(g_tm,g_dm,NULL);
1365
1366 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dmtest);
1367 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1368
1369 test_EnumDocumentMgr(g_tm,dmtest,NULL);
1370
1371 ITfDocumentMgr_Release(dmtest);
1372 test_EnumDocumentMgr(g_tm,g_dm,dmtest);
1373
1374 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1375 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1376 ok(dmtest == NULL,"Initial focus not null\n");
1377
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");
1384
1385 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1386 ok(SUCCEEDED(hr),"GetFocus Failed\n");
1387 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1388
1389 cnt = ITfDocumentMgr_Release(g_dm);
1390 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1391
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);
1396
1397 TextStoreACP_Constructor((IUnknown**)&ts);
1398
1399 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1400 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1401
1402 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1403 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1404
1405 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1406 ok(SUCCEEDED(hr),"CreateContext Failed\n");
1407
1408 test_EnumContexts(g_dm, NULL);
1409
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);
1414
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");
1425
1426 test_EnumContexts(g_dm, cxt);
1427
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);
1433
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);
1439
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");
1445
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);
1452
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);
1459
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");
1464
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);
1471
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);
1478
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");
1485
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");
1490
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);
1495
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);
1500
1501 hr = ITfDocumentMgr_Pop(g_dm, 0);
1502 ok(FAILED(hr),"Pop Succeeded\n");
1503
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);
1508
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);
1513
1514 ITfContext_Release(cxt);
1515 ITfContext_Release(cxt2);
1516 ITfContext_Release(cxt3);
1517 }
1518
1519 static void test_endSession(void)
1520 {
1521 HRESULT hr;
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;
1530 }
1531
1532 static void test_TfGuidAtom(void)
1533 {
1534 GUID gtest,g1;
1535 HRESULT hr;
1536 TfGuidAtom atom1,atom2;
1537 BOOL equal;
1538
1539 CoCreateGuid(&gtest);
1540
1541 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
1542 /*
1543 hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,NULL);
1544 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1545 */
1546 hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,&atom1);
1547 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1548 hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,&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,&gtest),"guids do not match\n");
1556 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,&gtest,NULL);
1557 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1558 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,&gtest,&equal);
1559 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1560 ok(equal == TRUE,"Equal value invalid\n");
1561
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");
1569 }
1570
1571 static void test_ClientId(void)
1572 {
1573 ITfClientId *pcid;
1574 TfClientId id1,id2;
1575 HRESULT hr;
1576 GUID g2;
1577
1578 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1579 ok(SUCCEEDED(hr),"Unable to acquire ITfClientId interface\n");
1580
1581 CoCreateGuid(&g2);
1582
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);
1599 }
1600
1601 /**********************************************************************
1602 * ITfEditSession
1603 **********************************************************************/
1604 typedef struct tagEditSession
1605 {
1606 const ITfEditSessionVtbl *EditSessionVtbl;
1607 LONG refCount;
1608 } EditSession;
1609
1610 static void EditSession_Destructor(EditSession *This)
1611 {
1612 HeapFree(GetProcessHeap(),0,This);
1613 }
1614
1615 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1616 {
1617 EditSession *This = (EditSession *)iface;
1618 *ppvOut = NULL;
1619
1620 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1621 {
1622 *ppvOut = This;
1623 }
1624
1625 if (*ppvOut)
1626 {
1627 IUnknown_AddRef(iface);
1628 return S_OK;
1629 }
1630
1631 return E_NOINTERFACE;
1632 }
1633
1634 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1635 {
1636 EditSession *This = (EditSession *)iface;
1637 return InterlockedIncrement(&This->refCount);
1638 }
1639
1640 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1641 {
1642 EditSession *This = (EditSession *)iface;
1643 ULONG ret;
1644
1645 ret = InterlockedDecrement(&This->refCount);
1646 if (ret == 0)
1647 EditSession_Destructor(This);
1648 return ret;
1649 }
1650
1651 static void test_InsertAtSelection(TfEditCookie ec, ITfContext *cxt)
1652 {
1653 HRESULT hr;
1654 ITfInsertAtSelection *iis;
1655 ITfRange *range=NULL;
1656 static const WCHAR txt[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1657
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);
1667 }
1668
1669 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1670 TfEditCookie ec)
1671 {
1672 ITfContext *cxt;
1673 ITfDocumentMgr *dm;
1674 ITfRange *range;
1675 TF_SELECTION selection;
1676 ULONG fetched;
1677 HRESULT hr;
1678
1679 sink_fire_ok(&test_DoEditSession,"EditSession_DoEditSession");
1680 sink_check_ok(&test_ACP_RequestLock,"RequestLock");
1681
1682 ITfThreadMgr_GetFocus(g_tm, &dm);
1683 ITfDocumentMgr_GetTop(dm,&cxt);
1684
1685 hr = ITfContext_GetStart(cxt,ec,NULL);
1686 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1687
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");
1692
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");
1696
1697 ITfRange_Release(range);
1698
1699 hr = ITfContext_GetEnd(cxt,ec,NULL);
1700 ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1701
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");
1706
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");
1712
1713 ITfRange_Release(range);
1714
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);
1723
1724 test_InsertAtSelection(ec, cxt);
1725
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");
1731
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);
1739
1740 ITfContext_Release(cxt);
1741 ITfDocumentMgr_Release(dm);
1742 return 0xdeadcafe;
1743 }
1744
1745 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1746 {
1747 EditSession_QueryInterface,
1748 EditSession_AddRef,
1749 EditSession_Release,
1750
1751 EditSession_DoEditSession
1752 };
1753
1754 static HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1755 {
1756 EditSession *This;
1757
1758 *ppOut = NULL;
1759 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1760 if (This == NULL)
1761 return E_OUTOFMEMORY;
1762
1763 This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1764 This->refCount = 1;
1765
1766 *ppOut = (ITfEditSession*)This;
1767 return S_OK;
1768 }
1769
1770 static void test_TStoApplicationText(void)
1771 {
1772 HRESULT hr, hrSession;
1773 ITfEditSession *es;
1774 ITfContext *cxt;
1775 ITfDocumentMgr *dm;
1776 ITfTextEditSink *sink;
1777 ITfSource *source = NULL;
1778 DWORD editSinkCookie = -1;
1779
1780 ITfThreadMgr_GetFocus(g_tm, &dm);
1781 EditSession_Constructor(&es);
1782 ITfDocumentMgr_GetTop(dm,&cxt);
1783
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");
1787 if (source)
1788 {
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");
1792 }
1793
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);
1799
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");
1807
1808 /* signal a change to allow readwrite sessions */
1809 documentStatus = 0;
1810 test_ACP_RequestLock = SINK_EXPECTED;
1811 ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1812 sink_check_ok(&test_ACP_RequestLock,"RequestLock");
1813
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);
1825
1826 if (source)
1827 {
1828 hr = ITfSource_UnadviseSink(source, editSinkCookie);
1829 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
1830 ITfTextEditSink_Release(sink);
1831 ITfSource_Release(source);
1832 }
1833
1834 ITfContext_Release(cxt);
1835 ITfDocumentMgr_Release(dm);
1836 ITfEditSession_Release(es);
1837 }
1838
1839 static void enum_compartments(ITfCompartmentMgr *cmpmgr, REFGUID present, REFGUID absent)
1840 {
1841 BOOL found,found2;
1842 IEnumGUID *ppEnum;
1843 found = FALSE;
1844 found2 = FALSE;
1845 if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr, &ppEnum)))
1846 {
1847 ULONG fetched;
1848 GUID g;
1849 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
1850 {
1851 WCHAR str[50];
1852 CHAR strA[50];
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))
1857 found = TRUE;
1858 if (absent && IsEqualGUID(absent, &g))
1859 found2 = TRUE;
1860 }
1861 IEnumGUID_Release(ppEnum);
1862 }
1863 if (present)
1864 ok(found,"Did not find compartment\n");
1865 if (absent)
1866 ok(!found2,"Found compartment that should be absent\n");
1867 }
1868
1869 static void test_Compartments(void)
1870 {
1871 ITfContext *cxt;
1872 ITfDocumentMgr *dm;
1873 ITfCompartmentMgr *cmpmgr;
1874 ITfCompartment *cmp;
1875 HRESULT hr;
1876
1877 ITfThreadMgr_GetFocus(g_tm, &dm);
1878 ITfDocumentMgr_GetTop(dm,&cxt);
1879
1880 /* Global */
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);
1888
1889 /* Thread */
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);
1899
1900 /* DocumentMgr */
1901 hr = ITfDocumentMgr_QueryInterface(dm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1902 ok(SUCCEEDED(hr),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1903
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);
1908
1909 /* Context */
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);
1914
1915 ITfContext_Release(cxt);
1916 ITfDocumentMgr_Release(dm);
1917 }
1918
1919 static void processPendingMessages(void)
1920 {
1921 MSG msg;
1922 while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1923 TranslateMessage(&msg);
1924 DispatchMessage(&msg);
1925 }
1926 }
1927
1928 static void test_AssociateFocus(void)
1929 {
1930 ITfDocumentMgr *dm1, *dm2, *olddm, *dmcheck, *dmorig;
1931 HWND wnd1, wnd2, wnd3;
1932 HRESULT hr;
1933
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);
1941
1942 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm1);
1943 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1944
1945 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm2);
1946 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1947
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");
1954
1955 processPendingMessages();
1956
1957 test_OnInitDocumentMgr = SINK_OPTIONAL; /* Vista and greater */
1958 test_OnPushContext = SINK_OPTIONAL; /* Vista and greater */
1959
1960 ShowWindow(wnd1,SW_SHOWNORMAL);
1961 SetFocus(wnd1);
1962 sink_check_ok(&test_OnInitDocumentMgr,"OnInitDocumentMgr");
1963 sink_check_ok(&test_OnPushContext,"OnPushContext");
1964
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");
1970
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");
1977
1978 processPendingMessages();
1979
1980 ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1981 ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1982 ITfDocumentMgr_Release(dmcheck);
1983
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);
1990
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);
1997
1998 test_CurrentFocus = dm2;
1999 test_PrevFocus = dm1;
2000 test_OnSetFocus = SINK_OPTIONAL; /* wine and Winxp */
2001 ShowWindow(wnd2,SW_SHOWNORMAL);
2002 SetFocus(wnd2);
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();
2008
2009 ShowWindow(wnd3,SW_SHOWNORMAL);
2010 SetFocus(wnd3);
2011 processPendingMessages();
2012
2013 test_CurrentFocus = dm1;
2014 test_PrevFocus = dm2;
2015 test_OnSetFocus = SINK_EXPECTED;
2016 SetFocus(wnd1);
2017 processPendingMessages();
2018 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2019
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);
2024
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");
2031
2032 test_CurrentFocus = FOCUS_IGNORE; /* NULL on XP, system default on Vista */
2033 test_PrevFocus = dmorig;
2034 test_OnSetFocus = SINK_EXPECTED;
2035 SetFocus(wnd3);
2036 processPendingMessages();
2037 sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2038
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);
2047
2048 SetFocus(wnd2);
2049 processPendingMessages();
2050 SetFocus(wnd1);
2051 processPendingMessages();
2052
2053 ITfDocumentMgr_Release(dm1);
2054 ITfDocumentMgr_Release(dm2);
2055
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");
2062
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");
2072 }
2073
2074 START_TEST(inputprocessor)
2075 {
2076 if (SUCCEEDED(initialize()))
2077 {
2078 test_Register();
2079 test_RegisterCategory();
2080 test_EnumLanguageProfiles();
2081 test_EnumInputProcessorInfo();
2082 test_Enable();
2083 test_ThreadMgrAdviseSinks();
2084 test_Activate();
2085 test_startSession();
2086 test_TfGuidAtom();
2087 test_ClientId();
2088 test_KeystrokeMgr();
2089 test_TStoApplicationText();
2090 test_Compartments();
2091 test_AssociateFocus();
2092 test_endSession();
2093 test_FindClosestCategory();
2094 test_Disable();
2095 test_ThreadMgrUnadviseSinks();
2096 test_UnregisterCategory();
2097 test_Unregister();
2098 }
2099 else
2100 skip("Unable to create InputProcessor\n");
2101 cleanup();
2102 }