mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / qedit / tests / timeline.c
blob0d01d519fd9cb28a43f0b4f4b47d654e3454c155
1 /*
2 * Unit tests for Timeline
4 * Copyright (C) 2016 Alex Henrie
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 "qedit.h"
23 #include "wine/test.h"
25 static ULONG get_refcount(void *iface)
27 IUnknown *unknown = iface;
28 IUnknown_AddRef(unknown);
29 return IUnknown_Release(unknown);
32 static const GUID test_iid = {0x33333333};
33 static LONG outer_ref = 1;
35 static HRESULT WINAPI outer_QueryInterface(IUnknown *iface, REFIID iid, void **out)
37 if (IsEqualGUID(iid, &IID_IUnknown)
38 || IsEqualGUID(iid, &IID_IAMTimeline)
39 || IsEqualGUID(iid, &test_iid))
41 *out = (IUnknown *)0xdeadbeef;
42 return S_OK;
44 ok(0, "unexpected call %s\n", wine_dbgstr_guid(iid));
45 return E_NOINTERFACE;
48 static ULONG WINAPI outer_AddRef(IUnknown *iface)
50 return InterlockedIncrement(&outer_ref);
53 static ULONG WINAPI outer_Release(IUnknown *iface)
55 return InterlockedDecrement(&outer_ref);
58 static const IUnknownVtbl outer_vtbl =
60 outer_QueryInterface,
61 outer_AddRef,
62 outer_Release,
65 static IUnknown test_outer = {&outer_vtbl};
67 static void test_aggregation(void)
69 IAMTimeline *timeline, *timeline2;
70 IUnknown *unk, *unk2;
71 HRESULT hr;
72 ULONG ref;
74 timeline = (IAMTimeline *)0xdeadbeef;
75 hr = CoCreateInstance(&CLSID_AMTimeline, &test_outer, CLSCTX_INPROC_SERVER,
76 &IID_IAMTimeline, (void **)&timeline);
77 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
78 ok(!timeline, "Got interface %p.\n", timeline);
80 hr = CoCreateInstance(&CLSID_AMTimeline, &test_outer, CLSCTX_INPROC_SERVER,
81 &IID_IUnknown, (void **)&unk);
82 ok(hr == S_OK, "Got hr %#x.\n", hr);
83 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
84 ok(unk != &test_outer, "Returned IUnknown should not be outer IUnknown.\n");
85 ref = get_refcount(unk);
86 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
88 ref = IUnknown_AddRef(unk);
89 ok(ref == 2, "Got unexpected refcount %d.\n", ref);
90 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
92 ref = IUnknown_Release(unk);
93 ok(ref == 1, "Got unexpected refcount %d.\n", ref);
94 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
96 hr = IUnknown_QueryInterface(unk, &IID_IUnknown, (void **)&unk2);
97 ok(hr == S_OK, "Got hr %#x.\n", hr);
98 ok(unk2 == unk, "Got unexpected IUnknown %p.\n", unk2);
99 IUnknown_Release(unk2);
101 hr = IUnknown_QueryInterface(unk, &IID_IAMTimeline, (void **)&timeline);
102 ok(hr == S_OK, "Got hr %#x.\n", hr);
104 hr = IAMTimeline_QueryInterface(timeline, &IID_IUnknown, (void **)&unk2);
105 ok(hr == S_OK, "Got hr %#x.\n", hr);
106 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
108 hr = IAMTimeline_QueryInterface(timeline, &IID_IAMTimeline, (void **)&timeline2);
109 ok(hr == S_OK, "Got hr %#x.\n", hr);
110 ok(timeline2 == (IAMTimeline *)0xdeadbeef, "Got unexpected IAMTimeline %p.\n", timeline2);
112 hr = IUnknown_QueryInterface(unk, &test_iid, (void **)&unk2);
113 ok(hr == E_NOINTERFACE, "Got hr %#x.\n", hr);
114 ok(!unk2, "Got unexpected IUnknown %p.\n", unk2);
116 hr = IAMTimeline_QueryInterface(timeline, &test_iid, (void **)&unk2);
117 ok(hr == S_OK, "Got hr %#x.\n", hr);
118 ok(unk2 == (IUnknown *)0xdeadbeef, "Got unexpected IUnknown %p.\n", unk2);
120 IAMTimeline_Release(timeline);
121 ref = IUnknown_Release(unk);
122 ok(!ref, "Got unexpected refcount %d.\n", ref);
123 ok(outer_ref == 1, "Got unexpected refcount %d.\n", outer_ref);
126 static void test_timeline(void)
128 HRESULT hr;
129 IAMTimeline *timeline = NULL;
130 IAMTimeline *timeline2 = (IAMTimeline *)0xdeadbeef;
131 IAMTimelineObj *obj = (IAMTimelineObj *)0xdeadbeef;
132 IAMTimelineObj obj_iface;
133 TIMELINE_MAJOR_TYPE type;
135 hr = CoCreateInstance(&CLSID_AMTimeline, NULL, CLSCTX_INPROC_SERVER, &IID_IAMTimeline, (void **)&timeline);
136 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "CoCreateInstance failed: %08x\n", hr);
137 if (!timeline) return;
139 hr = IAMTimeline_QueryInterface(timeline, &IID_IAMTimelineObj, NULL);
140 ok(hr == E_POINTER, "Expected E_POINTER got %08x\n", hr);
142 hr = IAMTimeline_QueryInterface(timeline, &IID_IAMTimelineObj, (void **)&obj);
143 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE got %08x\n", hr);
144 ok(!obj, "Expected NULL got %p\n", obj);
146 hr = IAMTimeline_CreateEmptyNode(timeline, NULL, 0);
147 ok(hr == E_POINTER, "Expected E_POINTER got %08x\n", hr);
149 hr = IAMTimeline_CreateEmptyNode(timeline, NULL, TIMELINE_MAJOR_TYPE_COMPOSITE);
150 ok(hr == E_POINTER, "Expected E_POINTER got %08x\n", hr);
152 for (type = 0; type < 256; type++)
154 obj = &obj_iface;
155 hr = IAMTimeline_CreateEmptyNode(timeline, &obj, type);
156 switch (type)
158 case TIMELINE_MAJOR_TYPE_COMPOSITE:
159 case TIMELINE_MAJOR_TYPE_TRACK:
160 case TIMELINE_MAJOR_TYPE_SOURCE:
161 case TIMELINE_MAJOR_TYPE_TRANSITION:
162 case TIMELINE_MAJOR_TYPE_EFFECT:
163 case TIMELINE_MAJOR_TYPE_GROUP:
164 ok(hr == S_OK, "CreateEmptyNode failed: %08x\n", hr);
165 if (obj != &obj_iface) IAMTimelineObj_Release(obj);
166 break;
167 default:
168 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", hr);
169 ok(obj == &obj_iface, "Expected %p got %p\n", &obj_iface, obj);
173 obj = NULL;
174 hr = IAMTimeline_CreateEmptyNode(timeline, &obj, TIMELINE_MAJOR_TYPE_COMPOSITE);
175 ok(hr == S_OK, "CreateEmptyNode failed: %08x\n", hr);
176 if (!obj) return;
178 hr = IAMTimelineObj_QueryInterface(obj, &IID_IAMTimeline, NULL);
179 ok(hr == E_POINTER, "Expected E_POINTER got %08x\n", hr);
181 hr = IAMTimelineObj_QueryInterface(obj, &IID_IAMTimeline, (void **)&timeline2);
182 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE got %08x\n", hr);
183 ok(!timeline2, "Expected NULL got %p\n", timeline2);
185 hr = IAMTimelineObj_GetTimelineType(obj, NULL);
186 ok(hr == E_POINTER, "Expected E_POINTER got %08x\n", hr);
188 hr = IAMTimelineObj_GetTimelineType(obj, &type);
189 ok(hr == S_OK, "GetTimelineType failed: %08x\n", hr);
190 ok(type == TIMELINE_MAJOR_TYPE_COMPOSITE, "Expected TIMELINE_MAJOR_TYPE_COMPOSITE got %d\n", type);
192 for (type = 0; type < 256; type++)
194 hr = IAMTimelineObj_SetTimelineType(obj, type);
195 if (type == TIMELINE_MAJOR_TYPE_COMPOSITE)
196 ok(hr == S_OK, "SetTimelineType failed: %08x\n", hr);
197 else
198 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG got %08x\n", hr);
201 hr = IAMTimelineObj_GetTimelineNoRef(obj, NULL);
202 ok(hr == E_POINTER, "Expected E_POINTER got %08x\n", hr);
204 timeline2 = (IAMTimeline *)0xdeadbeef;
205 hr = IAMTimelineObj_GetTimelineNoRef(obj, &timeline2);
206 ok(hr == E_NOINTERFACE, "Expected E_NOINTERFACE got %08x\n", hr);
207 ok(!timeline2, "Expected NULL got %p\n", timeline2);
209 IAMTimelineObj_Release(obj);
210 IAMTimeline_Release(timeline);
213 static void test_timelineobj_interfaces(void)
215 HRESULT hr;
216 IAMTimeline *timeline = NULL;
217 IAMTimelineObj *obj;
219 hr = CoCreateInstance(&CLSID_AMTimeline, NULL, CLSCTX_INPROC_SERVER, &IID_IAMTimeline, (void **)&timeline);
220 ok(hr == S_OK || broken(hr == REGDB_E_CLASSNOTREG), "CoCreateInstance failed: %08x\n", hr);
221 if (!timeline)
222 return;
224 hr = IAMTimeline_CreateEmptyNode(timeline, &obj, TIMELINE_MAJOR_TYPE_GROUP);
225 ok(hr == S_OK, "CreateEmptyNode failed: %08x\n", hr);
226 if(hr == S_OK)
228 IAMTimelineGroup *group;
229 IAMTimelineObj *obj2;
231 hr = IAMTimelineObj_QueryInterface(obj, &IID_IAMTimelineGroup, (void **)&group);
232 ok(hr == S_OK, "got %08x\n", hr);
234 hr = IAMTimelineGroup_QueryInterface(group, &IID_IAMTimelineObj, (void **)&obj2);
235 ok(hr == S_OK, "got %08x\n", hr);
236 ok(obj == obj2, "Different pointers\n");
237 IAMTimelineObj_Release(obj2);
239 IAMTimelineGroup_Release(group);
241 IAMTimelineObj_Release(obj);
244 IAMTimeline_Release(timeline);
247 START_TEST(timeline)
249 IAMTimeline *timeline;
250 HRESULT hr;
252 CoInitialize(NULL);
254 if (FAILED(hr = CoCreateInstance(&CLSID_AMTimeline, NULL, CLSCTX_INPROC_SERVER,
255 &IID_IAMTimeline, (void **)&timeline)))
257 /* qedit.dll does not exist on 2003. */
258 win_skip("Failed to create timeline object, hr %#x.\n", hr);
259 return;
261 IAMTimeline_Release(timeline);
263 test_aggregation();
264 test_timeline();
265 test_timelineobj_interfaces();
267 CoUninitialize();