windows.media.speech/tests: Allow recognizer state to be idle during active recogniti...
[wine.git] / dlls / windows.media.speech / tests / speech.c
blobfb0fa9e3b4d0565cffa2cc4ec52cf6eff4a5f024
1 /*
2 * Copyright 2021 RĂ©mi Bernon for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 #define COBJMACROS
19 #include <stdarg.h>
21 #include "corerror.h"
22 #include "windef.h"
23 #include "winbase.h"
24 #include "winerror.h"
25 #include "winstring.h"
27 #include "initguid.h"
28 #include "roapi.h"
30 #define WIDL_using_Windows_Foundation
31 #define WIDL_using_Windows_Foundation_Collections
32 #include "windows.foundation.h"
33 #define WIDL_using_Windows_Globalization
34 #include "windows.globalization.h"
35 #define WIDL_using_Windows_Media_SpeechRecognition
36 #include "windows.media.speechrecognition.h"
37 #define WIDL_using_Windows_Media_SpeechSynthesis
38 #include "windows.media.speechsynthesis.h"
40 #include "wine/test.h"
42 #define AsyncStatus_Closed 4
44 #define SPERR_WINRT_INTERNAL_ERROR 0x800455a0
45 #define SPERR_WINRT_INCORRECT_FORMAT 0x80131537
47 #define IHandler_RecognitionResult ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionResultGeneratedEventArgs
48 #define IHandler_RecognitionResultVtbl ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionResultGeneratedEventArgsVtbl
49 #define IID_IHandler_RecognitionResult IID_ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionResultGeneratedEventArgs
50 #define impl_from_IHandler_RecognitionResult impl_from_ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionResultGeneratedEventArgs
51 #define IHandler_RecognitionResult_iface ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionResultGeneratedEventArgs_iface
53 #define IHandler_RecognitionCompleted ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionCompletedEventArgs
54 #define IHandler_RecognitionCompletedVtbl ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionCompletedEventArgsVtbl
55 #define IID_IHandler_RecognitionCompleted IID_ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionCompletedEventArgs
56 #define impl_from_IHandler_RecognitionCompleted impl_from_ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionCompletedEventArgs
57 #define IHandler_RecognitionCompleted_iface ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionCompletedEventArgs_iface
59 #define IAsyncHandler_IInspectable_iface IAsyncOperationCompletedHandler_IInspectable_iface
61 HRESULT (WINAPI *pDllGetActivationFactory)(HSTRING, IActivationFactory **);
62 static BOOL is_win10_1507 = FALSE;
63 static BOOL is_win10_1709 = FALSE;
65 static inline LONG get_ref(IUnknown *obj)
67 IUnknown_AddRef(obj);
68 return IUnknown_Release(obj);
71 #define check_refcount(obj, exp) check_refcount_(__LINE__, obj, exp)
72 static inline void check_refcount_(unsigned int line, void *obj, LONG exp)
74 LONG ref = get_ref(obj);
75 ok_(__FILE__, line)(exp == ref, "Unexpected refcount %lu, expected %lu\n", ref, exp);
78 #define check_interface(obj, iid, exp) check_interface_(__LINE__, obj, iid, exp, FALSE)
79 #define check_optional_interface(obj, iid, exp) check_interface_(__LINE__, obj, iid, exp, TRUE)
80 static void check_interface_(unsigned int line, void *obj, const IID *iid, BOOL supported, BOOL optional)
82 IUnknown *iface = obj;
83 HRESULT hr, expected_hr;
84 IUnknown *unk;
86 expected_hr = supported ? S_OK : E_NOINTERFACE;
88 hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
89 ok_(__FILE__, line)(hr == expected_hr || broken(hr == E_NOINTERFACE && optional), "Got hr %#lx, expected %#lx.\n", hr, expected_hr);
90 if (SUCCEEDED(hr))
91 IUnknown_Release(unk);
94 static const char *debugstr_hstring(HSTRING hstr)
96 const WCHAR *str;
97 UINT32 len;
98 if (hstr && !((ULONG_PTR)hstr >> 16)) return "(invalid)";
99 str = WindowsGetStringRawBuffer(hstr, &len);
100 return wine_dbgstr_wn(str, len);
103 struct completed_event_handler
105 IHandler_RecognitionCompleted IHandler_RecognitionCompleted_iface;
106 LONG ref;
109 static inline struct completed_event_handler *impl_from_IHandler_RecognitionCompleted( IHandler_RecognitionCompleted *iface )
111 return CONTAINING_RECORD(iface, struct completed_event_handler, IHandler_RecognitionCompleted_iface);
114 HRESULT WINAPI completed_event_handler_QueryInterface( IHandler_RecognitionCompleted *iface, REFIID iid, void **out )
116 if (IsEqualGUID(iid, &IID_IUnknown) ||
117 IsEqualGUID(iid, &IID_IAgileObject) ||
118 IsEqualGUID(iid, &IID_IHandler_RecognitionCompleted))
120 IUnknown_AddRef(iface);
121 *out = iface;
122 return S_OK;
125 trace("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
126 *out = NULL;
127 return E_NOINTERFACE;
130 ULONG WINAPI completed_event_handler_AddRef( IHandler_RecognitionCompleted *iface )
132 struct completed_event_handler *impl = impl_from_IHandler_RecognitionCompleted(iface);
133 ULONG ref = InterlockedIncrement(&impl->ref);
134 return ref;
137 ULONG WINAPI completed_event_handler_Release( IHandler_RecognitionCompleted *iface )
139 struct completed_event_handler *impl = impl_from_IHandler_RecognitionCompleted(iface);
140 ULONG ref = InterlockedDecrement(&impl->ref);
141 return ref;
144 HRESULT WINAPI completed_event_handler_Invoke( IHandler_RecognitionCompleted *iface,
145 ISpeechContinuousRecognitionSession *sender,
146 ISpeechContinuousRecognitionCompletedEventArgs *args )
148 trace("iface %p, sender %p, args %p.\n", iface, sender, args);
149 return S_OK;
152 static const struct IHandler_RecognitionCompletedVtbl completed_event_handler_vtbl =
154 /* IUnknown methods */
155 completed_event_handler_QueryInterface,
156 completed_event_handler_AddRef,
157 completed_event_handler_Release,
158 /* ITypedEventHandler<SpeechContinuousRecognitionSession*, SpeechContinuousRecognitionCompletedEventArgs* > methods */
159 completed_event_handler_Invoke
162 static HRESULT WINAPI completed_event_handler_create_static( struct completed_event_handler *impl )
164 impl->IHandler_RecognitionCompleted_iface.lpVtbl = &completed_event_handler_vtbl;
165 impl->ref = 1;
167 return S_OK;
170 struct recognition_result_handler
172 IHandler_RecognitionResult IHandler_RecognitionResult_iface;
173 LONG ref;
176 static inline struct recognition_result_handler *impl_from_IHandler_RecognitionResult( IHandler_RecognitionResult *iface )
178 return CONTAINING_RECORD(iface, struct recognition_result_handler, IHandler_RecognitionResult_iface);
181 HRESULT WINAPI recognition_result_handler_QueryInterface( IHandler_RecognitionResult *iface, REFIID iid, void **out )
183 if (IsEqualGUID(iid, &IID_IUnknown) ||
184 IsEqualGUID(iid, &IID_IAgileObject) ||
185 IsEqualGUID(iid, &IID_IHandler_RecognitionResult))
187 IUnknown_AddRef(iface);
188 *out = iface;
189 return S_OK;
192 trace("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
193 *out = NULL;
194 return E_NOINTERFACE;
197 ULONG WINAPI recognition_result_handler_AddRef( IHandler_RecognitionResult *iface )
199 struct recognition_result_handler *impl = impl_from_IHandler_RecognitionResult(iface);
200 ULONG ref = InterlockedIncrement(&impl->ref);
201 return ref;
204 ULONG WINAPI recognition_result_handler_Release( IHandler_RecognitionResult *iface )
206 struct recognition_result_handler *impl = impl_from_IHandler_RecognitionResult(iface);
207 ULONG ref = InterlockedDecrement(&impl->ref);
208 return ref;
211 HRESULT WINAPI recognition_result_handler_Invoke( IHandler_RecognitionResult *iface,
212 ISpeechContinuousRecognitionSession *sender,
213 ISpeechContinuousRecognitionResultGeneratedEventArgs *args )
215 trace("iface %p, sender %p, args %p.\n", iface, sender, args);
216 return S_OK;
219 static const struct IHandler_RecognitionResultVtbl recognition_result_handler_vtbl =
221 /* IUnknown methods */
222 recognition_result_handler_QueryInterface,
223 recognition_result_handler_AddRef,
224 recognition_result_handler_Release,
225 /* ITypedEventHandler<SpeechContinuousRecognitionSession*, SpeechContinuousRecognitionResultGeneratedEventArgs* > methods */
226 recognition_result_handler_Invoke
229 static HRESULT WINAPI recognition_result_handler_create_static( struct recognition_result_handler *impl )
231 impl->IHandler_RecognitionResult_iface.lpVtbl = &recognition_result_handler_vtbl;
232 impl->ref = 1;
234 return S_OK;
237 struct async_void_handler
239 IAsyncActionCompletedHandler IAsyncActionCompletedHandler_iface;
240 LONG ref;
242 HANDLE event_block;
243 HANDLE event_finished;
246 static inline struct async_void_handler *impl_from_IAsyncActionCompletedHandler(IAsyncActionCompletedHandler *iface)
248 return CONTAINING_RECORD(iface, struct async_void_handler, IAsyncActionCompletedHandler_iface);
251 HRESULT WINAPI async_void_handler_QueryInterface( IAsyncActionCompletedHandler *iface, REFIID iid, void **out )
253 if (IsEqualGUID(iid, &IID_IUnknown) ||
254 IsEqualGUID(iid, &IID_IAgileObject) ||
255 IsEqualGUID(iid, &IID_IAsyncActionCompletedHandler))
257 IUnknown_AddRef(iface);
258 *out = iface;
259 return S_OK;
262 trace("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
263 *out = NULL;
264 return E_NOINTERFACE;
267 ULONG WINAPI async_void_handler_AddRef( IAsyncActionCompletedHandler *iface )
269 struct async_void_handler *impl = impl_from_IAsyncActionCompletedHandler(iface);
270 ULONG ref = InterlockedIncrement(&impl->ref);
271 return ref;
274 ULONG WINAPI async_void_handler_Release( IAsyncActionCompletedHandler *iface )
276 struct async_void_handler *impl = impl_from_IAsyncActionCompletedHandler(iface);
277 ULONG ref = InterlockedDecrement(&impl->ref);
278 return ref;
281 HRESULT WINAPI async_void_handler_Invoke( IAsyncActionCompletedHandler *iface, IAsyncAction *sender, AsyncStatus status )
283 struct async_void_handler *impl = impl_from_IAsyncActionCompletedHandler(iface);
285 trace("iface %p, sender %p, status %d.\n", iface, sender, status);
287 /* Signal finishing of the handler. */
288 if (impl->event_finished) SetEvent(impl->event_finished);
289 /* Block handler until event is set. */
290 if (impl->event_block) WaitForSingleObject(impl->event_block, INFINITE);
292 return S_OK;
295 static const struct IAsyncActionCompletedHandlerVtbl async_void_handler_vtbl =
297 /* IUnknown methods */
298 async_void_handler_QueryInterface,
299 async_void_handler_AddRef,
300 async_void_handler_Release,
301 /* IAsyncActionCompletedHandler methods */
302 async_void_handler_Invoke
306 static HRESULT WINAPI async_void_handler_create_static( struct async_void_handler *impl )
308 impl->IAsyncActionCompletedHandler_iface.lpVtbl = &async_void_handler_vtbl;
309 impl->ref = 1;
311 return S_OK;
314 #define await_async_void(operation, handler) await_async_void_(__LINE__, operation, handler)
315 static void await_async_void_( unsigned int line, IAsyncAction *action, struct async_void_handler *handler )
317 HRESULT hr;
319 async_void_handler_create_static(handler);
320 handler->event_block = NULL;
321 handler->event_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
322 ok_(__FILE__, line)(!!handler->event_finished, "event_finished wasn't created.\n");
324 hr = IAsyncAction_put_Completed(action, &handler->IAsyncActionCompletedHandler_iface);
325 ok_(__FILE__, line)(hr == S_OK, "IAsyncAction_put_Completed failed, hr %#lx.\n", hr);
326 ok_(__FILE__, line)(!WaitForSingleObject(handler->event_finished , 5000), "Wait for event_finished failed.\n");
327 CloseHandle(handler->event_finished);
330 struct async_inspectable_handler
332 IAsyncOperationCompletedHandler_IInspectable IAsyncHandler_IInspectable_iface;
333 const GUID *iid;
334 LONG ref;
336 HANDLE event_block;
337 HANDLE event_finished;
340 static inline struct async_inspectable_handler *impl_from_IAsyncOperationCompletedHandler_IInspectable( IAsyncOperationCompletedHandler_IInspectable *iface )
342 return CONTAINING_RECORD(iface, struct async_inspectable_handler, IAsyncHandler_IInspectable_iface);
345 HRESULT WINAPI async_inspectable_handler_QueryInterface( IAsyncOperationCompletedHandler_IInspectable *iface,
346 REFIID iid,
347 void **out )
349 struct async_inspectable_handler *impl = impl_from_IAsyncOperationCompletedHandler_IInspectable(iface);
351 if (IsEqualGUID(iid, &IID_IUnknown) ||
352 IsEqualGUID(iid, &IID_IAgileObject) ||
353 IsEqualGUID(iid, impl->iid))
355 IUnknown_AddRef(iface);
356 *out = iface;
357 return S_OK;
360 trace("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
361 *out = NULL;
362 return E_NOINTERFACE;
365 ULONG WINAPI async_inspectable_handler_AddRef( IAsyncOperationCompletedHandler_IInspectable *iface )
367 struct async_inspectable_handler *impl = impl_from_IAsyncOperationCompletedHandler_IInspectable(iface);
368 ULONG ref = InterlockedIncrement(&impl->ref);
369 return ref;
372 ULONG WINAPI async_inspectable_handler_Release( IAsyncOperationCompletedHandler_IInspectable *iface )
374 struct async_inspectable_handler *impl = impl_from_IAsyncOperationCompletedHandler_IInspectable(iface);
375 ULONG ref = InterlockedDecrement(&impl->ref);
376 return ref;
379 HRESULT WINAPI async_inspectable_handler_Invoke( IAsyncOperationCompletedHandler_IInspectable *iface,
380 IAsyncOperation_IInspectable *sender,
381 AsyncStatus status )
383 struct async_inspectable_handler *impl = impl_from_IAsyncOperationCompletedHandler_IInspectable(iface);
385 trace("Iface %p, sender %p, status %d.\n", iface, sender, status);
387 /* Signal finishing of the handler. */
388 if (impl->event_finished) SetEvent(impl->event_finished);
389 /* Block handler until event is set. */
390 if (impl->event_block) WaitForSingleObject(impl->event_block, INFINITE);
392 return S_OK;
395 static const struct IAsyncOperationCompletedHandler_IInspectableVtbl async_inspectable_handler_vtbl =
397 /* IUnknown methods */
398 async_inspectable_handler_QueryInterface,
399 async_inspectable_handler_AddRef,
400 async_inspectable_handler_Release,
401 /* IAsyncOperationCompletedHandler<IInspectable* > methods */
402 async_inspectable_handler_Invoke
405 static HRESULT WINAPI async_inspectable_handler_create_static( struct async_inspectable_handler *impl, const GUID *iid )
407 impl->IAsyncOperationCompletedHandler_IInspectable_iface.lpVtbl = &async_inspectable_handler_vtbl;
408 impl->iid = iid;
409 impl->ref = 1;
411 return S_OK;
414 #define await_async_inspectable(operation, handler, iid) await_async_inspectable_(__LINE__, operation, handler, iid)
415 static void await_async_inspectable_( unsigned int line, IAsyncOperation_IInspectable *operation, struct async_inspectable_handler *handler, const GUID *handler_iid )
417 HRESULT hr;
419 async_inspectable_handler_create_static(handler, handler_iid);
420 handler->event_block = NULL;
421 handler->event_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
422 ok_(__FILE__, line)(!!handler->event_finished, "event_finished wasn't created.\n");
424 hr = IAsyncOperation_IInspectable_put_Completed(operation, &handler->IAsyncHandler_IInspectable_iface);
425 ok_(__FILE__, line)(hr == S_OK, "IAsyncOperation_IInspectable_put_Completed failed, hr %#lx.\n", hr);
426 ok_(__FILE__, line)(!WaitForSingleObject(handler->event_finished , 5000), "Wait for event_finished failed.\n");
427 CloseHandle(handler->event_finished);
430 #define check_async_info(obj, exp_id, exp_status, exp_hr) check_async_info_(__LINE__, obj, exp_id, exp_status, exp_hr)
431 static void check_async_info_( unsigned int line, IInspectable *async_obj, UINT32 expect_id, AsyncStatus expect_status, HRESULT expect_hr)
433 IAsyncInfo *async_info;
434 AsyncStatus async_status;
435 UINT32 async_id;
436 HRESULT hr, async_hr;
438 hr = IInspectable_QueryInterface(async_obj, &IID_IAsyncInfo, (void **)&async_info);
439 ok_(__FILE__, line)(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
441 async_id = 0xdeadbeef;
442 hr = IAsyncInfo_get_Id(async_info, &async_id);
443 if (expect_status < 4) todo_wine ok_(__FILE__, line)(hr == S_OK, "IAsyncInfo_get_Id returned %#lx\n", hr);
444 else todo_wine ok_(__FILE__, line)(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_Id returned %#lx\n", hr);
445 todo_wine ok_(__FILE__, line)(async_id == expect_id, "got async_id %#x\n", async_id);
447 async_status = 0xdeadbeef;
448 hr = IAsyncInfo_get_Status(async_info, &async_status);
449 if (expect_status < 4) ok_(__FILE__, line)(hr == S_OK, "IAsyncInfo_get_Status returned %#lx\n", hr);
450 else ok_(__FILE__, line)(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_Status returned %#lx\n", hr);
451 ok_(__FILE__, line)(async_status == expect_status, "got async_status %#x\n", async_status);
453 async_hr = 0xdeadbeef;
454 hr = IAsyncInfo_get_ErrorCode(async_info, &async_hr);
455 if (expect_status < 4) ok_(__FILE__, line)(hr == S_OK, "IAsyncInfo_get_ErrorCode returned %#lx\n", hr);
456 else ok_(__FILE__, line)(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_ErrorCode returned %#lx\n", hr);
457 if (expect_status < 4) ok_(__FILE__, line)(async_hr == expect_hr, "got async_hr %#lx\n", async_hr);
458 else ok_(__FILE__, line)(async_hr == E_ILLEGAL_METHOD_CALL, "got async_hr %#lx\n", async_hr);
460 IAsyncInfo_Release(async_info);
463 struct iterator_hstring
465 IIterator_HSTRING IIterator_HSTRING_iface;
466 LONG ref;
468 UINT32 index;
469 UINT32 size;
470 HSTRING *values;
473 static inline struct iterator_hstring *impl_from_IIterator_HSTRING( IIterator_HSTRING *iface )
475 return CONTAINING_RECORD(iface, struct iterator_hstring, IIterator_HSTRING_iface);
478 static HRESULT WINAPI iterator_hstring_QueryInterface( IIterator_HSTRING *iface, REFIID iid, void **out )
480 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
482 if (IsEqualGUID(iid, &IID_IUnknown) ||
483 IsEqualGUID(iid, &IID_IInspectable) ||
484 IsEqualGUID(iid, &IID_IAgileObject) ||
485 IsEqualGUID(iid, &IID_IIterator_HSTRING))
487 IInspectable_AddRef((*out = &impl->IIterator_HSTRING_iface));
488 return S_OK;
491 *out = NULL;
492 return E_NOINTERFACE;
495 static ULONG WINAPI iterator_hstring_AddRef( IIterator_HSTRING *iface )
497 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
498 ULONG ref = InterlockedIncrement(&impl->ref);
499 return ref;
502 static ULONG WINAPI iterator_hstring_Release( IIterator_HSTRING *iface )
504 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
505 ULONG ref = InterlockedDecrement(&impl->ref);
506 return ref;
509 static HRESULT WINAPI iterator_hstring_GetIids( IIterator_HSTRING *iface, ULONG *iid_count, IID **iids )
511 return E_NOTIMPL;
514 static HRESULT WINAPI iterator_hstring_GetRuntimeClassName( IIterator_HSTRING *iface, HSTRING *class_name )
516 return E_NOTIMPL;
519 static HRESULT WINAPI iterator_hstring_GetTrustLevel( IIterator_HSTRING *iface, TrustLevel *trust_level )
521 return E_NOTIMPL;
524 static HRESULT WINAPI iterator_hstring_get_Current( IIterator_HSTRING *iface, HSTRING *value )
526 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
527 HRESULT hr;
529 *value = NULL;
530 if (impl->index >= impl->size) return E_BOUNDS;
532 hr = WindowsDuplicateString(impl->values[impl->index], value);
533 return hr;
536 static HRESULT WINAPI iterator_hstring_get_HasCurrent( IIterator_HSTRING *iface, BOOL *value )
538 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
540 *value = impl->index < impl->size;
541 return S_OK;
544 static HRESULT WINAPI iterator_hstring_MoveNext( IIterator_HSTRING *iface, BOOL *value )
546 struct iterator_hstring *impl = impl_from_IIterator_HSTRING(iface);
548 if (impl->index < impl->size) impl->index++;
549 return IIterator_HSTRING_get_HasCurrent(iface, value);
552 static HRESULT WINAPI iterator_hstring_GetMany( IIterator_HSTRING *iface, UINT32 items_size,
553 HSTRING *items, UINT *count )
555 return E_NOTIMPL;
558 static const struct IIterator_HSTRINGVtbl iterator_hstring_vtbl =
560 /* IUnknown methods */
561 iterator_hstring_QueryInterface,
562 iterator_hstring_AddRef,
563 iterator_hstring_Release,
564 /* IInspectable methods */
565 iterator_hstring_GetIids,
566 iterator_hstring_GetRuntimeClassName,
567 iterator_hstring_GetTrustLevel,
568 /* IIterator<HSTRING> methods */
569 iterator_hstring_get_Current,
570 iterator_hstring_get_HasCurrent,
571 iterator_hstring_MoveNext,
572 iterator_hstring_GetMany
575 static HRESULT WINAPI iterator_hstring_create_static( struct iterator_hstring *impl, HSTRING *strings, UINT32 size )
577 impl->IIterator_HSTRING_iface.lpVtbl = &iterator_hstring_vtbl;
578 impl->ref = 1;
579 impl->index = 0;
580 impl->size = size;
581 impl->values = strings;
583 return S_OK;
586 struct iterable_hstring
588 IIterable_HSTRING IIterable_HSTRING_iface;
589 LONG ref;
591 IIterator_HSTRING *iterator;
594 static inline struct iterable_hstring *impl_from_Iterable_HSTRING( IIterable_HSTRING *iface )
596 return CONTAINING_RECORD(iface, struct iterable_hstring, IIterable_HSTRING_iface);
599 static HRESULT WINAPI iterable_hstring_QueryInterface( IIterable_HSTRING *iface, REFIID iid, void **out )
601 struct iterable_hstring *impl = impl_from_Iterable_HSTRING(iface);
603 trace("iface %p, iid %s, out %p stub!\n", iface, debugstr_guid(iid), out);
605 if (IsEqualGUID(iid, &IID_IUnknown) ||
606 IsEqualGUID(iid, &IID_IInspectable) ||
607 IsEqualGUID(iid, &IID_IAgileObject) ||
608 IsEqualGUID(iid, &IID_IIterable_HSTRING))
610 IInspectable_AddRef((*out = &impl->IIterable_HSTRING_iface));
611 return S_OK;
614 trace("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
615 *out = NULL;
616 return E_NOINTERFACE;
619 static ULONG WINAPI iterable_hstring_AddRef( IIterable_HSTRING *iface )
621 struct iterable_hstring *impl = impl_from_Iterable_HSTRING(iface);
622 ULONG ref = InterlockedIncrement(&impl->ref);
623 trace("iface %p, ref %lu.\n", iface, ref);
624 return ref;
627 static ULONG WINAPI iterable_hstring_Release( IIterable_HSTRING *iface )
629 struct iterable_hstring *impl = impl_from_Iterable_HSTRING(iface);
630 ULONG ref = InterlockedDecrement(&impl->ref);
631 trace("iface %p, ref %lu.\n", iface, ref);
632 return ref;
635 static HRESULT WINAPI iterable_hstring_GetIids( IIterable_HSTRING *iface, ULONG *iid_count, IID **iids )
637 trace("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids);
638 return E_NOTIMPL;
641 static HRESULT WINAPI iterable_hstring_GetRuntimeClassName( IIterable_HSTRING *iface, HSTRING *class_name )
643 trace("iface %p, class_name %p stub!\n", iface, class_name);
644 return E_NOTIMPL;
647 static HRESULT WINAPI iterable_hstring_GetTrustLevel( IIterable_HSTRING *iface, TrustLevel *trust_level )
649 trace("iface %p, trust_level %p stub!\n", iface, trust_level);
650 return E_NOTIMPL;
653 static HRESULT WINAPI iterable_hstring_First( IIterable_HSTRING *iface, IIterator_HSTRING **value )
655 struct iterable_hstring *impl = impl_from_Iterable_HSTRING(iface);
656 struct iterator_hstring *impl_iter = impl_from_IIterator_HSTRING(impl->iterator);
658 impl_iter->index = 0;
659 IIterator_HSTRING_AddRef((*value = impl->iterator));
660 return S_OK;
663 static const struct IIterable_HSTRINGVtbl iterable_hstring_vtbl =
665 /* IUnknown methods */
666 iterable_hstring_QueryInterface,
667 iterable_hstring_AddRef,
668 iterable_hstring_Release,
669 /* IInspectable methods */
670 iterable_hstring_GetIids,
671 iterable_hstring_GetRuntimeClassName,
672 iterable_hstring_GetTrustLevel,
673 /* IIterable<HSTRING> methods */
674 iterable_hstring_First
677 static HRESULT WINAPI iterable_hstring_create_static( struct iterable_hstring *impl, struct iterator_hstring *iterator )
679 impl->IIterable_HSTRING_iface.lpVtbl = &iterable_hstring_vtbl;
680 impl->ref = 1;
681 impl->iterator = &iterator->IIterator_HSTRING_iface;
683 return S_OK;
686 static void test_ActivationFactory(void)
688 static const WCHAR *synthesizer_name = L"Windows.Media.SpeechSynthesis.SpeechSynthesizer";
689 static const WCHAR *recognizer_name = L"Windows.Media.SpeechRecognition.SpeechRecognizer";
690 static const WCHAR *garbage_name = L"Some.Garbage.Class";
691 IActivationFactory *factory = NULL, *factory2 = NULL, *factory3 = NULL, *factory4 = NULL;
692 ISpeechRecognizerStatics2 *recognizer_statics2 = NULL;
693 HSTRING str, str2, str3;
694 HMODULE hdll;
695 HRESULT hr;
696 ULONG ref;
698 hr = RoInitialize(RO_INIT_MULTITHREADED);
699 ok(hr == S_OK, "RoInitialize failed, hr %#lx.\n", hr);
701 hr = WindowsCreateString(synthesizer_name, wcslen(synthesizer_name), &str);
702 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
704 hr = WindowsCreateString(recognizer_name, wcslen(recognizer_name), &str2);
705 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
707 hr = WindowsCreateString(garbage_name, wcslen(garbage_name), &str3);
708 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
710 hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory);
711 ok(hr == S_OK, "RoGetActivationFactory failed, hr %#lx.\n", hr);
713 check_refcount(factory, 2);
715 check_interface(factory, &IID_IInspectable, TRUE);
716 check_interface(factory, &IID_IAgileObject, TRUE);
717 check_interface(factory, &IID_IInstalledVoicesStatic, TRUE);
718 check_interface(factory, &IID_ISpeechRecognizerFactory, FALSE);
719 check_interface(factory, &IID_ISpeechRecognizerStatics, FALSE);
720 check_interface(factory, &IID_ISpeechRecognizerStatics2, FALSE);
722 hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory2);
723 ok(hr == S_OK, "RoGetActivationFactory failed, hr %#lx.\n", hr);
724 ok(factory == factory2, "Factories pointed at factory %p factory2 %p.\n", factory, factory2);
725 check_refcount(factory2, 3);
727 hr = RoGetActivationFactory(str2, &IID_IActivationFactory, (void **)&factory3);
728 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "Got unexpected hr %#lx.\n", hr);
730 if (hr == S_OK) /* Win10+ only */
732 check_refcount(factory3, 2);
733 ok(factory != factory3, "Factories pointed at factory %p factory3 %p.\n", factory, factory3);
735 check_interface(factory3, &IID_IInspectable, TRUE);
736 check_interface(factory3, &IID_IAgileObject, TRUE);
737 check_interface(factory3, &IID_ISpeechRecognizerFactory, TRUE);
738 check_interface(factory3, &IID_ISpeechRecognizerStatics, TRUE);
740 hr = IActivationFactory_QueryInterface(factory3, &IID_ISpeechRecognizerStatics2, (void **)&recognizer_statics2);
741 ok(hr == S_OK || broken(hr == E_NOINTERFACE), "IActivationFactory_QueryInterface failed, hr %#lx.\n", hr);
743 if (hr == S_OK) /* ISpeechRecognizerStatics2 not available in Win10 1507 */
745 ref = ISpeechRecognizerStatics2_Release(recognizer_statics2);
746 ok(ref == 2, "Got unexpected refcount: %lu.\n", ref);
748 else is_win10_1507 = TRUE;
750 check_interface(factory3, &IID_IInstalledVoicesStatic, FALSE);
752 ref = IActivationFactory_Release(factory3);
753 ok(ref == 1, "Got unexpected refcount: %lu.\n", ref);
756 hdll = LoadLibraryW(L"windows.media.speech.dll");
758 if (hdll)
760 pDllGetActivationFactory = (void *)GetProcAddress(hdll, "DllGetActivationFactory");
761 ok(!!pDllGetActivationFactory, "DllGetActivationFactory not found.\n");
763 hr = pDllGetActivationFactory(str3, &factory4);
764 ok((hr == CLASS_E_CLASSNOTAVAILABLE), "Got unexpected hr %#lx.\n", hr);
765 FreeLibrary(hdll);
768 hr = RoGetActivationFactory(str3, &IID_IActivationFactory, (void **)&factory4);
769 ok((hr == REGDB_E_CLASSNOTREG), "RoGetActivationFactory failed, hr %#lx.\n", hr);
771 ref = IActivationFactory_Release(factory2);
772 ok(ref == 2, "Got unexpected refcount: %lu.\n", ref);
774 ref = IActivationFactory_Release(factory);
775 ok(ref == 1, "Got unexpected refcount: %lu.\n", ref);
777 WindowsDeleteString(str);
778 WindowsDeleteString(str2);
779 WindowsDeleteString(str3);
781 RoUninitialize();
784 static void test_SpeechSynthesizer(void)
786 static const WCHAR *simple_ssml =
787 L"<speak version='1.0' xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-US'>"
788 "Hello, how are you doing today?"
789 "</speak>";
790 static const WCHAR *simple_synth_text = L"Hello, how are you doing today?";
791 static const WCHAR *speech_synthesizer_name = L"Windows.Media.SpeechSynthesis.SpeechSynthesizer";
792 static const WCHAR *speech_synthesizer_name2 = L"windows.media.speechsynthesis.speechsynthesizer";
793 static const WCHAR *unknown_class_name = L"Unknown.Class";
794 IActivationFactory *factory = NULL, *factory2 = NULL;
795 IAsyncOperation_SpeechSynthesisStream *operation_ss_stream = NULL;
796 IVectorView_IMediaMarker *media_markers = NULL;
797 IVectorView_VoiceInformation *voices = NULL;
798 IInstalledVoicesStatic *voices_static = NULL;
799 ISpeechSynthesisStream *ss_stream = NULL;
800 IVoiceInformation *voice;
801 IInspectable *inspectable = NULL, *tmp_inspectable = NULL;
802 IAgileObject *agile_object = NULL, *tmp_agile_object = NULL;
803 ISpeechSynthesizer *synthesizer;
804 ISpeechSynthesizer2 *synthesizer2;
805 IClosable *closable;
806 struct async_inspectable_handler async_inspectable_handler;
807 HMODULE hdll;
808 HSTRING str, str2;
809 HRESULT hr;
810 UINT32 size;
811 ULONG ref;
813 hr = RoInitialize(RO_INIT_MULTITHREADED);
814 ok(hr == S_OK, "RoInitialize failed, hr %#lx\n", hr);
816 hr = WindowsCreateString(speech_synthesizer_name, wcslen(speech_synthesizer_name), &str);
817 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx\n", hr);
819 hdll = LoadLibraryW(L"windows.media.speech.dll");
820 if (hdll)
822 pDllGetActivationFactory = (void *)GetProcAddress(hdll, "DllGetActivationFactory");
823 ok(!!pDllGetActivationFactory, "DllGetActivationFactory not found.\n");
825 hr = WindowsCreateString(unknown_class_name, wcslen(unknown_class_name), &str2);
826 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx\n", hr);
828 hr = pDllGetActivationFactory(str2, &factory);
829 ok(hr == CLASS_E_CLASSNOTAVAILABLE, "Got unexpected hr %#lx.\n", hr);
831 WindowsDeleteString(str2);
833 hr = WindowsCreateString(speech_synthesizer_name2, wcslen(speech_synthesizer_name2), &str2);
834 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx\n", hr);
836 hr = pDllGetActivationFactory(str2, &factory2);
837 ok(hr == CLASS_E_CLASSNOTAVAILABLE, "Got unexpected hr %#lx.\n", hr);
839 WindowsDeleteString(str2);
841 hr = pDllGetActivationFactory(str, &factory2);
842 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
844 else
846 win_skip("Failed to load library, err %lu.\n", GetLastError());
849 hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory);
850 ok(hr == S_OK, "RoGetActivationFactory failed, hr %#lx\n", hr);
852 if (hdll)
854 ok(factory == factory2, "Got unexpected factory %p, factory2 %p.\n", factory, factory2);
855 IActivationFactory_Release(factory2);
856 FreeLibrary(hdll);
859 /* Test static Synth ifaces: IActivationFactory, IInstalledVoicesStatic, etc. */
860 hr = IActivationFactory_QueryInterface(factory, &IID_IInspectable, (void **)&inspectable);
861 ok(hr == S_OK, "IActivationFactory_QueryInterface IID_IInspectable failed, hr %#lx\n", hr);
863 hr = IActivationFactory_QueryInterface(factory, &IID_IAgileObject, (void **)&agile_object);
864 ok(hr == S_OK, "IActivationFactory_QueryInterface IID_IAgileObject failed, hr %#lx\n", hr);
866 hr = IActivationFactory_QueryInterface(factory, &IID_IInstalledVoicesStatic, (void **)&voices_static);
867 ok(hr == S_OK, "IActivationFactory_QueryInterface IID_IInstalledVoicesStatic failed, hr %#lx\n", hr);
869 hr = IInstalledVoicesStatic_QueryInterface(voices_static, &IID_IInspectable, (void **)&tmp_inspectable);
870 ok(hr == S_OK, "IInstalledVoicesStatic_QueryInterface IID_IInspectable failed, hr %#lx\n", hr);
871 ok(tmp_inspectable == inspectable, "IInstalledVoicesStatic_QueryInterface IID_IInspectable returned %p, expected %p\n", tmp_inspectable, inspectable);
872 IInspectable_Release(tmp_inspectable);
874 hr = IInstalledVoicesStatic_QueryInterface(voices_static, &IID_IAgileObject, (void **)&tmp_agile_object);
875 ok(hr == S_OK, "IInstalledVoicesStatic_QueryInterface IID_IAgileObject failed, hr %#lx\n", hr);
876 ok(tmp_agile_object == agile_object, "IInstalledVoicesStatic_QueryInterface IID_IAgileObject returned %p, expected %p\n", tmp_agile_object, agile_object);
877 IAgileObject_Release(tmp_agile_object);
879 hr = IInstalledVoicesStatic_get_AllVoices(voices_static, &voices);
880 ok(hr == S_OK, "IInstalledVoicesStatic_get_AllVoices failed, hr %#lx\n", hr);
882 hr = IVectorView_VoiceInformation_QueryInterface(voices, &IID_IInspectable, (void **)&tmp_inspectable);
883 ok(hr == S_OK, "IVectorView_VoiceInformation_QueryInterface voices failed, hr %#lx\n", hr);
884 ok(tmp_inspectable != inspectable, "IVectorView_VoiceInformation_QueryInterface voices returned %p, expected %p\n", tmp_inspectable, inspectable);
885 IInspectable_Release(tmp_inspectable);
887 hr = IVectorView_VoiceInformation_QueryInterface(voices, &IID_IAgileObject, (void **)&tmp_agile_object);
888 ok(hr == E_NOINTERFACE, "IVectorView_VoiceInformation_QueryInterface voices failed, hr %#lx\n", hr);
890 size = 0xdeadbeef;
891 hr = IVectorView_VoiceInformation_get_Size(voices, &size);
892 ok(hr == S_OK, "IVectorView_VoiceInformation_get_Size voices failed, hr %#lx\n", hr);
893 todo_wine ok(size != 0 && size != 0xdeadbeef, "IVectorView_VoiceInformation_get_Size returned %u\n", size);
895 voice = (IVoiceInformation *)0xdeadbeef;
896 hr = IVectorView_VoiceInformation_GetAt(voices, size, &voice);
897 ok(hr == E_BOUNDS, "IVectorView_VoiceInformation_GetAt failed, hr %#lx\n", hr);
898 ok(voice == NULL, "IVectorView_VoiceInformation_GetAt returned %p\n", voice);
900 hr = IVectorView_VoiceInformation_GetMany(voices, size, 1, &voice, &size);
901 ok(hr == S_OK, "IVectorView_VoiceInformation_GetMany failed, hr %#lx\n", hr);
902 ok(size == 0, "IVectorView_VoiceInformation_GetMany returned count %u\n", size);
904 IVectorView_VoiceInformation_Release(voices);
906 hr = IInstalledVoicesStatic_get_DefaultVoice(voices_static, &voice);
907 todo_wine ok(hr == S_OK, "IInstalledVoicesStatic_get_DefaultVoice failed, hr %#lx\n", hr);
909 if (hr == S_OK)
911 IVoiceInformation_get_Description(voice, &str2);
912 trace("SpeechSynthesizer default voice %s.\n", debugstr_hstring(str2));
914 WindowsDeleteString(str2);
915 ref = IVoiceInformation_Release(voice);
916 ok(ref == 0, "Got unexpected ref %lu.\n", ref);
919 IInstalledVoicesStatic_Release(voices_static);
920 IAgileObject_Release(agile_object);
921 IInspectable_Release(inspectable);
923 /* Test Synthesizer */
924 hr = IActivationFactory_QueryInterface(factory, &IID_ISpeechSynthesizer, (void **)&synthesizer);
925 ok(hr == E_NOINTERFACE, "Got unexpected hr %#lx.\n", hr);
927 hr = RoActivateInstance(str, &inspectable);
928 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
929 WindowsDeleteString(str);
931 hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechSynthesizer, (void **)&synthesizer);
932 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
934 /* Test SynthesizeTextToStreamAsync */
935 hr = WindowsCreateString(simple_synth_text, wcslen(simple_synth_text), &str);
936 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx\n", hr);
938 hr = ISpeechSynthesizer_SynthesizeTextToStreamAsync(synthesizer, NULL, &operation_ss_stream);
939 ok(hr == S_OK, "ISpeechSynthesizer_SynthesizeTextToStreamAsync failed, hr %#lx\n", hr);
940 IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream);
942 hr = ISpeechSynthesizer_SynthesizeTextToStreamAsync(synthesizer, str, &operation_ss_stream);
943 ok(hr == S_OK, "ISpeechSynthesizer_SynthesizeTextToStreamAsync failed, hr %#lx\n", hr);
945 await_async_inspectable((IAsyncOperation_IInspectable *)operation_ss_stream,
946 &async_inspectable_handler,
947 &IID_IAsyncOperationCompletedHandler_SpeechSynthesisStream);
948 check_async_info((IInspectable *)operation_ss_stream, 2, Completed, S_OK);
949 check_interface(operation_ss_stream, &IID_IAsyncOperation_SpeechSynthesisStream, TRUE);
950 check_interface(operation_ss_stream, &IID_IAgileObject, TRUE);
952 hr = IAsyncOperation_SpeechSynthesisStream_GetResults(operation_ss_stream, &ss_stream);
953 ok(hr == S_OK, "IAsyncOperation_SpeechSynthesisStream_GetResults failed, hr %#lx\n", hr);
955 hr = ISpeechSynthesisStream_get_Markers(ss_stream, &media_markers);
956 ok(hr == S_OK, "ISpeechSynthesisStream_get_Markers failed, hr %#lx\n", hr);
957 check_interface(media_markers, &IID_IVectorView_IMediaMarker, TRUE);
958 check_interface(media_markers, &IID_IIterable_IMediaMarker, TRUE);
959 check_interface(media_markers, &IID_IAgileObject, TRUE);
961 ref = IVectorView_IMediaMarker_Release(media_markers);
962 ok(ref == 0, "Got unexpected ref %lu.\n", ref);
964 ref = ISpeechSynthesisStream_Release(ss_stream);
965 ok(ref == 0, "Got unexpected ref %lu.\n", ref);
967 IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream);
969 /* Test SynthesizeSsmlToStreamAsync */
970 hr = WindowsCreateString(simple_ssml, wcslen(simple_ssml), &str2);
971 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx\n", hr);
973 hr = ISpeechSynthesizer_SynthesizeSsmlToStreamAsync(synthesizer, str2, &operation_ss_stream);
974 ok(hr == S_OK, "ISpeechSynthesizer_SynthesizeSsmlToStreamAsync failed, hr %#lx\n", hr);
976 await_async_inspectable((IAsyncOperation_IInspectable *)operation_ss_stream,
977 &async_inspectable_handler,
978 &IID_IAsyncOperationCompletedHandler_SpeechSynthesisStream);
979 check_async_info((IInspectable *)operation_ss_stream, 3, Completed, S_OK);
980 check_interface(operation_ss_stream, &IID_IAsyncOperation_SpeechSynthesisStream, TRUE);
981 check_interface(operation_ss_stream, &IID_IAgileObject, TRUE);
983 hr = IAsyncOperation_SpeechSynthesisStream_GetResults(operation_ss_stream, &ss_stream);
984 ok(hr == S_OK, "IAsyncOperation_SpeechSynthesisStream_GetResults failed, hr %#lx\n", hr);
985 check_interface(ss_stream, &IID_ISpeechSynthesisStream, TRUE);
986 check_interface(ss_stream, &IID_IAgileObject, TRUE);
988 ref = ISpeechSynthesisStream_Release(ss_stream);
989 ok(ref == 0, "Got unexpected ref %lu.\n", ref);
991 IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream);
993 operation_ss_stream = (void *)0xdeadbeef;
994 hr = ISpeechSynthesizer_SynthesizeSsmlToStreamAsync(synthesizer, NULL, &operation_ss_stream);
995 /* Broken on Win 8 + 8.1 */
996 ok(hr == S_OK || broken(hr == E_INVALIDARG), "ISpeechSynthesizer_SynthesizeSsmlToStreamAsync failed, hr %#lx\n", hr);
998 if (hr == S_OK)
1000 ok(!!operation_ss_stream, "operation_ss_stream had value %p.\n", operation_ss_stream);
1001 IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream);
1003 else ok(operation_ss_stream == NULL, "operation_ss_stream had value %p.\n", operation_ss_stream);
1005 operation_ss_stream = (void *)0xdeadbeef;
1006 hr = ISpeechSynthesizer_SynthesizeSsmlToStreamAsync(synthesizer, str, &operation_ss_stream);
1007 /* Broken on Win 8 + 8.1 */
1008 ok(hr == S_OK || broken(hr == SPERR_WINRT_INCORRECT_FORMAT), "ISpeechSynthesizer_SynthesizeSsmlToStreamAsync failed, hr %#lx\n", hr);
1010 if (hr == S_OK)
1012 ok(!!operation_ss_stream, "operation_ss_stream had value %p.\n", operation_ss_stream);
1013 IAsyncOperation_SpeechSynthesisStream_Release(operation_ss_stream);
1015 else ok(operation_ss_stream == NULL, "operation_ss_stream had value %p.\n", operation_ss_stream);
1017 WindowsDeleteString(str2);
1018 WindowsDeleteString(str);
1020 hr = IInspectable_QueryInterface(inspectable, &IID_IClosable, (void **)&closable);
1021 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1023 /* Test ISpeechSynthesizer2 iface */
1024 hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechSynthesizer2, (void **)&synthesizer2);
1025 ok(hr == S_OK || broken(hr == E_NOINTERFACE), "Got unexpected hr %#lx.\n", hr); /* Requires Win10 >= 1703 */
1027 if (hr == S_OK)
1029 ISpeechSynthesizerOptions *options;
1031 hr = ISpeechSynthesizer2_get_Options(synthesizer2, &options);
1032 todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1034 if (hr == S_OK)
1036 ISpeechSynthesizerOptions3 *options3;
1038 check_interface(options, &IID_IAgileObject, TRUE);
1039 check_optional_interface(options, &IID_ISpeechSynthesizerOptions2, TRUE); /* Requires Win10 >= 1709 */
1041 hr = ISpeechSynthesizerOptions_QueryInterface(options, &IID_ISpeechSynthesizerOptions3, (void **)&options3);
1042 ok(hr == S_OK || broken(hr == E_NOINTERFACE), "Got unexpected hr %#lx.\n", hr); /* Requires Win10 >= 1803 */
1044 if (hr == S_OK)
1046 ref = ISpeechSynthesizerOptions3_Release(options3);
1047 ok(ref == 2, "Got unexpected ref %lu.\n", ref);
1049 else
1050 is_win10_1709 = TRUE;
1052 ref = ISpeechSynthesizerOptions_Release(options);
1053 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1056 ref = ISpeechSynthesizer2_Release(synthesizer2);
1057 ok(ref == 3, "Got unexpected ref %lu.\n", ref);
1060 ref = IClosable_Release(closable);
1061 ok(ref == 2, "Got unexpected ref %lu.\n", ref);
1063 ref = ISpeechSynthesizer_Release(synthesizer);
1064 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1066 ref = IInspectable_Release(inspectable);
1067 ok(!ref, "Got unexpected ref %lu.\n", ref);
1069 IActivationFactory_Release(factory);
1070 RoUninitialize();
1073 static void test_VoiceInformation(void)
1075 static const WCHAR *voice_information_name = L"Windows.Media.SpeechSynthesis.VoiceInformation";
1077 IActivationFactory *factory = NULL;
1078 HSTRING str;
1079 HRESULT hr;
1081 hr = RoInitialize(RO_INIT_MULTITHREADED);
1082 ok(hr == S_OK, "RoInitialize failed, hr %#lx\n", hr);
1084 hr = WindowsCreateString(voice_information_name, wcslen(voice_information_name), &str);
1085 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx\n", hr);
1087 hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory);
1088 ok(hr == REGDB_E_CLASSNOTREG, "RoGetActivationFactory returned unexpected hr %#lx\n", hr);
1090 WindowsDeleteString(str);
1092 RoUninitialize();
1095 struct put_completed_thread_param
1097 IAsyncOperationCompletedHandler_IInspectable *handler;
1098 IAsyncOperation_IInspectable *operation;
1101 static DWORD WINAPI put_completed_thread(void *arg)
1103 struct put_completed_thread_param *param = arg;
1104 HRESULT hr;
1106 hr = IAsyncOperation_IInspectable_put_Completed(param->operation, param->handler);
1107 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1109 return 0;
1112 static void test_SpeechRecognizer(void)
1114 static const WCHAR *speech_recognition_name = L"Windows.Media.SpeechRecognition.SpeechRecognizer";
1115 IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult *handler = NULL;
1116 IAsyncOperation_SpeechRecognitionCompilationResult *operation = NULL;
1117 ISpeechRecognitionCompilationResult *compilation_result = NULL;
1118 IVector_ISpeechRecognitionConstraint *constraints = NULL;
1119 ISpeechContinuousRecognitionSession *session = NULL;
1120 ISpeechRecognizerFactory *sr_factory = NULL;
1121 ISpeechRecognizerStatics *sr_statics = NULL;
1122 ISpeechRecognizerStatics2 *sr_statics2 = NULL;
1123 ISpeechRecognizer *recognizer = NULL;
1124 ISpeechRecognizer2 *recognizer2 = NULL;
1125 IActivationFactory *factory = NULL;
1126 IInspectable *inspectable = NULL;
1127 ILanguage *language = NULL;
1128 IAsyncInfo *info = NULL;
1129 struct put_completed_thread_param put_completed_param;
1130 struct async_inspectable_handler compilation_handler;
1131 struct completed_event_handler completed_handler;
1132 struct recognition_result_handler result_handler;
1133 SpeechRecognitionResultStatus result_status;
1134 EventRegistrationToken token = { .value = 0 };
1135 AsyncStatus async_status;
1136 HSTRING hstr, hstr_lang;
1137 HANDLE put_thread;
1138 LONG ref, old_ref;
1139 HRESULT hr;
1141 hr = RoInitialize(RO_INIT_MULTITHREADED);
1142 ok(hr == S_OK, "RoInitialize failed, hr %#lx.\n", hr);
1144 hr = WindowsCreateString(speech_recognition_name, wcslen(speech_recognition_name), &hstr);
1145 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.n", hr);
1147 hr = RoGetActivationFactory(hstr, &IID_IActivationFactory, (void **)&factory);
1148 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "RoGetActivationFactory failed, hr %#lx.\n", hr);
1150 if (hr == REGDB_E_CLASSNOTREG) /* Win 8 and 8.1 */
1152 win_skip("SpeechRecognizer activation factory not available!\n");
1153 goto done;
1156 check_interface(factory, &IID_IAgileObject, TRUE);
1158 hr = IActivationFactory_QueryInterface(factory, &IID_ISpeechRecognizerFactory, (void **)&sr_factory);
1159 ok(hr == S_OK, "IActivationFactory_QueryInterface IID_ISpeechRecognizer failed, hr %#lx.\n", hr);
1161 hr = IActivationFactory_QueryInterface(factory, &IID_ISpeechRecognizerStatics, (void **)&sr_statics);
1162 ok(hr == S_OK, "IActivationFactory_QueryInterface IID_ISpeechRecognizerStatics failed, hr %#lx.\n", hr);
1164 hr = ISpeechRecognizerStatics_get_SystemSpeechLanguage(sr_statics, &language);
1165 todo_wine ok(hr == S_OK, "ISpeechRecognizerStatics_SystemSpeechLanguage failed, hr %#lx.\n", hr);
1167 if (hr == S_OK)
1169 hr = ILanguage_get_LanguageTag(language, &hstr_lang);
1170 ok(hr == S_OK, "ILanguage_get_LanguageTag failed, hr %#lx.\n", hr);
1172 trace("SpeechRecognizer default language %s.\n", debugstr_hstring(hstr_lang));
1174 ILanguage_Release(language);
1177 ref = ISpeechRecognizerStatics_Release(sr_statics);
1178 ok(ref == 3, "Got unexpected ref %lu.\n", ref);
1180 hr = IActivationFactory_QueryInterface(factory, &IID_ISpeechRecognizerStatics2, (void **)&sr_statics2);
1181 ok(hr == S_OK || broken(hr == E_NOINTERFACE), "IActivationFactory_QueryInterface IID_ISpeechRecognizerStatics2 failed, hr %#lx.\n", hr);
1183 if (hr == S_OK) /* SpeechRecognizerStatics2 not implemented on Win10 1507 */
1185 ref = ISpeechRecognizerStatics2_Release(sr_statics2);
1186 ok(ref == 3, "Got unexpected ref %lu.\n", ref);
1189 ref = ISpeechRecognizerFactory_Release(sr_factory);
1190 ok(ref == 2, "Got unexpected ref %lu.\n", ref);
1192 ref = IActivationFactory_Release(factory);
1193 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1195 hr = RoActivateInstance(hstr, &inspectable);
1196 ok(hr == S_OK || broken(hr == SPERR_WINRT_INTERNAL_ERROR), "Got unexpected hr %#lx.\n", hr);
1198 if (hr == S_OK)
1200 check_refcount(inspectable, 1);
1202 hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer, (void **)&recognizer);
1203 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1205 hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer2, (void **)&recognizer2);
1206 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1208 check_interface(inspectable, &IID_IClosable, TRUE);
1210 hr = ISpeechRecognizer2_get_ContinuousRecognitionSession(recognizer2, &session);
1211 ok(hr == S_OK, "ISpeechRecognizer2_get_ContinuousRecognitionSession failed, hr %#lx.\n", hr);
1212 check_refcount(session, 2);
1213 check_refcount(inspectable, 3);
1215 ref = ISpeechRecognizer2_Release(recognizer2);
1216 ok(ref == 2, "Got unexpected ref %lu.\n", ref);
1218 hr = ISpeechContinuousRecognitionSession_add_Completed(session, NULL, &token);
1219 ok(hr == E_INVALIDARG, "ISpeechContinuousRecognitionSession_add_ResultGenerated failed, hr %#lx.\n", hr);
1221 token.value = 0xdeadbeef;
1222 completed_event_handler_create_static(&completed_handler);
1223 hr = ISpeechContinuousRecognitionSession_add_Completed(session, &completed_handler.IHandler_RecognitionCompleted_iface, &token);
1224 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_add_ResultGenerated failed, hr %#lx.\n", hr);
1225 ok(token.value != 0xdeadbeef, "Got unexpexted token: %#I64x.\n", token.value);
1227 hr = ISpeechContinuousRecognitionSession_remove_Completed(session, token);
1228 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_remove_ResultGenerated failed, hr %#lx.\n", hr);
1230 hr = ISpeechContinuousRecognitionSession_add_ResultGenerated(session, NULL, &token);
1231 ok(hr == E_INVALIDARG, "ISpeechContinuousRecognitionSession_add_ResultGenerated failed, hr %#lx.\n", hr);
1233 token.value = 0xdeadbeef;
1234 recognition_result_handler_create_static(&result_handler);
1235 hr = ISpeechContinuousRecognitionSession_add_ResultGenerated(session, &result_handler.IHandler_RecognitionResult_iface, &token);
1236 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_add_ResultGenerated failed, hr %#lx.\n", hr);
1237 ok(token.value != 0xdeadbeef, "Got unexpexted token: %#I64x.\n", token.value);
1239 hr = ISpeechContinuousRecognitionSession_remove_ResultGenerated(session, token);
1240 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_remove_ResultGenerated failed, hr %#lx.\n", hr);
1242 ref = ISpeechContinuousRecognitionSession_Release(session);
1243 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1245 hr = ISpeechRecognizer_get_Constraints(recognizer, &constraints);
1246 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_get_Constraints failed, hr %#lx.\n", hr);
1248 ref = IVector_ISpeechRecognitionConstraint_Release(constraints);
1249 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1251 hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation);
1252 ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr);
1254 handler = (void*)0xdeadbeef;
1255 hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler);
1256 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1257 ok(handler == NULL, "Handler had value %p.\n", handler);
1259 if (FAILED(hr)) goto skip_operation;
1261 compilation_result = (void*)0xdeadbeef;
1262 hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result);
1263 ok(hr == E_ILLEGAL_METHOD_CALL || hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1265 if (hr == E_ILLEGAL_METHOD_CALL) /* Sometimes the operation could have already finished here, */
1266 /* if so skip waiting and getting the results a second time. */
1268 ok(compilation_result == (void*)0xdeadbeef, "Compilation result had value %p.\n", compilation_result);
1270 await_async_inspectable((IAsyncOperation_IInspectable *)operation,
1271 &compilation_handler,
1272 &IID_IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult);
1274 hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, NULL);
1275 ok(hr == E_ILLEGAL_DELEGATE_ASSIGNMENT, "Got unexpected hr %#lx.\n", hr);
1277 hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler);
1278 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1280 compilation_result = (void*)0xdeadbeef;
1281 hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result);
1282 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1285 ok(compilation_result != (void*)0xdeadbeef, "Compilation result had value %p.\n", compilation_result);
1286 check_interface(compilation_result, &IID_IAgileObject, TRUE);
1288 check_async_info((IInspectable *)operation, 1, Completed, S_OK);
1290 hr = ISpeechRecognitionCompilationResult_get_Status(compilation_result, &result_status);
1291 ok(hr == S_OK, "ISpeechRecognitionCompilationResult_get_Status failed, hr %#lx.\n", hr);
1292 ok(result_status == SpeechRecognitionResultStatus_Success, "Got unexpected status %#x.\n", result_status);
1294 ref = ISpeechRecognitionCompilationResult_Release(compilation_result);
1295 ok(!ref , "Got unexpected ref %lu.\n", ref);
1297 hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result);
1298 ok(hr == E_UNEXPECTED, "Got unexpected hr %#lx.\n", hr);
1300 hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info);
1301 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1303 hr = IAsyncInfo_Cancel(info);
1304 ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr);
1305 check_async_info((IInspectable *)operation, 1, Completed, S_OK);
1307 hr = IAsyncInfo_Close(info);
1308 ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr);
1309 check_async_info((IInspectable *)operation, 1, AsyncStatus_Closed, S_OK);
1311 hr = IAsyncInfo_Close(info);
1312 ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr);
1313 check_async_info((IInspectable *)operation, 1, AsyncStatus_Closed, S_OK);
1315 IAsyncInfo_Release(info);
1317 hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, NULL);
1318 ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr);
1320 handler = (void*)0xdeadbeef;
1321 hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler);
1322 ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr);
1324 IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
1326 /* Test if AsyncOperation is started immediately. */
1327 hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation);
1328 ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr);
1329 check_interface(operation, &IID_IAgileObject, TRUE);
1331 hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info);
1332 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1334 async_status = 0xdeadbeef;
1335 hr = IAsyncInfo_get_Status(info, &async_status);
1336 ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr);
1337 ok(async_status != AsyncStatus_Closed, "Status was %#x.\n", async_status);
1338 IAsyncInfo_Release(info);
1340 await_async_inspectable((IAsyncOperation_IInspectable *)operation,
1341 &compilation_handler,
1342 &IID_IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult);
1343 check_async_info((IInspectable *)operation, 2, Completed, S_OK);
1345 IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
1347 ref = ISpeechRecognizer_Release(recognizer);
1348 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1350 ref = IInspectable_Release(inspectable);
1351 ok(!ref, "Got unexpected ref %lu.\n", ref);
1353 /* Test if AsyncInfo_Close waits for the handler to finish. */
1354 hr = RoActivateInstance(hstr, &inspectable);
1355 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1357 hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer, (void **)&recognizer);
1358 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1360 async_inspectable_handler_create_static(&compilation_handler, &IID_IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult);
1361 compilation_handler.event_block = CreateEventW(NULL, FALSE, FALSE, NULL);
1362 compilation_handler.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
1364 ok(!!compilation_handler.event_block, "event_block wasn't created.\n");
1365 ok(!!compilation_handler.event_finished, "event_finished wasn't created.\n");
1367 hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation);
1368 ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr);
1370 put_completed_param.handler = &compilation_handler.IAsyncHandler_IInspectable_iface;
1371 put_completed_param.operation = (IAsyncOperation_IInspectable *)operation;
1372 put_thread = CreateThread(NULL, 0, put_completed_thread, &put_completed_param, 0, NULL);
1374 ok(!WaitForSingleObject(compilation_handler.event_finished, 5000), "Wait for event_finished failed.\n");
1376 todo_wine ok(compilation_handler.ref == 3, "Got unexpected ref %lu.\n", compilation_handler.ref);
1378 handler = (void*)0xdeadbeef;
1379 old_ref = compilation_handler.ref;
1380 hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler);
1381 ok(hr == S_OK, "IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed failed, hr %#lx.\n", hr);
1382 todo_wine ok(handler == (void *)&compilation_handler.IAsyncHandler_IInspectable_iface, "Handler was %p.\n", handler);
1384 ref = compilation_handler.ref - old_ref;
1385 todo_wine ok(ref == 1, "The ref was increased by %lu.\n", ref);
1386 if (handler) IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult_Release(handler);
1388 hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info);
1389 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1391 hr = IAsyncInfo_Close(info); /* If IAsyncInfo_Close would wait for the handler to finish, the test would get stuck here. */
1392 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1394 SetEvent(compilation_handler.event_block);
1395 ok(!WaitForSingleObject(put_thread, 1000), "Wait for block_thread failed.\n");
1396 check_async_info((IInspectable *)operation, 1, AsyncStatus_Closed, S_OK);
1398 CloseHandle(put_thread);
1399 CloseHandle(compilation_handler.event_block);
1400 CloseHandle(compilation_handler.event_finished);
1402 IAsyncInfo_Release(info);
1404 skip_operation:
1405 IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
1407 ref = ISpeechRecognizer_Release(recognizer);
1408 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1410 ref = IInspectable_Release(inspectable);
1411 ok(!ref, "Got unexpected ref %lu.\n", ref);
1413 else if (hr == SPERR_WINRT_INTERNAL_ERROR) /* Not sure when this triggers. Probably if a language pack is not installed. */
1415 win_skip("Could not init SpeechRecognizer with default language!\n");
1418 done:
1419 WindowsDeleteString(hstr);
1421 RoUninitialize();
1424 static void test_SpeechRecognitionListConstraint(void)
1426 static const WCHAR *speech_recognition_list_constraint_name = L"Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint";
1427 static const WCHAR *speech_constraints[] = { L"This is a test.", L"Number 5!", L"What time is it?" };
1428 static const WCHAR *speech_constraint_tag = L"test_message";
1429 ISpeechRecognitionListConstraintFactory *listconstraint_factory = NULL;
1430 ISpeechRecognitionListConstraint *listconstraint = NULL;
1431 ISpeechRecognitionConstraint *constraint = NULL;
1432 IVector_HSTRING *hstring_vector = NULL;
1433 IActivationFactory *factory = NULL;
1434 IInspectable *inspectable = NULL;
1435 struct iterator_hstring iterator_hstring;
1436 struct iterable_hstring iterable_hstring;
1437 HSTRING commands[3], str, tag, tag_out;
1438 UINT32 i, vector_size = 0;
1439 BOOLEAN enabled;
1440 INT32 str_cmp;
1441 HRESULT hr;
1442 LONG ref;
1444 hr = RoInitialize(RO_INIT_MULTITHREADED);
1445 ok(hr == S_OK, "RoInitialize failed, hr %#lx.\n", hr);
1447 hr = WindowsCreateString(speech_recognition_list_constraint_name, wcslen(speech_recognition_list_constraint_name), &str);
1448 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
1450 hr = WindowsCreateString(speech_constraint_tag, wcslen(speech_constraint_tag), &tag);
1451 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
1453 for (i = 0; i < ARRAY_SIZE(commands); i++)
1455 hr = WindowsCreateString(speech_constraints[i], wcslen(speech_constraints[i]), &commands[i]);
1456 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
1459 hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory);
1460 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "RoGetActivationFactory failed, hr %#lx.\n", hr);
1462 if (hr == REGDB_E_CLASSNOTREG) /* Win 8 and 8.1 */
1464 win_skip("SpeechRecognitionListConstraint activation factory not available!\n");
1465 goto done;
1468 hr = IActivationFactory_ActivateInstance(factory, &inspectable);
1469 ok(hr == E_NOTIMPL, "IActivationFactory_ActivateInstance failed, hr %#lx.\n", hr);
1471 check_refcount(factory, 2);
1472 check_interface(factory, &IID_IInspectable, TRUE);
1473 check_interface(factory, &IID_IAgileObject, TRUE);
1475 hr = IActivationFactory_QueryInterface(factory, &IID_ISpeechRecognitionListConstraintFactory, (void **)&listconstraint_factory);
1476 ok(hr == S_OK, "IActivationFactory_QueryInterface IID_ISpeechRecognitionListConstraintFactory failed, hr %#lx.\n", hr);
1478 hr = ISpeechRecognitionListConstraintFactory_Create(listconstraint_factory, NULL, &listconstraint);
1479 ok(hr == E_POINTER, "ISpeechRecognitionListConstraintFactory_Create failed, hr %#lx.\n", hr);
1481 hr = ISpeechRecognitionListConstraintFactory_CreateWithTag(listconstraint_factory, NULL, NULL, &listconstraint);
1482 ok(hr == E_POINTER, "ISpeechRecognitionListConstraintFactory_Create failed, hr %#lx.\n", hr);
1485 * The create functions break on Win10 <= 1709 x32 with the given iterator.
1486 * Seems like a Windows bug, but if you see an issue in the test's code, please FIXME.
1487 * Skipping these tests.
1489 if (broken((is_win10_1507 || is_win10_1709) && (sizeof(void*) == 4)))
1491 win_skip("SpeechRecognitionListConstraint object creation broken on Win10 <= 1709 x32!\n");
1492 goto skip_create;
1495 iterator_hstring_create_static(&iterator_hstring, commands, ARRAY_SIZE(commands));
1496 iterable_hstring_create_static(&iterable_hstring, &iterator_hstring);
1498 hr = ISpeechRecognitionListConstraintFactory_CreateWithTag(listconstraint_factory, &iterable_hstring.IIterable_HSTRING_iface, NULL, &listconstraint);
1499 ok(hr == S_OK, "ISpeechRecognitionListConstraintFactory_Create failed, hr %#lx.\n", hr);
1501 ref = ISpeechRecognitionListConstraint_Release(listconstraint);
1502 ok(ref == 0, "Got unexpected ref %lu.\n", ref);
1504 iterator_hstring_create_static(&iterator_hstring, commands, ARRAY_SIZE(commands));
1505 iterable_hstring_create_static(&iterable_hstring, &iterator_hstring);
1507 hr = ISpeechRecognitionListConstraintFactory_CreateWithTag(listconstraint_factory, &iterable_hstring.IIterable_HSTRING_iface, tag, &listconstraint);
1508 ok(hr == S_OK, "ISpeechRecognitionListConstraintFactory_CreateWithTag failed, hr %#lx.\n", hr);
1510 check_refcount(listconstraint, 1);
1511 check_interface(listconstraint, &IID_IInspectable, TRUE);
1512 check_interface(listconstraint, &IID_IAgileObject, TRUE);
1514 hr = ISpeechRecognitionListConstraint_QueryInterface(listconstraint, &IID_ISpeechRecognitionConstraint, (void **)&constraint);
1515 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1517 hr = ISpeechRecognitionListConstraint_get_Commands(listconstraint, &hstring_vector);
1518 ok(hr == S_OK, "ISpeechRecognitionListConstraint_Commands failed, hr %#lx.\n", hr);
1520 hr = IVector_HSTRING_get_Size(hstring_vector, &vector_size);
1521 ok(hr == S_OK, "IVector_HSTRING_get_Size failed, hr %#lx.\n", hr);
1522 ok(vector_size == ARRAY_SIZE(commands), "Got unexpected vector_size %u.\n", vector_size);
1524 for (i = 0; i < vector_size; i++)
1526 HSTRING str;
1528 hr = IVector_HSTRING_GetAt(hstring_vector, i, &str);
1529 ok(hr == S_OK, "IVector_HSTRING_GetAt failed, hr %#lx.\n", hr);
1530 hr = WindowsCompareStringOrdinal(commands[i], str, &str_cmp);
1531 ok(hr == S_OK, "WindowsCompareStringOrdinal failed, hr %#lx.\n", hr);
1532 ok(!str_cmp, "Strings not equal.\n");
1534 WindowsDeleteString(str);
1537 ref = IVector_HSTRING_Release(hstring_vector);
1538 ok(ref == 0, "Got unexpected ref %lu.\n", ref);
1540 hr = ISpeechRecognitionConstraint_get_Tag(constraint, &tag_out);
1541 todo_wine ok(hr == S_OK, "ISpeechRecognitionConstraint_get_Tag failed, hr %#lx.\n", hr);
1543 if (FAILED(hr))
1544 goto skip_tests;
1546 hr = WindowsCompareStringOrdinal(tag, tag_out, &str_cmp);
1547 todo_wine ok(hr == S_OK, "WindowsCompareStringOrdinal failed, hr %#lx.\n", hr);
1548 todo_wine ok(!str_cmp, "Strings not equal.\n");
1549 hr = WindowsDeleteString(tag_out);
1550 todo_wine ok(hr == S_OK, "WindowsDeleteString failed, hr %#lx.\n", hr);
1552 skip_tests:
1553 hr = ISpeechRecognitionConstraint_put_IsEnabled(constraint, TRUE);
1554 ok(hr == S_OK, "ISpeechRecognitionConstraint_put_IsEnabled failed, hr %#lx.\n", hr);
1555 hr = ISpeechRecognitionConstraint_get_IsEnabled(constraint, &enabled);
1556 ok(hr == S_OK, "ISpeechRecognitionConstraint_get_IsEnabled failed, hr %#lx.\n", hr);
1557 ok(enabled, "ListConstraint didn't get enabled.\n");
1559 ref = ISpeechRecognitionConstraint_Release(constraint);
1560 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1562 ref = ISpeechRecognitionListConstraint_Release(listconstraint);
1563 ok(ref == 0, "Got unexpected ref %lu.\n", ref);
1565 skip_create:
1566 ref = ISpeechRecognitionListConstraintFactory_Release(listconstraint_factory);
1567 ok(ref == 2, "Got unexpected ref %lu.\n", ref);
1569 ref = IActivationFactory_Release(factory);
1570 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1572 done:
1573 WindowsDeleteString(str);
1574 WindowsDeleteString(tag);
1575 for (i = 0; i < ARRAY_SIZE(commands); i++)
1576 WindowsDeleteString(commands[i]);
1578 RoUninitialize();
1581 struct action_put_completed_thread_param
1583 IAsyncActionCompletedHandler *handler;
1584 IAsyncAction *action;
1587 static DWORD WINAPI action_put_completed_thread(void *arg)
1589 struct action_put_completed_thread_param *param = arg;
1590 HRESULT hr;
1592 hr = IAsyncAction_put_Completed(param->action, param->handler);
1593 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1595 return 0;
1598 static void test_Recognition(void)
1600 static const WCHAR *list_constraint_name = L"Windows.Media.SpeechRecognition.SpeechRecognitionListConstraint";
1601 static const WCHAR *recognizer_name = L"Windows.Media.SpeechRecognition.SpeechRecognizer";
1602 static const WCHAR *speech_constraint_tag = L"test_message";
1603 static const WCHAR *speech_constraints[] = { L"This is a test.", L"Number 5!", L"What time is it?" };
1604 ISpeechRecognitionListConstraintFactory *listconstraint_factory = NULL;
1605 IAsyncOperation_SpeechRecognitionCompilationResult *operation = NULL;
1606 IVector_ISpeechRecognitionConstraint *constraints = NULL;
1607 ISpeechContinuousRecognitionSession *session = NULL;
1608 ISpeechRecognitionListConstraint *listconstraint = NULL;
1609 ISpeechRecognitionConstraint *constraint = NULL;
1610 ISpeechRecognizer *recognizer = NULL;
1611 ISpeechRecognizer2 *recognizer2 = NULL;
1612 IAsyncActionCompletedHandler *handler = NULL;
1613 IAsyncAction *action = NULL, *action2 = NULL;
1614 IInspectable *inspectable = NULL;
1615 IAsyncInfo *info = NULL;
1616 struct async_inspectable_handler compilation_handler;
1617 struct action_put_completed_thread_param put_param;
1618 struct recognition_result_handler result_handler;
1619 struct async_void_handler action_handler;
1620 struct iterator_hstring iterator_hstring;
1621 struct iterable_hstring iterable_hstring;
1622 EventRegistrationToken token = { .value = 0 };
1623 SpeechRecognizerState recog_state;
1624 HSTRING commands[3], hstr, tag;
1625 HANDLE put_thread;
1626 LONG ref, old_ref;
1627 HRESULT hr;
1628 UINT32 i;
1629 BOOL set;
1631 hr = RoInitialize(RO_INIT_MULTITHREADED);
1632 ok(hr == S_OK, "RoInitialize failed, hr %#lx.\n", hr);
1634 for (i = 0; i < ARRAY_SIZE(commands); i++)
1636 hr = WindowsCreateString(speech_constraints[i], wcslen(speech_constraints[i]), &commands[i]);
1637 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
1641 * The create functions break on Win10 <= 1709 x32 with the given iterator.
1642 * Seems like a Windows bug, but if you see an issue in the test's code, please FIXME.
1643 * Skipping these tests.
1645 if (broken((is_win10_1507 || is_win10_1709) && (sizeof(void*) == 4)))
1647 win_skip("SpeechRecognitionListConstraint object creation broken on Win10 <= 1709 x32!\n");
1648 goto done;
1651 hr = WindowsCreateString(recognizer_name, wcslen(recognizer_name), &hstr);
1652 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
1654 hr = RoActivateInstance(hstr, &inspectable);
1655 ok(hr == S_OK || broken(hr == SPERR_WINRT_INTERNAL_ERROR || hr == REGDB_E_CLASSNOTREG), "Got unexpected hr %#lx.\n", hr);
1656 WindowsDeleteString(hstr);
1658 if (FAILED(hr)) /* Win 8 and 8.1 and Win10 without enabled SR. */
1660 win_skip("SpeechRecognizer cannot be activated!\n");
1661 goto done;
1664 hr = WindowsCreateString(list_constraint_name, wcslen(list_constraint_name), &hstr);
1665 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
1667 hr = RoGetActivationFactory(hstr, &IID_ISpeechRecognitionListConstraintFactory, (void **)&listconstraint_factory);
1668 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "RoGetActivationFactory failed, hr %#lx.\n", hr);
1669 WindowsDeleteString(hstr);
1671 hr = WindowsCreateString(speech_constraint_tag, wcslen(speech_constraint_tag), &tag);
1672 ok(hr == S_OK, "WindowsCreateString failed, hr %#lx.\n", hr);
1674 iterator_hstring_create_static(&iterator_hstring, commands, ARRAY_SIZE(commands));
1675 iterable_hstring_create_static(&iterable_hstring, &iterator_hstring);
1676 hr = ISpeechRecognitionListConstraintFactory_CreateWithTag(listconstraint_factory, &iterable_hstring.IIterable_HSTRING_iface, tag, &listconstraint);
1677 ok(hr == S_OK, "ISpeechRecognitionListConstraintFactory_Create failed, hr %#lx.\n", hr);
1678 WindowsDeleteString(tag);
1680 ref = ISpeechRecognitionListConstraintFactory_Release(listconstraint_factory);
1681 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1683 hr = ISpeechRecognitionListConstraint_QueryInterface(listconstraint, &IID_ISpeechRecognitionConstraint, (void **)&constraint);
1684 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1686 hr = ISpeechRecognitionConstraint_put_IsEnabled(constraint, TRUE);
1687 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1689 hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer, (void **)&recognizer);
1690 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1692 hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer2, (void **)&recognizer2);
1693 ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
1695 hr = ISpeechRecognizer2_get_ContinuousRecognitionSession(recognizer2, &session);
1696 ok(hr == S_OK, "ISpeechRecognizer2_get_ContinuousRecognitionSession failed, hr %#lx.\n", hr);
1698 hr = ISpeechRecognizer_get_Constraints(recognizer, &constraints);
1699 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_get_Constraints failed, hr %#lx.\n", hr);
1701 hr = IVector_ISpeechRecognitionConstraint_Clear(constraints);
1702 ok(hr == S_OK, "IVector_ISpeechRecognitionConstraint_Clear failed, hr %#lx.\n", hr);
1704 hr = IVector_ISpeechRecognitionConstraint_Append(constraints, constraint);
1705 ok(hr == S_OK, "IVector_ISpeechRecognitionConstraint_Append failed, hr %#lx.\n", hr);
1707 ref = IVector_ISpeechRecognitionConstraint_Release(constraints);
1708 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1710 ref = ISpeechRecognitionConstraint_Release(constraint);
1711 ok(ref == 2, "Got unexpected ref %lu.\n", ref);
1713 ref = ISpeechRecognitionListConstraint_Release(listconstraint);
1714 ok(ref == 1, "Got unexpected ref %lu.\n", ref);
1716 token.value = 0xdeadbeef;
1717 recognition_result_handler_create_static(&result_handler);
1718 hr = ISpeechContinuousRecognitionSession_add_ResultGenerated(session, &result_handler.IHandler_RecognitionResult_iface, &token);
1719 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_add_ResultGenerated failed, hr %#lx.\n", hr);
1720 ok(token.value != 0xdeadbeef, "Got unexpexted token: %#I64x.\n", token.value);
1722 recog_state = 0xdeadbeef;
1723 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1724 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1725 ok(recog_state == SpeechRecognizerState_Idle, "recog_state was %u.\n", recog_state);
1727 hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation);
1728 ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr);
1729 await_async_inspectable((IAsyncOperation_IInspectable *)operation,
1730 &compilation_handler,
1731 &IID_IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult);
1733 IAsyncOperation_IInspectable_Release((IAsyncOperation_IInspectable *)operation);
1735 hr = ISpeechContinuousRecognitionSession_StartAsync(session, &action);
1736 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_StartAsync failed, hr %#lx.\n", hr);
1738 handler = (void *)0xdeadbeef;
1739 hr = IAsyncAction_get_Completed(action, &handler);
1740 ok(hr == S_OK, "IAsyncAction_put_Completed failed, hr %#lx.\n", hr);
1741 ok(handler == NULL, "Handler was %p.\n", handler);
1743 await_async_void(action, &action_handler);
1745 action2 = (void *)0xdeadbeef;
1746 hr = ISpeechContinuousRecognitionSession_StartAsync(session, &action2);
1747 ok(hr == COR_E_INVALIDOPERATION, "ISpeechContinuousRecognitionSession_StartAsync failed, hr %#lx.\n", hr);
1748 ok(action2 == NULL, "action2 was %p.\n", action2);
1750 hr = IAsyncAction_QueryInterface(action, &IID_IAsyncInfo, (void **)&info);
1751 ok(hr == S_OK, "IAsyncAction_QueryInterface failed, hr %#lx.\n", hr);
1752 check_async_info((IInspectable *)action, 1, Completed, S_OK);
1754 hr = IAsyncInfo_Cancel(info);
1755 ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr);
1756 check_async_info((IInspectable *)action, 1, Completed, S_OK);
1758 hr = IAsyncInfo_Close(info);
1759 ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr);
1760 check_async_info((IInspectable *)action, 1, AsyncStatus_Closed, S_OK);
1762 hr = IAsyncInfo_Close(info);
1763 ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr);
1764 check_async_info((IInspectable *)action, 1, AsyncStatus_Closed, S_OK);
1766 hr = IAsyncInfo_Cancel(info);
1767 todo_wine ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr);
1768 check_async_info((IInspectable *)action, 1, AsyncStatus_Closed, S_OK);
1770 IAsyncInfo_Release(info);
1772 recog_state = 0xdeadbeef;
1773 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1774 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1775 ok(recog_state == SpeechRecognizerState_Capturing || broken(recog_state == SpeechRecognizerState_Idle), "recog_state was %u.\n", recog_state);
1778 * TODO: Use a loopback device together with prerecorded audio files to test the recognizer's functionality.
1781 hr = ISpeechContinuousRecognitionSession_PauseAsync(session, &action2);
1782 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_PauseAsync failed, hr %#lx.\n", hr);
1783 await_async_void(action2, &action_handler);
1784 check_async_info((IInspectable *)action2, 3, Completed, S_OK);
1785 IAsyncAction_Release(action2);
1787 recog_state = 0xdeadbeef;
1788 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1789 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1790 ok(recog_state == SpeechRecognizerState_Paused ||
1791 broken(recog_state == SpeechRecognizerState_Capturing) /* Broken on Win10 1507 */, "recog_state was %u.\n", recog_state);
1793 /* Check what happens if we try to pause again, when the session is already paused. */
1794 hr = ISpeechContinuousRecognitionSession_PauseAsync(session, &action2);
1795 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_PauseAsync failed, hr %#lx.\n", hr);
1796 await_async_void(action2, &action_handler);
1797 check_async_info((IInspectable *)action2, 4, Completed, S_OK);
1798 IAsyncAction_Release(action2);
1800 hr = ISpeechContinuousRecognitionSession_Resume(session);
1801 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_Resume failed, hr %#lx.\n", hr);
1803 /* Resume when already resumed. */
1804 hr = ISpeechContinuousRecognitionSession_Resume(session);
1805 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_Resume failed, hr %#lx.\n", hr);
1807 recog_state = 0xdeadbeef;
1808 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1809 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1810 ok(recog_state == SpeechRecognizerState_Capturing, "recog_state was %u.\n", recog_state);
1812 hr = ISpeechContinuousRecognitionSession_StopAsync(session, &action2);
1813 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_StopAsync failed, hr %#lx.\n", hr);
1815 async_void_handler_create_static(&action_handler);
1816 action_handler.event_block = CreateEventW(NULL, FALSE, FALSE, NULL);
1817 action_handler.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
1818 ok(!!action_handler.event_block, "Block event wasn't created.\n");
1819 ok(!!action_handler.event_finished, "Finished event wasn't created.\n");
1821 /* Check if IAsyncInfo_Close is non blocking. */
1822 put_param.handler = &action_handler.IAsyncActionCompletedHandler_iface;
1823 put_param.action = action2;
1824 put_thread = CreateThread(NULL, 0, action_put_completed_thread, &put_param, 0, NULL);
1825 ok(!WaitForSingleObject(action_handler.event_finished , 5000), "Wait for event_finished failed.\n");
1827 handler = (void *)0xdeadbeef;
1828 old_ref = action_handler.ref;
1829 hr = IAsyncAction_get_Completed(action2, &handler);
1830 ok(hr == S_OK, "IAsyncAction_get_Completed failed, hr %#lx.\n", hr);
1832 todo_wine ok(handler == &action_handler.IAsyncActionCompletedHandler_iface, "Handler was %p.\n", handler);
1834 ref = action_handler.ref - old_ref;
1835 todo_wine ok(ref == 1, "The ref was increased by %lu.\n", ref);
1836 if (handler) IAsyncActionCompletedHandler_Release(handler);
1838 hr = IAsyncAction_QueryInterface(action2, &IID_IAsyncInfo, (void **)&info);
1839 ok(hr == S_OK, "IAsyncAction_QueryInterface failed, hr %#lx.\n", hr);
1841 hr = IAsyncInfo_Close(info); /* If IAsyncInfo_Close would wait for the handler to finish, the test would get stuck here. */
1842 ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr);
1843 check_async_info((IInspectable *)action2, 5, AsyncStatus_Closed, S_OK);
1845 set = SetEvent(action_handler.event_block);
1846 ok(set == TRUE, "Event 'event_block' wasn't set.\n");
1847 ok(!WaitForSingleObject(put_thread, 1000), "Wait for put_thread failed.\n");
1848 IAsyncInfo_Release(info);
1850 CloseHandle(action_handler.event_finished);
1851 CloseHandle(action_handler.event_block);
1852 CloseHandle(put_thread);
1854 ok(action != action2, "actions were the same!\n");
1856 IAsyncAction_Release(action2);
1857 IAsyncAction_Release(action);
1859 recog_state = 0xdeadbeef;
1860 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1861 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1862 ok(recog_state == SpeechRecognizerState_Idle, "recog_state was %u.\n", recog_state);
1864 /* Try stopping, when already stopped. */
1865 hr = ISpeechContinuousRecognitionSession_StopAsync(session, &action);
1866 ok(hr == COR_E_INVALIDOPERATION, "ISpeechContinuousRecognitionSession_StopAsync failed, hr %#lx.\n", hr);
1867 ok(action == NULL, "action was %p.\n", action);
1869 /* Test, if Start/StopAsync resets the pause state. */
1870 hr = ISpeechContinuousRecognitionSession_StartAsync(session, &action);
1871 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_StartAsync failed, hr %#lx.\n", hr);
1872 await_async_void(action, &action_handler);
1873 IAsyncAction_Release(action);
1875 hr = ISpeechContinuousRecognitionSession_PauseAsync(session, &action);
1876 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_PauseAsync failed, hr %#lx.\n", hr);
1877 await_async_void(action, &action_handler);
1878 IAsyncAction_Release(action);
1880 recog_state = 0xdeadbeef;
1881 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1882 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1883 ok(recog_state == SpeechRecognizerState_Paused ||
1884 broken(recog_state == SpeechRecognizerState_Capturing) /* Broken on Win10 1507 */, "recog_state was %u.\n", recog_state);
1886 hr = ISpeechContinuousRecognitionSession_StopAsync(session, &action);
1887 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_PauseAsync failed, hr %#lx.\n", hr);
1888 await_async_void(action, &action_handler);
1889 IAsyncAction_Release(action);
1891 recog_state = 0xdeadbeef;
1892 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1893 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1894 ok(recog_state == SpeechRecognizerState_Idle, "recog_state was %u.\n", recog_state);
1896 hr = ISpeechContinuousRecognitionSession_StartAsync(session, &action);
1897 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_PauseAsync failed, hr %#lx.\n", hr);
1898 await_async_void(action, &action_handler);
1899 IAsyncAction_Release(action);
1901 recog_state = 0xdeadbeef;
1902 hr = ISpeechRecognizer2_get_State(recognizer2, &recog_state);
1903 ok(hr == S_OK, "ISpeechRecognizer2_get_State failed, hr %#lx.\n", hr);
1904 ok(recog_state == SpeechRecognizerState_Capturing
1905 || broken(recog_state == SpeechRecognizerState_Idle) /* Sometimes Windows is a little behind. */,
1906 "recog_state was %u.\n", recog_state);
1908 hr = ISpeechContinuousRecognitionSession_StopAsync(session, &action);
1909 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_PauseAsync failed, hr %#lx.\n", hr);
1910 await_async_void(action, &action_handler);
1911 IAsyncAction_Release(action);
1913 hr = ISpeechContinuousRecognitionSession_remove_ResultGenerated(session, token);
1914 ok(hr == S_OK, "ISpeechContinuousRecognitionSession_remove_ResultGenerated failed, hr %#lx.\n", hr);
1916 ISpeechContinuousRecognitionSession_Release(session);
1917 ISpeechRecognizer2_Release(recognizer2);
1918 ISpeechRecognizer_Release(recognizer);
1919 IInspectable_Release(inspectable);
1921 done:
1922 for (i = 0; i < ARRAY_SIZE(commands); i++)
1923 WindowsDeleteString(commands[i]);
1925 RoUninitialize();
1928 START_TEST(speech)
1930 test_ActivationFactory();
1931 test_SpeechSynthesizer();
1932 test_VoiceInformation();
1933 test_SpeechRecognizer();
1934 test_SpeechRecognitionListConstraint();
1935 test_Recognition();