[PATCH 2/6] windows.media.speech: Add IAsyncOperation<Inspectable*> stub.
Bernhard Kölbl
besentv at gmail.com
Thu Mar 31 11:17:57 CDT 2022
Together with some tests and return an instance of it in
ISpeechRecognizer_CompileConstraintsAsync.
Signed-off-by: Bernhard Kölbl <besentv at gmail.com>
---
dlls/windows.media.speech/Makefile.in | 1 +
dlls/windows.media.speech/async.c | 156 ++++++++++++++++++++++
dlls/windows.media.speech/private.h | 2 +
dlls/windows.media.speech/recognizer.c | 7 +-
dlls/windows.media.speech/tests/speech.c | 161 +++++++++++++++++++++++
include/windows.foundation.idl | 2 +
6 files changed, 326 insertions(+), 3 deletions(-)
create mode 100644 dlls/windows.media.speech/async.c
diff --git a/dlls/windows.media.speech/Makefile.in b/dlls/windows.media.speech/Makefile.in
index 5a8291ba6f0..10903cb1d7b 100644
--- a/dlls/windows.media.speech/Makefile.in
+++ b/dlls/windows.media.speech/Makefile.in
@@ -2,6 +2,7 @@ MODULE = windows.media.speech.dll
IMPORTS = combase uuid
C_SRCS = \
+ async.c \
event_handlers.c \
listconstraint.c \
main.c \
diff --git a/dlls/windows.media.speech/async.c b/dlls/windows.media.speech/async.c
new file mode 100644
index 00000000000..9905a6d75ab
--- /dev/null
+++ b/dlls/windows.media.speech/async.c
@@ -0,0 +1,156 @@
+/* WinRT Windows.Media.Speech implementation
+ *
+ * Copyright 2022 Bernhard Kölbl for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "private.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(speech);
+
+/*
+ *
+ * IAsyncOperation<IInspectable*>
+ *
+ */
+
+struct async_operation
+{
+ IAsyncOperation_IInspectable IAsyncOperation_IInspectable_iface;
+ const GUID *iid;
+ LONG ref;
+};
+
+static inline struct async_operation *impl_from_IAsyncOperation_IInspectable(IAsyncOperation_IInspectable *iface)
+{
+ return CONTAINING_RECORD(iface, struct async_operation, IAsyncOperation_IInspectable_iface);
+}
+
+static HRESULT WINAPI async_operation_QueryInterface( IAsyncOperation_IInspectable *iface, REFIID iid, void **out )
+{
+ struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(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, impl->iid))
+ {
+ IInspectable_AddRef((*out = &impl->IAsyncOperation_IInspectable_iface));
+ return S_OK;
+ }
+
+ WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
+ *out = NULL;
+ return E_NOINTERFACE;
+}
+
+static ULONG WINAPI async_operation_AddRef( IAsyncOperation_IInspectable *iface )
+{
+ struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(iface);
+ ULONG ref = InterlockedIncrement(&impl->ref);
+ TRACE("iface %p, ref %lu.\n", iface, ref);
+ return ref;
+}
+
+static ULONG WINAPI async_operation_Release( IAsyncOperation_IInspectable *iface )
+{
+ struct async_operation *impl = impl_from_IAsyncOperation_IInspectable(iface);
+
+ ULONG ref = InterlockedDecrement(&impl->ref);
+ TRACE("iface %p, ref %lu.\n", iface, ref);
+
+ if (!ref)
+ free(impl);
+
+ return ref;
+}
+
+static HRESULT WINAPI async_operation_GetIids( IAsyncOperation_IInspectable *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 async_operation_GetRuntimeClassName( IAsyncOperation_IInspectable *iface, HSTRING *class_name )
+{
+ FIXME("iface %p, class_name %p stub!\n", iface, class_name);
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI async_operation_GetTrustLevel( IAsyncOperation_IInspectable *iface, TrustLevel *trust_level )
+{
+ FIXME("iface %p, trust_level %p stub!\n", iface, trust_level);
+ return E_NOTIMPL;
+}
+
+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;
+}
+
+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;
+}
+
+static HRESULT WINAPI async_operation_GetResults( IAsyncOperation_IInspectable *iface, IInspectable ***results )
+{
+ FIXME("iface %p, results %p stub!\n", iface, results);
+ return E_NOTIMPL;
+}
+
+static const struct IAsyncOperation_IInspectableVtbl async_operation_vtbl =
+{
+ /* IUnknown methods */
+ async_operation_QueryInterface,
+ async_operation_AddRef,
+ async_operation_Release,
+ /* IInspectable methods */
+ async_operation_GetIids,
+ async_operation_GetRuntimeClassName,
+ async_operation_GetTrustLevel,
+ /* IAsyncOperation<IInspectable*> */
+ async_operation_put_Completed,
+ async_operation_get_Completed,
+ async_operation_GetResults
+};
+
+HRESULT async_operation_create( const GUID *iid, IAsyncOperation_IInspectable **out )
+{
+ struct async_operation *impl;
+
+ if (!(impl = calloc(1, sizeof(*impl))))
+ {
+ *out = NULL;
+ return E_OUTOFMEMORY;
+ }
+
+ impl->IAsyncOperation_IInspectable_iface.lpVtbl = &async_operation_vtbl;
+ impl->iid = iid;
+ impl->ref = 1;
+
+ *out = &impl->IAsyncOperation_IInspectable_iface;
+ TRACE("created %p\n", *out);
+ return S_OK;
+}
diff --git a/dlls/windows.media.speech/private.h b/dlls/windows.media.speech/private.h
index a5177ddd538..1cf61c51f1e 100644
--- a/dlls/windows.media.speech/private.h
+++ b/dlls/windows.media.speech/private.h
@@ -69,6 +69,8 @@ struct vector_iids
const GUID *view;
};
+HRESULT async_operation_create( const GUID *iid, 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 );
HRESULT typed_event_handlers_notify( struct list *list, IInspectable *sender, IInspectable *args );
diff --git a/dlls/windows.media.speech/recognizer.c b/dlls/windows.media.speech/recognizer.c
index 36836f83a98..b16ecb24641 100644
--- a/dlls/windows.media.speech/recognizer.c
+++ b/dlls/windows.media.speech/recognizer.c
@@ -124,7 +124,7 @@ static HRESULT WINAPI session_set_AutoStopSilenceTimeout( ISpeechContinuousRecog
static HRESULT WINAPI session_StartAsync( ISpeechContinuousRecognitionSession *iface, IAsyncAction **action )
{
- FIXME("iface %p, action %p semi stub!\n", iface, action);
+ FIXME("iface %p, action %p stub!\n", iface, action);
return E_NOTIMPL;
}
@@ -351,8 +351,9 @@ static HRESULT WINAPI recognizer_get_UIOptions( ISpeechRecognizer *iface, ISpeec
static HRESULT WINAPI recognizer_CompileConstraintsAsync( ISpeechRecognizer *iface,
IAsyncOperation_SpeechRecognitionCompilationResult **operation )
{
- FIXME("iface %p, operation %p stub!\n", iface, operation);
- return E_NOTIMPL;
+ IAsyncOperation_IInspectable **value = (IAsyncOperation_IInspectable **)operation;
+ FIXME("iface %p, operation %p semi-stub!\n", iface, operation);
+ return async_operation_create(&IID_IAsyncOperation_SpeechRecognitionCompilationResult, 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 8093c4b95b8..542d6fcf8d0 100644
--- a/dlls/windows.media.speech/tests/speech.c
+++ b/dlls/windows.media.speech/tests/speech.c
@@ -52,6 +52,12 @@
#define impl_from_IHandler_RecognitionCompleted impl_from_ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionCompletedEventArgs
#define IHandler_RecognitionCompleted_iface ITypedEventHandler_SpeechContinuousRecognitionSession_SpeechContinuousRecognitionCompletedEventArgs_iface
+#define IAsyncHandler_Compilation IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult
+#define IAsyncHandler_CompilationVtbl IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResultVtbl
+#define IID_IAsyncHandler_Compilation IID_IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult
+#define impl_from_IAsyncHandler_Compilation impl_from_IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult
+#define IAsyncHandler_Compilation_iface IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult_iface
+
HRESULT WINAPI (*pDllGetActivationFactory)(HSTRING, IActivationFactory **);
static BOOL is_win10_1507 = FALSE;
@@ -226,6 +232,83 @@ static HRESULT WINAPI recognition_result_handler_create_static( struct recogniti
return S_OK;
}
+struct compilation_handler
+{
+ IAsyncHandler_Compilation IAsyncHandler_Compilation_iface;
+ LONG ref;
+
+ HANDLE event_finished;
+ DWORD thread_id;
+};
+
+static inline struct compilation_handler *impl_from_IAsyncHandler_Compilation( IAsyncHandler_Compilation *iface )
+{
+ return CONTAINING_RECORD(iface, struct compilation_handler, IAsyncHandler_Compilation_iface);
+}
+
+HRESULT WINAPI compilation_handler_QueryInterface( IAsyncHandler_Compilation *iface,
+ REFIID iid,
+ void **out )
+{
+ if (IsEqualGUID(iid, &IID_IUnknown) ||
+ IsEqualGUID(iid, &IID_IAgileObject) ||
+ IsEqualGUID(iid, &IID_IAsyncHandler_Compilation))
+ {
+ IUnknown_AddRef(iface);
+ *out = iface;
+ return S_OK;
+ }
+
+ trace("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
+ *out = NULL;
+ return E_NOINTERFACE;
+}
+
+ULONG WINAPI compilation_handler_AddRef( IAsyncHandler_Compilation *iface )
+{
+ struct compilation_handler *impl = impl_from_IAsyncHandler_Compilation(iface);
+ ULONG ref = InterlockedIncrement(&impl->ref);
+ return ref;
+}
+
+ULONG WINAPI compilation_handler_Release( IAsyncHandler_Compilation *iface )
+{
+ struct compilation_handler *impl = impl_from_IAsyncHandler_Compilation(iface);
+ ULONG ref = InterlockedDecrement(&impl->ref);
+ return ref;
+}
+
+HRESULT WINAPI compilation_handler_Invoke( IAsyncHandler_Compilation *iface,
+ IAsyncOperation_SpeechRecognitionCompilationResult *info,
+ AsyncStatus status )
+{
+ struct compilation_handler *impl = impl_from_IAsyncHandler_Compilation(iface);
+ DWORD id = GetCurrentThreadId();
+ trace("iface %p, info %p, status %d.\n", iface, info, status);
+ ok(impl->thread_id == id, "thread id %lu not matching %lu.\n", impl->thread_id, id);
+ if (impl->event_finished) SetEvent(impl->event_finished);
+ return S_OK;
+}
+
+static const struct IAsyncHandler_CompilationVtbl compilation_handler_vtbl =
+{
+ /* IUnknown methods */
+ compilation_handler_QueryInterface,
+ compilation_handler_AddRef,
+ compilation_handler_Release,
+ /* IAsyncOperationCompletedHandler<SpeechRecognitionCompilationResult* > methods */
+ compilation_handler_Invoke
+};
+
+
+static HRESULT WINAPI compilation_handler_create_static( struct compilation_handler *impl )
+{
+ impl->IAsyncHandler_Compilation_iface.lpVtbl = &compilation_handler_vtbl;
+ impl->ref = 1;
+
+ return S_OK;
+}
+
struct iterator_hstring
{
IIterator_HSTRING IIterator_HSTRING_iface;
@@ -729,6 +812,8 @@ static void test_VoiceInformation(void)
static void test_SpeechRecognizer(void)
{
static const WCHAR *speech_recognition_name = L"Windows.Media.SpeechRecognition.SpeechRecognizer";
+ IAsyncOperationCompletedHandler_SpeechRecognitionCompilationResult *handler = NULL;
+ IAsyncOperation_SpeechRecognitionCompilationResult *operation = NULL;
IVector_ISpeechRecognitionConstraint *constraints = NULL;
ISpeechContinuousRecognitionSession *session = NULL;
ISpeechRecognizerFactory *sr_factory = NULL;
@@ -740,11 +825,15 @@ static void test_SpeechRecognizer(void)
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 compilation_handler compilation_handler;
EventRegistrationToken token = { .value = 0 };
+ AsyncStatus async_status;
HSTRING hstr, hstr_lang;
HRESULT hr;
+ UINT32 id;
LONG ref;
hr = RoInitialize(RO_INIT_MULTITHREADED);
@@ -848,6 +937,78 @@ static void test_SpeechRecognizer(void)
ref = IVector_ISpeechRecognitionConstraint_Release(constraints);
ok(ref == 1, "Got unexpected ref %lu.\n", ref);
+ compilation_handler_create_static(&compilation_handler);
+ compilation_handler.event_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
+ compilation_handler.thread_id = GetCurrentThreadId();
+
+ if (!compilation_handler.event_finished) goto skip_compile;
+
+ hr = ISpeechRecognizer_CompileConstraintsAsync(recognizer, &operation);
+ ok(hr == S_OK, "ISpeechRecognizer_CompileConstraintsAsync failed, hr %#lx.\n", hr);
+ check_interface(operation, &IID_IAgileObject, TRUE);
+
+ 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);
+
+ if (FAILED(hr)) goto skip_operation;
+
+ hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, &compilation_handler.IAsyncHandler_Compilation_iface);
+ todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
+ check_refcount(&compilation_handler.IAsyncHandler_Compilation_iface, 1);
+
+ WaitForSingleObject(compilation_handler.event_finished, INFINITE);
+
+ 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_QueryInterface(operation, &IID_IAsyncInfo, (void **)&info);
+ todo_wine ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr);
+
+ IAsyncInfo_AddRef(info);
+ check_refcount(operation, 3);
+ check_refcount(info, 3);
+
+ IAsyncOperation_SpeechRecognitionCompilationResult_AddRef(operation);
+ check_refcount(operation, 4);
+ check_refcount(info, 4);
+ IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
+
+ ref = IAsyncInfo_Release(info);
+ todo_wine ok(ref == 2, "Got unexpected ref %lu.\n", ref);
+
+ id = 0xdeadbeef;
+ hr = IAsyncInfo_get_Id(info, &id);
+ todo_wine ok(hr == S_OK, "IAsyncInfo_get_Id failed, hr %#lx.\n", hr);
+ todo_wine ok(id != 0xdeadbeef, "Id was %x.\n", id);
+
+ 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);
+
+ hr = IAsyncOperation_SpeechRecognitionCompilationResult_put_Completed(operation, NULL);
+ todo_wine ok(hr == E_ILLEGAL_DELEGATE_ASSIGNMENT, "Got unexpected hr %#lx.\n", hr);
+
+ hr = IAsyncInfo_Close(info);
+ todo_wine ok(hr == S_OK, "IAsyncInfo_Close failed, hr %#lx.\n", hr);
+
+ ref = IAsyncInfo_Release(info);
+ todo_wine 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);
+
+skip_operation:
+ ref = IAsyncOperation_SpeechRecognitionCompilationResult_Release(operation);
+ ok(!ref, "Got unexpected ref %lu.\n", ref);
+
+ CloseHandle(compilation_handler.event_finished);
+
+skip_compile:
ref = ISpeechContinuousRecognitionSession_Release(session);
ok(ref == 1, "Got unexpected ref %lu.\n", ref);
diff --git a/include/windows.foundation.idl b/include/windows.foundation.idl
index 87aaac0f160..c5f4c04a334 100644
--- a/include/windows.foundation.idl
+++ b/include/windows.foundation.idl
@@ -168,7 +168,9 @@ namespace Windows {
interface Windows.Foundation.Collections.IVector<IInspectable *>;
interface Windows.Foundation.Collections.IMapView<HSTRING, Windows.Foundation.Collections.IVectorView<HSTRING>*>;
interface Windows.Foundation.EventHandler<IInspectable *>;
+ interface Windows.Foundation.AsyncOperationCompletedHandler<IInspectable *>;
interface Windows.Foundation.AsyncOperationCompletedHandler<boolean>;
+ interface Windows.Foundation.IAsyncOperation<IInspectable *>;
interface Windows.Foundation.IAsyncOperation<boolean>;
interface Windows.Foundation.IReference<INT32>;
interface Windows.Foundation.TypedEventHandler<IInspectable *, IInspectable *>;
--
2.35.1
More information about the wine-devel
mailing list