2 * Misc unit tests for Quartz
4 * Copyright (C) 2007 Google (Lei Zhang)
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
23 #include "wine/test.h"
26 #define QI_SUCCEED(iface, riid, ppv) hr = IUnknown_QueryInterface(iface, &riid, (LPVOID*)&ppv); \
27 ok(hr == S_OK, "IUnknown_QueryInterface returned %x\n", hr); \
28 ok(ppv != NULL, "Pointer is NULL\n");
30 #define QI_FAIL(iface, riid, ppv) hr = IUnknown_QueryInterface(iface, &riid, (LPVOID*)&ppv); \
31 ok(hr == E_NOINTERFACE, "IUnknown_QueryInterface returned %x\n", hr); \
32 ok(ppv == NULL, "Pointer is %p\n", ppv);
34 #define ADDREF_EXPECT(iface, num) if (iface) { \
35 hr = IUnknown_AddRef(iface); \
36 ok(hr == num, "IUnknown_AddRef should return %d, got %d\n", num, hr); \
39 #define RELEASE_EXPECT(iface, num) if (iface) { \
40 hr = IUnknown_Release(iface); \
41 ok(hr == num, "IUnknown_Release should return %d, got %d\n", num, hr); \
44 static void test_aggregation(const CLSID clsidOuter
, const CLSID clsidInner
,
45 const IID iidOuter
, const IID iidInner
)
48 IUnknown
*pUnkOuter
= NULL
;
49 IUnknown
*pUnkInner
= NULL
;
50 IUnknown
*pUnkInnerFail
= NULL
;
51 IUnknown
*pUnkOuterTest
= NULL
;
52 IUnknown
*pUnkInnerTest
= NULL
;
53 IUnknown
*pUnkAggregatee
= NULL
;
54 IUnknown
*pUnkAggregator
= NULL
;
55 IUnknown
*pUnkTest
= NULL
;
57 hr
= CoCreateInstance(&clsidOuter
, NULL
, CLSCTX_INPROC_SERVER
,
58 &IID_IUnknown
, (LPVOID
*)&pUnkOuter
);
59 ok(hr
== S_OK
, "CoCreateInstance failed with %x\n", hr
);
60 ok(pUnkOuter
!= NULL
, "pUnkOuter is NULL\n");
64 skip("pUnkOuter is NULL\n");
68 /* for aggregation, we should only be able to request IUnknown */
69 hr
= CoCreateInstance(&clsidInner
, pUnkOuter
, CLSCTX_INPROC_SERVER
,
70 &iidInner
, (LPVOID
*)&pUnkInnerFail
);
71 ok(hr
== E_NOINTERFACE
, "CoCreateInstance returned %x\n", hr
);
72 ok(pUnkInnerFail
== NULL
, "pUnkInnerFail is not NULL\n");
74 /* aggregation, request IUnknown */
75 hr
= CoCreateInstance(&clsidInner
, pUnkOuter
, CLSCTX_INPROC_SERVER
,
76 &IID_IUnknown
, (LPVOID
*)&pUnkInner
);
77 ok(hr
== S_OK
, "CoCreateInstance returned %x\n", hr
);
78 ok(pUnkInner
!= NULL
, "pUnkInner is NULL\n");
82 skip("pUnkInner is NULL\n");
86 ADDREF_EXPECT(pUnkOuter
, 2);
87 ADDREF_EXPECT(pUnkInner
, 2);
88 RELEASE_EXPECT(pUnkOuter
, 1);
89 RELEASE_EXPECT(pUnkInner
, 1);
91 QI_FAIL(pUnkOuter
, iidInner
, pUnkAggregatee
);
92 QI_FAIL(pUnkInner
, iidOuter
, pUnkAggregator
);
94 /* these QueryInterface calls should work */
95 QI_SUCCEED(pUnkOuter
, iidOuter
, pUnkAggregator
);
96 QI_SUCCEED(pUnkOuter
, IID_IUnknown
, pUnkOuterTest
);
97 QI_SUCCEED(pUnkInner
, iidInner
, pUnkAggregatee
);
98 QI_SUCCEED(pUnkInner
, IID_IUnknown
, pUnkInnerTest
);
100 if (!pUnkAggregator
|| !pUnkOuterTest
|| !pUnkAggregatee
103 skip("One of the required interfaces is NULL\n");
107 ADDREF_EXPECT(pUnkAggregator
, 5);
108 ADDREF_EXPECT(pUnkOuterTest
, 6);
109 ADDREF_EXPECT(pUnkAggregatee
, 7);
110 ADDREF_EXPECT(pUnkInnerTest
, 3);
111 RELEASE_EXPECT(pUnkAggregator
, 6);
112 RELEASE_EXPECT(pUnkOuterTest
, 5);
113 RELEASE_EXPECT(pUnkAggregatee
, 4);
114 RELEASE_EXPECT(pUnkInnerTest
, 2);
116 QI_SUCCEED(pUnkAggregator
, IID_IUnknown
, pUnkTest
);
117 QI_SUCCEED(pUnkOuterTest
, IID_IUnknown
, pUnkTest
);
118 QI_SUCCEED(pUnkAggregatee
, IID_IUnknown
, pUnkTest
);
119 QI_SUCCEED(pUnkInnerTest
, IID_IUnknown
, pUnkTest
);
121 QI_FAIL(pUnkAggregator
, iidInner
, pUnkTest
);
122 QI_FAIL(pUnkOuterTest
, iidInner
, pUnkTest
);
123 QI_FAIL(pUnkAggregatee
, iidInner
, pUnkTest
);
124 QI_SUCCEED(pUnkInnerTest
, iidInner
, pUnkTest
);
126 QI_SUCCEED(pUnkAggregator
, iidOuter
, pUnkTest
);
127 QI_SUCCEED(pUnkOuterTest
, iidOuter
, pUnkTest
);
128 QI_SUCCEED(pUnkAggregatee
, iidOuter
, pUnkTest
);
129 QI_FAIL(pUnkInnerTest
, iidOuter
, pUnkTest
);
131 RELEASE_EXPECT(pUnkAggregator
, 10);
132 RELEASE_EXPECT(pUnkOuterTest
, 9);
133 RELEASE_EXPECT(pUnkAggregatee
, 8);
134 RELEASE_EXPECT(pUnkInnerTest
, 2);
135 RELEASE_EXPECT(pUnkOuter
, 7);
136 RELEASE_EXPECT(pUnkInner
, 1);
139 static void test_video_renderer_aggregations(void)
141 const IID
* iids
[] = {
142 &IID_IMediaFilter
, &IID_IBaseFilter
, &IID_IBasicVideo
, &IID_IVideoWindow
146 for (i
= 0; i
< sizeof(iids
) / sizeof(iids
[0]); i
++)
148 test_aggregation(CLSID_SystemClock
, CLSID_VideoRenderer
,
149 IID_IReferenceClock
, *iids
[i
]);
153 static void test_filter_graph_aggregations(void)
155 const IID
* iids
[] = {
156 &IID_IFilterGraph2
, &IID_IMediaControl
, &IID_IGraphBuilder
,
157 &IID_IFilterGraph
, &IID_IMediaSeeking
, &IID_IBasicAudio
, &IID_IBasicVideo
,
158 &IID_IVideoWindow
, &IID_IMediaEventEx
, &IID_IMediaFilter
,
159 &IID_IMediaEventSink
, &IID_IGraphConfig
, &IID_IMediaPosition
163 for (i
= 0; i
< sizeof(iids
) / sizeof(iids
[0]); i
++)
165 test_aggregation(CLSID_SystemClock
, CLSID_FilterGraph
,
166 IID_IReferenceClock
, *iids
[i
]);
174 test_video_renderer_aggregations();
175 test_filter_graph_aggregations();