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);
88 static void test_createport(void)
90 IDirectMusicPerformance8 *perf;
91 IDirectMusic *music = NULL;
92 IDirectMusicPort *port = NULL;
93 DMUS_PORTCAPS portcaps;
94 DMUS_PORTPARAMS portparams;
98 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
99 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
100 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
102 hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL);
103 ok(hr == S_OK, "Init failed: %08x\n", hr);
104 ok(music != NULL, "Didn't get IDirectMusic pointer\n");
108 portcaps.dwSize = sizeof(portcaps);
110 hr = IDirectMusic_EnumPort(music, i, &portcaps);
111 ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr);
115 ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize);
116 trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags);
117 trace("portcaps(%u).guidPort: %s\n", i, debugstr_guid(&portcaps.guidPort));
118 trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass);
119 trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType);
120 trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize);
121 trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups);
122 trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices);
123 trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels);
124 trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags);
125 trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription));
131 win_skip("No ports available, skipping tests\n");
135 portparams.dwSize = sizeof(portparams);
137 /* dwValidParams == 0 -> S_OK, filled struct */
138 portparams.dwValidParams = 0;
139 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
140 &portparams, &port, NULL);
141 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
142 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
144 IDirectMusicPort_Release(port);
147 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
149 /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */
150 portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
151 portparams.dwChannelGroups = 0;
152 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
153 &portparams, &port, NULL);
154 todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr);
155 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
157 IDirectMusicPort_Release(port);
160 ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
162 /* dwValidParams != 0, valid params -> S_OK */
163 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
164 &portparams, &port, NULL);
165 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
166 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
168 IDirectMusicPort_Release(port);
171 /* GUID_NULL succeeds */
172 portparams.dwValidParams = 0;
173 hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
174 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
175 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
177 IDirectMusicPort_Release(port);
180 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
182 /* null GUID fails */
183 portparams.dwValidParams = 0;
184 hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL);
185 ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr);
186 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
187 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
189 /* garbage GUID fails */
190 portparams.dwValidParams = 0;
191 hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL);
192 ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr);
193 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
194 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
196 IDirectMusic_Release(music);
197 IDirectMusicPerformance_Release(perf);
200 static void test_COM(void)
202 IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
203 IDirectMusicPerformance *dmp2;
204 IDirectMusicPerformance8 *dmp8;
208 /* COM aggregation */
209 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, (IUnknown*)&dmp, CLSCTX_INPROC_SERVER,
210 &IID_IUnknown, (void**)&dmp);
211 ok(hr == CLASS_E_NOAGGREGATION,
212 "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
213 ok(!dmp, "dmp = %p\n", dmp);
216 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
217 &IID_IDirectSound, (void**)&dmp);
218 ok(hr == E_NOINTERFACE,
219 "DirectMusicPerformance create failed: %08x, expected E_NOINTERFACE\n", hr);
222 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
223 &IID_IDirectMusicPerformance, (void**)&dmp);
224 ok(hr == S_OK, "DirectMusicPerformance create failed: %08x, expected S_OK\n", hr);
225 refcount = IDirectMusicPerformance_AddRef(dmp);
226 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
227 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance2, (void**)&dmp2);
228 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance2 failed: %08x\n", hr);
229 IDirectMusicPerformance_AddRef(dmp);
230 refcount = IDirectMusicPerformance_Release(dmp);
231 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
232 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance8, (void**)&dmp8);
233 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance8 failed: %08x\n", hr);
234 refcount = IDirectMusicPerformance_Release(dmp);
235 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
236 refcount = IDirectMusicPerformance8_Release(dmp8);
237 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
238 refcount = IDirectMusicPerformance_Release(dmp2);
239 ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
240 refcount = IDirectMusicPerformance_Release(dmp);
241 ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
244 static void test_dms_COM(void)
246 IDirectMusicSegment8 *dms = (IDirectMusicSegment8*)0xdeadbeef;
247 IDirectMusicObject *dmo;
248 IPersistStream *stream;
253 /* COM aggregation */
254 hr = CoCreateInstance(&CLSID_DirectMusicSegment, (IUnknown*)&dms, CLSCTX_INPROC_SERVER,
255 &IID_IUnknown, (void**)&dms);
256 ok(hr == CLASS_E_NOAGGREGATION,
257 "DirectMusicSegment create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
258 ok(!dms, "dms = %p\n", dms);
261 hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
262 &IID_IDirectSound, (void**)&dms);
263 ok(hr == E_NOINTERFACE,
264 "DirectMusicSegment create failed: %08x, expected E_NOINTERFACE\n", hr);
267 hr = CoCreateInstance(&CLSID_DirectMusicSegment, NULL, CLSCTX_INPROC_SERVER,
268 &IID_IDirectMusicSegment8, (void**)&dms);
269 ok(hr == S_OK, "DirectMusicSegment create failed: %08x, expected S_OK\n", hr);
270 refcount = IDirectMusicSegment8_AddRef(dms);
271 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
272 hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IDirectMusicObject, (void**)&dmo);
273 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicObject failed: %08x\n", hr);
274 IDirectMusicSegment8_AddRef(dms);
275 refcount = IDirectMusicSegment8_Release(dms);
276 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
277 hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IPersistStream, (void**)&stream);
278 ok(hr == S_OK, "QueryInterface for IID_IPersistStream failed: %08x\n", hr);
279 refcount = IDirectMusicSegment8_Release(dms);
280 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
281 hr = IDirectMusicSegment8_QueryInterface(dms, &IID_IUnknown, (void**)&unk);
282 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
283 refcount = IUnknown_Release(unk);
284 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
285 refcount = IDirectMusicObject_Release(dmo);
286 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
287 refcount = IPersistStream_Release(stream);
288 ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
289 refcount = IDirectMusicSegment8_Release(dms);
290 ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
293 START_TEST( performance )
297 hr = CoInitialize(NULL);
299 skip("Cannot initialize COM (%x)\n", hr);
303 hr = test_InitAudio();
305 skip("InitAudio failed (%x)\n", hr);