msctf/tests: Test ITfKeystrokeMgr::IsPreservedKey.
[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 #define SINK_UNEXPECTED 0
42 #define SINK_EXPECTED 1
43 #define SINK_FIRED 2
44
45 static BOOL test_ShouldActivate = FALSE;
46 static BOOL test_ShouldDeactivate = FALSE;
47
48 static DWORD tmSinkCookie;
49 static DWORD tmSinkRefCount;
50 static ITfDocumentMgr *test_CurrentFocus = NULL;
51 static ITfDocumentMgr *test_PrevFocus = NULL;
52 static INT  test_OnSetFocus = SINK_UNEXPECTED;
53 static INT  test_OnInitDocumentMgr = SINK_UNEXPECTED;
54 static INT  test_OnPushContext = SINK_UNEXPECTED;
55 static INT  test_OnPopContext = SINK_UNEXPECTED;
56
57 HRESULT RegisterTextService(REFCLSID rclsid);
58 HRESULT UnregisterTextService();
59 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut);
60 HRESULT TextStoreACP_Constructor(IUnknown **ppOut);
61
62 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
63 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
64 DEFINE_GUID(CLSID_TF_CategoryMgr,         0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
65 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD,     0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
66 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH,       0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
67 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING,  0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
68 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER,  0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
69 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
70 DEFINE_GUID(CLSID_TF_ThreadMgr,           0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
71 DEFINE_GUID(CLSID_PreservedKey,           0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
72
73
74 static HRESULT initialize(void)
75 {
76     HRESULT hr;
77     CoInitialize(NULL);
78     hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
79           CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
80     if (SUCCEEDED(hr))
81         hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
82           CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
83     if (SUCCEEDED(hr))
84         hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
85           CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
86     return hr;
87 }
88
89 static void cleanup(void)
90 {
91     if (g_ipp)
92         ITfInputProcessorProfiles_Release(g_ipp);
93     if (g_cm)
94         ITfCategoryMgr_Release(g_cm);
95     if (g_tm)
96         ITfThreadMgr_Release(g_tm);
97     CoUninitialize();
98 }
99
100 static void test_Register(void)
101 {
102     HRESULT hr;
103
104     static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
105     static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
106
107     hr = RegisterTextService(&CLSID_FakeService);
108     ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
109     hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
110     ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
111     hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
112     ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
113 }
114
115 static void test_Unregister(void)
116 {
117     HRESULT hr;
118     hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
119     ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
120     UnregisterTextService();
121 }
122
123 static void test_EnumInputProcessorInfo(void)
124 {
125     IEnumGUID *ppEnum;
126     BOOL found = FALSE;
127
128     if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
129     {
130         ULONG fetched;
131         GUID g;
132         while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
133         {
134             if(IsEqualGUID(&g,&CLSID_FakeService))
135                 found = TRUE;
136         }
137     }
138     ok(found,"Did not find registered text service\n");
139 }
140
141 static void test_EnumLanguageProfiles(void)
142 {
143     BOOL found = FALSE;
144     IEnumTfLanguageProfiles *ppEnum;
145     if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
146     {
147         TF_LANGUAGEPROFILE profile;
148         while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
149         {
150             if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
151             {
152                 found = TRUE;
153                 ok(profile.langid == gLangid, "LangId Incorrect\n");
154                 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
155                 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
156             }
157         }
158     }
159     ok(found,"Registered text service not found\n");
160 }
161
162 static void test_RegisterCategory(void)
163 {
164     HRESULT hr;
165     hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
166     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
167     hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
168     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
169 }
170
171 static void test_UnregisterCategory(void)
172 {
173     HRESULT hr;
174     hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
175     todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
176     hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
177     todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
178 }
179
180 static void test_FindClosestCategory(void)
181 {
182     GUID output;
183     HRESULT hr;
184     const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
185
186     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
187     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
188     ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
189
190     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
191     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
192     ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
193
194     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
195     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
196     ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
197 }
198
199 static void test_Enable(void)
200 {
201     HRESULT hr;
202     BOOL enabled = FALSE;
203
204     hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
205     ok(SUCCEEDED(hr),"Failed to enable text service\n");
206     hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
207     ok(SUCCEEDED(hr),"Failed to get enabled state\n");
208     ok(enabled == TRUE,"enabled state incorrect\n");
209 }
210
211 static void test_Disable(void)
212 {
213     HRESULT hr;
214
215     trace("Disabling\n");
216     hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
217     ok(SUCCEEDED(hr),"Failed to disable text service\n");
218 }
219
220 static void test_ThreadMgrAdviseSinks(void)
221 {
222     ITfSource *source = NULL;
223     HRESULT hr;
224     IUnknown *sink;
225
226     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
227     ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
228     if (!source)
229         return;
230
231     ThreadMgrEventSink_Constructor(&sink);
232
233     tmSinkRefCount = 1;
234     tmSinkCookie = 0;
235     hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
236     ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
237     ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
238
239     /* Advising the sink adds a ref, Relesing here lets the object be deleted
240        when unadvised */
241     tmSinkRefCount = 2;
242     IUnknown_Release(sink);
243     ITfSource_Release(source);
244 }
245
246 static void test_ThreadMgrUnadviseSinks(void)
247 {
248     ITfSource *source = NULL;
249     HRESULT hr;
250
251     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
252     ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
253     if (!source)
254         return;
255
256     tmSinkRefCount = 1;
257     hr = ITfSource_UnadviseSink(source, tmSinkCookie);
258     ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
259     ITfSource_Release(source);
260 }
261
262 static void test_KeystrokeMgr(void)
263 {
264     ITfKeystrokeMgr *keymgr= NULL;
265     HRESULT hr;
266     TF_PRESERVEDKEY tfpk;
267     BOOL preserved;
268
269     hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
270     ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
271
272     tfpk.uVKey = 'A';
273     tfpk.uModifiers = TF_MOD_SHIFT;
274
275     hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
276     todo_wine ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
277
278     hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
279     todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
280
281     hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
282     todo_wine ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded \n");
283
284     preserved = FALSE;
285     hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
286     todo_wine ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
287     if (hr == S_OK) todo_wine ok(preserved == TRUE,"misreporting preserved key\n");
288
289     hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
290     todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
291
292     hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
293     todo_wine ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
294     if (hr == S_FALSE) todo_wine ok(preserved == FALSE,"misreporting preserved key\n");
295
296     hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
297     todo_wine ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
298
299     ITfKeystrokeMgr_Release(keymgr);
300 }
301
302 static void test_Activate(void)
303 {
304     HRESULT hr;
305
306     hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
307     todo_wine ok(SUCCEEDED(hr),"Failed to Activate text service\n");
308 }
309
310 static int inline check_context_refcount(ITfContext *iface)
311 {
312     IUnknown_AddRef(iface);
313     return IUnknown_Release(iface);
314 }
315
316 static void test_startSession(void)
317 {
318     HRESULT hr;
319     DWORD cnt;
320     DWORD editCookie;
321     ITfDocumentMgr *dmtest;
322     ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
323     ITextStoreACP *ts;
324
325     test_ShouldActivate = TRUE;
326     ITfThreadMgr_Activate(g_tm,&cid);
327     todo_wine ok(cid != tid,"TextService id mistakenly matches Client id\n");
328
329     hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
330     ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
331
332     hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
333     ok(SUCCEEDED(hr),"GetFocus Failed\n");
334     ok(dmtest == NULL,"Initial focus not null\n");
335
336     test_CurrentFocus = g_dm;
337     test_PrevFocus = NULL;
338     test_OnSetFocus  = SINK_EXPECTED;
339     hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
340     ok(SUCCEEDED(hr),"SetFocus Failed\n");
341     ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
342     test_OnSetFocus  = SINK_UNEXPECTED;
343
344     hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
345     ok(SUCCEEDED(hr),"GetFocus Failed\n");
346     ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
347
348     cnt = ITfDocumentMgr_Release(g_dm);
349     ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
350
351     hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
352     ok(SUCCEEDED(hr),"GetFocus Failed\n");
353     ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
354
355     TextStoreACP_Constructor((IUnknown**)&ts);
356
357     hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
358     ok(SUCCEEDED(hr),"CreateContext Failed\n");
359
360     hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
361     ok(SUCCEEDED(hr),"CreateContext Failed\n");
362
363     hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
364     ok(SUCCEEDED(hr),"CreateContext Failed\n");
365
366     cnt = check_context_refcount(cxt);
367     test_OnPushContext = SINK_EXPECTED;
368     test_OnInitDocumentMgr = SINK_EXPECTED;
369     hr = ITfDocumentMgr_Push(g_dm, cxt);
370     ok(SUCCEEDED(hr),"Push Failed\n");
371     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
372     ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
373     ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
374
375     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
376     ok(SUCCEEDED(hr),"GetTop Failed\n");
377     ok(cxtTest == cxt, "Wrong context on top\n");
378     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
379     cnt = ITfContext_Release(cxtTest);
380
381     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
382     ok(SUCCEEDED(hr),"GetBase Failed\n");
383     ok(cxtTest == cxt, "Wrong context on Base\n");
384     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
385     ITfContext_Release(cxtTest);
386
387     check_context_refcount(cxt2);
388     test_OnPushContext = SINK_EXPECTED;
389     hr = ITfDocumentMgr_Push(g_dm, cxt2);
390     ok(SUCCEEDED(hr),"Push Failed\n");
391     ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
392
393     cnt = check_context_refcount(cxt2);
394     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
395     ok(SUCCEEDED(hr),"GetTop Failed\n");
396     ok(cxtTest == cxt2, "Wrong context on top\n");
397     ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
398     ITfContext_Release(cxtTest);
399
400     cnt = check_context_refcount(cxt);
401     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
402     ok(SUCCEEDED(hr),"GetBase Failed\n");
403     ok(cxtTest == cxt, "Wrong context on Base\n");
404     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
405     ITfContext_Release(cxtTest);
406
407     cnt = check_context_refcount(cxt3);
408     hr = ITfDocumentMgr_Push(g_dm, cxt3);
409     ok(!SUCCEEDED(hr),"Push Succeeded\n");
410     ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
411
412     cnt = check_context_refcount(cxt2);
413     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
414     ok(SUCCEEDED(hr),"GetTop Failed\n");
415     ok(cxtTest == cxt2, "Wrong context on top\n");
416     ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
417     ITfContext_Release(cxtTest);
418
419     cnt = check_context_refcount(cxt);
420     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
421     ok(SUCCEEDED(hr),"GetBase Failed\n");
422     ok(cxtTest == cxt, "Wrong context on Base\n");
423     ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
424     ITfContext_Release(cxtTest);
425
426     cnt = check_context_refcount(cxt2);
427     test_OnPopContext = SINK_EXPECTED;
428     hr = ITfDocumentMgr_Pop(g_dm, 0);
429     ok(SUCCEEDED(hr),"Pop Failed\n");
430     ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
431     ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
432
433     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
434     ok(SUCCEEDED(hr),"GetTop Failed\n");
435     ok(cxtTest == cxt, "Wrong context on top\n");
436     ITfContext_Release(cxtTest);
437
438     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
439     ok(SUCCEEDED(hr),"GetBase Failed\n");
440     ok(cxtTest == cxt, "Wrong context on base\n");
441     ITfContext_Release(cxtTest);
442
443     hr = ITfDocumentMgr_Pop(g_dm, 0);
444     ok(!SUCCEEDED(hr),"Pop Succeeded\n");
445
446     hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
447     ok(SUCCEEDED(hr),"GetTop Failed\n");
448     ok(cxtTest == cxt, "Wrong context on top\n");
449     ITfContext_Release(cxtTest);
450
451     hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
452     ok(SUCCEEDED(hr),"GetBase Failed\n");
453     ok(cxtTest == cxt, "Wrong context on base\n");
454     ITfContext_Release(cxtTest);
455
456     ITfContext_Release(cxt);
457     ITfContext_Release(cxt2);
458     ITfContext_Release(cxt3);
459 }
460
461 static void test_endSession(void)
462 {
463     test_ShouldDeactivate = TRUE;
464     test_CurrentFocus = NULL;
465     test_PrevFocus = g_dm;
466     test_OnSetFocus  = SINK_EXPECTED;
467     ITfThreadMgr_Deactivate(g_tm);
468     ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
469     test_OnSetFocus  = SINK_UNEXPECTED;
470 }
471
472 START_TEST(inputprocessor)
473 {
474     if (SUCCEEDED(initialize()))
475     {
476         gLangid = GetUserDefaultLCID();
477         test_Register();
478         test_RegisterCategory();
479         test_EnumInputProcessorInfo();
480         test_Enable();
481         test_ThreadMgrAdviseSinks();
482         test_Activate();
483         test_startSession();
484         test_KeystrokeMgr();
485         test_endSession();
486         test_EnumLanguageProfiles();
487         test_FindClosestCategory();
488         test_Disable();
489         test_ThreadMgrUnadviseSinks();
490         test_UnregisterCategory();
491         test_Unregister();
492     }
493     else
494         skip("Unable to create InputProcessor\n");
495     cleanup();
496 }
497
498 /**********************************************************************
499  * ITextStoreACP
500  **********************************************************************/
501 typedef struct tagTextStoreACP
502 {
503     const ITextStoreACPVtbl *TextStoreACPVtbl;
504     LONG refCount;
505 } TextStoreACP;
506
507 static void TextStoreACP_Destructor(TextStoreACP *This)
508 {
509     HeapFree(GetProcessHeap(),0,This);
510 }
511
512 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
513 {
514     TextStoreACP *This = (TextStoreACP *)iface;
515     *ppvOut = NULL;
516
517     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
518     {
519         *ppvOut = This;
520     }
521
522     if (*ppvOut)
523     {
524         IUnknown_AddRef(iface);
525         return S_OK;
526     }
527
528     return E_NOINTERFACE;
529 }
530
531 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
532 {
533     TextStoreACP *This = (TextStoreACP *)iface;
534     return InterlockedIncrement(&This->refCount);
535 }
536
537 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
538 {
539     TextStoreACP *This = (TextStoreACP *)iface;
540     ULONG ret;
541
542     ret = InterlockedDecrement(&This->refCount);
543     if (ret == 0)
544         TextStoreACP_Destructor(This);
545     return ret;
546 }
547
548 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
549     REFIID riid, IUnknown *punk, DWORD dwMask)
550 {
551     trace("\n");
552     return S_OK;
553 }
554
555 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
556     IUnknown *punk)
557 {
558     trace("\n");
559     return S_OK;
560 }
561 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
562     DWORD dwLockFlags, HRESULT *phrSession)
563 {
564     trace("\n");
565     return S_OK;
566 }
567 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
568     TS_STATUS *pdcs)
569 {
570     trace("\n");
571     return S_OK;
572 }
573 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
574     LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
575     LONG *pacpResultEnd)
576 {
577     trace("\n");
578     return S_OK;
579 }
580 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
581     ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
582 {
583     trace("\n");
584     return S_OK;
585 }
586 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
587     ULONG ulCount, const TS_SELECTION_ACP *pSelection)
588 {
589     trace("\n");
590     return S_OK;
591 }
592 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
593     LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
594     ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
595     ULONG *pcRunInfoRet, LONG *pacpNext)
596 {
597     trace("\n");
598     return S_OK;
599 }
600 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
601     DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
602     ULONG cch, TS_TEXTCHANGE *pChange)
603 {
604     trace("\n");
605     return S_OK;
606 }
607 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
608     LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
609 {
610     trace("\n");
611     return S_OK;
612 }
613 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
614     LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
615 {
616     trace("\n");
617     return S_OK;
618 }
619 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
620     const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
621 {
622     trace("\n");
623     return S_OK;
624 }
625 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
626     DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
627     TS_TEXTCHANGE *pChange)
628 {
629     trace("\n");
630     return S_OK;
631 }
632 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
633     DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
634     LONG *pacpEnd, TS_TEXTCHANGE *pChange)
635 {
636     trace("\n");
637     return S_OK;
638 }
639 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
640     DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
641     TS_TEXTCHANGE *pChange)
642 {
643     trace("\n");
644     return S_OK;
645 }
646 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
647     DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
648 {
649     trace("\n");
650     return S_OK;
651 }
652 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
653     LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
654     DWORD dwFlags)
655 {
656     trace("\n");
657     return S_OK;
658 }
659 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
660     LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
661     DWORD dwFlags)
662 {
663     trace("\n");
664     return S_OK;
665 }
666 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
667     LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
668     DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
669 {
670     trace("\n");
671     return S_OK;
672 }
673 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
674     ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
675 {
676     trace("\n");
677     return S_OK;
678 }
679 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
680     LONG *pacp)
681 {
682     trace("\n");
683     return S_OK;
684 }
685 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
686     TsViewCookie *pvcView)
687 {
688     trace("\n");
689     return S_OK;
690 }
691 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
692     TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
693     LONG *pacp)
694 {
695     trace("\n");
696     return S_OK;
697 }
698 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
699     TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
700     BOOL *pfClipped)
701 {
702     trace("\n");
703     return S_OK;
704 }
705 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
706     TsViewCookie vcView, RECT *prc)
707 {
708     trace("\n");
709     return S_OK;
710 }
711 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
712     TsViewCookie vcView, HWND *phwnd)
713 {
714     trace("\n");
715     return S_OK;
716 }
717
718 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
719 {
720     TextStoreACP_QueryInterface,
721     TextStoreACP_AddRef,
722     TextStoreACP_Release,
723
724     TextStoreACP_AdviseSink,
725     TextStoreACP_UnadviseSink,
726     TextStoreACP_RequestLock,
727     TextStoreACP_GetStatus,
728     TextStoreACP_QueryInsert,
729     TextStoreACP_GetSelection,
730     TextStoreACP_SetSelection,
731     TextStoreACP_GetText,
732     TextStoreACP_SetText,
733     TextStoreACP_GetFormattedText,
734     TextStoreACP_GetEmbedded,
735     TextStoreACP_QueryInsertEmbedded,
736     TextStoreACP_InsertEmbedded,
737     TextStoreACP_InsertTextAtSelection,
738     TextStoreACP_InsertEmbeddedAtSelection,
739     TextStoreACP_RequestSupportedAttrs,
740     TextStoreACP_RequestAttrsAtPosition,
741     TextStoreACP_RequestAttrsTransitioningAtPosition,
742     TextStoreACP_FindNextAttrTransition,
743     TextStoreACP_RetrieveRequestedAttrs,
744     TextStoreACP_GetEndACP,
745     TextStoreACP_GetActiveView,
746     TextStoreACP_GetACPFromPoint,
747     TextStoreACP_GetTextExt,
748     TextStoreACP_GetScreenExt,
749     TextStoreACP_GetWnd
750 };
751
752 HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
753 {
754     TextStoreACP *This;
755
756     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
757     if (This == NULL)
758         return E_OUTOFMEMORY;
759
760     This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
761     This->refCount = 1;
762
763     *ppOut = (IUnknown *)This;
764     return S_OK;
765 }
766
767 /**********************************************************************
768  * ITfThreadMgrEventSink
769  **********************************************************************/
770 typedef struct tagThreadMgrEventSink
771 {
772     const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
773     LONG refCount;
774 } ThreadMgrEventSink;
775
776 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
777 {
778     HeapFree(GetProcessHeap(),0,This);
779 }
780
781 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
782 {
783     ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
784     *ppvOut = NULL;
785
786     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
787     {
788         *ppvOut = This;
789     }
790
791     if (*ppvOut)
792     {
793         IUnknown_AddRef(iface);
794         return S_OK;
795     }
796
797     return E_NOINTERFACE;
798 }
799
800 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
801 {
802     ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
803     ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
804     return InterlockedIncrement(&This->refCount);
805 }
806
807 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
808 {
809     ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
810     ULONG ret;
811
812     ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
813     ret = InterlockedDecrement(&This->refCount);
814     if (ret == 0)
815         ThreadMgrEventSink_Destructor(This);
816     return ret;
817 }
818
819 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
820 ITfDocumentMgr *pdim)
821 {
822     ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
823     test_OnInitDocumentMgr = SINK_FIRED;
824     return S_OK;
825 }
826
827 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
828 ITfDocumentMgr *pdim)
829 {
830     trace("\n");
831     return S_OK;
832 }
833
834 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
835 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
836 {
837     ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
838     ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
839     ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
840     test_OnSetFocus = SINK_FIRED;
841     return S_OK;
842 }
843
844 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
845 ITfContext *pic)
846 {
847     ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
848     test_OnPushContext = SINK_FIRED;
849     return S_OK;
850 }
851
852 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
853 ITfContext *pic)
854 {
855     ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
856     test_OnPopContext = SINK_FIRED;
857     return S_OK;
858 }
859
860 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
861 {
862     ThreadMgrEventSink_QueryInterface,
863     ThreadMgrEventSink_AddRef,
864     ThreadMgrEventSink_Release,
865
866     ThreadMgrEventSink_OnInitDocumentMgr,
867     ThreadMgrEventSink_OnUninitDocumentMgr,
868     ThreadMgrEventSink_OnSetFocus,
869     ThreadMgrEventSink_OnPushContext,
870     ThreadMgrEventSink_OnPopContext
871 };
872
873 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
874 {
875     ThreadMgrEventSink *This;
876
877     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
878     if (This == NULL)
879         return E_OUTOFMEMORY;
880
881     This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
882     This->refCount = 1;
883
884     *ppOut = (IUnknown *)This;
885     return S_OK;
886 }
887
888
889 /********************************************************************************************
890  * Stub text service for testing
891  ********************************************************************************************/
892
893 static LONG TS_refCount;
894 static IClassFactory *cf;
895 static DWORD regid;
896
897 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
898
899 typedef struct tagClassFactory
900 {
901     const IClassFactoryVtbl *vtbl;
902     LONG   ref;
903     LPFNCONSTRUCTOR ctor;
904 } ClassFactory;
905
906 typedef struct tagTextService
907 {
908     const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
909     LONG refCount;
910 } TextService;
911
912 static void ClassFactory_Destructor(ClassFactory *This)
913 {
914     HeapFree(GetProcessHeap(),0,This);
915     TS_refCount--;
916 }
917
918 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
919 {
920     *ppvOut = NULL;
921     if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
922     {
923         IClassFactory_AddRef(iface);
924         *ppvOut = iface;
925         return S_OK;
926     }
927
928     return E_NOINTERFACE;
929 }
930
931 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
932 {
933     ClassFactory *This = (ClassFactory *)iface;
934     return InterlockedIncrement(&This->ref);
935 }
936
937 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
938 {
939     ClassFactory *This = (ClassFactory *)iface;
940     ULONG ret = InterlockedDecrement(&This->ref);
941
942     if (ret == 0)
943         ClassFactory_Destructor(This);
944     return ret;
945 }
946
947 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
948 {
949     ClassFactory *This = (ClassFactory *)iface;
950     HRESULT ret;
951     IUnknown *obj;
952
953     ret = This->ctor(punkOuter, &obj);
954     if (FAILED(ret))
955         return ret;
956     ret = IUnknown_QueryInterface(obj, iid, ppvOut);
957     IUnknown_Release(obj);
958     return ret;
959 }
960
961 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
962 {
963     if(fLock)
964         InterlockedIncrement(&TS_refCount);
965     else
966         InterlockedDecrement(&TS_refCount);
967
968     return S_OK;
969 }
970
971 static const IClassFactoryVtbl ClassFactoryVtbl = {
972     /* IUnknown */
973     ClassFactory_QueryInterface,
974     ClassFactory_AddRef,
975     ClassFactory_Release,
976
977     /* IClassFactory*/
978     ClassFactory_CreateInstance,
979     ClassFactory_LockServer
980 };
981
982 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
983 {
984     ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
985     This->vtbl = &ClassFactoryVtbl;
986     This->ref = 1;
987     This->ctor = ctor;
988     *ppvOut = (LPVOID)This;
989     TS_refCount++;
990     return S_OK;
991 }
992
993 static void TextService_Destructor(TextService *This)
994 {
995     HeapFree(GetProcessHeap(),0,This);
996 }
997
998 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
999 {
1000     TextService *This = (TextService *)iface;
1001     *ppvOut = NULL;
1002
1003     if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
1004     {
1005         *ppvOut = This;
1006     }
1007
1008     if (*ppvOut)
1009     {
1010         IUnknown_AddRef(iface);
1011         return S_OK;
1012     }
1013
1014     return E_NOINTERFACE;
1015 }
1016
1017 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
1018 {
1019     TextService *This = (TextService *)iface;
1020     return InterlockedIncrement(&This->refCount);
1021 }
1022
1023 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
1024 {
1025     TextService *This = (TextService *)iface;
1026     ULONG ret;
1027
1028     ret = InterlockedDecrement(&This->refCount);
1029     if (ret == 0)
1030         TextService_Destructor(This);
1031     return ret;
1032 }
1033
1034 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
1035         ITfThreadMgr *ptim, TfClientId id)
1036 {
1037     trace("TextService_Activate\n");
1038     ok(test_ShouldActivate,"Activation came unexpectedly\n");
1039     tid = id;
1040     return S_OK;
1041 }
1042
1043 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
1044 {
1045     trace("TextService_Deactivate\n");
1046     ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
1047     return S_OK;
1048 }
1049
1050 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
1051 {
1052     TextService_QueryInterface,
1053     TextService_AddRef,
1054     TextService_Release,
1055
1056     TextService_Activate,
1057     TextService_Deactivate
1058 };
1059
1060 HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
1061 {
1062     TextService *This;
1063     if (pUnkOuter)
1064         return CLASS_E_NOAGGREGATION;
1065
1066     This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
1067     if (This == NULL)
1068         return E_OUTOFMEMORY;
1069
1070     This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
1071     This->refCount = 1;
1072
1073     *ppOut = (IUnknown *)This;
1074     return S_OK;
1075 }
1076
1077 HRESULT RegisterTextService(REFCLSID rclsid)
1078 {
1079     ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
1080     return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1081 }
1082
1083 HRESULT UnregisterTextService()
1084 {
1085     return CoRevokeClassObject(regid);
1086 }