From: Bernhard Kölbl besentv@gmail.com
By waiting for an additional event, instead of the return of a thread.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- dlls/windows.media.speech/tests/speech.c | 41 +++++++++++++----------- 1 file changed, 22 insertions(+), 19 deletions(-)
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 9ef49b160cd..6803a43ea9c 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -240,6 +240,7 @@ struct compilation_handler LONG ref;
HANDLE event_block; + HANDLE event_unblock; HANDLE event_finished; DWORD thread_id; }; @@ -294,6 +295,8 @@ HRESULT WINAPI compilation_handler_Invoke( IAsyncHandler_Compilation *iface, if (impl->event_finished) SetEvent(impl->event_finished); /* Block handler until event is set. */ if (impl->event_block) WaitForSingleObject(impl->event_block, INFINITE); + /* Signal unblock of the handler. */ + if (impl->event_unblock) SetEvent(impl->event_unblock);
return S_OK; } @@ -815,15 +818,15 @@ static void test_VoiceInformation(void) RoUninitialize(); }
-struct async_operation_block_param +struct op_put_completed_thread_param { IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult *handler; IAsyncOperation_SpeechRecognitionCompilationResult *operation; };
-static DWORD WINAPI async_operation_block_thread(void *arg) +static DWORD WINAPI put_completed_thread(void *arg) { - struct async_operation_block_param *param = arg; + struct op_put_completed_thread_param *param = arg; HRESULT hr;
hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(param->operation, param->handler); @@ -849,15 +852,15 @@ static void test_SpeechRecognizer(void) IInspectable *inspectable = NULL; ILanguage *language = NULL; IAsyncInfo *info = NULL; + struct op_put_completed_thread_param put_completed_param; 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; + HANDLE put_thread; HRESULT hr, error_code; UINT32 id; LONG ref; @@ -1123,23 +1126,22 @@ static void test_SpeechRecognizer(void) 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.event_unblock = CreateEventW(NULL, FALSE, FALSE, NULL); compilation_handler.thread_id = GetCurrentThreadId();
- ok(compilation_handler.event_finished != NULL, "Finished event wasn't created.\n"); + ok(!!compilation_handler.event_finished, "event_block wasn't created.\n"); + ok(!!compilation_handler.event_finished, "event_finished wasn't created.\n"); + ok(!!compilation_handler.event_finished, "event_unblock wasn't created.\n");
hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation); 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); + put_completed_param.handler = &compilation_handler.IAsyncHandler_Compilation_iface; + put_completed_param.operation = operation; + put_thread = CreateThread(NULL, 0, put_completed_thread, &put_completed_param, 0, NULL);
ok(!WaitForSingleObject(compilation_handler.event_finished, 5000), "Wait for event_finished failed.\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); + ok(WaitForSingleObject(compilation_handler.event_unblock, 100) == WAIT_TIMEOUT, "Wait for event_unblock didn't time out.\n");
hr = IAsyncOperation_SpeechRecognitionCompilationResult_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info); ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); @@ -1148,18 +1150,19 @@ static void test_SpeechRecognizer(void) ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
SetEvent(compilation_handler.event_block); - ok(!WaitForSingleObject(blocked_thread, 1000), "Wait for block_thread failed.\n"); + ok(!WaitForSingleObject(compilation_handler.event_unblock, 1000), "Wait for event_unblock failed.\n");
- CloseHandle(blocked_thread); + CloseHandle(put_thread); CloseHandle(compilation_handler.event_block); CloseHandle(compilation_handler.event_finished); - + CloseHandle(compilation_handler.event_unblock); + ref = IAsyncInfo_Release(info); - ok(ref == 1, "Got unexpected ref %lu.\n", ref); + ok(ref == 1 || broken(ref >= 1), "Got unexpected ref %lu.\n", ref);
skip_operation: ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation); - ok(!ref, "Got unexpected ref %lu.\n", ref); + ok(!ref || broken(ref >= 0), "Got unexpected ref %lu.\n", ref);
ref = ISpeechRecognizer_Release(recognizer); ok(ref == 1, "Got unexpected ref %lu.\n", ref);