dsound/tests: Add tests for implicit MTA creation in IDirectSound::Initialize().
[wine.git] / dlls / dsound / tests / dsound8.c
blob2bdeb49fe9787c6a207e9676ebd4158caad3b93e
1 /*
2 * Tests basic sound playback in DirectSound.
3 * In particular we test each standard Windows sound format to make sure
4 * we handle the sound card/driver quirks correctly.
6 * Part of this test involves playing test tones. But this only makes
7 * sense if someone is going to carefully listen to it, and would only
8 * bother everyone else.
9 * So this is only done if the test is being run in interactive mode.
11 * Copyright (c) 2002-2004 Francois Gouget
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #define COBJMACROS
29 #include <windows.h>
30 #include <stdio.h>
32 #include "wine/test.h"
33 #include "mmsystem.h"
34 #include "dsound.h"
35 #include "dsconf.h"
36 #include "ks.h"
37 #include "ksmedia.h"
38 #include "dmo.h"
40 #include "initguid.h"
42 #include "uuids.h"
43 #include "wingdi.h"
44 #include "mmdeviceapi.h"
45 #include "audioclient.h"
46 #include "propkey.h"
47 #include "devpkey.h"
49 #include "dsound_test.h"
51 static const GUID testdmo_clsid = {0x1234};
53 int align(int length, int align)
55 return (length / align) * align;
58 static void IDirectSound8_test(LPDIRECTSOUND8 dso, BOOL initialized,
59 LPCGUID lpGuid)
61 HRESULT rc;
62 DSCAPS dscaps;
63 int ref;
64 IUnknown * unknown;
65 IDirectSound * ds;
66 IDirectSound8 * ds8;
67 DWORD speaker_config, new_speaker_config, ref_speaker_config;
68 DWORD certified;
70 /* Try to Query for objects */
71 rc=IDirectSound8_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown);
72 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %08lx\n", rc);
73 if (rc==DS_OK)
74 IUnknown_Release(unknown);
76 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds);
77 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %08lx\n", rc);
78 if (rc==DS_OK)
79 IDirectSound_Release(ds);
81 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8);
82 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound8) "
83 "should have returned DSERR_INVALIDPARAM, returned: %08lx\n", rc);
84 if (rc==DS_OK)
85 IDirectSound8_Release(ds8);
87 if (initialized == FALSE) {
88 /* try uninitialized object */
89 rc=IDirectSound8_GetCaps(dso,0);
90 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps(NULL) "
91 "should have returned DSERR_UNINITIALIZED, returned: %08lx\n", rc);
93 rc=IDirectSound8_GetCaps(dso,&dscaps);
94 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps() "
95 "should have returned DSERR_UNINITIALIZED, returned: %08lx\n", rc);
97 rc=IDirectSound8_Compact(dso);
98 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_Compact() "
99 "should have returned DSERR_UNINITIALIZED, returned: %08lx\n", rc);
101 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
102 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetSpeakerConfig() "
103 "should have returned DSERR_UNINITIALIZED, returned: %08lx\n", rc);
105 rc=IDirectSound8_VerifyCertification(dso, &certified);
106 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_VerifyCertification() "
107 "should have returned DSERR_UNINITIALIZED, returned: %08lx\n", rc);
109 rc=IDirectSound8_Initialize(dso,lpGuid);
110 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
111 "IDirectSound8_Initialize() failed: %08lx\n",rc);
112 if (rc==DSERR_NODRIVER) {
113 trace(" No Driver\n");
114 goto EXIT;
115 } else if (rc==E_FAIL) {
116 trace(" No Device\n");
117 goto EXIT;
118 } else if (rc==DSERR_ALLOCATED) {
119 trace(" Already In Use\n");
120 goto EXIT;
124 rc=IDirectSound8_Initialize(dso,lpGuid);
125 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound8_Initialize() "
126 "should have returned DSERR_ALREADYINITIALIZED: %08lx\n", rc);
128 /* DSOUND: Error: Invalid caps buffer */
129 rc=IDirectSound8_GetCaps(dso,0);
130 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
131 "should have returned DSERR_INVALIDPARAM, returned: %08lx\n", rc);
133 ZeroMemory(&dscaps, sizeof(dscaps));
135 /* DSOUND: Error: Invalid caps buffer */
136 rc=IDirectSound8_GetCaps(dso,&dscaps);
137 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() "
138 "should have returned DSERR_INVALIDPARAM, returned: %08lx\n", rc);
140 dscaps.dwSize=sizeof(dscaps);
142 /* DSOUND: Running on a certified driver */
143 rc=IDirectSound8_GetCaps(dso,&dscaps);
144 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08lx\n",rc);
146 rc=IDirectSound8_Compact(dso);
147 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound8_Compact() failed: %08lx\n", rc);
149 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
150 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
152 rc=IDirectSound8_Compact(dso);
153 ok(rc==DS_OK,"IDirectSound8_Compact() failed: %08lx\n",rc);
155 rc=IDirectSound8_GetSpeakerConfig(dso,0);
156 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetSpeakerConfig(NULL) "
157 "should have returned DSERR_INVALIDPARAM, returned: %08lx\n", rc);
159 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config);
160 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %08lx\n", rc);
161 ref_speaker_config = speaker_config;
163 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
164 DSSPEAKER_GEOMETRY_WIDE);
165 if (speaker_config == ref_speaker_config)
166 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO,
167 DSSPEAKER_GEOMETRY_NARROW);
168 if(rc==DS_OK) {
169 rc=IDirectSound8_SetSpeakerConfig(dso,speaker_config);
170 ok(rc==DS_OK,"IDirectSound8_SetSpeakerConfig() failed: %08lx\n", rc);
172 if (rc==DS_OK) {
173 rc=IDirectSound8_GetSpeakerConfig(dso,&new_speaker_config);
174 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %08lx\n", rc);
175 if (rc==DS_OK && speaker_config!=new_speaker_config && ref_speaker_config!=new_speaker_config)
176 trace("IDirectSound8_GetSpeakerConfig() failed to set speaker "
177 "config: expected 0x%08lx or 0x%08lx, got 0x%08lx\n",
178 speaker_config,ref_speaker_config,new_speaker_config);
179 IDirectSound8_SetSpeakerConfig(dso,ref_speaker_config);
182 rc=IDirectSound8_VerifyCertification(dso, &certified);
183 ok(rc==DS_OK||rc==E_NOTIMPL,"IDirectSound8_VerifyCertification() failed: %08lx\n", rc);
185 EXIT:
186 ref=IDirectSound8_Release(dso);
187 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
190 static void IDirectSound8_tests(void)
192 HRESULT rc;
193 LPDIRECTSOUND8 dso=NULL;
194 LPCLASSFACTORY cf=NULL;
196 trace("Testing IDirectSound8\n");
198 rc=CoGetClassObject(&CLSID_DirectSound8, CLSCTX_INPROC_SERVER, NULL,
199 &IID_IClassFactory, (void**)&cf);
200 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound8, IID_IClassFactory) "
201 "failed: %08lx\n", rc);
203 rc=CoGetClassObject(&CLSID_DirectSound8, CLSCTX_INPROC_SERVER, NULL,
204 &IID_IUnknown, (void**)&cf);
205 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSound8, IID_IUnknown) "
206 "failed: %08lx\n", rc);
208 /* try the COM class factory method of creation with no device specified */
209 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
210 &IID_IDirectSound8, (void**)&dso);
211 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG,"CoCreateInstance() failed: %08lx\n", rc);
212 if (rc==REGDB_E_CLASSNOTREG) {
213 trace(" Class Not Registered\n");
214 return;
216 if (dso)
217 IDirectSound8_test(dso, FALSE, NULL);
219 /* try the COM class factory method of creation with default playback
220 * device specified */
221 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
222 &IID_IDirectSound8, (void**)&dso);
223 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %08lx\n", rc);
224 if (dso)
225 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultPlayback);
227 /* try the COM class factory method of creation with default voice
228 * playback device specified */
229 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
230 &IID_IDirectSound8, (void**)&dso);
231 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %08lx\n", rc);
232 if (dso)
233 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback);
235 /* try the COM class factory method of creation with a bad
236 * IID specified */
237 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
238 &CLSID_DirectSoundPrivate, (void**)&dso);
239 ok(rc==E_NOINTERFACE,
240 "CoCreateInstance(CLSID_DirectSound8,CLSID_DirectSoundPrivate) "
241 "should have failed: %08lx\n",rc);
243 /* try the COM class factory method of creation with a bad
244 * GUID and IID specified */
245 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER,
246 &IID_IDirectSound8, (void**)&dso);
247 ok(rc==REGDB_E_CLASSNOTREG,
248 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound8) "
249 "should have failed: %08lx\n",rc);
251 /* try with no device specified */
252 rc = DirectSoundCreate8(NULL, &dso, NULL);
253 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
254 "DirectSoundCreate8() failed: %08lx\n",rc);
255 if (rc==DS_OK && dso)
256 IDirectSound8_test(dso, TRUE, NULL);
258 /* try with default playback device specified */
259 rc = DirectSoundCreate8(&DSDEVID_DefaultPlayback, &dso, NULL);
260 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
261 "DirectSoundCreate8() failed: %08lx\n",rc);
262 if (rc==DS_OK && dso)
263 IDirectSound8_test(dso, TRUE, NULL);
265 /* try with default voice playback device specified */
266 rc = DirectSoundCreate8(&DSDEVID_DefaultVoicePlayback, &dso, NULL);
267 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
268 "DirectSoundCreate8() failed: %08lx\n",rc);
269 if (rc==DS_OK && dso)
270 IDirectSound8_test(dso, TRUE, NULL);
272 /* try with a bad device specified */
273 rc = DirectSoundCreate8(&DSDEVID_DefaultVoiceCapture, &dso, NULL);
274 ok(rc==DSERR_NODRIVER,"DirectSoundCreate8(DSDEVID_DefaultVoiceCapture) "
275 "should have failed: %08lx\n",rc);
278 static HRESULT test_dsound8(LPGUID lpGuid)
280 HRESULT rc;
281 LPDIRECTSOUND8 dso=NULL;
282 int ref;
284 /* DSOUND: Error: Invalid interface buffer */
285 rc = DirectSoundCreate8(lpGuid, 0, NULL);
286 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate8() should have returned "
287 "DSERR_INVALIDPARAM, returned: %08lx\n",rc);
289 /* Create the DirectSound8 object */
290 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
291 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
292 "DirectSoundCreate8() failed: %08lx\n",rc);
293 if (rc!=DS_OK)
294 return rc;
296 /* Try the enumerated device */
297 IDirectSound8_test(dso, TRUE, lpGuid);
299 /* Try the COM class factory method of creation with enumerated device */
300 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
301 &IID_IDirectSound8, (void**)&dso);
302 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %08lx\n", rc);
303 if (dso)
304 IDirectSound8_test(dso, FALSE, lpGuid);
306 /* Create a DirectSound8 object */
307 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
308 ok(rc==DS_OK,"DirectSoundCreate8() failed: %08lx\n",rc);
309 if (rc==DS_OK) {
310 LPDIRECTSOUND8 dso1=NULL;
312 /* Create a second DirectSound8 object */
313 rc = DirectSoundCreate8(lpGuid, &dso1, NULL);
314 ok(rc==DS_OK,"DirectSoundCreate8() failed: %08lx\n",rc);
315 if (rc==DS_OK) {
316 /* Release the second DirectSound8 object */
317 ref=IDirectSound8_Release(dso1);
318 ok(ref==0,"IDirectSound8_Release() has %d references, "
319 "should have 0\n",ref);
320 ok(dso!=dso1,"DirectSound8 objects should be unique: "
321 "dso=%p,dso1=%p\n",dso,dso1);
324 /* Release the first DirectSound8 object */
325 ref=IDirectSound8_Release(dso);
326 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",
327 ref);
328 if (ref!=0)
329 return DSERR_GENERIC;
330 } else
331 return rc;
333 /* Create a DirectSound8 object */
334 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
335 ok(rc==DS_OK,"DirectSoundCreate8() failed: %08lx\n",rc);
336 if (rc==DS_OK) {
337 LPDIRECTSOUNDBUFFER secondary;
338 DSBUFFERDESC bufdesc;
339 WAVEFORMATEX wfx;
341 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
342 ZeroMemory(&bufdesc, sizeof(bufdesc));
343 bufdesc.dwSize=sizeof(bufdesc);
344 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D;
345 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
346 wfx.nBlockAlign);
347 bufdesc.lpwfxFormat=&wfx;
348 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
349 ok(rc==DS_OK && secondary!=NULL,
350 "IDirectSound8_CreateSoundBuffer() failed to create a secondary "
351 "buffer: %08lx\n",rc);
352 if (rc==DS_OK && secondary!=NULL) {
353 LPDIRECTSOUND3DBUFFER buffer3d;
354 LPDIRECTSOUNDBUFFER8 buffer8;
355 rc=IDirectSoundBuffer_QueryInterface(secondary,
356 &IID_IDirectSound3DBuffer,
357 (void **)&buffer3d);
358 ok(rc==DS_OK && buffer3d!=NULL,
359 "IDirectSound8_QueryInterface() failed: %08lx\n", rc);
360 if (rc==DS_OK && buffer3d!=NULL) {
361 ref=IDirectSound3DBuffer_AddRef(buffer3d);
362 ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, "
363 "should have 2\n",ref);
365 rc=IDirectSoundBuffer_QueryInterface(secondary,
366 &IID_IDirectSoundBuffer8,
367 (void **)&buffer8);
368 if (rc==DS_OK && buffer8!=NULL) {
369 ok(buffer8==(IDirectSoundBuffer8*)secondary,
370 "IDirectSoundBuffer8 iface different from IDirectSoundBuffer.\n");
371 ref=IDirectSoundBuffer8_AddRef(buffer8);
372 ok(ref==3,"IDirectSoundBuffer8_AddRef() has %d references, "
373 "should have 3\n",ref);
375 ref=IDirectSoundBuffer_AddRef(secondary);
376 ok(ref==4,"IDirectSoundBuffer_AddRef() has %d references, "
377 "should have 4\n",ref);
379 /* release with buffer */
380 ref=IDirectSound8_Release(dso);
381 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",
382 ref);
383 if (ref!=0)
384 return DSERR_GENERIC;
385 } else
386 return rc;
388 return DS_OK;
391 static HRESULT test_primary8(LPGUID lpGuid)
393 HRESULT rc;
394 LPDIRECTSOUND8 dso=NULL;
395 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL;
396 LPDIRECTSOUNDBUFFER8 pb8 = NULL;
397 DSBUFFERDESC bufdesc;
398 DSCAPS dscaps;
399 WAVEFORMATEX wfx;
400 int ref;
402 /* Create the DirectSound object */
403 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
404 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
405 "DirectSoundCreate8() failed: %08lx\n",rc);
406 if (rc!=DS_OK)
407 return rc;
409 /* Get the device capabilities */
410 ZeroMemory(&dscaps, sizeof(dscaps));
411 dscaps.dwSize=sizeof(dscaps);
412 rc=IDirectSound8_GetCaps(dso,&dscaps);
413 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08lx\n",rc);
414 if (rc!=DS_OK)
415 goto EXIT;
417 /* DSOUND: Error: Invalid buffer description pointer */
418 rc=IDirectSound8_CreateSoundBuffer(dso,0,0,NULL);
419 ok(rc==DSERR_INVALIDPARAM,
420 "IDirectSound8_CreateSoundBuffer should have returned "
421 "DSERR_INVALIDPARAM, returned: %08lx\n",rc);
423 /* DSOUND: Error: Invalid buffer description pointer */
424 rc=IDirectSound8_CreateSoundBuffer(dso,0,&primary,NULL);
425 ok(rc==DSERR_INVALIDPARAM && primary==0,
426 "IDirectSound8_CreateSoundBuffer() should have returned "
427 "DSERR_INVALIDPARAM, returned: rc=%08lx,dsbo=%p\n",
428 rc,primary);
430 ZeroMemory(&bufdesc, sizeof(bufdesc));
431 bufdesc.dwSize = sizeof(DSBUFFERDESC);
433 /* DSOUND: Error: Invalid dsound buffer interface pointer */
434 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,0,NULL);
435 ok(rc==DSERR_INVALIDPARAM && primary==0,
436 "IDirectSound8_CreateSoundBuffer() should have failed: rc=%08lx,"
437 "dsbo=%p\n",rc,primary);
439 ZeroMemory(&bufdesc, sizeof(bufdesc));
441 /* DSOUND: Error: Invalid size */
442 /* DSOUND: Error: Invalid buffer description */
443 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
444 ok(rc==DSERR_INVALIDPARAM && primary==0,
445 "IDirectSound8_CreateSoundBuffer() should have failed: rc=%08lx,"
446 "primary=%p\n",rc,primary);
448 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
449 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
450 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
451 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
452 if (rc!=DS_OK)
453 goto EXIT;
455 /* Testing the primary buffer */
456 primary=NULL;
457 ZeroMemory(&bufdesc, sizeof(bufdesc));
458 bufdesc.dwSize=sizeof(bufdesc);
459 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
460 bufdesc.lpwfxFormat = &wfx;
461 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2);
462 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
463 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() should have "
464 "returned DSERR_INVALIDPARAM, returned: %08lx\n", rc);
465 if (rc==DS_OK && primary!=NULL)
466 IDirectSoundBuffer_Release(primary);
468 primary=NULL;
469 ZeroMemory(&bufdesc, sizeof(bufdesc));
470 bufdesc.dwSize=sizeof(bufdesc);
471 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME;
472 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
473 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL),
474 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: "
475 "%08lx\n",rc);
476 if (rc==DSERR_CONTROLUNAVAIL)
477 trace(" No Primary\n");
478 else if (rc==DS_OK && primary!=NULL) {
479 LONG vol;
481 /* Try to create a second primary buffer */
482 /* DSOUND: Error: The primary buffer already exists.
483 * Any changes made to the buffer description will be ignored. */
484 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&second,NULL);
485 ok(rc==DS_OK && second==primary,
486 "IDirectSound8_CreateSoundBuffer() should have returned original "
487 "primary buffer: %08lx\n",rc);
488 ref=IDirectSoundBuffer_Release(second);
489 ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, "
490 "should have 1\n",ref);
492 /* Try to duplicate a primary buffer */
493 /* DSOUND: Error: Can't duplicate primary buffers */
494 rc=IDirectSound8_DuplicateSoundBuffer(dso,primary,&third);
495 /* rc=0x88780032 */
496 ok(rc!=DS_OK,"IDirectSound8_DuplicateSoundBuffer() primary buffer "
497 "should have failed %08lx\n",rc);
499 /* Primary buffers don't have an IDirectSoundBuffer8 */
500 rc = IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundBuffer8, (LPVOID*)&pb8);
501 ok(FAILED(rc), "Primary buffer does have an IDirectSoundBuffer8: %08lx\n", rc);
503 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
504 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %08lx\n", rc);
506 if (winetest_interactive) {
507 trace("Playing a 5 seconds reference tone at the current volume.\n");
508 if (rc==DS_OK)
509 trace("(the current volume is %ld according to DirectSound)\n",
510 vol);
511 trace("All subsequent tones should be identical to this one.\n");
512 trace("Listen for stutter, changes in pitch, volume, etc.\n");
514 test_buffer8(dso,&primary,TRUE,FALSE,0,FALSE,0,
515 winetest_interactive && !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
516 5.0,FALSE,NULL,FALSE,FALSE);
518 ref=IDirectSoundBuffer_Release(primary);
519 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
520 "should have 0\n",ref);
523 /* Set the CooperativeLevel back to normal */
524 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
525 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
526 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
528 EXIT:
529 ref=IDirectSound8_Release(dso);
530 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
531 if (ref!=0)
532 return DSERR_GENERIC;
534 return rc;
538 * Test the primary buffer at different formats while keeping the
539 * secondary buffer at a constant format.
541 static HRESULT test_primary_secondary8(LPGUID lpGuid)
543 HRESULT rc;
544 LPDIRECTSOUND8 dso=NULL;
545 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
546 DSBUFFERDESC bufdesc;
547 DSCAPS dscaps;
548 WAVEFORMATEX wfx, wfx2;
549 int ref;
550 unsigned int f, tag;
552 /* Create the DirectSound object */
553 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
554 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
555 "DirectSoundCreate8() failed: %08lx\n",rc);
556 if (rc!=DS_OK)
557 return rc;
559 /* Get the device capabilities */
560 ZeroMemory(&dscaps, sizeof(dscaps));
561 dscaps.dwSize=sizeof(dscaps);
562 rc=IDirectSound8_GetCaps(dso,&dscaps);
563 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08lx\n",rc);
564 if (rc!=DS_OK)
565 goto EXIT;
567 /* We must call SetCooperativeLevel before creating primary buffer */
568 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
569 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
570 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
571 if (rc!=DS_OK)
572 goto EXIT;
574 ZeroMemory(&bufdesc, sizeof(bufdesc));
575 bufdesc.dwSize=sizeof(bufdesc);
576 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
577 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
578 ok(rc==DS_OK && primary!=NULL,
579 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer "
580 "%08lx\n",rc);
582 if (rc==DS_OK && primary!=NULL) {
583 for (f = 0; f < ARRAY_SIZE(formats); f++) {
584 for (tag = 0; tag < ARRAY_SIZE(format_tags); tag++) {
585 /* if float, we only want to test 32-bit */
586 if ((format_tags[tag] == WAVE_FORMAT_IEEE_FLOAT) && (formats[f][1] != 32))
587 continue;
589 /* We must call SetCooperativeLevel to be allowed to call
590 * SetFormat */
591 /* DSOUND: Setting DirectSound cooperative level to
592 * DSSCL_PRIORITY */
593 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
594 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
595 if (rc!=DS_OK)
596 goto EXIT;
598 init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
599 formats[f][2]);
600 wfx2=wfx;
601 rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
602 ok(rc==DS_OK
603 || rc==DSERR_INVALIDPARAM, /* 2003 */
604 "IDirectSoundBuffer_SetFormat(%s) failed: %08lx\n",
605 format_string(&wfx), rc);
607 /* There is no guarantee that SetFormat will actually change the
608 * format to what we asked for. It depends on what the soundcard
609 * supports. So we must re-query the format.
611 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
612 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08lx\n", rc);
613 if (rc==DS_OK &&
614 (wfx.wFormatTag!=wfx2.wFormatTag ||
615 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
616 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
617 wfx.nChannels!=wfx2.nChannels)) {
618 trace("Requested primary format tag=0x%04x %ldx%dx%d "
619 "avg.B/s=%ld align=%d\n",
620 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
621 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
622 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
623 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
624 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
627 /* Set the CooperativeLevel back to normal */
628 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
629 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
630 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
632 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
634 secondary=NULL;
635 ZeroMemory(&bufdesc, sizeof(bufdesc));
636 bufdesc.dwSize=sizeof(bufdesc);
637 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
638 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
639 wfx.nBlockAlign);
640 bufdesc.lpwfxFormat=&wfx2;
641 if (winetest_interactive) {
642 trace(" Testing a primary buffer at %ldx%dx%d (fmt=%d) with a "
643 "secondary buffer at %ldx%dx%d\n",
644 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
645 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
647 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
648 ok(rc==DS_OK && secondary!=NULL,
649 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
650 "buffer %08lx\n",rc);
652 if (rc==DS_OK && secondary!=NULL) {
653 test_buffer8(dso,&secondary,FALSE,FALSE,0,FALSE,0,
654 winetest_interactive,1.0,FALSE,NULL,FALSE,FALSE);
656 ref=IDirectSoundBuffer_Release(secondary);
657 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
658 "should have 0\n",ref);
663 ref=IDirectSoundBuffer_Release(primary);
664 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
665 "should have 0\n",ref);
668 /* Set the CooperativeLevel back to normal */
669 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
670 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
671 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
673 EXIT:
674 ref=IDirectSound8_Release(dso);
675 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
676 if (ref!=0)
677 return DSERR_GENERIC;
679 return rc;
682 static HRESULT test_secondary8(LPGUID lpGuid)
684 HRESULT rc;
685 LPDIRECTSOUND8 dso=NULL;
686 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
687 DSBUFFERDESC bufdesc;
688 DSCAPS dscaps;
689 WAVEFORMATEX wfx, wfx1;
690 DWORD f, tag;
691 int ref;
693 /* Create the DirectSound object */
694 rc = DirectSoundCreate8(lpGuid, &dso, NULL);
695 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
696 "DirectSoundCreate8() failed: %08lx\n",rc);
697 if (rc!=DS_OK)
698 return rc;
700 /* Get the device capabilities */
701 ZeroMemory(&dscaps, sizeof(dscaps));
702 dscaps.dwSize=sizeof(dscaps);
703 rc=IDirectSound8_GetCaps(dso,&dscaps);
704 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %08lx\n",rc);
705 if (rc!=DS_OK)
706 goto EXIT;
708 /* We must call SetCooperativeLevel before creating primary buffer */
709 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
710 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
711 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
712 if (rc!=DS_OK)
713 goto EXIT;
715 ZeroMemory(&bufdesc, sizeof(bufdesc));
716 bufdesc.dwSize=sizeof(bufdesc);
717 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
718 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
719 ok(rc==DS_OK && primary!=NULL,
720 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer "
721 "%08lx\n",rc);
723 if (rc==DS_OK && primary!=NULL) {
724 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
725 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08lx\n", rc);
726 if (rc!=DS_OK)
727 goto EXIT1;
729 for (f = 0; f < ARRAY_SIZE(formats); f++) {
730 for (tag = 0; tag < ARRAY_SIZE(format_tags); tag++) {
731 WAVEFORMATEXTENSIBLE wfxe;
733 /* if float, we only want to test 32-bit */
734 if ((format_tags[tag] == WAVE_FORMAT_IEEE_FLOAT) && (formats[f][1] != 32))
735 continue;
737 init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
738 formats[f][2]);
739 secondary=NULL;
740 ZeroMemory(&bufdesc, sizeof(bufdesc));
741 bufdesc.dwSize=sizeof(bufdesc);
742 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
743 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
744 wfx.nBlockAlign);
745 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
746 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() "
747 "should have returned DSERR_INVALIDPARAM, returned: %08lx\n", rc);
748 if (rc==DS_OK && secondary!=NULL)
749 IDirectSoundBuffer_Release(secondary);
751 secondary=NULL;
752 ZeroMemory(&bufdesc, sizeof(bufdesc));
753 bufdesc.dwSize=sizeof(bufdesc);
754 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
755 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
756 wfx.nBlockAlign);
757 bufdesc.lpwfxFormat=&wfx;
758 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
759 if (wfx.wBitsPerSample != 8 && wfx.wBitsPerSample != 16)
760 ok(((rc == DSERR_CONTROLUNAVAIL || rc == DSERR_INVALIDCALL || rc == DSERR_INVALIDPARAM /* 2003 */) && !secondary)
761 || rc == DS_OK, /* driver dependent? */
762 "IDirectSound_CreateSoundBuffer() "
763 "should have returned (DSERR_CONTROLUNAVAIL or DSERR_INVALIDCALL) "
764 "and NULL, returned: %08lx %p\n", rc, secondary);
765 else
766 ok(rc==DS_OK && secondary!=NULL,
767 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
768 "buffer %08lx\n",rc);
769 if (secondary)
770 IDirectSoundBuffer_Release(secondary);
771 secondary = NULL;
773 bufdesc.lpwfxFormat=(WAVEFORMATEX*)&wfxe;
774 wfxe.Format = wfx;
775 wfxe.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
776 wfxe.SubFormat = (format_tags[tag] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
777 wfxe.Format.cbSize = 1;
778 wfxe.Samples.wValidBitsPerSample = wfx.wBitsPerSample;
779 wfxe.dwChannelMask = (wfx.nChannels == 1 ? KSAUDIO_SPEAKER_MONO : KSAUDIO_SPEAKER_STEREO);
781 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
782 ok(rc==DSERR_INVALIDPARAM && !secondary,
783 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
784 rc, secondary);
785 if (secondary)
787 IDirectSoundBuffer_Release(secondary);
788 secondary=NULL;
791 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx) + 1;
793 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
794 ok(((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL /* 2003 */ || rc==DSERR_INVALIDPARAM) && !secondary)
795 || rc==DS_OK /* driver dependent? */,
796 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
797 rc, secondary);
798 if (secondary)
800 IDirectSoundBuffer_Release(secondary);
801 secondary=NULL;
804 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx);
805 wfxe.SubFormat = GUID_NULL;
806 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
807 ok((rc==DSERR_INVALIDPARAM || rc==DSERR_INVALIDCALL) && !secondary,
808 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
809 rc, secondary);
810 if (secondary)
812 IDirectSoundBuffer_Release(secondary);
813 secondary=NULL;
816 wfxe.Format.cbSize = sizeof(wfxe);
817 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
818 ok((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL || rc==DSERR_INVALIDPARAM) && !secondary,
819 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
820 rc, secondary);
821 if (secondary)
823 IDirectSoundBuffer_Release(secondary);
824 secondary=NULL;
827 wfxe.SubFormat = (format_tags[tag] == WAVE_FORMAT_PCM ? KSDATAFORMAT_SUBTYPE_PCM : KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
828 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
829 ok(rc==DS_OK && secondary,
830 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
831 rc, secondary);
832 if (secondary)
834 IDirectSoundBuffer_Release(secondary);
835 secondary=NULL;
838 wfxe.Format.cbSize = sizeof(wfxe) + 1;
839 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
840 ok(((rc==DSERR_CONTROLUNAVAIL || rc==DSERR_INVALIDCALL /* 2003 */ || rc==DSERR_INVALIDPARAM) && !secondary)
841 || rc==DS_OK /* driver dependent? */,
842 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
843 rc, secondary);
844 if (secondary)
846 IDirectSoundBuffer_Release(secondary);
847 secondary=NULL;
850 wfxe.Format.cbSize = sizeof(wfxe) - sizeof(wfx);
851 ++wfxe.Samples.wValidBitsPerSample;
852 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
853 ok(rc==DSERR_INVALIDPARAM && !secondary,
854 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
855 rc, secondary);
856 if (secondary)
858 IDirectSoundBuffer_Release(secondary);
859 secondary=NULL;
861 --wfxe.Samples.wValidBitsPerSample;
863 wfxe.Samples.wValidBitsPerSample = 0;
864 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
865 ok(rc==DS_OK && secondary,
866 "IDirectSound_CreateSoundBuffer() returned: %08lx %p\n",
867 rc, secondary);
868 if (secondary)
870 IDirectSoundBuffer_Release(secondary);
871 secondary=NULL;
873 wfxe.Samples.wValidBitsPerSample = wfxe.Format.wBitsPerSample;
875 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
876 ok(rc==DS_OK && secondary!=NULL,
877 "IDirectSound_CreateSoundBuffer() failed to create a secondary "
878 "buffer %08lx\n",rc);
880 if (rc==DS_OK && secondary!=NULL) {
881 if (winetest_interactive) {
882 trace(" Testing a secondary buffer at %ldx%dx%d (fmt=%d) "
883 "with a primary buffer at %ldx%dx%d\n",
884 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
885 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
887 test_buffer8(dso,&secondary,FALSE,FALSE,0,FALSE,0,
888 winetest_interactive,1.0,FALSE,NULL,FALSE,FALSE);
890 ref=IDirectSoundBuffer_Release(secondary);
891 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
892 "should have 0\n",ref);
896 EXIT1:
897 ref=IDirectSoundBuffer_Release(primary);
898 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
899 "should have 0\n",ref);
902 /* Set the CooperativeLevel back to normal */
903 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
904 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
905 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08lx\n", rc);
907 EXIT:
908 ref=IDirectSound8_Release(dso);
909 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
910 if (ref!=0)
911 return DSERR_GENERIC;
913 return rc;
916 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
917 LPCSTR lpcstrModule, LPVOID lpContext)
919 HRESULT rc;
920 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
921 rc = test_dsound8(lpGuid);
922 if (rc == DSERR_NODRIVER)
923 trace(" No Driver\n");
924 else if (rc == DSERR_ALLOCATED)
925 trace(" Already In Use\n");
926 else if (rc == E_FAIL)
927 trace(" No Device\n");
928 else {
929 test_primary8(lpGuid);
930 test_primary_secondary8(lpGuid);
931 test_secondary8(lpGuid);
934 return TRUE;
937 static void dsound8_tests(void)
939 HRESULT rc;
940 rc = DirectSoundEnumerateA(dsenum_callback, NULL);
941 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %08lx\n",rc);
944 static void test_hw_buffers(void)
946 IDirectSound8 *ds;
947 IDirectSoundBuffer *primary, *primary2, **secondaries, *secondary;
948 IDirectSoundBuffer8 *buf8;
949 DSCAPS caps;
950 DSBCAPS bufcaps;
951 DSBUFFERDESC bufdesc;
952 WAVEFORMATEX fmt;
953 UINT i;
954 HRESULT hr;
956 hr = DirectSoundCreate8(NULL, &ds, NULL);
957 ok(hr == S_OK || hr == DSERR_NODRIVER || hr == DSERR_ALLOCATED || hr == E_FAIL,
958 "DirectSoundCreate8 failed: %08lx\n", hr);
959 if(hr != S_OK)
960 return;
962 caps.dwSize = sizeof(caps);
964 hr = IDirectSound8_GetCaps(ds, &caps);
965 ok(hr == S_OK, "GetCaps failed: %08lx\n", hr);
967 ok(caps.dwPrimaryBuffers == 1, "Got wrong number of primary buffers: %lu\n",
968 caps.dwPrimaryBuffers);
970 /* DSBCAPS_LOC* is ignored for primary buffers */
971 bufdesc.dwSize = sizeof(bufdesc);
972 bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE |
973 DSBCAPS_PRIMARYBUFFER;
974 bufdesc.dwBufferBytes = 0;
975 bufdesc.dwReserved = 0;
976 bufdesc.lpwfxFormat = NULL;
977 bufdesc.guid3DAlgorithm = GUID_NULL;
979 hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &primary, NULL);
980 ok(hr == S_OK, "CreateSoundBuffer failed: %08lx\n", hr);
981 if(hr != S_OK){
982 IDirectSound8_Release(ds);
983 return;
986 bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCSOFTWARE |
987 DSBCAPS_PRIMARYBUFFER;
989 hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &primary2, NULL);
990 ok(hr == S_OK, "CreateSoundBuffer failed: %08lx\n", hr);
991 ok(primary == primary2, "Got different primary buffers: %p, %p\n", primary, primary2);
992 if(hr == S_OK)
993 IDirectSoundBuffer_Release(primary2);
995 buf8 = (IDirectSoundBuffer8 *)0xDEADBEEF;
996 hr = IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundBuffer8,
997 (void**)&buf8);
998 ok(hr == E_NOINTERFACE, "QueryInterface gave wrong failure: %08lx\n", hr);
999 ok(buf8 == NULL, "Pointer didn't get set to NULL\n");
1001 fmt.wFormatTag = WAVE_FORMAT_PCM;
1002 fmt.nChannels = 2;
1003 fmt.nSamplesPerSec = 48000;
1004 fmt.wBitsPerSample = 16;
1005 fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8;
1006 fmt.nAvgBytesPerSec = fmt.nBlockAlign * fmt.nSamplesPerSec;
1007 fmt.cbSize = 0;
1009 bufdesc.lpwfxFormat = &fmt;
1010 bufdesc.dwBufferBytes = fmt.nSamplesPerSec * fmt.nBlockAlign / 10;
1011 bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_LOCHARDWARE |
1012 DSBCAPS_CTRLVOLUME;
1014 secondaries = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
1015 sizeof(IDirectSoundBuffer *) * caps.dwMaxHwMixingAllBuffers);
1017 /* try to fill all of the hw buffers */
1018 trace("dwMaxHwMixingAllBuffers: %lu\n", caps.dwMaxHwMixingAllBuffers);
1019 trace("dwMaxHwMixingStaticBuffers: %lu\n", caps.dwMaxHwMixingStaticBuffers);
1020 trace("dwMaxHwMixingStreamingBuffers: %lu\n", caps.dwMaxHwMixingStreamingBuffers);
1021 for(i = 0; i < caps.dwMaxHwMixingAllBuffers; ++i){
1022 hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &secondaries[i], NULL);
1023 ok(hr == S_OK || hr == E_NOTIMPL || broken(hr == DSERR_CONTROLUNAVAIL) || broken(hr == E_FAIL),
1024 "CreateSoundBuffer(%u) failed: %08lx\n", i, hr);
1025 if(hr != S_OK)
1026 break;
1028 bufcaps.dwSize = sizeof(bufcaps);
1029 hr = IDirectSoundBuffer_GetCaps(secondaries[i], &bufcaps);
1030 ok(hr == S_OK, "GetCaps failed: %08lx\n", hr);
1031 ok((bufcaps.dwFlags & DSBCAPS_LOCHARDWARE) != 0,
1032 "Buffer wasn't allocated in hardware, dwFlags: %lx\n", bufcaps.dwFlags);
1035 /* see if we can create one more */
1036 hr = IDirectSound8_CreateSoundBuffer(ds, &bufdesc, &secondary, NULL);
1037 ok((i == caps.dwMaxHwMixingAllBuffers && hr == DSERR_ALLOCATED) || /* out of hw buffers */
1038 (caps.dwMaxHwMixingAllBuffers == 0 && hr == DSERR_INVALIDCALL) || /* no hw buffers at all */
1039 hr == E_NOTIMPL || /* don't support hw buffers */
1040 broken(hr == DSERR_CONTROLUNAVAIL) || /* vmware winxp, others? */
1041 broken(hr == E_FAIL) || /* broken AC97 driver */
1042 broken(hr == S_OK) /* broken driver allows more hw bufs than dscaps claims */,
1043 "CreateSoundBuffer(%u) gave wrong error: %08lx\n", i, hr);
1044 if(hr == S_OK)
1045 IDirectSoundBuffer_Release(secondary);
1047 for(i = 0; i < caps.dwMaxHwMixingAllBuffers; ++i)
1048 if(secondaries[i])
1049 IDirectSoundBuffer_Release(secondaries[i]);
1051 HeapFree(GetProcessHeap(), 0, secondaries);
1053 IDirectSoundBuffer_Release(primary);
1054 IDirectSound8_Release(ds);
1057 static struct {
1058 UINT dev_count;
1059 GUID guid;
1060 } default_info = { 0 };
1062 static BOOL WINAPI default_device_cb(GUID *guid, const char *desc,
1063 const char *module, void *user)
1065 trace("guid: %p, desc: %s\n", guid, desc);
1066 if(!guid)
1067 ok(default_info.dev_count == 0, "Got NULL GUID not in first position\n");
1068 else{
1069 if(default_info.dev_count == 0){
1070 ok(IsEqualGUID(guid, &default_info.guid), "Expected default device GUID\n");
1071 }else{
1072 ok(!IsEqualGUID(guid, &default_info.guid), "Got default GUID at unexpected location: %u\n",
1073 default_info.dev_count);
1076 /* only count real devices */
1077 ++default_info.dev_count;
1080 return TRUE;
1083 static void test_first_device(void)
1085 IMMDeviceEnumerator *devenum;
1086 IMMDevice *defdev;
1087 IPropertyStore *ps;
1088 PROPVARIANT pv;
1089 HRESULT hr;
1091 hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL,
1092 CLSCTX_INPROC_SERVER, &IID_IMMDeviceEnumerator, (void**)&devenum);
1093 if(FAILED(hr)){
1094 win_skip("MMDevAPI is not available, skipping default device test\n");
1095 return;
1098 hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(devenum, eRender,
1099 eMultimedia, &defdev);
1100 if (hr == E_NOTFOUND) {
1101 win_skip("No default device found\n");
1102 return;
1104 ok(hr == S_OK, "GetDefaultAudioEndpoint failed: %08lx\n", hr);
1106 hr = IMMDevice_OpenPropertyStore(defdev, STGM_READ, &ps);
1107 ok(hr == S_OK, "OpenPropertyStore failed: %08lx\n", hr);
1109 PropVariantInit(&pv);
1111 hr = IPropertyStore_GetValue(ps, &PKEY_AudioEndpoint_GUID, &pv);
1112 ok(hr == S_OK, "GetValue failed: %08lx\n", hr);
1114 CLSIDFromString(pv.pwszVal, &default_info.guid);
1116 PropVariantClear(&pv);
1117 IPropertyStore_Release(ps);
1118 IMMDevice_Release(defdev);
1119 IMMDeviceEnumerator_Release(devenum);
1121 hr = DirectSoundEnumerateA(default_device_cb, NULL);
1122 ok(hr == S_OK, "DirectSoundEnumerateA failed: %08lx\n", hr);
1125 static void test_COM(void)
1127 IDirectSound *ds;
1128 IDirectSound8 *ds8 = (IDirectSound8*)0xdeadbeef;
1129 IUnknown *unk, *unk8;
1130 ULONG refcount;
1131 HRESULT hr;
1133 /* COM aggregation */
1134 hr = CoCreateInstance(&CLSID_DirectSound8, (IUnknown*)0xdeadbeef, CLSCTX_INPROC_SERVER,
1135 &IID_IUnknown, (void**)&ds8);
1136 ok(hr == CLASS_E_NOAGGREGATION,
1137 "DirectSound create failed: %08lx, expected CLASS_E_NOAGGREGATION\n", hr);
1138 ok(!ds8, "ds8 = %p\n", ds8);
1140 /* Invalid RIID */
1141 hr = CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
1142 &IID_IDirectSound3DBuffer, (void**)&ds8);
1143 ok(hr == E_NOINTERFACE,
1144 "DirectSound create failed: %08lx, expected E_NOINTERFACE\n", hr);
1146 /* Same refcount for IDirectSound and IDirectSound8 */
1147 hr = CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectSound8,
1148 (void**)&ds8);
1149 ok(hr == S_OK, "DirectSound create failed: %08lx, expected S_OK\n", hr);
1150 refcount = IDirectSound8_AddRef(ds8);
1151 ok(refcount == 2, "refcount == %lu, expected 2\n", refcount);
1152 hr = IDirectSound8_QueryInterface(ds8, &IID_IDirectSound, (void**)&ds);
1153 ok(hr == S_OK, "QueryInterface for IID_IDirectSound failed: %08lx\n", hr);
1154 refcount = IDirectSound8_AddRef(ds8);
1155 ok(refcount == 4, "refcount == %lu, expected 4\n", refcount);
1156 refcount = IDirectSound_AddRef(ds);
1157 ok(refcount == 5, "refcount == %lu, expected 5\n", refcount);
1159 /* Separate refcount for IUnknown */
1160 hr = IDirectSound_QueryInterface(ds, &IID_IUnknown, (void**)&unk);
1161 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08lx\n", hr);
1162 refcount = IUnknown_AddRef(unk);
1163 ok(refcount == 2, "refcount == %lu, expected 2\n", refcount);
1164 hr = IDirectSound8_QueryInterface(ds8, &IID_IUnknown, (void**)&unk8);
1165 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08lx\n", hr);
1166 refcount = IUnknown_AddRef(unk8);
1167 ok(refcount == 4, "refcount == %lu, expected 4\n", refcount);
1168 refcount = IDirectSound_AddRef(ds);
1169 ok(refcount == 6, "refcount == %lu, expected 6\n", refcount);
1171 while (IDirectSound_Release(ds));
1172 while (IUnknown_Release(unk));
1175 static void test_primary_flags(void)
1177 HRESULT rc;
1178 IDirectSound8 *dso;
1179 IDirectSoundBuffer *primary = NULL;
1180 IDirectSoundFXI3DL2Reverb *reverb;
1181 DSBUFFERDESC bufdesc;
1182 DSCAPS dscaps;
1184 /* Create a DirectSound8 object */
1185 rc = DirectSoundCreate8(NULL, &dso, NULL);
1186 ok(rc == DS_OK || rc==DSERR_NODRIVER, "Failed: %08lx\n",rc);
1188 if (rc!=DS_OK)
1189 return;
1191 rc = IDirectSound8_SetCooperativeLevel(dso, get_hwnd(), DSSCL_PRIORITY);
1192 ok(rc == DS_OK,"Failed: %08lx\n", rc);
1193 if (rc != DS_OK) {
1194 IDirectSound8_Release(dso);
1195 return;
1198 dscaps.dwSize = sizeof(dscaps);
1199 rc = IDirectSound8_GetCaps(dso, &dscaps);
1200 ok(rc == DS_OK,"Failed: %08lx\n", rc);
1201 trace("0x%lx\n", dscaps.dwFlags);
1203 ZeroMemory(&bufdesc, sizeof(bufdesc));
1204 bufdesc.dwSize = sizeof(bufdesc);
1205 bufdesc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRLFX;
1206 rc = IDirectSound8_CreateSoundBuffer(dso, &bufdesc, &primary, NULL);
1207 ok(rc == E_INVALIDARG, "got %08lx\n", rc);
1209 ZeroMemory(&bufdesc, sizeof(bufdesc));
1210 bufdesc.dwSize = sizeof(bufdesc);
1211 bufdesc.dwFlags = DSBCAPS_PRIMARYBUFFER | DSBCAPS_CTRL3D;
1212 rc = IDirectSound8_CreateSoundBuffer(dso, &bufdesc, &primary, NULL);
1213 ok((rc == DS_OK && primary != NULL), "Failed to create a primary buffer: %08lx\n", rc);
1214 if (rc == DS_OK) {
1215 rc = IDirectSoundBuffer_QueryInterface(primary, &IID_IDirectSoundFXI3DL2Reverb, (LPVOID*)&reverb);
1216 ok(rc==E_NOINTERFACE,"Failed: %08lx\n", rc);
1218 IDirectSoundBuffer_Release(primary);
1221 IDirectSound8_Release(dso);
1224 static IMediaObject testdmo;
1225 static IMediaObjectInPlace testdmo_inplace;
1226 static LONG testdmo_refcount;
1227 static WAVEFORMATEX testdmo_input_type;
1228 static BOOL testdmo_input_type_set, testdmo_output_type_set;
1230 static unsigned int got_Discontinuity;
1231 static HANDLE got_Process;
1233 static HRESULT WINAPI dmo_QueryInterface(IMediaObject *iface, REFIID iid, void **out)
1235 if (winetest_debug > 1) trace("QueryInterface(%s)\n", wine_dbgstr_guid(iid));
1237 if (IsEqualGUID(iid, &IID_IMediaObject))
1238 *out = iface;
1239 else if (IsEqualGUID(iid, &IID_IMediaObjectInPlace))
1240 *out = &testdmo_inplace;
1241 else
1242 return E_NOINTERFACE;
1244 IUnknown_AddRef((IUnknown *)*out);
1245 return S_OK;
1248 static ULONG WINAPI dmo_AddRef(IMediaObject *iface)
1250 return InterlockedIncrement(&testdmo_refcount);
1253 static ULONG WINAPI dmo_Release(IMediaObject *iface)
1255 return InterlockedDecrement(&testdmo_refcount);
1258 static HRESULT WINAPI dmo_GetStreamCount(IMediaObject *iface, DWORD *input, DWORD *output)
1260 ok(0, "Unexpected call.\n");
1261 return E_NOTIMPL;
1264 static HRESULT WINAPI dmo_GetInputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
1266 ok(0, "Unexpected call.\n");
1267 return E_NOTIMPL;
1270 static HRESULT WINAPI dmo_GetOutputStreamInfo(IMediaObject *iface, DWORD index, DWORD *flags)
1272 ok(0, "Unexpected call.\n");
1273 return E_NOTIMPL;
1276 static HRESULT WINAPI dmo_GetInputType(IMediaObject *iface, DWORD index, DWORD type_index, DMO_MEDIA_TYPE *type)
1278 ok(0, "Unexpected call.\n");
1279 return E_NOTIMPL;
1282 static HRESULT WINAPI dmo_GetOutputType(IMediaObject *iface, DWORD index, DWORD type_index, DMO_MEDIA_TYPE *type)
1284 ok(0, "Unexpected call.\n");
1285 return E_NOTIMPL;
1288 static HRESULT WINAPI dmo_SetInputType(IMediaObject *iface, DWORD index, const DMO_MEDIA_TYPE *type, DWORD flags)
1290 const WAVEFORMATEX *wfx;
1292 if (winetest_debug > 1) trace("SetInputType()\n");
1294 ok(!index, "Got unexpected index %lu.\n", index);
1295 ok(!flags, "Got unexpected flags %#lx.\n", flags);
1297 ok(IsEqualGUID(&type->majortype, &MEDIATYPE_Audio), "Got major type %s.\n", debugstr_guid(&type->majortype));
1298 todo_wine ok(IsEqualGUID(&type->subtype, &MEDIASUBTYPE_PCM), "Got subtype %s.\n", debugstr_guid(&type->subtype));
1299 ok(type->bFixedSizeSamples == TRUE, "Got fixed size %d.\n", type->bFixedSizeSamples);
1300 ok(!type->bTemporalCompression, "Got temporal compression %d.\n", type->bTemporalCompression);
1301 ok(IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx), "Got format type %s.\n", debugstr_guid(&type->formattype));
1302 ok(!type->pUnk, "Got pUnk %p.\n", type->pUnk);
1303 ok(type->cbFormat == sizeof(WAVEFORMATEX), "Got format size %lu.\n", type->cbFormat);
1305 wfx = (WAVEFORMATEX *)type->pbFormat;
1306 todo_wine ok(type->lSampleSize == wfx->nBlockAlign, "Got sample size %lu.\n", type->lSampleSize);
1308 if (wfx->wBitsPerSample != 8)
1309 return DMO_E_TYPE_NOT_ACCEPTED;
1311 testdmo_input_type = *wfx;
1312 testdmo_input_type_set = TRUE;
1313 return S_OK;
1316 static HRESULT WINAPI dmo_SetOutputType(IMediaObject *iface, DWORD index, const DMO_MEDIA_TYPE *type, DWORD flags)
1318 if (winetest_debug > 1) trace("SetOutputType()\n");
1320 ok(!index, "Got unexpected index %lu.\n", index);
1321 ok(!flags, "Got unexpected flags %#lx.\n", flags);
1323 ok(testdmo_input_type_set, "Expected the input type to be set.\n");
1325 ok(IsEqualGUID(&type->majortype, &MEDIATYPE_Audio), "Got major type %s.\n", debugstr_guid(&type->majortype));
1326 ok(IsEqualGUID(&type->subtype, &MEDIASUBTYPE_PCM), "Got subtype %s.\n", debugstr_guid(&type->subtype));
1327 ok(type->bFixedSizeSamples == TRUE, "Got fixed size %d.\n", type->bFixedSizeSamples);
1328 ok(!type->bTemporalCompression, "Got temporal compression %d.\n", type->bTemporalCompression);
1329 ok(type->lSampleSize == 1, "Got sample size %lu.\n", type->lSampleSize);
1330 ok(IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx), "Got format type %s.\n", debugstr_guid(&type->formattype));
1331 ok(!type->pUnk, "Got pUnk %p.\n", type->pUnk);
1332 ok(type->cbFormat == sizeof(WAVEFORMATEX), "Got format size %lu.\n", type->cbFormat);
1334 ok(!memcmp(type->pbFormat, &testdmo_input_type, sizeof(WAVEFORMATEX)), "Format blocks didn't match.\n");
1336 testdmo_output_type_set = TRUE;
1337 return S_OK;
1340 static HRESULT WINAPI dmo_GetInputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
1342 ok(0, "Unexpected call.\n");
1343 return E_NOTIMPL;
1346 static HRESULT WINAPI dmo_GetOutputCurrentType(IMediaObject *iface, DWORD index, DMO_MEDIA_TYPE *type)
1348 ok(0, "Unexpected call.\n");
1349 return E_NOTIMPL;
1352 static HRESULT WINAPI dmo_GetInputSizeInfo(IMediaObject *iface, DWORD index,
1353 DWORD *size, DWORD *lookahead, DWORD *alignment)
1355 ok(0, "Unexpected call.\n");
1356 return E_NOTIMPL;
1359 static HRESULT WINAPI dmo_GetOutputSizeInfo(IMediaObject *iface, DWORD index, DWORD *size, DWORD *alignment)
1361 ok(0, "Unexpected call.\n");
1362 return E_NOTIMPL;
1365 static HRESULT WINAPI dmo_GetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME *latency)
1367 ok(0, "Unexpected call.\n");
1368 return E_NOTIMPL;
1371 static HRESULT WINAPI dmo_SetInputMaxLatency(IMediaObject *iface, DWORD index, REFERENCE_TIME latency)
1373 ok(0, "Unexpected call.\n");
1374 return E_NOTIMPL;
1377 static HRESULT WINAPI dmo_Flush(IMediaObject *iface)
1379 ok(0, "Unexpected call.\n");
1380 return E_NOTIMPL;
1383 static HRESULT WINAPI dmo_Discontinuity(IMediaObject *iface, DWORD index)
1385 if (winetest_debug > 1) trace("Discontinuity()\n");
1386 ++got_Discontinuity;
1387 return S_OK;
1390 static HRESULT WINAPI dmo_AllocateStreamingResources(IMediaObject *iface)
1392 ok(0, "Unexpected call.\n");
1393 return E_NOTIMPL;
1396 static HRESULT WINAPI dmo_FreeStreamingResources(IMediaObject *iface)
1398 ok(0, "Unexpected call.\n");
1399 return E_NOTIMPL;
1402 static HRESULT WINAPI dmo_GetInputStatus(IMediaObject *iface, DWORD index, DWORD *flags)
1404 ok(0, "Unexpected call.\n");
1405 return E_NOTIMPL;
1408 static HRESULT WINAPI dmo_ProcessInput(IMediaObject *iface, DWORD index,
1409 IMediaBuffer *buffer, DWORD flags, REFERENCE_TIME timestamp, REFERENCE_TIME timelength)
1411 ok(0, "Unexpected call.\n");
1412 return E_NOTIMPL;
1415 static HRESULT WINAPI dmo_ProcessOutput(IMediaObject *iface, DWORD flags,
1416 DWORD count, DMO_OUTPUT_DATA_BUFFER *buffers, DWORD *status)
1418 ok(0, "Unexpected call.\n");
1419 return E_NOTIMPL;
1422 static HRESULT WINAPI dmo_Lock(IMediaObject *iface, LONG lock)
1424 ok(0, "Unexpected call.\n");
1425 return E_NOTIMPL;
1428 static const IMediaObjectVtbl dmo_vtbl =
1430 dmo_QueryInterface,
1431 dmo_AddRef,
1432 dmo_Release,
1433 dmo_GetStreamCount,
1434 dmo_GetInputStreamInfo,
1435 dmo_GetOutputStreamInfo,
1436 dmo_GetInputType,
1437 dmo_GetOutputType,
1438 dmo_SetInputType,
1439 dmo_SetOutputType,
1440 dmo_GetInputCurrentType,
1441 dmo_GetOutputCurrentType,
1442 dmo_GetInputSizeInfo,
1443 dmo_GetOutputSizeInfo,
1444 dmo_GetInputMaxLatency,
1445 dmo_SetInputMaxLatency,
1446 dmo_Flush,
1447 dmo_Discontinuity,
1448 dmo_AllocateStreamingResources,
1449 dmo_FreeStreamingResources,
1450 dmo_GetInputStatus,
1451 dmo_ProcessInput,
1452 dmo_ProcessOutput,
1453 dmo_Lock,
1456 static HRESULT WINAPI dmo_inplace_QueryInterface(IMediaObjectInPlace *iface, REFIID iid, void **out)
1458 return IMediaObject_QueryInterface(&testdmo, iid, out);
1461 static ULONG WINAPI dmo_inplace_AddRef(IMediaObjectInPlace *iface)
1463 return IMediaObject_AddRef(&testdmo);
1466 static ULONG WINAPI dmo_inplace_Release(IMediaObjectInPlace *iface)
1468 return IMediaObject_Release(&testdmo);
1471 static HRESULT WINAPI dmo_inplace_Process(IMediaObjectInPlace *iface, ULONG size,
1472 BYTE *data, REFERENCE_TIME start, DWORD flags)
1474 if (winetest_debug > 1) trace("Process(size %lu)\n", size);
1476 ok(!start, "Got start time %s.\n", wine_dbgstr_longlong(start));
1477 ok(!flags, "Got flags %#lx.\n", flags);
1479 SetEvent(got_Process);
1481 return S_FALSE;
1484 static HRESULT WINAPI dmo_inplace_Clone(IMediaObjectInPlace *iface, IMediaObjectInPlace **ret_dmo)
1486 ok(0, "Unexpected call.\n");
1487 return E_NOTIMPL;
1490 static HRESULT WINAPI dmo_inplace_GetLatency(IMediaObjectInPlace *iface, REFERENCE_TIME *latency)
1492 ok(0, "Unexpected call.\n");
1493 return E_NOTIMPL;
1496 static const IMediaObjectInPlaceVtbl dmo_inplace_vtbl =
1498 dmo_inplace_QueryInterface,
1499 dmo_inplace_AddRef,
1500 dmo_inplace_Release,
1501 dmo_inplace_Process,
1502 dmo_inplace_Clone,
1503 dmo_inplace_GetLatency,
1506 static IMediaObject testdmo = {&dmo_vtbl};
1507 static IMediaObjectInPlace testdmo_inplace = {&dmo_inplace_vtbl};
1509 static HRESULT WINAPI dmo_cf_QueryInterface(IClassFactory *iface, REFIID iid, void **out)
1511 if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IClassFactory))
1513 *out = iface;
1514 return S_OK;
1516 return E_NOINTERFACE;
1519 static ULONG WINAPI dmo_cf_AddRef(IClassFactory *iface)
1521 return 2;
1524 static ULONG WINAPI dmo_cf_Release(IClassFactory *iface)
1526 return 1;
1529 static HRESULT WINAPI dmo_cf_CreateInstance(IClassFactory *iface, IUnknown *outer, REFIID iid, void **out)
1531 ok(!outer, "Unexpected outer parameter.\n");
1532 ok(IsEqualGUID(iid, &IID_IMediaObject), "Got unexpected iid %s.\n", wine_dbgstr_guid(iid));
1534 *out = &testdmo;
1535 IMediaObject_AddRef(&testdmo);
1536 return S_OK;
1539 static HRESULT WINAPI dmo_cf_LockServer(IClassFactory *iface, BOOL lock)
1541 ok(0, "Unexpected call.\n");
1542 return S_OK;
1545 static const IClassFactoryVtbl dmo_cf_vtbl =
1547 dmo_cf_QueryInterface,
1548 dmo_cf_AddRef,
1549 dmo_cf_Release,
1550 dmo_cf_CreateInstance,
1551 dmo_cf_LockServer,
1554 static IClassFactory testdmo_cf = {&dmo_cf_vtbl};
1556 static void test_effects(void)
1558 DSBPOSITIONNOTIFY notify_params = {DSBPN_OFFSETSTOP, CreateEventA(NULL, TRUE, FALSE, NULL)};
1559 DSBUFFERDESC buffer_desc = {.dwSize = sizeof(buffer_desc)};
1560 IMediaObject *echo = NULL, *reverb = NULL;
1561 IDirectSoundBuffer8 *buffer8;
1562 DSEFFECTDESC effects[2] = {};
1563 IDirectSoundBuffer *buffer;
1564 IDirectSoundNotify *notify;
1565 IDirectSound8 *dsound;
1566 DWORD size1, size2;
1567 IMediaObject *dmo;
1568 void *ptr1, *ptr2;
1569 WAVEFORMATEX wfx;
1570 DWORD results[2];
1571 IUnknown *unk;
1572 HRESULT hr;
1573 ULONG ref;
1575 hr = DirectSoundCreate8(NULL, &dsound, NULL);
1576 ok(hr == DS_OK || hr == DSERR_NODRIVER, "Got hr %#lx.\n", hr);
1577 if (FAILED(hr))
1578 return;
1580 hr = IDirectSound8_SetCooperativeLevel(dsound, get_hwnd(), DSSCL_PRIORITY);
1581 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1583 effects[0].dwSize = effects[1].dwSize = sizeof(effects[0]);
1584 effects[0].guidDSFXClass = GUID_DSFX_STANDARD_PARAMEQ;
1586 init_format(&wfx, WAVE_FORMAT_PCM, 11025, 8, 1);
1587 buffer_desc.dwBufferBytes = align(wfx.nAvgBytesPerSec * BUFFER_LEN / 1000, wfx.nBlockAlign);
1588 buffer_desc.lpwfxFormat = &wfx;
1589 hr = IDirectSound8_CreateSoundBuffer(dsound, &buffer_desc, &buffer, NULL);
1590 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1591 hr = IDirectSoundBuffer_QueryInterface(buffer, &IID_IDirectSoundBuffer8, (void **)&buffer8);
1592 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1593 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1594 ok(hr == DSERR_CONTROLUNAVAIL, "Got hr %#lx.\n", hr);
1596 IDirectSoundBuffer8_Release(buffer8);
1597 IDirectSoundBuffer_Release(buffer);
1599 buffer_desc.dwFlags = DSBCAPS_CTRLFX | DSBCAPS_CTRLPOSITIONNOTIFY;
1600 hr = IDirectSound8_CreateSoundBuffer(dsound, &buffer_desc, &buffer, NULL);
1601 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1602 hr = IDirectSoundBuffer_QueryInterface(buffer, &IID_IDirectSoundBuffer8, (void **)&buffer8);
1603 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1604 hr = IDirectSoundBuffer8_QueryInterface(buffer, &IID_IDirectSoundNotify, (void **)&notify);
1605 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1607 hr = IDirectSoundNotify_SetNotificationPositions(notify, 1, &notify_params);
1608 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1610 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, NULL, NULL);
1611 ok(hr == DSERR_INVALIDPARAM, "Got hr %#lx.\n", hr);
1612 hr = IDirectSoundBuffer8_SetFX(buffer8, 0, effects, NULL);
1613 ok(hr == DSERR_INVALIDPARAM, "Got hr %#lx.\n", hr);
1614 hr = IDirectSoundBuffer8_SetFX(buffer8, 0, NULL, results);
1615 ok(hr == DSERR_INVALIDPARAM, "Got hr %#lx.\n", hr);
1617 results[0] = 0xdeadbeef;
1618 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1619 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1620 ok(results[0] == DSFXR_LOCSOFTWARE, "Got result %#lx.\n", results[0]);
1622 hr = IDirectSoundBuffer8_Lock(buffer8, 0, 0, &ptr1, &size1, &ptr2, &size2, DSBLOCK_ENTIREBUFFER);
1623 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1624 results[0] = 0xdeadbeef;
1625 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1626 ok(hr == DSERR_INVALIDCALL, "Got hr %#lx.\n", hr);
1627 todo_wine ok(results[0] == 0xdeadbeef, "Got result %#lx.\n", results[0]);
1628 hr = IDirectSoundBuffer8_Unlock(buffer8, ptr1, size1, ptr2, size2);
1629 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1631 hr = IDirectSoundBuffer8_Play(buffer8, 0, 0, DSBPLAY_LOOPING);
1632 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1633 results[0] = 0xdeadbeef;
1634 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1635 ok(hr == DSERR_INVALIDCALL, "Got hr %#lx.\n", hr);
1636 todo_wine ok(results[0] == 0xdeadbeef, "Got result %#lx.\n", results[0]);
1637 hr = IDirectSoundBuffer8_Stop(buffer8);
1638 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1639 ok(!WaitForSingleObject(notify_params.hEventNotify, 1000), "Wait timed out.\n");
1641 effects[0].guidDSFXClass = GUID_NULL;
1642 results[0] = 0xdeadbeef;
1643 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1644 ok(hr == REGDB_E_CLASSNOTREG, "Got hr %#lx.\n", hr);
1645 ok(results[0] == DSFXR_UNKNOWN, "Got result %#lx.\n", results[0]);
1647 effects[0].guidDSFXClass = GUID_DSFX_STANDARD_PARAMEQ;
1648 results[0] = 0xdeadbeef;
1649 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1650 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1651 ok(results[0] == DSFXR_LOCSOFTWARE, "Got result %#lx.\n", results[0]);
1653 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0, &IID_IMediaObject, NULL);
1654 ok(hr == DSERR_INVALIDPARAM, "Got hr %#lx.\n", hr);
1656 dmo = (IMediaObject *)0xdeadbeef;
1657 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0, &GUID_NULL, (void **)&dmo);
1658 ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr);
1659 ok(!dmo, "Got object %p.\n", dmo);
1661 dmo = (IMediaObject *)0xdeadbeef;
1662 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_NULL, 0, &IID_IMediaObject, (void **)&dmo);
1663 ok(hr == DSERR_OBJECTNOTFOUND, "Got hr %#lx.\n", hr);
1664 ok(dmo == (IMediaObject *)0xdeadbeef, "Got object %p.\n", dmo);
1666 dmo = NULL;
1667 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0, &IID_IMediaObject, (void **)&dmo);
1668 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1669 ok(!!dmo, "Expected a non-NULL object.\n");
1670 IMediaObject_Release(dmo);
1672 dmo = NULL;
1673 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_DSFX_STANDARD_PARAMEQ, 0, &IID_IMediaObject, (void **)&dmo);
1674 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1675 ok(!!dmo, "Expected a non-NULL object.\n");
1676 IMediaObject_Release(dmo);
1678 dmo = (IMediaObject *)0xdeadbeef;
1679 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 1, &IID_IMediaObject, (void **)&dmo);
1680 ok(hr == DSERR_OBJECTNOTFOUND, "Got hr %#lx.\n", hr);
1681 ok(dmo == (IMediaObject *)0xdeadbeef, "Got object %p.\n", dmo);
1683 effects[0].guidDSFXClass = GUID_DSFX_STANDARD_PARAMEQ;
1684 effects[1].guidDSFXClass = GUID_NULL;
1685 results[0] = results[1] = 0xdeadbeef;
1686 hr = IDirectSoundBuffer8_SetFX(buffer8, 2, effects, results);
1687 ok(hr == REGDB_E_CLASSNOTREG, "Got hr %#lx.\n", hr);
1688 ok(results[0] == DSFXR_PRESENT, "Got result %#lx.\n", results[0]);
1689 ok(results[1] == DSFXR_UNKNOWN, "Got result %#lx.\n", results[1]);
1691 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0, &IID_IMediaObject, (void **)&dmo);
1692 todo_wine ok(hr == DSERR_OBJECTNOTFOUND, "Got hr %#lx.\n", hr);
1694 effects[0].guidDSFXClass = GUID_DSFX_STANDARD_PARAMEQ;
1695 effects[1].guidDSFXClass = GUID_DSFX_STANDARD_I3DL2REVERB;
1696 results[0] = results[1] = 0xdeadbeef;
1697 hr = IDirectSoundBuffer8_SetFX(buffer8, 2, effects, results);
1698 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1699 ok(results[0] == DSFXR_LOCSOFTWARE, "Got result %#lx.\n", results[0]);
1700 ok(results[1] == DSFXR_LOCSOFTWARE, "Got result %#lx.\n", results[1]);
1702 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_DSFX_STANDARD_PARAMEQ, 0, &IID_IMediaObject, (void **)&dmo);
1703 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1704 echo = dmo;
1705 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8,
1706 &GUID_DSFX_STANDARD_I3DL2REVERB, 0, &IID_IMediaObject, (void **)&dmo);
1707 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1708 reverb = dmo;
1710 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0, &IID_IMediaObject, (void **)&dmo);
1711 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1712 ok(dmo == echo, "Expected %p, got %p.\n", echo, dmo);
1713 IMediaObject_Release(dmo);
1715 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 1, &IID_IMediaObject, (void **)&dmo);
1716 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1717 ok(dmo == reverb, "Expected %p, got %p.\n", reverb, dmo);
1718 IMediaObject_Release(dmo);
1720 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8,
1721 &GUID_DSFX_STANDARD_I3DL2REVERB, 1, &IID_IMediaObject, (void **)&dmo);
1722 ok(hr == DSERR_OBJECTNOTFOUND, "Got hr %#lx.\n", hr);
1724 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0, &IID_IDirectSoundFXParamEq, (void **)&unk);
1725 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1726 IUnknown_Release(unk);
1728 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0,
1729 &IID_IDirectSoundFXParamEq, (void **)&unk);
1730 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1731 IUnknown_Release(unk);
1733 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0,
1734 &IID_IDirectSoundFXI3DL2Reverb, (void **)&unk);
1735 ok(hr == E_NOINTERFACE, "Got hr %#lx.\n", hr);
1737 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 1,
1738 &IID_IDirectSoundFXI3DL2Reverb, (void **)&unk);
1739 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1740 IUnknown_Release(unk);
1742 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8,
1743 &GUID_DSFX_STANDARD_I3DL2REVERB, 0, &IID_IDirectSoundFXI3DL2Reverb, (void **)&unk);
1744 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1745 IUnknown_Release(unk);
1747 IMediaObject_Release(echo);
1748 IMediaObject_Release(reverb);
1750 got_Process = CreateEventA(NULL, TRUE, FALSE, NULL);
1752 effects[0].guidDSFXClass = testdmo_clsid;
1753 results[0] = 0xdeadbeef;
1754 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1755 todo_wine ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1756 todo_wine ok(results[0] == DSFXR_LOCSOFTWARE, "Got result %#lx.\n", results[0]);
1757 todo_wine ok(!memcmp(&testdmo_input_type, &wfx, sizeof(WAVEFORMATEX)), "Format blocks didn't match.\n");
1759 ResetEvent(notify_params.hEventNotify);
1760 hr = IDirectSoundBuffer8_Play(buffer8, 0, 0, 0);
1761 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1762 todo_wine ok(got_Discontinuity == 1, "Got %u calls to IMediaObject::Discontinuity().\n", got_Discontinuity);
1764 todo_wine ok(!WaitForSingleObject(got_Process, 100), "Wait timed out.\n");
1766 hr = IDirectSoundBuffer8_Stop(buffer8);
1767 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1768 todo_wine ok(got_Discontinuity == 1, "Got %u calls to IMediaObject::Discontinuity().\n", got_Discontinuity);
1769 ok(!WaitForSingleObject(notify_params.hEventNotify, 1000), "Wait timed out.\n");
1771 ResetEvent(notify_params.hEventNotify);
1772 hr = IDirectSoundBuffer8_Play(buffer8, 0, 0, 0);
1773 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1774 todo_wine ok(got_Discontinuity == 2, "Got %u calls to IMediaObject::Discontinuity().\n", got_Discontinuity);
1776 hr = IDirectSoundBuffer8_Stop(buffer8);
1777 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1778 ok(!WaitForSingleObject(notify_params.hEventNotify, 1000), "Wait timed out.\n");
1780 hr = IDirectSoundBuffer8_SetFX(buffer8, 0, NULL, NULL);
1781 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1783 hr = IDirectSoundBuffer8_GetObjectInPath(buffer8, &GUID_All_Objects, 0, &IID_IMediaObject, (void **)&dmo);
1784 ok(hr == DSERR_OBJECTNOTFOUND, "Got hr %#lx.\n", hr);
1786 CloseHandle(got_Process);
1787 IDirectSoundBuffer8_Release(buffer8);
1788 ref = IDirectSoundBuffer_Release(buffer);
1789 ok(!ref, "Got outstanding refcount %lu.\n", ref);
1791 init_format(&wfx, WAVE_FORMAT_PCM, 11025, 16, 1);
1792 hr = IDirectSound8_CreateSoundBuffer(dsound, &buffer_desc, &buffer, NULL);
1793 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1794 hr = IDirectSoundBuffer_QueryInterface(buffer, &IID_IDirectSoundBuffer8, (void **)&buffer8);
1795 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1797 results[0] = 0xdeadbeef;
1798 hr = IDirectSoundBuffer8_SetFX(buffer8, 1, effects, results);
1799 ok(hr == DMO_E_TYPE_NOT_ACCEPTED, "Got hr %#lx.\n", hr);
1800 todo_wine ok(results[0] == DSFXR_UNKNOWN, "Got result %#lx.\n", results[0]);
1802 IDirectSoundNotify_Release(notify);
1803 IDirectSoundBuffer8_Release(buffer8);
1804 ref = IDirectSoundBuffer_Release(buffer);
1805 ok(!ref, "Got outstanding refcount %lu.\n", ref);
1807 ref = IDirectSound8_Release(dsound);
1808 ok(!ref, "Got outstanding refcount %lu.\n", ref);
1811 static void test_AcquireResources(void)
1813 IDirectSound8 *dsound;
1814 IDirectSoundBuffer *primary, *secondary;
1815 DSBUFFERDESC bufdesc;
1816 WAVEFORMATEX fmt;
1817 HRESULT hr;
1819 hr = DirectSoundCreate8(NULL, &dsound, NULL);
1820 ok(hr == DS_OK || hr == DSERR_NODRIVER, "Got hr %#lx.\n", hr);
1821 if (FAILED(hr))
1822 return;
1824 hr = IDirectSound8_SetCooperativeLevel(dsound, get_hwnd(), DSSCL_PRIORITY);
1825 ok(hr == DS_OK, "Got hr %#lx.\n", hr);
1827 bufdesc.dwSize = sizeof(bufdesc);
1828 bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_PRIMARYBUFFER;
1829 bufdesc.dwBufferBytes = 0;
1830 bufdesc.dwReserved = 0;
1831 bufdesc.lpwfxFormat = NULL;
1832 bufdesc.guid3DAlgorithm = GUID_NULL;
1834 hr = IDirectSound8_CreateSoundBuffer(dsound, &bufdesc, &primary, NULL);
1835 ok(hr == S_OK, "CreateSoundBuffer failed: %08lx\n", hr);
1836 if(hr != S_OK) {
1837 IDirectSound_Release(dsound);
1838 return;
1841 fmt.wFormatTag = WAVE_FORMAT_PCM;
1842 fmt.nChannels = 2;
1843 fmt.nSamplesPerSec = 48000;
1844 fmt.wBitsPerSample = 16;
1845 fmt.nBlockAlign = fmt.nChannels * fmt.wBitsPerSample / 8;
1846 fmt.nAvgBytesPerSec = fmt.nBlockAlign * fmt.nSamplesPerSec;
1847 fmt.cbSize = 0;
1849 bufdesc.lpwfxFormat = &fmt;
1850 bufdesc.dwBufferBytes = fmt.nSamplesPerSec * fmt.nBlockAlign / 10;
1851 bufdesc.dwFlags = DSBCAPS_LOCDEFER | DSBCAPS_CTRLVOLUME;
1853 /* see if we can create one more */
1854 hr = IDirectSound8_CreateSoundBuffer(dsound, &bufdesc, &secondary, NULL);
1855 ok(hr == S_OK, "CreateSoundBuffer gave wrong error: %08lx\n", hr);
1856 if(hr == S_OK) {
1857 DWORD status;
1858 IDirectSoundBuffer8 *buffer8;
1860 hr = IDirectSoundBuffer_QueryInterface(secondary, &IID_IDirectSoundBuffer8, (void **)&buffer8);
1861 ok(hr == S_OK, "got: %08lx\n", hr);
1863 status = 0xFFFF;
1864 hr = IDirectSoundBuffer8_GetStatus(buffer8, &status);
1865 ok(hr == S_OK, "got: %08lx\n", hr);
1866 todo_wine ok(status == 0, "got: %08lx\n", status);
1868 hr = IDirectSoundBuffer8_AcquireResources(buffer8, 0, 0, NULL);
1869 ok(hr == S_OK, "got: %08lx\n", hr);
1871 status = 0xFFFF;
1872 hr = IDirectSoundBuffer8_GetStatus(buffer8, &status);
1873 ok(hr == S_OK, "got: %08lx\n", hr);
1874 ok(status == DSBSTATUS_LOCSOFTWARE, "got: %08lx\n", status);
1876 IDirectSoundBuffer8_Release(buffer8);
1877 IDirectSoundBuffer_Release(secondary);
1880 IDirectSoundBuffer_Release(primary);
1881 IDirectSound_Release(dsound);
1884 static void test_implicit_mta(void)
1886 HRESULT hr;
1887 IDirectSound8 *dso;
1888 struct apt_data test_apt_data;
1890 check_apttype(&test_apt_data);
1891 ok(test_apt_data.type == APTTYPE_UNITIALIZED, "got apt type %d.\n", test_apt_data.type);
1893 /* test DirectSound8 object */
1894 hr = CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER,
1895 &IID_IDirectSound8, (void**)&dso);
1896 ok(hr == S_OK, "CoCreateInstance(CLSID_DirectSound8) failed: %08lx\n", hr);
1898 check_apttype(&test_apt_data);
1899 ok(test_apt_data.type == APTTYPE_UNITIALIZED, "got apt type %d.\n", test_apt_data.type);
1901 hr = IDirectSound8_Initialize(dso, NULL);
1902 ok(hr == DS_OK || hr == DSERR_NODRIVER || hr == DSERR_ALLOCATED || hr == E_FAIL,
1903 "IDirectSound8_Initialize() failed: %08lx\n", hr);
1904 if (hr == DS_OK) {
1905 check_apttype(&test_apt_data);
1906 todo_wine
1907 ok(test_apt_data.type == APTTYPE_MTA, "got apt type %d.\n", test_apt_data.type);
1908 todo_wine
1909 ok(test_apt_data.qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
1910 "got apt type qualifier %d.\n", test_apt_data.qualifier);
1912 IDirectSound8_Release(dso);
1914 check_apttype(&test_apt_data);
1915 ok(test_apt_data.type == APTTYPE_UNITIALIZED, "got apt type %d.\n", test_apt_data.type);
1917 /* test DirectSoundCreate8 */
1918 hr = DirectSoundCreate8(NULL, &dso, NULL);
1919 ok(hr == DS_OK || hr == DSERR_NODRIVER || hr == DSERR_ALLOCATED || hr == E_FAIL,
1920 "DirectSoundCreate8() failed: %08lx\n", hr);
1921 if (hr == DS_OK) {
1922 check_apttype(&test_apt_data);
1923 todo_wine
1924 ok(test_apt_data.type == APTTYPE_MTA, "got apt type %d.\n", test_apt_data.type);
1925 todo_wine
1926 ok(test_apt_data.qualifier == APTTYPEQUALIFIER_IMPLICIT_MTA,
1927 "got apt type qualifier %d.\n", test_apt_data.qualifier);
1928 IDirectSound8_Release(dso);
1931 check_apttype(&test_apt_data);
1932 ok(test_apt_data.type == APTTYPE_UNITIALIZED, "got apt type %d.\n", test_apt_data.type);
1935 START_TEST(dsound8)
1937 DWORD cookie;
1938 HRESULT hr;
1940 CoInitialize(NULL);
1942 /* Run implicit MTA tests before test COM so that a MTA won't be created before this test is run. */
1943 test_implicit_mta();
1944 test_COM();
1945 IDirectSound8_tests();
1946 dsound8_tests();
1947 test_hw_buffers();
1948 test_first_device();
1949 test_primary_flags();
1950 test_AcquireResources();
1952 hr = CoRegisterClassObject(&testdmo_clsid, (IUnknown *)&testdmo_cf,
1953 CLSCTX_INPROC_SERVER, REGCLS_MULTIPLEUSE, &cookie);
1954 ok(hr == S_OK, "Failed to register class, hr %#lx.\n", hr);
1956 test_effects();
1958 CoRevokeClassObject(cookie);
1960 CoUninitialize();