mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / qdvd / tests / navigator.c
blob51999065cf57ab544bd4c16bfd0ed6d69cc982a6
1 /*
2 * Navigator filter 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 IBaseFilter *create_navigator(void)
28 IBaseFilter *filter = NULL;
29 HRESULT hr = CoCreateInstance(&CLSID_DVDNavigator, NULL,
30 CLSCTX_INPROC_SERVER, &IID_IBaseFilter, (void **)&filter);
31 ok(hr == S_OK, "Got hr %#x.\n", hr);
32 return filter;
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 IBaseFilter *filter = create_navigator();
61 check_interface(filter, &IID_IBaseFilter, TRUE);
62 todo_wine check_interface(filter, &IID_IDvdControl, TRUE);
63 check_interface(filter, &IID_IDvdControl2, TRUE);
64 todo_wine check_interface(filter, &IID_IDvdInfo, TRUE);
65 check_interface(filter, &IID_IDvdInfo2, TRUE);
66 check_interface(filter, &IID_IMediaFilter, TRUE);
67 check_interface(filter, &IID_IPersist, TRUE);
68 todo_wine check_interface(filter, &IID_ISpecifyPropertyPages, TRUE);
69 check_interface(filter, &IID_IUnknown, TRUE);
71 check_interface(filter, &IID_IAMFilterMiscFlags, FALSE);
72 check_interface(filter, &IID_IBasicAudio, FALSE);
73 check_interface(filter, &IID_IBasicVideo, FALSE);
74 check_interface(filter, &IID_IFileSourceFilter, FALSE);
75 check_interface(filter, &IID_IKsPropertySet, FALSE);
76 check_interface(filter, &IID_IMediaPosition, FALSE);
77 check_interface(filter, &IID_IMediaSeeking, FALSE);
78 check_interface(filter, &IID_IPersistPropertyBag, FALSE);
79 check_interface(filter, &IID_IPersistStream, FALSE);
80 check_interface(filter, &IID_IPin, FALSE);
81 check_interface(filter, &IID_IQualityControl, FALSE);
82 check_interface(filter, &IID_IQualProp, FALSE);
83 check_interface(filter, &IID_IReferenceClock, FALSE);
84 check_interface(filter, &IID_IVideoWindow, FALSE);
86 IBaseFilter_Release(filter);
89 static const GUID test_iid = {0x33333333};
90 static LONG outer_ref = 1;
92 static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
94 if (IsEqualGUID(iid, &IID_IUnknown)
95 || IsEqualGUID(iid, &IID_IBaseFilter)
96 || IsEqualGUID(iid, &test_iid))
98 *out = (IUnknown *)0xdeadbeef;
99 return S_OK;
101 ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
102 return E_NOINTERFACE;
105 static ULONG WINAPI outer_AddRef(IUnknown *iface)
107 return InterlockedIncrement(&outer_ref);
110 static ULONG WINAPI outer_Release(IUnknown *iface)
112 return InterlockedDecrement(&outer_ref);
115 static const IUnknownVtbl outer_vtbl =
117 outer_QueryInterface,
118 outer_AddRef,
119 outer_Release,
122 static IUnknown test_outer = {&outer_vtbl};
124 static void test_aggregation(void)
126 IBaseFilter *filter, *filter2;
127 IUnknown *unk, *unk2;
128 HRESULT hr;
129 ULONG ref;
131 filter = (IBaseFilter *)0xdeadbeef;
132 hr = CoCreateInstance(&CLSID_DVDNavigator, &test_outer, CLSCTX_INPROC_SERVER,
133 &IID_IBaseFilter, (void **)&filter);
134 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
135 ok(!filter, "Got interface %p.\n", filter);
137 hr = CoCreateInstance(&CLSID_DVDNavigator, &test_outer, CLSCTX_INPROC_SERVER,
138 &IID_IUnknown, (void **)&unk);
139 ok(hr == S_OK, "Got hr %#x.\n", hr);
140 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
141 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
142 ref = get_refcount(unk);
143 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
145 ref = IUnknown_AddRef(unk);
146 ok(ref == 2, "Got unexpected refcount %d.\n", ref);
147 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
149 ref = IUnknown_Release(unk);
150 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
151 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
153 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
154 ok(hr == S_OK, "Got hr %#x.\n", hr);
155 ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
156 IUnknown_Release(unk2);
158 hr = IUnknown_QueryInterface(unk, &IID_IBaseFilter, (void **)&filter);
159 ok(hr == S_OK, "Got hr %#x.\n", hr);
161 hr = IBaseFilter_QueryInterface(filter, &IID_IUnknown, (void **)&unk2);
162 ok(hr == S_OK, "Got hr %#x.\n", hr);
163 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
165 hr = IBaseFilter_QueryInterface(filter, &IID_IBaseFilter, (void **)&filter2);
166 ok(hr == S_OK, "Got hr %#x.\n", hr);
167 ok(filter2 == (IBaseFilter *)0xdeadbeef, "Got unexpected IBaseFilter %p.\n", filter2);
169 hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
170 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
171 ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
173 hr = IBaseFilter_QueryInterface(filter, &test_iid, (void **)&unk2);
174 ok(hr == S_OK, "Got hr %#x.\n", hr);
175 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
177 IBaseFilter_Release(filter);
178 ref = IUnknown_Release(unk);
179 ok(!ref, "Got unexpected refcount %d.\n", ref);
180 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
183 START_TEST(navigator)
185 CoInitializeEx(NULL, COINIT_MULTITHREADED);
187 test_interfaces();
188 test_aggregation();
190 CoUninitialize();