1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Misc unit tests for Quartz
*
* Copyright (C) 2007 Google (Lei Zhang)
*
* 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 "wine/test.h"
#include "dshow.h"
#define QI_SUCCEED(iface, riid, ppv) hr = IUnknown_QueryInterface(iface, &riid, (LPVOID*)&ppv); \
ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr); \
ok(ppv != NULL, "Pointer is NULL\n");
#define QI_FAIL(iface, riid, ppv) hr = IUnknown_QueryInterface(iface, &riid, (LPVOID*)&ppv); \
ok(hr == E_NOINTERFACE, "IUnknown_QueryInterface returned %x\n", hr); \
ok(ppv == NULL, "Pointer is %p\n", ppv);
#define ADDREF_EXPECT(iface, num) if (iface) { \
refCount = IUnknown_AddRef(iface); \
ok(refCount == num, "IUnknown_AddRef should return %d, got %d\n", num, refCount); \
}
#define RELEASE_EXPECT(iface, num) if (iface) { \
refCount = IUnknown_Release(iface); \
ok(refCount == num, "IUnknown_Release should return %d, got %d\n", num, refCount); \
}
static void test_aggregation(const CLSID clsidOuter, const CLSID clsidInner,
const IID iidOuter, const IID iidInner)
{
HRESULT hr;
ULONG refCount;
IUnknown *pUnkOuter = NULL;
IUnknown *pUnkInner = NULL;
IUnknown *pUnkInnerFail = NULL;
IUnknown *pUnkOuterTest = NULL;
IUnknown *pUnkInnerTest = NULL;
IUnknown *pUnkAggregatee = NULL;
IUnknown *pUnkAggregator = NULL;
IUnknown *pUnkTest = NULL;
hr = CoCreateInstance(&clsidOuter, NULL, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (LPVOID*)&pUnkOuter);
ok(hr == S_OK, "CoCreateInstance failed with %x\n", hr);
ok(pUnkOuter != NULL, "pUnkOuter is NULL\n");
if (!pUnkOuter)
{
skip("pUnkOuter is NULL\n");
return;
}
/* for aggregation, we should only be able to request IUnknown */
hr = CoCreateInstance(&clsidInner, pUnkOuter, CLSCTX_INPROC_SERVER,
&iidInner, (LPVOID*)&pUnkInnerFail);
if (hr == REGDB_E_CLASSNOTREG)
{
skip("Class not registered\n");
return;
}
ok(hr == E_NOINTERFACE, "CoCreateInstance returned %x\n", hr);
ok(pUnkInnerFail == NULL, "pUnkInnerFail is not NULL\n");
/* aggregation, request IUnknown */
hr = CoCreateInstance(&clsidInner, pUnkOuter, CLSCTX_INPROC_SERVER,
&IID_IUnknown, (LPVOID*)&pUnkInner);
ok(hr == S_OK, "CoCreateInstance returned %x\n", hr);
ok(pUnkInner != NULL, "pUnkInner is NULL\n");
if (!pUnkInner)
{
skip("pUnkInner is NULL\n");
return;
}
ADDREF_EXPECT(pUnkOuter, 2);
ADDREF_EXPECT(pUnkInner, 2);
RELEASE_EXPECT(pUnkOuter, 1);
RELEASE_EXPECT(pUnkInner, 1);
QI_FAIL(pUnkOuter, iidInner, pUnkAggregatee);
QI_FAIL(pUnkInner, iidOuter, pUnkAggregator);
/* these QueryInterface calls should work */
QI_SUCCEED(pUnkOuter, iidOuter, pUnkAggregator);
QI_SUCCEED(pUnkOuter, IID_IUnknown, pUnkOuterTest);
/* IGraphConfig interface comes with DirectShow 9 */
if(IsEqualGUID(&IID_IGraphConfig, &iidInner))
{
hr = IUnknown_QueryInterface(pUnkInner, &iidInner, (LPVOID*)&pUnkAggregatee);
ok(hr == S_OK || broken(hr == E_NOINTERFACE), "IUnknown_QueryInterface returned %x\n", hr);
ok(pUnkAggregatee != NULL || broken(!pUnkAggregatee), "Pointer is NULL\n");
}
else
{
QI_SUCCEED(pUnkInner, iidInner, pUnkAggregatee);
}
QI_SUCCEED(pUnkInner, IID_IUnknown, pUnkInnerTest);
if (!pUnkAggregator || !pUnkOuterTest || !pUnkAggregatee
|| !pUnkInnerTest)
{
skip("One of the required interfaces is NULL\n");
return;
}
ADDREF_EXPECT(pUnkAggregator, 5);
ADDREF_EXPECT(pUnkOuterTest, 6);
ADDREF_EXPECT(pUnkAggregatee, 7);
ADDREF_EXPECT(pUnkInnerTest, 3);
RELEASE_EXPECT(pUnkAggregator, 6);
RELEASE_EXPECT(pUnkOuterTest, 5);
RELEASE_EXPECT(pUnkAggregatee, 4);
RELEASE_EXPECT(pUnkInnerTest, 2);
QI_SUCCEED(pUnkAggregator, IID_IUnknown, pUnkTest);
QI_SUCCEED(pUnkOuterTest, IID_IUnknown, pUnkTest);
QI_SUCCEED(pUnkAggregatee, IID_IUnknown, pUnkTest);
QI_SUCCEED(pUnkInnerTest, IID_IUnknown, pUnkTest);
QI_FAIL(pUnkAggregator, iidInner, pUnkTest);
QI_FAIL(pUnkOuterTest, iidInner, pUnkTest);
QI_FAIL(pUnkAggregatee, iidInner, pUnkTest);
QI_SUCCEED(pUnkInnerTest, iidInner, pUnkTest);
QI_SUCCEED(pUnkAggregator, iidOuter, pUnkTest);
QI_SUCCEED(pUnkOuterTest, iidOuter, pUnkTest);
QI_SUCCEED(pUnkAggregatee, iidOuter, pUnkTest);
QI_FAIL(pUnkInnerTest, iidOuter, pUnkTest);
RELEASE_EXPECT(pUnkAggregator, 10);
RELEASE_EXPECT(pUnkOuterTest, 9);
RELEASE_EXPECT(pUnkAggregatee, 8);
RELEASE_EXPECT(pUnkInnerTest, 2);
RELEASE_EXPECT(pUnkOuter, 7);
RELEASE_EXPECT(pUnkInner, 1);
do
{
refCount = IUnknown_Release(pUnkInner);
} while (refCount);
do
{
refCount = IUnknown_Release(pUnkOuter);
} while (refCount);
}
static void test_null_renderer_aggregations(void)
{
const IID * iids[] = {
&IID_IMediaFilter, &IID_IBaseFilter
};
int i;
for (i = 0; i < sizeof(iids) / sizeof(iids[0]); i++)
{
test_aggregation(CLSID_SystemClock, CLSID_NullRenderer, IID_IReferenceClock, *iids[i]);
}
}
static void test_video_renderer_aggregations(void)
{
const IID * iids[] = {
&IID_IMediaFilter, &IID_IBaseFilter, &IID_IBasicVideo, &IID_IVideoWindow
};
int i;
for (i = 0; i < sizeof(iids) / sizeof(iids[0]); i++)
{
test_aggregation(CLSID_SystemClock, CLSID_VideoRenderer,
IID_IReferenceClock, *iids[i]);
}
}
static void test_filter_graph_aggregations(void)
{
const IID * iids[] = {
&IID_IFilterGraph2, &IID_IMediaControl, &IID_IGraphBuilder,
&IID_IFilterGraph, &IID_IMediaSeeking, &IID_IBasicAudio, &IID_IBasicVideo,
&IID_IVideoWindow, &IID_IMediaEventEx, &IID_IMediaFilter,
&IID_IMediaEventSink, &IID_IGraphConfig, &IID_IMediaPosition
};
int i;
for (i = 0; i < sizeof(iids) / sizeof(iids[0]); i++)
{
test_aggregation(CLSID_SystemClock, CLSID_FilterGraph,
IID_IReferenceClock, *iids[i]);
}
}
static void test_filter_mapper_aggregations(void)
{
const IID * iids[] = {
&IID_IFilterMapper2, &IID_IFilterMapper
};
int i;
for (i = 0; i < sizeof(iids) / sizeof(iids[0]); i++)
{
test_aggregation(CLSID_SystemClock, CLSID_FilterMapper2,
IID_IReferenceClock, *iids[i]);
}
}
START_TEST(misc)
{
CoInitialize(NULL);
test_null_renderer_aggregations();
test_video_renderer_aggregations();
test_filter_graph_aggregations();
test_filter_mapper_aggregations();
CoUninitialize();
}