Fix some places where no driver present causes problems.
[wine/gsoc_dplay.git] / dlls / dsound / tests / ds3d8.c
blob7b8e9ca4daf9be701d78a15bc4f40c2cf49a05fc
1 /*
2 * Tests the panning and 3D functions of DirectSound
4 * Part of this test involves playing test tones. But this only makes
5 * sense if someone is going to carefully listen to it, and would only
6 * bother everyone else.
7 * So this is only done if the test is being run in interactive mode.
9 * Copyright (c) 2002-2004 Francois Gouget
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define NONAMELESSSTRUCT
27 #define NONAMELESSUNION
28 #include <windows.h>
30 #include <math.h>
31 #include <stdlib.h>
33 #include "wine/test.h"
34 #include "windef.h"
35 #include "wingdi.h"
36 #include "dsound.h"
37 #include "dxerr8.h"
39 #include "dsound_test.h"
41 static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,LPUNKNOWN)=NULL;
43 typedef struct {
44 char* wave;
45 DWORD wave_len;
47 LPDIRECTSOUNDBUFFER dsbo;
48 LPWAVEFORMATEX wfx;
49 DWORD buffer_size;
50 DWORD written;
51 DWORD played;
52 DWORD offset;
53 } play_state_t;
55 static int buffer_refill8(play_state_t* state, DWORD size)
57 LPVOID ptr1,ptr2;
58 DWORD len1,len2;
59 HRESULT rc;
61 if (size>state->wave_len-state->written)
62 size=state->wave_len-state->written;
64 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
65 &ptr1,&len1,&ptr2,&len2,0);
66 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
67 DXGetErrorString8(rc));
68 if (rc!=DS_OK)
69 return -1;
71 memcpy(ptr1,state->wave+state->written,len1);
72 state->written+=len1;
73 if (ptr2!=NULL) {
74 memcpy(ptr2,state->wave+state->written,len2);
75 state->written+=len2;
77 state->offset=state->written % state->buffer_size;
78 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
79 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
80 DXGetErrorString8(rc));
81 if (rc!=DS_OK)
82 return -1;
83 return size;
86 static int buffer_silence8(play_state_t* state, DWORD size)
88 LPVOID ptr1,ptr2;
89 DWORD len1,len2;
90 HRESULT rc;
91 BYTE s;
93 rc=IDirectSoundBuffer_Lock(state->dsbo,state->offset,size,
94 &ptr1,&len1,&ptr2,&len2,0);
95 ok(rc==DS_OK,"IDirectSoundBuffer_Lock() failed: %s\n",
96 DXGetErrorString8(rc));
97 if (rc!=DS_OK)
98 return -1;
100 s=(state->wfx->wBitsPerSample==8?0x80:0);
101 memset(ptr1,s,len1);
102 if (ptr2!=NULL) {
103 memset(ptr2,s,len2);
105 state->offset=(state->offset+size) % state->buffer_size;
106 rc=IDirectSoundBuffer_Unlock(state->dsbo,ptr1,len1,ptr2,len2);
107 ok(rc==DS_OK,"IDirectSoundBuffer_Unlock() failed: %s\n",
108 DXGetErrorString8(rc));
109 if (rc!=DS_OK)
110 return -1;
111 return size;
114 static int buffer_service8(play_state_t* state)
116 DWORD last_play_pos,play_pos,buf_free;
117 HRESULT rc;
119 rc=IDirectSoundBuffer_GetCurrentPosition(state->dsbo,&play_pos,NULL);
120 ok(rc==DS_OK,"IDirectSoundBuffer_GetCurrentPosition() failed: %s\n",
121 DXGetErrorString8(rc));
122 if (rc!=DS_OK) {
123 goto STOP;
126 /* Update the amount played */
127 last_play_pos=state->played % state->buffer_size;
128 if (play_pos<last_play_pos)
129 state->played+=state->buffer_size-last_play_pos+play_pos;
130 else
131 state->played+=play_pos-last_play_pos;
133 if (winetest_debug > 1)
134 trace("buf size=%ld last_play_pos=%ld play_pos=%ld played=%ld / %ld\n",
135 state->buffer_size,last_play_pos,play_pos,state->played,
136 state->wave_len);
138 if (state->played>state->wave_len)
140 /* Everything has been played */
141 goto STOP;
144 /* Refill the buffer */
145 if (state->offset<=play_pos)
146 buf_free=play_pos-state->offset;
147 else
148 buf_free=state->buffer_size-state->offset+play_pos;
150 if (winetest_debug > 1)
151 trace("offset=%ld free=%ld written=%ld / %ld\n",
152 state->offset,buf_free,state->written,state->wave_len);
153 if (buf_free==0)
154 return 1;
156 if (state->written<state->wave_len)
158 int w=buffer_refill8(state,buf_free);
159 if (w==-1)
160 goto STOP;
161 buf_free-=w;
162 if (state->written==state->wave_len && winetest_debug > 1)
163 trace("last sound byte at %ld\n",
164 (state->written % state->buffer_size));
167 if (buf_free>0) {
168 /* Fill with silence */
169 if (winetest_debug > 1)
170 trace("writing %ld bytes of silence\n",buf_free);
171 if (buffer_silence8(state,buf_free)==-1)
172 goto STOP;
174 return 1;
176 STOP:
177 if (winetest_debug > 1)
178 trace("stopping playback\n");
179 rc=IDirectSoundBuffer_Stop(state->dsbo);
180 ok(rc==DS_OK,"IDirectSoundBuffer_Stop() failed: %s\n",
181 DXGetErrorString8(rc));
182 return 0;
185 void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER dsbo,
186 BOOL is_primary, BOOL set_volume, LONG volume,
187 BOOL set_pan, LONG pan, BOOL play, double duration,
188 BOOL buffer3d, LPDIRECTSOUND3DLISTENER listener,
189 BOOL move_listener, BOOL move_sound)
191 HRESULT rc;
192 DSBCAPS dsbcaps;
193 WAVEFORMATEX wfx,wfx2;
194 DWORD size,status,freq;
195 int ref;
197 /* DSOUND: Error: Invalid caps pointer */
198 rc=IDirectSoundBuffer_GetCaps(dsbo,0);
199 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
200 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
202 ZeroMemory(&dsbcaps, sizeof(dsbcaps));
204 /* DSOUND: Error: Invalid caps pointer */
205 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
206 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetCaps() should have "
207 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
209 dsbcaps.dwSize=sizeof(dsbcaps);
210 rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
211 ok(rc==DS_OK,"IDirectSoundBuffer_GetCaps() failed: %s\n",
212 DXGetErrorString8(rc));
213 if (rc==DS_OK && winetest_debug > 1) {
214 trace(" Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags,
215 dsbcaps.dwBufferBytes);
218 /* Query the format size. Note that it may not match sizeof(wfx) */
219 size=0;
220 rc=IDirectSoundBuffer_GetFormat(dsbo,NULL,0,&size);
221 ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
222 "returned the needed size: rc=%s size=%ld\n",DXGetErrorString8(rc),size);
224 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
225 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
226 DXGetErrorString8(rc));
227 if (rc==DS_OK && winetest_debug > 1) {
228 trace(" Format: %s tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
229 is_primary ? "Primary" : "Secondary",
230 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
231 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
234 /* DSOUND: Error: Invalid frequency buffer */
235 rc=IDirectSoundBuffer_GetFrequency(dsbo,0);
236 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetFrequency() should have "
237 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
239 /* DSOUND: Error: Primary buffers don't support CTRLFREQUENCY */
240 rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq);
241 ok((rc==DS_OK && !is_primary) || (rc==DSERR_CONTROLUNAVAIL&&is_primary) ||
242 (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
243 "IDirectSoundBuffer_GetFrequency() failed: %s\n",DXGetErrorString8(rc));
244 if (rc==DS_OK) {
245 ok(freq==wfx.nSamplesPerSec,"The frequency returned by GetFrequency "
246 "%ld does not match the format %ld\n",freq,wfx.nSamplesPerSec);
249 /* DSOUND: Error: Invalid status pointer */
250 rc=IDirectSoundBuffer_GetStatus(dsbo,0);
251 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_GetStatus() should have "
252 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
254 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
255 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
256 DXGetErrorString8(rc));
257 ok(status==0,"status=0x%lx instead of 0\n",status);
259 if (is_primary) {
260 /* We must call SetCooperativeLevel to be allowed to call SetFormat */
261 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
262 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
263 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) "
264 "failed: %s\n",DXGetErrorString8(rc));
265 if (rc!=DS_OK)
266 return;
268 /* DSOUND: Error: Invalid format pointer */
269 rc=IDirectSoundBuffer_SetFormat(dsbo,0);
270 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have "
271 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
273 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
274 rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2);
275 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n",
276 DXGetErrorString8(rc));
278 /* There is no garantee that SetFormat will actually change the
279 * format to what we asked for. It depends on what the soundcard
280 * supports. So we must re-query the format.
282 rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
283 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n",
284 DXGetErrorString8(rc));
285 if (rc==DS_OK &&
286 (wfx.wFormatTag!=wfx2.wFormatTag ||
287 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
288 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
289 wfx.nChannels!=wfx2.nChannels)) {
290 trace("Requested format tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
291 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
292 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
293 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
294 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
295 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
298 /* Set the CooperativeLevel back to normal */
299 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
300 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
301 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
302 "failed: %s\n",DXGetErrorString8(rc));
305 if (play) {
306 play_state_t state;
307 DS3DLISTENER listener_param;
308 LPDIRECTSOUND3DBUFFER buffer=NULL;
309 DS3DBUFFER buffer_param;
310 DWORD start_time,now;
312 if (winetest_interactive) {
313 trace(" Playing %g second 440Hz tone at %ldx%dx%d\n", duration,
314 wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels);
317 if (is_primary) {
318 /* We must call SetCooperativeLevel to be allowed to call Lock */
319 /* DSOUND: Setting DirectSound cooperative level to
320 * DSSCL_WRITEPRIMARY */
321 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),
322 DSSCL_WRITEPRIMARY);
323 ok(rc==DS_OK,
324 "IDirectSound8_SetCooperativeLevel(DSSCL_WRITEPRIMARY) failed: "
325 "%s\n",DXGetErrorString8(rc));
326 if (rc!=DS_OK)
327 return;
329 if (buffer3d) {
330 LPDIRECTSOUNDBUFFER temp_buffer;
332 rc=IDirectSoundBuffer_QueryInterface(dsbo,&IID_IDirectSound3DBuffer,
333 (LPVOID *)&buffer);
334 ok(rc==DS_OK,"IDirectSoundBuffer_QueryInterface() failed: %s\n",
335 DXGetErrorString8(rc));
336 if (rc!=DS_OK)
337 return;
339 /* check the COM interface */
340 rc=IDirectSoundBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,
341 (LPVOID *)&temp_buffer);
342 ok(rc==DS_OK && temp_buffer!=NULL,
343 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
344 DXGetErrorString8(rc));
345 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",
346 (DWORD)temp_buffer,(DWORD)dsbo);
347 ref=IDirectSoundBuffer_Release(temp_buffer);
348 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
349 "should have 1\n",ref);
351 temp_buffer=NULL;
352 rc=IDirectSound3DBuffer_QueryInterface(dsbo, &IID_IDirectSoundBuffer,
353 (LPVOID *)&temp_buffer);
354 ok(rc==DS_OK && temp_buffer!=NULL,
355 "IDirectSound3DBuffer_QueryInterface() failed: %s\n",
356 DXGetErrorString8(rc));
357 ok(temp_buffer==dsbo,"COM interface broken: 0x%08lx != 0x%08lx\n",
358 (DWORD)temp_buffer,(DWORD)dsbo);
359 ref=IDirectSoundBuffer_Release(temp_buffer);
360 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
361 "should have 1\n",ref);
363 #if 0
364 /* FIXME: this works on windows */
365 ref=IDirectSoundBuffer_Release(dsbo);
366 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
367 "should have 0\n",ref);
369 rc=IDirectSound3DBuffer_QueryInterface(buffer,
370 &IID_IDirectSoundBuffer,
371 (LPVOID *)&dsbo);
372 ok(rc==DS_OK && dsbo!=NULL,"IDirectSound3DBuffer_QueryInterface() "
373 "failed: %s\n",DXGetErrorString8(rc),
374 #endif
376 /* DSOUND: Error: Invalid buffer */
377 rc=IDirectSound3DBuffer_GetAllParameters(buffer,0);
378 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
379 "failed: %s\n",DXGetErrorString8(rc));
381 ZeroMemory(&buffer_param, sizeof(buffer_param));
383 /* DSOUND: Error: Invalid buffer */
384 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
385 ok(rc==DSERR_INVALIDPARAM,"IDirectSound3DBuffer_GetAllParameters() "
386 "failed: %s\n",DXGetErrorString8(rc));
388 buffer_param.dwSize=sizeof(buffer_param);
389 rc=IDirectSound3DBuffer_GetAllParameters(buffer,&buffer_param);
390 ok(rc==DS_OK,"IDirectSound3DBuffer_GetAllParameters() failed: %s\n",
391 DXGetErrorString8(rc));
393 if (set_volume) {
394 if (dsbcaps.dwFlags & DSBCAPS_CTRLVOLUME) {
395 LONG val;
396 rc=IDirectSoundBuffer_GetVolume(dsbo,&val);
397 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n",
398 DXGetErrorString8(rc));
400 rc=IDirectSoundBuffer_SetVolume(dsbo,volume);
401 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume() failed: %s\n",
402 DXGetErrorString8(rc));
403 } else {
404 /* DSOUND: Error: Buffer does not have CTRLVOLUME */
405 rc=IDirectSoundBuffer_GetVolume(dsbo,&volume);
406 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetVolume() "
407 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
408 DXGetErrorString8(rc));
412 if (set_pan) {
413 if (dsbcaps.dwFlags & DSBCAPS_CTRLPAN) {
414 LONG val;
415 rc=IDirectSoundBuffer_GetPan(dsbo,&val);
416 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan() failed: %s\n",
417 DXGetErrorString8(rc));
419 rc=IDirectSoundBuffer_SetPan(dsbo,pan);
420 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan() failed: %s\n",
421 DXGetErrorString8(rc));
422 } else {
423 /* DSOUND: Error: Buffer does not have CTRLPAN */
424 rc=IDirectSoundBuffer_GetPan(dsbo,&pan);
425 ok(rc==DSERR_CONTROLUNAVAIL,"IDirectSoundBuffer_GetPan() "
426 "should have returned DSERR_CONTROLUNAVAIL, returned: %s\n",
427 DXGetErrorString8(rc));
431 state.wave=wave_generate_la(&wfx,duration,&state.wave_len);
433 state.dsbo=dsbo;
434 state.wfx=&wfx;
435 state.buffer_size=dsbcaps.dwBufferBytes;
436 state.played=state.written=state.offset=0;
437 buffer_refill8(&state,state.buffer_size);
439 rc=IDirectSoundBuffer_Play(dsbo,0,0,DSBPLAY_LOOPING);
440 ok(rc==DS_OK,"IDirectSoundBuffer_Play() failed: %s\n",
441 DXGetErrorString8(rc));
443 rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
444 ok(rc==DS_OK,"IDirectSoundBuffer_GetStatus() failed: %s\n",
445 DXGetErrorString8(rc));
446 ok(status==(DSBSTATUS_PLAYING|DSBSTATUS_LOOPING),
447 "GetStatus: bad status: %lx\n",status);
449 if (listener) {
450 ZeroMemory(&listener_param,sizeof(listener_param));
451 listener_param.dwSize=sizeof(listener_param);
452 rc=IDirectSound3DListener_GetAllParameters(listener,&listener_param);
453 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
454 "failed: %s\n",DXGetErrorString8(rc));
455 if (move_listener) {
456 listener_param.vPosition.x = -5.0;
457 listener_param.vVelocity.x = 10.0/duration;
459 rc=IDirectSound3DListener_SetAllParameters(listener,
460 &listener_param,
461 DS3D_IMMEDIATE);
462 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: %s\n",
463 DXGetErrorString8(rc));
465 if (buffer3d) {
466 if (move_sound) {
467 buffer_param.vPosition.x = 100.0;
468 buffer_param.vVelocity.x = -200.0/duration;
470 buffer_param.flMinDistance = 10;
471 rc=IDirectSound3DBuffer_SetAllParameters(buffer,&buffer_param,
472 DS3D_IMMEDIATE);
473 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
474 DXGetErrorString8(rc));
477 start_time=GetTickCount();
478 while (buffer_service8(&state)) {
479 WaitForSingleObject(GetCurrentProcess(),TIME_SLICE);
480 now=GetTickCount();
481 if (listener && move_listener) {
482 listener_param.vPosition.x = -5.0+10.0*(now-start_time)/
483 1000/duration;
484 if (winetest_debug>2)
485 trace("listener position=%g\n",listener_param.vPosition.x);
486 rc=IDirectSound3DListener_SetPosition(listener,
487 listener_param.vPosition.x,listener_param.vPosition.y,
488 listener_param.vPosition.z,DS3D_IMMEDIATE);
489 ok(rc==DS_OK,"IDirectSound3dListener_SetPosition() failed: "
490 "%s\n",DXGetErrorString8(rc));
492 if (buffer3d && move_sound) {
493 buffer_param.vPosition.x = 100-200.0*(now-start_time)/
494 1000/duration;
495 if (winetest_debug>2)
496 trace("sound position=%g\n",buffer_param.vPosition.x);
497 rc=IDirectSound3DBuffer_SetPosition(buffer,
498 buffer_param.vPosition.x,buffer_param.vPosition.y,
499 buffer_param.vPosition.z,DS3D_IMMEDIATE);
500 ok(rc==DS_OK,"IDirectSound3dBuffer_SetPosition() failed: %s\n",
501 DXGetErrorString8(rc));
504 /* Check the sound duration was within 10% of the expected value */
505 now=GetTickCount();
506 ok(fabs(1000*duration-now+start_time)<=100*duration,
507 "The sound played for %ld ms instead of %g ms\n",
508 now-start_time,1000*duration);
510 free(state.wave);
511 if (is_primary) {
512 /* Set the CooperativeLevel back to normal */
513 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
514 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
515 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) "
516 "failed: %s\n",DXGetErrorString8(rc));
518 if (buffer3d) {
519 ref=IDirectSound3DBuffer_Release(buffer);
520 ok(ref==0,"IDirectSound3DBuffer_Release() has %d references, "
521 "should have 0\n",ref);
526 static HRESULT test_secondary8(LPGUID lpGuid, int play,
527 int has_3d, int has_3dbuffer,
528 int has_listener, int has_duplicate,
529 int move_listener, int move_sound)
531 HRESULT rc;
532 LPDIRECTSOUND8 dso=NULL;
533 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
534 LPDIRECTSOUND3DLISTENER listener=NULL;
535 DSBUFFERDESC bufdesc;
536 WAVEFORMATEX wfx;
537 int ref;
539 /* Create the DirectSound object */
540 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
541 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n",
542 DXGetErrorString8(rc));
543 if (rc!=DS_OK)
544 return rc;
546 /* We must call SetCooperativeLevel before creating primary buffer */
547 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
548 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
549 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
550 "%s\n",DXGetErrorString8(rc));
551 if (rc!=DS_OK)
552 goto EXIT;
554 ZeroMemory(&bufdesc, sizeof(bufdesc));
555 bufdesc.dwSize=sizeof(bufdesc);
556 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
557 if (has_3d)
558 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
559 else
560 bufdesc.dwFlags|=(DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
561 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
562 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() "
563 "failed to create a %sprimary buffer: %s\n",has_3d?"3D ":"",
564 DXGetErrorString8(rc));
566 if (rc==DS_OK && primary!=NULL) {
567 if (has_listener) {
568 rc=IDirectSoundBuffer_QueryInterface(primary,
569 &IID_IDirectSound3DListener,
570 (void **)&listener);
571 ok(rc==DS_OK && listener!=NULL,
572 "IDirectSoundBuffer_QueryInterface() failed to get a 3D "
573 "listener %s\n",DXGetErrorString8(rc));
574 ref=IDirectSoundBuffer_Release(primary);
575 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
576 "should have 0\n",ref);
577 if (rc==DS_OK && listener!=NULL) {
578 DS3DLISTENER listener_param;
579 ZeroMemory(&listener_param,sizeof(listener_param));
580 /* DSOUND: Error: Invalid buffer */
581 rc=IDirectSound3DListener_GetAllParameters(listener,0);
582 ok(rc==DSERR_INVALIDPARAM,
583 "IDirectSound3dListener_GetAllParameters() should have "
584 "returned DSERR_INVALIDPARAM, returned: %s\n",
585 DXGetErrorString8(rc));
587 /* DSOUND: Error: Invalid buffer */
588 rc=IDirectSound3DListener_GetAllParameters(listener,
589 &listener_param);
590 ok(rc==DSERR_INVALIDPARAM,
591 "IDirectSound3dListener_GetAllParameters() should have "
592 "returned DSERR_INVALIDPARAM, returned: %s\n",
593 DXGetErrorString8(rc));
595 listener_param.dwSize=sizeof(listener_param);
596 rc=IDirectSound3DListener_GetAllParameters(listener,
597 &listener_param);
598 ok(rc==DS_OK,"IDirectSound3dListener_GetAllParameters() "
599 "failed: %s\n",DXGetErrorString8(rc));
601 else
602 goto EXIT;
605 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,2);
606 secondary=NULL;
607 ZeroMemory(&bufdesc, sizeof(bufdesc));
608 bufdesc.dwSize=sizeof(bufdesc);
609 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
610 if (has_3d)
611 bufdesc.dwFlags|=DSBCAPS_CTRL3D;
612 else
613 bufdesc.dwFlags|=
614 (DSBCAPS_CTRLFREQUENCY|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN);
615 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec*BUFFER_LEN/1000;
616 bufdesc.lpwfxFormat=&wfx;
617 if (has_3d) {
618 /* a stereo 3D buffer should fail */
619 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
620 ok(rc==DSERR_INVALIDPARAM,
621 "IDirectSound8_CreateSoundBuffer(secondary) should have "
622 "returned DSERR_INVALIDPARAM, returned %s\n",
623 DXGetErrorString8(rc));
624 if (secondary)
625 ref=IDirectSoundBuffer_Release(secondary);
626 init_format(&wfx,WAVE_FORMAT_PCM,22050,16,1);
629 if (winetest_interactive) {
630 trace(" Testing a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d\n",
631 has_3dbuffer?"3D ":"",
632 has_duplicate?"duplicated ":"",
633 listener!=NULL||move_sound?"with ":"",
634 move_listener?"moving ":"",
635 listener!=NULL?"listener ":"",
636 listener&&move_sound?"and moving sound ":move_sound?
637 "moving sound ":"",
638 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
640 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
641 ok(rc==DS_OK && secondary!=NULL,"IDirectSound8_CreateSoundBuffer() "
642 "failed to create a %s%ssecondary buffer %s%s%s%sat %ldx%dx%d (%s): %s\n",
643 has_3dbuffer?"3D ":"", has_duplicate?"duplicated ":"",
644 listener!=NULL||move_sound?"with ":"", move_listener?"moving ":"",
645 listener!=NULL?"listener ":"",
646 listener&&move_sound?"and moving sound ":move_sound?
647 "moving sound ":"",
648 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
649 getDSBCAPS(bufdesc.dwFlags),DXGetErrorString8(rc));
650 if (rc==DS_OK && secondary!=NULL) {
651 if (!has_3d) {
652 DWORD refpan,pan;
653 LONG refvol,vol;
655 /* Check the initial secondary buffer's volume and pan */
656 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
657 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(secondary) failed: "
658 "%s\n",DXGetErrorString8(rc));
659 ok(vol==0,"wrong volume for a new secondary buffer: %ld\n",vol);
660 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
661 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(secondary) failed: "
662 "%s\n",DXGetErrorString8(rc));
663 ok(pan==0,"wrong pan for a new secondary buffer: %ld\n",pan);
665 /* Check that changing the secondary buffer's volume and pan
666 * does not impact the primary buffer's volume and pan
668 rc=IDirectSoundBuffer_GetVolume(primary,&refvol);
669 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume(primary) failed: "
670 "%s\n",DXGetErrorString8(rc));
671 rc=IDirectSoundBuffer_GetPan(primary,&refpan);
672 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: "
673 "%s\n",DXGetErrorString8(rc));
675 rc=IDirectSoundBuffer_SetVolume(secondary,-1000);
676 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
677 "%s\n",DXGetErrorString8(rc));
678 rc=IDirectSoundBuffer_GetVolume(secondary,&vol);
679 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
680 "%s\n",DXGetErrorString8(rc));
681 ok(vol==-1000,"secondary: wrong volume %ld instead of -1000\n",
682 vol);
683 rc=IDirectSoundBuffer_SetPan(secondary,-1000);
684 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
685 "%s\n",DXGetErrorString8(rc));
686 rc=IDirectSoundBuffer_GetPan(secondary,&pan);
687 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
688 "%s\n",DXGetErrorString8(rc));
689 ok(pan==-1000,"secondary: wrong pan %ld instead of -1000\n",
690 pan);
692 rc=IDirectSoundBuffer_GetVolume(primary,&vol);
693 ok(rc==DS_OK,"IDirectSoundBuffer_`GetVolume(primary) failed: i"
694 "%s\n",DXGetErrorString8(rc));
695 ok(vol==refvol,"The primary volume changed from %ld to %ld\n",
696 refvol,vol);
697 rc=IDirectSoundBuffer_GetPan(primary,&pan);
698 ok(rc==DS_OK,"IDirectSoundBuffer_GetPan(primary) failed: "
699 "%s\n",DXGetErrorString8(rc));
700 ok(pan==refpan,"The primary pan changed from %ld to %ld\n",
701 refpan,pan);
703 rc=IDirectSoundBuffer_SetVolume(secondary,0);
704 ok(rc==DS_OK,"IDirectSoundBuffer_SetVolume(secondary) failed: "
705 "%s\n",DXGetErrorString8(rc));
706 rc=IDirectSoundBuffer_SetPan(secondary,0);
707 ok(rc==DS_OK,"IDirectSoundBuffer_SetPan(secondary) failed: "
708 "%s\n",DXGetErrorString8(rc));
710 if (has_duplicate) {
711 LPDIRECTSOUNDBUFFER duplicated=NULL;
713 /* DSOUND: Error: Invalid source buffer */
714 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,0);
715 ok(rc==DSERR_INVALIDPARAM,
716 "IDirectSound8_DuplicateSoundBuffer() should have returned "
717 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
719 /* DSOUND: Error: Invalid dest buffer */
720 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,0);
721 ok(rc==DSERR_INVALIDPARAM,
722 "IDirectSound8_DuplicateSoundBuffer() should have returned "
723 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
725 /* DSOUND: Error: Invalid source buffer */
726 rc=IDirectSound8_DuplicateSoundBuffer(dso,0,&duplicated);
727 ok(rc==DSERR_INVALIDPARAM,
728 "IDirectSound8_DuplicateSoundBuffer() should have returned "
729 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
731 duplicated=NULL;
732 rc=IDirectSound8_DuplicateSoundBuffer(dso,secondary,
733 &duplicated);
734 ok(rc==DS_OK && duplicated!=NULL,
735 "IDirectSound8_DuplicateSoundBuffer() failed to duplicate "
736 "a secondary buffer: %s\n",DXGetErrorString8(rc));
738 if (rc==DS_OK && duplicated!=NULL) {
739 ref=IDirectSoundBuffer_Release(secondary);
740 ok(ref==0,"IDirectSoundBuffer_Release() secondary has %d "
741 "references, should have 0\n",ref);
742 secondary=duplicated;
746 if (rc==DS_OK && secondary!=NULL) {
747 double duration;
748 duration=(move_listener || move_sound?4.0:1.0);
749 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0,
750 winetest_interactive,duration,has_3dbuffer,
751 listener,move_listener,move_sound);
752 ref=IDirectSoundBuffer_Release(secondary);
753 ok(ref==0,"IDirectSoundBuffer_Release() %s has %d references, "
754 "should have 0\n",has_duplicate?"duplicated":"secondary",
755 ref);
759 if (has_listener) {
760 ref=IDirectSound3DListener_Release(listener);
761 ok(ref==0,"IDirectSound3dListener_Release() listener has %d "
762 "references, should have 0\n",ref);
763 } else {
764 ref=IDirectSoundBuffer_Release(primary);
765 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
766 "should have 0\n",ref);
769 /* Set the CooperativeLevel back to normal */
770 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
771 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
772 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
773 "%s\n",DXGetErrorString8(rc));
775 EXIT:
776 ref=IDirectSound8_Release(dso);
777 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
778 if (ref!=0)
779 return DSERR_GENERIC;
781 return rc;
784 static HRESULT test_primary8(LPGUID lpGuid)
786 HRESULT rc;
787 LPDIRECTSOUND8 dso=NULL;
788 LPDIRECTSOUNDBUFFER primary=NULL;
789 DSBUFFERDESC bufdesc;
790 DSCAPS dscaps;
791 int ref, i;
793 /* Create the DirectSound object */
794 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
795 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n",
796 DXGetErrorString8(rc));
797 if (rc!=DS_OK)
798 return rc;
800 /* Get the device capabilities */
801 ZeroMemory(&dscaps, sizeof(dscaps));
802 dscaps.dwSize=sizeof(dscaps);
803 rc=IDirectSound8_GetCaps(dso,&dscaps);
804 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
805 if (rc!=DS_OK)
806 goto EXIT;
808 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
809 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
810 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
811 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
812 "%s\n",DXGetErrorString8(rc));
813 if (rc!=DS_OK)
814 goto EXIT;
816 /* Testing the primary buffer */
817 primary=NULL;
818 ZeroMemory(&bufdesc, sizeof(bufdesc));
819 bufdesc.dwSize=sizeof(bufdesc);
820 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME|DSBCAPS_CTRLPAN;
821 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
822 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
823 "to create a primary buffer: 0x%lx\n",rc);
824 if (rc==DS_OK && primary!=NULL) {
825 test_buffer8(dso,primary,1,TRUE,0,TRUE,0,winetest_interactive &&
826 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,NULL,0,0);
827 if (winetest_interactive) {
828 LONG volume,pan;
830 volume = DSBVOLUME_MAX;
831 for (i = 0; i < 6; i++) {
832 test_buffer8(dso,primary,1,TRUE,volume,TRUE,0,
833 winetest_interactive &&
834 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
835 1.0,0,NULL,0,0);
836 volume -= ((DSBVOLUME_MAX-DSBVOLUME_MIN) / 40);
839 pan = DSBPAN_LEFT;
840 for (i = 0; i < 7; i++) {
841 test_buffer8(dso,primary,1,TRUE,0,TRUE,pan,
842 winetest_interactive &&
843 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
844 pan += ((DSBPAN_RIGHT-DSBPAN_LEFT) / 6);
847 ref=IDirectSoundBuffer_Release(primary);
848 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
849 "should have 0\n",ref);
852 /* Set the CooperativeLevel back to normal */
853 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
854 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
855 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
856 "%s\n",DXGetErrorString8(rc));
858 EXIT:
859 ref=IDirectSound8_Release(dso);
860 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
861 if (ref!=0)
862 return DSERR_GENERIC;
864 return rc;
867 static HRESULT test_primary_3d8(LPGUID lpGuid)
869 HRESULT rc;
870 LPDIRECTSOUND8 dso=NULL;
871 LPDIRECTSOUNDBUFFER primary=NULL;
872 DSBUFFERDESC bufdesc;
873 DSCAPS dscaps;
874 int ref;
876 /* Create the DirectSound object */
877 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
878 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n",
879 DXGetErrorString8(rc));
880 if (rc!=DS_OK)
881 return rc;
883 /* Get the device capabilities */
884 ZeroMemory(&dscaps, sizeof(dscaps));
885 dscaps.dwSize=sizeof(dscaps);
886 rc=IDirectSound8_GetCaps(dso,&dscaps);
887 ok(rc==DS_OK,"IDirectSound8_GetCaps failed: %s\n",DXGetErrorString8(rc));
888 if (rc!=DS_OK)
889 goto EXIT;
891 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
892 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
893 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
894 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
895 "%s\n",DXGetErrorString8(rc));
896 if (rc!=DS_OK)
897 goto EXIT;
899 primary=NULL;
900 ZeroMemory(&bufdesc, sizeof(bufdesc));
901 bufdesc.dwSize=sizeof(bufdesc);
902 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
903 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
904 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
905 "to create a primary buffer: %s\n",DXGetErrorString8(rc));
906 if (rc==DS_OK && primary!=NULL) {
907 ref=IDirectSoundBuffer_Release(primary);
908 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
909 "should have 0\n",ref);
910 primary=NULL;
911 ZeroMemory(&bufdesc, sizeof(bufdesc));
912 bufdesc.dwSize=sizeof(bufdesc);
913 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
914 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
915 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() "
916 "failed to create a 3D primary buffer: %s\n",DXGetErrorString8(rc));
917 if (rc==DS_OK && primary!=NULL) {
918 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,
919 winetest_interactive &&
920 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),1.0,0,0,0,0);
921 ref=IDirectSoundBuffer_Release(primary);
922 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
923 "should have 0\n",ref);
926 /* Set the CooperativeLevel back to normal */
927 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
928 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
929 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_NORMAL) failed: "
930 "%s\n",DXGetErrorString8(rc));
932 EXIT:
933 ref=IDirectSound8_Release(dso);
934 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
935 if (ref!=0)
936 return DSERR_GENERIC;
938 return rc;
941 static HRESULT test_primary_3d_with_listener8(LPGUID lpGuid)
943 HRESULT rc;
944 LPDIRECTSOUND8 dso=NULL;
945 LPDIRECTSOUNDBUFFER primary=NULL;
946 DSBUFFERDESC bufdesc;
947 DSCAPS dscaps;
948 int ref;
950 /* Create the DirectSound object */
951 rc=pDirectSoundCreate8(lpGuid,&dso,NULL);
952 ok(rc==DS_OK||rc==DSERR_NODRIVER,"DirectSoundCreate8() failed: %s\n",
953 DXGetErrorString8(rc));
954 if (rc!=DS_OK)
955 return rc;
957 /* Get the device capabilities */
958 ZeroMemory(&dscaps, sizeof(dscaps));
959 dscaps.dwSize=sizeof(dscaps);
960 rc=IDirectSound8_GetCaps(dso,&dscaps);
961 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc));
962 if (rc!=DS_OK)
963 goto EXIT;
965 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */
966 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
967 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
968 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel(DSSCL_PRIORITY) failed: "
969 "%s\n",DXGetErrorString8(rc));
970 if (rc!=DS_OK)
971 goto EXIT;
972 primary=NULL;
973 ZeroMemory(&bufdesc, sizeof(bufdesc));
974 bufdesc.dwSize=sizeof(bufdesc);
975 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRL3D;
976 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
977 ok(rc==DS_OK && primary!=NULL,"IDirectSound8_CreateSoundBuffer() failed "
978 "to create a 3D primary buffer %s\n",DXGetErrorString8(rc));
979 if (rc==DS_OK && primary!=NULL) {
980 LPDIRECTSOUND3DLISTENER listener=NULL;
981 rc=IDirectSoundBuffer_QueryInterface(primary,
982 &IID_IDirectSound3DListener,
983 (void **)&listener);
984 ok(rc==DS_OK && listener!=NULL,"IDirectSoundBuffer_QueryInterface() "
985 "failed to get a 3D listener: %s\n",DXGetErrorString8(rc));
986 if (rc==DS_OK && listener!=NULL) {
987 LPDIRECTSOUNDBUFFER temp_buffer=NULL;
989 /* Checking the COM interface */
990 rc=IDirectSoundBuffer_QueryInterface(primary,
991 &IID_IDirectSoundBuffer,
992 (LPVOID *)&temp_buffer);
993 ok(rc==DS_OK && temp_buffer!=NULL,
994 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
995 DXGetErrorString8(rc));
996 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != "
997 "0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
998 if (rc==DS_OK && temp_buffer!=NULL) {
999 ref=IDirectSoundBuffer_Release(temp_buffer);
1000 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1001 "should have 1\n",ref);
1003 temp_buffer=NULL;
1004 rc=IDirectSound3DListener_QueryInterface(listener,
1005 &IID_IDirectSoundBuffer,(LPVOID *)&temp_buffer);
1006 ok(rc==DS_OK && temp_buffer!=NULL,
1007 "IDirectSoundBuffer_QueryInterface() failed: %s\n",
1008 DXGetErrorString8(rc));
1009 ok(temp_buffer==primary,"COM interface broken: 0x%08lx != "
1010 "0x%08lx\n",(DWORD)temp_buffer,(DWORD)primary);
1011 ref=IDirectSoundBuffer_Release(temp_buffer);
1012 ok(ref==1,"IDirectSoundBuffer_Release() has %d references, "
1013 "should have 1\n",ref);
1015 /* Testing the buffer */
1016 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,
1017 winetest_interactive &&
1018 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),
1019 1.0,0,listener,0,0);
1022 /* Testing the reference counting */
1023 ref=IDirectSound3DListener_Release(listener);
1024 ok(ref==0,"IDirectSound3DListener_Release() listener has %d "
1025 "references, should have 0\n",ref);
1028 /* Testing the reference counting */
1029 ref=IDirectSoundBuffer_Release(primary);
1030 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, "
1031 "should have 0\n",ref);
1034 EXIT:
1035 ref=IDirectSound8_Release(dso);
1036 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref);
1037 if (ref!=0)
1038 return DSERR_GENERIC;
1040 return rc;
1043 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
1044 LPCSTR lpcstrModule, LPVOID lpContext)
1046 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
1048 trace(" Testing the primary buffer\n");
1049 test_primary8(lpGuid);
1051 trace(" Testing 3D primary buffer\n");
1052 test_primary_3d8(lpGuid);
1054 trace(" Testing 3D primary buffer with listener\n");
1055 test_primary_3d_with_listener8(lpGuid);
1057 /* Testing secondary buffers */
1058 test_secondary8(lpGuid,winetest_interactive,0,0,0,0,0,0);
1059 test_secondary8(lpGuid,winetest_interactive,0,0,0,1,0,0);
1061 /* Testing 3D secondary buffers */
1062 test_secondary8(lpGuid,winetest_interactive,1,0,0,0,0,0);
1063 test_secondary8(lpGuid,winetest_interactive,1,1,0,0,0,0);
1064 test_secondary8(lpGuid,winetest_interactive,1,1,0,1,0,0);
1065 test_secondary8(lpGuid,winetest_interactive,1,0,1,0,0,0);
1066 test_secondary8(lpGuid,winetest_interactive,1,0,1,1,0,0);
1067 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,0);
1068 test_secondary8(lpGuid,winetest_interactive,1,1,1,1,0,0);
1069 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,0);
1070 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,0,1);
1071 test_secondary8(lpGuid,winetest_interactive,1,1,1,0,1,1);
1073 return 1;
1076 static void ds3d8_tests()
1078 HRESULT rc;
1079 rc=DirectSoundEnumerateA(&dsenum_callback,NULL);
1080 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc));
1083 START_TEST(ds3d8)
1085 HMODULE hDsound;
1087 CoInitialize(NULL);
1089 hDsound = LoadLibraryA("dsound.dll");
1090 if (!hDsound) {
1091 trace("dsound.dll not found\n");
1092 return;
1095 pDirectSoundCreate8 = (void*)GetProcAddress(hDsound, "DirectSoundCreate8");
1096 if (!pDirectSoundCreate8) {
1097 trace("ds3d8 test skipped\n");
1098 return;
1101 ds3d8_tests();