2 * Unit tests for capture functions
4 * Copyright (c) 2002 Francois Gouget
5 * Copyright (c) 2003 Robert Reif
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "wine/test.h"
31 #include "dsound_test.h"
33 #define NOTIFICATIONS 5
35 static HRESULT (WINAPI *pDirectSoundCaptureCreate)(LPCGUID,LPDIRECTSOUNDCAPTURE*,LPUNKNOWN)=NULL;
36 static HRESULT (WINAPI *pDirectSoundCaptureEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
38 static const char * get_format_str(WORD format)
41 #define WAVE_FORMAT(f) case f: return #f
43 WAVE_FORMAT(WAVE_FORMAT_PCM);
44 WAVE_FORMAT(WAVE_FORMAT_ADPCM);
45 WAVE_FORMAT(WAVE_FORMAT_IBM_CVSD);
46 WAVE_FORMAT(WAVE_FORMAT_ALAW);
47 WAVE_FORMAT(WAVE_FORMAT_MULAW);
48 WAVE_FORMAT(WAVE_FORMAT_OKI_ADPCM);
49 WAVE_FORMAT(WAVE_FORMAT_IMA_ADPCM);
50 WAVE_FORMAT(WAVE_FORMAT_MEDIASPACE_ADPCM);
51 WAVE_FORMAT(WAVE_FORMAT_SIERRA_ADPCM);
52 WAVE_FORMAT(WAVE_FORMAT_G723_ADPCM);
53 WAVE_FORMAT(WAVE_FORMAT_DIGISTD);
54 WAVE_FORMAT(WAVE_FORMAT_DIGIFIX);
55 WAVE_FORMAT(WAVE_FORMAT_DIALOGIC_OKI_ADPCM);
56 WAVE_FORMAT(WAVE_FORMAT_YAMAHA_ADPCM);
57 WAVE_FORMAT(WAVE_FORMAT_SONARC);
58 WAVE_FORMAT(WAVE_FORMAT_DSPGROUP_TRUESPEECH);
59 WAVE_FORMAT(WAVE_FORMAT_ECHOSC1);
60 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF36);
61 WAVE_FORMAT(WAVE_FORMAT_APTX);
62 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF10);
63 WAVE_FORMAT(WAVE_FORMAT_DOLBY_AC2);
64 WAVE_FORMAT(WAVE_FORMAT_GSM610);
65 WAVE_FORMAT(WAVE_FORMAT_ANTEX_ADPCME);
66 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_VQLPC);
67 WAVE_FORMAT(WAVE_FORMAT_DIGIREAL);
68 WAVE_FORMAT(WAVE_FORMAT_DIGIADPCM);
69 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_CR10);
70 WAVE_FORMAT(WAVE_FORMAT_NMS_VBXADPCM);
71 WAVE_FORMAT(WAVE_FORMAT_G721_ADPCM);
72 WAVE_FORMAT(WAVE_FORMAT_MPEG);
73 WAVE_FORMAT(WAVE_FORMAT_MPEGLAYER3);
74 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_ADPCM);
75 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH8);
76 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH10);
77 WAVE_FORMAT(WAVE_FORMAT_FM_TOWNS_SND);
78 WAVE_FORMAT(WAVE_FORMAT_OLIGSM);
79 WAVE_FORMAT(WAVE_FORMAT_OLIADPCM);
80 WAVE_FORMAT(WAVE_FORMAT_OLICELP);
81 WAVE_FORMAT(WAVE_FORMAT_OLISBC);
82 WAVE_FORMAT(WAVE_FORMAT_OLIOPR);
83 WAVE_FORMAT(WAVE_FORMAT_DEVELOPMENT);
84 WAVE_FORMAT(WAVE_FORMAT_EXTENSIBLE);
87 sprintf(msg, "Unknown(0x%04x)", format);
91 const char * format_string(const WAVEFORMATEX* wfx)
95 sprintf(str, "%5dx%2dx%d %s",
96 wfx->nSamplesPerSec, wfx->wBitsPerSample, wfx->nChannels,
97 get_format_str(wfx->wFormatTag));
102 static void IDirectSoundCapture_test(LPDIRECTSOUNDCAPTURE dsco,
103 BOOL initialized, LPCGUID lpGuid)
109 IDirectSoundCapture * dsc;
111 /* Try to Query for objects */
112 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IUnknown,
114 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IUnknown) "
115 "failed: %08x\n", rc);
117 IDirectSoundCapture_Release(unknown);
119 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IDirectSoundCapture,
121 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IDirectSoundCapture) "
122 "failed: %08x\n", rc);
124 IDirectSoundCapture_Release(dsc);
126 if (initialized == FALSE) {
127 /* try uninitialized object */
128 rc=IDirectSoundCapture_GetCaps(dsco,0);
129 ok(rc==DSERR_UNINITIALIZED||rc==E_INVALIDARG,
130 "IDirectSoundCapture_GetCaps(NULL) should have returned "
131 "DSERR_UNINITIALIZED or E_INVALIDARG, returned: %08x\n", rc);
133 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps);
134 ok(rc==DSERR_UNINITIALIZED,"IDirectSoundCapture_GetCaps() "
135 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
137 rc=IDirectSoundCapture_Initialize(dsco, lpGuid);
138 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||
139 rc==E_FAIL||rc==E_INVALIDARG,
140 "IDirectSoundCapture_Initialize() failed: %08x\n", rc);
141 if (rc==DSERR_NODRIVER||rc==E_INVALIDARG) {
142 trace(" No Driver\n");
144 } else if (rc==E_FAIL) {
145 trace(" No Device\n");
147 } else if (rc==DSERR_ALLOCATED) {
148 trace(" Already In Use\n");
153 rc=IDirectSoundCapture_Initialize(dsco, lpGuid);
154 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSoundCapture_Initialize() "
155 "should have returned DSERR_ALREADYINITIALIZED: %08x\n", rc);
157 /* DSOUND: Error: Invalid caps buffer */
158 rc=IDirectSoundCapture_GetCaps(dsco, 0);
159 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundCapture_GetCaps(NULL) "
160 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
162 ZeroMemory(&dsccaps, sizeof(dsccaps));
164 /* DSOUND: Error: Invalid caps buffer */
165 rc=IDirectSound_GetCaps(dsco, &dsccaps);
166 ok(rc==DSERR_INVALIDPARAM, "IDirectSound_GetCaps() "
167 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
169 dsccaps.dwSize=sizeof(dsccaps);
171 /* DSOUND: Running on a certified driver */
172 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps);
173 ok(rc==DS_OK, "IDirectSoundCapture_GetCaps() failed: %08x\n", rc);
176 ref=IDirectSoundCapture_Release(dsco);
177 ok(ref==0, "IDirectSoundCapture_Release() has %d references, "
178 "should have 0\n", ref);
181 static void test_capture(void)
184 LPDIRECTSOUNDCAPTURE dsco=NULL;
185 LPCLASSFACTORY cf=NULL;
187 trace("Testing IDirectSoundCapture\n");
189 rc=CoGetClassObject(&CLSID_DirectSoundCapture, CLSCTX_INPROC_SERVER, NULL,
190 &IID_IClassFactory, (void**)&cf);
191 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) "
192 "failed: %08x\n", rc);
194 rc=CoGetClassObject(&CLSID_DirectSoundCapture, CLSCTX_INPROC_SERVER, NULL,
195 &IID_IUnknown, (void**)&cf);
196 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSoundCapture, IID_IUnknown) "
197 "failed: %08x\n", rc);
199 /* try the COM class factory method of creation with no device specified */
200 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
201 &IID_IDirectSoundCapture, (void**)&dsco);
202 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %08x\n", rc);
203 if (rc==REGDB_E_CLASSNOTREG) {
204 trace(" Class Not Registered\n");
208 IDirectSoundCapture_test(dsco, FALSE, NULL);
210 /* try the COM class factory method of creation with default capture
211 * device specified */
212 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
213 &IID_IDirectSoundCapture, (void**)&dsco);
214 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %08x\n", rc);
216 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultCapture);
218 /* try the COM class factory method of creation with default voice
219 * capture device specified */
220 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
221 &IID_IDirectSoundCapture, (void**)&dsco);
222 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %08x\n", rc);
224 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultVoiceCapture);
226 /* try the COM class factory method of creation with a bad
228 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
229 &CLSID_DirectSoundPrivate, (void**)&dsco);
230 ok(rc==E_NOINTERFACE,
231 "CoCreateInstance(CLSID_DirectSoundCapture,CLSID_DirectSoundPrivate) "
232 "should have failed: %08x\n",rc);
234 /* try with no device specified */
235 rc=pDirectSoundCaptureCreate(NULL,&dsco,NULL);
236 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
237 "DirectSoundCaptureCreate(NULL) failed: %08x\n",rc);
238 if (rc==S_OK && dsco)
239 IDirectSoundCapture_test(dsco, TRUE, NULL);
241 /* try with default capture device specified */
242 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultCapture,&dsco,NULL);
243 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
244 "DirectSoundCaptureCreate(DSDEVID_DefaultCapture) failed: %08x\n", rc);
245 if (rc==DS_OK && dsco)
246 IDirectSoundCapture_test(dsco, TRUE, NULL);
248 /* try with default voice capture device specified */
249 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoiceCapture,&dsco,NULL);
250 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
251 "DirectSoundCaptureCreate(DSDEVID_DefaultVoiceCapture) failed: %08x\n", rc);
252 if (rc==DS_OK && dsco)
253 IDirectSoundCapture_test(dsco, TRUE, NULL);
255 /* try with a bad device specified */
256 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoicePlayback,&dsco,NULL);
257 ok(rc==DSERR_NODRIVER,
258 "DirectSoundCaptureCreate(DSDEVID_DefaultVoicePlatback) "
259 "should have failed: %08x\n",rc);
260 if (rc==DS_OK && dsco)
261 IDirectSoundCapture_Release(dsco);
268 LPDIRECTSOUNDCAPTUREBUFFER dscbo;
270 DSBPOSITIONNOTIFY posnotify[NOTIFICATIONS];
271 HANDLE event[NOTIFICATIONS];
272 LPDIRECTSOUNDNOTIFY notify;
282 static int capture_buffer_service(capture_state_t* state)
287 DWORD capture_pos,read_pos;
289 rc=IDirectSoundCaptureBuffer_GetCurrentPosition(state->dscbo,&capture_pos,
291 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCurrentPosition() failed: %08x\n", rc);
295 rc=IDirectSoundCaptureBuffer_Lock(state->dscbo,state->offset,state->size,
296 &ptr1,&len1,&ptr2,&len2,0);
297 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Lock() failed: %08x\n", rc);
301 rc=IDirectSoundCaptureBuffer_Unlock(state->dscbo,ptr1,len1,ptr2,len2);
302 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Unlock() failed: %08x\n", rc);
306 state->offset = (state->offset + state->size) % state->buffer_size;
311 static void test_capture_buffer(LPDIRECTSOUNDCAPTURE dsco,
312 LPDIRECTSOUNDCAPTUREBUFFER dscbo, int record)
318 capture_state_t state;
321 /* Private dsound.dll: Error: Invalid caps pointer */
322 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,0);
323 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should "
324 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
326 /* Private dsound.dll: Error: Invalid caps pointer */
328 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps);
329 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should "
330 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
332 dscbcaps.dwSize=sizeof(dscbcaps);
333 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps);
334 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCaps() failed: %08x\n", rc);
335 if (rc==DS_OK && winetest_debug > 1) {
336 trace(" Caps: size = %d flags=0x%08x buffer size=%d\n",
337 dscbcaps.dwSize,dscbcaps.dwFlags,dscbcaps.dwBufferBytes);
340 /* Query the format size. Note that it may not match sizeof(wfx) */
341 /* Private dsound.dll: Error: Either pwfxFormat or pdwSizeWritten must
343 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,NULL);
344 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetFormat() should "
345 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
348 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,&size);
349 ok(rc==DS_OK && size!=0,"IDirectSoundCaptureBuffer_GetFormat() should "
350 "have returned the needed size: rc=%08x, size=%d\n", rc,size);
352 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,&wfx,sizeof(wfx),NULL);
353 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetFormat() failed: %08x\n", rc);
354 if (rc==DS_OK && winetest_debug > 1) {
355 trace(" Format: tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
356 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
357 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
360 /* Private dsound.dll: Error: Invalid status pointer */
361 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,0);
362 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetStatus() should "
363 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
365 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status);
366 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %08x\n", rc);
367 if (rc==DS_OK && winetest_debug > 1) {
368 trace(" Status=0x%04x\n",status);
371 ZeroMemory(&state, sizeof(state));
374 state.buffer_size = dscbcaps.dwBufferBytes;
375 for (i = 0; i < NOTIFICATIONS; i++)
376 state.event[i] = CreateEvent( NULL, FALSE, FALSE, NULL );
377 state.size = dscbcaps.dwBufferBytes / NOTIFICATIONS;
379 rc=IDirectSoundCaptureBuffer_QueryInterface(dscbo,&IID_IDirectSoundNotify,
380 (void **)&(state.notify));
381 ok((rc==DS_OK)&&(state.notify!=NULL),
382 "IDirectSoundCaptureBuffer_QueryInterface() failed: %08x\n", rc);
384 for (i = 0; i < NOTIFICATIONS; i++) {
385 state.posnotify[i].dwOffset = (i * state.size) + state.size - 1;
386 state.posnotify[i].hEventNotify = state.event[i];
389 rc=IDirectSoundNotify_SetNotificationPositions(state.notify,NOTIFICATIONS,
391 ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions() failed: %08x\n", rc);
393 ref=IDirectSoundNotify_Release(state.notify);
394 ok(ref==0,"IDirectSoundNotify_Release(): has %d references, should have "
398 rc=IDirectSoundCaptureBuffer_Start(dscbo,DSCBSTART_LOOPING);
399 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Start() failed: %08x\n", rc);
401 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status);
402 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %08x\n", rc);
403 ok(status==(DSCBSTATUS_CAPTURING|DSCBSTATUS_LOOPING),
404 "GetStatus: bad status: %x\n",status);
406 /* wait for the notifications */
407 for (i = 0; i < (NOTIFICATIONS * 2); i++) {
408 rc=WaitForMultipleObjects(NOTIFICATIONS,state.event,FALSE,3000);
409 ok(rc==(WAIT_OBJECT_0+(i%NOTIFICATIONS)),
410 "WaitForMultipleObjects failed: 0x%x\n",rc);
411 if (rc!=(WAIT_OBJECT_0+(i%NOTIFICATIONS))) {
412 ok((rc==WAIT_TIMEOUT)||(rc==WAIT_FAILED),
413 "Wrong notification: should be %d, got %d\n",
414 i%NOTIFICATIONS,rc-WAIT_OBJECT_0);
416 if (!capture_buffer_service(&state))
420 rc=IDirectSoundCaptureBuffer_Stop(dscbo);
421 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Stop() failed: %08x\n", rc);
425 static BOOL WINAPI dscenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
426 LPCSTR lpcstrModule, LPVOID lpContext)
429 LPDIRECTSOUNDCAPTURE dsco=NULL;
430 LPDIRECTSOUNDCAPTUREBUFFER dscbo=NULL;
431 DSCBUFFERDESC bufdesc;
437 /* Private dsound.dll: Error: Invalid interface buffer */
438 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
439 rc=pDirectSoundCaptureCreate(lpGuid,NULL,NULL);
440 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCaptureCreate() should have "
441 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
443 rc=pDirectSoundCaptureCreate(lpGuid,&dsco,NULL);
444 ok((rc==DS_OK)||(rc==DSERR_NODRIVER)||(rc==E_FAIL)||(rc==DSERR_ALLOCATED),
445 "DirectSoundCaptureCreate() failed: %08x\n",rc);
447 if (rc==DSERR_NODRIVER)
448 trace(" No Driver\n");
450 trace(" No Device\n");
451 else if (rc==DSERR_ALLOCATED)
452 trace(" Already In Use\n");
456 /* Private dsound.dll: Error: Invalid caps buffer */
457 rc=IDirectSoundCapture_GetCaps(dsco,NULL);
458 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have "
459 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
461 /* Private dsound.dll: Error: Invalid caps buffer */
463 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps);
464 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have "
465 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
467 dsccaps.dwSize=sizeof(dsccaps);
468 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps);
469 ok(rc==DS_OK,"IDirectSoundCapture_GetCaps() failed: %08x\n", rc);
470 if (rc==DS_OK && winetest_debug > 1) {
471 trace(" Caps: size=%d flags=0x%08x formats=%05x channels=%d\n",
472 dsccaps.dwSize,dsccaps.dwFlags,dsccaps.dwFormats,
476 /* Private dsound.dll: Error: Invalid size */
477 /* Private dsound.dll: Error: Invalid capture buffer description */
478 ZeroMemory(&bufdesc, sizeof(bufdesc));
481 bufdesc.dwBufferBytes=0;
482 bufdesc.dwReserved=0;
483 bufdesc.lpwfxFormat=NULL;
484 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
485 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
486 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
488 ref=IDirectSoundCaptureBuffer_Release(dscbo);
489 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
490 "should have 0\n",ref);
493 /* Private dsound.dll: Error: Invalid buffer size */
494 /* Private dsound.dll: Error: Invalid capture buffer description */
495 ZeroMemory(&bufdesc, sizeof(bufdesc));
496 bufdesc.dwSize=sizeof(bufdesc);
498 bufdesc.dwBufferBytes=0;
499 bufdesc.dwReserved=0;
500 bufdesc.lpwfxFormat=NULL;
501 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
502 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
503 "should have returned DSERR_INVALIDPARAM, returned %08x\n", rc);
505 ref=IDirectSoundCaptureBuffer_Release(dscbo);
506 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
507 "should have 0\n",ref);
510 /* Private dsound.dll: Error: Invalid buffer size */
511 /* Private dsound.dll: Error: Invalid capture buffer description */
512 ZeroMemory(&bufdesc, sizeof(bufdesc));
513 ZeroMemory(&wfx, sizeof(wfx));
514 bufdesc.dwSize=sizeof(bufdesc);
516 bufdesc.dwBufferBytes=0;
517 bufdesc.dwReserved=0;
518 bufdesc.lpwfxFormat=&wfx;
519 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
520 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
521 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
523 ref=IDirectSoundCaptureBuffer_Release(dscbo);
524 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
525 "should have 0\n",ref);
528 /* Private dsound.dll: Error: Invalid buffer size */
529 /* Private dsound.dll: Error: Invalid capture buffer description */
530 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
531 ZeroMemory(&bufdesc, sizeof(bufdesc));
532 bufdesc.dwSize=sizeof(bufdesc);
534 bufdesc.dwBufferBytes=0;
535 bufdesc.dwReserved=0;
536 bufdesc.lpwfxFormat=&wfx;
537 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
538 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
539 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
541 ref=IDirectSoundCaptureBuffer_Release(dscbo);
542 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
543 "should have 0\n",ref);
546 for (f=0;f<NB_FORMATS;f++) {
548 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
550 ZeroMemory(&bufdesc, sizeof(bufdesc));
551 bufdesc.dwSize=sizeof(bufdesc);
553 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
554 bufdesc.dwReserved=0;
555 bufdesc.lpwfxFormat=&wfx;
556 if (winetest_interactive)
557 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
558 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
559 ok(((rc==DS_OK)&&(dscbo!=NULL))
560 || rc==DSERR_BADFORMAT || rc==DSERR_INVALIDCALL || rc==DSERR_NODRIVER
561 || rc==DSERR_ALLOCATED || rc==E_INVALIDARG || rc==E_FAIL,
562 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
563 "%s capture buffer: %08x\n",format_string(&wfx),rc);
565 test_capture_buffer(dsco, dscbo, winetest_interactive);
566 ref=IDirectSoundCaptureBuffer_Release(dscbo);
567 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
568 "should have 0\n",ref);
569 } else if (rc==DSERR_BADFORMAT) {
570 ok(!(dsccaps.dwFormats & formats[f][3]),
571 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
572 "capture buffer: format listed as supported but using it failed\n");
573 if (!(dsccaps.dwFormats & formats[f][3]))
574 trace(" Format not supported: %s\n", format_string(&wfx));
575 } else if (rc==DSERR_NODRIVER) {
576 trace(" No Driver\n");
577 } else if (rc==DSERR_ALLOCATED) {
578 trace(" Already In Use\n");
579 } else if (rc==E_INVALIDARG) { /* try the old version struct */
580 DSCBUFFERDESC1 bufdesc1;
581 ZeroMemory(&bufdesc1, sizeof(bufdesc1));
582 bufdesc1.dwSize=sizeof(bufdesc1);
584 bufdesc1.dwBufferBytes=wfx.nAvgBytesPerSec;
585 bufdesc1.dwReserved=0;
586 bufdesc1.lpwfxFormat=&wfx;
587 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,
588 (DSCBUFFERDESC*)&bufdesc1,&dscbo,NULL);
589 ok(rc==DS_OK || broken(rc==DSERR_INVALIDPARAM),
590 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
591 "%s capture buffer: %08x\n",format_string(&wfx), rc);
592 if (rc==DSERR_INVALIDPARAM) {
593 skip("broken driver\n");
597 test_capture_buffer(dsco, dscbo, winetest_interactive);
598 ref=IDirectSoundCaptureBuffer_Release(dscbo);
599 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d "
600 "references, should have 0\n",ref);
602 } else if (rc==E_FAIL) {
603 /* WAVE_FORMAT_PCM only allows 8 and 16 bits per sample, so only
604 * report a failure if the bits per sample is 8 or 16
606 if (wfx.wBitsPerSample == 8 || wfx.wBitsPerSample == 16)
607 ok(FALSE,"Should not fail for 8 or 16 bits per sample\n");
611 /* try a non PCM format */
614 /* FIXME: Why is this commented out? */
615 init_format(&wfx,WAVE_FORMAT_MULAW,8000,8,1);
616 ZeroMemory(&bufdesc, sizeof(bufdesc));
617 bufdesc.dwSize=sizeof(bufdesc);
618 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED;
619 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
620 bufdesc.dwReserved=0;
621 bufdesc.lpwfxFormat=&wfx;
622 if (winetest_interactive)
623 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
624 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
625 ok((rc==DS_OK)&&(dscbo!=NULL),"IDirectSoundCapture_CreateCaptureBuffer() "
626 "failed to create a capture buffer: %08x\n",rc);
627 if ((rc==DS_OK)&&(dscbo!=NULL)) {
628 test_capture_buffer(dsco, dscbo, winetest_interactive);
629 ref=IDirectSoundCaptureBuffer_Release(dscbo);
630 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
631 "should have 0\n",ref);
635 /* Try an invalid format to test error handling */
638 /* FIXME: Remove this test altogether? */
639 init_format(&wfx,WAVE_FORMAT_PCM,2000000,16,2);
640 ZeroMemory(&bufdesc, sizeof(bufdesc));
641 bufdesc.dwSize=sizeof(bufdesc);
642 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED;
643 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
644 bufdesc.dwReserved=0;
645 bufdesc.lpwfxFormat=&wfx;
646 if (winetest_interactive)
647 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
648 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
649 ok(rc!=DS_OK,"IDirectSoundCapture_CreateCaptureBuffer() should have failed "
650 "at 2 MHz %08x\n",rc);
655 ref=IDirectSoundCapture_Release(dsco);
656 ok(ref==0,"IDirectSoundCapture_Release() has %d references, should "
663 static void test_enumerate(void)
666 rc=pDirectSoundCaptureEnumerateA(&dscenum_callback,NULL);
667 ok(rc==DS_OK,"DirectSoundCaptureEnumerateA() failed: %08x\n", rc);
670 static void test_COM(void)
672 IDirectSoundCapture *dsc = (IDirectSoundCapture*)0xdeadbeef;
673 IDirectSoundCaptureBuffer *buffer = (IDirectSoundCaptureBuffer*)0xdeadbeef;
674 IDirectSoundNotify *notify;
676 DSCBUFFERDESC bufdesc;
681 hr = pDirectSoundCaptureCreate(NULL, &dsc, (IUnknown*)0xdeadbeef);
682 ok(hr == DSERR_NOAGGREGATION,
683 "DirectSoundCaptureCreate failed: %08x, expected DSERR_NOAGGREGATION\n", hr);
684 ok(dsc == (IDirectSoundCapture*)0xdeadbeef, "dsc = %p\n", dsc);
686 hr = pDirectSoundCaptureCreate(NULL, &dsc, NULL);
687 if (hr == DSERR_NODRIVER) {
691 ok(hr == DS_OK, "DirectSoundCaptureCreate failed: %08x, expected DS_OK\n", hr);
693 /* Different refcount for IDirectSoundCapture and for IUnknown */
694 refcount = IDirectSoundCapture_AddRef(dsc);
695 ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
696 hr = IDirectSoundCapture_QueryInterface(dsc, &IID_IUnknown, (void**)&unk);
697 ok(hr == S_OK, "QueryInterface for IID_IUnknown failed: %08x\n", hr);
698 refcount = IUnknown_AddRef(unk);
699 ok(refcount == 2, "refcount == %u, expected 2\n", refcount);
700 IUnknown_Release(unk);
701 IUnknown_Release(unk);
702 IDirectSoundCapture_Release(dsc);
704 init_format(&wfx, WAVE_FORMAT_PCM, 44100, 16, 1);
705 ZeroMemory(&bufdesc, sizeof(bufdesc));
706 bufdesc.dwSize = sizeof(bufdesc);
707 bufdesc.dwBufferBytes = wfx.nAvgBytesPerSec;
708 bufdesc.lpwfxFormat = &wfx;
710 hr = IDirectSoundCapture_CreateCaptureBuffer(dsc, &bufdesc, &buffer, (IUnknown*)0xdeadbeef);
711 if (hr == E_INVALIDARG) {
712 /* Old DirectX has only the 1st version of the DSCBUFFERDESC struct */
713 bufdesc.dwSize = sizeof(DSCBUFFERDESC1);
714 hr = IDirectSoundCapture_CreateCaptureBuffer(dsc, &bufdesc, &buffer, (IUnknown*)0xdeadbeef);
716 ok(hr == DSERR_NOAGGREGATION,
717 "IDirectSoundCapture_CreateCaptureBuffer failed: %08x, expected DSERR_NOAGGREGATION\n", hr);
718 ok(buffer == (IDirectSoundCaptureBuffer*)0xdeadbeef || !buffer /* Win2k without DirectX9 */,
719 "buffer = %p\n", buffer);
721 hr = IDirectSoundCapture_CreateCaptureBuffer(dsc, &bufdesc, &buffer, NULL);
722 ok(hr == DS_OK, "IDirectSoundCapture_CreateCaptureBuffer failed: %08x, expected DS_OK\n", hr);
724 /* IDirectSoundCaptureBuffer and IDirectSoundNotify have separate refcounts */
725 IDirectSoundCaptureBuffer_AddRef(buffer);
726 refcount = IDirectSoundCaptureBuffer_AddRef(buffer);
727 ok(refcount == 3, "IDirectSoundCaptureBuffer refcount is %u, expected 3\n", refcount);
728 hr = IDirectSoundCaptureBuffer_QueryInterface(buffer, &IID_IDirectSoundNotify, (void**)¬ify);
729 ok(hr == DS_OK, "IDirectSoundCapture_QueryInterface failed: %08x, expected DS_OK\n", hr);
730 refcount = IDirectSoundNotify_AddRef(notify);
731 ok(refcount == 2, "IDirectSoundNotify refcount is %u, expected 2\n", refcount);
732 IDirectSoundCaptureBuffer_AddRef(buffer);
733 refcount = IDirectSoundCaptureBuffer_Release(buffer);
734 ok(refcount == 3, "IDirectSoundCaptureBuffer refcount is %u, expected 3\n", refcount);
736 /* Release IDirectSoundCaptureBuffer while keeping IDirectSoundNotify alive */
737 while (IDirectSoundCaptureBuffer_Release(buffer) > 0);
738 refcount = IDirectSoundNotify_AddRef(notify);
739 ok(refcount == 3, "IDirectSoundNotify refcount is %u, expected 3\n", refcount);
740 refcount = IDirectSoundCaptureBuffer_AddRef(buffer);
741 ok(refcount == 1, "IDirectSoundCaptureBuffer refcount is %u, expected 1\n", refcount);
743 while (IDirectSoundNotify_Release(notify) > 0);
744 refcount = IDirectSoundCaptureBuffer_Release(buffer);
745 ok(refcount == 0, "IDirectSoundCaptureBuffer refcount is %u, expected 0\n", refcount);
746 refcount = IDirectSoundCapture_Release(dsc);
747 ok(refcount == 0, "IDirectSoundCapture refcount is %u, expected 0\n", refcount);
756 hDsound = LoadLibrary("dsound.dll");
758 skip("dsound.dll not found - skipping all tests\n");
762 pDirectSoundCaptureCreate = (void*)GetProcAddress(hDsound, "DirectSoundCaptureCreate");
763 pDirectSoundCaptureEnumerateA = (void*)GetProcAddress(hDsound, "DirectSoundCaptureEnumerateA");
764 if (!pDirectSoundCaptureCreate || !pDirectSoundCaptureEnumerateA) {
765 skip("DirectSoundCapture{Create,Enumerate} missing - skipping all tests\n");
773 FreeLibrary(hDsound);