An asynchronous media event request cannot be cancelled. This means that we cannot test for no event firing within a certain timeout, because if we did we would leave a pending thread that will spoil future tests. Using synchronous APIs and repeated requests, we can wait for an even with a certain timeout, without doing damages if the timeout is reached.
Signed-off-by: Giovanni Mascellani gmascellani@codeweavers.com --- dlls/mfplat/tests/mfplat.c | 106 ++++++++++++++----------------------- 1 file changed, 41 insertions(+), 65 deletions(-)
diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 90440a10c62..a18fb9256d6 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -565,77 +565,53 @@ static const IMFAsyncCallbackVtbl test_create_from_file_handler_callback_vtbl = test_create_from_file_handler_callback_Invoke, };
-static HRESULT WINAPI source_events_callback_Invoke(IMFAsyncCallback *iface, IMFAsyncResult *result) +#define get_event(a, b, c) get_event_(a, b, c, __LINE__) +static BOOL get_event_(IMFMediaEventGenerator *generator, MediaEventType *met, PROPVARIANT *value, int line) { - struct test_callback *callback = impl_from_IMFAsyncCallback(iface); - IMFMediaEventGenerator *generator; - HRESULT hr; - - ok(!!result, "Unexpected result object.\n"); - - generator = (IMFMediaEventGenerator *)IMFAsyncResult_GetStateNoAddRef(result); - - hr = IMFMediaEventGenerator_EndGetEvent(generator, result, &callback->media_event); - ok(hr == S_OK, "Failed to create an object, hr %#x.\n", hr); - - SetEvent(callback->event); - - return S_OK; -} - -static const IMFAsyncCallbackVtbl events_callback_vtbl = -{ - testcallback_QueryInterface, - testcallback_AddRef, - testcallback_Release, - testcallback_GetParameters, - source_events_callback_Invoke, -}; - -static BOOL get_event(IMFMediaEventGenerator *generator, MediaEventType expected_event_type, PROPVARIANT *value) -{ - struct test_callback callback = {{ 0 }}; - MediaEventType event_type; - BOOL ret = FALSE; + IMFMediaEvent *event; HRESULT hr; + int i;
- callback.IMFAsyncCallback_iface.lpVtbl = &events_callback_vtbl; - callback.event = CreateEventA(NULL, FALSE, FALSE, NULL); - - for (;;) + for (i = 0; i < 10; i++) { - hr = IMFMediaEventGenerator_BeginGetEvent(generator, &callback.IMFAsyncCallback_iface, - (IUnknown *)generator); - ok(hr == S_OK, "Unexpected hr %#x.\n", hr); - - if (WaitForSingleObject(callback.event, 1000) == WAIT_TIMEOUT) - { - ok(0, "timeout\n"); + hr = IMFMediaEventGenerator_GetEvent(generator, MF_EVENT_FLAG_NO_WAIT, &event); + if (hr == S_OK) break; + if (hr != MF_E_NO_EVENTS_AVAILABLE) + { + ok_(__FILE__, line)(FALSE, "Unexpected hr %#x.\n", hr); + return FALSE; } - Sleep(10); + }
- hr = IMFMediaEvent_GetType(callback.media_event, &event_type); - ok(hr == S_OK, "Failed to event type, hr %#x.\n", hr); - - if ((ret = (event_type == expected_event_type))) - { - if (value) - { - hr = IMFMediaEvent_GetValue(callback.media_event, value); - ok(hr == S_OK, "Failed to get value of event, hr %#x.\n", hr); - } + if (i == 10) + return FALSE;
- break; - } + if (met) + { + hr = IMFMediaEvent_GetType(event, met); + ok_(__FILE__, line)(hr == S_OK, "Failed to get event type, hr %#x.\n", hr); + } + if (value) + { + hr = IMFMediaEvent_GetValue(event, value); + ok_(__FILE__, line)(hr == S_OK, "Failed to get event value, hr %#x.\n", hr); } + IMFMediaEvent_Release(event);
- CloseHandle(callback.event); - if (callback.media_event) - IMFMediaEvent_Release(callback.media_event); + return TRUE; +} + +#define expect_event(a, b, c) expect_event_(a, b, c, __LINE__) +static BOOL expect_event_(IMFMediaEventGenerator *generator, MediaEventType expected_met, PROPVARIANT *value, int line) +{ + MediaEventType met;
- return ret; + if (!get_event_(generator, &met, value, line)) + return FALSE; + ok_(__FILE__, line)(met == expected_met, "Got event %d instead of %d.\n", met, expected_met); + return met == expected_met; }
static void test_source_resolver(void) @@ -866,14 +842,14 @@ todo_wine ok(hr == S_OK, "Failed to start media source, hr %#x.\n", hr);
video_stream = NULL; - if (get_event((IMFMediaEventGenerator *)mediasource, MENewStream, &var)) + if (expect_event((IMFMediaEventGenerator *)mediasource, MENewStream, &var)) { ok(var.vt == VT_UNKNOWN, "Unexpected value type.\n"); video_stream = (IMFMediaStream *)var.punkVal; }
- get_event((IMFMediaEventGenerator *)mediasource, MESourceStarted, NULL); - get_event((IMFMediaEventGenerator *)video_stream, MEStreamStarted, NULL); + expect_event((IMFMediaEventGenerator *)mediasource, MESourceStarted, NULL); + expect_event((IMFMediaEventGenerator *)video_stream, MEStreamStarted, NULL);
sample_count = 10;
@@ -895,7 +871,7 @@ todo_wine IMFSample *sample; BOOL ret;
- ret = get_event((IMFMediaEventGenerator *)video_stream, MEMediaSample, &var); + ret = expect_event((IMFMediaEventGenerator *)video_stream, MEMediaSample, &var); ok(ret, "Sample %u not received.\n", i + 1); if (!ret) break; @@ -929,14 +905,14 @@ todo_wine
hr = IMFMediaStream_RequestSample(video_stream, NULL); ok (hr == S_OK || hr == MF_E_END_OF_STREAM, "Unexpected hr %#x.\n", hr); - get_event((IMFMediaEventGenerator *)video_stream, MEEndOfStream, NULL); + expect_event((IMFMediaEventGenerator *)video_stream, MEEndOfStream, NULL); }
hr = IMFMediaStream_RequestSample(video_stream, NULL); ok(hr == MF_E_END_OF_STREAM, "Unexpected hr %#x.\n", hr);
- get_event((IMFMediaEventGenerator *)mediasource, MEEndOfPresentation, NULL); + expect_event((IMFMediaEventGenerator *)mediasource, MEEndOfPresentation, NULL);
IMFMediaStream_Release(video_stream); IMFMediaTypeHandler_Release(handler);