msctf: Use ITfCategoryMgr::FindClosestCategory to set catid when enuming language...
[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 "shlwapi.h"
27 #include "shlguid.h"
28 #include "comcat.h"
29 #include "initguid.h"
30 #include "msctf.h"
31
32 static ITfInputProcessorProfiles* g_ipp;
33 static LANGID gLangid;
34 static ITfCategoryMgr * g_cm;
35
36 DEFINE_GUID(CLSID_FakeService, 0xEDE1A7AD,0x66DE,0x47E0,0xB6,0x20,0x3E,0x92,0xF8,0x24,0x6B,0xF3);
37 DEFINE_GUID(CLSID_TF_InputProcessorProfiles, 0x33c53a50,0xf456,0x4884,0xb0,0x49,0x85,0xfd,0x64,0x3e,0xcf,0xed);
38 DEFINE_GUID(CLSID_TF_CategoryMgr,         0xA4B544A1,0x438D,0x4B41,0x93,0x25,0x86,0x95,0x23,0xE2,0xD6,0xC7);
39 DEFINE_GUID(GUID_TFCAT_TIP_KEYBOARD,     0x34745c63,0xb2f0,0x4784,0x8b,0x67,0x5e,0x12,0xc8,0x70,0x1a,0x31);
40 DEFINE_GUID(GUID_TFCAT_TIP_SPEECH,       0xB5A73CD1,0x8355,0x426B,0xA1,0x61,0x25,0x98,0x08,0xF2,0x6B,0x14);
41 DEFINE_GUID(GUID_TFCAT_TIP_HANDWRITING,  0x246ecb87,0xc2f2,0x4abe,0x90,0x5b,0xc8,0xb3,0x8a,0xdd,0x2c,0x43);
42 DEFINE_GUID (GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER,  0x046B8C80,0x1647,0x40F7,0x9B,0x21,0xB9,0x3B,0x81,0xAA,0xBC,0x1B);
43 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
44
45
46 static HRESULT initialize(void)
47 {
48     HRESULT hr;
49     CoInitialize(NULL);
50     hr = CoCreateInstance (&CLSID_TF_InputProcessorProfiles, NULL,
51           CLSCTX_INPROC_SERVER, &IID_ITfInputProcessorProfiles, (void**)&g_ipp);
52     if (SUCCEEDED(hr))
53         hr = CoCreateInstance (&CLSID_TF_CategoryMgr, NULL,
54           CLSCTX_INPROC_SERVER, &IID_ITfCategoryMgr, (void**)&g_cm);
55     return hr;
56 }
57
58 static void cleanup(void)
59 {
60     if (g_ipp)
61         ITfInputProcessorProfiles_Release(g_ipp);
62     if (g_cm)
63         ITfCategoryMgr_Release(g_cm);
64     CoUninitialize();
65 }
66
67 static void test_Register(void)
68 {
69     HRESULT hr;
70
71     static const WCHAR szDesc[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',0};
72     static const WCHAR szFile[] = {'F','a','k','e',' ','W','i','n','e',' ','S','e','r','v','i','c','e',' ','F','i','l','e',0};
73
74     hr = ITfInputProcessorProfiles_Register(g_ipp, &CLSID_FakeService);
75     ok(SUCCEEDED(hr),"Unable to register text service(%x)\n",hr);
76     hr = ITfInputProcessorProfiles_AddLanguageProfile(g_ipp, &CLSID_FakeService, gLangid, &CLSID_FakeService, szDesc, sizeof(szDesc)/sizeof(WCHAR), szFile, sizeof(szFile)/sizeof(WCHAR), 1);
77     ok(SUCCEEDED(hr),"Unable to add Language Profile (%x)\n",hr);
78 }
79
80 static void test_Unregister(void)
81 {
82     HRESULT hr;
83     hr = ITfInputProcessorProfiles_Unregister(g_ipp, &CLSID_FakeService);
84     ok(SUCCEEDED(hr),"Unable to unregister text service(%x)\n",hr);
85 }
86
87 static void test_EnumInputProcessorInfo(void)
88 {
89     IEnumGUID *ppEnum;
90     BOOL found = FALSE;
91
92     if (SUCCEEDED(ITfInputProcessorProfiles_EnumInputProcessorInfo(g_ipp, &ppEnum)))
93     {
94         ULONG fetched;
95         GUID g;
96         while (IEnumGUID_Next(ppEnum, 1, &g, &fetched) == S_OK)
97         {
98             if(IsEqualGUID(&g,&CLSID_FakeService))
99                 found = TRUE;
100         }
101     }
102     ok(found,"Did not find registered text service\n");
103 }
104
105 static void test_EnumLanguageProfiles(void)
106 {
107     BOOL found = FALSE;
108     IEnumTfLanguageProfiles *ppEnum;
109     if (SUCCEEDED(ITfInputProcessorProfiles_EnumLanguageProfiles(g_ipp,gLangid,&ppEnum)))
110     {
111         TF_LANGUAGEPROFILE profile;
112         while (IEnumTfLanguageProfiles_Next(ppEnum,1,&profile,NULL)==S_OK)
113         {
114             if (IsEqualGUID(&profile.clsid,&CLSID_FakeService))
115             {
116                 found = TRUE;
117                 ok(profile.langid == gLangid, "LangId Incorrect\n");
118                 ok(IsEqualGUID(&profile.catid,&GUID_TFCAT_TIP_KEYBOARD), "CatId Incorrect\n");
119                 ok(IsEqualGUID(&profile.guidProfile,&CLSID_FakeService), "guidProfile Incorrect\n");
120             }
121         }
122     }
123     ok(found,"Registered text service not found\n");
124 }
125
126 static void test_RegisterCategory(void)
127 {
128     HRESULT hr;
129     hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
130     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
131     hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
132     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
133 }
134
135 static void test_UnregisterCategory(void)
136 {
137     HRESULT hr;
138     hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
139     todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
140     hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER, &CLSID_FakeService);
141     todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
142 }
143
144 static void test_FindClosestCategory(void)
145 {
146     GUID output;
147     HRESULT hr;
148     const GUID *list[3] = {&GUID_TFCAT_TIP_SPEECH, &GUID_TFCAT_TIP_KEYBOARD, &GUID_TFCAT_TIP_HANDWRITING};
149
150     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, NULL, 0);
151     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
152     ok(IsEqualGUID(&output,&GUID_TFCAT_DISPLAYATTRIBUTEPROVIDER),"Wrong GUID\n");
153
154     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 1);
155     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
156     ok(IsEqualGUID(&output,&GUID_NULL),"Wrong GUID\n");
157
158     hr = ITfCategoryMgr_FindClosestCategory(g_cm, &CLSID_FakeService, &output, list, 3);
159     ok(SUCCEEDED(hr),"ITfCategoryMgr_FindClosestCategory failed (%x)\n",hr);
160     ok(IsEqualGUID(&output,&GUID_TFCAT_TIP_KEYBOARD),"Wrong GUID\n");
161 }
162
163 START_TEST(inputprocessor)
164 {
165     if (SUCCEEDED(initialize()))
166     {
167         gLangid = GetUserDefaultLCID();
168         test_Register();
169         test_RegisterCategory();
170         test_EnumInputProcessorInfo();
171         test_EnumLanguageProfiles();
172         test_FindClosestCategory();
173         test_UnregisterCategory();
174         test_Unregister();
175     }
176     else
177         skip("Unable to create InputProcessor\n");
178     cleanup();
179 }