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"
32 #include "dsound_test.h"
34 #define NOTIFICATIONS 5
36 static HRESULT (WINAPI *pDirectSoundCaptureCreate)(LPCGUID,LPDIRECTSOUNDCAPTURE*,LPUNKNOWN)=NULL;
37 static HRESULT (WINAPI *pDirectSoundCaptureEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL;
39 static const char * get_format_str(WORD format)
42 #define WAVE_FORMAT(f) case f: return #f
44 WAVE_FORMAT(WAVE_FORMAT_PCM);
45 WAVE_FORMAT(WAVE_FORMAT_ADPCM);
46 WAVE_FORMAT(WAVE_FORMAT_IBM_CVSD);
47 WAVE_FORMAT(WAVE_FORMAT_ALAW);
48 WAVE_FORMAT(WAVE_FORMAT_MULAW);
49 WAVE_FORMAT(WAVE_FORMAT_OKI_ADPCM);
50 WAVE_FORMAT(WAVE_FORMAT_IMA_ADPCM);
51 WAVE_FORMAT(WAVE_FORMAT_MEDIASPACE_ADPCM);
52 WAVE_FORMAT(WAVE_FORMAT_SIERRA_ADPCM);
53 WAVE_FORMAT(WAVE_FORMAT_G723_ADPCM);
54 WAVE_FORMAT(WAVE_FORMAT_DIGISTD);
55 WAVE_FORMAT(WAVE_FORMAT_DIGIFIX);
56 WAVE_FORMAT(WAVE_FORMAT_DIALOGIC_OKI_ADPCM);
57 WAVE_FORMAT(WAVE_FORMAT_YAMAHA_ADPCM);
58 WAVE_FORMAT(WAVE_FORMAT_SONARC);
59 WAVE_FORMAT(WAVE_FORMAT_DSPGROUP_TRUESPEECH);
60 WAVE_FORMAT(WAVE_FORMAT_ECHOSC1);
61 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF36);
62 WAVE_FORMAT(WAVE_FORMAT_APTX);
63 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF10);
64 WAVE_FORMAT(WAVE_FORMAT_DOLBY_AC2);
65 WAVE_FORMAT(WAVE_FORMAT_GSM610);
66 WAVE_FORMAT(WAVE_FORMAT_ANTEX_ADPCME);
67 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_VQLPC);
68 WAVE_FORMAT(WAVE_FORMAT_DIGIREAL);
69 WAVE_FORMAT(WAVE_FORMAT_DIGIADPCM);
70 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_CR10);
71 WAVE_FORMAT(WAVE_FORMAT_NMS_VBXADPCM);
72 WAVE_FORMAT(WAVE_FORMAT_G721_ADPCM);
73 WAVE_FORMAT(WAVE_FORMAT_MPEG);
74 WAVE_FORMAT(WAVE_FORMAT_MPEGLAYER3);
75 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_ADPCM);
76 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH8);
77 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH10);
78 WAVE_FORMAT(WAVE_FORMAT_FM_TOWNS_SND);
79 WAVE_FORMAT(WAVE_FORMAT_OLIGSM);
80 WAVE_FORMAT(WAVE_FORMAT_OLIADPCM);
81 WAVE_FORMAT(WAVE_FORMAT_OLICELP);
82 WAVE_FORMAT(WAVE_FORMAT_OLISBC);
83 WAVE_FORMAT(WAVE_FORMAT_OLIOPR);
84 WAVE_FORMAT(WAVE_FORMAT_DEVELOPMENT);
85 WAVE_FORMAT(WAVE_FORMAT_EXTENSIBLE);
88 sprintf(msg, "Unknown(0x%04x)", format);
92 const char * format_string(const WAVEFORMATEX* wfx)
96 sprintf(str, "%5dx%2dx%d %s",
97 wfx->nSamplesPerSec, wfx->wBitsPerSample, wfx->nChannels,
98 get_format_str(wfx->wFormatTag));
103 static void IDirectSoundCapture_test(LPDIRECTSOUNDCAPTURE dsco,
104 BOOL initialized, LPCGUID lpGuid)
110 IDirectSoundCapture * dsc;
112 /* Try to Query for objects */
113 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IUnknown,
115 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IUnknown) "
116 "failed: %s\n", DXGetErrorString8(rc));
118 IDirectSoundCapture_Release(unknown);
120 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IDirectSoundCapture,
122 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IDirectSoundCapture) "
123 "failed: %s\n", DXGetErrorString8(rc));
125 IDirectSoundCapture_Release(dsc);
127 if (initialized == FALSE) {
128 /* try uninitialized object */
129 rc=IDirectSoundCapture_GetCaps(dsco,0);
130 ok(rc==DSERR_UNINITIALIZED||rc==E_INVALIDARG,
131 "IDirectSoundCapture_GetCaps(NULL) should have returned "
132 "DSERR_UNINITIALIZED or E_INVALIDARG, returned: %s\n",
133 DXGetErrorString8(rc));
135 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps);
136 ok(rc==DSERR_UNINITIALIZED,"IDirectSoundCapture_GetCaps() "
137 "should have returned DSERR_UNINITIALIZED, returned: %s\n",
138 DXGetErrorString8(rc));
140 rc=IDirectSoundCapture_Initialize(dsco, lpGuid);
141 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||
142 rc==E_FAIL||rc==E_INVALIDARG,
143 "IDirectSoundCapture_Initialize() failed: %s\n",
144 DXGetErrorString8(rc));
145 if (rc==DSERR_NODRIVER||rc==E_INVALIDARG) {
146 trace(" No Driver\n");
148 } else if (rc==E_FAIL) {
149 trace(" No Device\n");
151 } else if (rc==DSERR_ALLOCATED) {
152 trace(" Already In Use\n");
157 rc=IDirectSoundCapture_Initialize(dsco, lpGuid);
158 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSoundCapture_Initialize() "
159 "should have returned DSERR_ALREADYINITIALIZED: %s\n",
160 DXGetErrorString8(rc));
162 /* DSOUND: Error: Invalid caps buffer */
163 rc=IDirectSoundCapture_GetCaps(dsco, 0);
164 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundCapture_GetCaps(NULL) "
165 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
166 DXGetErrorString8(rc));
168 ZeroMemory(&dsccaps, sizeof(dsccaps));
170 /* DSOUND: Error: Invalid caps buffer */
171 rc=IDirectSound_GetCaps(dsco, &dsccaps);
172 ok(rc==DSERR_INVALIDPARAM, "IDirectSound_GetCaps() "
173 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
174 DXGetErrorString8(rc));
176 dsccaps.dwSize=sizeof(dsccaps);
178 /* DSOUND: Running on a certified driver */
179 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps);
180 ok(rc==DS_OK, "IDirectSoundCapture_GetCaps() failed: %s\n",
181 DXGetErrorString8(rc));
184 ref=IDirectSoundCapture_Release(dsco);
185 ok(ref==0, "IDirectSoundCapture_Release() has %d references, "
186 "should have 0\n", ref);
189 static void IDirectSoundCapture_tests(void)
192 LPDIRECTSOUNDCAPTURE dsco=NULL;
193 LPCLASSFACTORY cf=NULL;
195 trace("Testing IDirectSoundCapture\n");
197 rc=CoGetClassObject(&CLSID_DirectSoundCapture, CLSCTX_INPROC_SERVER, NULL,
198 &IID_IClassFactory, (void**)&cf);
199 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSoundCapture, IID_IClassFactory) "
200 "failed: %s\n", DXGetErrorString8(rc));
202 rc=CoGetClassObject(&CLSID_DirectSoundCapture, CLSCTX_INPROC_SERVER, NULL,
203 &IID_IUnknown, (void**)&cf);
204 ok(rc==S_OK,"CoGetClassObject(CLSID_DirectSoundCapture, IID_IUnknown) "
205 "failed: %s\n", DXGetErrorString8(rc));
207 /* try the COM class factory method of creation with no device specified */
208 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
209 &IID_IDirectSoundCapture, (void**)&dsco);
210 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %s\n",
211 DXGetErrorString8(rc));
212 if (rc==REGDB_E_CLASSNOTREG) {
213 trace(" Class Not Registered\n");
217 IDirectSoundCapture_test(dsco, FALSE, NULL);
219 /* try the COM class factory method of creation with default capture
220 * device specified */
221 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
222 &IID_IDirectSoundCapture, (void**)&dsco);
223 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %s\n",
224 DXGetErrorString8(rc));
226 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultCapture);
228 /* try the COM class factory method of creation with default voice
229 * capture device specified */
230 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
231 &IID_IDirectSoundCapture, (void**)&dsco);
232 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %s\n",
233 DXGetErrorString8(rc));
235 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultVoiceCapture);
237 /* try the COM class factory method of creation with a bad
239 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER,
240 &CLSID_DirectSoundPrivate, (void**)&dsco);
241 ok(rc==E_NOINTERFACE,
242 "CoCreateInstance(CLSID_DirectSoundCapture,CLSID_DirectSoundPrivate) "
243 "should have failed: %s\n",DXGetErrorString8(rc));
245 /* try with no device specified */
246 rc=pDirectSoundCaptureCreate(NULL,&dsco,NULL);
247 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
248 "DirectSoundCaptureCreate(NULL) failed: %s\n",DXGetErrorString8(rc));
249 if (rc==S_OK && dsco)
250 IDirectSoundCapture_test(dsco, TRUE, NULL);
252 /* try with default capture device specified */
253 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultCapture,&dsco,NULL);
254 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
255 "DirectSoundCaptureCreate(DSDEVID_DefaultCapture) failed: %s\n",
256 DXGetErrorString8(rc));
257 if (rc==DS_OK && dsco)
258 IDirectSoundCapture_test(dsco, TRUE, NULL);
260 /* try with default voice capture device specified */
261 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoiceCapture,&dsco,NULL);
262 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL,
263 "DirectSoundCaptureCreate(DSDEVID_DefaultVoiceCapture) failed: %s\n",
264 DXGetErrorString8(rc));
265 if (rc==DS_OK && dsco)
266 IDirectSoundCapture_test(dsco, TRUE, NULL);
268 /* try with a bad device specified */
269 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoicePlayback,&dsco,NULL);
270 ok(rc==DSERR_NODRIVER,
271 "DirectSoundCaptureCreate(DSDEVID_DefaultVoicePlatback) "
272 "should have failed: %s\n",DXGetErrorString8(rc));
273 if (rc==DS_OK && dsco)
274 IDirectSoundCapture_Release(dsco);
281 LPDIRECTSOUNDCAPTUREBUFFER dscbo;
283 DSBPOSITIONNOTIFY posnotify[NOTIFICATIONS];
284 HANDLE event[NOTIFICATIONS];
285 LPDIRECTSOUNDNOTIFY notify;
295 static int capture_buffer_service(capture_state_t* state)
300 DWORD capture_pos,read_pos;
302 rc=IDirectSoundCaptureBuffer_GetCurrentPosition(state->dscbo,&capture_pos,
304 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCurrentPosition() failed: %s\n",
305 DXGetErrorString8(rc));
309 rc=IDirectSoundCaptureBuffer_Lock(state->dscbo,state->offset,state->size,
310 &ptr1,&len1,&ptr2,&len2,0);
311 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Lock() failed: %s\n",
312 DXGetErrorString8(rc));
316 rc=IDirectSoundCaptureBuffer_Unlock(state->dscbo,ptr1,len1,ptr2,len2);
317 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Unlock() failed: %s\n",
318 DXGetErrorString8(rc));
322 state->offset = (state->offset + state->size) % state->buffer_size;
327 static void test_capture_buffer(LPDIRECTSOUNDCAPTURE dsco,
328 LPDIRECTSOUNDCAPTUREBUFFER dscbo, int record)
334 capture_state_t state;
337 /* Private dsound.dll: Error: Invalid caps pointer */
338 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,0);
339 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should "
340 "have returned DSERR_INVALIDPARAM, returned: %s\n",
341 DXGetErrorString8(rc));
343 /* Private dsound.dll: Error: Invalid caps pointer */
345 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps);
346 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should "
347 "have returned DSERR_INVALIDPARAM, returned: %s\n",
348 DXGetErrorString8(rc));
350 dscbcaps.dwSize=sizeof(dscbcaps);
351 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps);
352 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCaps() failed: %s\n",
353 DXGetErrorString8(rc));
354 if (rc==DS_OK && winetest_debug > 1) {
355 trace(" Caps: size = %d flags=0x%08x buffer size=%d\n",
356 dscbcaps.dwSize,dscbcaps.dwFlags,dscbcaps.dwBufferBytes);
359 /* Query the format size. Note that it may not match sizeof(wfx) */
360 /* Private dsound.dll: Error: Either pwfxFormat or pdwSizeWritten must
362 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,NULL);
363 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetFormat() should "
364 "have returned DSERR_INVALIDPARAM, returned: %s\n",
365 DXGetErrorString8(rc));
368 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,&size);
369 ok(rc==DS_OK && size!=0,"IDirectSoundCaptureBuffer_GetFormat() should "
370 "have returned the needed size: rc=%s, size=%d\n",
371 DXGetErrorString8(rc),size);
373 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,&wfx,sizeof(wfx),NULL);
374 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetFormat() failed: %s\n",
375 DXGetErrorString8(rc));
376 if (rc==DS_OK && winetest_debug > 1) {
377 trace(" Format: tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
378 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
379 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
382 /* Private dsound.dll: Error: Invalid status pointer */
383 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,0);
384 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetStatus() should "
385 "have returned DSERR_INVALIDPARAM, returned: %s\n",
386 DXGetErrorString8(rc));
388 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status);
389 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %s\n",
390 DXGetErrorString8(rc));
391 if (rc==DS_OK && winetest_debug > 1) {
392 trace(" Status=0x%04x\n",status);
395 ZeroMemory(&state, sizeof(state));
398 state.buffer_size = dscbcaps.dwBufferBytes;
399 for (i = 0; i < NOTIFICATIONS; i++)
400 state.event[i] = CreateEvent( NULL, FALSE, FALSE, NULL );
401 state.size = dscbcaps.dwBufferBytes / NOTIFICATIONS;
403 rc=IDirectSoundCaptureBuffer_QueryInterface(dscbo,&IID_IDirectSoundNotify,
404 (void **)&(state.notify));
405 ok((rc==DS_OK)&&(state.notify!=NULL),
406 "IDirectSoundCaptureBuffer_QueryInterface() failed: %s\n",
407 DXGetErrorString8(rc));
411 for (i = 0; i < NOTIFICATIONS; i++) {
412 state.posnotify[i].dwOffset = (i * state.size) + state.size - 1;
413 state.posnotify[i].hEventNotify = state.event[i];
416 rc=IDirectSoundNotify_SetNotificationPositions(state.notify,NOTIFICATIONS,
418 ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions() failed: %s\n",
419 DXGetErrorString8(rc));
423 ref=IDirectSoundNotify_Release(state.notify);
424 ok(ref==0,"IDirectSoundNotify_Release(): has %d references, should have "
430 rc=IDirectSoundCaptureBuffer_Start(dscbo,DSCBSTART_LOOPING);
431 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Start() failed: %s\n",
432 DXGetErrorString8(rc));
436 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status);
437 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %s\n",
438 DXGetErrorString8(rc));
439 ok(status==(DSCBSTATUS_CAPTURING|DSCBSTATUS_LOOPING),
440 "GetStatus: bad status: %x\n",status);
444 /* wait for the notifications */
445 for (i = 0; i < (NOTIFICATIONS * 2); i++) {
446 rc=WaitForMultipleObjects(NOTIFICATIONS,state.event,FALSE,3000);
447 ok(rc==(WAIT_OBJECT_0+(i%NOTIFICATIONS)),
448 "WaitForMultipleObjects failed: 0x%x\n",rc);
449 if (rc!=(WAIT_OBJECT_0+(i%NOTIFICATIONS))) {
450 ok((rc==WAIT_TIMEOUT)||(rc==WAIT_FAILED),
451 "Wrong notification: should be %d, got %d\n",
452 i%NOTIFICATIONS,rc-WAIT_OBJECT_0);
454 if (!capture_buffer_service(&state))
458 rc=IDirectSoundCaptureBuffer_Stop(dscbo);
459 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Stop() failed: %s\n",
460 DXGetErrorString8(rc));
466 static BOOL WINAPI dscenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
467 LPCSTR lpcstrModule, LPVOID lpContext)
470 LPDIRECTSOUNDCAPTURE dsco=NULL;
471 LPDIRECTSOUNDCAPTUREBUFFER dscbo=NULL;
472 DSCBUFFERDESC bufdesc;
478 /* Private dsound.dll: Error: Invalid interface buffer */
479 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule);
480 rc=pDirectSoundCaptureCreate(lpGuid,NULL,NULL);
481 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCaptureCreate() should have "
482 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
484 rc=pDirectSoundCaptureCreate(lpGuid,&dsco,NULL);
485 ok((rc==DS_OK)||(rc==DSERR_NODRIVER)||(rc==E_FAIL)||(rc==DSERR_ALLOCATED),
486 "DirectSoundCaptureCreate() failed: %s\n",DXGetErrorString8(rc));
488 if (rc==DSERR_NODRIVER)
489 trace(" No Driver\n");
491 trace(" No Device\n");
492 else if (rc==DSERR_ALLOCATED)
493 trace(" Already In Use\n");
497 /* Private dsound.dll: Error: Invalid caps buffer */
498 rc=IDirectSoundCapture_GetCaps(dsco,NULL);
499 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have "
500 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
502 /* Private dsound.dll: Error: Invalid caps buffer */
504 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps);
505 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have "
506 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc));
508 dsccaps.dwSize=sizeof(dsccaps);
509 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps);
510 ok(rc==DS_OK,"IDirectSoundCapture_GetCaps() failed: %s\n",
511 DXGetErrorString8(rc));
512 if (rc==DS_OK && winetest_debug > 1) {
513 trace(" Caps: size=%d flags=0x%08x formats=%05x channels=%d\n",
514 dsccaps.dwSize,dsccaps.dwFlags,dsccaps.dwFormats,
518 /* Private dsound.dll: Error: Invalid size */
519 /* Private dsound.dll: Error: Invalid capture buffer description */
520 ZeroMemory(&bufdesc, sizeof(bufdesc));
523 bufdesc.dwBufferBytes=0;
524 bufdesc.dwReserved=0;
525 bufdesc.lpwfxFormat=NULL;
526 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
527 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
528 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
529 DXGetErrorString8(rc));
531 ref=IDirectSoundCaptureBuffer_Release(dscbo);
532 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
533 "should have 0\n",ref);
536 /* Private dsound.dll: Error: Invalid buffer size */
537 /* Private dsound.dll: Error: Invalid capture buffer description */
538 ZeroMemory(&bufdesc, sizeof(bufdesc));
539 bufdesc.dwSize=sizeof(bufdesc);
541 bufdesc.dwBufferBytes=0;
542 bufdesc.dwReserved=0;
543 bufdesc.lpwfxFormat=NULL;
544 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
545 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
546 "should have returned DSERR_INVALIDPARAM, returned %s\n",
547 DXGetErrorString8(rc));
549 ref=IDirectSoundCaptureBuffer_Release(dscbo);
550 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
551 "should have 0\n",ref);
554 /* Private dsound.dll: Error: Invalid buffer size */
555 /* Private dsound.dll: Error: Invalid capture buffer description */
556 ZeroMemory(&bufdesc, sizeof(bufdesc));
557 ZeroMemory(&wfx, sizeof(wfx));
558 bufdesc.dwSize=sizeof(bufdesc);
560 bufdesc.dwBufferBytes=0;
561 bufdesc.dwReserved=0;
562 bufdesc.lpwfxFormat=&wfx;
563 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
564 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
565 "should have returned DSERR_INVALIDPARAM, returned :%s\n",
566 DXGetErrorString8(rc));
568 ref=IDirectSoundCaptureBuffer_Release(dscbo);
569 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
570 "should have 0\n",ref);
573 /* Private dsound.dll: Error: Invalid buffer size */
574 /* Private dsound.dll: Error: Invalid capture buffer description */
575 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1);
576 ZeroMemory(&bufdesc, sizeof(bufdesc));
577 bufdesc.dwSize=sizeof(bufdesc);
579 bufdesc.dwBufferBytes=0;
580 bufdesc.dwReserved=0;
581 bufdesc.lpwfxFormat=&wfx;
582 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
583 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() "
584 "should have returned DSERR_INVALIDPARAM, returned: %s\n",
585 DXGetErrorString8(rc));
587 ref=IDirectSoundCaptureBuffer_Release(dscbo);
588 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
589 "should have 0\n",ref);
592 for (f=0;f<NB_FORMATS;f++) {
594 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1],
596 ZeroMemory(&bufdesc, sizeof(bufdesc));
597 bufdesc.dwSize=sizeof(bufdesc);
599 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
600 bufdesc.dwReserved=0;
601 bufdesc.lpwfxFormat=&wfx;
602 if (winetest_interactive)
603 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
604 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
605 ok(((rc==DS_OK)&&(dscbo!=NULL))||(rc==DSERR_BADFORMAT)||
606 ((rc==DSERR_NODRIVER))||(rc==DSERR_ALLOCATED)||(rc==E_INVALIDARG)||(rc==E_FAIL),
607 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
608 "%s capture buffer: %s\n",format_string(&wfx),DXGetErrorString8(rc));
610 test_capture_buffer(dsco, dscbo, winetest_interactive);
611 ref=IDirectSoundCaptureBuffer_Release(dscbo);
612 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
613 "should have 0\n",ref);
614 } else if (rc==DSERR_BADFORMAT) {
615 ok(!(dsccaps.dwFormats & formats[f][3]),
616 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
617 "capture buffer: format listed as supported but using it failed\n");
618 if (!(dsccaps.dwFormats & formats[f][3]))
619 trace(" Format not supported: %s\n", format_string(&wfx));
620 } else if (rc==DSERR_NODRIVER) {
621 trace(" No Driver\n");
622 } else if (rc==DSERR_ALLOCATED) {
623 trace(" Already In Use\n");
624 } else if (rc==E_INVALIDARG) { /* try the old version struct */
625 DSCBUFFERDESC1 bufdesc1;
626 ZeroMemory(&bufdesc1, sizeof(bufdesc1));
627 bufdesc1.dwSize=sizeof(bufdesc1);
629 bufdesc1.dwBufferBytes=wfx.nAvgBytesPerSec;
630 bufdesc1.dwReserved=0;
631 bufdesc1.lpwfxFormat=&wfx;
632 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,
633 (DSCBUFFERDESC*)&bufdesc1,&dscbo,NULL);
634 ok(rc==DS_OK || broken(rc==E_INVALIDARG),
635 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a "
636 "%s capture buffer: %s\n",format_string(&wfx),
637 DXGetErrorString8(rc));
639 test_capture_buffer(dsco, dscbo, winetest_interactive);
640 ref=IDirectSoundCaptureBuffer_Release(dscbo);
641 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d "
642 "references, should have 0\n",ref);
644 } else if (rc==E_FAIL) {
645 /* WAVE_FORMAT_PCM only allows 8 and 16 bits per sample, so only
646 * report a failure if the bits per sample is 8 or 16
648 if (wfx.wBitsPerSample == 8 || wfx.wBitsPerSample == 16)
649 ok(FALSE,"Should not fail for 8 or 16 bits per sample\n");
653 /* try a non PCM format */
656 /* FIXME: Why is this commented out? */
657 init_format(&wfx,WAVE_FORMAT_MULAW,8000,8,1);
658 ZeroMemory(&bufdesc, sizeof(bufdesc));
659 bufdesc.dwSize=sizeof(bufdesc);
660 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED;
661 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
662 bufdesc.dwReserved=0;
663 bufdesc.lpwfxFormat=&wfx;
664 if (winetest_interactive)
665 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
666 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
667 ok((rc==DS_OK)&&(dscbo!=NULL),"IDirectSoundCapture_CreateCaptureBuffer() "
668 "failed to create a capture buffer: %s\n",DXGetErrorString8(rc));
669 if ((rc==DS_OK)&&(dscbo!=NULL)) {
670 test_capture_buffer(dsco, dscbo, winetest_interactive);
671 ref=IDirectSoundCaptureBuffer_Release(dscbo);
672 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, "
673 "should have 0\n",ref);
677 /* Try an invalid format to test error handling */
680 /* FIXME: Remove this test altogether? */
681 init_format(&wfx,WAVE_FORMAT_PCM,2000000,16,2);
682 ZeroMemory(&bufdesc, sizeof(bufdesc));
683 bufdesc.dwSize=sizeof(bufdesc);
684 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED;
685 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec;
686 bufdesc.dwReserved=0;
687 bufdesc.lpwfxFormat=&wfx;
688 if (winetest_interactive)
689 trace(" Testing the capture buffer at %s\n", format_string(&wfx));
690 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL);
691 ok(rc!=DS_OK,"IDirectSoundCapture_CreateCaptureBuffer() should have failed "
692 "at 2 MHz %s\n",DXGetErrorString8(rc));
697 ref=IDirectSoundCapture_Release(dsco);
698 ok(ref==0,"IDirectSoundCapture_Release() has %d references, should "
705 static void capture_tests(void)
708 rc=pDirectSoundCaptureEnumerateA(&dscenum_callback,NULL);
709 ok(rc==DS_OK,"DirectSoundCaptureEnumerateA() failed: %s\n",
710 DXGetErrorString8(rc));
719 hDsound = LoadLibrary("dsound.dll");
722 trace("DLL Version: %s\n", get_file_version("dsound.dll"));
724 pDirectSoundCaptureCreate=(void*)GetProcAddress(hDsound,
725 "DirectSoundCaptureCreate");
726 pDirectSoundCaptureEnumerateA=(void*)GetProcAddress(hDsound,
727 "DirectSoundCaptureEnumerateA");
728 if (pDirectSoundCaptureCreate && pDirectSoundCaptureEnumerateA)
730 IDirectSoundCapture_tests();
734 skip("capture test skipped\n");
736 FreeLibrary(hDsound);
739 skip("dsound.dll not found!\n");