dmcompos: Use the generic IPersistStream for DMChordMapTrack.
[wine.git] / dlls / dmcompos / tests / dmcompos.c
blob0ca559973e936495031389df24c05bad00ae8073
1 /*
2 * Copyright 2014 Michael Stefaniuc
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #define COBJMACROS
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <initguid.h>
24 #include <wine/test.h>
25 #include <dmusici.h>
27 #define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
29 static BOOL missing_dmcompos(void)
31 IDirectMusicComposer *dmc;
32 HRESULT hr = CoCreateInstance(&CLSID_DirectMusicComposer, NULL, CLSCTX_INPROC_SERVER,
33 &IID_IDirectMusicComposer, (void**)&dmc);
35 if (hr == S_OK && dmc)
37 IDirectMusicComposer_Release(dmc);
38 return FALSE;
40 return TRUE;
43 static void test_COM(void)
45 IDirectMusicComposer *dmc = (IDirectMusicComposer*)0xdeadbeef;
46 IUnknown *unk;
47 ULONG refcount;
48 HRESULT hr;
50 /* COM aggregation */
51 hr = CoCreateInstance(&CLSID_DirectMusicComposer, (IUnknown*)&dmc, CLSCTX_INPROC_SERVER,
52 &IID_IUnknown, (void**)&dmc);
53 ok(hr == CLASS_E_NOAGGREGATION,
54 "DirectMusicComposer create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
55 ok(!dmc, "dmc = %p\n", dmc);
57 /* Invalid RIID */
58 hr = CoCreateInstance(&CLSID_DirectMusicComposer, NULL, CLSCTX_INPROC_SERVER,
59 &IID_IDirectMusicObject, (void**)&dmc);
60 ok(hr == E_NOINTERFACE,
61 "DirectMusicComposer create failed: %08x, expected E_NOINTERFACE\n", hr);
63 /* Same refcount for all DirectMusicComposer interfaces */
64 hr = CoCreateInstance(&CLSID_DirectMusicComposer, NULL, CLSCTX_INPROC_SERVER,
65 &IID_IDirectMusicComposer, (void**)&dmc);
66 ok(hr == S_OK, "DirectMusicComposer create failed: %08x, expected S_OK\n", hr);
67 refcount = IDirectMusicComposer_AddRef(dmc);
68 ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
70 hr = IDirectMusicComposer_QueryInterface(dmc, &IID_IUnknown, (void**)&unk);
71 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
72 refcount = IUnknown_AddRef(unk);
73 ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
74 refcount = IUnknown_Release(unk);
76 while (IDirectMusicComposer_Release(dmc));
79 static void test_COM_chordmap(void)
81 IDirectMusicChordMap *dmcm = (IDirectMusicChordMap*)0xdeadbeef;
82 IDirectMusicObject *dmo;
83 IPersistStream *ps;
84 IUnknown *unk;
85 ULONG refcount;
86 HRESULT hr;
88 /* COM aggregation */
89 hr = CoCreateInstance(&CLSID_DirectMusicChordMap, (IUnknown*)&dmcm, CLSCTX_INPROC_SERVER,
90 &IID_IUnknown, (void**)&dmcm);
91 ok(hr == CLASS_E_NOAGGREGATION,
92 "DirectMusicChordMap create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
93 ok(!dmcm, "dmcm = %p\n", dmcm);
95 /* Invalid RIID */
96 hr = CoCreateInstance(&CLSID_DirectMusicChordMap, NULL, CLSCTX_INPROC_SERVER,
97 &IID_IClassFactory, (void**)&dmcm);
98 ok(hr == E_NOINTERFACE,
99 "DirectMusicChordMap create failed: %08x, expected E_NOINTERFACE\n", hr);
101 /* Same refcount for all DirectMusicChordMap interfaces */
102 hr = CoCreateInstance(&CLSID_DirectMusicChordMap, NULL, CLSCTX_INPROC_SERVER,
103 &IID_IDirectMusicChordMap, (void**)&dmcm);
104 ok(hr == S_OK, "DirectMusicChordMap create failed: %08x, expected S_OK\n", hr);
105 refcount = IDirectMusicChordMap_AddRef(dmcm);
106 ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
108 hr = IDirectMusicChordMap_QueryInterface(dmcm, &IID_IDirectMusicObject, (void**)&dmo);
109 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicObject failed: %08x\n", hr);
110 refcount = IDirectMusicObject_AddRef(dmo);
111 ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
112 refcount = IDirectMusicObject_Release(dmo);
114 hr = IDirectMusicChordMap_QueryInterface(dmcm, &IID_IPersistStream, (void**)&ps);
115 ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
116 refcount = IPersistStream_AddRef(ps);
117 ok(refcount == 5, "refcount == %u, expected 5\n", refcount);
118 refcount = IPersistStream_Release(ps);
120 hr = IDirectMusicChordMap_QueryInterface(dmcm, &IID_IUnknown, (void**)&unk);
121 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
122 refcount = IUnknown_AddRef(unk);
123 ok(refcount == 6, "refcount == %u, expected 6\n", refcount);
124 refcount = IUnknown_Release(unk);
126 while (IDirectMusicChordMap_Release(dmcm));
129 static void test_COM_template(void)
131 IPersistStream *ps = (IPersistStream*)0xdeadbeef;
132 IUnknown *unk;
133 ULONG refcount;
134 HRESULT hr;
136 /* COM aggregation */
137 hr = CoCreateInstance(&CLSID_DirectMusicTemplate, (IUnknown*)&ps, CLSCTX_INPROC_SERVER,
138 &IID_IUnknown, (void**)&ps);
139 ok(hr == CLASS_E_NOAGGREGATION,
140 "DirectMusicTemplate create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
141 ok(!ps, "ps = %p\n", ps);
143 /* Invalid RIID */
144 hr = CoCreateInstance(&CLSID_DirectMusicTemplate, NULL, CLSCTX_INPROC_SERVER,
145 &IID_IDirectMusicObject, (void**)&ps);
146 todo_wine ok(hr == E_NOINTERFACE,
147 "DirectMusicTemplate create failed: %08x, expected E_NOINTERFACE\n", hr);
149 /* Same refcount for all DirectMusicTemplate interfaces */
150 hr = CoCreateInstance(&CLSID_DirectMusicTemplate, NULL, CLSCTX_INPROC_SERVER,
151 &IID_IPersistStream, (void**)&ps);
152 todo_wine ok(hr == S_OK, "DirectMusicTemplate create failed: %08x, expected S_OK\n", hr);
153 if (hr != S_OK) {
154 skip("DirectMusicTemplate not implemented\n");
155 return;
157 refcount = IPersistStream_AddRef(ps);
158 ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
160 hr = IPersistStream_QueryInterface(ps, &IID_IUnknown, (void**)&unk);
161 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
162 refcount = IUnknown_AddRef(unk);
163 ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
164 refcount = IUnknown_Release(unk);
166 while (IPersistStream_Release(ps));
169 static void test_COM_track(void)
171 IDirectMusicTrack8 *dmt8;
172 IPersistStream *ps;
173 IUnknown *unk;
174 ULONG refcount;
175 HRESULT hr;
176 #define X(class) &CLSID_ ## class, #class
177 const struct {
178 REFCLSID clsid;
179 const char *name;
180 } class[] = {
181 { X(DirectMusicChordMapTrack) },
182 { X(DirectMusicSignPostTrack) },
184 #undef X
185 unsigned int i;
187 for (i = 0; i < ARRAY_SIZE(class); i++) {
188 /* COM aggregation */
189 dmt8 = (IDirectMusicTrack8*)0xdeadbeef;
190 hr = CoCreateInstance(class[i].clsid, (IUnknown*)&dmt8, CLSCTX_INPROC_SERVER, &IID_IUnknown,
191 (void**)&dmt8);
192 if (hr == REGDB_E_CLASSNOTREG) {
193 win_skip("%s not registered\n", class[i].name);
194 continue;
196 ok(hr == CLASS_E_NOAGGREGATION,
197 "%s create failed: %08x, expected CLASS_E_NOAGGREGATION\n", class[i].name, hr);
198 ok(!dmt8, "dmt8 = %p\n", dmt8);
200 /* Invalid RIID */
201 hr = CoCreateInstance(class[i].clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicObject,
202 (void**)&dmt8);
203 ok(hr == E_NOINTERFACE, "%s create failed: %08x, expected E_NOINTERFACE\n",
204 class[i].name, hr);
206 /* Same refcount for all DirectMusicTrack interfaces */
207 hr = CoCreateInstance(class[i].clsid, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicTrack8,
208 (void**)&dmt8);
209 if (hr == E_NOINTERFACE && !dmt8) {
210 skip("%s not created with CoCreateInstance()\n", class[i].name);
211 continue;
213 ok(hr == S_OK, "%s create failed: %08x, expected S_OK\n", class[i].name, hr);
214 refcount = IDirectMusicTrack8_AddRef(dmt8);
215 ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
217 hr = IDirectMusicTrack8_QueryInterface(dmt8, &IID_IPersistStream, (void**)&ps);
218 ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
219 refcount = IPersistStream_AddRef(ps);
220 ok(refcount == 4, "refcount == %u, expected 4\n", refcount);
221 IPersistStream_Release(ps);
223 hr = IDirectMusicTrack8_QueryInterface(dmt8, &IID_IUnknown, (void**)&unk);
224 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
225 refcount = IUnknown_AddRef(unk);
226 ok(refcount == 5, "refcount == %u, expected 5\n", refcount);
227 refcount = IUnknown_Release(unk);
229 while (IDirectMusicTrack8_Release(dmt8));
233 static void test_chordmap(void)
235 IDirectMusicChordMap *dmcm;
236 IPersistStream *ps;
237 CLSID class = { 0 };
238 ULARGE_INTEGER size;
239 HRESULT hr;
241 hr = CoCreateInstance(&CLSID_DirectMusicChordMap, NULL, CLSCTX_INPROC_SERVER,
242 &IID_IDirectMusicChordMap, (void**)&dmcm);
243 ok(hr == S_OK, "DirectMusicChordMap create failed: %08x, expected S_OK\n", hr);
245 /* IPersistStream */
246 hr = IDirectMusicChordMap_QueryInterface(dmcm, &IID_IPersistStream, (void**)&ps);
247 ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
248 hr = IPersistStream_GetClassID(ps, &class);
249 ok(hr == S_OK, "IPersistStream_GetClassID failed: %08x\n", hr);
250 ok(IsEqualGUID(&class, &CLSID_DirectMusicChordMap),
251 "Expected class CLSID_DirectMusicChordMap got %s\n", wine_dbgstr_guid(&class));
253 /* Unimplemented IPersistStream methods */
254 hr = IPersistStream_IsDirty(ps);
255 ok(hr == S_FALSE, "IPersistStream_IsDirty failed: %08x\n", hr);
256 hr = IPersistStream_GetSizeMax(ps, &size);
257 ok(hr == E_NOTIMPL, "IPersistStream_GetSizeMax failed: %08x\n", hr);
258 hr = IPersistStream_Save(ps, NULL, TRUE);
259 ok(hr == E_NOTIMPL, "IPersistStream_Save failed: %08x\n", hr);
261 while (IDirectMusicChordMap_Release(dmcm));
264 static void test_chordmaptrack(void)
266 IDirectMusicTrack8 *dmt8;
267 IPersistStream *ps;
268 CLSID class;
269 ULARGE_INTEGER size;
270 HRESULT hr;
272 hr = CoCreateInstance(&CLSID_DirectMusicChordMapTrack, NULL, CLSCTX_INPROC_SERVER,
273 &IID_IDirectMusicTrack8, (void**)&dmt8);
274 ok(hr == S_OK, "DirectMusicChordMapTrack create failed: %08x, expected S_OK\n", hr);
276 /* IDirectMusicTrack8 */
277 hr = IDirectMusicTrack8_Init(dmt8, NULL);
278 ok(hr == S_OK, "IDirectMusicTrack8_Init failed: %08x\n", hr);
279 hr = IDirectMusicTrack8_InitPlay(dmt8, NULL, NULL, NULL, 0, 0);
280 ok(hr == S_OK, "IDirectMusicTrack8_InitPlay failed: %08x\n", hr);
281 hr = IDirectMusicTrack8_EndPlay(dmt8, NULL);
282 ok(hr == S_OK, "IDirectMusicTrack8_EndPlay failed: %08x\n", hr);
283 hr = IDirectMusicTrack8_Play(dmt8, NULL, 0, 0, 0, 0, NULL, NULL, 0);
284 ok(hr == S_OK, "IDirectMusicTrack8_Play failed: %08x\n", hr);
285 todo_wine {
286 hr = IDirectMusicTrack8_GetParam(dmt8, NULL, 0, NULL, NULL);
287 ok(hr == E_POINTER, "IDirectMusicTrack8_GetParam failed: %08x\n", hr);
288 hr = IDirectMusicTrack8_SetParam(dmt8, NULL, 0, NULL);
289 ok(hr == E_POINTER, "IDirectMusicTrack8_SetParam failed: %08x\n", hr);
291 hr = IDirectMusicTrack8_IsParamSupported(dmt8, NULL);
292 ok(hr == E_POINTER, "IDirectMusicTrack8_IsParamSupported failed: %08x\n", hr);
293 hr = IDirectMusicTrack8_AddNotificationType(dmt8, NULL);
294 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_AddNotificationType failed: %08x\n", hr);
295 hr = IDirectMusicTrack8_RemoveNotificationType(dmt8, NULL);
296 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_RemoveNotificationType failed: %08x\n", hr);
297 todo_wine {
298 hr = IDirectMusicTrack8_Clone(dmt8, 0, 0, NULL);
299 ok(hr == E_POINTER, "IDirectMusicTrack8_Clone failed: %08x\n", hr);
300 hr = IDirectMusicTrack8_PlayEx(dmt8, NULL, 0, 0, 0, 0, NULL, NULL, 0);
301 ok(hr == E_POINTER, "IDirectMusicTrack8_PlayEx failed: %08x\n", hr);
302 hr = IDirectMusicTrack8_GetParamEx(dmt8, NULL, 0, NULL, NULL, NULL, 0);
303 ok(hr == E_POINTER, "IDirectMusicTrack8_GetParamEx failed: %08x\n", hr);
304 hr = IDirectMusicTrack8_SetParamEx(dmt8, NULL, 0, NULL, NULL, 0);
305 ok(hr == E_POINTER, "IDirectMusicTrack8_SetParamEx failed: %08x\n", hr);
307 hr = IDirectMusicTrack8_Compose(dmt8, NULL, 0, NULL);
308 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_Compose failed: %08x\n", hr);
309 hr = IDirectMusicTrack8_Join(dmt8, NULL, 0, NULL, 0, NULL);
310 todo_wine ok(hr == E_POINTER, "IDirectMusicTrack8_Join failed: %08x\n", hr);
312 /* IPersistStream */
313 hr = IDirectMusicTrack8_QueryInterface(dmt8, &IID_IPersistStream, (void**)&ps);
314 ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
315 hr = IPersistStream_GetClassID(ps, &class);
316 ok(hr == S_OK, "IPersistStream_GetClassID failed: %08x\n", hr);
317 ok(IsEqualGUID(&class, &CLSID_DirectMusicChordMapTrack),
318 "Expected class CLSID_DirectMusicChordMapTrack got %s\n", wine_dbgstr_guid(&class));
320 /* Unimplemented IPersistStream methods */
321 hr = IPersistStream_IsDirty(ps);
322 ok(hr == S_FALSE, "IPersistStream_IsDirty failed: %08x\n", hr);
323 hr = IPersistStream_GetSizeMax(ps, &size);
324 ok(hr == E_NOTIMPL, "IPersistStream_GetSizeMax failed: %08x\n", hr);
325 hr = IPersistStream_Save(ps, NULL, TRUE);
326 ok(hr == E_NOTIMPL, "IPersistStream_Save failed: %08x\n", hr);
328 while (IDirectMusicTrack8_Release(dmt8));
331 static void test_signposttrack(void)
333 IDirectMusicTrack8 *dmt8;
334 IPersistStream *ps;
335 CLSID class;
336 ULARGE_INTEGER size;
337 HRESULT hr;
339 hr = CoCreateInstance(&CLSID_DirectMusicSignPostTrack, NULL, CLSCTX_INPROC_SERVER,
340 &IID_IDirectMusicTrack8, (void**)&dmt8);
341 ok(hr == S_OK, "DirectMusicSignPostTrack create failed: %08x, expected S_OK\n", hr);
343 /* IDirectMusicTrack8 */
344 hr = IDirectMusicTrack8_Init(dmt8, NULL);
345 ok(hr == S_OK, "IDirectMusicTrack8_Init failed: %08x\n", hr);
346 if (0) {
347 /* Crashes on Windows */
348 hr = IDirectMusicTrack8_InitPlay(dmt8, NULL, NULL, NULL, 0, 0);
349 ok(hr == E_POINTER, "IDirectMusicTrack8_InitPlay failed: %08x\n", hr);
351 hr = IDirectMusicTrack8_EndPlay(dmt8, NULL);
352 ok(hr == S_OK, "IDirectMusicTrack8_EndPlay failed: %08x\n", hr);
353 hr = IDirectMusicTrack8_Play(dmt8, NULL, 0, 0, 0, 0, NULL, NULL, 0);
354 ok(hr == S_OK, "IDirectMusicTrack8_Play failed: %08x\n", hr);
355 hr = IDirectMusicTrack8_GetParam(dmt8, NULL, 0, NULL, NULL);
356 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_GetParam failed: %08x\n", hr);
357 hr = IDirectMusicTrack8_SetParam(dmt8, NULL, 0, NULL);
358 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_SetParam failed: %08x\n", hr);
359 hr = IDirectMusicTrack8_IsParamSupported(dmt8, NULL);
360 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_IsParamSupported failed: %08x\n", hr);
361 todo_wine {
362 hr = IDirectMusicTrack8_AddNotificationType(dmt8, NULL);
363 ok(hr == E_POINTER, "IDirectMusicTrack8_AddNotificationType failed: %08x\n", hr);
364 hr = IDirectMusicTrack8_RemoveNotificationType(dmt8, NULL);
365 ok(hr == E_POINTER, "IDirectMusicTrack8_RemoveNotificationType failed: %08x\n", hr);
366 hr = IDirectMusicTrack8_Clone(dmt8, 0, 0, NULL);
367 ok(hr == E_POINTER, "IDirectMusicTrack8_Clone failed: %08x\n", hr);
368 hr = IDirectMusicTrack8_PlayEx(dmt8, NULL, 0, 0, 0, 0, NULL, NULL, 0);
369 ok(hr == E_POINTER, "IDirectMusicTrack8_PlayEx failed: %08x\n", hr);
371 hr = IDirectMusicTrack8_GetParamEx(dmt8, NULL, 0, NULL, NULL, NULL, 0);
372 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_GetParamEx failed: %08x\n", hr);
373 hr = IDirectMusicTrack8_SetParamEx(dmt8, NULL, 0, NULL, NULL, 0);
374 ok(hr == E_NOTIMPL, "IDirectMusicTrack8_SetParamEx failed: %08x\n", hr);
375 todo_wine {
376 hr = IDirectMusicTrack8_Compose(dmt8, NULL, 0, NULL);
377 ok(hr == E_POINTER, "IDirectMusicTrack8_Compose failed: %08x\n", hr);
378 hr = IDirectMusicTrack8_Join(dmt8, NULL, 0, NULL, 0, NULL);
379 ok(hr == E_POINTER, "IDirectMusicTrack8_Join failed: %08x\n", hr);
382 /* IPersistStream */
383 hr = IDirectMusicTrack8_QueryInterface(dmt8, &IID_IPersistStream, (void**)&ps);
384 ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
385 hr = IPersistStream_GetClassID(ps, &class);
386 todo_wine ok(hr == S_OK, "IPersistStream_GetClassID failed: %08x\n", hr);
387 todo_wine ok(IsEqualGUID(&class, &CLSID_DirectMusicSignPostTrack),
388 "Expected class CLSID_DirectMusicSignPostTrack got %s\n", wine_dbgstr_guid(&class));
389 hr = IPersistStream_Save(ps, NULL, TRUE);
390 todo_wine ok(hr == E_POINTER, "IPersistStream_Save failed: %08x\n", hr);
392 /* Unimplemented IPersistStream methods */
393 hr = IPersistStream_IsDirty(ps);
394 todo_wine ok(hr == S_FALSE, "IPersistStream_IsDirty failed: %08x\n", hr);
395 hr = IPersistStream_GetSizeMax(ps, &size);
396 ok(hr == E_NOTIMPL, "IPersistStream_GetSizeMax failed: %08x\n", hr);
398 while (IDirectMusicTrack8_Release(dmt8));
401 START_TEST(dmcompos)
403 CoInitialize(NULL);
405 if (missing_dmcompos())
407 skip("dmcompos not available\n");
408 CoUninitialize();
409 return;
411 test_COM();
412 test_COM_chordmap();
413 test_COM_template();
414 test_COM_track();
415 test_chordmap();
416 test_chordmaptrack();
417 test_signposttrack();
419 CoUninitialize();