quartz/tests: Clean up test_query_interface().

Signed-off-by: Zebediah Figura <z.figura12@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Zebediah Figura 2019-03-12 00:32:55 -05:00 committed by Alexandre Julliard
parent fd2412fbe5
commit cbb7fd5256
1 changed files with 113 additions and 93 deletions

View File

@ -26,104 +26,122 @@
#include "amaudio.h"
#include "wine/test.h"
#define QI_SUCCEED(iface, riid, ppv) hr = IUnknown_QueryInterface(iface, &riid, (LPVOID*)&ppv); \
ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr); \
ok(ppv != NULL, "Pointer is NULL\n");
#define RELEASE_EXPECT(iface, num) if (iface) { \
hr = IUnknown_Release((IUnknown*)iface); \
ok(hr == num, "IUnknown_Release should return %d, got %d\n", num, hr); \
}
static IUnknown *pDSRender = NULL;
static BOOL create_dsound_renderer(void)
static IBaseFilter *create_dsound_render(void)
{
HRESULT hr;
hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (LPVOID*)&pDSRender);
return (hr == S_OK && pDSRender != NULL);
IBaseFilter *filter = NULL;
HRESULT hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
&IID_IBaseFilter, (void **)&filter);
ok(hr == S_OK, "Got hr %#x.\n", hr);
return filter;
}
static void release_dsound_renderer(void)
static HRESULT WINAPI property_bag_QueryInterface(IPropertyBag *iface, REFIID iid, void **out)
{
HRESULT hr;
hr = IUnknown_Release(pDSRender);
ok(hr == 0, "IUnknown_Release failed with %x\n", hr);
ok(0, "Unexpected call (iid %s).\n", wine_dbgstr_guid(iid));
return E_NOINTERFACE;
}
static ULONG WINAPI property_bag_AddRef(IPropertyBag *iface)
{
ok(0, "Unexpected call.\n");
return 2;
}
static ULONG WINAPI property_bag_Release(IPropertyBag *iface)
{
ok(0, "Unexpected call.\n");
return 1;
}
static HRESULT WINAPI property_bag_Read(IPropertyBag *iface, const WCHAR *name, VARIANT *var, IErrorLog *log)
{
static const WCHAR dsguidW[] = {'D','S','G','u','i','d',0};
WCHAR guidstr[39];
ok(!lstrcmpW(name, dsguidW), "Got unexpected name %s.\n", wine_dbgstr_w(name));
ok(V_VT(var) == VT_BSTR, "Got unexpected type %u.\n", V_VT(var));
StringFromGUID2(&DSDEVID_DefaultPlayback, guidstr, ARRAY_SIZE(guidstr));
V_BSTR(var) = SysAllocString(guidstr);
return S_OK;
}
static HRESULT WINAPI property_bag_Write(IPropertyBag *iface, const WCHAR *name, VARIANT *var)
{
ok(0, "Unexpected call (name %s).\n", wine_dbgstr_w(name));
return E_FAIL;
}
static const IPropertyBagVtbl property_bag_vtbl =
{
property_bag_QueryInterface,
property_bag_AddRef,
property_bag_Release,
property_bag_Read,
property_bag_Write,
};
static void test_property_bag(void)
{
IPropertyBag property_bag = {&property_bag_vtbl};
IPersistPropertyBag *ppb;
ICreateDevEnum *devenum;
IEnumMoniker *enummon;
IPropertyBag *propbag;
IMoniker *mon;
HRESULT hr;
ULONG ref;
CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
&IID_ICreateDevEnum, (void **)&devenum);
ICreateDevEnum_CreateClassEnumerator(devenum, &CLSID_AudioRendererCategory, &enummon, 0);
hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
&IID_IPersistPropertyBag, (void **)&ppb);
todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
if (hr != S_OK) return;
while (IEnumMoniker_Next(enummon, 1, &mon, NULL) == S_OK)
{
hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
&IID_IPersistPropertyBag, (void **)&ppb);
todo_wine ok(hr == S_OK, "Got hr %#x.\n", hr);
if (hr != S_OK) break;
hr = IPersistPropertyBag_InitNew(ppb);
ok(hr == S_OK, "Got hr %#x.\n", hr);
IMoniker_BindToStorage(mon, NULL, NULL, &IID_IPropertyBag, (void **)&propbag);
hr = IPersistPropertyBag_Load(ppb, &property_bag, NULL);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IPersistPropertyBag_InitNew(ppb);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IPersistPropertyBag_Load(ppb, propbag, NULL);
ok(hr == S_OK, "Got hr %#x.\n", hr);
IPersistPropertyBag_Release(ppb);
IPropertyBag_Release(propbag);
IMoniker_Release(mon);
}
IEnumMoniker_Release(enummon);
ICreateDevEnum_Release(devenum);
ref = IPersistPropertyBag_Release(ppb);
ok(!ref, "Got unexpected refcount %d.\n", ref);
}
static void test_query_interface(void)
#define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
{
HRESULT hr;
IBaseFilter *pBaseFilter = NULL;
IBasicAudio *pBasicAudio = NULL;
IMediaPosition *pMediaPosition = NULL;
IMediaSeeking *pMediaSeeking = NULL;
IQualityControl *pQualityControl = NULL;
IPersistPropertyBag *ppb = NULL;
IDirectSound3DBuffer *ds3dbuf = NULL;
IReferenceClock *clock = NULL;
IAMDirectSound *pAMDirectSound = NULL;
IUnknown *iface = iface_ptr;
HRESULT hr, expected_hr;
IUnknown *unk;
QI_SUCCEED(pDSRender, IID_IBaseFilter, pBaseFilter);
RELEASE_EXPECT(pBaseFilter, 1);
QI_SUCCEED(pDSRender, IID_IBasicAudio, pBasicAudio);
RELEASE_EXPECT(pBasicAudio, 1);
QI_SUCCEED(pDSRender, IID_IMediaSeeking, pMediaSeeking);
RELEASE_EXPECT(pMediaSeeking, 1);
QI_SUCCEED(pDSRender, IID_IReferenceClock, clock);
RELEASE_EXPECT(clock, 1);
QI_SUCCEED(pDSRender, IID_IAMDirectSound, pAMDirectSound);
RELEASE_EXPECT( pAMDirectSound, 1);
todo_wine {
QI_SUCCEED(pDSRender, IID_IDirectSound3DBuffer, ds3dbuf);
RELEASE_EXPECT(ds3dbuf, 1);
QI_SUCCEED(pDSRender, IID_IPersistPropertyBag, ppb);
RELEASE_EXPECT(ppb, 1);
}
QI_SUCCEED(pDSRender, IID_IMediaPosition, pMediaPosition);
RELEASE_EXPECT(pMediaPosition, 1);
QI_SUCCEED(pDSRender, IID_IQualityControl, pQualityControl);
RELEASE_EXPECT(pQualityControl, 1);
expected_hr = supported ? S_OK : E_NOINTERFACE;
hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x, expected %#x.\n", hr, expected_hr);
if (SUCCEEDED(hr))
IUnknown_Release(unk);
}
static void test_interfaces(void)
{
IBaseFilter *filter = create_dsound_render();
check_interface(filter, &IID_IAMDirectSound, TRUE);
check_interface(filter, &IID_IBaseFilter, TRUE);
check_interface(filter, &IID_IBasicAudio, TRUE);
todo_wine check_interface(filter, &IID_IDirectSound3DBuffer, TRUE);
check_interface(filter, &IID_IMediaFilter, TRUE);
check_interface(filter, &IID_IMediaPosition, TRUE);
check_interface(filter, &IID_IMediaSeeking, TRUE);
check_interface(filter, &IID_IPersist, TRUE);
todo_wine check_interface(filter, &IID_IPersistPropertyBag, TRUE);
check_interface(filter, &IID_IQualityControl, TRUE);
check_interface(filter, &IID_IReferenceClock, TRUE);
check_interface(filter, &IID_IUnknown, TRUE);
todo_wine check_interface(filter, &IID_IAMFilterMiscFlags, FALSE);
check_interface(filter, &IID_IBasicVideo, FALSE);
check_interface(filter, &IID_IKsPropertySet, FALSE);
check_interface(filter, &IID_IPin, FALSE);
check_interface(filter, &IID_IQualProp, FALSE);
check_interface(filter, &IID_IVideoWindow, FALSE);
IBaseFilter_Release(filter);
}
static void test_pin(IPin *pin)
@ -145,19 +163,11 @@ static void test_pin(IPin *pin)
static void test_basefilter(void)
{
IEnumPins *pin_enum = NULL;
IBaseFilter *base = NULL;
IBaseFilter *base = create_dsound_render();
IPin *pins[2];
ULONG ref;
HRESULT hr;
IUnknown_QueryInterface(pDSRender, &IID_IBaseFilter, (void **)&base);
if (base == NULL)
{
/* test_query_interface handles this case */
skip("No IBaseFilter\n");
return;
}
hr = IBaseFilter_EnumPins(base, NULL);
ok(hr == E_POINTER, "hr = %08x and not E_POINTER\n", hr);
@ -192,15 +202,25 @@ static void test_basefilter(void)
START_TEST(dsoundrender)
{
IBaseFilter *filter;
HRESULT hr;
CoInitialize(NULL);
if (!create_dsound_renderer())
hr = CoCreateInstance(&CLSID_DSoundRender, NULL, CLSCTX_INPROC_SERVER,
&IID_IBaseFilter, (void **)&filter);
if (hr == VFW_E_NO_AUDIO_HARDWARE)
{
skip("No audio hardware.\n");
CoUninitialize();
return;
}
ok(hr == S_OK, "Got hr %#x.\n", hr);
IBaseFilter_Release(filter);
test_property_bag();
test_query_interface();
test_interfaces();
test_basefilter();
release_dsound_renderer();
CoUninitialize();
}