mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / sapi / tests / token.c
blob47196d42dc7595cbae34c365aefe138da792b622
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 HRESULT hr;
33 HKEY key;
34 LONG res;
36 hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_INPROC_SERVER,
37 &IID_ISpRegDataKey, (void **)&data_key );
38 ok( hr == S_OK, "got %08x\n", hr );
40 res = RegCreateKeyExA( HKEY_CURRENT_USER, "Software\\Winetest\\sapi", 0, NULL, 0, KEY_ALL_ACCESS,
41 NULL, &key, NULL );
42 ok( res == ERROR_SUCCESS, "got %d\n", res );
44 hr = ISpRegDataKey_SetKey( data_key, key, FALSE );
45 ok( hr == S_OK, "got %08x\n", hr );
46 hr = ISpRegDataKey_SetKey( data_key, key, FALSE );
47 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08x\n", hr );
49 ISpRegDataKey_Release( data_key );
52 static void test_token_category(void)
54 ISpObjectTokenCategory *cat;
55 IEnumSpObjectTokens *enum_tokens;
56 HRESULT hr;
57 ULONG count;
59 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
60 &IID_ISpObjectTokenCategory, (void **)&cat );
61 ok( hr == S_OK, "got %08x\n", hr );
63 hr = ISpObjectTokenCategory_EnumTokens( cat, NULL, NULL, &enum_tokens );
64 ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
66 hr = ISpObjectTokenCategory_SetId( cat, L"bogus", FALSE );
67 ok( hr == SPERR_INVALID_REGISTRY_KEY, "got %08x\n", hr );
69 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_VOICES, FALSE );
70 ok( hr == S_OK, "got %08x\n", hr );
72 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_VOICES, FALSE );
73 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08x\n", hr );
75 hr = ISpObjectTokenCategory_EnumTokens( cat, NULL, NULL, &enum_tokens );
76 ok( hr == S_OK, "got %08x\n", hr );
78 hr = IEnumSpObjectTokens_GetCount( enum_tokens, &count );
79 ok( hr == S_OK, "got %08x\n", hr );
81 IEnumSpObjectTokens_Release( enum_tokens );
82 ISpObjectTokenCategory_Release( cat );
85 static void test_token_enum(void)
87 ISpObjectTokenEnumBuilder *token_enum;
88 HRESULT hr;
89 ISpObjectToken *token;
90 ULONG count;
92 hr = CoCreateInstance( &CLSID_SpObjectTokenEnum, NULL, CLSCTX_INPROC_SERVER,
93 &IID_ISpObjectTokenEnumBuilder, (void **)&token_enum );
94 ok( hr == S_OK, "got %08x\n", hr );
96 hr = ISpObjectTokenEnumBuilder_GetCount( token_enum, &count );
97 ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
99 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 1, &token, &count );
100 ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
102 hr = ISpObjectTokenEnumBuilder_SetAttribs( token_enum, NULL, NULL );
103 ok( hr == S_OK, "got %08x\n", hr );
105 count = 0xdeadbeef;
106 hr = ISpObjectTokenEnumBuilder_GetCount( token_enum, &count );
107 ok( hr == S_OK, "got %08x\n", hr );
108 ok( count == 0, "got %u\n", count );
110 count = 0xdeadbeef;
111 hr = ISpObjectTokenEnumBuilder_Next( token_enum, 1, &token, &count );
112 ok( hr == S_FALSE, "got %08x\n", hr );
113 ok( count == 0, "got %u\n", count );
115 ISpObjectTokenEnumBuilder_Release( token_enum );
118 static void test_default_token_id(void)
120 ISpObjectTokenCategory *cat;
121 HRESULT hr;
122 LPWSTR token_id = NULL;
123 LONG res;
124 WCHAR regvalue[512];
125 DWORD regvalue_size;
127 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
128 &IID_ISpObjectTokenCategory, (void **)&cat );
129 ok( hr == S_OK, "got %08x\n", hr );
131 token_id = (LPWSTR)0xdeadbeef;
132 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
133 ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
134 ok( token_id == (LPWSTR)0xdeadbeef, "got %p\n", token_id );
136 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL );
137 ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
139 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_AUDIOOUT, FALSE );
140 ok( hr == S_OK, "got %08x\n", hr );
142 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, NULL );
143 ok( hr == E_POINTER, "got %08x\n", hr );
145 token_id = (LPWSTR)0xdeadbeef;
146 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
148 /* AudioOutput under windows server returns this error */
149 if (hr == SPERR_NOT_FOUND) {
150 /* also happens if TokenEnums/Tokens is empty or doesn't exist */
151 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
152 return;
155 ok( hr == S_OK, "got %08x\n", hr );
156 ok( token_id != (LPWSTR)0xdeadbeef && token_id != NULL, "got %p\n", token_id );
158 regvalue_size = sizeof( regvalue );
159 res = RegGetValueW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Speech\\AudioOutput",
160 L"DefaultDefaultTokenId", RRF_RT_REG_SZ, NULL,
161 (LPVOID)&regvalue, &regvalue_size);
162 if (res == ERROR_FILE_NOT_FOUND) {
163 skip( "DefaultDefaultTokenId not found for AudioOutput category (%s)\n",
164 wine_dbgstr_w(token_id) );
165 } else {
166 ok( res == ERROR_SUCCESS, "got %08x\n", res );
167 ok( !wcscmp(regvalue, token_id),
168 "GetDefaultTokenId (%s) should be equal to the DefaultDefaultTokenId key (%s)\n",
169 wine_dbgstr_w(token_id), wine_dbgstr_w(regvalue) );
172 CoTaskMemFree( token_id );
173 ISpObjectTokenCategory_Release( cat );
176 static void test_object_token(void)
178 ISpObjectToken *token;
179 HRESULT hr;
180 LPWSTR tempW, token_id;
181 ISpObjectTokenCategory *cat;
183 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
184 &IID_ISpObjectToken, (void **)&token );
185 ok( hr == S_OK, "got %08x\n", hr );
187 hr = ISpObjectToken_GetId( token, NULL );
188 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
190 tempW = (LPWSTR)0xdeadbeef;
191 hr = ISpObjectToken_GetId( token, &tempW );
192 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
193 ok( tempW == (LPWSTR)0xdeadbeef, "got %s\n", wine_dbgstr_w(tempW) );
195 hr = ISpObjectToken_GetCategory( token, NULL );
196 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
198 cat = (LPVOID)0xdeadbeef;
199 hr = ISpObjectToken_GetCategory( token, &cat );
200 todo_wine ok( hr == SPERR_UNINITIALIZED, "got %08x\n", hr );
201 ok( cat == (LPVOID)0xdeadbeef, "got %p\n", cat );
203 hr = ISpObjectToken_SetId( token, NULL, NULL, FALSE );
204 ok( hr == E_POINTER, "got %08x\n", hr );
205 hr = ISpObjectToken_SetId( token, L"bogus", NULL, FALSE );
206 ok( hr == E_POINTER, "got %08x\n", hr );
208 hr = ISpObjectToken_SetId( token, NULL, L"bogus", FALSE );
209 ok( hr == SPERR_NOT_FOUND, "got %08x\n", hr );
210 hr = ISpObjectToken_SetId( token, NULL, L"HKEY_LOCAL_MACHINE\\SOFTWARE\\winetest bogus", FALSE );
211 ok( hr == SPERR_NOT_FOUND, "got %08x\n", hr );
213 /* SetId succeeds even if the key is invalid, but exists */
214 hr = ISpObjectToken_SetId( token, NULL, L"HKEY_LOCAL_MACHINE\\SOFTWARE", FALSE );
215 ok( hr == S_OK, "got %08x\n", hr );
217 hr = ISpObjectToken_SetId( token, NULL, NULL, FALSE );
218 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08x\n", hr );
219 hr = ISpObjectToken_SetId( token, NULL, L"bogus", FALSE );
220 ok( hr == SPERR_ALREADY_INITIALIZED, "got %08x\n", hr );
222 hr = ISpObjectToken_GetId( token, NULL );
223 todo_wine ok( hr == E_POINTER, "got %08x\n", hr );
225 hr = ISpObjectToken_GetCategory( token, NULL );
226 todo_wine ok( hr == E_POINTER, "got %08x\n", hr );
228 tempW = NULL;
229 hr = ISpObjectToken_GetId( token, &tempW );
230 todo_wine ok( hr == S_OK, "got %08x\n", hr );
231 todo_wine ok( tempW != NULL, "got %p\n", tempW );
232 if (tempW) {
233 ok( !wcscmp(tempW, L"HKEY_LOCAL_MACHINE\\SOFTWARE"), "got %s\n",
234 wine_dbgstr_w(tempW) );
235 CoTaskMemFree( tempW );
238 cat = (LPVOID)0xdeadbeef;
239 hr = ISpObjectToken_GetCategory( token, &cat );
240 todo_wine ok( hr == SPERR_INVALID_REGISTRY_KEY, "got %08x\n", hr );
241 ok( cat == (LPVOID)0xdeadbeef, "got %p\n", cat );
243 /* get the default token id for SPCAT_AUDIOOUT */
244 hr = CoCreateInstance( &CLSID_SpObjectTokenCategory, NULL, CLSCTX_INPROC_SERVER,
245 &IID_ISpObjectTokenCategory, (void **)&cat );
246 ok( hr == S_OK, "got %08x\n", hr );
247 hr = ISpObjectTokenCategory_SetId( cat, SPCAT_AUDIOOUT, FALSE );
248 ok( hr == S_OK, "got %08x\n", hr );
249 token_id = (LPWSTR)0xdeadbeef;
250 hr = ISpObjectTokenCategory_GetDefaultTokenId( cat, &token_id );
251 if (hr == SPERR_NOT_FOUND) {
252 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
253 return;
255 ok( hr == S_OK, "got %08x\n", hr );
256 ok( token_id != (LPWSTR)0xdeadbeef && token_id != NULL, "got %p\n", token_id );
257 ISpObjectTokenCategory_Release( cat );
259 /* recreate token in order to SetId again */
260 ISpObjectToken_Release( token );
261 hr = CoCreateInstance( &CLSID_SpObjectToken, NULL, CLSCTX_INPROC_SERVER,
262 &IID_ISpObjectToken, (void **)&token );
263 ok( hr == S_OK, "got %08x\n", hr );
265 /* NULL appears to auto-detect the category */
266 hr = ISpObjectToken_SetId( token, NULL, token_id, FALSE );
267 ok( hr == S_OK, "got %08x\n", hr );
269 tempW = NULL;
270 hr = ISpObjectToken_GetId( token, &tempW );
271 todo_wine ok( hr == S_OK, "got %08x\n", hr );
272 todo_wine ok( tempW != NULL, "got %p\n", tempW );
273 if (tempW) {
274 ok( !wcsncmp(tempW, token_id, wcslen(token_id)),
275 "got %s (expected %s)\n", wine_dbgstr_w(tempW), wine_dbgstr_w(token_id) );
276 CoTaskMemFree( tempW );
279 cat = (LPVOID)0xdeadbeef;
280 hr = ISpObjectToken_GetCategory( token, &cat );
281 todo_wine ok( hr == S_OK, "got %08x\n", hr );
282 todo_wine ok( cat != (LPVOID)0xdeadbeef, "got %p\n", cat );
283 if (cat != (LPVOID)0xdeadbeef) {
284 tempW = NULL;
285 hr = ISpObjectTokenCategory_GetId( cat, &tempW );
286 todo_wine ok( hr == S_OK, "got %08x\n", hr );
287 todo_wine ok( tempW != NULL, "got %p\n", tempW );
288 if (tempW) {
289 ok( !wcscmp(tempW, SPCAT_AUDIOOUT), "got %s\n", wine_dbgstr_w(tempW) );
290 CoTaskMemFree( tempW );
293 /* not freed by ISpObjectToken_Release */
294 ISpObjectTokenCategory_Release( cat );
297 ISpObjectToken_Release( token );
300 START_TEST(token)
302 CoInitialize( NULL );
303 test_data_key();
304 test_token_category();
305 test_token_enum();
306 test_default_token_id();
307 test_object_token();
308 CoUninitialize();