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
25 #include "wine/test.h"
30 #include "dsound_test.h"
32 #define NOTIFICATIONS 5
34 static HRESULT (WINAPI *pDirectSoundCaptureCreate)(LPCGUID,LPDIRECTSOUNDCAPTURE*,LPUNKNOWN)=NULL;
35 static HRESULT (WINAPI *pDirectSoundCaptureEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
37 static const char * get_format_str(WORD format)
40 #define WAVE_FORMAT(f) case f: return #f
42 WAVE_FORMAT(WAVE_FORMAT_PCM);
43 WAVE_FORMAT(WAVE_FORMAT_ADPCM);
44 WAVE_FORMAT(WAVE_FORMAT_IBM_CVSD);
45 WAVE_FORMAT(WAVE_FORMAT_ALAW);
46 WAVE_FORMAT(WAVE_FORMAT_MULAW);
47 WAVE_FORMAT(WAVE_FORMAT_OKI_ADPCM);
48 WAVE_FORMAT(WAVE_FORMAT_IMA_ADPCM);
49 WAVE_FORMAT(WAVE_FORMAT_MEDIASPACE_ADPCM);
50 WAVE_FORMAT(WAVE_FORMAT_SIERRA_ADPCM);
51 WAVE_FORMAT(WAVE_FORMAT_G723_ADPCM);
52 WAVE_FORMAT(WAVE_FORMAT_DIGISTD);
53 WAVE_FORMAT(WAVE_FORMAT_DIGIFIX);
54 WAVE_FORMAT(WAVE_FORMAT_DIALOGIC_OKI_ADPCM);
55 WAVE_FORMAT(WAVE_FORMAT_YAMAHA_ADPCM);
56 WAVE_FORMAT(WAVE_FORMAT_SONARC);
57 WAVE_FORMAT(WAVE_FORMAT_DSPGROUP_TRUESPEECH);
58 WAVE_FORMAT(WAVE_FORMAT_ECHOSC1);
59 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF36);
60 WAVE_FORMAT(WAVE_FORMAT_APTX);
61 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF10);
62 WAVE_FORMAT(WAVE_FORMAT_DOLBY_AC2);
63 WAVE_FORMAT(WAVE_FORMAT_GSM610);
64 WAVE_FORMAT(WAVE_FORMAT_ANTEX_ADPCME);
65 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_VQLPC);
66 WAVE_FORMAT(WAVE_FORMAT_DIGIREAL);
67 WAVE_FORMAT(WAVE_FORMAT_DIGIADPCM);
68 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_CR10);
69 WAVE_FORMAT(WAVE_FORMAT_NMS_VBXADPCM);
70 WAVE_FORMAT(WAVE_FORMAT_G721_ADPCM);
71 WAVE_FORMAT(WAVE_FORMAT_MPEG);
72 WAVE_FORMAT(WAVE_FORMAT_MPEGLAYER3);
73 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_ADPCM);
74 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH8);
75 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH10);
76 WAVE_FORMAT(WAVE_FORMAT_FM_TOWNS_SND);
77 WAVE_FORMAT(WAVE_FORMAT_OLIGSM);
78 WAVE_FORMAT(WAVE_FORMAT_OLIADPCM);
79 WAVE_FORMAT(WAVE_FORMAT_OLICELP);
80 WAVE_FORMAT(WAVE_FORMAT_OLISBC);
81 WAVE_FORMAT(WAVE_FORMAT_OLIOPR);
82 WAVE_FORMAT(WAVE_FORMAT_DEVELOPMENT);
83 WAVE_FORMAT(WAVE_FORMAT_EXTENSIBLE);
86 sprintf(msg, "Unknown(0x%04x)", format);
90 const char * format_string(const WAVEFORMATEX* wfx)
94 sprintf(str, "%5dx%2dx%d %s",
95 wfx->nSamplesPerSec, wfx->wBitsPerSample, wfx->nChannels,
96 get_format_str(wfx->wFormatTag));
101 static void IDirectSoundCapture_test(LPDIRECTSOUNDCAPTURE dsco,
102 BOOL initialized, LPCGUID lpGuid)
108 IDirectSoundCapture * dsc;
110 /* Try to Query for objects */
111 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IUnknown,
113 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IUnknown) "
114 "failed: %08x\n", rc);
116 IDirectSoundCapture_Release(unknown);
118 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IDirectSoundCapture,
120 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IDirectSoundCapture) "
121 "failed: %08x\n", rc);
123 IDirectSoundCapture_Release(dsc);
125 if (initialized == FALSE) {
126 /* try uninitialized object */
127 rc=IDirectSoundCapture_GetCaps(dsco,0);
128 ok(rc==DSERR_UNINITIALIZED||rc==E_INVALIDARG,
129 "IDirectSoundCapture_GetCaps(NULL) should have returned "
130 "DSERR_UNINITIALIZED or E_INVALIDARG, returned: %08x\n", rc);
132 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps);
133 ok(rc==DSERR_UNINITIALIZED,"IDirectSoundCapture_GetCaps() "
134 "should have returned DSERR_UNINITIALIZED, returned: %08x\n", rc);
136 rc=IDirectSoundCapture_Initialize(dsco, lpGuid);
137 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||
138 rc==E_FAIL||rc==E_INVALIDARG,
139 "IDirectSoundCapture_Initialize() failed: %08x\n", rc);
140 if (rc==DSERR_NODRIVER||rc==E_INVALIDARG) {
141 trace(" No Driver\n");
143 } else if (rc==E_FAIL) {
144 trace(" No Device\n");
146 } else if (rc==DSERR_ALLOCATED) {
147 trace(" Already In Use\n");
152 rc=IDirectSoundCapture_Initialize(dsco, lpGuid);
153 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSoundCapture_Initialize() "
154 "should have returned DSERR_ALREADYINITIALIZED: %08x\n", rc);
156 /* DSOUND: Error: Invalid caps buffer */
157 rc=IDirectSoundCapture_GetCaps(dsco, 0);
158 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundCapture_GetCaps(NULL) "
159 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
161 ZeroMemory(&dsccaps, sizeof(dsccaps));
163 /* DSOUND: Error: Invalid caps buffer */
164 rc=IDirectSound_GetCaps(dsco, &dsccaps);
165 ok(rc==DSERR_INVALIDPARAM, "IDirectSound_GetCaps() "
166 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
168 dsccaps.dwSize=sizeof(dsccaps);
170 /* DSOUND: Running on a certified driver */
171 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps);
172 ok(rc==DS_OK, "IDirectSoundCapture_GetCaps() failed: %08x\n", rc);
175 ref=IDirectSoundCapture_Release(dsco);
176 ok(ref==0, "IDirectSoundCapture_Release() has %d references, "
177 "should have 0\n", ref);
180 static void IDirectSoundCapture_tests(void)
183 LPDIRECTSOUNDCAPTURE dsco=NULL;
184 LPCLASSFACTORY cf=NULL;
186 trace("Testing IDirectSoundCapture\n");
188 rc=CoGetClassObject(&CLSID_DirectSoundCapture, CLSCTX_INPROC_SERVER, NULL,
189 &IID_IClassFactory, (void**)&cf);
190 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) "
191 "failed: %08x\n", rc);
193 rc=CoGetClassObject(&CLSID_DirectSoundCapture, CLSCTX_INPROC_SERVER, NULL,
194 &IID_IUnknown, (void**)&cf);
195 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSoundCapture, IID_IUnknown) "
196 "failed: %08x\n", rc);
198 /* try the COM class factory method of creation with no device specified */
199 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
200 &IID_IDirectSoundCapture, (void**)&dsco);
201 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %08x\n", rc);
202 if (rc==REGDB_E_CLASSNOTREG) {
203 trace(" Class Not Registered\n");
207 IDirectSoundCapture_test(dsco, FALSE, NULL);
209 /* try the COM class factory method of creation with default capture
210 * device specified */
211 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
212 &IID_IDirectSoundCapture, (void**)&dsco);
213 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %08x\n", rc);
215 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultCapture);
217 /* try the COM class factory method of creation with default voice
218 * capture device specified */
219 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
220 &IID_IDirectSoundCapture, (void**)&dsco);
221 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %08x\n", rc);
223 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultVoiceCapture);
225 /* try the COM class factory method of creation with a bad
227 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
228 &CLSID_DirectSoundPrivate, (void**)&dsco);
229 ok(rc==E_NOINTERFACE,
230 "CoCreateInstance(CLSID_DirectSoundCapture,CLSID_DirectSoundPrivate) "
231 "should have failed: %08x\n",rc);
233 /* try with no device specified */
234 rc=pDirectSoundCaptureCreate(NULL,&dsco,NULL);
235 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
236 "DirectSoundCaptureCreate(NULL) failed: %08x\n",rc);
237 if (rc==S_OK && dsco)
238 IDirectSoundCapture_test(dsco, TRUE, NULL);
240 /* try with default capture device specified */
241 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultCapture,&dsco,NULL);
242 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
243 "DirectSoundCaptureCreate(DSDEVID_DefaultCapture) failed: %08x\n", rc);
244 if (rc==DS_OK && dsco)
245 IDirectSoundCapture_test(dsco, TRUE, NULL);
247 /* try with default voice capture device specified */
248 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoiceCapture,&dsco,NULL);
249 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
250 "DirectSoundCaptureCreate(DSDEVID_DefaultVoiceCapture) failed: %08x\n", rc);
251 if (rc==DS_OK && dsco)
252 IDirectSoundCapture_test(dsco, TRUE, NULL);
254 /* try with a bad device specified */
255 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoicePlayback,&dsco,NULL);
256 ok(rc==DSERR_NODRIVER,
257 "DirectSoundCaptureCreate(DSDEVID_DefaultVoicePlatback) "
258 "should have failed: %08x\n",rc);
259 if (rc==DS_OK && dsco)
260 IDirectSoundCapture_Release(dsco);
267 LPDIRECTSOUNDCAPTUREBUFFER dscbo;
269 DSBPOSITIONNOTIFY posnotify[NOTIFICATIONS];
270 HANDLE event[NOTIFICATIONS];
271 LPDIRECTSOUNDNOTIFY notify;
281 static int capture_buffer_service(capture_state_t* state)
286 DWORD capture_pos,read_pos;
288 rc=IDirectSoundCaptureBuffer_GetCurrentPosition(state->dscbo,&capture_pos,
290 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCurrentPosition() failed: %08x\n", rc);
294 rc=IDirectSoundCaptureBuffer_Lock(state->dscbo,state->offset,state->size,
295 &ptr1,&len1,&ptr2,&len2,0);
296 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Lock() failed: %08x\n", rc);
300 rc=IDirectSoundCaptureBuffer_Unlock(state->dscbo,ptr1,len1,ptr2,len2);
301 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Unlock() failed: %08x\n", rc);
305 state->offset = (state->offset + state->size) % state->buffer_size;
310 static void test_capture_buffer(LPDIRECTSOUNDCAPTURE dsco,
311 LPDIRECTSOUNDCAPTUREBUFFER dscbo, int record)
317 capture_state_t state;
320 /* Private dsound.dll: Error: Invalid caps pointer */
321 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,0);
322 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should "
323 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
325 /* Private dsound.dll: Error: Invalid caps pointer */
327 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps);
328 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should "
329 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
331 dscbcaps.dwSize=sizeof(dscbcaps);
332 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps);
333 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCaps() failed: %08x\n", rc);
334 if (rc==DS_OK && winetest_debug > 1) {
335 trace(" Caps: size = %d flags=0x%08x buffer size=%d\n",
336 dscbcaps.dwSize,dscbcaps.dwFlags,dscbcaps.dwBufferBytes);
339 /* Query the format size. Note that it may not match sizeof(wfx) */
340 /* Private dsound.dll: Error: Either pwfxFormat or pdwSizeWritten must
342 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,NULL);
343 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetFormat() should "
344 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
347 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,&size);
348 ok(rc==DS_OK && size!=0,"IDirectSoundCaptureBuffer_GetFormat() should "
349 "have returned the needed size: rc=%08x, size=%d\n", rc,size);
351 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,&wfx,sizeof(wfx),NULL);
352 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetFormat() failed: %08x\n", rc);
353 if (rc==DS_OK && winetest_debug > 1) {
354 trace(" Format: tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
355 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
356 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
359 /* Private dsound.dll: Error: Invalid status pointer */
360 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,0);
361 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetStatus() should "
362 "have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
364 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status);
365 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %08x\n", rc);
366 if (rc==DS_OK && winetest_debug > 1) {
367 trace(" Status=0x%04x\n",status);
370 ZeroMemory(&state, sizeof(state));
373 state.buffer_size = dscbcaps.dwBufferBytes;
374 for (i = 0; i < NOTIFICATIONS; i++)
375 state.event[i] = CreateEvent( NULL, FALSE, FALSE, NULL );
376 state.size = dscbcaps.dwBufferBytes / NOTIFICATIONS;
378 rc=IDirectSoundCaptureBuffer_QueryInterface(dscbo,&IID_IDirectSoundNotify,
379 (void **)&(state.notify));
380 ok((rc==DS_OK)&&(state.notify!=NULL),
381 "IDirectSoundCaptureBuffer_QueryInterface() failed: %08x\n", rc);
385 for (i = 0; i < NOTIFICATIONS; i++) {
386 state.posnotify[i].dwOffset = (i * state.size) + state.size - 1;
387 state.posnotify[i].hEventNotify = state.event[i];
390 rc=IDirectSoundNotify_SetNotificationPositions(state.notify,NOTIFICATIONS,
392 ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions() failed: %08x\n", rc);
396 ref=IDirectSoundNotify_Release(state.notify);
397 ok(ref==0,"IDirectSoundNotify_Release(): has %d references, should have "
403 rc=IDirectSoundCaptureBuffer_Start(dscbo,DSCBSTART_LOOPING);
404 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Start() failed: %08x\n", rc);
408 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status);
409 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %08x\n", rc);
410 ok(status==(DSCBSTATUS_CAPTURING|DSCBSTATUS_LOOPING),
411 "GetStatus: bad status: %x\n",status);
415 /* wait for the notifications */
416 for (i = 0; i < (NOTIFICATIONS * 2); i++) {
417 rc=WaitForMultipleObjects(NOTIFICATIONS,state.event,FALSE,3000);
418 ok(rc==(WAIT_OBJECT_0+(i%NOTIFICATIONS)),
419 "WaitForMultipleObjects failed: 0x%x\n",rc);
420 if (rc!=(WAIT_OBJECT_0+(i%NOTIFICATIONS))) {
421 ok((rc==WAIT_TIMEOUT)||(rc==WAIT_FAILED),
422 "Wrong notification: should be %d, got %d\n",
423 i%NOTIFICATIONS,rc-WAIT_OBJECT_0);
425 if (!capture_buffer_service(&state))
429 rc=IDirectSoundCaptureBuffer_Stop(dscbo);
430 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Stop() failed: %08x\n", rc);
436 static BOOL WINAPI dscenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
437 LPCSTR lpcstrModule, LPVOID lpContext)
440 LPDIRECTSOUNDCAPTURE dsco=NULL;
441 LPDIRECTSOUNDCAPTUREBUFFER dscbo=NULL;
442 DSCBUFFERDESC bufdesc;
448 /* Private dsound.dll: Error: Invalid interface buffer */
449 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
450 rc=pDirectSoundCaptureCreate(lpGuid,NULL,NULL);
451 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCaptureCreate() should have "
452 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
454 rc=pDirectSoundCaptureCreate(lpGuid,&dsco,NULL);
455 ok((rc==DS_OK)||(rc==DSERR_NODRIVER)||(rc==E_FAIL)||(rc==DSERR_ALLOCATED),
456 "DirectSoundCaptureCreate() failed: %08x\n",rc);
458 if (rc==DSERR_NODRIVER)
459 trace(" No Driver\n");
461 trace(" No Device\n");
462 else if (rc==DSERR_ALLOCATED)
463 trace(" Already In Use\n");
467 /* Private dsound.dll: Error: Invalid caps buffer */
468 rc=IDirectSoundCapture_GetCaps(dsco,NULL);
469 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have "
470 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
472 /* Private dsound.dll: Error: Invalid caps buffer */
474 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps);
475 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have "
476 "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
478 dsccaps.dwSize=sizeof(dsccaps);
479 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps);
480 ok(rc==DS_OK,"IDirectSoundCapture_GetCaps() failed: %08x\n", rc);
481 if (rc==DS_OK && winetest_debug > 1) {
482 trace(" Caps: size=%d flags=0x%08x formats=%05x channels=%d\n",
483 dsccaps.dwSize,dsccaps.dwFlags,dsccaps.dwFormats,
487 /* Private dsound.dll: Error: Invalid size */
488 /* Private dsound.dll: Error: Invalid capture buffer description */
489 ZeroMemory(&bufdesc, sizeof(bufdesc));
492 bufdesc.dwBufferBytes=0;
493 bufdesc.dwReserved=0;
494 bufdesc.lpwfxFormat=NULL;
495 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
496 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
497 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
499 ref=IDirectSoundCaptureBuffer_Release(dscbo);
500 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
501 "should have 0\n",ref);
504 /* Private dsound.dll: Error: Invalid buffer size */
505 /* Private dsound.dll: Error: Invalid capture buffer description */
506 ZeroMemory(&bufdesc, sizeof(bufdesc));
507 bufdesc.dwSize=sizeof(bufdesc);
509 bufdesc.dwBufferBytes=0;
510 bufdesc.dwReserved=0;
511 bufdesc.lpwfxFormat=NULL;
512 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
513 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
514 "should have returned DSERR_INVALIDPARAM, returned %08x\n", rc);
516 ref=IDirectSoundCaptureBuffer_Release(dscbo);
517 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
518 "should have 0\n",ref);
521 /* Private dsound.dll: Error: Invalid buffer size */
522 /* Private dsound.dll: Error: Invalid capture buffer description */
523 ZeroMemory(&bufdesc, sizeof(bufdesc));
524 ZeroMemory(&wfx, sizeof(wfx));
525 bufdesc.dwSize=sizeof(bufdesc);
527 bufdesc.dwBufferBytes=0;
528 bufdesc.dwReserved=0;
529 bufdesc.lpwfxFormat=&wfx;
530 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
531 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
532 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
534 ref=IDirectSoundCaptureBuffer_Release(dscbo);
535 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
536 "should have 0\n",ref);
539 /* Private dsound.dll: Error: Invalid buffer size */
540 /* Private dsound.dll: Error: Invalid capture buffer description */
541 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
542 ZeroMemory(&bufdesc, sizeof(bufdesc));
543 bufdesc.dwSize=sizeof(bufdesc);
545 bufdesc.dwBufferBytes=0;
546 bufdesc.dwReserved=0;
547 bufdesc.lpwfxFormat=&wfx;
548 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
549 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
550 "should have returned DSERR_INVALIDPARAM, returned: %08x\n", rc);
552 ref=IDirectSoundCaptureBuffer_Release(dscbo);
553 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
554 "should have 0\n",ref);
557 for (f=0;f<NB_FORMATS;f++) {
559 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
561 ZeroMemory(&bufdesc, sizeof(bufdesc));
562 bufdesc.dwSize=sizeof(bufdesc);
564 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
565 bufdesc.dwReserved=0;
566 bufdesc.lpwfxFormat=&wfx;
567 if (winetest_interactive)
568 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
569 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
570 ok(((rc==DS_OK)&&(dscbo!=NULL))
571 || rc==DSERR_BADFORMAT || rc==DSERR_INVALIDCALL || rc==DSERR_NODRIVER
572 || rc==DSERR_ALLOCATED || rc==E_INVALIDARG || rc==E_FAIL,
573 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
574 "%s capture buffer: %08x\n",format_string(&wfx),rc);
576 test_capture_buffer(dsco, dscbo, winetest_interactive);
577 ref=IDirectSoundCaptureBuffer_Release(dscbo);
578 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
579 "should have 0\n",ref);
580 } else if (rc==DSERR_BADFORMAT) {
581 ok(!(dsccaps.dwFormats & formats[f][3]),
582 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
583 "capture buffer: format listed as supported but using it failed\n");
584 if (!(dsccaps.dwFormats & formats[f][3]))
585 trace(" Format not supported: %s\n", format_string(&wfx));
586 } else if (rc==DSERR_NODRIVER) {
587 trace(" No Driver\n");
588 } else if (rc==DSERR_ALLOCATED) {
589 trace(" Already In Use\n");
590 } else if (rc==E_INVALIDARG) { /* try the old version struct */
591 DSCBUFFERDESC1 bufdesc1;
592 ZeroMemory(&bufdesc1, sizeof(bufdesc1));
593 bufdesc1.dwSize=sizeof(bufdesc1);
595 bufdesc1.dwBufferBytes=wfx.nAvgBytesPerSec;
596 bufdesc1.dwReserved=0;
597 bufdesc1.lpwfxFormat=&wfx;
598 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,
599 (DSCBUFFERDESC*)&bufdesc1,&dscbo,NULL);
600 ok(rc==DS_OK || broken(rc==DSERR_INVALIDPARAM),
601 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
602 "%s capture buffer: %08x\n",format_string(&wfx), rc);
603 if (rc==DSERR_INVALIDPARAM) {
604 skip("broken driver\n");
608 test_capture_buffer(dsco, dscbo, winetest_interactive);
609 ref=IDirectSoundCaptureBuffer_Release(dscbo);
610 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d "
611 "references, should have 0\n",ref);
613 } else if (rc==E_FAIL) {
614 /* WAVE_FORMAT_PCM only allows 8 and 16 bits per sample, so only
615 * report a failure if the bits per sample is 8 or 16
617 if (wfx.wBitsPerSample == 8 || wfx.wBitsPerSample == 16)
618 ok(FALSE,"Should not fail for 8 or 16 bits per sample\n");
622 /* try a non PCM format */
625 /* FIXME: Why is this commented out? */
626 init_format(&wfx,WAVE_FORMAT_MULAW,8000,8,1);
627 ZeroMemory(&bufdesc, sizeof(bufdesc));
628 bufdesc.dwSize=sizeof(bufdesc);
629 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED;
630 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
631 bufdesc.dwReserved=0;
632 bufdesc.lpwfxFormat=&wfx;
633 if (winetest_interactive)
634 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
635 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
636 ok((rc==DS_OK)&&(dscbo!=NULL),"IDirectSoundCapture_CreateCaptureBuffer() "
637 "failed to create a capture buffer: %08x\n",rc);
638 if ((rc==DS_OK)&&(dscbo!=NULL)) {
639 test_capture_buffer(dsco, dscbo, winetest_interactive);
640 ref=IDirectSoundCaptureBuffer_Release(dscbo);
641 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
642 "should have 0\n",ref);
646 /* Try an invalid format to test error handling */
649 /* FIXME: Remove this test altogether? */
650 init_format(&wfx,WAVE_FORMAT_PCM,2000000,16,2);
651 ZeroMemory(&bufdesc, sizeof(bufdesc));
652 bufdesc.dwSize=sizeof(bufdesc);
653 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED;
654 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
655 bufdesc.dwReserved=0;
656 bufdesc.lpwfxFormat=&wfx;
657 if (winetest_interactive)
658 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
659 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
660 ok(rc!=DS_OK,"IDirectSoundCapture_CreateCaptureBuffer() should have failed "
661 "at 2 MHz %08x\n",rc);
666 ref=IDirectSoundCapture_Release(dsco);
667 ok(ref==0,"IDirectSoundCapture_Release() has %d references, should "
674 static void capture_tests(void)
677 rc=pDirectSoundCaptureEnumerateA(&dscenum_callback,NULL);
678 ok(rc==DS_OK,"DirectSoundCaptureEnumerateA() failed: %08x\n", rc);
687 hDsound = LoadLibrary("dsound.dll");
690 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
692 pDirectSoundCaptureCreate=(void*)GetProcAddress(hDsound,
693 "DirectSoundCaptureCreate");
694 pDirectSoundCaptureEnumerateA=(void*)GetProcAddress(hDsound,
695 "DirectSoundCaptureEnumerateA");
696 if (pDirectSoundCaptureCreate && pDirectSoundCaptureEnumerateA)
698 IDirectSoundCapture_tests();
702 skip("capture test skipped\n");
704 FreeLibrary(hDsound);
707 skip("dsound.dll not found!\n");