The tests were mostly broken, racing or inconsistent.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- v2: Remove the tests in one patch and also remove the refcount check. --- dlls/windows.media.speech/tests/speech.c | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-)
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 3021686b228..4f1f92ded5f 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -966,7 +966,6 @@ static void test_SpeechRecognizer(void)
hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, &compilation_handler.IAsyncHandler_Compilation_iface); todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); - todo_wine check_refcount(&compilation_handler.IAsyncHandler_Compilation_iface, 1);
todo_wine ok(!WaitForSingleObject(compilation_handler.event_finished, 1000), "Wait for event_finished failed.\n"); CloseHandle(compilation_handler.event_finished); @@ -974,10 +973,8 @@ static void test_SpeechRecognizer(void) hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, NULL); todo_wine ok(hr == E_ILLEGAL_DELEGATE_ASSIGNMENT, "Got unexpected hr %#lx.\n", hr);
- handler = (void*)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler); todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); - todo_wine ok(handler == NULL, "Handler had value %p.\n", handler);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); @@ -996,14 +993,6 @@ static void test_SpeechRecognizer(void) hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- /* Check if AsyncInfo and AsyncOperation share the same refcount. */ - IAsyncOperation_SpeechRecognitionCompilationResult_AddRef(operation); - todo_wine check_refcount(operation, 3); - todo_wine check_refcount(info, 3); - - IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation); - todo_wine check_refcount(info, 2); - id = 0xdeadbeef; hr = IAsyncInfo_get_Id(info, &id); todo_wine ok(hr == S_OK, "IAsyncInfo_get_Id failed, hr %#lx.\n", hr); @@ -1058,16 +1047,10 @@ static void test_SpeechRecognizer(void) hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- /* This one can fail, if the async operation had already finished */ - compilation_result = (void*)0xdeadbeef; - hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); - todo_wine ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr); - todo_wine ok(compilation_result == (void*)0xdeadbeef, "Compilation result had value %p.\n", compilation_result); - async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(info, &async_status); todo_wine ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(async_status == Started || async_status == Completed, "Status was %#x.\n", async_status); + todo_wine ok(async_status != AsyncStatus_Closed, "Status was %#x.\n", async_status);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, &compilation_handler2.IAsyncHandler_Compilation_iface); todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/tests/speech.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 4f1f92ded5f..12ac407b751 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -834,7 +834,6 @@ static void test_SpeechRecognizer(void) struct completed_event_handler completed_handler; struct recognition_result_handler result_handler; struct compilation_handler compilation_handler; - struct compilation_handler compilation_handler2; SpeechRecognitionResultStatus result_status; EventRegistrationToken token = { .value = 0 }; AsyncStatus async_status; @@ -1034,11 +1033,11 @@ static void test_SpeechRecognizer(void) IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
/* Test if AsyncOperation is started immediately. */ - compilation_handler_create_static(&compilation_handler2); - compilation_handler2.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL); - compilation_handler2.thread_id = GetCurrentThreadId(); + compilation_handler_create_static(&compilation_handler); + compilation_handler.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL); + compilation_handler.thread_id = GetCurrentThreadId();
- ok(compilation_handler2.event_finished != NULL, "Finished event wasn't created.\n"); + ok(compilation_handler.event_finished != NULL, "Finished event wasn't created.\n");
hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation); todo_wine ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr); @@ -1052,11 +1051,11 @@ static void test_SpeechRecognizer(void) todo_wine ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); todo_wine ok(async_status != AsyncStatus_Closed, "Status was %#x.\n", async_status);
- hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, &compilation_handler2.IAsyncHandler_Compilation_iface); + hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, &compilation_handler.IAsyncHandler_Compilation_iface); todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- todo_wine ok(!WaitForSingleObject(compilation_handler2.event_finished, 1000), "Wait for event_finished failed.\n"); - CloseHandle(compilation_handler2.event_finished); + todo_wine ok(!WaitForSingleObject(compilation_handler.event_finished, 1000), "Wait for event_finished failed.\n"); + CloseHandle(compilation_handler.event_finished);
async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(info, &async_status);
Signed-off-by: Rémi Bernon rbernon@codeweavers.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- v2: Remove unnecessary variable name. --- dlls/windows.media.speech/tests/speech.c | 96 ++++++++++++++++++++---- 1 file changed, 82 insertions(+), 14 deletions(-)
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 12ac407b751..f1c0f991cec 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -239,8 +239,8 @@ struct compilation_handler IAsyncHandler_Compilation IAsyncHandler_Compilation_iface; LONG ref;
+ HANDLE event_block; HANDLE event_finished; - BOOLEAN sleeping; DWORD thread_id; };
@@ -290,8 +290,10 @@ HRESULT WINAPI compilation_handler_Invoke( IAsyncHandler_Compilation *iface, trace("Iface %p, info %p, status %d.\n", iface, info, status); trace("Caller thread id %lu callback thread id %lu.\n", impl->thread_id, id);
- ok(status != Started, "Got unexpected status %#x.\n", status); + /* Signal finishing of the handler. */ if (impl->event_finished) SetEvent(impl->event_finished); + /* Block handler until event is set. */ + if (impl->event_block) WaitForSingleObject(impl->event_block, INFINITE);
return S_OK; } @@ -813,6 +815,23 @@ static void test_VoiceInformation(void) RoUninitialize(); }
+struct async_operation_block_param +{ + IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult *handler; + IAsyncOperation_SpeechRecognitionCompilationResult *operation; +}; + +static DWORD WINAPI async_operation_block_thread(void *arg) +{ + struct async_operation_block_param *param = arg; + HRESULT hr; + + hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(param->operation, param->handler); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + return 0; +} + static void test_SpeechRecognizer(void) { static const WCHAR *speech_recognition_name = L"Windows.Media.SpeechRecognition.SpeechRecognizer"; @@ -828,16 +847,17 @@ static void test_SpeechRecognizer(void) ISpeechRecognizer2 *recognizer2 = NULL; IActivationFactory *factory = NULL; IInspectable *inspectable = NULL; - IClosable *closable = NULL; ILanguage *language = NULL; IAsyncInfo *info = NULL; struct completed_event_handler completed_handler; struct recognition_result_handler result_handler; + struct async_operation_block_param block_param; struct compilation_handler compilation_handler; SpeechRecognitionResultStatus result_status; EventRegistrationToken token = { .value = 0 }; AsyncStatus async_status; HSTRING hstr, hstr_lang; + HANDLE blocked_thread; HRESULT hr; UINT32 id; LONG ref; @@ -909,11 +929,16 @@ static void test_SpeechRecognizer(void) hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer2, (void **)&recognizer2); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
+ check_interface(inspectable, &IID_IClosable, TRUE); + hr = ISpeechRecognizer2_get_ContinuousRecognitionSession(recognizer2, &session); ok(hr == S_OK, "ISpeechRecognizer2_get_ContinuousRecognitionSession failed, hr %#lx.\n", hr); check_refcount(session, 2); check_refcount(inspectable, 3);
+ ref = ISpeechRecognizer2_Release(recognizer2); + ok(ref == 2, "Got unexpected ref %lu.\n", ref); + hr = ISpeechContinuousRecognitionSession_add_Completed(session, NULL, &token); ok(hr == E_INVALIDARG, "ISpeechContinuousRecognitionSession_add_ResultGenerated failed, hr %#lx.\n", hr);
@@ -938,6 +963,9 @@ static void test_SpeechRecognizer(void) hr = ISpeechContinuousRecognitionSession_remove_ResultGenerated(session, token); ok(hr == S_OK, "ISpeechContinuousRecognitionSession_remove_ResultGenerated failed, hr %#lx.\n", hr);
+ ref = ISpeechContinuousRecognitionSession_Release(session); + ok(ref == 1, "Got unexpected ref %lu.\n", ref); + hr = ISpeechRecognizer_get_Constraints(recognizer, &constraints); ok(hr == S_OK, "ISpeechContinuousRecognitionSession_get_Constraints failed, hr %#lx.\n", hr);
@@ -1064,22 +1092,62 @@ static void test_SpeechRecognizer(void)
ref = IAsyncInfo_Release(info); todo_wine ok(ref == 1, "Got unexpected ref %lu.\n", ref); - -skip_operation: ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation); - ok(!ref, "Got unexpected ref %lu.\n", ref); + todo_wine ok(!ref, "Got unexpected ref %lu.\n", ref);
- ref = ISpeechContinuousRecognitionSession_Release(session); - ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ref = ISpeechRecognizer_Release(recognizer); + todo_wine ok(ref == 1, "Got unexpected ref %lu.\n", ref);
- hr = IInspectable_QueryInterface(inspectable, &IID_IClosable, (void **)&closable); - ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ref = IInspectable_Release(inspectable); + todo_wine ok(!ref, "Got unexpected ref %lu.\n", ref);
- ref = IClosable_Release(closable); - ok(ref == 3, "Got unexpected ref %lu.\n", ref); + /* Test if AsyncInfo_Close waits for the handler to finish. */ + hr = RoActivateInstance(hstr, &inspectable); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- ref = ISpeechRecognizer2_Release(recognizer2); - ok(ref == 2, "Got unexpected ref %lu.\n", ref); + hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer, (void **)&recognizer); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + compilation_handler_create_static(&compilation_handler); + compilation_handler.event_block = CreateEventW(NULL, FALSE, FALSE, NULL); + compilation_handler.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL); + compilation_handler.thread_id = GetCurrentThreadId(); + + todo_wine ok(compilation_handler.event_finished != NULL, "Finished event wasn't created.\n"); + + hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation); + todo_wine ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr); + + block_param.handler = &compilation_handler.IAsyncHandler_Compilation_iface; + block_param.operation = operation; + blocked_thread = CreateThread(NULL, 0, async_operation_block_thread, &block_param, 0, NULL); + + todo_wine ok(!WaitForSingleObject(compilation_handler.event_finished, 5000), "Wait for event_finished failed.\n"); + + todo_wine ok(WaitForSingleObject(blocked_thread, 100) == WAIT_TIMEOUT, "Wait for block_thread didn't time out.\n"); + + todo_wine ok(compilation_handler.ref == 3, "Got unexpected ref %lu.\n", compilation_handler.ref); + todo_wine check_refcount(operation, 3); + + hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + hr = IAsyncInfo_Close(info); /* If IAsyncInfo_Close would wait for the handler to finish, the test would get stuck here. */ + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + + SetEvent(compilation_handler.event_block); + todo_wine ok(!WaitForSingleObject(blocked_thread, 1000), "Wait for block_thread failed.\n"); + + CloseHandle(blocked_thread); + CloseHandle(compilation_handler.event_block); + CloseHandle(compilation_handler.event_finished); + + ref = IAsyncInfo_Release(info); + todo_wine ok(ref == 1, "Got unexpected ref %lu.\n", ref); + +skip_operation: + ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation); + ok(!ref, "Got unexpected ref %lu.\n", ref);
ref = ISpeechRecognizer_Release(recognizer); ok(ref == 1, "Got unexpected ref %lu.\n", ref);
Signed-off-by: Rémi Bernon rbernon@codeweavers.com
On 4/22/22 15:41, Rémi Bernon wrote:
Signed-off-by: Rémi Bernon rbernon@codeweavers.com
(Though there's a trailing white space that needs stripping)
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/async.c | 138 ++++++++++++++++++++--- dlls/windows.media.speech/tests/speech.c | 105 +++++++++-------- 2 files changed, 177 insertions(+), 66 deletions(-)
diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c index 94d0b35d9c1..2a6824b640a 100644 --- a/dlls/windows.media.speech/async.c +++ b/dlls/windows.media.speech/async.c @@ -23,6 +23,9 @@
WINE_DEFAULT_DEBUG_CHANNEL(speech);
+#define Closed 4 +#define HANDLER_NOT_SET ((void *)~(ULONG_PTR)0) + /* * * IAsyncOperation<IInspectable*> @@ -35,6 +38,11 @@ struct async_operation IAsyncInfo IAsyncInfo_iface; const GUID *iid; LONG ref; + + IAsyncOperationCompletedHandler_IInspectable *handler; + + AsyncStatus status; + HRESULT hr; };
static inline struct async_operation *impl_from_IAsyncOperation_IInspectable(IAsyncOperation_IInspectable *iface) @@ -84,7 +92,14 @@ static ULONG WINAPI async_operation_Release( IAsyncOperation_IInspectable *iface TRACE("iface %p, ref %lu.\n", iface, ref);
if (!ref) + { + IAsyncInfo_Close(&impl->IAsyncInfo_iface); + + if (impl->handler && impl->handler != HANDLER_NOT_SET) + IAsyncOperationCompletedHandler_IInspectable_Release(impl->handler); + free(impl); + }
return ref; } @@ -110,21 +125,72 @@ static HRESULT WINAPI async_operation_GetTrustLevel( IAsyncOperation_IInspectabl static HRESULT WINAPI async_operation_put_Completed( IAsyncOperation_IInspectable *iface, IAsyncOperationCompletedHandler_IInspectable *handler ) { - FIXME("iface %p, handler %p stub!\n", iface, handler); - return E_NOTIMPL; + struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(iface); + HRESULT hr = S_OK; + + TRACE("iface %p, handler %p.\n", iface, handler); + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + else if (impl->handler != HANDLER_NOT_SET) + hr = E_ILLEGAL_DELEGATE_ASSIGNMENT; + /* + impl->handler can only be set once with async_operation_put_Completed, + so by default we set a non HANDLER_NOT_SET value, in this case handler. + */ + else if ((impl->handler = handler)) + { + IAsyncOperationCompletedHandler_IInspectable_AddRef(impl->handler); + + if (impl->status > Started) + { + IAsyncOperation_IInspectable *operation = &impl->IAsyncOperation_IInspectable_iface; + AsyncStatus status = impl->status; + impl->handler = NULL; /* Prevent concurrent invoke. */ + + IAsyncOperationCompletedHandler_IInspectable_Invoke(handler, operation, status); + IAsyncOperationCompletedHandler_IInspectable_Release(handler); + + return S_OK; + } + } + + return hr; }
static HRESULT WINAPI async_operation_get_Completed( IAsyncOperation_IInspectable *iface, IAsyncOperationCompletedHandler_IInspectable **handler ) { - FIXME("iface %p, handler %p stub!\n", iface, handler); - return E_NOTIMPL; + struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(iface); + HRESULT hr; + + FIXME("iface %p, handler %p semi stub!\n", iface, handler); + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + else + hr = S_OK; + + *handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL; + return hr; }
static HRESULT WINAPI async_operation_GetResults( IAsyncOperation_IInspectable *iface, IInspectable **results ) { - FIXME("iface %p, results %p stub!\n", iface, results); - return E_NOTIMPL; + /* NOTE: Despite the name, this function only returns one result! */ + struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(iface); + HRESULT hr; + + TRACE("iface %p, results %p.\n", iface, results); + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + else if (impl->status > Started) + hr = S_OK; + else + hr = E_UNEXPECTED; + + return hr; }
static const struct IAsyncOperation_IInspectableVtbl async_operation_vtbl = @@ -159,26 +225,56 @@ static HRESULT WINAPI async_operation_info_get_Id( IAsyncInfo *iface, UINT32 *id
static HRESULT WINAPI async_operation_info_get_Status( IAsyncInfo *iface, AsyncStatus *status ) { - FIXME("iface %p, status %p stub!\n", iface, status); - return E_NOTIMPL; + struct async_operation *impl = impl_from_IAsyncInfo(iface); + HRESULT hr; + + TRACE("iface %p, status %p.\n", iface, status); + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + else + hr = S_OK; + + *status = impl->status; + return hr; }
static HRESULT WINAPI async_operation_info_get_ErrorCode( IAsyncInfo *iface, HRESULT *error_code ) { - FIXME("iface %p, error_code %p stub!\n", iface, error_code); - return E_NOTIMPL; + struct async_operation *impl = impl_from_IAsyncInfo(iface); + TRACE("iface %p, error_code %p.\n", iface, error_code); + + *error_code = impl->hr; + return S_OK; }
static HRESULT WINAPI async_operation_info_Cancel( IAsyncInfo *iface ) { - FIXME("iface %p stub!\n", iface); - return E_NOTIMPL; + struct async_operation *impl = impl_from_IAsyncInfo(iface); + HRESULT hr; + + TRACE("iface %p.\n", iface); + hr = S_OK; + + if (impl->status == Closed) + hr = E_ILLEGAL_METHOD_CALL; + else if (impl->status == Started) + impl->status = Canceled; + + return hr; }
static HRESULT WINAPI async_operation_info_Close( IAsyncInfo *iface ) { - FIXME("iface %p stub!\n", iface); - return E_NOTIMPL; + struct async_operation *impl = impl_from_IAsyncInfo(iface); + + TRACE("iface %p.\n", iface); + + if (impl->status == Started) + return E_ILLEGAL_STATE_CHANGE; + + impl->status = Closed; + return S_OK; }
static const struct IAsyncInfoVtbl async_operation_info_vtbl = @@ -202,11 +298,14 @@ static const struct IAsyncInfoVtbl async_operation_info_vtbl = HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable **out ) { struct async_operation *impl; + HRESULT hr; + + *out = NULL;
if (!(impl = calloc(1, sizeof(*impl)))) { - *out = NULL; - return E_OUTOFMEMORY; + hr = E_OUTOFMEMORY; + goto error; }
impl->IAsyncOperation_IInspectable_iface.lpVtbl = &async_operation_vtbl; @@ -214,7 +313,14 @@ HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable ** impl->iid = iid; impl->ref = 1;
+ impl->handler = HANDLER_NOT_SET; + impl->status = Completed; + *out = &impl->IAsyncOperation_IInspectable_iface; TRACE("created %p\n", *out); return S_OK; + +error: + free(impl); + return hr; } diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index f1c0f991cec..8e2901a5511 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -981,44 +981,49 @@ static void test_SpeechRecognizer(void)
handler = (void*)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); - todo_wine ok(handler == NULL, "Handler had value %p.\n", handler); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(handler == NULL, "Handler had value %p.\n", handler);
if (FAILED(hr)) goto skip_operation;
compilation_result = (void*)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); todo_wine ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr); - todo_wine ok(compilation_result == (void*)0xdeadbeef, "Compilation result had value %p.\n", compilation_result); + ok(compilation_result == (void*)0xdeadbeef, "Compilation result had value %p.\n", compilation_result);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, &compilation_handler.IAsyncHandler_Compilation_iface); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- todo_wine ok(!WaitForSingleObject(compilation_handler.event_finished, 1000), "Wait for event_finished failed.\n"); + ok(!WaitForSingleObject(compilation_handler.event_finished, 1000), "Wait for event_finished failed.\n"); CloseHandle(compilation_handler.event_finished);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, NULL); - todo_wine ok(hr == E_ILLEGAL_DELEGATE_ASSIGNMENT, "Got unexpected hr %#lx.\n", hr); + ok(hr == E_ILLEGAL_DELEGATE_ASSIGNMENT, "Got unexpected hr %#lx.\n", hr);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
+ compilation_result = (void*)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); - todo_wine check_interface(compilation_result, &IID_IAgileObject, TRUE); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- hr = ISpeechRecognitionCompilationResult_get_Status(compilation_result, &result_status); - todo_wine ok(hr == S_OK, "ISpeechRecognitionCompilationResult_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(result_status == SpeechRecognitionResultStatus_Success, "Got unexpected status %#x.\n", result_status); + if (compilation_result != (void*)0xdeadbeef) + { + todo_wine check_interface(compilation_result, &IID_IAgileObject, TRUE);
- ref = ISpeechRecognitionCompilationResult_Release(compilation_result); - todo_wine ok(!ref , "Got unexpected ref %lu.\n", ref); + hr = ISpeechRecognitionCompilationResult_get_Status(compilation_result, &result_status); + todo_wine ok(hr == S_OK, "ISpeechRecognitionCompilationResult_get_Status failed, hr %#lx.\n", hr); + todo_wine ok(result_status == SpeechRecognitionResultStatus_Success, "Got unexpected status %#x.\n", result_status); + + ref = ISpeechRecognitionCompilationResult_Release(compilation_result); + todo_wine ok(!ref , "Got unexpected ref %lu.\n", ref); + }
hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); todo_wine ok(hr == E_UNEXPECTED, "Got unexpected hr %#lx.\n", hr);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
id = 0xdeadbeef; hr = IAsyncInfo_get_Id(info, &id); @@ -1027,36 +1032,36 @@ static void test_SpeechRecognizer(void)
async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(info, &async_status); - todo_wine ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(async_status == Completed, "Status was %#x.\n", async_status); + ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); + ok(async_status == Completed, "Status was %#x.\n", async_status);
hr = IAsyncInfo_Cancel(info); - todo_wine ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr); + ok(hr == S_OK, "IAsyncInfo_Cancel failed, hr %#lx.\n", hr);
async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(info, &async_status); - todo_wine ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(async_status == Completed, "Status was %#x.\n", async_status); + ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); + ok(async_status == Completed, "Status was %#x.\n", async_status);
hr = IAsyncInfo_Close(info); - todo_wine ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr); + ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr); hr = IAsyncInfo_Close(info); - todo_wine ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr); + ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr);
async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(info, &async_status); - todo_wine ok(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(async_status == AsyncStatus_Closed, "Status was %#x.\n", async_status); + ok(hr == E_ILLEGAL_METHOD_CALL, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); + ok(async_status == AsyncStatus_Closed, "Status was %#x.\n", async_status);
ref = IAsyncInfo_Release(info); - todo_wine ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ok(ref == 1, "Got unexpected ref %lu.\n", ref);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, NULL); - todo_wine ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr); + ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr);
handler = (void*)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_get_Completed(operation, &handler); - todo_wine ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr); + ok(hr == E_ILLEGAL_METHOD_CALL, "Got unexpected hr %#lx.\n", hr);
IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
@@ -1068,82 +1073,82 @@ static void test_SpeechRecognizer(void) ok(compilation_handler.event_finished != NULL, "Finished event wasn't created.\n");
hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation); - todo_wine ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr); - todo_wine check_interface(operation, &IID_IAgileObject, TRUE); + ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr); + check_interface(operation, &IID_IAgileObject, TRUE);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(info, &async_status); - todo_wine ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(async_status != AsyncStatus_Closed, "Status was %#x.\n", async_status); + ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); + ok(async_status != AsyncStatus_Closed, "Status was %#x.\n", async_status);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, &compilation_handler.IAsyncHandler_Compilation_iface); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- todo_wine ok(!WaitForSingleObject(compilation_handler.event_finished, 1000), "Wait for event_finished failed.\n"); + ok(!WaitForSingleObject(compilation_handler.event_finished, 1000), "Wait for event_finished failed.\n"); CloseHandle(compilation_handler.event_finished);
async_status = 0xdeadbeef; hr = IAsyncInfo_get_Status(info, &async_status); - todo_wine ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(async_status == Completed, "Status was %#x.\n", async_status); + ok(hr == S_OK, "IAsyncInfo_get_Status failed, hr %#lx.\n", hr); + ok(async_status == Completed, "Status was %#x.\n", async_status);
ref = IAsyncInfo_Release(info); - todo_wine ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ok(ref == 1, "Got unexpected ref %lu.\n", ref); ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation); - todo_wine ok(!ref, "Got unexpected ref %lu.\n", ref); + ok(!ref, "Got unexpected ref %lu.\n", ref);
ref = ISpeechRecognizer_Release(recognizer); - todo_wine ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ok(ref == 1, "Got unexpected ref %lu.\n", ref);
ref = IInspectable_Release(inspectable); - todo_wine ok(!ref, "Got unexpected ref %lu.\n", ref); + ok(!ref, "Got unexpected ref %lu.\n", ref);
/* Test if AsyncInfo_Close waits for the handler to finish. */ hr = RoActivateInstance(hstr, &inspectable); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = IInspectable_QueryInterface(inspectable, &IID_ISpeechRecognizer, (void **)&recognizer); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
compilation_handler_create_static(&compilation_handler); compilation_handler.event_block = CreateEventW(NULL, FALSE, FALSE, NULL); compilation_handler.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL); compilation_handler.thread_id = GetCurrentThreadId();
- todo_wine ok(compilation_handler.event_finished != NULL, "Finished event wasn't created.\n"); + ok(compilation_handler.event_finished != NULL, "Finished event wasn't created.\n");
hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation); - todo_wine ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr); + ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr);
block_param.handler = &compilation_handler.IAsyncHandler_Compilation_iface; block_param.operation = operation; blocked_thread = CreateThread(NULL, 0, async_operation_block_thread, &block_param, 0, NULL);
- todo_wine ok(!WaitForSingleObject(compilation_handler.event_finished, 5000), "Wait for event_finished failed.\n"); + ok(!WaitForSingleObject(compilation_handler.event_finished, 5000), "Wait for event_finished failed.\n");
- todo_wine ok(WaitForSingleObject(blocked_thread, 100) == WAIT_TIMEOUT, "Wait for block_thread didn't time out.\n"); + ok(WaitForSingleObject(blocked_thread, 100) == WAIT_TIMEOUT, "Wait for block_thread didn't time out.\n");
todo_wine ok(compilation_handler.ref == 3, "Got unexpected ref %lu.\n", compilation_handler.ref); todo_wine check_refcount(operation, 3);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
hr = IAsyncInfo_Close(info); /* If IAsyncInfo_Close would wait for the handler to finish, the test would get stuck here. */ - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
SetEvent(compilation_handler.event_block); - todo_wine ok(!WaitForSingleObject(blocked_thread, 1000), "Wait for block_thread failed.\n"); + ok(!WaitForSingleObject(blocked_thread, 1000), "Wait for block_thread failed.\n");
CloseHandle(blocked_thread); CloseHandle(compilation_handler.event_block); CloseHandle(compilation_handler.event_finished);
ref = IAsyncInfo_Release(info); - todo_wine ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ok(ref == 1, "Got unexpected ref %lu.\n", ref);
skip_operation: ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
Signed-off-by: Rémi Bernon rbernon@codeweavers.com
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/async.c | 95 +++++++++++++++++++++++- dlls/windows.media.speech/private.h | 4 +- dlls/windows.media.speech/recognizer.c | 7 +- dlls/windows.media.speech/tests/speech.c | 8 +- 4 files changed, 105 insertions(+), 9 deletions(-)
diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c index 2a6824b640a..1e6dd336c84 100644 --- a/dlls/windows.media.speech/async.c +++ b/dlls/windows.media.speech/async.c @@ -40,7 +40,13 @@ struct async_operation LONG ref;
IAsyncOperationCompletedHandler_IInspectable *handler; + IInspectable *result;
+ async_operation_callback callback; + TP_WORK *async_run_work; + IInspectable *invoker; + + CRITICAL_SECTION cs; AsyncStatus status; HRESULT hr; }; @@ -95,9 +101,14 @@ static ULONG WINAPI async_operation_Release( IAsyncOperation_IInspectable *iface { IAsyncInfo_Close(&impl->IAsyncInfo_iface);
+ if (impl->invoker) + IInspectable_Release(impl->invoker); if (impl->handler && impl->handler != HANDLER_NOT_SET) IAsyncOperationCompletedHandler_IInspectable_Release(impl->handler); + if (impl->result) + IInspectable_Release(impl->result);
+ DeleteCriticalSection(&impl->cs); free(impl); }
@@ -130,6 +141,7 @@ static HRESULT WINAPI async_operation_put_Completed( IAsyncOperation_IInspectabl
TRACE("iface %p, handler %p.\n", iface, handler);
+ EnterCriticalSection(&impl->cs); if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; else if (impl->handler != HANDLER_NOT_SET) @@ -147,6 +159,7 @@ static HRESULT WINAPI async_operation_put_Completed( IAsyncOperation_IInspectabl IAsyncOperation_IInspectable *operation = &impl->IAsyncOperation_IInspectable_iface; AsyncStatus status = impl->status; impl->handler = NULL; /* Prevent concurrent invoke. */ + LeaveCriticalSection(&impl->cs);
IAsyncOperationCompletedHandler_IInspectable_Invoke(handler, operation, status); IAsyncOperationCompletedHandler_IInspectable_Release(handler); @@ -154,6 +167,7 @@ static HRESULT WINAPI async_operation_put_Completed( IAsyncOperation_IInspectabl return S_OK; } } + LeaveCriticalSection(&impl->cs);
return hr; } @@ -166,12 +180,15 @@ static HRESULT WINAPI async_operation_get_Completed( IAsyncOperation_IInspectabl
FIXME("iface %p, handler %p semi stub!\n", iface, handler);
+ EnterCriticalSection(&impl->cs); if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; else hr = S_OK;
*handler = (impl->handler != HANDLER_NOT_SET) ? impl->handler : NULL; + LeaveCriticalSection(&impl->cs); + return hr; }
@@ -183,12 +200,18 @@ static HRESULT WINAPI async_operation_GetResults( IAsyncOperation_IInspectable *
TRACE("iface %p, results %p.\n", iface, results);
+ EnterCriticalSection(&impl->cs); if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; - else if (impl->status > Started) + else if (impl->status > Started && impl->result) + { + *results = impl->result; + impl->result = NULL; /* NOTE: AsyncOperation gives up it's reference to result here! */ hr = S_OK; + } else hr = E_UNEXPECTED; + LeaveCriticalSection(&impl->cs);
return hr; } @@ -230,12 +253,15 @@ static HRESULT WINAPI async_operation_info_get_Status( IAsyncInfo *iface, AsyncS
TRACE("iface %p, status %p.\n", iface, status);
+ EnterCriticalSection(&impl->cs); if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; else hr = S_OK;
*status = impl->status; + LeaveCriticalSection(&impl->cs); + return hr; }
@@ -244,7 +270,10 @@ static HRESULT WINAPI async_operation_info_get_ErrorCode( IAsyncInfo *iface, HRE struct async_operation *impl = impl_from_IAsyncInfo(iface); TRACE("iface %p, error_code %p.\n", iface, error_code);
+ EnterCriticalSection(&impl->cs); *error_code = impl->hr; + LeaveCriticalSection(&impl->cs); + return S_OK; }
@@ -256,10 +285,12 @@ static HRESULT WINAPI async_operation_info_Cancel( IAsyncInfo *iface ) TRACE("iface %p.\n", iface); hr = S_OK;
+ EnterCriticalSection(&impl->cs); if (impl->status == Closed) hr = E_ILLEGAL_METHOD_CALL; else if (impl->status == Started) impl->status = Canceled; + LeaveCriticalSection(&impl->cs);
return hr; } @@ -270,10 +301,22 @@ static HRESULT WINAPI async_operation_info_Close( IAsyncInfo *iface )
TRACE("iface %p.\n", iface);
+ EnterCriticalSection(&impl->cs); if (impl->status == Started) + { + LeaveCriticalSection(&impl->cs); return E_ILLEGAL_STATE_CHANGE; + } + + if (impl->async_run_work) + { + CloseThreadpoolWork(impl->async_run_work); + impl->async_run_work = NULL; + }
impl->status = Closed; + LeaveCriticalSection(&impl->cs); + return S_OK; }
@@ -295,7 +338,38 @@ static const struct IAsyncInfoVtbl async_operation_info_vtbl = async_operation_info_Close };
-HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable **out ) +static void CALLBACK async_run_cb(TP_CALLBACK_INSTANCE *instance, void *data, TP_WORK *work) +{ + IAsyncOperation_IInspectable *operation = data; + IInspectable *result = NULL; + struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(operation); + HRESULT hr; + + hr = impl->callback(impl->invoker, &result); + + EnterCriticalSection(&impl->cs); + if (impl->status < Closed) + impl->status = FAILED(hr) ? Error : Completed; + + impl->result = result; + impl->hr = hr; + + if (impl->handler != NULL && impl->handler != HANDLER_NOT_SET) + { + IAsyncOperationCompletedHandler_IInspectable *handler = impl->handler; + AsyncStatus status = impl->status; + impl->handler = NULL; /* Prevent concurrent invoke. */ + LeaveCriticalSection(&impl->cs); + + IAsyncOperationCompletedHandler_IInspectable_Invoke(handler, operation, status); + IAsyncOperationCompletedHandler_IInspectable_Release(handler); + } + else LeaveCriticalSection(&impl->cs); + + IAsyncOperation_IInspectable_Release(operation); +} + +HRESULT async_operation_create( const GUID *iid, IInspectable *invoker, async_operation_callback callback, IAsyncOperation_IInspectable **out ) { struct async_operation *impl; HRESULT hr; @@ -314,7 +388,22 @@ HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable ** impl->ref = 1;
impl->handler = HANDLER_NOT_SET; - impl->status = Completed; + impl->callback = callback; + impl->status = Started; + + IAsyncOperation_IInspectable_AddRef(&impl->IAsyncOperation_IInspectable_iface); /* AddRef to keep the obj alive in the callback. */ + if (!(impl->async_run_work = CreateThreadpoolWork(async_run_cb, &impl->IAsyncOperation_IInspectable_iface, NULL))) + { + hr = HRESULT_FROM_WIN32(GetLastError()); + goto error; + } + + if (invoker) IInspectable_AddRef((impl->invoker = invoker)); + + InitializeCriticalSection(&impl->cs); + impl->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": async_operation.cs"); + + SubmitThreadpoolWork(impl->async_run_work);
*out = &impl->IAsyncOperation_IInspectable_iface; TRACE("created %p\n", *out); diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h index 1cf61c51f1e..4b55a5cbfa7 100644 --- a/dlls/windows.media.speech/private.h +++ b/dlls/windows.media.speech/private.h @@ -69,7 +69,9 @@ struct vector_iids const GUID *view; };
-HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable **out ); +typedef HRESULT (WINAPI *async_operation_callback)( IInspectable *invoker, IInspectable **result ); + +HRESULT async_operation_create( const GUID *iid, IInspectable *invoker, async_operation_callback callback, IAsyncOperation_IInspectable **out );
HRESULT typed_event_handlers_append( struct list *list, ITypedEventHandler_IInspectable_IInspectable *handler, EventRegistrationToken *token ); HRESULT typed_event_handlers_remove( struct list *list, EventRegistrationToken *token ); diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index b16ecb24641..9802a4ae5da 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -348,12 +348,17 @@ static HRESULT WINAPI recognizer_get_UIOptions( ISpeechRecognizer *iface, ISpeec return E_NOTIMPL; }
+static HRESULT WINAPI compile_callback( IInspectable *invoker, IInspectable **result ) +{ + return S_OK; +} + static HRESULT WINAPI recognizer_CompileConstraintsAsync( ISpeechRecognizer *iface, IAsyncOperation_SpeechRecognitionCompilationResult **operation ) { IAsyncOperation_IInspectable **value = (IAsyncOperation_IInspectable **)operation; FIXME("iface %p, operation %p semi-stub!\n", iface, operation); - return async_operation_create(&IID_IAsyncOperation_SpeechRecognitionCompilationResult, value); + return async_operation_create(&IID_IAsyncOperation_SpeechRecognitionCompilationResult, NULL, compile_callback, value); }
static HRESULT WINAPI recognizer_RecognizeAsync( ISpeechRecognizer *iface, diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 8e2901a5511..22f35880706 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -1005,7 +1005,7 @@ static void test_SpeechRecognizer(void)
compilation_result = (void*)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); - ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
if (compilation_result != (void*)0xdeadbeef) { @@ -1020,7 +1020,7 @@ static void test_SpeechRecognizer(void) }
hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); - todo_wine ok(hr == E_UNEXPECTED, "Got unexpected hr %#lx.\n", hr); + ok(hr == E_UNEXPECTED, "Got unexpected hr %#lx.\n", hr);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); @@ -1096,9 +1096,9 @@ static void test_SpeechRecognizer(void) ok(async_status == Completed, "Status was %#x.\n", async_status);
ref = IAsyncInfo_Release(info); - ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ok(ref >= 1, "Got unexpected ref %lu.\n", ref); ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation); - ok(!ref, "Got unexpected ref %lu.\n", ref); + ok(ref >= 0, "Got unexpected ref %lu.\n", ref);
ref = ISpeechRecognizer_Release(recognizer); ok(ref == 1, "Got unexpected ref %lu.\n", ref);
Signed-off-by: Rémi Bernon rbernon@codeweavers.com ---
@@ -1096,9 +1096,9 @@ static void test_SpeechRecognizer(void) ok(async_status == Completed, "Status was %#x.\n", async_status);
ref = IAsyncInfo_Release(info);
ok(ref == 1, "Got unexpected ref %lu.\n", ref);
ok(ref >= 1, "Got unexpected ref %lu.\n", ref); ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
ok(!ref, "Got unexpected ref %lu.\n", ref);
ok(ref >= 0, "Got unexpected ref %lu.\n", ref);
Though I think this check is then useless.
Not, if ref is 0 on the second last check. :3
Rémi Bernon rbernon@codeweavers.com schrieb am Fr., 22. Apr. 2022, 15:45:
Signed-off-by: Rémi Bernon rbernon@codeweavers.com
@@ -1096,9 +1096,9 @@ static void test_SpeechRecognizer(void) ok(async_status == Completed, "Status was %#x.\n",
async_status);
ref = IAsyncInfo_Release(info);
ok(ref == 1, "Got unexpected ref %lu.\n", ref);
ok(ref >= 1, "Got unexpected ref %lu.\n", ref); ref =
IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
ok(!ref, "Got unexpected ref %lu.\n", ref);
ok(ref >= 0, "Got unexpected ref %lu.\n", ref);
Though I think this check is then useless.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/recognizer.c | 124 ++++++++++++++++++++++- dlls/windows.media.speech/tests/speech.c | 17 ++-- 2 files changed, 130 insertions(+), 11 deletions(-)
diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c index 9802a4ae5da..39813ef5607 100644 --- a/dlls/windows.media.speech/recognizer.c +++ b/dlls/windows.media.speech/recognizer.c @@ -23,6 +23,128 @@
WINE_DEFAULT_DEBUG_CHANNEL(speech);
+/* + * + * ISpeechRecognitionCompilationResult + * + */ + +struct compilation_result +{ + ISpeechRecognitionCompilationResult ISpeechRecognitionCompilationResult_iface; + LONG ref; + + SpeechRecognitionResultStatus status; +}; + +static inline struct compilation_result *impl_from_ISpeechRecognitionCompilationResult( ISpeechRecognitionCompilationResult *iface ) +{ + return CONTAINING_RECORD(iface, struct compilation_result, ISpeechRecognitionCompilationResult_iface); +} + +static HRESULT WINAPI compilation_result_QueryInterface( ISpeechRecognitionCompilationResult *iface, REFIID iid, void **out ) +{ + struct compilation_result *impl = impl_from_ISpeechRecognitionCompilationResult(iface); + + TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out); + + if (IsEqualGUID(iid, &IID_IUnknown) || + IsEqualGUID(iid, &IID_IInspectable) || + IsEqualGUID(iid, &IID_IAgileObject) || + IsEqualGUID(iid, &IID_ISpeechRecognitionCompilationResult)) + { + IInspectable_AddRef((*out = &impl->ISpeechRecognitionCompilationResult_iface)); + return S_OK; + } + + WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid)); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI compilation_result_AddRef( ISpeechRecognitionCompilationResult *iface ) +{ + struct compilation_result *impl = impl_from_ISpeechRecognitionCompilationResult(iface); + ULONG ref = InterlockedIncrement(&impl->ref); + TRACE("iface %p, ref %lu.\n", iface, ref); + return ref; +} + +static ULONG WINAPI compilation_result_Release( ISpeechRecognitionCompilationResult *iface ) +{ + struct compilation_result *impl = impl_from_ISpeechRecognitionCompilationResult(iface); + + ULONG ref = InterlockedDecrement(&impl->ref); + TRACE("iface %p, ref %lu.\n", iface, ref); + + if (!ref) + free(impl); + + return ref; +} + +static HRESULT WINAPI compilation_result_GetIids( ISpeechRecognitionCompilationResult *iface, ULONG *iid_count, IID **iids ) +{ + FIXME("iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids); + return E_NOTIMPL; +} + +static HRESULT WINAPI compilation_result_GetRuntimeClassName( ISpeechRecognitionCompilationResult *iface, HSTRING *class_name ) +{ + FIXME("iface %p, class_name %p stub!\n", iface, class_name); + return E_NOTIMPL; +} + +static HRESULT WINAPI compilation_result_GetTrustLevel( ISpeechRecognitionCompilationResult *iface, TrustLevel *trust_level ) +{ + FIXME("iface %p, trust_level %p stub!\n", iface, trust_level); + return E_NOTIMPL; +} + +static HRESULT WINAPI compilation_result_get_Status( ISpeechRecognitionCompilationResult *iface, SpeechRecognitionResultStatus *value ) +{ + struct compilation_result *impl = impl_from_ISpeechRecognitionCompilationResult(iface); + TRACE("iface %p, value %p.\n", iface, value); + *value = impl->status; + return S_OK; +} + +static const struct ISpeechRecognitionCompilationResultVtbl compilation_result_vtbl = +{ + /* IUnknown methods */ + compilation_result_QueryInterface, + compilation_result_AddRef, + compilation_result_Release, + /* IInspectable methods */ + compilation_result_GetIids, + compilation_result_GetRuntimeClassName, + compilation_result_GetTrustLevel, + /* ISpeechRecognitionCompilationResult methods */ + compilation_result_get_Status +}; + + +static HRESULT WINAPI compilation_result_create( SpeechRecognitionResultStatus status, ISpeechRecognitionCompilationResult **out ) +{ + struct compilation_result *impl; + + TRACE("out %p.\n", out); + + if (!(impl = calloc(1, sizeof(*impl)))) + { + *out = NULL; + return E_OUTOFMEMORY; + } + + impl->ISpeechRecognitionCompilationResult_iface.lpVtbl = &compilation_result_vtbl; + impl->ref = 1; + impl->status = status; + + *out = &impl->ISpeechRecognitionCompilationResult_iface; + TRACE("created %p\n", *out); + return S_OK; +} + /* * * SpeechContinuousRecognitionSession @@ -350,7 +472,7 @@ static HRESULT WINAPI recognizer_get_UIOptions( ISpeechRecognizer *iface, ISpeec
static HRESULT WINAPI compile_callback( IInspectable *invoker, IInspectable **result ) { - return S_OK; + return compilation_result_create(SpeechRecognitionResultStatus_Success, (ISpeechRecognitionCompilationResult **) result); }
static HRESULT WINAPI recognizer_CompileConstraintsAsync( ISpeechRecognizer *iface, diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 22f35880706..4c18764e9f0 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -1005,19 +1005,16 @@ static void test_SpeechRecognizer(void)
compilation_result = (void*)0xdeadbeef; hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); - todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
- if (compilation_result != (void*)0xdeadbeef) - { - todo_wine check_interface(compilation_result, &IID_IAgileObject, TRUE); + check_interface(compilation_result, &IID_IAgileObject, TRUE);
- hr = ISpeechRecognitionCompilationResult_get_Status(compilation_result, &result_status); - todo_wine ok(hr == S_OK, "ISpeechRecognitionCompilationResult_get_Status failed, hr %#lx.\n", hr); - todo_wine ok(result_status == SpeechRecognitionResultStatus_Success, "Got unexpected status %#x.\n", result_status); + hr = ISpeechRecognitionCompilationResult_get_Status(compilation_result, &result_status); + ok(hr == S_OK, "ISpeechRecognitionCompilationResult_get_Status failed, hr %#lx.\n", hr); + ok(result_status == SpeechRecognitionResultStatus_Success, "Got unexpected status %#x.\n", result_status);
- ref = ISpeechRecognitionCompilationResult_Release(compilation_result); - todo_wine ok(!ref , "Got unexpected ref %lu.\n", ref); - } + ref = ISpeechRecognitionCompilationResult_Release(compilation_result); + ok(!ref , "Got unexpected ref %lu.\n", ref);
hr = IAsyncOperation_SpeechRecognitionCompilationResult_GetResults(operation, &compilation_result); ok(hr == E_UNEXPECTED, "Got unexpected hr %#lx.\n", hr);
Signed-off-by: Rémi Bernon rbernon@codeweavers.com