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
24 #include "wine/test.h"
32 static ITfInputProcessorProfiles
* g_ipp
;
33 static LANGID gLangid
;
34 static ITfCategoryMgr
* g_cm
= NULL
;
35 static ITfThreadMgr
* g_tm
= NULL
;
37 HRESULT
RegisterTextService(REFCLSID rclsid
);
38 HRESULT
UnregisterTextService();
40 DEFINE_GUID(CLSID_FakeService
, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
41 DEFINE_GUID(CLSID_TF_InputProcessorProfiles
, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
42 DEFINE_GUID(CLSID_TF_CategoryMgr
, 0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
43 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD
, 0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
44 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH
, 0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
45 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING
, 0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
46 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, 0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
47 DEFINE_GUID(GUID_NULL
,0,0,0,0,0,0,0,0,0,0,0);
48 DEFINE_GUID(CLSID_TF_ThreadMgr
, 0x529a9e6b,0x6587,0x4f23,0xab,0x9e,0x9c,0x7d,0x68,0x3e,0x3c,0x50);
51 static HRESULT
initialize(void)
55 hr
= CoCreateInstance (&CLSID_TF_InputProcessorProfiles
, NULL
,
56 CLSCTX_INPROC_SERVER
, &IID_ITfInputProcessorProfiles
, (void**)&g_ipp
);
58 hr
= CoCreateInstance (&CLSID_TF_CategoryMgr
, NULL
,
59 CLSCTX_INPROC_SERVER
, &IID_ITfCategoryMgr
, (void**)&g_cm
);
61 hr
= CoCreateInstance (&CLSID_TF_ThreadMgr
, NULL
,
62 CLSCTX_INPROC_SERVER
, &IID_ITfThreadMgr
, (void**)&g_tm
);
66 static void cleanup(void)
69 ITfInputProcessorProfiles_Release(g_ipp
);
71 ITfCategoryMgr_Release(g_cm
);
73 ITfThreadMgr_Release(g_tm
);
77 static void test_Register(void)
81 static const WCHAR szDesc
[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
82 static const WCHAR szFile
[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
84 hr
= RegisterTextService(&CLSID_FakeService
);
85 ok(SUCCEEDED(hr
),"Unable to register COM for TextService\n");
86 hr
= ITfInputProcessorProfiles_Register(g_ipp
, &CLSID_FakeService
);
87 ok(SUCCEEDED(hr
),"Unable to register text service(%x)\n",hr
);
88 hr
= ITfInputProcessorProfiles_AddLanguageProfile(g_ipp
, &CLSID_FakeService
, gLangid
, &CLSID_FakeService
, szDesc
, sizeof(szDesc
)/sizeof(WCHAR
), szFile
, sizeof(szFile
)/sizeof(WCHAR
), 1);
89 ok(SUCCEEDED(hr
),"Unable to add Language Profile (%x)\n",hr
);
92 static void test_Unregister(void)
95 hr
= ITfInputProcessorProfiles_Unregister(g_ipp
, &CLSID_FakeService
);
96 ok(SUCCEEDED(hr
),"Unable to unregister text service(%x)\n",hr
);
97 UnregisterTextService();
100 static void test_EnumInputProcessorInfo(void)
105 if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp
, &ppEnum
)))
109 while (IEnumGUID_Next(ppEnum
, 1, &g
, &fetched
) == S_OK
)
111 if(IsEqualGUID(&g
,&CLSID_FakeService
))
115 ok(found
,"Did not find registered text service\n");
118 static void test_EnumLanguageProfiles(void)
121 IEnumTfLanguageProfiles
*ppEnum
;
122 if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp
,gLangid
,&ppEnum
)))
124 TF_LANGUAGEPROFILE profile
;
125 while (IEnumTfLanguageProfiles_Next(ppEnum
,1,&profile
,NULL
)==S_OK
)
127 if (IsEqualGUID(&profile
.clsid
,&CLSID_FakeService
))
130 ok(profile
.langid
== gLangid
, "LangId Incorrect\n");
131 ok(IsEqualGUID(&profile
.catid
,&GUID_TFCAT_TIP_KEYBOARD
), "CatId Incorrect\n");
132 ok(IsEqualGUID(&profile
.guidProfile
,&CLSID_FakeService
), "guidProfile Incorrect\n");
136 ok(found
,"Registered text service not found\n");
139 static void test_RegisterCategory(void)
142 hr
= ITfCategoryMgr_RegisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_TIP_KEYBOARD
, &CLSID_FakeService
);
143 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterCategory failed\n");
144 hr
= ITfCategoryMgr_RegisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, &CLSID_FakeService
);
145 ok(SUCCEEDED(hr
),"ITfCategoryMgr_RegisterCategory failed\n");
148 static void test_UnregisterCategory(void)
151 hr
= ITfCategoryMgr_UnregisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_TIP_KEYBOARD
, &CLSID_FakeService
);
152 todo_wine
ok(SUCCEEDED(hr
),"ITfCategoryMgr_UnregisterCategory failed\n");
153 hr
= ITfCategoryMgr_UnregisterCategory(g_cm
, &CLSID_FakeService
, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
, &CLSID_FakeService
);
154 todo_wine
ok(SUCCEEDED(hr
),"ITfCategoryMgr_UnregisterCategory failed\n");
157 static void test_FindClosestCategory(void)
161 const GUID
*list
[3] = {&GUID_TFCAT_TIP_SPEECH
, &GUID_TFCAT_TIP_KEYBOARD
, &GUID_TFCAT_TIP_HANDWRITING
};
163 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, NULL
, 0);
164 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
165 ok(IsEqualGUID(&output
,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER
),"Wrong GUID\n");
167 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, list
, 1);
168 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
169 ok(IsEqualGUID(&output
,&GUID_NULL
),"Wrong GUID\n");
171 hr
= ITfCategoryMgr_FindClosestCategory(g_cm
, &CLSID_FakeService
, &output
, list
, 3);
172 ok(SUCCEEDED(hr
),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr
);
173 ok(IsEqualGUID(&output
,&GUID_TFCAT_TIP_KEYBOARD
),"Wrong GUID\n");
176 static void test_Enable(void)
179 BOOL enabled
= FALSE
;
181 hr
= ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, TRUE
);
182 ok(SUCCEEDED(hr
),"Failed to enable text service\n");
183 hr
= ITfInputProcessorProfiles_IsEnabledLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, &enabled
);
184 ok(SUCCEEDED(hr
),"Failed to get enabled state\n");
185 ok(enabled
== TRUE
,"enabled state incorrect\n");
188 static void test_Disable(void)
192 trace("Disabling\n");
193 hr
= ITfInputProcessorProfiles_EnableLanguageProfile(g_ipp
,&CLSID_FakeService
, gLangid
, &CLSID_FakeService
, FALSE
);
194 ok(SUCCEEDED(hr
),"Failed to disable text service\n");
197 START_TEST(inputprocessor
)
199 if (SUCCEEDED(initialize()))
201 gLangid
= GetUserDefaultLCID();
203 test_RegisterCategory();
204 test_EnumInputProcessorInfo();
206 test_EnumLanguageProfiles();
207 test_FindClosestCategory();
209 test_UnregisterCategory();
213 skip("Unable to create InputProcessor\n");
219 /********************************************************************************************
220 * Stub text service for testing
221 ********************************************************************************************/
223 static LONG TS_refCount
;
224 static IClassFactory
*cf
;
227 typedef HRESULT (*LPFNCONSTRUCTOR
)(IUnknown
*pUnkOuter
, IUnknown
**ppvOut
);
229 typedef struct tagClassFactory
231 const IClassFactoryVtbl
*vtbl
;
233 LPFNCONSTRUCTOR ctor
;
236 typedef struct tagTextService
238 const ITfTextInputProcessorVtbl
*TextInputProcessorVtbl
;
242 static void ClassFactory_Destructor(ClassFactory
*This
)
244 HeapFree(GetProcessHeap(),0,This
);
248 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, LPVOID
*ppvOut
)
251 if (IsEqualIID(riid
, &IID_IClassFactory
) || IsEqualIID(riid
, &IID_IUnknown
))
253 IClassFactory_AddRef(iface
);
258 return E_NOINTERFACE
;
261 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
263 ClassFactory
*This
= (ClassFactory
*)iface
;
264 return InterlockedIncrement(&This
->ref
);
267 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
269 ClassFactory
*This
= (ClassFactory
*)iface
;
270 ULONG ret
= InterlockedDecrement(&This
->ref
);
273 ClassFactory_Destructor(This
);
277 static HRESULT WINAPI
ClassFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*punkOuter
, REFIID iid
, LPVOID
*ppvOut
)
279 ClassFactory
*This
= (ClassFactory
*)iface
;
283 ret
= This
->ctor(punkOuter
, &obj
);
286 ret
= IUnknown_QueryInterface(obj
, iid
, ppvOut
);
287 IUnknown_Release(obj
);
291 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
294 InterlockedIncrement(&TS_refCount
);
296 InterlockedDecrement(&TS_refCount
);
301 static const IClassFactoryVtbl ClassFactoryVtbl
= {
303 ClassFactory_QueryInterface
,
305 ClassFactory_Release
,
308 ClassFactory_CreateInstance
,
309 ClassFactory_LockServer
312 static HRESULT
ClassFactory_Constructor(LPFNCONSTRUCTOR ctor
, LPVOID
*ppvOut
)
314 ClassFactory
*This
= HeapAlloc(GetProcessHeap(),0,sizeof(ClassFactory
));
315 This
->vtbl
= &ClassFactoryVtbl
;
318 *ppvOut
= (LPVOID
)This
;
323 static void TextService_Destructor(TextService
*This
)
325 HeapFree(GetProcessHeap(),0,This
);
328 static HRESULT WINAPI
TextService_QueryInterface(ITfTextInputProcessor
*iface
, REFIID iid
, LPVOID
*ppvOut
)
330 TextService
*This
= (TextService
*)iface
;
333 if (IsEqualIID(iid
, &IID_IUnknown
) || IsEqualIID(iid
, &IID_ITfTextInputProcessor
))
340 IUnknown_AddRef(iface
);
344 return E_NOINTERFACE
;
347 static ULONG WINAPI
TextService_AddRef(ITfTextInputProcessor
*iface
)
349 TextService
*This
= (TextService
*)iface
;
350 return InterlockedIncrement(&This
->refCount
);
353 static ULONG WINAPI
TextService_Release(ITfTextInputProcessor
*iface
)
355 TextService
*This
= (TextService
*)iface
;
358 ret
= InterlockedDecrement(&This
->refCount
);
360 TextService_Destructor(This
);
364 static HRESULT WINAPI
TextService_Activate(ITfTextInputProcessor
*iface
,
365 ITfThreadMgr
*ptim
, TfClientId id
)
367 trace("TextService_Activate\n");
371 static HRESULT WINAPI
TextService_Deactivate(ITfTextInputProcessor
*iface
)
373 trace("TextService_Deactivate\n");
377 static const ITfTextInputProcessorVtbl TextService_TextInputProcessorVtbl
=
379 TextService_QueryInterface
,
383 TextService_Activate
,
384 TextService_Deactivate
387 HRESULT
TextService_Constructor(IUnknown
*pUnkOuter
, IUnknown
**ppOut
)
391 return CLASS_E_NOAGGREGATION
;
393 This
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(TextService
));
395 return E_OUTOFMEMORY
;
397 This
->TextInputProcessorVtbl
= &TextService_TextInputProcessorVtbl
;
400 *ppOut
= (IUnknown
*)This
;
404 HRESULT
RegisterTextService(REFCLSID rclsid
)
406 ClassFactory_Constructor( TextService_Constructor
,(LPVOID
*)&cf
);
407 return CoRegisterClassObject(rclsid
, (IUnknown
*) cf
, CLSCTX_INPROC_SERVER
, REGCLS_MULTIPLEUSE
, ®id
);
410 HRESULT
UnregisterTextService()
412 return CoRevokeClassObject(regid
);