sapi: Partially reimplement ISpObjectTokenEnumBuilder storing a token array.
[wine.git] / dlls / sapi / tests / token.c
blob128210fca0b5f45d1e12368b3b80a7806d942325
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;
36 WCHAR *value = NULL;
38 hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_INPROC_SERVER,
39 &IID_ISpRegDataKey, (void **)&data_key );
40 ok( hr == S_OK, "got %08lx\n", hr );
42 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Winetest\\sapi", 0, NULL, 0, KEY_ALL_ACCESS,
43 NULL, &key, NULL );
44 ok( res == ERROR_SUCCESS, "got %ld\n", res );
46 hr = ISpRegDataKey_CreateKey( data_key, L"Testing", &sub );
47 ok( hr == E_HANDLE, "got %08lx\n", hr );
49 hr = ISpRegDataKey_GetStringValue( data_key, L"Voice", &value );
50 ok( hr == E_HANDLE, "got %08lx\n", hr );
52 hr = ISpRegDataKey_SetStringValue( data_key, L"Voice", L"Test" );
53 ok( hr == E_HANDLE, "got %08lx\n", hr );
55 hr = ISpRegDataKey_SetKey( data_key, key, FALSE );
56 ok( hr == S_OK, "got %08lx\n", hr );
57 hr = ISpRegDataKey_SetKey( data_key, key, FALSE );
58 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
60 hr = ISpRegDataKey_GetStringValue( data_key, L"Voice", &value );
61 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
63 hr = ISpRegDataKey_GetStringValue( data_key, L"", &value );
64 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
66 hr = ISpRegDataKey_SetStringValue( data_key, L"Voice", L"Test" );
67 ok( hr == S_OK, "got %08lx\n", hr );
69 hr = ISpRegDataKey_GetStringValue( data_key, L"Voice", &value );
70 ok( hr == S_OK, "got %08lx\n", hr );
71 ok( !wcscmp( value, L"Test" ), "got %s\n", wine_dbgstr_w(value) );
72 CoTaskMemFree( value );
74 hr = ISpRegDataKey_OpenKey( data_key, L"Testing", &sub );
75 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
77 hr = ISpRegDataKey_CreateKey( data_key, L"Testing", &sub );
78 ok( hr == S_OK, "got %08lx\n", hr );
79 ISpDataKey_Release(sub);
81 hr = ISpRegDataKey_OpenKey( data_key, L"Testing", &sub );
82 ok( hr == S_OK, "got %08lx\n", hr );
83 ISpDataKey_Release(sub);
85 ISpRegDataKey_Release( data_key );
87 hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_INPROC_SERVER,
88 &IID_ISpRegDataKey, (void **)&data_key );
89 ok( hr == S_OK, "got %08lx\n", hr );
91 res = RegOpenKeyExA( HKEY_CURRENT_USER, "Software\\Winetest\\sapi", 0, KEY_ALL_ACCESS, &key );
92 ok( res == ERROR_SUCCESS, "got %ld\n", res );
94 hr = ISpRegDataKey_SetKey( data_key, key, TRUE );
95 ok( hr == S_OK, "got %08lx\n", hr );
97 hr = ISpRegDataKey_SetStringValue( data_key, L"Voice2", L"Test2" );
98 ok( hr == S_OK, "got %08lx\n", hr );
100 hr = ISpRegDataKey_GetStringValue( data_key, L"Voice2", &value );
101 ok( hr == S_OK, "got %08lx\n", hr );
102 ok( !wcscmp( value, L"Test2" ), "got %s\n", wine_dbgstr_w(value) );
103 CoTaskMemFree( value );
105 hr = ISpRegDataKey_CreateKey( data_key, L"Testing2", &sub );
106 ok( hr == S_OK, "got %08lx\n", hr );
107 ISpDataKey_Release(sub);
109 ISpRegDataKey_Release( data_key );
112 static void setup_test_voice_tokens(void)
114 HKEY key;
115 ISpRegDataKey *data_key;
116 ISpDataKey *attrs_key;
117 LSTATUS ret;
118 HRESULT hr;
120 ret = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Winetest\\sapi\\TestVoices\\Tokens", 0, NULL, 0,
121 KEY_ALL_ACCESS, NULL, &key, NULL );
122 ok( ret == ERROR_SUCCESS, "got %ld\n", ret );
124 hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_INPROC_SERVER,
125 &IID_ISpRegDataKey, (void **)&data_key );
126 ok( hr == S_OK, "got %08lx\n", hr );
127 hr = ISpRegDataKey_SetKey( data_key, key, FALSE );
128 ok( hr == S_OK, "got %08lx\n", hr );
130 ISpRegDataKey_CreateKey( data_key, L"Voice1\\Attributes", &attrs_key );
131 ISpDataKey_SetStringValue( attrs_key, L"Language", L"409" );
132 ISpDataKey_SetStringValue( attrs_key, L"Gender", L"Female" );
133 ISpDataKey_SetStringValue( attrs_key, L"Age", L"Child" );
134 ISpDataKey_SetStringValue( attrs_key, L"Vendor", L"Vendor2" );
135 ISpDataKey_Release( attrs_key );
137 ISpRegDataKey_CreateKey( data_key, L"Voice2\\Attributes", &attrs_key );
138 ISpDataKey_SetStringValue( attrs_key, L"Language", L"406;407;408;409;40a" );
139 ISpDataKey_SetStringValue( attrs_key, L"Gender", L"Female" );
140 ISpDataKey_SetStringValue( attrs_key, L"Age", L"Adult" );
141 ISpDataKey_SetStringValue( attrs_key, L"Vendor", L"Vendor1" );
142 ISpDataKey_Release( attrs_key );
144 ISpRegDataKey_CreateKey( data_key, L"Voice3\\Attributes", &attrs_key );
145 ISpDataKey_SetStringValue( attrs_key, L"Language", L"409;411" );
146 ISpDataKey_SetStringValue( attrs_key, L"Gender", L"Female" );
147 ISpDataKey_SetStringValue( attrs_key, L"Age", L"Child" );
148 ISpDataKey_SetStringValue( attrs_key, L"Vendor", L"Vendor1" );
149 ISpDataKey_Release( attrs_key );
151 ISpRegDataKey_CreateKey( data_key, L"Voice4\\Attributes", &attrs_key );
152 ISpDataKey_SetStringValue( attrs_key, L"Language", L"411" );
153 ISpDataKey_SetStringValue( attrs_key, L"Gender", L"Male" );
154 ISpDataKey_SetStringValue( attrs_key, L"Age", L"Adult" );
155 ISpDataKey_Release( attrs_key );
157 ISpRegDataKey_CreateKey( data_key, L"Voice5\\Attributes", &attrs_key );
158 ISpDataKey_SetStringValue( attrs_key, L"Language", L"411" );
159 ISpDataKey_SetStringValue( attrs_key, L"Gender", L"Female" );
160 ISpDataKey_SetStringValue( attrs_key, L"Age", L"Adult" );
161 ISpDataKey_SetStringValue( attrs_key, L"Vendor", L"Vendor2" );
162 ISpDataKey_Release( attrs_key );
164 ISpRegDataKey_Release( data_key );
167 static const WCHAR test_cat[] = L"HKEY_CURRENT_USER\\Software\\Winetest\\sapi\\TestVoices";
169 static void test_token_category(void)
171 ISpObjectTokenCategory *cat;
172 IEnumSpObjectTokens *enum_tokens;
173 HRESULT hr;
174 ULONG count;
176 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
177 &IID_ISpObjectTokenCategory, (void **)&cat );
178 ok( hr == S_OK, "got %08lx\n", hr );
180 hr = ISpObjectTokenCategory_EnumTokens( cat, NULL, NULL, &enum_tokens );
181 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
183 hr = ISpObjectTokenCategory_SetId( cat, L"bogus", FALSE );
184 ok( hr == SPERR_INVALID_REGISTRY_KEY, "got %08lx\n", hr );
186 hr = ISpObjectTokenCategory_SetId( cat, test_cat, FALSE );
187 ok( hr == S_OK, "got %08lx\n", hr );
189 hr = ISpObjectTokenCategory_SetId( cat, test_cat, FALSE );
190 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
192 hr = ISpObjectTokenCategory_EnumTokens( cat, NULL, NULL, &enum_tokens );
193 ok( hr == S_OK, "got %08lx\n", hr );
195 count = 0xdeadbeef;
196 hr = IEnumSpObjectTokens_GetCount( enum_tokens, &count );
197 ok( hr == S_OK, "got %08lx\n", hr );
198 ok( count == 5, "got %lu\n", count );
200 IEnumSpObjectTokens_Release( enum_tokens );
201 ISpObjectTokenCategory_Release( cat );
204 static void test_token_enum(void)
206 ISpObjectTokenEnumBuilder *token_enum;
207 HRESULT hr;
208 ISpObjectToken *tokens[3];
209 ISpObjectToken *out_tokens[3];
210 WCHAR token_id[MAX_PATH];
211 ULONG count;
212 int i;
214 hr = CoCreateInstance( &CLSID_SpObjectTokenEnum, NULL, CLSCTX_INPROC_SERVER,
215 &IID_ISpObjectTokenEnumBuilder, (void **)&token_enum );
216 ok( hr == S_OK, "got %08lx\n", hr );
218 hr = ISpObjectTokenEnumBuilder_GetCount( token_enum, &count );
219 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
221 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 1, tokens, &count );
222 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
224 hr = ISpObjectTokenEnumBuilder_SetAttribs( token_enum, NULL, NULL );
225 ok( hr == S_OK, "got %08lx\n", hr );
227 count = 0xdeadbeef;
228 hr = ISpObjectTokenEnumBuilder_GetCount( token_enum, &count );
229 ok( hr == S_OK, "got %08lx\n", hr );
230 ok( count == 0, "got %lu\n", count );
232 count = 0xdeadbeef;
233 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 1, &out_tokens[0], &count );
234 ok( hr == S_FALSE, "got %08lx\n", hr );
235 ok( count == 0, "got %lu\n", count );
237 for ( i = 0; i < 3; i++ ) {
238 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
239 &IID_ISpObjectToken, (void **)&tokens[i] );
240 ok( hr == S_OK, "got %08lx\n", hr );
242 swprintf( token_id, MAX_PATH, L"%ls\\Tokens\\Voice%d", test_cat, i + 1 );
243 hr = ISpObjectToken_SetId( tokens[i], NULL, token_id, FALSE );
244 ok( hr == S_OK, "got %08lx\n", hr );
247 hr = ISpObjectTokenEnumBuilder_AddTokens( token_enum, 3, tokens );
248 ok( hr == S_OK, "got %08lx\n", hr );
250 out_tokens[0] = (ISpObjectToken *)0xdeadbeef;
251 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 1, &out_tokens[0], NULL );
252 ok( hr == S_OK, "got %08lx\n", hr );
253 ok( out_tokens[0] == tokens[0], "got %p\n", out_tokens[0] );
255 out_tokens[0] = (ISpObjectToken *)0xdeadbeef;
256 hr = ISpObjectTokenEnumBuilder_Item( token_enum, 0, &out_tokens[0] );
257 ok( hr == S_OK, "got %08lx\n", hr );
258 ok( out_tokens[0] == tokens[0], "got %p\n", out_tokens[0] );
260 hr = ISpObjectTokenEnumBuilder_Item( token_enum, 3, &out_tokens[0] );
261 ok( hr == SPERR_NO_MORE_ITEMS, "got %08lx\n", hr );
263 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 3, &out_tokens[1], NULL );
264 ok( hr == E_POINTER, "got %08lx\n", hr );
266 count = 0xdeadbeef;
267 out_tokens[1] = out_tokens[2] = (ISpObjectToken *)0xdeadbeef;
268 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 3, &out_tokens[1], &count );
269 ok( hr == S_FALSE, "got %08lx\n", hr );
270 ok( count == 2, "got %lu\n", count );
271 ok( out_tokens[1] == tokens[1], "got %p\n", out_tokens[1] );
272 ok( out_tokens[2] == tokens[2], "got %p\n", out_tokens[2] );
274 ISpObjectTokenEnumBuilder_Release( token_enum );
276 for ( i = 0; i < 3; i++ ) ISpObjectToken_Release( tokens[i] );
279 static void test_default_token_id(void)
281 ISpObjectTokenCategory *cat;
282 HRESULT hr;
283 LPWSTR token_id = NULL;
284 LONG res;
285 WCHAR regvalue[512];
286 DWORD regvalue_size;
288 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
289 &IID_ISpObjectTokenCategory, (void **)&cat );
290 ok( hr == S_OK, "got %08lx\n", hr );
292 token_id = (LPWSTR)0xdeadbeef;
293 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
294 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
295 ok( token_id == (LPWSTR)0xdeadbeef, "got %p\n", token_id );
297 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL );
298 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
300 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_AUDIOOUT, FALSE );
301 ok( hr == S_OK, "got %08lx\n", hr );
303 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL );
304 ok( hr == E_POINTER, "got %08lx\n", hr );
306 token_id = (LPWSTR)0xdeadbeef;
307 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
309 /* AudioOutput under windows server returns this error */
310 if (hr == SPERR_NOT_FOUND) {
311 /* also happens if TokenEnums/Tokens is empty or doesn't exist */
312 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
313 return;
316 ok( hr == S_OK, "got %08lx\n", hr );
317 ok( token_id != (LPWSTR)0xdeadbeef && token_id != NULL, "got %p\n", token_id );
319 regvalue_size = sizeof( regvalue );
320 res = RegGetValueW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Speech\\AudioOutput",
321 L"DefaultDefaultTokenId", RRF_RT_REG_SZ, NULL,
322 (LPVOID)&regvalue, &regvalue_size);
323 if (res == ERROR_FILE_NOT_FOUND) {
324 skip( "DefaultDefaultTokenId not found for AudioOutput category (%s)\n",
325 wine_dbgstr_w(token_id) );
326 } else {
327 ok( res == ERROR_SUCCESS, "got %08lx\n", res );
328 ok( !wcscmp(regvalue, token_id),
329 "GetDefaultTokenId (%s) should be equal to the DefaultDefaultTokenId key (%s)\n",
330 wine_dbgstr_w(token_id), wine_dbgstr_w(regvalue) );
333 CoTaskMemFree( token_id );
334 ISpObjectTokenCategory_Release( cat );
337 static void tests_token_voices(void)
339 ISpObjectTokenCategory *cat;
340 HRESULT hr;
341 IEnumSpObjectTokens *tokens;
342 ISpObjectToken *item;
343 ULONG fetched = 0;
344 ULONG count;
346 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
347 &IID_ISpObjectTokenCategory, (void **)&cat );
348 ok( hr == S_OK, "got %08lx\n", hr );
350 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_VOICES, FALSE );
351 ok( hr == S_OK, "got %08lx\n", hr );
353 hr = ISpObjectTokenCategory_EnumTokens(cat, NULL, NULL, &tokens);
354 ok( hr == S_OK, "got %08lx\n", hr );
356 hr = IEnumSpObjectTokens_GetCount( tokens, &count );
357 ok( hr == S_OK, "got %08lx\n", hr );
358 ok( count != 0, "got %lu\n", count );
359 ISpObjectTokenCategory_Release( cat );
361 hr = IEnumSpObjectTokens_Item(tokens, 0, &item);
362 ok( hr == S_OK, "got %08lx\n", hr );
363 ISpObjectToken_Release(item);
365 hr = IEnumSpObjectTokens_Next(tokens, 1, &item, &fetched);
366 ok( hr == S_OK, "got %08lx\n", hr );
367 ISpObjectToken_Release(item);
369 IEnumSpObjectTokens_Release(tokens);
373 #define TESTCLASS_CLSID L"{67DD26B6-50BA-3297-253E-619346F177F8}"
374 static const GUID CLSID_TestClass = {0x67DD26B6,0x50BA,0x3297,{0x25,0x3E,0x61,0x93,0x46,0xF1,0x77,0xF8}};
376 static ISpObjectToken *test_class_token;
378 static HRESULT WINAPI test_class_QueryInterface(ISpObjectWithToken *iface, REFIID riid, void **ppv)
380 if (IsEqualGUID( riid, &IID_IUnknown ) || IsEqualGUID( riid, &IID_ISpObjectWithToken ))
382 *ppv = iface;
383 return S_OK;
386 *ppv = NULL;
387 return E_NOINTERFACE;
390 static ULONG WINAPI test_class_AddRef(ISpObjectWithToken *iface)
392 return 2;
395 static ULONG WINAPI test_class_Release(ISpObjectWithToken *iface)
397 return 1;
400 static HRESULT WINAPI test_class_SetObjectToken(ISpObjectWithToken *iface, ISpObjectToken *token)
402 ok( token != NULL, "token == NULL\n" );
403 test_class_token = token;
404 ISpObjectToken_AddRef(test_class_token);
405 return S_OK;
408 static HRESULT WINAPI test_class_GetObjectToken(ISpObjectWithToken *iface, ISpObjectToken **token)
410 ok( 0, "unexpected call\n" );
411 return E_NOTIMPL;
414 static const ISpObjectWithTokenVtbl test_class_vtbl = {
415 test_class_QueryInterface,
416 test_class_AddRef,
417 test_class_Release,
418 test_class_SetObjectToken,
419 test_class_GetObjectToken
422 static ISpObjectWithToken test_class = { &test_class_vtbl };
424 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
426 if (IsEqualGUID( &IID_IUnknown, riid ) || IsEqualGUID( &IID_IClassFactory, riid ))
428 *ppv = iface;
429 return S_OK;
432 *ppv = NULL;
433 return E_NOINTERFACE;
436 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
438 return 2;
441 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
443 return 1;
446 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface,
447 IUnknown *pUnkOuter, REFIID riid, void **ppv)
449 ok( pUnkOuter == NULL, "pUnkOuter != NULL\n" );
450 ok( IsEqualGUID(riid, &IID_IUnknown), "riid = %s\n", wine_dbgstr_guid(riid) );
452 *ppv = &test_class;
453 return S_OK;
456 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
458 ok( 0, "unexpected call\n" );
459 return E_NOTIMPL;
462 static const IClassFactoryVtbl ClassFactoryVtbl = {
463 ClassFactory_QueryInterface,
464 ClassFactory_AddRef,
465 ClassFactory_Release,
466 ClassFactory_CreateInstance,
467 ClassFactory_LockServer
470 static IClassFactory test_class_cf = { &ClassFactoryVtbl };
472 static void test_object_token(void)
474 static const WCHAR test_token_id[] = L"HKEY_CURRENT_USER\\Software\\Winetest\\sapi\\TestToken";
476 ISpObjectToken *token;
477 ISpDataKey *sub_key;
478 HRESULT hr;
479 LPWSTR tempW, token_id;
480 ISpObjectTokenCategory *cat;
481 DWORD regid;
482 IUnknown *obj;
484 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
485 &IID_ISpObjectToken, (void **)&token );
486 ok( hr == S_OK, "got %08lx\n", hr );
488 hr = ISpObjectToken_GetId( token, NULL );
489 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
491 tempW = (LPWSTR)0xdeadbeef;
492 hr = ISpObjectToken_GetId( token, &tempW );
493 ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
494 ok( tempW == (LPWSTR)0xdeadbeef, "got %s\n", wine_dbgstr_w(tempW) );
496 hr = ISpObjectToken_GetCategory( token, NULL );
497 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
499 cat = (LPVOID)0xdeadbeef;
500 hr = ISpObjectToken_GetCategory( token, &cat );
501 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08lx\n", hr );
502 ok( cat == (LPVOID)0xdeadbeef, "got %p\n", cat );
504 hr = ISpObjectToken_SetId( token, NULL, NULL, FALSE );
505 ok( hr == E_POINTER, "got %08lx\n", hr );
506 hr = ISpObjectToken_SetId( token, L"bogus", NULL, FALSE );
507 ok( hr == E_POINTER, "got %08lx\n", hr );
509 hr = ISpObjectToken_SetId( token, NULL, L"bogus", FALSE );
510 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
511 hr = ISpObjectToken_SetId( token, NULL, L"HKEY_LOCAL_MACHINE\\SOFTWARE\\winetest bogus", FALSE );
512 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
514 /* SetId succeeds even if the key is invalid, but exists */
515 hr = ISpObjectToken_SetId( token, NULL, L"HKEY_LOCAL_MACHINE\\SOFTWARE", FALSE );
516 ok( hr == S_OK, "got %08lx\n", hr );
518 hr = ISpObjectToken_SetId( token, NULL, NULL, FALSE );
519 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
520 hr = ISpObjectToken_SetId( token, NULL, L"bogus", FALSE );
521 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08lx\n", hr );
523 hr = ISpObjectToken_GetId( token, NULL );
524 ok( hr == E_POINTER, "got %08lx\n", hr );
526 hr = ISpObjectToken_GetCategory( token, NULL );
527 todo_wine ok( hr == E_POINTER, "got %08lx\n", hr );
529 tempW = NULL;
530 hr = ISpObjectToken_GetId( token, &tempW );
531 ok( hr == S_OK, "got %08lx\n", hr );
532 ok( tempW != NULL, "got %p\n", tempW );
533 if (tempW) {
534 ok( !wcscmp(tempW, L"HKEY_LOCAL_MACHINE\\SOFTWARE"), "got %s\n",
535 wine_dbgstr_w(tempW) );
536 CoTaskMemFree( tempW );
539 hr = ISpObjectToken_OpenKey(token, L"Non-exist", &sub_key);
540 ok( hr == SPERR_NOT_FOUND, "got %08lx\n", hr );
542 hr = ISpObjectToken_OpenKey(token, L"Classes", &sub_key);
543 ok( hr == S_OK, "got %08lx\n", hr );
544 ISpDataKey_Release(sub_key);
546 cat = (LPVOID)0xdeadbeef;
547 hr = ISpObjectToken_GetCategory( token, &cat );
548 todo_wine ok( hr == SPERR_INVALID_REGISTRY_KEY, "got %08lx\n", hr );
549 ok( cat == (LPVOID)0xdeadbeef, "got %p\n", cat );
551 /* get the default token id for SPCAT_AUDIOOUT */
552 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
553 &IID_ISpObjectTokenCategory, (void **)&cat );
554 ok( hr == S_OK, "got %08lx\n", hr );
555 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_AUDIOOUT, FALSE );
556 ok( hr == S_OK, "got %08lx\n", hr );
557 token_id = (LPWSTR)0xdeadbeef;
558 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
559 if (hr == SPERR_NOT_FOUND) {
560 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
561 return;
563 ok( hr == S_OK, "got %08lx\n", hr );
564 ok( token_id != (LPWSTR)0xdeadbeef && token_id != NULL, "got %p\n", token_id );
565 ISpObjectTokenCategory_Release( cat );
567 /* recreate token in order to SetId again */
568 ISpObjectToken_Release( token );
569 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
570 &IID_ISpObjectToken, (void **)&token );
571 ok( hr == S_OK, "got %08lx\n", hr );
573 /* NULL appears to auto-detect the category */
574 hr = ISpObjectToken_SetId( token, NULL, token_id, FALSE );
575 ok( hr == S_OK, "got %08lx\n", hr );
577 tempW = NULL;
578 hr = ISpObjectToken_GetId( token, &tempW );
579 ok( hr == S_OK, "got %08lx\n", hr );
580 ok( tempW != NULL, "got %p\n", tempW );
581 if (tempW) {
582 ok( !wcsncmp(tempW, token_id, wcslen(token_id)),
583 "got %s (expected %s)\n", wine_dbgstr_w(tempW), wine_dbgstr_w(token_id) );
584 CoTaskMemFree( tempW );
587 cat = (LPVOID)0xdeadbeef;
588 hr = ISpObjectToken_GetCategory( token, &cat );
589 todo_wine ok( hr == S_OK, "got %08lx\n", hr );
590 todo_wine ok( cat != (LPVOID)0xdeadbeef, "got %p\n", cat );
591 if (cat != (LPVOID)0xdeadbeef) {
592 tempW = NULL;
593 hr = ISpObjectTokenCategory_GetId( cat, &tempW );
594 todo_wine ok( hr == S_OK, "got %08lx\n", hr );
595 todo_wine ok( tempW != NULL, "got %p\n", tempW );
596 if (tempW) {
597 ok( !wcscmp(tempW, SPCAT_AUDIOOUT), "got %s\n", wine_dbgstr_w(tempW) );
598 CoTaskMemFree( tempW );
601 /* not freed by ISpObjectToken_Release */
602 ISpObjectTokenCategory_Release( cat );
605 hr = CoRegisterClassObject( &CLSID_TestClass, (IUnknown *)&test_class_cf,
606 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &regid );
607 ok( hr == S_OK, "got %08lx\n", hr );
609 ISpObjectToken_Release( token );
610 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
611 &IID_ISpObjectToken, (void **)&token );
612 ok( hr == S_OK, "got %08lx\n", hr );
614 hr = ISpObjectToken_SetId( token, NULL, test_token_id, TRUE );
615 ok( hr == S_OK, "got %08lx\n", hr );
617 hr = ISpObjectToken_CreateKey( token, L"Attributes", &sub_key );
618 ok( hr == S_OK, "got %08lx\n", hr );
619 ISpDataKey_Release( sub_key );
621 hr = ISpObjectToken_SetStringValue( token, L"CLSID", TESTCLASS_CLSID );
622 ok( hr == S_OK, "got %08lx\n", hr );
624 tempW = NULL;
625 hr = ISpObjectToken_GetStringValue( token, L"CLSID", &tempW );
627 ok( hr == S_OK, "got %08lx\n", hr );
628 if ( tempW ) {
629 ok( !wcsncmp( tempW, TESTCLASS_CLSID, wcslen(TESTCLASS_CLSID) ),
630 "got %s (expected %s)\n", wine_dbgstr_w(tempW), wine_dbgstr_w(TESTCLASS_CLSID) );
631 CoTaskMemFree( tempW );
634 test_class_token = NULL;
635 hr = ISpObjectToken_CreateInstance( token, NULL, CLSCTX_INPROC_SERVER, &IID_IUnknown, (void **)&obj );
636 if ( hr == E_ACCESSDENIED ) {
637 win_skip( "ISpObjectToken_CreateInstance returned E_ACCESSDENIED\n" );
638 return;
640 ok( hr == S_OK, "got %08lx\n", hr );
641 ok( test_class_token != NULL, "test_class_token not set\n" );
643 tempW = NULL;
644 hr = ISpObjectToken_GetId( test_class_token, &tempW );
645 ok( tempW != NULL, "got %p\n", tempW );
646 if (tempW) {
647 ok( !wcsncmp(tempW, test_token_id, wcslen(test_token_id)),
648 "got %s (expected %s)\n", wine_dbgstr_w(tempW), wine_dbgstr_w(test_token_id) );
649 CoTaskMemFree( tempW );
652 ISpObjectToken_Release( test_class_token );
653 IUnknown_Release( obj );
654 ISpObjectToken_Release( token );
657 START_TEST(token)
659 CoInitialize( NULL );
660 RegDeleteTreeA( HKEY_CURRENT_USER, "Software\\Winetest\\sapi" );
661 test_data_key();
662 setup_test_voice_tokens();
663 test_token_category();
664 test_token_enum();
665 test_default_token_id();
666 test_object_token();
667 tests_token_voices();
668 CoUninitialize();