msctf: Implement ITfCategoryMgr::RegisterGUID, ITfCategoryMgr::GetGUID and ITfCategor...
[wine/hacks.git] / dlls / msctf / tests / inputprocessor.c
blobb5ae5081a4f136a1d5528b034f3a713e647c9a1d
1 /*
2 * Unit tests for ITfInputProcessor
4 * Copyright 2009 Aric Stewart, CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdio.h>
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"
33 static ITfInputProcessorProfiles* g_ipp;
34 static LANGID gLangid;
35 static ITfCategoryMgr * g_cm = NULL;
36 static ITfThreadMgr* g_tm = NULL;
37 static ITfDocumentMgr *g_dm = NULL;
38 static TfClientId cid = 0;
39 static TfClientId tid = 0;
41 #define SINK_UNEXPECTED 0
42 #define SINK_EXPECTED 1
43 #define SINK_FIRED 2
45 static BOOL test_ShouldActivate = FALSE;
46 static BOOL test_ShouldDeactivate = FALSE;
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 static INT test_KEV_OnSetFocus = SINK_UNEXPECTED;
58 HRESULT RegisterTextService(REFCLSID rclsid);
59 HRESULT UnregisterTextService();
60 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut);
61 HRESULT TextStoreACP_Constructor(IUnknown **ppOut);
63 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
64 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
65 DEFINE_GUID(CLSID_TF_CategoryMgr, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
66 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
67 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
68 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
69 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
70 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
71 DEFINE_GUID(CLSID_TF_ThreadMgr, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
72 DEFINE_GUID(CLSID_PreservedKey, 0xA0ED8E55,0xCD3B,0x4274,0xB2,0x95,0xF6,0xC9,0xBA,0x2B,0x84,0x72);
75 static HRESULT initialize(void)
77 HRESULT hr;
78 CoInitialize(NULL);
79 hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
80 CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
81 if (SUCCEEDED(hr))
82 hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
83 CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
84 if (SUCCEEDED(hr))
85 hr = CoCreateInstance (&CLSID_TF_ThreadMgr, NULL,
86 CLSCTX_INPROC_SERVER, &IID_ITfThreadMgr, (void**)&g_tm);
87 return hr;
90 static void cleanup(void)
92 if (g_ipp)
93 ITfInputProcessorProfiles_Release(g_ipp);
94 if (g_cm)
95 ITfCategoryMgr_Release(g_cm);
96 if (g_tm)
97 ITfThreadMgr_Release(g_tm);
98 CoUninitialize();
101 static void test_Register(void)
103 HRESULT hr;
105 static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
106 static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
108 hr = ITfInputProcessorProfiles_GetCurrentLanguage(g_ipp,&gLangid);
109 ok(SUCCEEDED(hr),"Unable to get current language id\n");
110 trace("Current Language %x\n",gLangid);
112 hr = RegisterTextService(&CLSID_FakeService);
113 ok(SUCCEEDED(hr),"Unable to register COM for TextService\n");
114 hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
115 ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
116 hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
117 ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
120 static void test_Unregister(void)
122 HRESULT hr;
123 hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
124 ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
125 UnregisterTextService();
128 static void test_EnumInputProcessorInfo(void)
130 IEnumGUID *ppEnum;
131 BOOL found = FALSE;
133 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
135 ULONG fetched;
136 GUID g;
137 while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
139 if(IsEqualGUID(&g,&CLSID_FakeService))
140 found = TRUE;
143 ok(found,"Did not find registered text service\n");
146 static void test_EnumLanguageProfiles(void)
148 BOOL found = FALSE;
149 IEnumTfLanguageProfiles *ppEnum;
150 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
152 TF_LANGUAGEPROFILE profile;
153 while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
155 if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
157 found = TRUE;
158 ok(profile.langid == gLangid, "LangId Incorrect\n");
159 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
160 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
164 ok(found,"Registered text service not found\n");
167 static void test_RegisterCategory(void)
169 HRESULT hr;
170 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
171 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
172 hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
173 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
176 static void test_UnregisterCategory(void)
178 HRESULT hr;
179 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
180 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
181 hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
182 ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
185 static void test_FindClosestCategory(void)
187 GUID output;
188 HRESULT hr;
189 const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
191 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
192 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
193 ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
195 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
196 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
197 ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
199 hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
200 ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
201 ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
204 static void test_Enable(void)
206 HRESULT hr;
207 BOOL enabled = FALSE;
209 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, TRUE);
210 ok(SUCCEEDED(hr),"Failed to enable text service\n");
211 hr = ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, &enabled);
212 ok(SUCCEEDED(hr),"Failed to get enabled state\n");
213 ok(enabled == TRUE,"enabled state incorrect\n");
216 static void test_Disable(void)
218 HRESULT hr;
220 trace("Disabling\n");
221 hr = ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp,&CLSID_FakeService, gLangid, &CLSID_FakeService, FALSE);
222 ok(SUCCEEDED(hr),"Failed to disable text service\n");
225 static void test_ThreadMgrAdviseSinks(void)
227 ITfSource *source = NULL;
228 HRESULT hr;
229 IUnknown *sink;
231 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
232 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
233 if (!source)
234 return;
236 ThreadMgrEventSink_Constructor(&sink);
238 tmSinkRefCount = 1;
239 tmSinkCookie = 0;
240 hr = ITfSource_AdviseSink(source,&IID_ITfThreadMgrEventSink, sink, &tmSinkCookie);
241 ok(SUCCEEDED(hr),"Failed to Advise Sink\n");
242 ok(tmSinkCookie!=0,"Failed to get sink cookie\n");
244 /* Advising the sink adds a ref, Relesing here lets the object be deleted
245 when unadvised */
246 tmSinkRefCount = 2;
247 IUnknown_Release(sink);
248 ITfSource_Release(source);
251 static void test_ThreadMgrUnadviseSinks(void)
253 ITfSource *source = NULL;
254 HRESULT hr;
256 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfSource, (LPVOID*)&source);
257 ok(SUCCEEDED(hr),"Failed to get IID_ITfSource for ThreadMgr\n");
258 if (!source)
259 return;
261 tmSinkRefCount = 1;
262 hr = ITfSource_UnadviseSink(source, tmSinkCookie);
263 ok(SUCCEEDED(hr),"Failed to unadvise Sink\n");
264 ITfSource_Release(source);
267 /**********************************************************************
268 * ITfKeyEventSink
269 **********************************************************************/
270 typedef struct tagKeyEventSink
272 const ITfKeyEventSinkVtbl *KeyEventSinkVtbl;
273 LONG refCount;
274 } KeyEventSink;
276 static void KeyEventSink_Destructor(KeyEventSink *This)
278 HeapFree(GetProcessHeap(),0,This);
281 static HRESULT WINAPI KeyEventSink_QueryInterface(ITfKeyEventSink *iface, REFIID iid, LPVOID *ppvOut)
283 KeyEventSink *This = (KeyEventSink *)iface;
284 *ppvOut = NULL;
286 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfKeyEventSink))
288 *ppvOut = This;
291 if (*ppvOut)
293 IUnknown_AddRef(iface);
294 return S_OK;
297 return E_NOINTERFACE;
300 static ULONG WINAPI KeyEventSink_AddRef(ITfKeyEventSink *iface)
302 KeyEventSink *This = (KeyEventSink *)iface;
303 return InterlockedIncrement(&This->refCount);
306 static ULONG WINAPI KeyEventSink_Release(ITfKeyEventSink *iface)
308 KeyEventSink *This = (KeyEventSink *)iface;
309 ULONG ret;
311 ret = InterlockedDecrement(&This->refCount);
312 if (ret == 0)
313 KeyEventSink_Destructor(This);
314 return ret;
317 static HRESULT WINAPI KeyEventSink_OnSetFocus(ITfKeyEventSink *iface,
318 BOOL fForeground)
320 ok(test_KEV_OnSetFocus == SINK_EXPECTED,"Unexpected KeyEventSink_OnSetFocus\n");
321 test_KEV_OnSetFocus = SINK_FIRED;
322 return S_OK;
325 static HRESULT WINAPI KeyEventSink_OnTestKeyDown(ITfKeyEventSink *iface,
326 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
328 trace("\n");
329 return S_OK;
332 static HRESULT WINAPI KeyEventSink_OnTestKeyUp(ITfKeyEventSink *iface,
333 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
335 trace("\n");
336 return S_OK;
339 static HRESULT WINAPI KeyEventSink_OnKeyDown(ITfKeyEventSink *iface,
340 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
342 trace("\n");
343 return S_OK;
346 static HRESULT WINAPI KeyEventSink_OnKeyUp(ITfKeyEventSink *iface,
347 ITfContext *pic, WPARAM wParam, LPARAM lParam, BOOL *pfEaten)
349 trace("\n");
350 return S_OK;
353 static HRESULT WINAPI KeyEventSink_OnPreservedKey(ITfKeyEventSink *iface,
354 ITfContext *pic, REFGUID rguid, BOOL *pfEaten)
356 trace("\n");
357 return S_OK;
360 static const ITfKeyEventSinkVtbl KeyEventSink_KeyEventSinkVtbl =
362 KeyEventSink_QueryInterface,
363 KeyEventSink_AddRef,
364 KeyEventSink_Release,
366 KeyEventSink_OnSetFocus,
367 KeyEventSink_OnTestKeyDown,
368 KeyEventSink_OnTestKeyUp,
369 KeyEventSink_OnKeyDown,
370 KeyEventSink_OnKeyUp,
371 KeyEventSink_OnPreservedKey
374 HRESULT KeyEventSink_Constructor(ITfKeyEventSink **ppOut)
376 KeyEventSink *This;
378 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(KeyEventSink));
379 if (This == NULL)
380 return E_OUTOFMEMORY;
382 This->KeyEventSinkVtbl = &KeyEventSink_KeyEventSinkVtbl;
383 This->refCount = 1;
385 *ppOut = (ITfKeyEventSink*)This;
386 return S_OK;
390 static void test_KeystrokeMgr(void)
392 ITfKeystrokeMgr *keymgr= NULL;
393 HRESULT hr;
394 TF_PRESERVEDKEY tfpk;
395 BOOL preserved;
396 ITfKeyEventSink *sink;
398 KeyEventSink_Constructor(&sink);
400 hr = ITfThreadMgr_QueryInterface(g_tm, &IID_ITfKeystrokeMgr, (LPVOID*)&keymgr);
401 ok(SUCCEEDED(hr),"Failed to get IID_ITfKeystrokeMgr for ThreadMgr\n");
403 tfpk.uVKey = 'A';
404 tfpk.uModifiers = TF_MOD_SHIFT;
406 test_KEV_OnSetFocus = SINK_EXPECTED;
407 hr = ITfKeystrokeMgr_AdviseKeyEventSink(keymgr,tid,sink,TRUE);
408 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_AdviseKeyEventSink failed\n");
409 todo_wine ok(test_KEV_OnSetFocus == SINK_FIRED, "KeyEventSink_OnSetFocus not fired as expected\n");
411 hr =ITfKeystrokeMgr_PreserveKey(keymgr, 0, &CLSID_PreservedKey, &tfpk, NULL, 0);
412 todo_wine ok(hr==E_INVALIDARG,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
414 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
415 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_PreserveKey failed\n");
417 hr =ITfKeystrokeMgr_PreserveKey(keymgr, tid, &CLSID_PreservedKey, &tfpk, NULL, 0);
418 todo_wine ok(hr == TF_E_ALREADY_EXISTS,"ITfKeystrokeMgr_PreserveKey inproperly succeeded\n");
420 preserved = FALSE;
421 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
422 todo_wine ok(hr == S_OK, "ITfKeystrokeMgr_IsPreservedKey failed\n");
423 if (hr == S_OK) todo_wine ok(preserved == TRUE,"misreporting preserved key\n");
425 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
426 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnpreserveKey failed\n");
428 hr = ITfKeystrokeMgr_IsPreservedKey(keymgr, &CLSID_PreservedKey, &tfpk, &preserved);
429 todo_wine ok(hr == S_FALSE, "ITfKeystrokeMgr_IsPreservedKey failed\n");
430 if (hr == S_FALSE) todo_wine ok(preserved == FALSE,"misreporting preserved key\n");
432 hr = ITfKeystrokeMgr_UnpreserveKey(keymgr, &CLSID_PreservedKey,&tfpk);
433 todo_wine ok(hr==CONNECT_E_NOCONNECTION,"ITfKeystrokeMgr_UnpreserveKey inproperly succeeded\n");
435 hr = ITfKeystrokeMgr_UnadviseKeyEventSink(keymgr,tid);
436 todo_wine ok(SUCCEEDED(hr),"ITfKeystrokeMgr_UnadviseKeyEventSink failed\n");
438 ITfKeystrokeMgr_Release(keymgr);
439 ITfKeyEventSink_Release(sink);
442 static void test_Activate(void)
444 HRESULT hr;
446 hr = ITfInputProcessorProfiles_ActivateLanguageProfile(g_ipp,&CLSID_FakeService,gLangid,&CLSID_FakeService);
447 todo_wine ok(SUCCEEDED(hr),"Failed to Activate text service\n");
450 static inline int check_context_refcount(ITfContext *iface)
452 IUnknown_AddRef(iface);
453 return IUnknown_Release(iface);
456 static void test_startSession(void)
458 HRESULT hr;
459 DWORD cnt;
460 DWORD editCookie;
461 ITfDocumentMgr *dmtest;
462 ITfContext *cxt,*cxt2,*cxt3,*cxtTest;
463 ITextStoreACP *ts;
465 test_ShouldActivate = TRUE;
466 ITfThreadMgr_Activate(g_tm,&cid);
467 todo_wine ok(cid != tid,"TextService id mistakenly matches Client id\n");
469 hr = ITfThreadMgr_CreateDocumentMgr(g_tm,&g_dm);
470 ok(SUCCEEDED(hr),"CreateDocumentMgr failed\n");
472 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
473 ok(SUCCEEDED(hr),"GetFocus Failed\n");
474 ok(dmtest == NULL,"Initial focus not null\n");
476 test_CurrentFocus = g_dm;
477 test_PrevFocus = NULL;
478 test_OnSetFocus = SINK_EXPECTED;
479 hr = ITfThreadMgr_SetFocus(g_tm,g_dm);
480 ok(SUCCEEDED(hr),"SetFocus Failed\n");
481 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
482 test_OnSetFocus = SINK_UNEXPECTED;
484 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
485 ok(SUCCEEDED(hr),"GetFocus Failed\n");
486 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
488 cnt = ITfDocumentMgr_Release(g_dm);
489 ok(cnt == 2,"DocumentMgr refcount not expected (2 vs %i)\n",cnt);
491 hr = ITfThreadMgr_GetFocus(g_tm,&dmtest);
492 ok(SUCCEEDED(hr),"GetFocus Failed\n");
493 ok(g_dm == dmtest,"Expected DocumentMgr not focused\n");
495 TextStoreACP_Constructor((IUnknown**)&ts);
497 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, (IUnknown*)ts, &cxt, &editCookie);
498 ok(SUCCEEDED(hr),"CreateContext Failed\n");
500 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt2, &editCookie);
501 ok(SUCCEEDED(hr),"CreateContext Failed\n");
503 hr = ITfDocumentMgr_CreateContext(g_dm, cid, 0, NULL, &cxt3, &editCookie);
504 ok(SUCCEEDED(hr),"CreateContext Failed\n");
506 cnt = check_context_refcount(cxt);
507 test_OnPushContext = SINK_EXPECTED;
508 test_OnInitDocumentMgr = SINK_EXPECTED;
509 hr = ITfDocumentMgr_Push(g_dm, cxt);
510 ok(SUCCEEDED(hr),"Push Failed\n");
511 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
512 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
513 ok(test_OnInitDocumentMgr == SINK_FIRED, "OnInitDocumentMgr sink not fired\n");
515 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
516 ok(SUCCEEDED(hr),"GetTop Failed\n");
517 ok(cxtTest == cxt, "Wrong context on top\n");
518 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
519 cnt = ITfContext_Release(cxtTest);
521 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
522 ok(SUCCEEDED(hr),"GetBase Failed\n");
523 ok(cxtTest == cxt, "Wrong context on Base\n");
524 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
525 ITfContext_Release(cxtTest);
527 check_context_refcount(cxt2);
528 test_OnPushContext = SINK_EXPECTED;
529 hr = ITfDocumentMgr_Push(g_dm, cxt2);
530 ok(SUCCEEDED(hr),"Push Failed\n");
531 ok(test_OnPushContext == SINK_FIRED, "OnPushContext sink not fired\n");
533 cnt = check_context_refcount(cxt2);
534 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
535 ok(SUCCEEDED(hr),"GetTop Failed\n");
536 ok(cxtTest == cxt2, "Wrong context on top\n");
537 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
538 ITfContext_Release(cxtTest);
540 cnt = check_context_refcount(cxt);
541 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
542 ok(SUCCEEDED(hr),"GetBase Failed\n");
543 ok(cxtTest == cxt, "Wrong context on Base\n");
544 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
545 ITfContext_Release(cxtTest);
547 cnt = check_context_refcount(cxt3);
548 hr = ITfDocumentMgr_Push(g_dm, cxt3);
549 ok(!SUCCEEDED(hr),"Push Succeeded\n");
550 ok(check_context_refcount(cxt3) == cnt, "Ref changed\n");
552 cnt = check_context_refcount(cxt2);
553 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
554 ok(SUCCEEDED(hr),"GetTop Failed\n");
555 ok(cxtTest == cxt2, "Wrong context on top\n");
556 ok(check_context_refcount(cxt2) > cnt, "Ref count did not increase\n");
557 ITfContext_Release(cxtTest);
559 cnt = check_context_refcount(cxt);
560 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
561 ok(SUCCEEDED(hr),"GetBase Failed\n");
562 ok(cxtTest == cxt, "Wrong context on Base\n");
563 ok(check_context_refcount(cxt) > cnt, "Ref count did not increase\n");
564 ITfContext_Release(cxtTest);
566 cnt = check_context_refcount(cxt2);
567 test_OnPopContext = SINK_EXPECTED;
568 hr = ITfDocumentMgr_Pop(g_dm, 0);
569 ok(SUCCEEDED(hr),"Pop Failed\n");
570 ok(check_context_refcount(cxt2) < cnt, "Ref count did not decrease\n");
571 ok(test_OnPopContext == SINK_FIRED, "OnPopContext sink not fired\n");
573 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
574 ok(SUCCEEDED(hr),"GetTop Failed\n");
575 ok(cxtTest == cxt, "Wrong context on top\n");
576 ITfContext_Release(cxtTest);
578 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
579 ok(SUCCEEDED(hr),"GetBase Failed\n");
580 ok(cxtTest == cxt, "Wrong context on base\n");
581 ITfContext_Release(cxtTest);
583 hr = ITfDocumentMgr_Pop(g_dm, 0);
584 ok(!SUCCEEDED(hr),"Pop Succeeded\n");
586 hr = ITfDocumentMgr_GetTop(g_dm, &cxtTest);
587 ok(SUCCEEDED(hr),"GetTop Failed\n");
588 ok(cxtTest == cxt, "Wrong context on top\n");
589 ITfContext_Release(cxtTest);
591 hr = ITfDocumentMgr_GetBase(g_dm, &cxtTest);
592 ok(SUCCEEDED(hr),"GetBase Failed\n");
593 ok(cxtTest == cxt, "Wrong context on base\n");
594 ITfContext_Release(cxtTest);
596 ITfContext_Release(cxt);
597 ITfContext_Release(cxt2);
598 ITfContext_Release(cxt3);
601 static void test_endSession(void)
603 test_ShouldDeactivate = TRUE;
604 test_CurrentFocus = NULL;
605 test_PrevFocus = g_dm;
606 test_OnSetFocus = SINK_EXPECTED;
607 ITfThreadMgr_Deactivate(g_tm);
608 ok(test_OnSetFocus == SINK_FIRED, "OnSetFocus sink not called\n");
609 test_OnSetFocus = SINK_UNEXPECTED;
612 static void test_TfGuidAtom(void)
614 GUID gtest,g1;
615 HRESULT hr;
616 TfGuidAtom atom1,atom2;
617 BOOL equal;
619 CoCreateGuid(&gtest);
621 /* msdn reports this should return E_INVALIDARG. However my test show it crashing (winxp)*/
623 hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,NULL);
624 ok(hr==E_INVALIDARG,"ITfCategoryMgr_RegisterGUID should have failed\n");
626 hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,&atom1);
627 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
628 hr = ITfCategoryMgr_RegisterGUID(g_cm,&gtest,&atom2);
629 ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterGUID failed\n");
630 ok(atom1 == atom2,"atoms do not match\n");
631 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,NULL);
632 ok(hr==E_INVALIDARG,"ITfCategoryMgr_GetGUID should have failed\n");
633 hr = ITfCategoryMgr_GetGUID(g_cm,atom2,&g1);
634 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
635 ok(IsEqualGUID(&g1,&gtest),"guids do not match\n");
636 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,&gtest,NULL);
637 ok(hr==E_INVALIDARG,"ITfCategoryMgr_IsEqualTfGuidAtom should have failed\n");
638 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,atom1,&gtest,&equal);
639 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
640 ok(equal == TRUE,"Equal value invalid\n");
642 /* show that cid and tid TfClientIds are also TfGuidAtoms */
643 hr = ITfCategoryMgr_IsEqualTfGuidAtom(g_cm,tid,&CLSID_FakeService,&equal);
644 ok(SUCCEEDED(hr),"ITfCategoryMgr_IsEqualTfGuidAtom failed\n");
645 todo_wine ok(equal == TRUE,"Equal value invalid\n");
646 hr = ITfCategoryMgr_GetGUID(g_cm,cid,&g1);
647 ok(SUCCEEDED(hr),"ITfCategoryMgr_GetGUID failed\n");
648 todo_wine ok(!IsEqualGUID(&g1,&GUID_NULL),"guid should not be NULL\n");
651 START_TEST(inputprocessor)
653 if (SUCCEEDED(initialize()))
655 test_Register();
656 test_RegisterCategory();
657 test_EnumInputProcessorInfo();
658 test_Enable();
659 test_ThreadMgrAdviseSinks();
660 test_Activate();
661 test_startSession();
662 test_TfGuidAtom();
663 test_KeystrokeMgr();
664 test_endSession();
665 test_EnumLanguageProfiles();
666 test_FindClosestCategory();
667 test_Disable();
668 test_ThreadMgrUnadviseSinks();
669 test_UnregisterCategory();
670 test_Unregister();
672 else
673 skip("Unable to create InputProcessor\n");
674 cleanup();
677 /**********************************************************************
678 * ITextStoreACP
679 **********************************************************************/
680 typedef struct tagTextStoreACP
682 const ITextStoreACPVtbl *TextStoreACPVtbl;
683 LONG refCount;
684 } TextStoreACP;
686 static void TextStoreACP_Destructor(TextStoreACP *This)
688 HeapFree(GetProcessHeap(),0,This);
691 static HRESULT WINAPI TextStoreACP_QueryInterface(ITextStoreACP *iface, REFIID iid, LPVOID *ppvOut)
693 TextStoreACP *This = (TextStoreACP *)iface;
694 *ppvOut = NULL;
696 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITextStoreACP))
698 *ppvOut = This;
701 if (*ppvOut)
703 IUnknown_AddRef(iface);
704 return S_OK;
707 return E_NOINTERFACE;
710 static ULONG WINAPI TextStoreACP_AddRef(ITextStoreACP *iface)
712 TextStoreACP *This = (TextStoreACP *)iface;
713 return InterlockedIncrement(&This->refCount);
716 static ULONG WINAPI TextStoreACP_Release(ITextStoreACP *iface)
718 TextStoreACP *This = (TextStoreACP *)iface;
719 ULONG ret;
721 ret = InterlockedDecrement(&This->refCount);
722 if (ret == 0)
723 TextStoreACP_Destructor(This);
724 return ret;
727 static HRESULT WINAPI TextStoreACP_AdviseSink(ITextStoreACP *iface,
728 REFIID riid, IUnknown *punk, DWORD dwMask)
730 trace("\n");
731 return S_OK;
734 static HRESULT WINAPI TextStoreACP_UnadviseSink(ITextStoreACP *iface,
735 IUnknown *punk)
737 trace("\n");
738 return S_OK;
740 static HRESULT WINAPI TextStoreACP_RequestLock(ITextStoreACP *iface,
741 DWORD dwLockFlags, HRESULT *phrSession)
743 trace("\n");
744 return S_OK;
746 static HRESULT WINAPI TextStoreACP_GetStatus(ITextStoreACP *iface,
747 TS_STATUS *pdcs)
749 trace("\n");
750 return S_OK;
752 static HRESULT WINAPI TextStoreACP_QueryInsert(ITextStoreACP *iface,
753 LONG acpTestStart, LONG acpTestEnd, ULONG cch, LONG *pacpResultStart,
754 LONG *pacpResultEnd)
756 trace("\n");
757 return S_OK;
759 static HRESULT WINAPI TextStoreACP_GetSelection(ITextStoreACP *iface,
760 ULONG ulIndex, ULONG ulCount, TS_SELECTION_ACP *pSelection, ULONG *pcFetched)
762 trace("\n");
763 return S_OK;
765 static HRESULT WINAPI TextStoreACP_SetSelection(ITextStoreACP *iface,
766 ULONG ulCount, const TS_SELECTION_ACP *pSelection)
768 trace("\n");
769 return S_OK;
771 static HRESULT WINAPI TextStoreACP_GetText(ITextStoreACP *iface,
772 LONG acpStart, LONG acpEnd, WCHAR *pchPlain, ULONG cchPlainReq,
773 ULONG *pcchPlainRet, TS_RUNINFO *prgRunInfo, ULONG cRunInfoReq,
774 ULONG *pcRunInfoRet, LONG *pacpNext)
776 trace("\n");
777 return S_OK;
779 static HRESULT WINAPI TextStoreACP_SetText(ITextStoreACP *iface,
780 DWORD dwFlags, LONG acpStart, LONG acpEnd, const WCHAR *pchText,
781 ULONG cch, TS_TEXTCHANGE *pChange)
783 trace("\n");
784 return S_OK;
786 static HRESULT WINAPI TextStoreACP_GetFormattedText(ITextStoreACP *iface,
787 LONG acpStart, LONG acpEnd, IDataObject **ppDataObject)
789 trace("\n");
790 return S_OK;
792 static HRESULT WINAPI TextStoreACP_GetEmbedded(ITextStoreACP *iface,
793 LONG acpPos, REFGUID rguidService, REFIID riid, IUnknown **ppunk)
795 trace("\n");
796 return S_OK;
798 static HRESULT WINAPI TextStoreACP_QueryInsertEmbedded(ITextStoreACP *iface,
799 const GUID *pguidService, const FORMATETC *pFormatEtc, BOOL *pfInsertable)
801 trace("\n");
802 return S_OK;
804 static HRESULT WINAPI TextStoreACP_InsertEmbedded(ITextStoreACP *iface,
805 DWORD dwFlags, LONG acpStart, LONG acpEnd, IDataObject *pDataObject,
806 TS_TEXTCHANGE *pChange)
808 trace("\n");
809 return S_OK;
811 static HRESULT WINAPI TextStoreACP_InsertTextAtSelection(ITextStoreACP *iface,
812 DWORD dwFlags, const WCHAR *pchText, ULONG cch, LONG *pacpStart,
813 LONG *pacpEnd, TS_TEXTCHANGE *pChange)
815 trace("\n");
816 return S_OK;
818 static HRESULT WINAPI TextStoreACP_InsertEmbeddedAtSelection(ITextStoreACP *iface,
819 DWORD dwFlags, IDataObject *pDataObject, LONG *pacpStart, LONG *pacpEnd,
820 TS_TEXTCHANGE *pChange)
822 trace("\n");
823 return S_OK;
825 static HRESULT WINAPI TextStoreACP_RequestSupportedAttrs(ITextStoreACP *iface,
826 DWORD dwFlags, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs)
828 trace("\n");
829 return S_OK;
831 static HRESULT WINAPI TextStoreACP_RequestAttrsAtPosition(ITextStoreACP *iface,
832 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
833 DWORD dwFlags)
835 trace("\n");
836 return S_OK;
838 static HRESULT WINAPI TextStoreACP_RequestAttrsTransitioningAtPosition(ITextStoreACP *iface,
839 LONG acpPos, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
840 DWORD dwFlags)
842 trace("\n");
843 return S_OK;
845 static HRESULT WINAPI TextStoreACP_FindNextAttrTransition(ITextStoreACP *iface,
846 LONG acpStart, LONG acpHalt, ULONG cFilterAttrs, const TS_ATTRID *paFilterAttrs,
847 DWORD dwFlags, LONG *pacpNext, BOOL *pfFound, LONG *plFoundOffset)
849 trace("\n");
850 return S_OK;
852 static HRESULT WINAPI TextStoreACP_RetrieveRequestedAttrs(ITextStoreACP *iface,
853 ULONG ulCount, TS_ATTRVAL *paAttrVals, ULONG *pcFetched)
855 trace("\n");
856 return S_OK;
858 static HRESULT WINAPI TextStoreACP_GetEndACP(ITextStoreACP *iface,
859 LONG *pacp)
861 trace("\n");
862 return S_OK;
864 static HRESULT WINAPI TextStoreACP_GetActiveView(ITextStoreACP *iface,
865 TsViewCookie *pvcView)
867 trace("\n");
868 return S_OK;
870 static HRESULT WINAPI TextStoreACP_GetACPFromPoint(ITextStoreACP *iface,
871 TsViewCookie vcView, const POINT *ptScreen, DWORD dwFlags,
872 LONG *pacp)
874 trace("\n");
875 return S_OK;
877 static HRESULT WINAPI TextStoreACP_GetTextExt(ITextStoreACP *iface,
878 TsViewCookie vcView, LONG acpStart, LONG acpEnd, RECT *prc,
879 BOOL *pfClipped)
881 trace("\n");
882 return S_OK;
884 static HRESULT WINAPI TextStoreACP_GetScreenExt(ITextStoreACP *iface,
885 TsViewCookie vcView, RECT *prc)
887 trace("\n");
888 return S_OK;
890 static HRESULT WINAPI TextStoreACP_GetWnd(ITextStoreACP *iface,
891 TsViewCookie vcView, HWND *phwnd)
893 trace("\n");
894 return S_OK;
897 static const ITextStoreACPVtbl TextStoreACP_TextStoreACPVtbl =
899 TextStoreACP_QueryInterface,
900 TextStoreACP_AddRef,
901 TextStoreACP_Release,
903 TextStoreACP_AdviseSink,
904 TextStoreACP_UnadviseSink,
905 TextStoreACP_RequestLock,
906 TextStoreACP_GetStatus,
907 TextStoreACP_QueryInsert,
908 TextStoreACP_GetSelection,
909 TextStoreACP_SetSelection,
910 TextStoreACP_GetText,
911 TextStoreACP_SetText,
912 TextStoreACP_GetFormattedText,
913 TextStoreACP_GetEmbedded,
914 TextStoreACP_QueryInsertEmbedded,
915 TextStoreACP_InsertEmbedded,
916 TextStoreACP_InsertTextAtSelection,
917 TextStoreACP_InsertEmbeddedAtSelection,
918 TextStoreACP_RequestSupportedAttrs,
919 TextStoreACP_RequestAttrsAtPosition,
920 TextStoreACP_RequestAttrsTransitioningAtPosition,
921 TextStoreACP_FindNextAttrTransition,
922 TextStoreACP_RetrieveRequestedAttrs,
923 TextStoreACP_GetEndACP,
924 TextStoreACP_GetActiveView,
925 TextStoreACP_GetACPFromPoint,
926 TextStoreACP_GetTextExt,
927 TextStoreACP_GetScreenExt,
928 TextStoreACP_GetWnd
931 HRESULT TextStoreACP_Constructor(IUnknown **ppOut)
933 TextStoreACP *This;
935 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextStoreACP));
936 if (This == NULL)
937 return E_OUTOFMEMORY;
939 This->TextStoreACPVtbl = &TextStoreACP_TextStoreACPVtbl;
940 This->refCount = 1;
942 *ppOut = (IUnknown *)This;
943 return S_OK;
946 /**********************************************************************
947 * ITfThreadMgrEventSink
948 **********************************************************************/
949 typedef struct tagThreadMgrEventSink
951 const ITfThreadMgrEventSinkVtbl *ThreadMgrEventSinkVtbl;
952 LONG refCount;
953 } ThreadMgrEventSink;
955 static void ThreadMgrEventSink_Destructor(ThreadMgrEventSink *This)
957 HeapFree(GetProcessHeap(),0,This);
960 static HRESULT WINAPI ThreadMgrEventSink_QueryInterface(ITfThreadMgrEventSink *iface, REFIID iid, LPVOID *ppvOut)
962 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
963 *ppvOut = NULL;
965 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfThreadMgrEventSink))
967 *ppvOut = This;
970 if (*ppvOut)
972 IUnknown_AddRef(iface);
973 return S_OK;
976 return E_NOINTERFACE;
979 static ULONG WINAPI ThreadMgrEventSink_AddRef(ITfThreadMgrEventSink *iface)
981 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
982 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
983 return InterlockedIncrement(&This->refCount);
986 static ULONG WINAPI ThreadMgrEventSink_Release(ITfThreadMgrEventSink *iface)
988 ThreadMgrEventSink *This = (ThreadMgrEventSink *)iface;
989 ULONG ret;
991 ok (tmSinkRefCount == This->refCount,"ThreadMgrEventSink refcount off %i vs %i\n",This->refCount,tmSinkRefCount);
992 ret = InterlockedDecrement(&This->refCount);
993 if (ret == 0)
994 ThreadMgrEventSink_Destructor(This);
995 return ret;
998 static HRESULT WINAPI ThreadMgrEventSink_OnInitDocumentMgr(ITfThreadMgrEventSink *iface,
999 ITfDocumentMgr *pdim)
1001 ok(test_OnInitDocumentMgr == SINK_EXPECTED, "Unexpected OnInitDocumentMgr sink\n");
1002 test_OnInitDocumentMgr = SINK_FIRED;
1003 return S_OK;
1006 static HRESULT WINAPI ThreadMgrEventSink_OnUninitDocumentMgr(ITfThreadMgrEventSink *iface,
1007 ITfDocumentMgr *pdim)
1009 trace("\n");
1010 return S_OK;
1013 static HRESULT WINAPI ThreadMgrEventSink_OnSetFocus(ITfThreadMgrEventSink *iface,
1014 ITfDocumentMgr *pdimFocus, ITfDocumentMgr *pdimPrevFocus)
1016 ok(test_OnSetFocus == SINK_EXPECTED, "Unexpected OnSetFocus sink\n");
1017 ok(pdimFocus == test_CurrentFocus,"Sink reports wrong focus\n");
1018 ok(pdimPrevFocus == test_PrevFocus,"Sink reports wrong previous focus\n");
1019 test_OnSetFocus = SINK_FIRED;
1020 return S_OK;
1023 static HRESULT WINAPI ThreadMgrEventSink_OnPushContext(ITfThreadMgrEventSink *iface,
1024 ITfContext *pic)
1026 ok(test_OnPushContext == SINK_EXPECTED, "Unexpected OnPushContext sink\n");
1027 test_OnPushContext = SINK_FIRED;
1028 return S_OK;
1031 static HRESULT WINAPI ThreadMgrEventSink_OnPopContext(ITfThreadMgrEventSink *iface,
1032 ITfContext *pic)
1034 ok(test_OnPopContext == SINK_EXPECTED, "Unexpected OnPopContext sink\n");
1035 test_OnPopContext = SINK_FIRED;
1036 return S_OK;
1039 static const ITfThreadMgrEventSinkVtbl ThreadMgrEventSink_ThreadMgrEventSinkVtbl =
1041 ThreadMgrEventSink_QueryInterface,
1042 ThreadMgrEventSink_AddRef,
1043 ThreadMgrEventSink_Release,
1045 ThreadMgrEventSink_OnInitDocumentMgr,
1046 ThreadMgrEventSink_OnUninitDocumentMgr,
1047 ThreadMgrEventSink_OnSetFocus,
1048 ThreadMgrEventSink_OnPushContext,
1049 ThreadMgrEventSink_OnPopContext
1052 HRESULT ThreadMgrEventSink_Constructor(IUnknown **ppOut)
1054 ThreadMgrEventSink *This;
1056 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(ThreadMgrEventSink));
1057 if (This == NULL)
1058 return E_OUTOFMEMORY;
1060 This->ThreadMgrEventSinkVtbl = &ThreadMgrEventSink_ThreadMgrEventSinkVtbl;
1061 This->refCount = 1;
1063 *ppOut = (IUnknown *)This;
1064 return S_OK;
1068 /********************************************************************************************
1069 * Stub text service for testing
1070 ********************************************************************************************/
1072 static LONG TS_refCount;
1073 static IClassFactory *cf;
1074 static DWORD regid;
1076 typedef HRESULT (*LPFNCONSTRUCTOR)(IUnknown *pUnkOuter, IUnknown **ppvOut);
1078 typedef struct tagClassFactory
1080 const IClassFactoryVtbl *vtbl;
1081 LONG ref;
1082 LPFNCONSTRUCTOR ctor;
1083 } ClassFactory;
1085 typedef struct tagTextService
1087 const ITfTextInputProcessorVtbl *TextInputProcessorVtbl;
1088 LONG refCount;
1089 } TextService;
1091 static void ClassFactory_Destructor(ClassFactory *This)
1093 HeapFree(GetProcessHeap(),0,This);
1094 TS_refCount--;
1097 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, LPVOID *ppvOut)
1099 *ppvOut = NULL;
1100 if (IsEqualIID(riid, &IID_IClassFactory) || IsEqualIID(riid, &IID_IUnknown))
1102 IClassFactory_AddRef(iface);
1103 *ppvOut = iface;
1104 return S_OK;
1107 return E_NOINTERFACE;
1110 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
1112 ClassFactory *This = (ClassFactory *)iface;
1113 return InterlockedIncrement(&This->ref);
1116 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
1118 ClassFactory *This = (ClassFactory *)iface;
1119 ULONG ret = InterlockedDecrement(&This->ref);
1121 if (ret == 0)
1122 ClassFactory_Destructor(This);
1123 return ret;
1126 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface, IUnknown *punkOuter, REFIID iid, LPVOID *ppvOut)
1128 ClassFactory *This = (ClassFactory *)iface;
1129 HRESULT ret;
1130 IUnknown *obj;
1132 ret = This->ctor(punkOuter, &obj);
1133 if (FAILED(ret))
1134 return ret;
1135 ret = IUnknown_QueryInterface(obj, iid, ppvOut);
1136 IUnknown_Release(obj);
1137 return ret;
1140 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
1142 if(fLock)
1143 InterlockedIncrement(&TS_refCount);
1144 else
1145 InterlockedDecrement(&TS_refCount);
1147 return S_OK;
1150 static const IClassFactoryVtbl ClassFactoryVtbl = {
1151 /* IUnknown */
1152 ClassFactory_QueryInterface,
1153 ClassFactory_AddRef,
1154 ClassFactory_Release,
1156 /* IClassFactory*/
1157 ClassFactory_CreateInstance,
1158 ClassFactory_LockServer
1161 static HRESULT ClassFactory_Constructor(LPFNCONSTRUCTOR ctor, LPVOID *ppvOut)
1163 ClassFactory *This = HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory));
1164 This->vtbl = &ClassFactoryVtbl;
1165 This->ref = 1;
1166 This->ctor = ctor;
1167 *ppvOut = (LPVOID)This;
1168 TS_refCount++;
1169 return S_OK;
1172 static void TextService_Destructor(TextService *This)
1174 HeapFree(GetProcessHeap(),0,This);
1177 static HRESULT WINAPI TextService_QueryInterface(ITfTextInputProcessor *iface, REFIID iid, LPVOID *ppvOut)
1179 TextService *This = (TextService *)iface;
1180 *ppvOut = NULL;
1182 if (IsEqualIID(iid, &IID_IUnknown) || IsEqualIID(iid, &IID_ITfTextInputProcessor))
1184 *ppvOut = This;
1187 if (*ppvOut)
1189 IUnknown_AddRef(iface);
1190 return S_OK;
1193 return E_NOINTERFACE;
1196 static ULONG WINAPI TextService_AddRef(ITfTextInputProcessor *iface)
1198 TextService *This = (TextService *)iface;
1199 return InterlockedIncrement(&This->refCount);
1202 static ULONG WINAPI TextService_Release(ITfTextInputProcessor *iface)
1204 TextService *This = (TextService *)iface;
1205 ULONG ret;
1207 ret = InterlockedDecrement(&This->refCount);
1208 if (ret == 0)
1209 TextService_Destructor(This);
1210 return ret;
1213 static HRESULT WINAPI TextService_Activate(ITfTextInputProcessor *iface,
1214 ITfThreadMgr *ptim, TfClientId id)
1216 trace("TextService_Activate\n");
1217 ok(test_ShouldActivate,"Activation came unexpectedly\n");
1218 tid = id;
1219 return S_OK;
1222 static HRESULT WINAPI TextService_Deactivate(ITfTextInputProcessor *iface)
1224 trace("TextService_Deactivate\n");
1225 ok(test_ShouldDeactivate,"Deactivation came unexpectedly\n");
1226 return S_OK;
1229 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl=
1231 TextService_QueryInterface,
1232 TextService_AddRef,
1233 TextService_Release,
1235 TextService_Activate,
1236 TextService_Deactivate
1239 HRESULT TextService_Constructor(IUnknown *pUnkOuter, IUnknown **ppOut)
1241 TextService *This;
1242 if (pUnkOuter)
1243 return CLASS_E_NOAGGREGATION;
1245 This = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(TextService));
1246 if (This == NULL)
1247 return E_OUTOFMEMORY;
1249 This->TextInputProcessorVtbl= &TextService_TextInputProcessorVtbl;
1250 This->refCount = 1;
1252 *ppOut = (IUnknown *)This;
1253 return S_OK;
1256 HRESULT RegisterTextService(REFCLSID rclsid)
1258 ClassFactory_Constructor( TextService_Constructor ,(LPVOID*)&cf);
1259 return CoRegisterClassObject(rclsid, (IUnknown*) cf, CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid);
1262 HRESULT UnregisterTextService()
1264 return CoRevokeClassObject(regid);