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
26 #include <wine/test.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 const char *debugstr_guid(REFIID riid)
38 sprintf(buf, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
39 riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
40 riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
41 riid->Data4[5], riid->Data4[6], riid->Data4[7]);
46 static HRESULT test_InitAudio(void)
48 IDirectMusicPerformance8 *idmusicperformance;
49 IDirectSound *pDirectSound;
50 IDirectMusicPort *pDirectMusicPort;
51 IDirectMusicAudioPath *pDirectMusicAudioPath;
54 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
55 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (LPVOID *)&idmusicperformance);
57 skip("Cannot create DirectMusicPerformance object (%x)\n", hr);
63 hr = IDirectMusicPerformance8_InitAudio(idmusicperformance ,NULL,
64 &pDirectSound, NULL, DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL);
68 pDirectMusicPort = NULL;
69 hr = IDirectMusicPerformance8_PChannelInfo(idmusicperformance, 0, &pDirectMusicPort, NULL, NULL);
70 ok(hr == S_OK, "Failed to call PChannelInfo (%x)\n", hr);
71 ok(pDirectMusicPort != NULL, "IDirectMusicPort not set\n");
72 if (hr == S_OK && pDirectMusicPort != NULL)
73 IDirectMusicPort_Release(pDirectMusicPort);
75 hr = IDirectMusicPerformance8_GetDefaultAudioPath(idmusicperformance, &pDirectMusicAudioPath);
76 ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr);
78 IDirectMusicAudioPath_Release(pDirectMusicAudioPath);
80 hr = IDirectMusicPerformance8_CloseDown(idmusicperformance);
81 ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr);
83 IDirectMusicPerformance8_Release(idmusicperformance);
85 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
86 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8,
87 (void**)&idmusicperformance);
88 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
90 hr = IDirectMusicPerformance8_InitAudio(idmusicperformance, NULL, NULL,
91 NULL, 0, 64, 0, NULL);
92 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
94 hr = IDirectMusicPerformance8_CloseDown(idmusicperformance);
95 ok(hr == S_OK, "CloseDown failed: %08x\n", hr);
97 IDirectMusicPerformance8_Release(idmusicperformance);
102 static void test_createport(void)
104 IDirectMusicPerformance8 *perf;
105 IDirectMusic *music = NULL;
106 IDirectMusicPort *port = NULL;
107 DMUS_PORTCAPS portcaps;
108 DMUS_PORTPARAMS portparams;
112 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
113 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
114 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
116 hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL);
117 ok(hr == S_OK, "Init failed: %08x\n", hr);
118 ok(music != NULL, "Didn't get IDirectMusic pointer\n");
122 portcaps.dwSize = sizeof(portcaps);
124 hr = IDirectMusic_EnumPort(music, i, &portcaps);
125 ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr);
129 ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize);
130 trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags);
131 trace("portcaps(%u).guidPort: %s\n", i, debugstr_guid(&portcaps.guidPort));
132 trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass);
133 trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType);
134 trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize);
135 trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups);
136 trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices);
137 trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels);
138 trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags);
139 trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription));
145 win_skip("No ports available, skipping tests\n");
149 portparams.dwSize = sizeof(portparams);
151 /* dwValidParams == 0 -> S_OK, filled struct */
152 portparams.dwValidParams = 0;
153 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
154 &portparams, &port, NULL);
155 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
156 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
158 IDirectMusicPort_Release(port);
161 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
163 /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */
164 portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
165 portparams.dwChannelGroups = 0;
166 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
167 &portparams, &port, NULL);
168 todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr);
169 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
171 IDirectMusicPort_Release(port);
174 ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
176 /* dwValidParams != 0, valid params -> S_OK */
177 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
178 &portparams, &port, NULL);
179 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
180 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
182 IDirectMusicPort_Release(port);
185 /* GUID_NULL succeeds */
186 portparams.dwValidParams = 0;
187 hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
188 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
189 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
191 IDirectMusicPort_Release(port);
194 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
196 /* null GUID fails */
197 portparams.dwValidParams = 0;
198 hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL);
199 ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr);
200 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
201 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
203 /* garbage GUID fails */
204 portparams.dwValidParams = 0;
205 hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL);
206 ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr);
207 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
208 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
210 IDirectMusic_Release(music);
211 IDirectMusicPerformance_Release(perf);
214 static void test_COM(void)
216 IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
217 IDirectMusicPerformance *dmp2;
218 IDirectMusicPerformance8 *dmp8;
222 /* COM aggregation */
223 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, (IUnknown*)&dmp, CLSCTX_INPROC_SERVER,
224 &IID_IUnknown, (void**)&dmp);
225 ok(hr == CLASS_E_NOAGGREGATION,
226 "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
227 ok(!dmp, "dmp = %p\n", dmp);
230 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
231 &IID_IDirectSound, (void**)&dmp);
232 ok(hr == E_NOINTERFACE,
233 "DirectMusicPerformance create failed: %08x, expected E_NOINTERFACE\n", hr);
236 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
237 &IID_IDirectMusicPerformance, (void**)&dmp);
238 ok(hr == S_OK, "DirectMusicPerformance create failed: %08x, expected S_OK\n", hr);
239 refcount = IDirectMusicPerformance_AddRef(dmp);
240 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
241 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance2, (void**)&dmp2);
242 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance2 failed: %08x\n", hr);
243 IDirectMusicPerformance_AddRef(dmp);
244 refcount = IDirectMusicPerformance_Release(dmp);
245 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
246 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance8, (void**)&dmp8);
247 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance8 failed: %08x\n", hr);
248 refcount = IDirectMusicPerformance_Release(dmp);
249 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
250 refcount = IDirectMusicPerformance8_Release(dmp8);
251 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
252 refcount = IDirectMusicPerformance_Release(dmp2);
253 ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
254 refcount = IDirectMusicPerformance_Release(dmp);
255 ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
258 static void test_dms_COM(void)
260 IDirectMusicSegment8 *dms = (IDirectMusicSegment8*)0xdeadbeef;
261 IDirectMusicObject *dmo;
262 IPersistStream *stream;
267 /* COM aggregation */
268 hr = CoCreateInstance(&CLSID_DirectMusicSegment, (IUnknown*)&dms, CLSCTX_INPROC_SERVER,
269 &IID_IUnknown, (void**)&dms);
270 ok(hr == CLASS_E_NOAGGREGATION,
271 "DirectMusicSegment create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
272 ok(!dms, "dms = %p\n", dms);
275 hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
276 &IID_IDirectSound, (void**)&dms);
277 ok(hr == E_NOINTERFACE,
278 "DirectMusicSegment create failed: %08x, expected E_NOINTERFACE\n", hr);
281 hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
282 &IID_IDirectMusicSegment8, (void**)&dms);
283 ok(hr == S_OK, "DirectMusicSegment create failed: %08x, expected S_OK\n", hr);
284 refcount = IDirectMusicSegment8_AddRef(dms);
285 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
286 hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IDirectMusicObject, (void**)&dmo);
287 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicObject failed: %08x\n", hr);
288 IDirectMusicSegment8_AddRef(dms);
289 refcount = IDirectMusicSegment8_Release(dms);
290 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
291 hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IPersistStream, (void**)&stream);
292 ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
293 refcount = IDirectMusicSegment8_Release(dms);
294 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
295 hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IUnknown, (void**)&unk);
296 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
297 refcount = IUnknown_Release(unk);
298 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
299 refcount = IDirectMusicObject_Release(dmo);
300 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
301 refcount = IPersistStream_Release(stream);
302 ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
303 refcount = IDirectMusicSegment8_Release(dms);
304 ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
307 START_TEST( performance )
311 hr = CoInitialize(NULL);
313 skip("Cannot initialize COM (%x)\n", hr);
317 hr = test_InitAudio();
319 skip("InitAudio failed (%x)\n", hr);