qedit/tests: Clean up and expand aggregation tests.

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-04-15 23:20:51 -05:00 committed by Alexandre Julliard
parent eb5b2cfbc2
commit a6b00b4db6
3 changed files with 299 additions and 74 deletions

View File

@ -30,47 +30,107 @@
#include "control.h" #include "control.h"
#include "rc.h" #include "rc.h"
/* Outer IUnknown for COM aggregation tests */ static ULONG get_refcount(void *iface)
struct unk_impl { {
IUnknown IUnknown_iface; IUnknown *unknown = iface;
LONG ref; IUnknown_AddRef(unknown);
IUnknown *inner_unk; return IUnknown_Release(unknown);
}
static const GUID test_iid = {0x33333333};
static LONG outer_ref = 1;
static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
{
if (IsEqualGUID(iid, &IID_IUnknown)
|| IsEqualGUID(iid, &IID_IMediaDet)
|| IsEqualGUID(iid, &test_iid))
{
*out = (IUnknown *)0xdeadbeef;
return S_OK;
}
ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
return E_NOINTERFACE;
}
static ULONG WINAPI outer_AddRef(IUnknown *iface)
{
return InterlockedIncrement(&outer_ref);
}
static ULONG WINAPI outer_Release(IUnknown *iface)
{
return InterlockedDecrement(&outer_ref);
}
static const IUnknownVtbl outer_vtbl =
{
outer_QueryInterface,
outer_AddRef,
outer_Release,
}; };
static inline struct unk_impl *impl_from_IUnknown(IUnknown *iface) static IUnknown test_outer = {&outer_vtbl};
static void test_aggregation(void)
{ {
return CONTAINING_RECORD(iface, struct unk_impl, IUnknown_iface); IMediaDet *detector, *detector2;
IUnknown *unk, *unk2;
HRESULT hr;
ULONG ref;
detector = (IMediaDet *)0xdeadbeef;
hr = CoCreateInstance(&CLSID_MediaDet, &test_outer, CLSCTX_INPROC_SERVER,
&IID_IMediaDet, (void **)&detector);
todo_wine ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
ok(!detector, "Got interface %p.\n", detector);
hr = CoCreateInstance(&CLSID_MediaDet, &test_outer, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (void **)&unk);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
ref = get_refcount(unk);
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
ref = IUnknown_AddRef(unk);
ok(ref == 2, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
ref = IUnknown_Release(unk);
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
IUnknown_Release(unk2);
hr = IUnknown_QueryInterface(unk, &IID_IMediaDet, (void **)&detector);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IMediaDet_QueryInterface(detector, &IID_IUnknown, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
hr = IMediaDet_QueryInterface(detector, &IID_IMediaDet, (void **)&detector2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(detector2 == (IMediaDet *)0xdeadbeef, "Got unexpected IMediaDet %p.\n", detector2);
hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
hr = IMediaDet_QueryInterface(detector, &test_iid, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
IMediaDet_Release(detector);
ref = IUnknown_Release(unk);
ok(!ref, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
} }
static HRESULT WINAPI unk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
{
struct unk_impl *This = impl_from_IUnknown(iface);
return IUnknown_QueryInterface(This->inner_unk, riid, ppv);
}
static ULONG WINAPI unk_AddRef(IUnknown *iface)
{
struct unk_impl *This = impl_from_IUnknown(iface);
return InterlockedIncrement(&This->ref);
}
static ULONG WINAPI unk_Release(IUnknown *iface)
{
struct unk_impl *This = impl_from_IUnknown(iface);
return InterlockedDecrement(&This->ref);
}
static const IUnknownVtbl unk_vtbl =
{
unk_QueryInterface,
unk_AddRef,
unk_Release
};
static WCHAR test_avi_filename[MAX_PATH]; static WCHAR test_avi_filename[MAX_PATH];
static WCHAR test_sound_avi_filename[MAX_PATH]; static WCHAR test_sound_avi_filename[MAX_PATH];
@ -131,9 +191,7 @@ static BOOL init_tests(void)
static void test_mediadet(void) static void test_mediadet(void)
{ {
HRESULT hr; HRESULT hr;
struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL};
IMediaDet *pM = NULL; IMediaDet *pM = NULL;
ULONG refcount;
BSTR filename = NULL; BSTR filename = NULL;
LONG nstrms = 0; LONG nstrms = 0;
LONG strm; LONG strm;
@ -142,22 +200,6 @@ static void test_mediadet(void)
int flags; int flags;
int i; int i;
/* COM aggregation */
hr = CoCreateInstance(&CLSID_MediaDet, &unk_obj.IUnknown_iface, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (void**)&unk_obj.inner_unk);
ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
hr = IUnknown_QueryInterface(unk_obj.inner_unk, &IID_IMediaDet, (void**)&pM);
ok(hr == S_OK, "QueryInterface for IID_IMediaDet failed: %08x\n", hr);
refcount = IMediaDet_AddRef(pM);
ok(refcount == unk_obj.ref, "MediaDet just pretends to support COM aggregation\n");
refcount = IMediaDet_Release(pM);
ok(refcount == unk_obj.ref, "MediaDet just pretends to support COM aggregation\n");
refcount = IMediaDet_Release(pM);
ok(refcount == 19, "Refcount should be back at 19 but is %u\n", refcount);
IUnknown_Release(unk_obj.inner_unk);
/* test.avi has one video stream. */ /* test.avi has one video stream. */
hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER, hr = CoCreateInstance(&CLSID_MediaDet, NULL, CLSCTX_INPROC_SERVER,
&IID_IMediaDet, (LPVOID*)&pM); &IID_IMediaDet, (LPVOID*)&pM);
@ -523,31 +565,14 @@ static ISampleGrabberCB my_sg_cb = { &sgcb_vt };
static void test_samplegrabber(void) static void test_samplegrabber(void)
{ {
struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL};
ISampleGrabber *sg; ISampleGrabber *sg;
IBaseFilter *bf; IBaseFilter *bf;
IPin *pin; IPin *pin;
IMemInputPin *inpin; IMemInputPin *inpin;
IEnumPins *pins; IEnumPins *pins;
ULONG refcount;
HRESULT hr; HRESULT hr;
FILTER_STATE fstate; FILTER_STATE fstate;
/* COM aggregation */
hr = CoCreateInstance(&CLSID_SampleGrabber, &unk_obj.IUnknown_iface, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (void**)&unk_obj.inner_unk);
ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
hr = IUnknown_QueryInterface(unk_obj.inner_unk, &IID_ISampleGrabber, (void**)&sg);
ok(hr == S_OK, "QueryInterface for IID_ISampleGrabber failed: %08x\n", hr);
refcount = ISampleGrabber_AddRef(sg);
ok(refcount == unk_obj.ref, "SampleGrabber just pretends to support COM aggregation\n");
refcount = ISampleGrabber_Release(sg);
ok(refcount == unk_obj.ref, "SampleGrabber just pretends to support COM aggregation\n");
refcount = ISampleGrabber_Release(sg);
ok(refcount == 19, "Refcount should be back at 19 but is %u\n", refcount);
IUnknown_Release(unk_obj.inner_unk);
/* Invalid RIID */ /* Invalid RIID */
hr = CoCreateInstance(&CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, &IID_IClassFactory, hr = CoCreateInstance(&CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER, &IID_IClassFactory,
(void**)&sg); (void**)&sg);
@ -629,8 +654,11 @@ START_TEST(mediadet)
} }
CoInitialize(NULL); CoInitialize(NULL);
test_aggregation();
test_mediadet(); test_mediadet();
test_samplegrabber(); test_samplegrabber();
test_COM_sg_enumpins(); test_COM_sg_enumpins();
CoUninitialize(); CoUninitialize();
} }

View File

@ -355,6 +355,100 @@ static void test_pin_info(void)
ok(!ref, "Got outstanding refcount %d.\n", ref); ok(!ref, "Got outstanding refcount %d.\n", ref);
} }
static const GUID test_iid = {0x33333333};
static LONG outer_ref = 1;
static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
{
if (IsEqualGUID(iid, &IID_IUnknown)
|| IsEqualGUID(iid, &IID_IBaseFilter)
|| IsEqualGUID(iid, &test_iid))
{
*out = (IUnknown *)0xdeadbeef;
return S_OK;
}
ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
return E_NOINTERFACE;
}
static ULONG WINAPI outer_AddRef(IUnknown *iface)
{
return InterlockedIncrement(&outer_ref);
}
static ULONG WINAPI outer_Release(IUnknown *iface)
{
return InterlockedDecrement(&outer_ref);
}
static const IUnknownVtbl outer_vtbl =
{
outer_QueryInterface,
outer_AddRef,
outer_Release,
};
static IUnknown test_outer = {&outer_vtbl};
static void test_aggregation(void)
{
IBaseFilter *filter, *filter2;
IUnknown *unk, *unk2;
HRESULT hr;
ULONG ref;
filter = (IBaseFilter *)0xdeadbeef;
hr = CoCreateInstance(&CLSID_SampleGrabber, &test_outer, CLSCTX_INPROC_SERVER,
&IID_IBaseFilter, (void **)&filter);
todo_wine ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
ok(!filter, "Got interface %p.\n", filter);
hr = CoCreateInstance(&CLSID_SampleGrabber, &test_outer, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (void **)&unk);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
ref = get_refcount(unk);
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
ref = IUnknown_AddRef(unk);
ok(ref == 2, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
ref = IUnknown_Release(unk);
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
IUnknown_Release(unk2);
hr = IUnknown_QueryInterface(unk, &IID_IBaseFilter, (void **)&filter);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IBaseFilter_QueryInterface(filter, &IID_IUnknown, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
hr = IBaseFilter_QueryInterface(filter, &IID_IBaseFilter, (void **)&filter2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(filter2 == (IBaseFilter *)0xdeadbeef, "Got unexpected IBaseFilter %p.\n", filter2);
hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
hr = IBaseFilter_QueryInterface(filter, &test_iid, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
IBaseFilter_Release(filter);
ref = IUnknown_Release(unk);
ok(!ref, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
}
START_TEST(samplegrabber) START_TEST(samplegrabber)
{ {
CoInitialize(NULL); CoInitialize(NULL);
@ -363,6 +457,7 @@ START_TEST(samplegrabber)
test_enum_pins(); test_enum_pins();
test_find_pin(); test_find_pin();
test_pin_info(); test_pin_info();
test_aggregation();
CoUninitialize(); CoUninitialize();
} }

View File

@ -19,10 +19,109 @@
*/ */
#define COBJMACROS #define COBJMACROS
#define CONST_VTABLE
#include "wine/test.h"
#include "qedit.h" #include "qedit.h"
#include "wine/test.h"
static ULONG get_refcount(void *iface)
{
IUnknown *unknown = iface;
IUnknown_AddRef(unknown);
return IUnknown_Release(unknown);
}
static const GUID test_iid = {0x33333333};
static LONG outer_ref = 1;
static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
{
if (IsEqualGUID(iid, &IID_IUnknown)
|| IsEqualGUID(iid, &IID_IAMTimeline)
|| IsEqualGUID(iid, &test_iid))
{
*out = (IUnknown *)0xdeadbeef;
return S_OK;
}
ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
return E_NOINTERFACE;
}
static ULONG WINAPI outer_AddRef(IUnknown *iface)
{
return InterlockedIncrement(&outer_ref);
}
static ULONG WINAPI outer_Release(IUnknown *iface)
{
return InterlockedDecrement(&outer_ref);
}
static const IUnknownVtbl outer_vtbl =
{
outer_QueryInterface,
outer_AddRef,
outer_Release,
};
static IUnknown test_outer = {&outer_vtbl};
static void test_aggregation(void)
{
IAMTimeline *timeline, *timeline2;
IUnknown *unk, *unk2;
HRESULT hr;
ULONG ref;
timeline = (IAMTimeline *)0xdeadbeef;
hr = CoCreateInstance(&CLSID_AMTimeline, &test_outer, CLSCTX_INPROC_SERVER,
&IID_IAMTimeline, (void **)&timeline);
todo_wine ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
ok(!timeline, "Got interface %p.\n", timeline);
hr = CoCreateInstance(&CLSID_AMTimeline, &test_outer, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (void **)&unk);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
ref = get_refcount(unk);
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
ref = IUnknown_AddRef(unk);
ok(ref == 2, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
ref = IUnknown_Release(unk);
ok(ref == 1, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
IUnknown_Release(unk2);
hr = IUnknown_QueryInterface(unk, &IID_IAMTimeline, (void **)&timeline);
ok(hr == S_OK, "Got hr %#x.\n", hr);
hr = IAMTimeline_QueryInterface(timeline, &IID_IUnknown, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
hr = IAMTimeline_QueryInterface(timeline, &IID_IAMTimeline, (void **)&timeline2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(timeline2 == (IAMTimeline *)0xdeadbeef, "Got unexpected IAMTimeline %p.\n", timeline2);
hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
hr = IAMTimeline_QueryInterface(timeline, &test_iid, (void **)&unk2);
ok(hr == S_OK, "Got hr %#x.\n", hr);
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
IAMTimeline_Release(timeline);
ref = IUnknown_Release(unk);
ok(!ref, "Got unexpected refcount %d.\n", ref);
ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
}
static void test_timeline(void) static void test_timeline(void)
{ {
@ -148,7 +247,10 @@ static void test_timelineobj_interfaces(void)
START_TEST(timeline) START_TEST(timeline)
{ {
CoInitialize(NULL); CoInitialize(NULL);
test_aggregation();
test_timeline(); test_timeline();
test_timelineobj_interfaces(); test_timelineobj_interfaces();
CoUninitialize(); CoUninitialize();
} }