msctf: Implement ITfInputProcessorProfiles::EnumInputProcessorInfo.
[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_RegisterCategory(void)
106 {
107     HRESULT hr;
108     hr = ITfCategoryMgr_RegisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
109     ok(SUCCEEDED(hr),"ITfCategoryMgr_RegisterCategory failed\n");
110 }
111
112 static void test_UnregisterCategory(void)
113 {
114     HRESULT hr;
115     hr = ITfCategoryMgr_UnregisterCategory(g_cm, &CLSID_FakeService, &GUID_TFCAT_TIP_KEYBOARD, &CLSID_FakeService);
116     todo_wine ok(SUCCEEDED(hr),"ITfCategoryMgr_UnregisterCategory failed\n");
117 }
118
119 START_TEST(inputprocessor)
120 {
121     if (SUCCEEDED(initialize()))
122     {
123         gLangid = GetUserDefaultLCID();
124         test_Register();
125         test_RegisterCategory();
126         test_EnumInputProcessorInfo();
127         test_UnregisterCategory();
128         test_Unregister();
129     }
130     else
131         skip("Unable to create InputProcessor\n");
132     cleanup();
133 }