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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define NONAMELESSSTRUCT
29 #define NONAMELESSUNION
35 #include "wine/test.h"
41 #include "dsound_test.h"
43 static void dsound_dsound_tests()
46 LPDIRECTSOUND dso
=NULL
;
53 rc
=CoCreateInstance(&CLSID_DirectSound
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectSound
, (void**)&dso
);
54 ok(rc
==S_OK
,"CoCreateInstance failed: %s\n",DXGetErrorString9(rc
));
56 /* Try to Query for objects */
57 rc
=IDirectSound_QueryInterface(dso
,&IID_IUnknown
,(LPVOID
*)&unknown
);
58 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IUnknown) failed: %s\n",DXGetErrorString9(rc
));
60 IDirectSound_Release(unknown
);
62 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound
,(LPVOID
*)&ds
);
63 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %s\n",DXGetErrorString9(rc
));
65 IDirectSound_Release(ds
);
67 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
68 ok(rc
==E_NOINTERFACE
,"IDirectSound_QueryInterface(IID_IDirectSound8) should have failed: %s\n",DXGetErrorString9(rc
));
70 IDirectSound8_Release(ds8
);
72 /* DSOUND: Error: Invalid caps buffer */
73 rc
=IDirectSound_GetCaps(dso
,0);
74 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
76 ZeroMemory(&dscaps
, sizeof(dscaps
));
78 /* DSOUND: Error: Invalid caps buffer */
79 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
80 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
82 dscaps
.dwSize
=sizeof(dscaps
);
84 /* DSOUND: Running on a certified driver */
85 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
86 ok(rc
==DS_OK
,"GetCaps failed: %s\n",DXGetErrorString9(rc
));
88 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
89 dscaps
.dwFlags
,dscaps
.dwMinSecondarySampleRate
,
90 dscaps
.dwMaxSecondarySampleRate
);
93 ref
=IDirectSound_Release(dso
);
94 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
97 rc
=DirectSoundCreate(NULL
,&dso
,NULL
);
98 ok(rc
==S_OK
,"DirectSoundCreate failed: %s\n",DXGetErrorString9(rc
));
100 /* Try to Query for objects */
101 rc
=IDirectSound_QueryInterface(dso
,&IID_IUnknown
,(LPVOID
*)&unknown
);
102 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IUnknown) failed: %s\n",DXGetErrorString9(rc
));
104 IDirectSound_Release(unknown
);
106 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound
,(LPVOID
*)&ds
);
107 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %s\n",DXGetErrorString9(rc
));
109 IDirectSound_Release(ds
);
111 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
112 ok(rc
==E_NOINTERFACE
,"IDirectSound_QueryInterface(IID_IDirectSound8) should have failed: %s\n",DXGetErrorString9(rc
));
114 IDirectSound8_Release(ds8
);
116 /* DSOUND: Error: Invalid caps buffer */
117 rc
=IDirectSound_GetCaps(dso
,0);
118 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
120 ZeroMemory(&dscaps
, sizeof(dscaps
));
122 /* DSOUND: Error: Invalid caps buffer */
123 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
124 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
126 dscaps
.dwSize
=sizeof(dscaps
);
128 /* DSOUND: Running on a certified driver */
129 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
130 ok(rc
==DS_OK
,"GetCaps failed: %s\n",DXGetErrorString9(rc
));
132 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
133 dscaps
.dwFlags
,dscaps
.dwMinSecondarySampleRate
,
134 dscaps
.dwMaxSecondarySampleRate
);
137 ref
=IDirectSound_Release(dso
);
138 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
142 static void dsound_dsound8_tests()
145 LPDIRECTSOUND8 dso
=NULL
;
152 rc
=CoCreateInstance(&CLSID_DirectSound8
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectSound8
, (void**)&dso
);
153 ok(rc
==S_OK
,"CoCreateInstance failed: %s\n",DXGetErrorString9(rc
));
155 /* Try to Query for objects */
156 rc
=IDirectSound8_QueryInterface(dso
,&IID_IUnknown
,(LPVOID
*)&unknown
);
157 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %s\n",DXGetErrorString9(rc
));
159 IDirectSound8_Release(unknown
);
161 rc
=IDirectSound8_QueryInterface(dso
,&IID_IDirectSound
,(LPVOID
*)&ds
);
162 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %s\n",DXGetErrorString9(rc
));
164 IDirectSound_Release(ds
);
166 rc
=IDirectSound8_QueryInterface(dso
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
167 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSound8) should have failed: %s\n",DXGetErrorString9(rc
));
169 IDirectSound8_Release(ds8
);
171 /* DSOUND: Error: Invalid caps buffer */
172 rc
=IDirectSound8_GetCaps(dso
,0);
173 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
175 ZeroMemory(&dscaps
, sizeof(dscaps
));
177 /* DSOUND: Error: Invalid caps buffer */
178 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
179 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
181 dscaps
.dwSize
=sizeof(dscaps
);
183 /* DSOUND: Running on a certified driver */
184 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
185 ok(rc
==DS_OK
,"GetCaps failed: %s\n",DXGetErrorString9(rc
));
187 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
188 dscaps
.dwFlags
,dscaps
.dwMinSecondarySampleRate
,
189 dscaps
.dwMaxSecondarySampleRate
);
192 ref
=IDirectSound8_Release(dso
);
193 ok(ref
==0,"IDirectSound8_Release has %d references, should have 0\n",ref
);
196 rc
=DirectSoundCreate8(NULL
,&dso
,NULL
);
197 ok(rc
==S_OK
,"DirectSoundCreate8 failed: %s\n",DXGetErrorString9(rc
));
199 /* Try to Query for objects */
200 rc
=IDirectSound8_QueryInterface(dso
,&IID_IUnknown
,(LPVOID
*)&unknown
);
201 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %s\n",DXGetErrorString9(rc
));
203 IDirectSound8_Release(unknown
);
205 rc
=IDirectSound8_QueryInterface(dso
,&IID_IDirectSound
,(LPVOID
*)&ds
);
206 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %s\n",DXGetErrorString9(rc
));
208 IDirectSound_Release(ds
);
210 rc
=IDirectSound8_QueryInterface(dso
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
211 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSound8) should have failed: %s\n",DXGetErrorString9(rc
));
213 IDirectSound8_Release(ds8
);
215 /* DSOUND: Error: Invalid caps buffer */
216 rc
=IDirectSound8_GetCaps(dso
,0);
217 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
219 ZeroMemory(&dscaps
, sizeof(dscaps
));
221 /* DSOUND: Error: Invalid caps buffer */
222 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
223 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
225 dscaps
.dwSize
=sizeof(dscaps
);
227 /* DSOUND: Running on a certified driver */
228 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
229 ok(rc
==DS_OK
,"GetCaps failed: %s\n",DXGetErrorString9(rc
));
231 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
232 dscaps
.dwFlags
,dscaps
.dwMinSecondarySampleRate
,
233 dscaps
.dwMaxSecondarySampleRate
);
236 ref
=IDirectSound8_Release(dso
);
237 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
241 static HRESULT
test_dsound(LPGUID lpGuid
)
244 LPDIRECTSOUND dso
=NULL
;
251 /* DSOUND: Error: Invalid interface buffer */
252 rc
=DirectSoundCreate(lpGuid
,0,NULL
);
253 ok(rc
==DSERR_INVALIDPARAM
,"DirectSoundCreate should have failed: %s\n",DXGetErrorString9(rc
));
255 /* Create the DirectSound object */
256 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
257 ok(rc
==DS_OK
,"DirectSoundCreate failed: %s\n",DXGetErrorString9(rc
));
261 /* Try to Query for objects */
262 rc
=IDirectSound_QueryInterface(dso
,&IID_IUnknown
,(LPVOID
*)&unknown
);
263 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IUnknown) failed: %s\n",DXGetErrorString9(rc
));
265 IDirectSound_Release(unknown
);
267 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound
,(LPVOID
*)&ds
);
268 ok(rc
==DS_OK
,"IDirectSound_QueryInterface(IID_IDirectSound) failed: %s\n",DXGetErrorString9(rc
));
270 IDirectSound_Release(ds
);
272 rc
=IDirectSound_QueryInterface(dso
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
273 ok(rc
==E_NOINTERFACE
,"IDirectSound_QueryInterface(IID_IDirectSound8) should have failed: %s\n",DXGetErrorString9(rc
));
275 IDirectSound8_Release(ds8
);
277 /* DSOUND: Error: Invalid caps buffer */
278 rc
=IDirectSound_GetCaps(dso
,0);
279 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
281 ZeroMemory(&dscaps
, sizeof(dscaps
));
283 /* DSOUND: Error: Invalid caps buffer */
284 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
285 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
287 dscaps
.dwSize
=sizeof(dscaps
);
289 /* DSOUND: Running on a certified driver */
290 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
291 ok(rc
==DS_OK
,"GetCaps failed: %s\n",DXGetErrorString9(rc
));
293 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
294 dscaps
.dwFlags
,dscaps
.dwMinSecondarySampleRate
,
295 dscaps
.dwMaxSecondarySampleRate
);
298 /* Release the DirectSound object */
299 ref
=IDirectSound_Release(dso
);
300 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
302 return DSERR_GENERIC
;
304 /* Create a DirectSound object */
305 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
306 ok(rc
==DS_OK
,"DirectSoundCreate failed: %s\n",DXGetErrorString9(rc
));
308 LPDIRECTSOUND dso1
=NULL
;
310 /* Create a second DirectSound object */
311 rc
=DirectSoundCreate(lpGuid
,&dso1
,NULL
);
312 ok(rc
==DS_OK
,"DirectSoundCreate failed: %s\n",DXGetErrorString9(rc
));
314 /* Release the second DirectSound object */
315 ref
=IDirectSound_Release(dso1
);
316 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
317 ok(dso
!=dso1
,"DirectSound objects should be unique: dso=0x%08lx,dso1=0x%08lx\n",(DWORD
)dso
,(DWORD
)dso1
);
320 /* Release the first DirectSound object */
321 ref
=IDirectSound_Release(dso
);
322 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
324 return DSERR_GENERIC
;
331 static HRESULT
test_dsound8(LPGUID lpGuid
)
334 LPDIRECTSOUND8 dso
=NULL
;
341 /* DSOUND: Error: Invalid interface buffer */
342 rc
=DirectSoundCreate8(lpGuid
,0,NULL
);
343 ok(rc
==DSERR_INVALIDPARAM
,"DirectSoundCreate8 should have failed: %s\n",DXGetErrorString9(rc
));
345 /* Create the DirectSound8 object */
346 rc
=DirectSoundCreate8(lpGuid
,&dso
,NULL
);
347 ok(rc
==DS_OK
,"DirectSoundCreate8 failed: %s\n",DXGetErrorString9(rc
));
351 /* Try to Query for objects */
352 rc
=IDirectSound8_QueryInterface(dso
,&IID_IUnknown
,(LPVOID
*)&unknown
);
353 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %s\n",DXGetErrorString9(rc
));
355 IDirectSound8_Release(unknown
);
357 rc
=IDirectSound8_QueryInterface(dso
,&IID_IDirectSound
,(LPVOID
*)&ds
);
358 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %s\n",DXGetErrorString9(rc
));
360 IDirectSound_Release(ds
);
362 rc
=IDirectSound8_QueryInterface(dso
,&IID_IDirectSound8
,(LPVOID
*)&ds8
);
363 ok(rc
==DS_OK
,"IDirectSound8_QueryInterface(IID_IDirectSound8) failed: %s\n",DXGetErrorString9(rc
));
365 IDirectSound8_Release(ds8
);
367 /* DSOUND: Error: Invalid caps buffer */
368 rc
=IDirectSound8_GetCaps(dso
,0);
369 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
371 ZeroMemory(&dscaps
, sizeof(dscaps
));
373 /* DSOUND: Error: Invalid caps buffer */
374 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
375 ok(rc
==DSERR_INVALIDPARAM
,"GetCaps should have failed: %s\n",DXGetErrorString9(rc
));
377 dscaps
.dwSize
=sizeof(dscaps
);
379 /* DSOUND: Running on a certified driver */
380 rc
=IDirectSound8_GetCaps(dso
,&dscaps
);
381 ok(rc
==DS_OK
,"GetCaps failed: %s\n",DXGetErrorString9(rc
));
383 trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
384 dscaps
.dwFlags
,dscaps
.dwMinSecondarySampleRate
,
385 dscaps
.dwMaxSecondarySampleRate
);
388 /* Release the DirectSound8 object */
389 ref
=IDirectSound8_Release(dso
);
390 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
392 return DSERR_GENERIC
;
394 /* Create a DirectSound8 object */
395 rc
=DirectSoundCreate8(lpGuid
,&dso
,NULL
);
396 ok(rc
==DS_OK
,"DirectSoundCreate failed: %s\n",DXGetErrorString9(rc
));
398 LPDIRECTSOUND8 dso1
=NULL
;
400 /* Create a second DirectSound8 object */
401 rc
=DirectSoundCreate8(lpGuid
,&dso1
,NULL
);
402 ok(rc
==DS_OK
,"DirectSoundCreate8 failed: %s\n",DXGetErrorString9(rc
));
404 /* Release the second DirectSound8 object */
405 ref
=IDirectSound8_Release(dso1
);
406 ok(ref
==0,"IDirectSound8_Release has %d references, should have 0\n",ref
);
407 ok(dso
!=dso1
,"DirectSound8 objects should be unique: dso=0x%08lx,dso1=0x%08lx\n",(DWORD
)dso
,(DWORD
)dso1
);
410 /* Release the first DirectSound8 object */
411 ref
=IDirectSound8_Release(dso
);
412 ok(ref
==0,"IDirectSound8_Release has %d references, should have 0\n",ref
);
414 return DSERR_GENERIC
;
421 static HRESULT
test_primary(LPGUID lpGuid
)
424 LPDIRECTSOUND dso
=NULL
;
425 LPDIRECTSOUNDBUFFER primary
=NULL
,second
=NULL
,third
=NULL
;
426 DSBUFFERDESC bufdesc
;
430 /* Create the DirectSound object */
431 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
432 ok(rc
==DS_OK
,"DirectSoundCreate failed: 0x%lx\n",rc
);
436 /* Get the device capabilities */
437 ZeroMemory(&dscaps
, sizeof(dscaps
));
438 dscaps
.dwSize
=sizeof(dscaps
);
439 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
440 ok(rc
==DS_OK
,"GetCaps failed: 0x%lx\n",rc
);
444 /* DSOUND: Error: Invalid buffer description pointer */
445 rc
=IDirectSound_CreateSoundBuffer(dso
,0,0,NULL
);
446 ok(rc
==DSERR_INVALIDPARAM
,"CreateSoundBuffer should have failed: 0x%lx\n",rc
);
448 /* DSOUND: Error: Invalid buffer description pointer */
449 rc
=IDirectSound_CreateSoundBuffer(dso
,0,&primary
,NULL
);
450 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,"CreateSoundBuffer should have failed: rc=0x%lx,dsbo=0x%lx\n",rc
,(DWORD
)primary
);
452 /* DSOUND: Error: Invalid buffer description pointer */
453 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,0,NULL
);
454 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,"CreateSoundBuffer should have failed: rc=0x%lx,dsbo=0x%lx\n",rc
,(DWORD
)primary
);
456 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
458 /* DSOUND: Error: Invalid size */
459 /* DSOUND: Error: Invalid buffer description */
460 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
461 ok(rc
==DSERR_INVALIDPARAM
&& primary
==0,"CreateSoundBuffer should have failed: rc=0x%lx,primary=0x%lx\n",rc
,(DWORD
)primary
);
463 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
464 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
465 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
466 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
470 /* Testing the primary buffer */
472 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
473 bufdesc
.dwSize
=sizeof(bufdesc
);
474 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
475 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
476 ok(rc
==DS_OK
&& primary
!=NULL
,"CreateSoundBuffer failed to create a primary buffer: 0x%lx\n",rc
);
477 if (rc
==DS_OK
&& primary
!=NULL
) {
478 /* Try to create a second primary buffer */
479 /* DSOUND: Error: The primary buffer already exists. Any changes made to the buffer description will be ignored. */
480 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&second
,NULL
);
481 ok(rc
==DS_OK
&& second
==primary
,"CreateSoundBuffer should have returned original primary buffer: 0x%lx\n",rc
);
482 ref
=IDirectSoundBuffer_Release(second
);
483 ok(ref
==1,"IDirectSoundBuffer_Release primary has %d references, should have 1\n",ref
);
485 /* Try to duplicate a primary buffer */
486 /* DSOUND: Error: Can't duplicate primary buffers */
487 rc
=IDirectSound_DuplicateSoundBuffer(dso
,primary
,&third
);
489 ok(rc
!=DS_OK
,"IDirectSound_DuplicateSoundBuffer primary buffer should have failed 0x%lx\n",rc
);
491 if (winetest_interactive
)
493 trace("Playing a 5 seconds reference tone.\n");
494 trace("All subsequent tones should be identical to this one.\n");
495 trace("Listen for stutter, changes in pitch, volume, etc.\n");
497 test_buffer(dso
,primary
,1,FALSE
,0,FALSE
,0,winetest_interactive
&& !(dscaps
.dwFlags
& DSCAPS_EMULDRIVER
),5.0,0,0,0,0);
499 ref
=IDirectSoundBuffer_Release(primary
);
500 ok(ref
==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref
);
503 /* Set the CooperativeLevel back to normal */
504 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
505 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
506 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%lx\n",rc
);
509 ref
=IDirectSound_Release(dso
);
510 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
512 return DSERR_GENERIC
;
517 static HRESULT
test_secondary(LPGUID lpGuid
)
520 LPDIRECTSOUND dso
=NULL
;
521 LPDIRECTSOUNDBUFFER primary
=NULL
,secondary
=NULL
;
522 DSBUFFERDESC bufdesc
;
527 /* Create the DirectSound object */
528 rc
=DirectSoundCreate(lpGuid
,&dso
,NULL
);
529 ok(rc
==DS_OK
,"DirectSoundCreate failed: 0x%lx\n",rc
);
533 /* Get the device capabilities */
534 ZeroMemory(&dscaps
, sizeof(dscaps
));
535 dscaps
.dwSize
=sizeof(dscaps
);
536 rc
=IDirectSound_GetCaps(dso
,&dscaps
);
537 ok(rc
==DS_OK
,"GetCaps failed: 0x%lx\n",rc
);
541 /* We must call SetCooperativeLevel before creating primary buffer */
542 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
543 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_PRIORITY
);
544 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%0lx\n",rc
);
548 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
549 bufdesc
.dwSize
=sizeof(bufdesc
);
550 bufdesc
.dwFlags
=DSBCAPS_PRIMARYBUFFER
;
551 bufdesc
.dwFlags
|=(DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
552 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&primary
,NULL
);
553 ok(rc
==DS_OK
&& primary
!=NULL
,"CreateSoundBuffer failed to create a primary buffer 0x%lx\n", rc
);
555 if (rc
==DS_OK
&& primary
!=NULL
) {
556 for (f
=0;f
<NB_FORMATS
;f
++) {
557 init_format(&wfx
,WAVE_FORMAT_PCM
,formats
[f
][0],formats
[f
][1],formats
[f
][2]);
559 ZeroMemory(&bufdesc
, sizeof(bufdesc
));
560 bufdesc
.dwSize
=sizeof(bufdesc
);
561 bufdesc
.dwFlags
=DSBCAPS_GETCURRENTPOSITION2
;
562 bufdesc
.dwFlags
|=(DSBCAPS_CTRLFREQUENCY
|DSBCAPS_CTRLVOLUME
|DSBCAPS_CTRLPAN
);
563 bufdesc
.dwBufferBytes
=wfx
.nAvgBytesPerSec
*BUFFER_LEN
/1000;
564 bufdesc
.lpwfxFormat
=&wfx
;
565 trace(" Testing a secondary buffer at %ldx%dx%d\n",
566 wfx
.nSamplesPerSec
,wfx
.wBitsPerSample
,wfx
.nChannels
);
567 rc
=IDirectSound_CreateSoundBuffer(dso
,&bufdesc
,&secondary
,NULL
);
568 ok(rc
==DS_OK
&& secondary
!=NULL
,"CreateSoundBuffer failed to create a secondary buffer 0x%lx\n",rc
);
570 if (rc
==DS_OK
&& secondary
!=NULL
) {
571 test_buffer(dso
,secondary
,0,FALSE
,0,FALSE
,0,winetest_interactive
,1.0,0,NULL
,0,0);
573 ref
=IDirectSoundBuffer_Release(secondary
);
574 ok(ref
==0,"IDirectSoundBuffer_Release has %d references, should have 0\n",ref
);
578 ref
=IDirectSoundBuffer_Release(primary
);
579 ok(ref
==0,"IDirectSoundBuffer_Release primary has %d references, should have 0\n",ref
);
582 /* Set the CooperativeLevel back to normal */
583 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
584 rc
=IDirectSound_SetCooperativeLevel(dso
,get_hwnd(),DSSCL_NORMAL
);
585 ok(rc
==DS_OK
,"SetCooperativeLevel failed: 0x%0lx\n",rc
);
588 ref
=IDirectSound_Release(dso
);
589 ok(ref
==0,"IDirectSound_Release has %d references, should have 0\n",ref
);
591 return DSERR_GENERIC
;
596 static BOOL WINAPI
dsenum_callback(LPGUID lpGuid
, LPCSTR lpcstrDescription
,
597 LPCSTR lpcstrModule
, LPVOID lpContext
)
599 trace("*** Testing %s - %s\n",lpcstrDescription
,lpcstrModule
);
601 test_dsound8(lpGuid
);
602 test_primary(lpGuid
);
603 test_secondary(lpGuid
);
608 static void dsound_tests()
611 rc
=DirectSoundEnumerateA(&dsenum_callback
,NULL
);
612 ok(rc
==DS_OK
,"DirectSoundEnumerate failed: %ld\n",rc
);
619 dsound_dsound_tests();
620 dsound_dsound8_tests();