172 lines
5.4 KiB
C
172 lines
5.4 KiB
C
|
/*
|
||
|
* Graph builder unit tests
|
||
|
*
|
||
|
* Copyright 2020 Gijs Vermeulen
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Lesser General Public
|
||
|
* License as published by the Free Software Foundation; either
|
||
|
* version 2.1 of the License, or (at your option) any later version.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Lesser General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Lesser General Public
|
||
|
* License along with this library; if not, write to the Free Software
|
||
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
||
|
*/
|
||
|
|
||
|
#define COBJMACROS
|
||
|
#include "dshow.h"
|
||
|
#include "wine/strmbase.h"
|
||
|
#include "wine/test.h"
|
||
|
|
||
|
static IDvdGraphBuilder *create_graph_builder(void)
|
||
|
{
|
||
|
IDvdGraphBuilder *graph = NULL;
|
||
|
HRESULT hr = CoCreateInstance(&CLSID_DvdGraphBuilder, NULL,
|
||
|
CLSCTX_INPROC_SERVER, &IID_IDvdGraphBuilder, (void **)&graph);
|
||
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
||
|
return graph;
|
||
|
}
|
||
|
|
||
|
static ULONG get_refcount(void *iface)
|
||
|
{
|
||
|
IUnknown *unknown = iface;
|
||
|
IUnknown_AddRef(unknown);
|
||
|
return IUnknown_Release(unknown);
|
||
|
}
|
||
|
|
||
|
#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)
|
||
|
{
|
||
|
IUnknown *iface = iface_ptr;
|
||
|
HRESULT hr, expected_hr;
|
||
|
IUnknown *unk;
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
IDvdGraphBuilder *graph = create_graph_builder();
|
||
|
|
||
|
check_interface(graph, &IID_IDvdGraphBuilder, TRUE);
|
||
|
check_interface(graph, &IID_IUnknown, TRUE);
|
||
|
|
||
|
check_interface(graph, &IID_IBaseFilter, FALSE);
|
||
|
|
||
|
IDvdGraphBuilder_Release(graph);
|
||
|
}
|
||
|
|
||
|
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_IDvdGraphBuilder)
|
||
|
|| 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)
|
||
|
{
|
||
|
IDvdGraphBuilder *graph, *graph2;
|
||
|
IUnknown *unk, *unk2;
|
||
|
HRESULT hr;
|
||
|
ULONG ref;
|
||
|
|
||
|
graph = (IDvdGraphBuilder *)0xdeadbeef;
|
||
|
hr = CoCreateInstance(&CLSID_DvdGraphBuilder, &test_outer, CLSCTX_INPROC_SERVER,
|
||
|
&IID_IDvdGraphBuilder, (void **)&graph);
|
||
|
ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
|
||
|
ok(!graph, "Got interface %p.\n", graph);
|
||
|
|
||
|
hr = CoCreateInstance(&CLSID_DvdGraphBuilder, &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_IDvdGraphBuilder, (void **)&graph);
|
||
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
||
|
|
||
|
hr = IDvdGraphBuilder_QueryInterface(graph, &IID_IUnknown, (void **)&unk2);
|
||
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
||
|
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
|
||
|
|
||
|
hr = IDvdGraphBuilder_QueryInterface(graph, &IID_IDvdGraphBuilder, (void **)&graph2);
|
||
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
||
|
ok(graph2 == (IDvdGraphBuilder *)0xdeadbeef, "Got unexpected IDvdGraphBuilder %p.\n", graph2);
|
||
|
|
||
|
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 = IDvdGraphBuilder_QueryInterface(graph, &test_iid, (void **)&unk2);
|
||
|
ok(hr == S_OK, "Got hr %#x.\n", hr);
|
||
|
ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
|
||
|
|
||
|
IDvdGraphBuilder_Release(graph);
|
||
|
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(graph)
|
||
|
{
|
||
|
CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||
|
|
||
|
test_interfaces();
|
||
|
test_aggregation();
|
||
|
|
||
|
CoUninitialize();
|
||
|
}
|