comctl32/tooltips: Reset window subclass data when removing tools.
[wine.git] / dlls / dmime / tests / performance.c
blobc4cbb32e185e45954dc2a4d3982cb7826d6b1917
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 HRESULT hr;
86 ULONG ref;
88 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
89 &IID_IDirectMusicPerformance8, (void **)&performance);
90 if (hr != S_OK) {
91 skip("Cannot create DirectMusicPerformance object (%x)\n", hr);
92 CoUninitialize();
93 return hr;
96 dsound = NULL;
97 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL,
98 DMUS_APATH_SHARED_STEREOPLUSREVERB, 128, DMUS_AUDIOF_ALL, NULL);
99 if(hr != S_OK)
100 return hr;
102 port = NULL;
103 hr = IDirectMusicPerformance8_PChannelInfo(performance, 0, &port, NULL, NULL);
104 ok(hr == S_OK, "Failed to call PChannelInfo (%x)\n", hr);
105 ok(port != NULL, "IDirectMusicPort not set\n");
106 if (hr == S_OK && port != NULL)
107 IDirectMusicPort_Release(port);
109 hr = IDirectMusicPerformance8_GetDefaultAudioPath(performance, &path);
110 ok(hr == S_OK, "Failed to call GetDefaultAudioPath (%x)\n", hr);
111 if (hr == S_OK)
112 IDirectMusicAudioPath_Release(path);
114 hr = IDirectMusicPerformance8_CloseDown(performance);
115 ok(hr == S_OK, "Failed to call CloseDown (%x)\n", hr);
117 IDirectMusicPerformance8_Release(performance);
119 /* Auto generated dmusic and dsound */
120 create_performance(&performance, NULL, NULL, FALSE);
121 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, NULL, NULL, 0, 64, 0, NULL);
122 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
123 destroy_performance(performance, NULL, NULL);
125 /* Refcounts for auto generated dmusic and dsound */
126 create_performance(&performance, NULL, NULL, FALSE);
127 dmusic = NULL;
128 dsound = NULL;
129 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
130 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
131 ref = get_refcount(dsound);
132 ok(ref == 3, "dsound ref count got %d expected 3\n", ref);
133 ref = get_refcount(dmusic);
134 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
135 destroy_performance(performance, NULL, NULL);
137 /* dsound without SetCooperativeLevel() */
138 create_performance(&performance, NULL, &dsound, FALSE);
139 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL, 0, 0, 0, NULL);
140 todo_wine ok(hr == DSERR_PRIOLEVELNEEDED, "InitAudio failed: %08x\n", hr);
141 destroy_performance(performance, NULL, dsound);
143 /* Using the wrong CLSID_DirectSound */
144 create_performance(&performance, NULL, NULL, FALSE);
145 hr = DirectSoundCreate(NULL, &dsound, NULL);
146 ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr);
147 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL, 0, 0, 0, NULL);
148 todo_wine ok(hr == E_NOINTERFACE, "InitAudio failed: %08x\n", hr);
149 destroy_performance(performance, NULL, dsound);
151 /* Init() works with just a CLSID_DirectSound */
152 create_performance(&performance, NULL, NULL, FALSE);
153 hr = DirectSoundCreate(NULL, &dsound, NULL);
154 ok(hr == S_OK, "DirectSoundCreate failed: %08x\n", hr);
155 hr = IDirectSound_SetCooperativeLevel(dsound, GetForegroundWindow(), DSSCL_PRIORITY);
156 ok(hr == S_OK, "SetCooperativeLevel failed: %08x\n", hr);
157 hr = IDirectMusicPerformance8_Init(performance, NULL, dsound, NULL);
158 ok(hr == S_OK, "Init failed: %08x\n", hr);
159 destroy_performance(performance, NULL, dsound);
161 /* Init() followed by InitAudio() */
162 create_performance(&performance, NULL, &dsound, TRUE);
163 hr = IDirectMusicPerformance8_Init(performance, NULL, dsound, NULL);
164 ok(hr == S_OK, "Init failed: %08x\n", hr);
165 hr = IDirectMusicPerformance8_InitAudio(performance, NULL, &dsound, NULL, 0, 0, 0, NULL);
166 ok(hr == DMUS_E_ALREADY_INITED, "InitAudio failed: %08x\n", hr);
167 destroy_performance(performance, NULL, dsound);
169 /* Provided dmusic and dsound */
170 create_performance(&performance, &dmusic, &dsound, TRUE);
171 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
172 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
173 ref = get_refcount(dsound);
174 todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
175 ref = get_refcount(dmusic);
176 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
177 destroy_performance(performance, dmusic, dsound);
179 /* Provided dmusic initialized with SetDirectSound */
180 create_performance(&performance, &dmusic, &dsound, TRUE);
181 IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
182 ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
183 ref = get_refcount(dsound);
184 ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
185 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, NULL, NULL, 0, 64, 0, NULL);
186 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
187 ref = get_refcount(dsound);
188 todo_wine ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
189 ref = get_refcount(dmusic);
190 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
191 destroy_performance(performance, dmusic, dsound);
193 /* Provided dmusic and dsound, dmusic initialized with SetDirectSound */
194 create_performance(&performance, &dmusic, &dsound, TRUE);
195 IDirectMusic_SetDirectSound(dmusic, dsound, NULL);
196 ok(hr == S_OK, "SetDirectSound failed: %08x\n", hr);
197 ref = get_refcount(dsound);
198 ok(ref == 2, "dsound ref count got %d expected 2\n", ref);
199 hr = IDirectMusicPerformance8_InitAudio(performance, &dmusic, &dsound, NULL, 0, 64, 0, NULL);
200 ok(hr == S_OK, "InitAudio failed: %08x\n", hr);
201 ref = get_refcount(dsound);
202 ok(ref == 3, "dsound ref count got %d expected 3\n", ref);
203 ref = get_refcount(dmusic);
204 ok(ref == 2, "dmusic ref count got %d expected 2\n", ref);
205 destroy_performance(performance, dmusic, dsound);
207 return S_OK;
210 static void test_createport(void)
212 IDirectMusicPerformance8 *perf;
213 IDirectMusic *music = NULL;
214 IDirectMusicPort *port = NULL;
215 DMUS_PORTCAPS portcaps;
216 DMUS_PORTPARAMS portparams;
217 DWORD i;
218 HRESULT hr;
220 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL,
221 CLSCTX_INPROC_SERVER, &IID_IDirectMusicPerformance8, (void**)&perf);
222 ok(hr == S_OK, "CoCreateInstance failed: %08x\n", hr);
224 hr = IDirectMusicPerformance8_Init(perf, &music, NULL, NULL);
225 ok(hr == S_OK, "Init failed: %08x\n", hr);
226 ok(music != NULL, "Didn't get IDirectMusic pointer\n");
228 i = 0;
229 while(1){
230 portcaps.dwSize = sizeof(portcaps);
232 hr = IDirectMusic_EnumPort(music, i, &portcaps);
233 ok(hr == S_OK || hr == S_FALSE || (i == 0 && hr == E_INVALIDARG), "EnumPort failed: %08x\n", hr);
234 if(hr != S_OK)
235 break;
237 ok(portcaps.dwSize == sizeof(portcaps), "Got unexpected portcaps struct size: %08x\n", portcaps.dwSize);
238 trace("portcaps(%u).dwFlags: %08x\n", i, portcaps.dwFlags);
239 trace("portcaps(%u).guidPort: %s\n", i, wine_dbgstr_guid(&portcaps.guidPort));
240 trace("portcaps(%u).dwClass: %08x\n", i, portcaps.dwClass);
241 trace("portcaps(%u).dwType: %08x\n", i, portcaps.dwType);
242 trace("portcaps(%u).dwMemorySize: %08x\n", i, portcaps.dwMemorySize);
243 trace("portcaps(%u).dwMaxChannelGroups: %08x\n", i, portcaps.dwMaxChannelGroups);
244 trace("portcaps(%u).dwMaxVoices: %08x\n", i, portcaps.dwMaxVoices);
245 trace("portcaps(%u).dwMaxAudioChannels: %08x\n", i, portcaps.dwMaxAudioChannels);
246 trace("portcaps(%u).dwEffectFlags: %08x\n", i, portcaps.dwEffectFlags);
247 trace("portcaps(%u).wszDescription: %s\n", i, wine_dbgstr_w(portcaps.wszDescription));
249 ++i;
252 if(i == 0){
253 win_skip("No ports available, skipping tests\n");
254 return;
257 portparams.dwSize = sizeof(portparams);
259 /* dwValidParams == 0 -> S_OK, filled struct */
260 portparams.dwValidParams = 0;
261 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
262 &portparams, &port, NULL);
263 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
264 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
266 IDirectMusicPort_Release(port);
267 port = NULL;
269 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
271 /* dwValidParams != 0, invalid param -> S_FALSE, filled struct */
272 portparams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
273 portparams.dwChannelGroups = 0;
274 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
275 &portparams, &port, NULL);
276 todo_wine ok(hr == S_FALSE, "CreatePort failed: %08x\n", hr);
277 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
279 IDirectMusicPort_Release(port);
280 port = NULL;
282 ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
284 /* dwValidParams != 0, valid params -> S_OK */
285 hr = IDirectMusic_CreatePort(music, &CLSID_DirectMusicSynth,
286 &portparams, &port, NULL);
287 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
288 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
290 IDirectMusicPort_Release(port);
291 port = NULL;
293 /* GUID_NULL succeeds */
294 portparams.dwValidParams = 0;
295 hr = IDirectMusic_CreatePort(music, &GUID_NULL, &portparams, &port, NULL);
296 ok(hr == S_OK, "CreatePort failed: %08x\n", hr);
297 ok(port != NULL, "Didn't get IDirectMusicPort pointer\n");
299 IDirectMusicPort_Release(port);
300 port = NULL;
302 todo_wine ok(portparams.dwValidParams != 0, "portparams struct was not filled in\n");
304 /* null GUID fails */
305 portparams.dwValidParams = 0;
306 hr = IDirectMusic_CreatePort(music, NULL, &portparams, &port, NULL);
307 ok(hr == E_POINTER, "CreatePort failed: %08x\n", hr);
308 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
309 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
311 /* garbage GUID fails */
312 portparams.dwValidParams = 0;
313 hr = IDirectMusic_CreatePort(music, &GUID_Bunk, &portparams, &port, NULL);
314 ok(hr == E_NOINTERFACE, "CreatePort failed: %08x\n", hr);
315 ok(port == NULL, "Get IDirectMusicPort pointer? %p\n", port);
316 ok(portparams.dwValidParams == 0, "portparams struct was filled in?\n");
318 IDirectMusic_Release(music);
319 IDirectMusicPerformance_Release(perf);
322 static void test_COM(void)
324 IDirectMusicPerformance *dmp = (IDirectMusicPerformance*)0xdeadbeef;
325 IDirectMusicPerformance *dmp2;
326 IDirectMusicPerformance8 *dmp8;
327 ULONG refcount;
328 HRESULT hr;
330 /* COM aggregation */
331 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, (IUnknown *)0xdeadbeef, CLSCTX_INPROC_SERVER,
332 &IID_IUnknown, (void**)&dmp);
333 ok(hr == CLASS_E_NOAGGREGATION,
334 "DirectMusicPerformance create failed: %08x, expected CLASS_E_NOAGGREGATION\n", hr);
335 ok(!dmp, "dmp = %p\n", dmp);
337 /* Invalid RIID */
338 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
339 &IID_IDirectMusicObject, (void**)&dmp);
340 ok(hr == E_NOINTERFACE,
341 "DirectMusicPerformance create failed: %08x, expected E_NOINTERFACE\n", hr);
343 /* Same refcount */
344 hr = CoCreateInstance(&CLSID_DirectMusicPerformance, NULL, CLSCTX_INPROC_SERVER,
345 &IID_IDirectMusicPerformance, (void**)&dmp);
346 ok(hr == S_OK, "DirectMusicPerformance create failed: %08x, expected S_OK\n", hr);
347 refcount = IDirectMusicPerformance_AddRef(dmp);
348 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
349 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance2, (void**)&dmp2);
350 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance2 failed: %08x\n", hr);
351 IDirectMusicPerformance_AddRef(dmp);
352 refcount = IDirectMusicPerformance_Release(dmp);
353 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
354 hr = IDirectMusicPerformance_QueryInterface(dmp, &IID_IDirectMusicPerformance8, (void**)&dmp8);
355 ok(hr == S_OK, "QueryInterface for IID_IDirectMusicPerformance8 failed: %08x\n", hr);
356 refcount = IDirectMusicPerformance_Release(dmp);
357 ok (refcount == 3, "refcount == %u, expected 3\n", refcount);
358 refcount = IDirectMusicPerformance8_Release(dmp8);
359 ok (refcount == 2, "refcount == %u, expected 2\n", refcount);
360 refcount = IDirectMusicPerformance_Release(dmp2);
361 ok (refcount == 1, "refcount == %u, expected 1\n", refcount);
362 refcount = IDirectMusicPerformance_Release(dmp);
363 ok (refcount == 0, "refcount == %u, expected 0\n", refcount);
366 START_TEST( performance )
368 HRESULT hr;
370 hr = CoInitialize(NULL);
371 if (FAILED(hr)) {
372 skip("Cannot initialize COM (%x)\n", hr);
373 return;
376 hr = test_InitAudio();
377 if (hr != S_OK) {
378 skip("InitAudio failed (%x)\n", hr);
379 return;
382 test_COM();
383 test_createport();
385 CoUninitialize();