makefiles: Don't use standard libs for programs that specify -nodefaultlibs.
[wine/zf.git] / dlls / dmime / tests / performance.c
blobcec89ca80aa922c39dcccbb24889abb0ce7c600d
1 /*
2 * Unit test suite for IDirectMusicPerformance
4 * Copyright 2010 Austin Lund
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
23 #include <stdarg.h>
24 #include <windef.h>
25 #include <initguid.h>
26 #include <wine/test.h>
27 #include <dmusici.h>
29 #include <stdio.h>
31 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
32 DEFINE_GUID(GUID_Bunk,0xFFFFFFFF,0xFFFF,0xFFFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF);
34 static void create_performance(IDirectMusicPerformance8 **performance, IDirectMusic **dmusic,
35 IDirectSound **dsound, BOOL set_cooplevel)
37 HRESULT hr;
39 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
40 &IID_IDirectMusicPerformance8, (void **)performance);
41 ok(hr == S_OK, "DirectMusicPerformance create failed: %08x\n", hr);
42 if (dmusic) {
43 hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic8,
44 (void **)dmusic);
45 ok(hr == S_OK, "DirectMusic create failed: %08x\n", hr);
47 if (dsound) {
48 hr = DirectSoundCreate8(NULL, (IDirectSound8 **)dsound, NULL);
49 ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr);
50 if (set_cooplevel) {
51 hr = IDirectSound_SetCooperativeLevel(*dsound, GetForegroundWindow(), DSSCL_PRIORITY);
52 ok(hr == S_OK, "SetCooperativeLevel failed: %08x\n", hr);
57 static void destroy_performance(IDirectMusicPerformance8 *performance, IDirectMusic *dmusic,
58 IDirectSound *dsound)
60 HRESULT hr;
62 hr = IDirectMusicPerformance8_CloseDown(performance);
63 ok(hr == S_OK, "CloseDown failed: %08x\n", hr);
64 IDirectMusicPerformance8_Release(performance);
65 if (dmusic)
66 IDirectMusic_Release(dmusic);
67 if (dsound)
68 IDirectSound_Release(dsound);
71 static ULONG get_refcount(void *iface)
73 IUnknown *unknown = iface;
74 IUnknown_AddRef(unknown);
75 return IUnknown_Release(unknown);
78 static HRESULT test_InitAudio(void)
80 IDirectMusicPerformance8 *performance;
81 IDirectMusic *dmusic;
82 IDirectSound *dsound;
83 IDirectMusicPort *port;
84 IDirectMusicAudioPath *path;
85 DWORD channel, group;
86 HRESULT hr;
87 ULONG ref;
89 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
90 &IID_IDirectMusicPerformance8, (void **)&performance);
91 if (hr != S_OK) {
92 skip("Cannot create DirectMusicPerformance object (%x)\n", hr);
93 CoUninitialize();
94 return hr;
97 dsound = NULL;
98 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL,
99 DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL);
100 if (hr != S_OK) {
101 IDirectMusicPerformance8_Release(performance);
102 return hr;
105 hr = IDirectMusicPerformance8_PChannelInfo(performance, 128, &port, NULL, NULL);
106 ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x\n", hr);
107 hr = IDirectMusicPerformance8_PChannelInfo(performance, 127, &port, NULL, NULL);
108 ok(hr == S_OK, "PChannelInfo failed, got %08x\n", hr);
109 IDirectMusicPort_Release(port);
110 port = NULL;
111 hr = IDirectMusicPerformance8_PChannelInfo(performance, 0, &port, NULL, NULL);
112 ok(hr == S_OK, "PChannelInfo failed, got %08x\n", hr);
113 ok(port != NULL, "IDirectMusicPort not set\n");
114 hr = IDirectMusicPerformance8_AssignPChannel(performance, 0, port, 0, 0);
115 todo_wine ok(hr == DMUS_E_AUDIOPATHS_IN_USE, "AssignPChannel failed (%08x)\n", hr);
116 hr = IDirectMusicPerformance8_AssignPChannelBlock(performance, 0, port, 0);
117 todo_wine ok(hr == DMUS_E_AUDIOPATHS_IN_USE, "AssignPChannelBlock failed (%08x)\n", hr);
118 IDirectMusicPort_Release(port);
120 hr = IDirectMusicPerformance8_GetDefaultAudioPath(performance, &path);
121 ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr);
122 if (hr == S_OK)
123 IDirectMusicAudioPath_Release(path);
125 hr = IDirectMusicPerformance8_CloseDown(performance);
126 ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr);
128 IDirectMusicPerformance8_Release(performance);
130 /* Auto generated dmusic and dsound */
131 create_performance(&performance, NULL, NULL, FALSE);
132 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, NULL, NULL, 0, 64, 0, NULL);
133 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
134 hr = IDirectMusicPerformance8_PChannelInfo(performance, 0, &port, NULL, NULL);
135 ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x\n", hr);
136 destroy_performance(performance, NULL, NULL);
138 /* Refcounts for auto generated dmusic and dsound */
139 create_performance(&performance, NULL, NULL, FALSE);
140 dmusic = NULL;
141 dsound = NULL;
142 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
143 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
144 ref = get_refcount(dsound);
145 ok(ref == 3, "dsound ref count got %d expected 3\n", ref);
146 ref = get_refcount(dmusic);
147 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
148 destroy_performance(performance, NULL, NULL);
150 /* dsound without SetCooperativeLevel() */
151 create_performance(&performance, NULL, &dsound, FALSE);
152 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL, 0, 0, 0, NULL);
153 todo_wine ok(hr == DSERR_PRIOLEVELNEEDED, "InitAudio failed: %08x\n", hr);
154 destroy_performance(performance, NULL, dsound);
156 /* Using the wrong CLSID_DirectSound */
157 create_performance(&performance, NULL, NULL, FALSE);
158 hr = DirectSoundCreate(NULL, &dsound, NULL);
159 ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr);
160 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL, 0, 0, 0, NULL);
161 todo_wine ok(hr == E_NOINTERFACE, "InitAudio failed: %08x\n", hr);
162 destroy_performance(performance, NULL, dsound);
164 /* Init() works with just a CLSID_DirectSound */
165 create_performance(&performance, NULL, NULL, FALSE);
166 hr = DirectSoundCreate(NULL, &dsound, NULL);
167 ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr);
168 hr = IDirectSound_SetCooperativeLevel(dsound, GetForegroundWindow(), DSSCL_PRIORITY);
169 ok(hr == S_OK, "SetCooperativeLevel failed: %08x\n", hr);
170 hr = IDirectMusicPerformance8_Init(performance, NULL, dsound, NULL);
171 ok(hr == S_OK, "Init failed: %08x\n", hr);
172 destroy_performance(performance, NULL, dsound);
174 /* Init() followed by InitAudio() */
175 create_performance(&performance, NULL, &dsound, TRUE);
176 hr = IDirectMusicPerformance8_Init(performance, NULL, dsound, NULL);
177 ok(hr == S_OK, "Init failed: %08x\n", hr);
178 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL, 0, 0, 0, NULL);
179 ok(hr == DMUS_E_ALREADY_INITED, "InitAudio failed: %08x\n", hr);
180 destroy_performance(performance, NULL, dsound);
182 /* Provided dmusic and dsound */
183 create_performance(&performance, &dmusic, &dsound, TRUE);
184 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
185 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
186 ref = get_refcount(dsound);
187 todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
188 ref = get_refcount(dmusic);
189 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
190 destroy_performance(performance, dmusic, dsound);
192 /* Provided dmusic initialized with SetDirectSound */
193 create_performance(&performance, &dmusic, &dsound, TRUE);
194 hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
195 ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
196 ref = get_refcount(dsound);
197 ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
198 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, NULL, NULL, 0, 64, 0, NULL);
199 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
200 ref = get_refcount(dsound);
201 todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
202 ref = get_refcount(dmusic);
203 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
204 destroy_performance(performance, dmusic, dsound);
206 /* Provided dmusic and dsound, dmusic initialized with SetDirectSound */
207 create_performance(&performance, &dmusic, &dsound, TRUE);
208 hr = IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
209 ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
210 ref = get_refcount(dsound);
211 ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
212 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
213 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
214 ref = get_refcount(dsound);
215 ok(ref == 3, "dsound ref count got %d expected 3\n", ref);
216 ref = get_refcount(dmusic);
217 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
218 destroy_performance(performance, dmusic, dsound);
220 /* InitAudio with perf channel count not a multiple of 16 rounds up */
221 create_performance(&performance, NULL, NULL, TRUE);
222 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, NULL, NULL,
223 DMUS_APATH_SHARED_STEREOPLUSREVERB, 29, DMUS_AUDIOF_ALL, NULL);
224 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
225 hr = IDirectMusicPerformance8_PChannelInfo(performance, 31, &port, &group, &channel);
226 ok(hr == S_OK && group == 2 && channel == 15,
227 "PChannelInfo failed, got %08x, %u, %u\n", hr, group, channel);
228 hr = IDirectMusicPerformance8_PChannelInfo(performance, 32, &port, NULL, NULL);
229 ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x\n", hr);
230 destroy_performance(performance, NULL, NULL);
232 return S_OK;
235 static void test_createport(void)
237 IDirectMusicPerformance8 *perf;
238 IDirectMusic *music = NULL;
239 IDirectMusicPort *port = NULL;
240 DMUS_PORTCAPS portcaps;
241 DMUS_PORTPARAMS portparams;
242 DWORD i;
243 HRESULT hr;
245 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
246 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
247 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
249 hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL);
250 ok(hr == S_OK, "Init failed: %08x\n", hr);
251 ok(music != NULL, "Didn't get IDirectMusic pointer\n");
253 i = 0;
254 while(1){
255 portcaps.dwSize = sizeof(portcaps);
257 hr = IDirectMusic_EnumPort(music, i, &portcaps);
258 ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr);
259 if(hr != S_OK)
260 break;
262 ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize);
263 trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags);
264 trace("portcaps(%u).guidPort: %s\n", i, wine_dbgstr_guid(&portcaps.guidPort));
265 trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass);
266 trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType);
267 trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize);
268 trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups);
269 trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices);
270 trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels);
271 trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags);
272 trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription));
274 ++i;
277 if(i == 0){
278 win_skip("No ports available, skipping tests\n");
279 return;
282 portparams.dwSize = sizeof(portparams);
284 /* dwValidParams == 0 -> S_OK, filled struct */
285 portparams.dwValidParams = 0;
286 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth, &portparams, &port, NULL);
287 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
288 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
289 todo_wine ok(portparams.dwValidParams, "portparams struct was not filled in\n");
290 IDirectMusicPort_Release(port);
291 port = NULL;
293 /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */
294 portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
295 portparams.dwChannelGroups = 0;
296 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth, &portparams, &port, NULL);
297 todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr);
298 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
299 ok(portparams.dwValidParams, "portparams struct was not filled in\n");
300 IDirectMusicPort_Release(port);
301 port = NULL;
303 /* dwValidParams != 0, valid params -> S_OK */
304 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth, &portparams, &port, NULL);
305 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
306 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
307 IDirectMusicPort_Release(port);
308 port = NULL;
310 /* GUID_NULL succeeds */
311 portparams.dwValidParams = 0;
312 hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
313 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
314 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
315 todo_wine ok(portparams.dwValidParams, "portparams struct was not filled in\n");
316 IDirectMusicPort_Release(port);
317 port = NULL;
319 /* null GUID fails */
320 portparams.dwValidParams = 0;
321 hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL);
322 ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr);
323 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
324 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
326 /* garbage GUID fails */
327 portparams.dwValidParams = 0;
328 hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL);
329 ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr);
330 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
331 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
333 hr = IDirectMusicPerformance8_CloseDown(perf);
334 ok(hr == S_OK, "CloseDown failed: %08x\n", hr);
336 IDirectMusic_Release(music);
337 IDirectMusicPerformance_Release(perf);
340 static void test_pchannel(void)
342 IDirectMusicPerformance8 *perf;
343 IDirectMusicPort *port = NULL, *port2;
344 DWORD channel, group;
345 unsigned int i;
346 HRESULT hr;
348 create_performance(&perf, NULL, NULL, TRUE);
349 hr = IDirectMusicPerformance8_Init(perf, NULL, NULL, NULL);
350 ok(hr == S_OK, "Init failed: %08x\n", hr);
351 hr = IDirectMusicPerformance8_PChannelInfo(perf, 0, &port, NULL, NULL);
352 ok(hr == E_INVALIDARG && !port, "PChannelInfo failed, got %08x, %p\n", hr, port);
354 /* Add default port. Sets PChannels 0-15 to the corresponding channels in group 1 */
355 hr = IDirectMusicPerformance8_AddPort(perf, NULL);
356 ok(hr == S_OK, "AddPort of default port failed: %08x\n", hr);
357 hr = IDirectMusicPerformance8_PChannelInfo(perf, 0, NULL, NULL, NULL);
358 ok(hr == S_OK, "PChannelInfo failed, got %08x\n", hr);
359 hr = IDirectMusicPerformance8_PChannelInfo(perf, 0, &port, NULL, NULL);
360 ok(hr == S_OK && port, "PChannelInfo failed, got %08x, %p\n", hr, port);
361 for (i = 1; i < 16; i++) {
362 hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
363 ok(hr == S_OK && port == port2 && group == 1 && channel == i,
364 "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
365 IDirectMusicPort_Release(port2);
368 /* Unset PChannels fail to retrieve */
369 hr = IDirectMusicPerformance8_PChannelInfo(perf, 16, &port2, NULL, NULL);
370 ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x, %p\n", hr, port);
371 hr = IDirectMusicPerformance8_PChannelInfo(perf, MAXDWORD - 16, &port2, NULL, NULL);
372 ok(hr == E_INVALIDARG, "PChannelInfo failed, got %08x, %p\n", hr, port);
374 /* Channel group 0 can be set just fine */
375 hr = IDirectMusicPerformance8_AssignPChannel(perf, 0, port, 0, 0);
376 ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
377 hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, 0, port, 0);
378 ok(hr == S_OK, "AssignPChannelBlock failed, got %08x\n", hr);
379 for (i = 1; i < 16; i++) {
380 hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
381 ok(hr == S_OK && port == port2 && group == 0 && channel == i,
382 "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
383 IDirectMusicPort_Release(port2);
386 /* Last PChannel Block can be set only individually but not read */
387 hr = IDirectMusicPerformance8_AssignPChannel(perf, MAXDWORD, port, 0, 3);
388 ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
389 port2 = (IDirectMusicPort *)0xdeadbeef;
390 hr = IDirectMusicPerformance8_PChannelInfo(perf, MAXDWORD, &port2, NULL, NULL);
391 todo_wine ok(hr == E_INVALIDARG && port2 == (IDirectMusicPort *)0xdeadbeef,
392 "PChannelInfo failed, got %08x, %p\n", hr, port2);
393 hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD, port, 0);
394 ok(hr == E_INVALIDARG, "AssignPChannelBlock failed, got %08x\n", hr);
395 hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD / 16, port, 1);
396 todo_wine ok(hr == E_INVALIDARG, "AssignPChannelBlock failed, got %08x\n", hr);
397 for (i = MAXDWORD - 15; i < MAXDWORD; i++) {
398 hr = IDirectMusicPerformance8_AssignPChannel(perf, i, port, 0, 0);
399 ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
400 hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, NULL, NULL);
401 todo_wine ok(hr == E_INVALIDARG && port2 == (IDirectMusicPort *)0xdeadbeef,
402 "PChannelInfo failed, got %08x, %p\n", hr, port2);
405 /* Second to last PChannel Block can be set only individually and read */
406 hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD / 16 - 1, port, 1);
407 todo_wine ok(hr == E_INVALIDARG, "AssignPChannelBlock failed, got %08x\n", hr);
408 for (i = MAXDWORD - 31; i < MAXDWORD - 15; i++) {
409 hr = IDirectMusicPerformance8_AssignPChannel(perf, i, port, 1, 7);
410 ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
411 hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
412 ok(hr == S_OK && port2 == port && group == 1 && channel == 7,
413 "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
414 IDirectMusicPort_Release(port2);
417 /* Third to last PChannel Block behaves normal */
418 hr = IDirectMusicPerformance8_AssignPChannelBlock(perf, MAXDWORD / 16 - 2, port, 0);
419 ok(hr == S_OK, "AssignPChannelBlock failed, got %08x\n", hr);
420 for (i = MAXDWORD - 47; i < MAXDWORD - 31; i++) {
421 hr = IDirectMusicPerformance8_PChannelInfo(perf, i, &port2, &group, &channel);
422 ok(hr == S_OK && port2 == port && group == 0 && channel == i % 16,
423 "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
424 IDirectMusicPort_Release(port2);
427 /* One PChannel set in a Block, rest is initialized too */
428 hr = IDirectMusicPerformance8_AssignPChannel(perf, 4711, port, 1, 13);
429 ok(hr == S_OK, "AssignPChannel failed, got %08x\n", hr);
430 hr = IDirectMusicPerformance8_PChannelInfo(perf, 4711, &port2, &group, &channel);
431 ok(hr == S_OK && port2 == port && group == 1 && channel == 13,
432 "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
433 IDirectMusicPort_Release(port2);
434 group = channel = 0xdeadbeef;
435 hr = IDirectMusicPerformance8_PChannelInfo(perf, 4712, &port2, &group, &channel);
436 ok(hr == S_OK && port2 == port && group == 0 && channel == 8,
437 "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
438 IDirectMusicPort_Release(port2);
439 group = channel = 0xdeadbeef;
440 hr = IDirectMusicPerformance8_PChannelInfo(perf, 4719, &port2, &group, &channel);
441 ok(hr == S_OK && port2 == port && group == 0 && channel == 15,
442 "PChannelInfo failed, got %08x, %p, %u, %u\n", hr, port2, group, channel);
443 IDirectMusicPort_Release(port2);
445 IDirectMusicPort_Release(port);
446 destroy_performance(perf, NULL, NULL);
449 static void test_COM(void)
451 IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
452 IDirectMusicPerformance *dmp2;
453 IDirectMusicPerformance8 *dmp8;
454 ULONG refcount;
455 HRESULT hr;
457 /* COM aggregation */
458 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, (IUnknown *)0xdeadbeef, CLSCTX_INPROC_SERVER,
459 &IID_IUnknown, (void**)&dmp);
460 ok(hr == CLASS_E_NOAGGREGATION,
461 "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
462 ok(!dmp, "dmp = %p\n", dmp);
464 /* Invalid RIID */
465 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
466 &IID_IDirectMusicObject, (void**)&dmp);
467 ok(hr == E_NOINTERFACE,
468 "DirectMusicPerformance create failed: %08x, expected E_NOINTERFACE\n", hr);
470 /* Same refcount */
471 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
472 &IID_IDirectMusicPerformance, (void**)&dmp);
473 ok(hr == S_OK, "DirectMusicPerformance create failed: %08x, expected S_OK\n", hr);
474 refcount = IDirectMusicPerformance_AddRef(dmp);
475 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
476 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance2, (void**)&dmp2);
477 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance2 failed: %08x\n", hr);
478 IDirectMusicPerformance_AddRef(dmp);
479 refcount = IDirectMusicPerformance_Release(dmp);
480 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
481 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance8, (void**)&dmp8);
482 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance8 failed: %08x\n", hr);
483 refcount = IDirectMusicPerformance_Release(dmp);
484 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
485 refcount = IDirectMusicPerformance8_Release(dmp8);
486 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
487 refcount = IDirectMusicPerformance_Release(dmp2);
488 ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
489 refcount = IDirectMusicPerformance_Release(dmp);
490 ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
493 static void test_notification_type(void)
495 static unsigned char rifffile[8+4+8+16+8+256] = "RIFF\x24\x01\x00\x00WAVE" /* header: 4 ("WAVE") + (8 + 16) (format segment) + (8 + 256) (data segment) = 0x124 */
496 "fmt \x10\x00\x00\x00\x01\x00\x20\x00\xAC\x44\x00\x00\x10\xB1\x02\x00\x04\x00\x10\x00" /* format segment: PCM, 2 chan, 44100 Hz, 16 bits */
497 "data\x00\x01\x00\x00"; /* 256 byte data segment (silence) */
499 IDirectMusicPerformance8 *perf;
500 IDirectMusic *music = NULL;
501 IDirectMusicSegment8 *prime_segment8;
502 IDirectMusicSegment8 *segment8 = NULL;
503 IDirectMusicLoader8 *loader;
504 IDirectMusicAudioPath8 *path;
505 IDirectMusicSegmentState *state;
506 IDirectSound *dsound = NULL;
507 HRESULT hr;
508 DWORD result;
509 HANDLE messages;
510 DMUS_NOTIFICATION_PMSG *msg;
511 BOOL found_end = FALSE;
512 DMUS_OBJECTDESC desc = {0};
514 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
515 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
516 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
518 hr = IDirectMusicPerformance8_InitAudio(perf, &music, &dsound, NULL, DMUS_APATH_DYNAMIC_STEREO, 64, DMUS_AUDIOF_ALL, NULL);
519 ok(music != NULL, "Didn't get IDirectMusic pointer\n");
520 ok(dsound != NULL, "Didn't get IDirectSound pointer\n");
522 hr = CoCreateInstance(&CLSID_DirectMusicLoader, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusicLoader8, (void**)&loader);
523 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
525 messages = CreateEventA( NULL, FALSE, FALSE, NULL );
527 hr = IDirectMusicPerformance8_AddNotificationType(perf, &GUID_NOTIFICATION_SEGMENT);
528 ok(hr == S_OK, "Failed: %08x\n", hr);
530 hr = IDirectMusicPerformance8_SetNotificationHandle(perf, messages, 0);
531 ok(hr == S_OK, "Failed: %08x\n", hr);
533 hr = IDirectMusicPerformance8_GetDefaultAudioPath(perf, &path);
534 ok(hr == S_OK, "Failed: %08x\n", hr);
535 ok(path != NULL, "Didn't get IDirectMusicAudioPath pointer\n");
537 desc.dwSize = sizeof(DMUS_OBJECTDESC);
538 desc.dwValidData = DMUS_OBJ_CLASS | DMUS_OBJ_MEMORY;
539 desc.guidClass = CLSID_DirectMusicSegment;
540 desc.pbMemData = rifffile;
541 desc.llMemLength = sizeof(rifffile);
542 hr = IDirectMusicLoader8_GetObject(loader, &desc, &IID_IDirectMusicSegment8, (void**)&prime_segment8);
543 ok(hr == S_OK, "Failed: %08x\n", hr);
544 ok(prime_segment8 != NULL, "Didn't get IDirectMusicSegment pointer\n");
546 hr = IDirectMusicSegment8_Download(prime_segment8, (IUnknown*)path);
547 ok(hr == S_OK, "Download failed: %08x\n", hr);
549 hr = IDirectMusicPerformance8_PlaySegmentEx(perf, (IUnknown*)prime_segment8,
550 NULL, NULL, DMUS_SEGF_SECONDARY, 0, &state, NULL, (IUnknown*)path);
551 ok(hr == S_OK, "PlaySegmentEx failed: %08x\n", hr);
552 ok(state != NULL, "Didn't get IDirectMusicSegmentState pointer\n");
554 while (!found_end) {
555 result = WaitForSingleObject(messages, 500);
556 todo_wine ok(result == WAIT_OBJECT_0, "Failed: %d\n", result);
557 if (result != WAIT_OBJECT_0)
558 break;
560 msg = NULL;
561 hr = IDirectMusicPerformance8_GetNotificationPMsg(perf, &msg);
562 ok(hr == S_OK, "Failed: %08x\n", hr);
563 ok(msg != NULL, "Unexpected NULL pointer\n");
564 if (FAILED(hr) || !msg)
565 break;
567 trace("Notification: %d\n", msg->dwNotificationOption);
569 if (msg->dwNotificationOption == DMUS_NOTIFICATION_SEGEND ||
570 msg->dwNotificationOption == DMUS_NOTIFICATION_SEGALMOSTEND) {
571 ok(msg->punkUser != NULL, "Unexpected NULL pointer\n");
572 if (msg->punkUser) {
573 IDirectMusicSegmentState8 *segmentstate;
574 IDirectMusicSegment *segment;
576 hr = IUnknown_QueryInterface(msg->punkUser, &IID_IDirectMusicSegmentState8, (void**)&segmentstate);
577 ok(hr == S_OK, "Failed: %08x\n", hr);
579 hr = IDirectMusicSegmentState8_GetSegment(segmentstate, &segment);
580 ok(hr == S_OK, "Failed: %08x\n", hr);
581 if (FAILED(hr)) {
582 IDirectMusicSegmentState8_Release(segmentstate);
583 break;
586 hr = IDirectMusicSegment_QueryInterface(segment, &IID_IDirectMusicSegment8, (void**)&segment8);
587 ok(hr == S_OK, "Failed: %08x\n", hr);
589 found_end = TRUE;
591 IDirectMusicSegment_Release(segment);
592 IDirectMusicSegmentState8_Release(segmentstate);
596 IDirectMusicPerformance8_FreePMsg(perf, (DMUS_PMSG*)msg);
598 todo_wine ok(prime_segment8 == segment8, "Wrong end segment\n");
599 todo_wine ok(found_end, "Didn't receive DMUS_NOTIFICATION_SEGEND message\n");
601 CloseHandle(messages);
603 if(segment8)
604 IDirectMusicSegment8_Release(segment8);
605 IDirectSound_Release(dsound);
606 IDirectMusicSegmentState_Release(state);
607 IDirectMusicAudioPath_Release(path);
608 IDirectMusicLoader8_Release(loader);
609 IDirectMusic_Release(music);
610 IDirectMusicPerformance8_Release(perf);
613 static void test_performance_graph(void)
615 HRESULT hr;
616 IDirectMusicPerformance8 *perf;
617 IDirectMusicGraph *graph = NULL, *graph2;
619 create_performance(&perf, NULL, NULL, FALSE);
620 hr = IDirectMusicPerformance8_Init(perf, NULL, NULL, NULL);
621 ok(hr == S_OK, "Init failed: %08x\n", hr);
623 hr = IDirectMusicPerformance8_GetGraph(perf, NULL);
624 ok(hr == E_POINTER, "Failed: %08x\n", hr);
626 hr = IDirectMusicPerformance8_GetGraph(perf, &graph2);
627 ok(hr == DMUS_E_NOT_FOUND, "Failed: %08x\n", hr);
628 ok(graph2 == NULL, "unexpected pointer.\n");
630 hr = IDirectMusicPerformance8_QueryInterface(perf, &IID_IDirectMusicGraph, (void**)&graph);
631 todo_wine ok(hr == S_OK, "Failed: %08x\n", hr);
633 if (graph)
634 IDirectMusicGraph_Release(graph);
635 destroy_performance(perf, NULL, NULL);
638 START_TEST( performance )
640 HRESULT hr;
642 hr = CoInitialize(NULL);
643 if (FAILED(hr)) {
644 skip("Cannot initialize COM (%x)\n", hr);
645 return;
648 hr = test_InitAudio();
649 if (hr != S_OK) {
650 skip("InitAudio failed (%x)\n", hr);
651 return;
654 test_COM();
655 test_createport();
656 test_pchannel();
657 test_notification_type();
658 test_performance_graph();
660 CoUninitialize();