Commit 738bbeb9 authored by Shaun Ren's avatar Shaun Ren Committed by Alexandre Julliard

sapi/tests: Add test for implicit MTA initialized by SpVoice.

Based on a patch by Connor McAdams.
parent cdc3eeb7
...@@ -34,6 +34,46 @@ static void _expect_ref(IUnknown *obj, ULONG ref, int line) ...@@ -34,6 +34,46 @@ static void _expect_ref(IUnknown *obj, ULONG ref, int line)
ok_(__FILE__,line)(rc == ref, "Unexpected refcount %ld, expected %ld.\n", rc, ref); ok_(__FILE__,line)(rc == ref, "Unexpected refcount %ld, expected %ld.\n", rc, ref);
} }
#define APTTYPE_UNITIALIZED APTTYPE_CURRENT
static struct
{
APTTYPE type;
APTTYPEQUALIFIER qualifier;
} test_apt_data;
static DWORD WINAPI test_apt_thread(void *param)
{
HRESULT hr;
hr = CoGetApartmentType(&test_apt_data.type, &test_apt_data.qualifier);
if (hr == CO_E_NOTINITIALIZED)
{
test_apt_data.type = APTTYPE_UNITIALIZED;
test_apt_data.qualifier = 0;
}
return 0;
}
static void check_apttype(void)
{
HANDLE thread;
MSG msg;
memset(&test_apt_data, 0xde, sizeof(test_apt_data));
thread = CreateThread(NULL, 0, test_apt_thread, NULL, 0, NULL);
while (MsgWaitForMultipleObjects(1, &thread, FALSE, INFINITE, QS_ALLINPUT) != WAIT_OBJECT_0)
{
while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
CloseHandle(thread);
}
static void test_interfaces(void) static void test_interfaces(void)
{ {
ISpeechVoice *speech_voice, *speech_voice2; ISpeechVoice *speech_voice, *speech_voice2;
...@@ -380,6 +420,7 @@ static void test_spvoice(void) ...@@ -380,6 +420,7 @@ static void test_spvoice(void)
static const WCHAR test_text[] = L"Hello! This is a test sentence."; static const WCHAR test_text[] = L"Hello! This is a test sentence.";
ISpVoice *voice; ISpVoice *voice;
IUnknown *dummy;
ISpMMSysAudio *audio_out; ISpMMSysAudio *audio_out;
ISpObjectTokenCategory *token_cat; ISpObjectTokenCategory *token_cat;
ISpObjectToken *token; ISpObjectToken *token;
...@@ -397,23 +438,57 @@ static void test_spvoice(void) ...@@ -397,23 +438,57 @@ static void test_spvoice(void)
return; return;
} }
check_apttype();
ok(test_apt_data.type == APTTYPE_UNITIALIZED, "got apt type %d.\n", test_apt_data.type);
hr = CoCreateInstance(&CLSID_SpVoice, NULL, CLSCTX_INPROC_SERVER, hr = CoCreateInstance(&CLSID_SpVoice, NULL, CLSCTX_INPROC_SERVER,
&IID_ISpVoice, (void **)&voice); &IID_ISpVoice, (void **)&voice);
ok(hr == S_OK, "Failed to create SpVoice: %#lx.\n", hr); ok(hr == S_OK, "Failed to create SpVoice: %#lx.\n", hr);
hr = ISpVoice_SetOutput(voice, NULL, TRUE); check_apttype();
ok(hr == S_OK, "got %#lx.\n", hr); ok(test_apt_data.type == APTTYPE_UNITIALIZED, "got apt type %d.\n", test_apt_data.type);
/* SpVoice initializes a MTA in SetOutput even if an invalid output object is given. */
hr = CoCreateInstance(&CLSID_SpDataKey, NULL, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (void **)&dummy);
ok(hr == S_OK, "Failed to create dummy: %#lx.\n", hr);
hr = ISpVoice_SetOutput(voice, dummy, TRUE);
ok(hr == E_INVALIDARG, "got %#lx.\n", hr);
check_apttype();
ok(test_apt_data.type == APTTYPE_MTA || broken(test_apt_data.type == APTTYPE_UNITIALIZED) /* w8, w10v1507 */,
"got apt type %d.\n", test_apt_data.type);
if (test_apt_data.type == APTTYPE_MTA)
ok(test_apt_data.qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
"got apt type qualifier %d.\n", test_apt_data.qualifier);
else
win_skip("apt type is not MTA.\n");
IUnknown_Release(dummy);
hr = CoCreateInstance(&CLSID_SpMMAudioOut, NULL, CLSCTX_INPROC_SERVER, hr = CoCreateInstance(&CLSID_SpMMAudioOut, NULL, CLSCTX_INPROC_SERVER,
&IID_ISpMMSysAudio, (void **)&audio_out); &IID_ISpMMSysAudio, (void **)&audio_out);
ok(hr == S_OK, "Failed to create SpMMAudioOut: %#lx.\n", hr); ok(hr == S_OK, "Failed to create SpMMAudioOut: %#lx.\n", hr);
hr = ISpVoice_SetOutput(voice, NULL, TRUE);
ok(hr == S_OK, "got %#lx.\n", hr);
hr = ISpVoice_SetOutput(voice, (IUnknown *)audio_out, TRUE); hr = ISpVoice_SetOutput(voice, (IUnknown *)audio_out, TRUE);
todo_wine ok(hr == S_FALSE, "got %#lx.\n", hr); todo_wine ok(hr == S_FALSE, "got %#lx.\n", hr);
hr = ISpVoice_SetVoice(voice, NULL); hr = ISpVoice_SetVoice(voice, NULL);
todo_wine ok(hr == S_OK, "got %#lx.\n", hr); todo_wine ok(hr == S_OK, "got %#lx.\n", hr);
check_apttype();
ok(test_apt_data.type == APTTYPE_MTA || broken(test_apt_data.type == APTTYPE_UNITIALIZED) /* w8, w10v1507 */,
"got apt type %d.\n", test_apt_data.type);
if (test_apt_data.type == APTTYPE_MTA)
ok(test_apt_data.qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
"got apt type qualifier %d.\n", test_apt_data.qualifier);
else
win_skip("apt type is not MTA.\n");
hr = ISpVoice_GetVoice(voice, &token); hr = ISpVoice_GetVoice(voice, &token);
todo_wine ok(hr == S_OK, "got %#lx.\n", hr); todo_wine ok(hr == S_OK, "got %#lx.\n", hr);
...@@ -517,6 +592,15 @@ static void test_spvoice(void) ...@@ -517,6 +592,15 @@ static void test_spvoice(void)
hr = ISpVoice_SetVoice(voice, token); hr = ISpVoice_SetVoice(voice, token);
ok(hr == S_OK, "got %#lx.\n", hr); ok(hr == S_OK, "got %#lx.\n", hr);
check_apttype();
ok(test_apt_data.type == APTTYPE_MTA || broken(test_apt_data.type == APTTYPE_UNITIALIZED) /* w8, w10v1507 */,
"got apt type %d.\n", test_apt_data.type);
if (test_apt_data.type == APTTYPE_MTA)
ok(test_apt_data.qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
"got apt type qualifier %d.\n", test_apt_data.qualifier);
else
win_skip("apt type is not MTA.\n");
test_engine.speak_called = FALSE; test_engine.speak_called = FALSE;
hr = ISpVoice_Speak(voice, NULL, SPF_PURGEBEFORESPEAK, NULL); hr = ISpVoice_Speak(voice, NULL, SPF_PURGEBEFORESPEAK, NULL);
ok(hr == S_OK, "got %#lx.\n", hr); ok(hr == S_OK, "got %#lx.\n", hr);
...@@ -548,6 +632,11 @@ static void test_spvoice(void) ...@@ -548,6 +632,11 @@ static void test_spvoice(void)
ok(stream_num == 1, "got %lu.\n", stream_num); ok(stream_num == 1, "got %lu.\n", stream_num);
ok(duration > 800 && duration < 3000, "took %lu ms.\n", duration); ok(duration > 800 && duration < 3000, "took %lu ms.\n", duration);
check_apttype();
ok(test_apt_data.type == APTTYPE_MTA, "got apt type %d.\n", test_apt_data.type);
ok(test_apt_data.qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
"got apt type qualifier %d.\n", test_apt_data.qualifier);
start = GetTickCount(); start = GetTickCount();
hr = ISpVoice_WaitUntilDone(voice, INFINITE); hr = ISpVoice_WaitUntilDone(voice, INFINITE);
duration = GetTickCount() - start; duration = GetTickCount() - start;
...@@ -602,7 +691,8 @@ done: ...@@ -602,7 +691,8 @@ done:
START_TEST(tts) START_TEST(tts)
{ {
CoInitialize(NULL); CoInitialize(NULL);
test_interfaces(); /* Run spvoice tests before interface tests so that a MTA won't be created before this test is run. */
test_spvoice(); test_spvoice();
test_interfaces();
CoUninitialize(); CoUninitialize();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment