To test, if the ifaces are static and if each activatable class has it's own activation factory.
Signed-off-by: Bernhard Kölbl besentv@gmail.com --- v2: Rename some variables. --- dlls/windows.media.speech/tests/speech.c | 120 +++++++++++++++++++++++ 1 file changed, 120 insertions(+)
diff --git a/dlls/windows.media.speech/tests/speech.c b/dlls/windows.media.speech/tests/speech.c index 38fd5c90dd0..e7dab073e31 100644 --- a/dlls/windows.media.speech/tests/speech.c +++ b/dlls/windows.media.speech/tests/speech.c @@ -29,6 +29,8 @@ #define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections #include "windows.foundation.h" +#define WIDL_using_Windows_Media_SpeechRecognition +#include "windows.media.speechrecognition.h" #define WIDL_using_Windows_Media_SpeechSynthesis #include "windows.media.speechsynthesis.h"
@@ -36,6 +38,123 @@
HRESULT WINAPI (*pDllGetActivationFactory)(HSTRING, IActivationFactory **);
+static void test_ActivationFactory(void) +{ + static const WCHAR *synthesizer_name = L"Windows.Media.SpeechSynthesis.SpeechSynthesizer"; + static const WCHAR *recognizer_name = L"Windows.Media.SpeechRecognition.SpeechRecognizer"; + IInspectable *inspectable = NULL, *inspectable2 = NULL; + IAgileObject *agile_object = NULL, *agile_object2 = NULL; + IActivationFactory *factory = NULL, *factory2 = NULL, *factory3 = NULL; + ISpeechRecognizerFactory *recognizer_factory = NULL; + ISpeechRecognizerStatics *recognizer_statics = NULL; + ISpeechRecognizerStatics2 *recognizer_statics2 = NULL; + IInstalledVoicesStatic *installed_voices = NULL; + HSTRING str, str2; + HRESULT hr; + ULONG ref; + + hr = RoInitialize(RO_INIT_MULTITHREADED); + ok(hr == S_OK, "RoInitialize failed, hr %#x.\n", hr); + + hr = WindowsCreateString(synthesizer_name, wcslen(synthesizer_name), &str); + ok(hr == S_OK, "WindowsCreateString failed, hr %#x.\n", hr); + + hr = WindowsCreateString(recognizer_name, wcslen(recognizer_name), &str2); + ok(hr == S_OK, "WindowsCreateString failed, hr %#x.\n", hr); + + hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory); + ok(hr == S_OK, "RoGetActivationFactory failed, hr %#x.\n", hr); + + ref = IActivationFactory_AddRef(factory); + ok(ref == 3, "Got unexpected refcount: %u.\n", ref); + + ref = IActivationFactory_Release(factory); + ok(ref == 2, "Got unexpected refcount: %u.\n", ref); + + hr = IActivationFactory_QueryInterface(factory, &IID_ISpeechRecognizerFactory, (void**)&recognizer_factory); + ok(hr == E_NOINTERFACE, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + hr = IActivationFactory_QueryInterface(factory, &IID_IInspectable, (void**)&inspectable); + ok(hr == S_OK, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + hr = IActivationFactory_QueryInterface(factory, &IID_IAgileObject, (void**)&agile_object); + ok(hr == S_OK, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + hr = IActivationFactory_QueryInterface(factory, &IID_IInstalledVoicesStatic, (void**)&installed_voices); + ok(hr == S_OK, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + ref = IInstalledVoicesStatic_Release(installed_voices); + ok(ref == 4, "Got unexpected refcount: %u.\n", ref); + + ref = IAgileObject_Release(agile_object); + ok(ref == 3, "Got unexpected refcount: %u.\n", ref); + + ref = IInspectable_Release(inspectable); + ok(ref == 2, "Got unexpected refcount: %u.\n", ref); + + hr = RoGetActivationFactory(str, &IID_IActivationFactory, (void **)&factory2); + ok(hr == S_OK, "RoGetActivationFactory failed, hr %#x.\n", hr); + ok(factory == factory2, "Factories pointed at factory %p factory2 %p.\n", factory, factory2); + + hr = RoGetActivationFactory(str2, &IID_IActivationFactory, (void **)&factory3); + todo_wine ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "RoGetActivationFactory failed, hr %#x.\n", hr); + + if(hr == S_OK) /* Win10+ only */ + { + ok(factory != factory3, "Factories pointed at factory %p factory3 %p.\n", factory, factory3); + + hr = IActivationFactory_QueryInterface(factory3, &IID_IInspectable, (void**)&inspectable2); + ok(hr == S_OK, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + hr = IActivationFactory_QueryInterface(factory3, &IID_IAgileObject, (void**)&agile_object2); + ok(hr == S_OK, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + hr = IActivationFactory_QueryInterface(factory3, &IID_ISpeechRecognizerFactory, (void**)&recognizer_factory); + ok(hr == S_OK, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + hr = IActivationFactory_QueryInterface(factory3, &IID_ISpeechRecognizerStatics, (void**)&recognizer_statics); + ok(hr == S_OK, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + ref = ISpeechRecognizerStatics_Release(recognizer_statics); + ok(ref == 5, "Got unexpected refcount: %u.\n", ref); + + ref = ISpeechRecognizerFactory_Release(recognizer_factory); + ok(ref == 4, "Got unexpected refcount: %u.\n", ref); + + ref = IAgileObject_Release(agile_object2); + ok(ref == 3, "Got unexpected refcount: %u.\n", ref); + + ref = IInspectable_Release(inspectable2); + ok(ref == 2, "Got unexpected refcount: %u.\n", ref); + + hr = IActivationFactory_QueryInterface(factory3, &IID_ISpeechRecognizerStatics2, (void**)&recognizer_statics2); + ok(hr == S_OK || broken(hr == E_NOINTERFACE), "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + if(hr == S_OK) /* ISpeechRecognizerStatics2 not available in Win10 1507 */ + { + ref = ISpeechRecognizerStatics2_Release(recognizer_statics2); + ok(ref == 2, "Got unexpected refcount: %u.\n", ref); + } + + hr = IActivationFactory_QueryInterface(factory3, &IID_IInstalledVoicesStatic, (void**)&installed_voices); + ok(hr == E_NOINTERFACE, "IActivationFactory_QueryInterface failed, hr %#x.\n", hr); + + ref = IActivationFactory_Release(factory3); + ok(ref == 1, "Got unexpected refcount: %u.\n", ref); + } + + ref = IActivationFactory_Release(factory2); + ok(ref == 2, "Got unexpected refcount: %u.\n", ref); + + ref = IActivationFactory_Release(factory); + ok(ref == 1, "Got unexpected refcount: %u.\n", ref); + + WindowsDeleteString(str); + WindowsDeleteString(str2); + + RoUninitialize(); +} + static void test_SpeechSynthesizer(void) { static const WCHAR *speech_synthesizer_name = L"Windows.Media.SpeechSynthesis.SpeechSynthesizer"; @@ -203,6 +322,7 @@ static void test_VoiceInformation(void)
START_TEST(speech) { + test_ActivationFactory(); test_SpeechSynthesizer(); test_VoiceInformation(); }