sapi: Implement ISpRegDataKey CreateKey.
[wine.git] / dlls / sapi / tests / token.c
blob63f5c651a50e8c45e1cf6284c51bd4769a8d49df
1 /*
2 * Speech API (SAPI) token tests.
4 * Copyright (C) 2017 Huw Davies
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 #define COBJMACROS
23 #include "initguid.h"
24 #include "sapiddk.h"
25 #include "sperror.h"
27 #include "wine/test.h"
29 static void test_data_key(void)
31 ISpRegDataKey *data_key;
32 ISpDataKey *sub;
33 HRESULT hr;
34 HKEY key;
35 LONG res;
37 hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_INPROC_SERVER,
38 &IID_ISpRegDataKey, (void **)&data_key );
39 ok( hr == S_OK, "got %08lx\n", hr );
41 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Winetest\\sapi", 0, NULL, 0, KEY_ALL_ACCESS,
42 NULL, &key, NULL );
43 ok( res == ERROR_SUCCESS, "got %ld\n", res );
45 hr = ISpRegDataKey_CreateKey( data_key, L"Testing", &sub );
46 ok( hr == E_HANDLE, "got %08lx\n", hr );
48 hr = ISpRegDataKey_SetKey( data_key, key, FALSE );
49 ok( hr == S_OK, "got %08lx\n", hr );
50 hr = ISpRegDataKey_SetKey( data_key, key, FALSE );
51 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
53 hr = ISpRegDataKey_CreateKey( data_key, L"Testing", &sub );
54 ok( hr == S_OK, "got %08lx\n", hr );
55 ISpDataKey_Release(sub);
57 ISpRegDataKey_Release( data_key );
60 static void test_token_category(void)
62 ISpObjectTokenCategory *cat;
63 IEnumSpObjectTokens *enum_tokens;
64 HRESULT hr;
65 ULONG count;
67 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
68 &IID_ISpObjectTokenCategory, (void **)&cat );
69 ok( hr == S_OK, "got %08lx\n", hr );
71 hr = ISpObjectTokenCategory_EnumTokens( cat, NULL, NULL, &enum_tokens );
72 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
74 hr = ISpObjectTokenCategory_SetId( cat, L"bogus", FALSE );
75 ok( hr == SPERR_INVALID_REGISTRY_KEY, "got %08lx\n", hr );
77 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_VOICES, FALSE );
78 ok( hr == S_OK, "got %08lx\n", hr );
80 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_VOICES, FALSE );
81 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
83 hr = ISpObjectTokenCategory_EnumTokens( cat, NULL, NULL, &enum_tokens );
84 ok( hr == S_OK, "got %08lx\n", hr );
86 hr = IEnumSpObjectTokens_GetCount( enum_tokens, &count );
87 ok( hr == S_OK, "got %08lx\n", hr );
89 IEnumSpObjectTokens_Release( enum_tokens );
90 ISpObjectTokenCategory_Release( cat );
93 static void test_token_enum(void)
95 ISpObjectTokenEnumBuilder *token_enum;
96 HRESULT hr;
97 ISpObjectToken *token;
98 ULONG count;
100 hr = CoCreateInstance( &CLSID_SpObjectTokenEnum, NULL, CLSCTX_INPROC_SERVER,
101 &IID_ISpObjectTokenEnumBuilder, (void **)&token_enum );
102 ok( hr == S_OK, "got %08lx\n", hr );
104 hr = ISpObjectTokenEnumBuilder_GetCount( token_enum, &count );
105 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
107 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 1, &token, &count );
108 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
110 hr = ISpObjectTokenEnumBuilder_SetAttribs( token_enum, NULL, NULL );
111 ok( hr == S_OK, "got %08lx\n", hr );
113 count = 0xdeadbeef;
114 hr = ISpObjectTokenEnumBuilder_GetCount( token_enum, &count );
115 ok( hr == S_OK, "got %08lx\n", hr );
116 ok( count == 0, "got %lu\n", count );
118 count = 0xdeadbeef;
119 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 1, &token, &count );
120 ok( hr == S_FALSE, "got %08lx\n", hr );
121 ok( count == 0, "got %lu\n", count );
123 ISpObjectTokenEnumBuilder_Release( token_enum );
126 static void test_default_token_id(void)
128 ISpObjectTokenCategory *cat;
129 HRESULT hr;
130 LPWSTR token_id = NULL;
131 LONG res;
132 WCHAR regvalue[512];
133 DWORD regvalue_size;
135 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
136 &IID_ISpObjectTokenCategory, (void **)&cat );
137 ok( hr == S_OK, "got %08lx\n", hr );
139 token_id = (LPWSTR)0xdeadbeef;
140 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
141 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
142 ok( token_id == (LPWSTR)0xdeadbeef, "got %p\n", token_id );
144 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL );
145 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
147 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_AUDIOOUT, FALSE );
148 ok( hr == S_OK, "got %08lx\n", hr );
150 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL );
151 ok( hr == E_POINTER, "got %08lx\n", hr );
153 token_id = (LPWSTR)0xdeadbeef;
154 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
156 /* AudioOutput under windows server returns this error */
157 if (hr == SPERR_NOT_FOUND) {
158 /* also happens if TokenEnums/Tokens is empty or doesn't exist */
159 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
160 return;
163 ok( hr == S_OK, "got %08lx\n", hr );
164 ok( token_id != (LPWSTR)0xdeadbeef && token_id != NULL, "got %p\n", token_id );
166 regvalue_size = sizeof( regvalue );
167 res = RegGetValueW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Speech\\AudioOutput",
168 L"DefaultDefaultTokenId", RRF_RT_REG_SZ, NULL,
169 (LPVOID)&regvalue, &regvalue_size);
170 if (res == ERROR_FILE_NOT_FOUND) {
171 skip( "DefaultDefaultTokenId not found for AudioOutput category (%s)\n",
172 wine_dbgstr_w(token_id) );
173 } else {
174 ok( res == ERROR_SUCCESS, "got %08lx\n", res );
175 ok( !wcscmp(regvalue, token_id),
176 "GetDefaultTokenId (%s) should be equal to the DefaultDefaultTokenId key (%s)\n",
177 wine_dbgstr_w(token_id), wine_dbgstr_w(regvalue) );
180 CoTaskMemFree( token_id );
181 ISpObjectTokenCategory_Release( cat );
184 static void test_object_token(void)
186 ISpObjectToken *token;
187 HRESULT hr;
188 LPWSTR tempW, token_id;
189 ISpObjectTokenCategory *cat;
191 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
192 &IID_ISpObjectToken, (void **)&token );
193 ok( hr == S_OK, "got %08lx\n", hr );
195 hr = ISpObjectToken_GetId( token, NULL );
196 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
198 tempW = (LPWSTR)0xdeadbeef;
199 hr = ISpObjectToken_GetId( token, &tempW );
200 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
201 ok( tempW == (LPWSTR)0xdeadbeef, "got %s\n", wine_dbgstr_w(tempW) );
203 hr = ISpObjectToken_GetCategory( token, NULL );
204 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
206 cat = (LPVOID)0xdeadbeef;
207 hr = ISpObjectToken_GetCategory( token, &cat );
208 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
209 ok( cat == (LPVOID)0xdeadbeef, "got %p\n", cat );
211 hr = ISpObjectToken_SetId( token, NULL, NULL, FALSE );
212 ok( hr == E_POINTER, "got %08lx\n", hr );
213 hr = ISpObjectToken_SetId( token, L"bogus", NULL, FALSE );
214 ok( hr == E_POINTER, "got %08lx\n", hr );
216 hr = ISpObjectToken_SetId( token, NULL, L"bogus", FALSE );
217 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
218 hr = ISpObjectToken_SetId( token, NULL, L"HKEY_LOCAL_MACHINE\\SOFTWARE\\winetest bogus", FALSE );
219 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
221 /* SetId succeeds even if the key is invalid, but exists */
222 hr = ISpObjectToken_SetId( token, NULL, L"HKEY_LOCAL_MACHINE\\SOFTWARE", FALSE );
223 ok( hr == S_OK, "got %08lx\n", hr );
225 hr = ISpObjectToken_SetId( token, NULL, NULL, FALSE );
226 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
227 hr = ISpObjectToken_SetId( token, NULL, L"bogus", FALSE );
228 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
230 hr = ISpObjectToken_GetId( token, NULL );
231 ok( hr == E_POINTER, "got %08lx\n", hr );
233 hr = ISpObjectToken_GetCategory( token, NULL );
234 todo_wine ok( hr == E_POINTER, "got %08lx\n", hr );
236 tempW = NULL;
237 hr = ISpObjectToken_GetId( token, &tempW );
238 ok( hr == S_OK, "got %08lx\n", hr );
239 ok( tempW != NULL, "got %p\n", tempW );
240 if (tempW) {
241 ok( !wcscmp(tempW, L"HKEY_LOCAL_MACHINE\\SOFTWARE"), "got %s\n",
242 wine_dbgstr_w(tempW) );
243 CoTaskMemFree( tempW );
246 cat = (LPVOID)0xdeadbeef;
247 hr = ISpObjectToken_GetCategory( token, &cat );
248 todo_wine ok( hr == SPERR_INVALID_REGISTRY_KEY, "got %08lx\n", hr );
249 ok( cat == (LPVOID)0xdeadbeef, "got %p\n", cat );
251 /* get the default token id for SPCAT_AUDIOOUT */
252 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
253 &IID_ISpObjectTokenCategory, (void **)&cat );
254 ok( hr == S_OK, "got %08lx\n", hr );
255 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_AUDIOOUT, FALSE );
256 ok( hr == S_OK, "got %08lx\n", hr );
257 token_id = (LPWSTR)0xdeadbeef;
258 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
259 if (hr == SPERR_NOT_FOUND) {
260 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
261 return;
263 ok( hr == S_OK, "got %08lx\n", hr );
264 ok( token_id != (LPWSTR)0xdeadbeef && token_id != NULL, "got %p\n", token_id );
265 ISpObjectTokenCategory_Release( cat );
267 /* recreate token in order to SetId again */
268 ISpObjectToken_Release( token );
269 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
270 &IID_ISpObjectToken, (void **)&token );
271 ok( hr == S_OK, "got %08lx\n", hr );
273 /* NULL appears to auto-detect the category */
274 hr = ISpObjectToken_SetId( token, NULL, token_id, FALSE );
275 ok( hr == S_OK, "got %08lx\n", hr );
277 tempW = NULL;
278 hr = ISpObjectToken_GetId( token, &tempW );
279 ok( hr == S_OK, "got %08lx\n", hr );
280 ok( tempW != NULL, "got %p\n", tempW );
281 if (tempW) {
282 ok( !wcsncmp(tempW, token_id, wcslen(token_id)),
283 "got %s (expected %s)\n", wine_dbgstr_w(tempW), wine_dbgstr_w(token_id) );
284 CoTaskMemFree( tempW );
287 cat = (LPVOID)0xdeadbeef;
288 hr = ISpObjectToken_GetCategory( token, &cat );
289 todo_wine ok( hr == S_OK, "got %08lx\n", hr );
290 todo_wine ok( cat != (LPVOID)0xdeadbeef, "got %p\n", cat );
291 if (cat != (LPVOID)0xdeadbeef) {
292 tempW = NULL;
293 hr = ISpObjectTokenCategory_GetId( cat, &tempW );
294 todo_wine ok( hr == S_OK, "got %08lx\n", hr );
295 todo_wine ok( tempW != NULL, "got %p\n", tempW );
296 if (tempW) {
297 ok( !wcscmp(tempW, SPCAT_AUDIOOUT), "got %s\n", wine_dbgstr_w(tempW) );
298 CoTaskMemFree( tempW );
301 /* not freed by ISpObjectToken_Release */
302 ISpObjectTokenCategory_Release( cat );
305 ISpObjectToken_Release( token );
308 START_TEST(token)
310 CoInitialize( NULL );
311 test_data_key();
312 test_token_category();
313 test_token_enum();
314 test_default_token_id();
315 test_object_token();
316 CoUninitialize();