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
27 #include "wine/test.h"
29 static void test_data_key(void)
31 ISpRegDataKey
*data_key
;
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
,
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
;
57 WCHAR bogus
[] = {'b','o','g','u','s',0};
60 hr
= CoCreateInstance( &CLSID_SpObjectTokenCategory
, NULL
, CLSCTX_INPROC_SERVER
,
61 &IID_ISpObjectTokenCategory
, (void **)&cat
);
62 ok( hr
== S_OK
, "got %08x\n", hr
);
64 hr
= ISpObjectTokenCategory_EnumTokens( cat
, NULL
, NULL
, &enum_tokens
);
65 ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
67 hr
= ISpObjectTokenCategory_SetId( cat
, bogus
, FALSE
);
68 ok( hr
== SPERR_INVALID_REGISTRY_KEY
, "got %08x\n", hr
);
70 hr
= ISpObjectTokenCategory_SetId( cat
, SPCAT_VOICES
, FALSE
);
71 ok( hr
== S_OK
, "got %08x\n", hr
);
73 hr
= ISpObjectTokenCategory_SetId( cat
, SPCAT_VOICES
, FALSE
);
74 ok( hr
== SPERR_ALREADY_INITIALIZED
, "got %08x\n", hr
);
76 hr
= ISpObjectTokenCategory_EnumTokens( cat
, NULL
, NULL
, &enum_tokens
);
77 ok( hr
== S_OK
, "got %08x\n", hr
);
79 hr
= IEnumSpObjectTokens_GetCount( enum_tokens
, &count
);
80 ok( hr
== S_OK
, "got %08x\n", hr
);
82 IEnumSpObjectTokens_Release( enum_tokens
);
83 ISpObjectTokenCategory_Release( cat
);
86 static void test_token_enum(void)
88 ISpObjectTokenEnumBuilder
*token_enum
;
90 ISpObjectToken
*token
;
93 hr
= CoCreateInstance( &CLSID_SpObjectTokenEnum
, NULL
, CLSCTX_INPROC_SERVER
,
94 &IID_ISpObjectTokenEnumBuilder
, (void **)&token_enum
);
95 ok( hr
== S_OK
, "got %08x\n", hr
);
97 hr
= ISpObjectTokenEnumBuilder_GetCount( token_enum
, &count
);
98 ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
100 hr
= ISpObjectTokenEnumBuilder_Next( token_enum
, 1, &token
, &count
);
101 ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
103 hr
= ISpObjectTokenEnumBuilder_SetAttribs( token_enum
, NULL
, NULL
);
104 ok( hr
== S_OK
, "got %08x\n", hr
);
107 hr
= ISpObjectTokenEnumBuilder_GetCount( token_enum
, &count
);
108 ok( hr
== S_OK
, "got %08x\n", hr
);
109 ok( count
== 0, "got %u\n", count
);
112 hr
= ISpObjectTokenEnumBuilder_Next( token_enum
, 1, &token
, &count
);
113 ok( hr
== S_FALSE
, "got %08x\n", hr
);
114 ok( count
== 0, "got %u\n", count
);
116 ISpObjectTokenEnumBuilder_Release( token_enum
);
119 static void test_default_token_id(void)
121 ISpObjectTokenCategory
*cat
;
123 LPWSTR token_id
= NULL
;
128 hr
= CoCreateInstance( &CLSID_SpObjectTokenCategory
, NULL
, CLSCTX_INPROC_SERVER
,
129 &IID_ISpObjectTokenCategory
, (void **)&cat
);
130 ok( hr
== S_OK
, "got %08x\n", hr
);
132 token_id
= (LPWSTR
)0xdeadbeef;
133 hr
= ISpObjectTokenCategory_GetDefaultTokenId( cat
, &token_id
);
134 ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
135 ok( token_id
== (LPWSTR
)0xdeadbeef, "got %p\n", token_id
);
137 hr
= ISpObjectTokenCategory_GetDefaultTokenId( cat
, NULL
);
138 ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
140 hr
= ISpObjectTokenCategory_SetId( cat
, SPCAT_AUDIOOUT
, FALSE
);
141 ok( hr
== S_OK
, "got %08x\n", hr
);
143 hr
= ISpObjectTokenCategory_GetDefaultTokenId( cat
, NULL
);
144 ok( hr
== E_POINTER
, "got %08x\n", hr
);
146 token_id
= (LPWSTR
)0xdeadbeef;
147 hr
= ISpObjectTokenCategory_GetDefaultTokenId( cat
, &token_id
);
149 /* AudioOutput under windows server returns this error */
150 if (hr
== SPERR_NOT_FOUND
) {
151 /* also happens if TokenEnums/Tokens is empty or doesn't exist */
152 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
156 ok( hr
== S_OK
, "got %08x\n", hr
);
157 ok( token_id
!= (LPWSTR
)0xdeadbeef && token_id
!= NULL
, "got %p\n", token_id
);
159 regvalue_size
= sizeof( regvalue
);
160 res
= RegGetValueW( HKEY_LOCAL_MACHINE
, L
"SOFTWARE\\Microsoft\\Speech\\AudioOutput",
161 L
"DefaultDefaultTokenId", RRF_RT_REG_SZ
, NULL
,
162 (LPVOID
)®value
, ®value_size
);
163 if (res
== ERROR_FILE_NOT_FOUND
) {
164 skip( "DefaultDefaultTokenId not found for AudioOutput category (%s)\n",
165 wine_dbgstr_w(token_id
) );
167 ok( res
== ERROR_SUCCESS
, "got %08x\n", res
);
168 ok( !wcscmp(regvalue
, token_id
),
169 "GetDefaultTokenId (%s) should be equal to the DefaultDefaultTokenId key (%s)\n",
170 wine_dbgstr_w(token_id
), wine_dbgstr_w(regvalue
) );
173 CoTaskMemFree( token_id
);
174 ISpObjectTokenCategory_Release( cat
);
177 static void test_object_token(void)
179 ISpObjectToken
*token
;
181 LPWSTR tempW
, token_id
;
182 ISpObjectTokenCategory
*cat
;
184 hr
= CoCreateInstance( &CLSID_SpObjectToken
, NULL
, CLSCTX_INPROC_SERVER
,
185 &IID_ISpObjectToken
, (void **)&token
);
186 ok( hr
== S_OK
, "got %08x\n", hr
);
188 hr
= ISpObjectToken_GetId( token
, NULL
);
189 todo_wine
ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
191 tempW
= (LPWSTR
)0xdeadbeef;
192 hr
= ISpObjectToken_GetId( token
, &tempW
);
193 todo_wine
ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
194 ok( tempW
== (LPWSTR
)0xdeadbeef, "got %s\n", wine_dbgstr_w(tempW
) );
196 hr
= ISpObjectToken_GetCategory( token
, NULL
);
197 todo_wine
ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
199 cat
= (LPVOID
)0xdeadbeef;
200 hr
= ISpObjectToken_GetCategory( token
, &cat
);
201 todo_wine
ok( hr
== SPERR_UNINITIALIZED
, "got %08x\n", hr
);
202 ok( cat
== (LPVOID
)0xdeadbeef, "got %p\n", cat
);
204 hr
= ISpObjectToken_SetId( token
, NULL
, NULL
, FALSE
);
205 todo_wine
ok( hr
== E_POINTER
, "got %08x\n", hr
);
206 hr
= ISpObjectToken_SetId( token
, L
"bogus", NULL
, FALSE
);
207 todo_wine
ok( hr
== E_POINTER
, "got %08x\n", hr
);
209 hr
= ISpObjectToken_SetId( token
, NULL
, L
"bogus", FALSE
);
210 todo_wine
ok( hr
== SPERR_NOT_FOUND
, "got %08x\n", hr
);
211 hr
= ISpObjectToken_SetId( token
, NULL
, L
"HKEY_LOCAL_MACHINE\\SOFTWARE\\winetest bogus", FALSE
);
212 todo_wine
ok( hr
== SPERR_NOT_FOUND
, "got %08x\n", hr
);
214 /* SetId succeeds even if the key is invalid, but exists */
215 hr
= ISpObjectToken_SetId( token
, NULL
, L
"HKEY_LOCAL_MACHINE\\SOFTWARE", FALSE
);
216 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
218 hr
= ISpObjectToken_SetId( token
, NULL
, NULL
, FALSE
);
219 todo_wine
ok( hr
== SPERR_ALREADY_INITIALIZED
, "got %08x\n", hr
);
220 hr
= ISpObjectToken_SetId( token
, NULL
, L
"bogus", FALSE
);
221 todo_wine
ok( hr
== SPERR_ALREADY_INITIALIZED
, "got %08x\n", hr
);
223 hr
= ISpObjectToken_GetId( token
, NULL
);
224 todo_wine
ok( hr
== E_POINTER
, "got %08x\n", hr
);
226 hr
= ISpObjectToken_GetCategory( token
, NULL
);
227 todo_wine
ok( hr
== E_POINTER
, "got %08x\n", hr
);
230 hr
= ISpObjectToken_GetId( token
, &tempW
);
231 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
232 todo_wine
ok( tempW
!= NULL
, "got %p\n", tempW
);
234 ok( !wcscmp(tempW
, L
"HKEY_LOCAL_MACHINE\\SOFTWARE"), "got %s\n",
235 wine_dbgstr_w(tempW
) );
236 CoTaskMemFree( tempW
);
239 cat
= (LPVOID
)0xdeadbeef;
240 hr
= ISpObjectToken_GetCategory( token
, &cat
);
241 todo_wine
ok( hr
== SPERR_INVALID_REGISTRY_KEY
, "got %08x\n", hr
);
242 ok( cat
== (LPVOID
)0xdeadbeef, "got %p\n", cat
);
244 /* get the default token id for SPCAT_AUDIOOUT */
245 hr
= CoCreateInstance( &CLSID_SpObjectTokenCategory
, NULL
, CLSCTX_INPROC_SERVER
,
246 &IID_ISpObjectTokenCategory
, (void **)&cat
);
247 ok( hr
== S_OK
, "got %08x\n", hr
);
248 hr
= ISpObjectTokenCategory_SetId( cat
, SPCAT_AUDIOOUT
, FALSE
);
249 ok( hr
== S_OK
, "got %08x\n", hr
);
250 token_id
= (LPWSTR
)0xdeadbeef;
251 hr
= ISpObjectTokenCategory_GetDefaultTokenId( cat
, &token_id
);
252 if (hr
== SPERR_NOT_FOUND
) {
253 skip( "AudioOutput category not found for GetDefaultTokenId\n" );
256 ok( hr
== S_OK
, "got %08x\n", hr
);
257 ok( token_id
!= (LPWSTR
)0xdeadbeef && token_id
!= NULL
, "got %p\n", token_id
);
258 ISpObjectTokenCategory_Release( cat
);
260 /* recreate token in order to SetId again */
261 ISpObjectToken_Release( token
);
262 hr
= CoCreateInstance( &CLSID_SpObjectToken
, NULL
, CLSCTX_INPROC_SERVER
,
263 &IID_ISpObjectToken
, (void **)&token
);
264 ok( hr
== S_OK
, "got %08x\n", hr
);
266 /* NULL appears to auto-detect the category */
267 hr
= ISpObjectToken_SetId( token
, NULL
, token_id
, FALSE
);
268 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
271 hr
= ISpObjectToken_GetId( token
, &tempW
);
272 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
273 todo_wine
ok( tempW
!= NULL
, "got %p\n", tempW
);
275 ok( !wcsncmp(tempW
, token_id
, wcslen(token_id
)),
276 "got %s (expected %s)\n", wine_dbgstr_w(tempW
), wine_dbgstr_w(token_id
) );
277 CoTaskMemFree( tempW
);
280 cat
= (LPVOID
)0xdeadbeef;
281 hr
= ISpObjectToken_GetCategory( token
, &cat
);
282 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
283 todo_wine
ok( cat
!= (LPVOID
)0xdeadbeef, "got %p\n", cat
);
284 if (cat
!= (LPVOID
)0xdeadbeef) {
286 hr
= ISpObjectTokenCategory_GetId( cat
, &tempW
);
287 todo_wine
ok( hr
== S_OK
, "got %08x\n", hr
);
288 todo_wine
ok( tempW
!= NULL
, "got %p\n", tempW
);
290 ok( !wcscmp(tempW
, SPCAT_AUDIOOUT
), "got %s\n", wine_dbgstr_w(tempW
) );
291 CoTaskMemFree( tempW
);
294 /* not freed by ISpObjectToken_Release */
295 ISpObjectTokenCategory_Release( cat
);
298 ISpObjectToken_Release( token
);
303 CoInitialize( NULL
);
305 test_token_category();
307 test_default_token_id();