From 24da40fa8556e247bb2521ac4ad920ad51532883 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Mon, 21 Nov 2011 14:46:57 +0100 Subject: [PATCH] qedit/tests: Add SampleGrabber COM aggregation test. --- dlls/qedit/tests/mediadet.c | 68 +++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/dlls/qedit/tests/mediadet.c b/dlls/qedit/tests/mediadet.c index de9b3a4c56c..1d9a2f108ef 100644 --- a/dlls/qedit/tests/mediadet.c +++ b/dlls/qedit/tests/mediadet.c @@ -19,6 +19,7 @@ */ #define COBJMACROS +#define CONST_VTABLE #include "initguid.h" #include "ole2.h" @@ -28,6 +29,47 @@ #include "qedit.h" #include "rc.h" +/* Outer IUnknown for COM aggregation tests */ +struct unk_impl { + IUnknown IUnknown_iface; + LONG ref; + IUnknown *inner_unk; +}; + +static inline struct unk_impl *impl_from_IUnknown(IUnknown *iface) +{ + return CONTAINING_RECORD(iface, struct unk_impl, IUnknown_iface); +} + +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_sound_avi_filename[MAX_PATH]; @@ -294,6 +336,31 @@ static void test_mediadet(void) DeleteFileW(test_sound_avi_filename); } +static void test_samplegrabber(void) +{ + struct unk_impl unk_obj = {{&unk_vtbl}, 19, NULL}; + ISampleGrabber *sg; + ULONG refcount; + HRESULT hr; + + /* COM aggregation */ + hr = CoCreateInstance(&CLSID_SampleGrabber, &unk_obj.IUnknown_iface, CLSCTX_INPROC_SERVER, + &IID_IUnknown, (void**)&unk_obj.inner_unk); + todo_wine ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr); + if (hr != S_OK) return; + + 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); +} + START_TEST(mediadet) { if (!init_tests()) @@ -304,5 +371,6 @@ START_TEST(mediadet) CoInitialize(NULL); test_mediadet(); + test_samplegrabber(); CoUninitialize(); }