wow64: Add thunks for the I/O completion syscalls.
[wine.git] / dlls / qdvd / tests / graph.c
blob93dc4e66a99d989a8a7f5a74f098a01e378fa1b3
1 /*
2 * Graph builder unit tests
4 * Copyright 2020 Gijs Vermeulen
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #include "dshow.h"
23 #include "wine/strmbase.h"
24 #include "wine/test.h"
26 static IDvdGraphBuilder *create_graph_builder(void)
28 IDvdGraphBuilder *graph = NULL;
29 HRESULT hr = CoCreateInstance(&CLSID_DvdGraphBuilder, NULL,
30 CLSCTX_INPROC_SERVER, &IID_IDvdGraphBuilder, (void **)&graph);
31 ok(hr == S_OK, "Got hr %#x.\n", hr);
32 return graph;
35 static ULONG get_refcount(void *iface)
37 IUnknown *unknown = iface;
38 IUnknown_AddRef(unknown);
39 return IUnknown_Release(unknown);
42 #define check_interface(a, b, c) check_interface_(__LINE__, a, b, c)
43 static void check_interface_(unsigned int line, void *iface_ptr, REFIID iid, BOOL supported)
45 IUnknown *iface = iface_ptr;
46 HRESULT hr, expected_hr;
47 IUnknown *unk;
49 expected_hr = supported ? S_OK : E_NOINTERFACE;
51 hr = IUnknown_QueryInterface(iface, iid, (void **)&unk);
52 ok_(__FILE__, line)(hr == expected_hr, "Got hr %#x, expected %#x.\n", hr, expected_hr);
53 if (SUCCEEDED(hr))
54 IUnknown_Release(unk);
57 static void test_interfaces(void)
59 IDvdGraphBuilder *graph = create_graph_builder();
61 check_interface(graph, &IID_IDvdGraphBuilder, TRUE);
62 check_interface(graph, &IID_IUnknown, TRUE);
64 check_interface(graph, &IID_IBaseFilter, FALSE);
66 IDvdGraphBuilder_Release(graph);
69 static const GUID test_iid = {0x33333333};
70 static LONG outer_ref = 1;
72 static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
74 if (IsEqualGUID(iid, &IID_IUnknown)
75 || IsEqualGUID(iid, &IID_IDvdGraphBuilder)
76 || IsEqualGUID(iid, &test_iid))
78 *out = (IUnknown *)0xdeadbeef;
79 return S_OK;
81 ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
82 return E_NOINTERFACE;
85 static ULONG WINAPI outer_AddRef(IUnknown *iface)
87 return InterlockedIncrement(&outer_ref);
90 static ULONG WINAPI outer_Release(IUnknown *iface)
92 return InterlockedDecrement(&outer_ref);
95 static const IUnknownVtbl outer_vtbl =
97 outer_QueryInterface,
98 outer_AddRef,
99 outer_Release,
102 static IUnknown test_outer = {&outer_vtbl};
104 static void test_aggregation(void)
106 IDvdGraphBuilder *graph, *graph2;
107 IUnknown *unk, *unk2;
108 HRESULT hr;
109 ULONG ref;
111 graph = (IDvdGraphBuilder *)0xdeadbeef;
112 hr = CoCreateInstance(&CLSID_DvdGraphBuilder, &test_outer, CLSCTX_INPROC_SERVER,
113 &IID_IDvdGraphBuilder, (void **)&graph);
114 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
115 ok(!graph, "Got interface %p.\n", graph);
117 hr = CoCreateInstance(&CLSID_DvdGraphBuilder, &test_outer, CLSCTX_INPROC_SERVER,
118 &IID_IUnknown, (void **)&unk);
119 ok(hr == S_OK, "Got hr %#x.\n", hr);
120 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
121 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
122 ref = get_refcount(unk);
123 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
125 ref = IUnknown_AddRef(unk);
126 ok(ref == 2, "Got unexpected refcount %d.\n", ref);
127 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
129 ref = IUnknown_Release(unk);
130 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
131 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
133 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
134 ok(hr == S_OK, "Got hr %#x.\n", hr);
135 ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
136 IUnknown_Release(unk2);
138 hr = IUnknown_QueryInterface(unk, &IID_IDvdGraphBuilder, (void **)&graph);
139 ok(hr == S_OK, "Got hr %#x.\n", hr);
141 hr = IDvdGraphBuilder_QueryInterface(graph, &IID_IUnknown, (void **)&unk2);
142 ok(hr == S_OK, "Got hr %#x.\n", hr);
143 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
145 hr = IDvdGraphBuilder_QueryInterface(graph, &IID_IDvdGraphBuilder, (void **)&graph2);
146 ok(hr == S_OK, "Got hr %#x.\n", hr);
147 ok(graph2 == (IDvdGraphBuilder *)0xdeadbeef, "Got unexpected IDvdGraphBuilder %p.\n", graph2);
149 hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
150 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
151 ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
153 hr = IDvdGraphBuilder_QueryInterface(graph, &test_iid, (void **)&unk2);
154 ok(hr == S_OK, "Got hr %#x.\n", hr);
155 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
157 IDvdGraphBuilder_Release(graph);
158 ref = IUnknown_Release(unk);
159 ok(!ref, "Got unexpected refcount %d.\n", ref);
160 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
163 START_TEST(graph)
165 CoInitializeEx(NULL, COINIT_MULTITHREADED);
167 test_interfaces();
168 test_aggregation();
170 CoUninitialize();