msctf/tests: Make _sink_check_ok() static.
[wine] / dlls / msctf / tests / 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
125     switch (action)
126     {
127         case SINK_OPTIONAL:
128             if (winetest_interactive)
129                 winetest_trace("optional sink %s not fired\n",name);
130         case SINK_FIRED:
131             break;
132         case SINK_IGNORE:
133             return;
134         default:
135             winetest_ok(0, "%s not fired as expected, in state %x\n",name,*sink);
136     }
137     *sink = SINK_UNEXPECTED;
138 }
139
140 #define sink_check_ok(a,b) (winetest_set_location(__FILE__,__LINE__), 0) ? 0 : _sink_check_ok(a,b)
141
142 /**********************************************************************
143  * ITextStoreACP
144  **********************************************************************/
145 typedef struct tagTextStoreACP
146 {
147     const ITextStoreACPVtbl *TextStoreACPVtbl;
148     LONG refCount;
149
150 } TextStoreACP;
151
152 static void TextStoreACP_Destructor(TextStoreACP *This)
153 {
154     HeapFree(GetProcessHeap(),0,This);
155 }
156
157 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
158 {
159     TextStoreACP *This = (TextStoreACP *)iface;
160     *ppvOut = NULL;
161
162     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
163     {
164         *ppvOut = This;
165     }
166
167     if (*ppvOut)
168     {
169         IUnknown_AddRef(iface);
170         return S_OK;
171     }
172
173     return E_NOINTERFACE;
174 }
175
176 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
177 {
178     TextStoreACP *This = (TextStoreACP *)iface;
179     return InterlockedIncrement(&This->refCount);
180 }
181
182 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
183 {
184     TextStoreACP *This = (TextStoreACP *)iface;
185     ULONG ret;
186
187     ret = InterlockedDecrement(&This->refCount);
188     if (ret == 0)
189         TextStoreACP_Destructor(This);
190     return ret;
191 }
192
193 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
194     REFIID riid, IUnknown *punk, DWORD dwMask)
195 {
196     HRESULT hr;
197
198     sink_fire_ok(&test_ACP_AdviseSink,"TextStoreACP_AdviseSink");
199
200     hr = IUnknown_QueryInterface(punk, &IID_ITextStoreACPSink,(LPVOID*)(&ACPSink));
201     ok(SUCCEEDED(hr),"Unable to QueryInterface on sink\n");
202     return S_OK;
203 }
204
205 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
206     IUnknown *punk)
207 {
208     trace("\n");
209     return S_OK;
210 }
211
212 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
213     DWORD dwLockFlags, HRESULT *phrSession)
214 {
215     sink_fire_ok(&test_ACP_RequestLock,"TextStoreACP_RequestLock");
216     *phrSession = ITextStoreACPSink_OnLockGranted(ACPSink, dwLockFlags);
217     return S_OK;
218 }
219 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
220     TS_STATUS *pdcs)
221 {
222     sink_fire_ok(&test_ACP_GetStatus,"TextStoreACP_GetStatus");
223     pdcs->dwDynamicFlags = documentStatus;
224     return S_OK;
225 }
226 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
227     LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
228     LONG *pacpResultEnd)
229 {
230     trace("\n");
231     return S_OK;
232 }
233 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
234     ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
235 {
236     sink_fire_ok(&test_ACP_GetSelection,"TextStoreACP_GetSelection");
237
238     pSelection->acpStart = 10;
239     pSelection->acpEnd = 20;
240     pSelection->style.fInterimChar = 0;
241     pSelection->style.ase = TS_AE_NONE;
242     *pcFetched = 1;
243
244     return S_OK;
245 }
246 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
247     ULONG ulCount, const TS_SELECTION_ACP *pSelection)
248 {
249     sink_fire_ok(&test_ACP_SetSelection,"TextStoreACP_SetSelection");
250     return S_OK;
251 }
252 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
253     LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
254     ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
255     ULONG *pcRunInfoRet, LONG *pacpNext)
256 {
257     trace("\n");
258     return S_OK;
259 }
260 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
261     DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
262     ULONG cch, TS_TEXTCHANGE *pChange)
263 {
264     trace("\n");
265     return S_OK;
266 }
267 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
268     LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
269 {
270     trace("\n");
271     return S_OK;
272 }
273 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
274     LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
275 {
276     trace("\n");
277     return S_OK;
278 }
279 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
280     const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
281 {
282     trace("\n");
283     return S_OK;
284 }
285 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
286     DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
287     TS_TEXTCHANGE *pChange)
288 {
289     trace("\n");
290     return S_OK;
291 }
292 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
293     DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
294     LONG *pacpEnd, TS_TEXTCHANGE *pChange)
295 {
296     sink_fire_ok(&test_ACP_InsertTextAtSelection,"TextStoreACP_InsertTextAtSelection");
297     return S_OK;
298 }
299 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
300     DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
301     TS_TEXTCHANGE *pChange)
302 {
303     trace("\n");
304     return S_OK;
305 }
306 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
307     DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
308 {
309     trace("\n");
310     return S_OK;
311 }
312 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
313     LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
314     DWORD dwFlags)
315 {
316     trace("\n");
317     return S_OK;
318 }
319 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
320     LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
321     DWORD dwFlags)
322 {
323     trace("\n");
324     return S_OK;
325 }
326 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
327     LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
328     DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
329 {
330     trace("\n");
331     return S_OK;
332 }
333 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
334     ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
335 {
336     trace("\n");
337     return S_OK;
338 }
339 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
340     LONG *pacp)
341 {
342     sink_fire_ok(&test_ACP_GetEndACP,"TextStoreACP_GetEndACP");
343     return S_OK;
344 }
345 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
346     TsViewCookie *pvcView)
347 {
348     trace("\n");
349     return S_OK;
350 }
351 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
352     TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
353     LONG *pacp)
354 {
355     trace("\n");
356     return S_OK;
357 }
358 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
359     TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
360     BOOL *pfClipped)
361 {
362     trace("\n");
363     return S_OK;
364 }
365 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
366     TsViewCookie vcView, RECT *prc)
367 {
368     trace("\n");
369     return S_OK;
370 }
371 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
372     TsViewCookie vcView, HWND *phwnd)
373 {
374     trace("\n");
375     return S_OK;
376 }
377
378 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
379 {
380     TextStoreACP_QueryInterface,
381     TextStoreACP_AddRef,
382     TextStoreACP_Release,
383
384     TextStoreACP_AdviseSink,
385     TextStoreACP_UnadviseSink,
386     TextStoreACP_RequestLock,
387     TextStoreACP_GetStatus,
388     TextStoreACP_QueryInsert,
389     TextStoreACP_GetSelection,
390     TextStoreACP_SetSelection,
391     TextStoreACP_GetText,
392     TextStoreACP_SetText,
393     TextStoreACP_GetFormattedText,
394     TextStoreACP_GetEmbedded,
395     TextStoreACP_QueryInsertEmbedded,
396     TextStoreACP_InsertEmbedded,
397     TextStoreACP_InsertTextAtSelection,
398     TextStoreACP_InsertEmbeddedAtSelection,
399     TextStoreACP_RequestSupportedAttrs,
400     TextStoreACP_RequestAttrsAtPosition,
401     TextStoreACP_RequestAttrsTransitioningAtPosition,
402     TextStoreACP_FindNextAttrTransition,
403     TextStoreACP_RetrieveRequestedAttrs,
404     TextStoreACP_GetEndACP,
405     TextStoreACP_GetActiveView,
406     TextStoreACP_GetACPFromPoint,
407     TextStoreACP_GetTextExt,
408     TextStoreACP_GetScreenExt,
409     TextStoreACP_GetWnd
410 };
411
412 static HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
413 {
414     TextStoreACP *This;
415
416     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
417     if (This == NULL)
418         return E_OUTOFMEMORY;
419
420     This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
421     This->refCount = 1;
422
423     *ppOut = (IUnknown *)This;
424     return S_OK;
425 }
426
427 /**********************************************************************
428  * ITfThreadMgrEventSink
429  **********************************************************************/
430 typedef struct tagThreadMgrEventSink
431 {
432     const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
433     LONG refCount;
434 } ThreadMgrEventSink;
435
436 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
437 {
438     HeapFree(GetProcessHeap(),0,This);
439 }
440
441 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
442 {
443     ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
444     *ppvOut = NULL;
445
446     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
447     {
448         *ppvOut = This;
449     }
450
451     if (*ppvOut)
452     {
453         IUnknown_AddRef(iface);
454         return S_OK;
455     }
456
457     return E_NOINTERFACE;
458 }
459
460 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
461 {
462     ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
463     ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
464     return InterlockedIncrement(&This->refCount);
465 }
466
467 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
468 {
469     ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
470     ULONG ret;
471
472     ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
473     ret = InterlockedDecrement(&This->refCount);
474     if (ret == 0)
475         ThreadMgrEventSink_Destructor(This);
476     return ret;
477 }
478
479 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
480 ITfDocumentMgr *pdim)
481 {
482     sink_fire_ok(&test_OnInitDocumentMgr,"ThreadMgrEventSink_OnInitDocumentMgr");
483     return S_OK;
484 }
485
486 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
487 ITfDocumentMgr *pdim)
488 {
489     trace("\n");
490     return S_OK;
491 }
492
493 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
494 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
495 {
496     sink_fire_ok(&test_OnSetFocus,"ThreadMgrEventSink_OnSetFocus");
497     if (test_CurrentFocus != FOCUS_IGNORE)
498         ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
499     if (test_PrevFocus != FOCUS_IGNORE)
500         ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
501     return S_OK;
502 }
503
504 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
505 ITfContext *pic)
506 {
507     HRESULT hr;
508     ITfDocumentMgr *docmgr;
509     ITfContext *test;
510
511     hr = ITfContext_GetDocumentMgr(pic,&docmgr);
512     ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
513     test = (ITfContext*)0xdeadbeef;
514     ITfDocumentMgr_Release(docmgr);
515     hr = ITfDocumentMgr_GetTop(docmgr,&test);
516     ok(SUCCEEDED(hr),"GetTop failed\n");
517     ok(test == pic, "Wrong context is on top\n");
518     if (test)
519         ITfContext_Release(test);
520
521     sink_fire_ok(&test_OnPushContext,"ThreadMgrEventSink_OnPushContext");
522     return S_OK;
523 }
524
525 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
526 ITfContext *pic)
527 {
528     HRESULT hr;
529     ITfDocumentMgr *docmgr;
530     ITfContext *test;
531
532     hr = ITfContext_GetDocumentMgr(pic,&docmgr);
533     ok(SUCCEEDED(hr),"GetDocumenMgr failed\n");
534     ITfDocumentMgr_Release(docmgr);
535     test = (ITfContext*)0xdeadbeef;
536     hr = ITfDocumentMgr_GetTop(docmgr,&test);
537     ok(SUCCEEDED(hr),"GetTop failed\n");
538     ok(test == pic, "Wrong context is on top\n");
539     if (test)
540         ITfContext_Release(test);
541
542     sink_fire_ok(&test_OnPopContext,"ThreadMgrEventSink_OnPopContext");
543     return S_OK;
544 }
545
546 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
547 {
548     ThreadMgrEventSink_QueryInterface,
549     ThreadMgrEventSink_AddRef,
550     ThreadMgrEventSink_Release,
551
552     ThreadMgrEventSink_OnInitDocumentMgr,
553     ThreadMgrEventSink_OnUninitDocumentMgr,
554     ThreadMgrEventSink_OnSetFocus,
555     ThreadMgrEventSink_OnPushContext,
556     ThreadMgrEventSink_OnPopContext
557 };
558
559 static HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
560 {
561     ThreadMgrEventSink *This;
562
563     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
564     if (This == NULL)
565         return E_OUTOFMEMORY;
566
567     This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
568     This->refCount = 1;
569
570     *ppOut = (IUnknown *)This;
571     return S_OK;
572 }
573
574
575 /********************************************************************************************
576  * Stub text service for testing
577  ********************************************************************************************/
578
579 static LONG TS_refCount;
580 static IClassFactory *cf;
581 static DWORD regid;
582
583 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
584
585 typedef struct tagClassFactory
586 {
587     const IClassFactoryVtbl *vtbl;
588     LONG   ref;
589     LPFNCONSTRUCTOR ctor;
590 } ClassFactory;
591
592 typedef struct tagTextService
593 {
594     const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
595     LONG refCount;
596 } TextService;
597
598 static void ClassFactory_Destructor(ClassFactory *This)
599 {
600     HeapFree(GetProcessHeap(),0,This);
601     TS_refCount--;
602 }
603
604 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
605 {
606     *ppvOut = NULL;
607     if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
608     {
609         IClassFactory_AddRef(iface);
610         *ppvOut = iface;
611         return S_OK;
612     }
613
614     return E_NOINTERFACE;
615 }
616
617 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
618 {
619     ClassFactory *This = (ClassFactory *)iface;
620     return InterlockedIncrement(&This->ref);
621 }
622
623 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
624 {
625     ClassFactory *This = (ClassFactory *)iface;
626     ULONG ret = InterlockedDecrement(&This->ref);
627
628     if (ret == 0)
629         ClassFactory_Destructor(This);
630     return ret;
631 }
632
633 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
634 {
635     ClassFactory *This = (ClassFactory *)iface;
636     HRESULT ret;
637     IUnknown *obj;
638
639     ret = This->ctor(punkOuter, &obj);
640     if (FAILED(ret))
641         return ret;
642     ret = IUnknown_QueryInterface(obj, iid, ppvOut);
643     IUnknown_Release(obj);
644     return ret;
645 }
646
647 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
648 {
649     if(fLock)
650         InterlockedIncrement(&TS_refCount);
651     else
652         InterlockedDecrement(&TS_refCount);
653
654     return S_OK;
655 }
656
657 static const IClassFactoryVtbl ClassFactoryVtbl = {
658     /* IUnknown */
659     ClassFactory_QueryInterface,
660     ClassFactory_AddRef,
661     ClassFactory_Release,
662
663     /* IClassFactory*/
664     ClassFactory_CreateInstance,
665     ClassFactory_LockServer
666 };
667
668 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
669 {
670     ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
671     This->vtbl = &ClassFactoryVtbl;
672     This->ref = 1;
673     This->ctor = ctor;
674     *ppvOut = (LPVOID)This;
675     TS_refCount++;
676     return S_OK;
677 }
678
679 static void TextService_Destructor(TextService *This)
680 {
681     HeapFree(GetProcessHeap(),0,This);
682 }
683
684 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
685 {
686     TextService *This = (TextService *)iface;
687     *ppvOut = NULL;
688
689     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
690     {
691         *ppvOut = This;
692     }
693
694     if (*ppvOut)
695     {
696         IUnknown_AddRef(iface);
697         return S_OK;
698     }
699
700     return E_NOINTERFACE;
701 }
702
703 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
704 {
705     TextService *This = (TextService *)iface;
706     return InterlockedIncrement(&This->refCount);
707 }
708
709 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
710 {
711     TextService *This = (TextService *)iface;
712     ULONG ret;
713
714     ret = InterlockedDecrement(&This->refCount);
715     if (ret == 0)
716         TextService_Destructor(This);
717     return ret;
718 }
719
720 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
721         ITfThreadMgr *ptim, TfClientId id)
722 {
723     trace("TextService_Activate\n");
724     ok(test_ShouldActivate,"Activation came unexpectedly\n");
725     tid = id;
726     return S_OK;
727 }
728
729 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
730 {
731     trace("TextService_Deactivate\n");
732     ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
733     return S_OK;
734 }
735
736 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
737 {
738     TextService_QueryInterface,
739     TextService_AddRef,
740     TextService_Release,
741
742     TextService_Activate,
743     TextService_Deactivate
744 };
745
746 static HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
747 {
748     TextService *This;
749     if (pUnkOuter)
750         return CLASS_E_NOAGGREGATION;
751
752     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
753     if (This == NULL)
754         return E_OUTOFMEMORY;
755
756     This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
757     This->refCount = 1;
758
759     *ppOut = (IUnknown *)This;
760     return S_OK;
761 }
762
763 static HRESULT RegisterTextService(REFCLSID rclsid)
764 {
765     ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
766     return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
767 }
768
769 static HRESULT UnregisterTextService()
770 {
771     return CoRevokeClassObject(regid);
772 }
773
774 /*
775  * The tests
776  */
777
778 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
779 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
780 DEFINE_GUID(CLSID_TF_CategoryMgr,         0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
781 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD,     0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
782 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH,       0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
783 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING,  0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
784 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER,  0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
785 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
786 DEFINE_GUID(CLSID_TF_ThreadMgr,           0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
787 DEFINE_GUID(CLSID_PreservedKey,           0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
788 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_DISABLED,     0x71a5b253,0x1951,0x466b,0x9f,0xbc,0x9c,0x88,0x08,0xfa,0x84,0xf2);
789 DEFINE_GUID(GUID_COMPARTMENT_KEYBOARD_OPENCLOSE,    0x58273aad,0x01bb,0x4164,0x95,0xc6,0x75,0x5b,0xa0,0xb5,0x16,0x2d);
790 DEFINE_GUID(GUID_COMPARTMENT_HANDWRITING_OPENCLOSE, 0xf9ae2c6b,0x1866,0x4361,0xaf,0x72,0x7a,0xa3,0x09,0x48,0x89,0x0e);
791 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_DISABLED,       0x56c5c607,0x0703,0x4e59,0x8e,0x52,0xcb,0xc8,0x4e,0x8b,0xbe,0x35);
792 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_OPENCLOSE,      0x544d6a63,0xe2e8,0x4752,0xbb,0xd1,0x00,0x09,0x60,0xbc,0xa0,0x83);
793 DEFINE_GUID(GUID_COMPARTMENT_SPEECH_GLOBALSTATE,    0x2a54fe8e,0x0d08,0x460c,0xa7,0x5d,0x87,0x03,0x5f,0xf4,0x36,0xc5);
794 DEFINE_GUID(GUID_COMPARTMENT_PERSISTMENUENABLED,    0x575f3783,0x70c8,0x47c8,0xae,0x5d,0x91,0xa0,0x1a,0x1f,0x75,0x92);
795 DEFINE_GUID(GUID_COMPARTMENT_EMPTYCONTEXT,          0xd7487dbf,0x804e,0x41c5,0x89,0x4d,0xad,0x96,0xfd,0x4e,0xea,0x13);
796 DEFINE_GUID(GUID_COMPARTMENT_TIPUISTATUS,           0x148ca3ec,0x0366,0x401c,0x8d,0x75,0xed,0x97,0x8d,0x85,0xfb,0xc9);
797
798 static HRESULT initialize(void)
799 {
800     HRESULT hr;
801     CoInitialize(NULL);
802     hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
803           CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
804     if (SUCCEEDED(hr))
805         hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
806           CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
807     if (SUCCEEDED(hr))
808         hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
809           CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
810     return hr;
811 }
812
813 static void cleanup(void)
814 {
815     if (g_ipp)
816         ITfInputProcessorProfiles_Release(g_ipp);
817     if (g_cm)
818         ITfCategoryMgr_Release(g_cm);
819     if (g_tm)
820         ITfThreadMgr_Release(g_tm);
821     CoUninitialize();
822 }
823
824 static void test_Register(void)
825 {
826     HRESULT hr;
827
828     static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
829     static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
830
831     hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
832     ok(SUCCEEDED(hr),"Unable to get current language id\n");
833     trace("Current Language %x\n",gLangid);
834
835     hr = RegisterTextService(&CLSID_FakeService);
836     ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
837     hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
838     ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
839     hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
840     ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
841 }
842
843 static void test_Unregister(void)
844 {
845     HRESULT hr;
846     hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
847     ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
848     UnregisterTextService();
849 }
850
851 static void test_EnumInputProcessorInfo(void)
852 {
853     IEnumGUID *ppEnum;
854     BOOL found = FALSE;
855
856     if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
857     {
858         ULONG fetched;
859         GUID g;
860         while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
861         {
862             if(IsEqualGUID(&g,&CLSID_FakeService))
863                 found = TRUE;
864         }
865     }
866     ok(found,"Did not find registered text service\n");
867 }
868
869 static void test_EnumLanguageProfiles(void)
870 {
871     BOOL found = FALSE;
872     IEnumTfLanguageProfiles *ppEnum;
873     if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
874     {
875         TF_LANGUAGEPROFILE profile;
876         while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
877         {
878             if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
879             {
880                 found = TRUE;
881                 ok(profile.langid == gLangid, "LangId Incorrect\n");
882                 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
883                 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
884             }
885         }
886     }
887     ok(found,"Registered text service not found\n");
888 }
889
890 static void test_RegisterCategory(void)
891 {
892     HRESULT hr;
893     hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
894     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
895     hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
896     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
897 }
898
899 static void test_UnregisterCategory(void)
900 {
901     HRESULT hr;
902     hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
903     ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
904     hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
905     ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
906 }
907
908 static void test_FindClosestCategory(void)
909 {
910     GUID output;
911     HRESULT hr;
912     const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
913
914     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
915     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
916     ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
917
918     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
919     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
920     ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
921
922     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
923     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
924     ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
925 }
926
927 static void test_Enable(void)
928 {
929     HRESULT hr;
930     BOOL enabled = FALSE;
931
932     hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
933     ok(SUCCEEDED(hr),"Failed to enable text service\n");
934     hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
935     ok(SUCCEEDED(hr),"Failed to get enabled state\n");
936     ok(enabled == TRUE,"enabled state incorrect\n");
937 }
938
939 static void test_Disable(void)
940 {
941     HRESULT hr;
942
943     trace("Disabling\n");
944     hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
945     ok(SUCCEEDED(hr),"Failed to disable text service\n");
946 }
947
948 static void test_ThreadMgrAdviseSinks(void)
949 {
950     ITfSource *source = NULL;
951     HRESULT hr;
952     IUnknown *sink;
953
954     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
955     ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
956     if (!source)
957         return;
958
959     hr = ThreadMgrEventSink_Constructor(&sink);
960     ok(hr == S_OK, "got %08x\n", hr);
961     if(FAILED(hr)) return;
962
963     tmSinkRefCount = 1;
964     tmSinkCookie = 0;
965     hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
966     ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
967     ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
968
969     /* Advising the sink adds a ref, Relesing here lets the object be deleted
970        when unadvised */
971     tmSinkRefCount = 2;
972     IUnknown_Release(sink);
973     ITfSource_Release(source);
974 }
975
976 static void test_ThreadMgrUnadviseSinks(void)
977 {
978     ITfSource *source = NULL;
979     HRESULT hr;
980
981     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
982     ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
983     if (!source)
984         return;
985
986     tmSinkRefCount = 1;
987     hr = ITfSource_UnadviseSink(source, tmSinkCookie);
988     ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
989     ITfSource_Release(source);
990 }
991
992 /**********************************************************************
993  * ITfKeyEventSink
994  **********************************************************************/
995 typedef struct tagKeyEventSink
996 {
997     const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
998     LONG refCount;
999 } KeyEventSink;
1000
1001 static void KeyEventSink_Destructor(KeyEventSink *This)
1002 {
1003     HeapFree(GetProcessHeap(),0,This);
1004 }
1005
1006 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
1007 {
1008     KeyEventSink *This = (KeyEventSink *)iface;
1009     *ppvOut = NULL;
1010
1011     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
1012     {
1013         *ppvOut = This;
1014     }
1015
1016     if (*ppvOut)
1017     {
1018         IUnknown_AddRef(iface);
1019         return S_OK;
1020     }
1021
1022     return E_NOINTERFACE;
1023 }
1024
1025 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
1026 {
1027     KeyEventSink *This = (KeyEventSink *)iface;
1028     return InterlockedIncrement(&This->refCount);
1029 }
1030
1031 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
1032 {
1033     KeyEventSink *This = (KeyEventSink *)iface;
1034     ULONG ret;
1035
1036     ret = InterlockedDecrement(&This->refCount);
1037     if (ret == 0)
1038         KeyEventSink_Destructor(This);
1039     return ret;
1040 }
1041
1042 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
1043         BOOL fForeground)
1044 {
1045     sink_fire_ok(&test_KEV_OnSetFocus,"KeyEventSink_OnSetFocus");
1046     return S_OK;
1047 }
1048
1049 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
1050         ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1051 {
1052     trace("\n");
1053     return S_OK;
1054 }
1055
1056 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
1057         ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1058 {
1059     trace("\n");
1060     return S_OK;
1061 }
1062
1063 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
1064         ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1065 {
1066     trace("\n");
1067     return S_OK;
1068 }
1069
1070 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
1071         ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
1072 {
1073     trace("\n");
1074     return S_OK;
1075 }
1076
1077 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
1078     ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
1079 {
1080     trace("\n");
1081     return S_OK;
1082 }
1083
1084 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
1085 {
1086     KeyEventSink_QueryInterface,
1087     KeyEventSink_AddRef,
1088     KeyEventSink_Release,
1089
1090     KeyEventSink_OnSetFocus,
1091     KeyEventSink_OnTestKeyDown,
1092     KeyEventSink_OnTestKeyUp,
1093     KeyEventSink_OnKeyDown,
1094     KeyEventSink_OnKeyUp,
1095     KeyEventSink_OnPreservedKey
1096 };
1097
1098 static HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
1099 {
1100     KeyEventSink *This;
1101
1102     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
1103     if (This == NULL)
1104         return E_OUTOFMEMORY;
1105
1106     This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
1107     This->refCount = 1;
1108
1109     *ppOut = (ITfKeyEventSink*)This;
1110     return S_OK;
1111 }
1112
1113
1114 static void test_KeystrokeMgr(void)
1115 {
1116     ITfKeystrokeMgr *keymgr= NULL;
1117     HRESULT hr;
1118     TF_PRESERVEDKEY tfpk;
1119     BOOL preserved;
1120     ITfKeyEventSink *sink = NULL;
1121
1122     KeyEventSink_Constructor(&sink);
1123
1124     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
1125     ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
1126
1127     tfpk.uVKey = 'A';
1128     tfpk.uModifiers = TF_MOD_SHIFT;
1129
1130     test_KEV_OnSetFocus = SINK_EXPECTED;
1131     hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1132     ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
1133     sink_check_ok(&test_KEV_OnSetFocus,"KeyEventSink_OnSetFocus");
1134     hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
1135     ok(hr == CONNECT_E_ADVISELIMIT,"Wrong return, expected CONNECT_E_ADVISELIMIT\n");
1136     hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,cid,sink,TRUE);
1137     ok(hr == E_INVALIDARG,"Wrong return, expected E_INVALIDARG\n");
1138
1139     hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
1140     ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1141
1142     hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1143     ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
1144
1145     hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
1146     ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
1147
1148     preserved = FALSE;
1149     hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1150     ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1151     if (hr == S_OK) ok(preserved == TRUE,"misreporting preserved key\n");
1152
1153     hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1154     ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
1155
1156     hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
1157     ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
1158     if (hr == S_FALSE) ok(preserved == FALSE,"misreporting preserved key\n");
1159
1160     hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
1161     ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
1162
1163     hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
1164     ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
1165
1166     ITfKeystrokeMgr_Release(keymgr);
1167     ITfKeyEventSink_Release(sink);
1168 }
1169
1170 static void test_Activate(void)
1171 {
1172     HRESULT hr;
1173
1174     hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
1175     ok(SUCCEEDED(hr),"Failed to Activate text service\n");
1176 }
1177
1178
1179 static void test_EnumContexts(ITfDocumentMgr *dm, ITfContext *search)
1180 {
1181     HRESULT hr;
1182     IEnumTfContexts* pEnum;
1183     BOOL found = FALSE;
1184
1185     hr = ITfDocumentMgr_EnumContexts(dm,&pEnum);
1186     ok(SUCCEEDED(hr),"EnumContexts failed\n");
1187     if (SUCCEEDED(hr))
1188     {
1189         ULONG fetched;
1190         ITfContext *cxt;
1191         while (IEnumTfContexts_Next(pEnum, 1, &cxt, &fetched) == S_OK)
1192         {
1193             if (!search)
1194                 found = TRUE;
1195             else if (search == cxt)
1196                 found = TRUE;
1197             ITfContext_Release(cxt);
1198         }
1199         IEnumTfContexts_Release(pEnum);
1200     }
1201     if (search)
1202         ok(found,"Did not find proper ITfContext\n");
1203     else
1204         ok(!found,"Found an ITfContext we should should not have\n");
1205 }
1206
1207 static void test_EnumDocumentMgr(ITfThreadMgr *tm, ITfDocumentMgr *search, ITfDocumentMgr *absent)
1208 {
1209     HRESULT hr;
1210     IEnumTfDocumentMgrs* pEnum;
1211     BOOL found = FALSE;
1212     BOOL notfound = TRUE;
1213
1214     hr = ITfThreadMgr_EnumDocumentMgrs(tm,&pEnum);
1215     ok(SUCCEEDED(hr),"EnumDocumentMgrs failed\n");
1216     if (SUCCEEDED(hr))
1217     {
1218         ULONG fetched;
1219         ITfDocumentMgr *dm;
1220         while (IEnumTfDocumentMgrs_Next(pEnum, 1, &dm, &fetched) == S_OK)
1221         {
1222             if (!search)
1223                 found = TRUE;
1224             else if (search == dm)
1225                 found = TRUE;
1226             if (absent && dm == absent)
1227                 notfound = FALSE;
1228             ITfDocumentMgr_Release(dm);
1229         }
1230         IEnumTfDocumentMgrs_Release(pEnum);
1231     }
1232     if (search)
1233         ok(found,"Did not find proper ITfDocumentMgr\n");
1234     else
1235         ok(!found,"Found an ITfDocumentMgr we should should not have\n");
1236     if (absent)
1237         ok(notfound,"Found an ITfDocumentMgr we believe should be absent\n");
1238 }
1239
1240 static inline int check_context_refcount(ITfContext *iface)
1241 {
1242     IUnknown_AddRef(iface);
1243     return IUnknown_Release(iface);
1244 }
1245
1246
1247 /**********************************************************************
1248  * ITfTextEditSink
1249  **********************************************************************/
1250 typedef struct tagTextEditSink
1251 {
1252     const ITfTextEditSinkVtbl *TextEditSinkVtbl;
1253     LONG refCount;
1254 } TextEditSink;
1255
1256 static void TextEditSink_Destructor(TextEditSink *This)
1257 {
1258     HeapFree(GetProcessHeap(),0,This);
1259 }
1260
1261 static HRESULT WINAPI TextEditSink_QueryInterface(ITfTextEditSink *iface, REFIID iid, LPVOID *ppvOut)
1262 {
1263     TextEditSink *This = (TextEditSink *)iface;
1264     *ppvOut = NULL;
1265
1266     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextEditSink))
1267     {
1268         *ppvOut = This;
1269     }
1270
1271     if (*ppvOut)
1272     {
1273         IUnknown_AddRef(iface);
1274         return S_OK;
1275     }
1276
1277     return E_NOINTERFACE;
1278 }
1279
1280 static ULONG WINAPI TextEditSink_AddRef(ITfTextEditSink *iface)
1281 {
1282     TextEditSink *This = (TextEditSink *)iface;
1283     return InterlockedIncrement(&This->refCount);
1284 }
1285
1286 static ULONG WINAPI TextEditSink_Release(ITfTextEditSink *iface)
1287 {
1288     TextEditSink *This = (TextEditSink *)iface;
1289     ULONG ret;
1290
1291     ret = InterlockedDecrement(&This->refCount);
1292     if (ret == 0)
1293         TextEditSink_Destructor(This);
1294     return ret;
1295 }
1296
1297 static HRESULT WINAPI TextEditSink_OnEndEdit(ITfTextEditSink *iface,
1298     ITfContext *pic, TfEditCookie ecReadOnly, ITfEditRecord *pEditRecord)
1299 {
1300     sink_fire_ok(&test_OnEndEdit,"TextEditSink_OnEndEdit");
1301     return S_OK;
1302 }
1303
1304 static const ITfTextEditSinkVtbl TextEditSink_TextEditSinkVtbl =
1305 {
1306     TextEditSink_QueryInterface,
1307     TextEditSink_AddRef,
1308     TextEditSink_Release,
1309
1310     TextEditSink_OnEndEdit
1311 };
1312
1313 static HRESULT TextEditSink_Constructor(ITfTextEditSink **ppOut)
1314 {
1315     TextEditSink *This;
1316
1317     *ppOut = NULL;
1318     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextEditSink));
1319     if (This == NULL)
1320         return E_OUTOFMEMORY;
1321
1322     This->TextEditSinkVtbl = &TextEditSink_TextEditSinkVtbl;
1323     This->refCount = 1;
1324
1325     *ppOut = (ITfTextEditSink*)This;
1326     return S_OK;
1327 }
1328
1329 static void test_startSession(void)
1330 {
1331     HRESULT hr;
1332     DWORD cnt;
1333     DWORD editCookie;
1334     ITfDocumentMgr *dmtest;
1335     ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
1336     ITextStoreACP *ts;
1337     TfClientId cid2 = 0;
1338
1339     hr = ITfThreadMgr_Deactivate(g_tm);
1340     ok(hr == E_UNEXPECTED,"Deactivate should have failed with E_UNEXPECTED\n");
1341
1342     test_ShouldActivate = TRUE;
1343     hr  = ITfThreadMgr_Activate(g_tm,&cid);
1344     ok(SUCCEEDED(hr),"Failed to Activate\n");
1345     ok(cid != tid,"TextService id mistakenly matches Client id\n");
1346
1347     test_ShouldActivate = FALSE;
1348     hr = ITfThreadMgr_Activate(g_tm,&cid2);
1349     ok(SUCCEEDED(hr),"Failed to Activate\n");
1350     ok (cid == cid2, "Second activate client ID does not match\n");
1351
1352     hr = ITfThreadMgr_Deactivate(g_tm);
1353     ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1354
1355     test_EnumDocumentMgr(g_tm,NULL,NULL);
1356
1357     hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
1358     ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1359
1360     test_EnumDocumentMgr(g_tm,g_dm,NULL);
1361
1362     hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dmtest);
1363     ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1364
1365     test_EnumDocumentMgr(g_tm,dmtest,NULL);
1366
1367     ITfDocumentMgr_Release(dmtest);
1368     test_EnumDocumentMgr(g_tm,g_dm,dmtest);
1369
1370     hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1371     ok(SUCCEEDED(hr),"GetFocus Failed\n");
1372     ok(dmtest == NULL,"Initial focus not null\n");
1373
1374     test_CurrentFocus = g_dm;
1375     test_PrevFocus = NULL;
1376     test_OnSetFocus  = SINK_EXPECTED;
1377     hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
1378     ok(SUCCEEDED(hr),"SetFocus Failed\n");
1379     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1380
1381     hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1382     ok(SUCCEEDED(hr),"GetFocus Failed\n");
1383     ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1384
1385     cnt = ITfDocumentMgr_Release(g_dm);
1386     ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
1387
1388     hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
1389     ok(SUCCEEDED(hr),"GetFocus Failed\n");
1390     ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
1391     ITfDocumentMgr_Release(dmtest);
1392
1393     TextStoreACP_Constructor((IUnknown**)&ts);
1394
1395     hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
1396     ok(SUCCEEDED(hr),"CreateContext Failed\n");
1397
1398     hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
1399     ok(SUCCEEDED(hr),"CreateContext Failed\n");
1400
1401     hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
1402     ok(SUCCEEDED(hr),"CreateContext Failed\n");
1403
1404     test_EnumContexts(g_dm, NULL);
1405
1406     hr = ITfContext_GetDocumentMgr(cxt,&dmtest);
1407     ok(hr == S_OK, "ITfContext_GetDocumentMgr failed with %x\n",hr);
1408     ok(dmtest == g_dm, "Wrong documentmgr\n");
1409     ITfDocumentMgr_Release(dmtest);
1410
1411     cnt = check_context_refcount(cxt);
1412     test_OnPushContext = SINK_EXPECTED;
1413     test_ACP_AdviseSink = SINK_EXPECTED;
1414     test_OnInitDocumentMgr = SINK_EXPECTED;
1415     hr = ITfDocumentMgr_Push(g_dm, cxt);
1416     ok(SUCCEEDED(hr),"Push Failed\n");
1417     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1418     sink_check_ok(&test_OnPushContext,"OnPushContext");
1419     sink_check_ok(&test_OnInitDocumentMgr,"OnInitDocumentMgr");
1420     sink_check_ok(&test_ACP_AdviseSink,"TextStoreACP_AdviseSink");
1421
1422     test_EnumContexts(g_dm, cxt);
1423
1424     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1425     ok(SUCCEEDED(hr),"GetTop Failed\n");
1426     ok(cxtTest == cxt, "Wrong context on top\n");
1427     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1428     cnt = ITfContext_Release(cxtTest);
1429
1430     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1431     ok(SUCCEEDED(hr),"GetBase Failed\n");
1432     ok(cxtTest == cxt, "Wrong context on Base\n");
1433     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1434     ITfContext_Release(cxtTest);
1435
1436     check_context_refcount(cxt2);
1437     test_OnPushContext = SINK_EXPECTED;
1438     hr = ITfDocumentMgr_Push(g_dm, cxt2);
1439     ok(SUCCEEDED(hr),"Push Failed\n");
1440     sink_check_ok(&test_OnPushContext,"OnPushContext");
1441
1442     cnt = check_context_refcount(cxt2);
1443     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1444     ok(SUCCEEDED(hr),"GetTop Failed\n");
1445     ok(cxtTest == cxt2, "Wrong context on top\n");
1446     ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1447     ITfContext_Release(cxtTest);
1448
1449     cnt = check_context_refcount(cxt);
1450     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1451     ok(SUCCEEDED(hr),"GetBase Failed\n");
1452     ok(cxtTest == cxt, "Wrong context on Base\n");
1453     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1454     ITfContext_Release(cxtTest);
1455
1456     cnt = check_context_refcount(cxt3);
1457     hr = ITfDocumentMgr_Push(g_dm, cxt3);
1458     ok(FAILED(hr),"Push Succeeded\n");
1459     ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
1460
1461     cnt = check_context_refcount(cxt2);
1462     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1463     ok(SUCCEEDED(hr),"GetTop Failed\n");
1464     ok(cxtTest == cxt2, "Wrong context on top\n");
1465     ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
1466     ITfContext_Release(cxtTest);
1467
1468     cnt = check_context_refcount(cxt);
1469     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1470     ok(SUCCEEDED(hr),"GetBase Failed\n");
1471     ok(cxtTest == cxt, "Wrong context on Base\n");
1472     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
1473     ITfContext_Release(cxtTest);
1474
1475     cnt = check_context_refcount(cxt2);
1476     test_OnPopContext = SINK_EXPECTED;
1477     hr = ITfDocumentMgr_Pop(g_dm, 0);
1478     ok(SUCCEEDED(hr),"Pop Failed\n");
1479     ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
1480     sink_check_ok(&test_OnPopContext,"OnPopContext");
1481
1482     dmtest = (void *)0xfeedface;
1483     hr = ITfContext_GetDocumentMgr(cxt2,&dmtest);
1484     ok(hr == S_FALSE, "ITfContext_GetDocumentMgr wrong rc %x\n",hr);
1485     ok(dmtest == NULL,"returned documentmgr should be null\n");
1486
1487     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1488     ok(SUCCEEDED(hr),"GetTop Failed\n");
1489     ok(cxtTest == cxt, "Wrong context on top\n");
1490     ITfContext_Release(cxtTest);
1491
1492     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1493     ok(SUCCEEDED(hr),"GetBase Failed\n");
1494     ok(cxtTest == cxt, "Wrong context on base\n");
1495     ITfContext_Release(cxtTest);
1496
1497     hr = ITfDocumentMgr_Pop(g_dm, 0);
1498     ok(FAILED(hr),"Pop Succeeded\n");
1499
1500     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
1501     ok(SUCCEEDED(hr),"GetTop Failed\n");
1502     ok(cxtTest == cxt, "Wrong context on top\n");
1503     ITfContext_Release(cxtTest);
1504
1505     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
1506     ok(SUCCEEDED(hr),"GetBase Failed\n");
1507     ok(cxtTest == cxt, "Wrong context on base\n");
1508     ITfContext_Release(cxtTest);
1509
1510     ITfContext_Release(cxt);
1511     ITfContext_Release(cxt2);
1512     ITfContext_Release(cxt3);
1513 }
1514
1515 static void test_endSession(void)
1516 {
1517     HRESULT hr;
1518     test_ShouldDeactivate = TRUE;
1519     test_CurrentFocus = NULL;
1520     test_PrevFocus = g_dm;
1521     test_OnSetFocus  = SINK_EXPECTED;
1522     hr = ITfThreadMgr_Deactivate(g_tm);
1523     ok(SUCCEEDED(hr),"Failed to Deactivate\n");
1524     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1525     test_OnSetFocus  = SINK_UNEXPECTED;
1526 }
1527
1528 static void test_TfGuidAtom(void)
1529 {
1530     GUID gtest,g1;
1531     HRESULT hr;
1532     TfGuidAtom atom1,atom2;
1533     BOOL equal;
1534
1535     CoCreateGuid(&gtest);
1536
1537     /* msdn reports this should return E_INVALIDARG.  However my test show it crashing (winxp)*/
1538     /*
1539     hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,NULL);
1540     ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
1541     */
1542     hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,&atom1);
1543     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1544     hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,&atom2);
1545     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
1546     ok(atom1 == atom2,"atoms do not match\n");
1547     hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
1548     ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
1549     hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
1550     ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1551     ok(IsEqualGUID(&g1,&gtest),"guids do not match\n");
1552     hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,&gtest,NULL);
1553     ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
1554     hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,&gtest,&equal);
1555     ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1556     ok(equal == TRUE,"Equal value invalid\n");
1557
1558     /* show that cid and tid TfClientIds are also TfGuidAtoms */
1559     hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
1560     ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
1561     ok(equal == TRUE,"Equal value invalid\n");
1562     hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
1563     ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
1564     ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
1565 }
1566
1567 static void test_ClientId(void)
1568 {
1569     ITfClientId *pcid;
1570     TfClientId id1,id2;
1571     HRESULT hr;
1572     GUID g2;
1573
1574     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfClientId, (LPVOID*)&pcid);
1575     ok(SUCCEEDED(hr),"Unable to acquire ITfClientId interface\n");
1576
1577     CoCreateGuid(&g2);
1578
1579     hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id1);
1580     ok(SUCCEEDED(hr),"GetClientId failed\n");
1581     hr = ITfClientId_GetClientId(pcid,&GUID_NULL,&id2);
1582     ok(SUCCEEDED(hr),"GetClientId failed\n");
1583     ok(id1==id2,"Id's for GUID_NULL do not match\n");
1584     hr = ITfClientId_GetClientId(pcid,&CLSID_FakeService,&id2);
1585     ok(SUCCEEDED(hr),"GetClientId failed\n");
1586     ok(id2!=id1,"Id matches GUID_NULL\n");
1587     ok(id2==tid,"Id for CLSID_FakeService not matching tid\n");
1588     ok(id2!=cid,"Id for CLSID_FakeService matching cid\n");
1589     hr = ITfClientId_GetClientId(pcid,&g2,&id2);
1590     ok(SUCCEEDED(hr),"GetClientId failed\n");
1591     ok(id2!=id1,"Id matches GUID_NULL\n");
1592     ok(id2!=tid,"Id for random guid matching tid\n");
1593     ok(id2!=cid,"Id for random guid matching cid\n");
1594     ITfClientId_Release(pcid);
1595 }
1596
1597 /**********************************************************************
1598  * ITfEditSession
1599  **********************************************************************/
1600 typedef struct tagEditSession
1601 {
1602     const ITfEditSessionVtbl *EditSessionVtbl;
1603     LONG refCount;
1604 } EditSession;
1605
1606 static void EditSession_Destructor(EditSession *This)
1607 {
1608     HeapFree(GetProcessHeap(),0,This);
1609 }
1610
1611 static HRESULT WINAPI EditSession_QueryInterface(ITfEditSession *iface, REFIID iid, LPVOID *ppvOut)
1612 {
1613     EditSession *This = (EditSession *)iface;
1614     *ppvOut = NULL;
1615
1616     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfEditSession))
1617     {
1618         *ppvOut = This;
1619     }
1620
1621     if (*ppvOut)
1622     {
1623         IUnknown_AddRef(iface);
1624         return S_OK;
1625     }
1626
1627     return E_NOINTERFACE;
1628 }
1629
1630 static ULONG WINAPI EditSession_AddRef(ITfEditSession *iface)
1631 {
1632     EditSession *This = (EditSession *)iface;
1633     return InterlockedIncrement(&This->refCount);
1634 }
1635
1636 static ULONG WINAPI EditSession_Release(ITfEditSession *iface)
1637 {
1638     EditSession *This = (EditSession *)iface;
1639     ULONG ret;
1640
1641     ret = InterlockedDecrement(&This->refCount);
1642     if (ret == 0)
1643         EditSession_Destructor(This);
1644     return ret;
1645 }
1646
1647 static void test_InsertAtSelection(TfEditCookie ec, ITfContext *cxt)
1648 {
1649     HRESULT hr;
1650     ITfInsertAtSelection *iis;
1651     ITfRange *range=NULL;
1652     static const WCHAR txt[] = {'H','e','l','l','o',' ','W','o','r','l','d',0};
1653
1654     hr = ITfContext_QueryInterface(cxt, &IID_ITfInsertAtSelection , (LPVOID*)&iis);
1655     ok(SUCCEEDED(hr),"Failed to get ITfInsertAtSelection interface\n");
1656     test_ACP_InsertTextAtSelection = SINK_EXPECTED;
1657     hr = ITfInsertAtSelection_InsertTextAtSelection(iis, ec, 0, txt, 11, &range);
1658     ok(SUCCEEDED(hr),"ITfInsertAtSelection_InsertTextAtSelection failed %x\n",hr);
1659     sink_check_ok(&test_ACP_InsertTextAtSelection,"InsertTextAtSelection");
1660     ok(range != NULL,"No range returned\n");
1661     ITfRange_Release(range);
1662     ITfInsertAtSelection_Release(iis);
1663 }
1664
1665 static HRESULT WINAPI EditSession_DoEditSession(ITfEditSession *iface,
1666 TfEditCookie ec)
1667 {
1668     ITfContext *cxt;
1669     ITfDocumentMgr *dm;
1670     ITfRange *range;
1671     TF_SELECTION selection;
1672     ULONG fetched;
1673     HRESULT hr;
1674
1675     sink_fire_ok(&test_DoEditSession,"EditSession_DoEditSession");
1676     sink_check_ok(&test_ACP_RequestLock,"RequestLock");
1677
1678     ITfThreadMgr_GetFocus(g_tm, &dm);
1679     ITfDocumentMgr_GetTop(dm,&cxt);
1680
1681     hr = ITfContext_GetStart(cxt,ec,NULL);
1682     ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1683
1684     range = (ITfRange*)0xdeaddead;
1685     hr = ITfContext_GetStart(cxt,0xdeadcafe,&range);
1686     ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1687     ok(range == NULL,"Range not set to NULL\n");
1688
1689     hr = ITfContext_GetStart(cxt,ec,&range);
1690     ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1691     ok(range != NULL,"Range set to NULL\n");
1692
1693     ITfRange_Release(range);
1694
1695     hr = ITfContext_GetEnd(cxt,ec,NULL);
1696     ok(hr == E_INVALIDARG,"Unexpected return code %x\n",hr);
1697
1698     range = (ITfRange*)0xdeaddead;
1699     hr = ITfContext_GetEnd(cxt,0xdeadcafe,&range);
1700     ok(hr == TF_E_NOLOCK,"Unexpected return code %x\n",hr);
1701     ok(range == NULL,"Range not set to NULL\n");
1702
1703     test_ACP_GetEndACP = SINK_EXPECTED;
1704     hr = ITfContext_GetEnd(cxt,ec,&range);
1705     ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1706     ok(range != NULL,"Range set to NULL\n");
1707     sink_check_ok(&test_ACP_GetEndACP,"GetEndACP");
1708
1709     ITfRange_Release(range);
1710
1711     selection.range = NULL;
1712     test_ACP_GetSelection = SINK_EXPECTED;
1713     hr = ITfContext_GetSelection(cxt, ec, TF_DEFAULT_SELECTION, 1, &selection, &fetched);
1714     ok(SUCCEEDED(hr),"ITfContext_GetSelection failed\n");
1715     ok(fetched == 1,"fetched incorrect\n");
1716     ok(selection.range != NULL,"NULL range\n");
1717     sink_check_ok(&test_ACP_GetSelection,"ACP_GetSepection");
1718     ITfRange_Release(selection.range);
1719
1720     test_InsertAtSelection(ec, cxt);
1721
1722     test_ACP_GetEndACP = SINK_EXPECTED;
1723     hr = ITfContext_GetEnd(cxt,ec,&range);
1724     ok(SUCCEEDED(hr),"Unexpected return code %x\n",hr);
1725     ok(range != NULL,"Range set to NULL\n");
1726     sink_check_ok(&test_ACP_GetEndACP,"GetEndACP");
1727
1728     selection.range = range;
1729     selection.style.ase = TF_AE_NONE;
1730     selection.style.fInterimChar = FALSE;
1731     test_ACP_SetSelection = SINK_EXPECTED;
1732     hr = ITfContext_SetSelection(cxt, ec, 1, &selection);
1733     sink_check_ok(&test_ACP_SetSelection,"SetSelection");
1734     ITfRange_Release(range);
1735
1736     ITfContext_Release(cxt);
1737     ITfDocumentMgr_Release(dm);
1738     return 0xdeadcafe;
1739 }
1740
1741 static const ITfEditSessionVtbl EditSession_EditSessionVtbl =
1742 {
1743     EditSession_QueryInterface,
1744     EditSession_AddRef,
1745     EditSession_Release,
1746
1747     EditSession_DoEditSession
1748 };
1749
1750 static HRESULT EditSession_Constructor(ITfEditSession **ppOut)
1751 {
1752     EditSession *This;
1753
1754     *ppOut = NULL;
1755     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(EditSession));
1756     if (This == NULL)
1757         return E_OUTOFMEMORY;
1758
1759     This->EditSessionVtbl = &EditSession_EditSessionVtbl;
1760     This->refCount = 1;
1761
1762     *ppOut = (ITfEditSession*)This;
1763     return S_OK;
1764 }
1765
1766 static void test_TStoApplicationText(void)
1767 {
1768     HRESULT hr, hrSession;
1769     ITfEditSession *es;
1770     ITfContext *cxt;
1771     ITfDocumentMgr *dm;
1772     ITfTextEditSink *sink;
1773     ITfSource *source = NULL;
1774     DWORD editSinkCookie = -1;
1775
1776     ITfThreadMgr_GetFocus(g_tm, &dm);
1777     EditSession_Constructor(&es);
1778     ITfDocumentMgr_GetTop(dm,&cxt);
1779
1780     TextEditSink_Constructor(&sink);
1781     hr = ITfContext_QueryInterface(cxt,&IID_ITfSource,(LPVOID*)&source);
1782     ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for Context\n");
1783     if (source)
1784     {
1785         hr = ITfSource_AdviseSink(source, &IID_ITfTextEditSink, (LPVOID)sink, &editSinkCookie);
1786         ok(SUCCEEDED(hr),"Failed to advise Sink\n");
1787         ok(editSinkCookie != -1,"Failed to get sink cookie\n");
1788     }
1789
1790     hrSession = 0xfeedface;
1791     /* Test no premissions flags */
1792     hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC, &hrSession);
1793     ok(hr == E_INVALIDARG,"RequestEditSession should have failed with %x not %x\n",E_INVALIDARG,hr);
1794     ok(hrSession == E_FAIL,"hrSession should be %x not %x\n",E_FAIL,hrSession);
1795
1796     documentStatus = TS_SD_READONLY;
1797     hrSession = 0xfeedface;
1798     test_ACP_GetStatus = SINK_EXPECTED;
1799     hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1800     ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1801     ok(hrSession == TS_E_READONLY,"Unexpected hrSession (%x)\n",hrSession);
1802     sink_check_ok(&test_ACP_GetStatus,"GetStatus");
1803
1804     /* signal a change to allow readwrite sessions */
1805     documentStatus = 0;
1806     test_ACP_RequestLock = SINK_EXPECTED;
1807     ITextStoreACPSink_OnStatusChange(ACPSink,documentStatus);
1808     sink_check_ok(&test_ACP_RequestLock,"RequestLock");
1809
1810     test_ACP_GetStatus = SINK_EXPECTED;
1811     test_ACP_RequestLock = SINK_EXPECTED;
1812     test_DoEditSession = SINK_EXPECTED;
1813     hrSession = 0xfeedface;
1814     test_OnEndEdit = SINK_EXPECTED;
1815     hr = ITfContext_RequestEditSession(cxt, tid, es, TF_ES_SYNC|TF_ES_READWRITE, &hrSession);
1816     ok(SUCCEEDED(hr),"ITfContext_RequestEditSession failed\n");
1817     sink_check_ok(&test_OnEndEdit,"OnEndEdit");
1818     sink_check_ok(&test_DoEditSession,"DoEditSession");
1819     sink_check_ok(&test_ACP_GetStatus,"GetStatus");
1820     ok(hrSession == 0xdeadcafe,"Unexpected hrSession (%x)\n",hrSession);
1821
1822     if (source)
1823     {
1824         hr = ITfSource_UnadviseSink(source, editSinkCookie);
1825         ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
1826         ITfTextEditSink_Release(sink);
1827         ITfSource_Release(source);
1828     }
1829
1830     ITfContext_Release(cxt);
1831     ITfDocumentMgr_Release(dm);
1832     ITfEditSession_Release(es);
1833 }
1834
1835 static void enum_compartments(ITfCompartmentMgr *cmpmgr, REFGUID present, REFGUID absent)
1836 {
1837     BOOL found,found2;
1838     IEnumGUID *ppEnum;
1839     found = FALSE;
1840     found2 = FALSE;
1841     if (SUCCEEDED(ITfCompartmentMgr_EnumCompartments(cmpmgr, &ppEnum)))
1842     {
1843         ULONG fetched;
1844         GUID g;
1845         while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
1846         {
1847             WCHAR str[50];
1848             CHAR strA[50];
1849             StringFromGUID2(&g,str,50);
1850             WideCharToMultiByte(CP_ACP,0,str,50,strA,50,0,0);
1851             trace("found %s\n",strA);
1852             if (present && IsEqualGUID(present,&g))
1853                 found = TRUE;
1854             if (absent && IsEqualGUID(absent, &g))
1855                 found2 = TRUE;
1856         }
1857         IEnumGUID_Release(ppEnum);
1858     }
1859     if (present)
1860         ok(found,"Did not find compartment\n");
1861     if (absent)
1862         ok(!found2,"Found compartment that should be absent\n");
1863 }
1864
1865 static void test_Compartments(void)
1866 {
1867     ITfContext *cxt;
1868     ITfDocumentMgr *dm;
1869     ITfCompartmentMgr *cmpmgr;
1870     ITfCompartment *cmp;
1871     HRESULT hr;
1872
1873     ITfThreadMgr_GetFocus(g_tm, &dm);
1874     ITfDocumentMgr_GetTop(dm,&cxt);
1875
1876     /* Global */
1877     hr = ITfThreadMgr_GetGlobalCompartment(g_tm, &cmpmgr);
1878     ok(SUCCEEDED(hr),"GetGlobalCompartment failed\n");
1879     hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_SPEECH_OPENCLOSE, &cmp);
1880     ok(SUCCEEDED(hr),"GetCompartment failed\n");
1881     ITfCompartment_Release(cmp);
1882     enum_compartments(cmpmgr,&GUID_COMPARTMENT_SPEECH_OPENCLOSE,NULL);
1883     ITfCompartmentMgr_Release(cmpmgr);
1884
1885     /* Thread */
1886     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1887     ok(SUCCEEDED(hr),"ThreadMgr QI for IID_ITfCompartmentMgr failed\n");
1888     hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &CLSID_FakeService, &cmp);
1889     ok(SUCCEEDED(hr),"GetCompartment failed\n");
1890     enum_compartments(cmpmgr,&CLSID_FakeService,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1891     ITfCompartmentMgr_ClearCompartment(cmpmgr,tid,&CLSID_FakeService);
1892     enum_compartments(cmpmgr,NULL,&CLSID_FakeService);
1893     ITfCompartmentMgr_Release(cmpmgr);
1894     ITfCompartment_Release(cmp);
1895
1896     /* DocumentMgr */
1897     hr = ITfDocumentMgr_QueryInterface(dm, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1898     ok(SUCCEEDED(hr),"DocumentMgr QI for IID_ITfCompartmentMgr failed\n");
1899
1900     hr = ITfCompartmentMgr_GetCompartment(cmpmgr, &GUID_COMPARTMENT_PERSISTMENUENABLED, &cmp);
1901     ok(SUCCEEDED(hr),"GetCompartment failed\n");
1902     enum_compartments(cmpmgr,&GUID_COMPARTMENT_PERSISTMENUENABLED,&GUID_COMPARTMENT_SPEECH_OPENCLOSE);
1903     ITfCompartmentMgr_Release(cmpmgr);
1904
1905     /* Context */
1906     hr = ITfContext_QueryInterface(cxt, &IID_ITfCompartmentMgr, (LPVOID*)&cmpmgr);
1907     ok(SUCCEEDED(hr),"Context QI for IID_ITfCompartmentMgr failed\n");
1908     enum_compartments(cmpmgr,NULL,&GUID_COMPARTMENT_PERSISTMENUENABLED);
1909     ITfCompartmentMgr_Release(cmpmgr);
1910
1911     ITfContext_Release(cxt);
1912     ITfDocumentMgr_Release(dm);
1913 }
1914
1915 static void processPendingMessages(void)
1916 {
1917     MSG msg;
1918     while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
1919         TranslateMessage(&msg);
1920         DispatchMessage(&msg);
1921     }
1922 }
1923
1924 static void test_AssociateFocus(void)
1925 {
1926     ITfDocumentMgr *dm1, *dm2, *olddm, *dmcheck, *dmorig;
1927     HWND wnd1, wnd2, wnd3;
1928     HRESULT hr;
1929
1930     ITfThreadMgr_GetFocus(g_tm, &dmorig);
1931     test_CurrentFocus = NULL;
1932     test_PrevFocus = dmorig;
1933     test_OnSetFocus  = SINK_EXPECTED;
1934     hr = ITfThreadMgr_SetFocus(g_tm,NULL);
1935     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1936     ITfDocumentMgr_Release(dmorig);
1937
1938     hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm1);
1939     ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1940
1941     hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&dm2);
1942     ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
1943
1944     wnd1 = CreateWindow("edit",NULL,WS_POPUP,0,0,200,60,NULL,NULL,NULL,NULL);
1945     ok(wnd1!=NULL,"Unable to create window 1\n");
1946     wnd2 = CreateWindow("edit",NULL,WS_POPUP,0,65,200,60,NULL,NULL,NULL,NULL);
1947     ok(wnd2!=NULL,"Unable to create window 2\n");
1948     wnd3 = CreateWindow("edit",NULL,WS_POPUP,0,130,200,60,NULL,NULL,NULL,NULL);
1949     ok(wnd3!=NULL,"Unable to create window 3\n");
1950
1951     processPendingMessages();
1952
1953     test_OnInitDocumentMgr = SINK_OPTIONAL; /* Vista and greater */
1954     test_OnPushContext = SINK_OPTIONAL; /* Vista and greater */
1955
1956     ShowWindow(wnd1,SW_SHOWNORMAL);
1957     SetFocus(wnd1);
1958     sink_check_ok(&test_OnInitDocumentMgr,"OnInitDocumentMgr");
1959     sink_check_ok(&test_OnPushContext,"OnPushContext");
1960
1961     test_OnSetFocus  = SINK_OPTIONAL; /* Vista and greater */
1962     ITfThreadMgr_GetFocus(g_tm, &test_PrevFocus);
1963     test_CurrentFocus = FOCUS_IGNORE; /* This is a default system context */
1964     processPendingMessages();
1965     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1966
1967     test_CurrentFocus = dm1;
1968     test_PrevFocus = FOCUS_IGNORE;
1969     test_OnSetFocus  = SINK_EXPECTED;
1970     hr = ITfThreadMgr_AssociateFocus(g_tm,wnd1,dm1,&olddm);
1971     ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1972     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
1973
1974     processPendingMessages();
1975
1976     ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1977     ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1978     ITfDocumentMgr_Release(dmcheck);
1979
1980     hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,dm2,&olddm);
1981     ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1982     processPendingMessages();
1983     ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1984     ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1985     ITfDocumentMgr_Release(dmcheck);
1986
1987     hr = ITfThreadMgr_AssociateFocus(g_tm,wnd3,dm2,&olddm);
1988     ok(SUCCEEDED(hr),"AssociateFocus failed\n");
1989     processPendingMessages();
1990     ITfThreadMgr_GetFocus(g_tm, &dmcheck);
1991     ok(dmcheck == dm1, "Expected DocumentMgr not focused\n");
1992     ITfDocumentMgr_Release(dmcheck);
1993
1994     test_CurrentFocus = dm2;
1995     test_PrevFocus = dm1;
1996     test_OnSetFocus  = SINK_EXPECTED;
1997     ShowWindow(wnd2,SW_SHOWNORMAL);
1998     SetFocus(wnd2);
1999     processPendingMessages();
2000     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2001
2002     ShowWindow(wnd3,SW_SHOWNORMAL);
2003     SetFocus(wnd3);
2004     processPendingMessages();
2005
2006     test_CurrentFocus = dm1;
2007     test_PrevFocus = dm2;
2008     test_OnSetFocus = SINK_EXPECTED;
2009     SetFocus(wnd1);
2010     processPendingMessages();
2011     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2012
2013     hr = ITfThreadMgr_AssociateFocus(g_tm,wnd3,NULL,&olddm);
2014     ok(SUCCEEDED(hr),"AssociateFocus failed\n");
2015     ok(olddm == dm2, "incorrect old DocumentMgr returned\n");
2016     ITfDocumentMgr_Release(olddm);
2017
2018     test_CurrentFocus = dmorig;
2019     test_PrevFocus = dm1;
2020     test_OnSetFocus  = SINK_EXPECTED;
2021     test_ACP_GetStatus = SINK_EXPECTED;
2022     ITfThreadMgr_SetFocus(g_tm,dmorig);
2023     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2024
2025     test_CurrentFocus = FOCUS_IGNORE; /* NULL on XP, system default on Vista */
2026     test_PrevFocus = dmorig;
2027     test_OnSetFocus  = SINK_EXPECTED;
2028     SetFocus(wnd3);
2029     processPendingMessages();
2030     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2031
2032     hr = ITfThreadMgr_AssociateFocus(g_tm,wnd2,NULL,&olddm);
2033     ok(SUCCEEDED(hr),"AssociateFocus failed\n");
2034     ok(olddm == dm2, "incorrect old DocumentMgr returned\n");
2035     ITfDocumentMgr_Release(olddm);
2036     hr = ITfThreadMgr_AssociateFocus(g_tm,wnd1,NULL,&olddm);
2037     ok(SUCCEEDED(hr),"AssociateFocus failed\n");
2038     ok(olddm == dm1, "incorrect old DocumentMgr returned\n");
2039     ITfDocumentMgr_Release(olddm);
2040
2041     SetFocus(wnd2);
2042     processPendingMessages();
2043     SetFocus(wnd1);
2044     processPendingMessages();
2045
2046     ITfDocumentMgr_Release(dm1);
2047     ITfDocumentMgr_Release(dm2);
2048
2049     test_CurrentFocus = dmorig;
2050     test_PrevFocus = FOCUS_IGNORE;
2051     test_OnSetFocus  = SINK_EXPECTED;
2052     test_ACP_GetStatus = SINK_IGNORE;
2053     ITfThreadMgr_SetFocus(g_tm,dmorig);
2054     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2055
2056     DestroyWindow(wnd1);
2057     DestroyWindow(wnd2);
2058     test_OnPopContext = SINK_OPTIONAL; /* Vista and greater */
2059     test_OnSetFocus = SINK_OPTIONAL; /* Vista and greater */
2060     ITfThreadMgr_GetFocus(g_tm, &test_PrevFocus);
2061     test_CurrentFocus = NULL;
2062     DestroyWindow(wnd3);
2063     sink_check_ok(&test_OnSetFocus,"OnSetFocus");
2064     sink_check_ok(&test_OnPopContext,"OnPopContext");
2065 }
2066
2067 START_TEST(inputprocessor)
2068 {
2069     if (SUCCEEDED(initialize()))
2070     {
2071         test_Register();
2072         test_RegisterCategory();
2073         test_EnumLanguageProfiles();
2074         test_EnumInputProcessorInfo();
2075         test_Enable();
2076         test_ThreadMgrAdviseSinks();
2077         test_Activate();
2078         test_startSession();
2079         test_TfGuidAtom();
2080         test_ClientId();
2081         test_KeystrokeMgr();
2082         test_TStoApplicationText();
2083         test_Compartments();
2084         test_AssociateFocus();
2085         test_endSession();
2086         test_FindClosestCategory();
2087         test_Disable();
2088         test_ThreadMgrUnadviseSinks();
2089         test_UnregisterCategory();
2090         test_Unregister();
2091     }
2092     else
2093         skip("Unable to create InputProcessor\n");
2094     cleanup();
2095 }