Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencapture.c
Go to the documentation of this file.
00001 /* 00002 * Unit tests for capture functions 00003 * 00004 * Copyright (c) 2002 Francois Gouget 00005 * Copyright (c) 2003 Robert Reif 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #define NONAMELESSSTRUCT 00023 #define NONAMELESSUNION 00024 #include <windows.h> 00025 00026 #include <stdio.h> 00027 00028 #include "wine/test.h" 00029 #include "dsound.h" 00030 #include "mmreg.h" 00031 #include "dxerr8.h" 00032 #include "dsconf.h" 00033 00034 #include "dsound_test.h" 00035 00036 #define NOTIFICATIONS 5 00037 00038 static HRESULT (WINAPI *pDirectSoundCaptureCreate)(LPCGUID,LPDIRECTSOUNDCAPTURE*,LPUNKNOWN)=NULL; 00039 static HRESULT (WINAPI *pDirectSoundCaptureEnumerateA)(LPDSENUMCALLBACKA,LPVOID)=NULL; 00040 00041 static const char * get_format_str(WORD format) 00042 { 00043 static char msg[32]; 00044 #define WAVE_FORMAT(f) case f: return #f 00045 switch (format) { 00046 WAVE_FORMAT(WAVE_FORMAT_PCM); 00047 WAVE_FORMAT(WAVE_FORMAT_ADPCM); 00048 WAVE_FORMAT(WAVE_FORMAT_IBM_CVSD); 00049 WAVE_FORMAT(WAVE_FORMAT_ALAW); 00050 WAVE_FORMAT(WAVE_FORMAT_MULAW); 00051 WAVE_FORMAT(WAVE_FORMAT_OKI_ADPCM); 00052 WAVE_FORMAT(WAVE_FORMAT_IMA_ADPCM); 00053 WAVE_FORMAT(WAVE_FORMAT_MEDIASPACE_ADPCM); 00054 WAVE_FORMAT(WAVE_FORMAT_SIERRA_ADPCM); 00055 WAVE_FORMAT(WAVE_FORMAT_G723_ADPCM); 00056 WAVE_FORMAT(WAVE_FORMAT_DIGISTD); 00057 WAVE_FORMAT(WAVE_FORMAT_DIGIFIX); 00058 WAVE_FORMAT(WAVE_FORMAT_DIALOGIC_OKI_ADPCM); 00059 WAVE_FORMAT(WAVE_FORMAT_YAMAHA_ADPCM); 00060 WAVE_FORMAT(WAVE_FORMAT_SONARC); 00061 WAVE_FORMAT(WAVE_FORMAT_DSPGROUP_TRUESPEECH); 00062 WAVE_FORMAT(WAVE_FORMAT_ECHOSC1); 00063 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF36); 00064 WAVE_FORMAT(WAVE_FORMAT_APTX); 00065 WAVE_FORMAT(WAVE_FORMAT_AUDIOFILE_AF10); 00066 WAVE_FORMAT(WAVE_FORMAT_DOLBY_AC2); 00067 WAVE_FORMAT(WAVE_FORMAT_GSM610); 00068 WAVE_FORMAT(WAVE_FORMAT_ANTEX_ADPCME); 00069 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_VQLPC); 00070 WAVE_FORMAT(WAVE_FORMAT_DIGIREAL); 00071 WAVE_FORMAT(WAVE_FORMAT_DIGIADPCM); 00072 WAVE_FORMAT(WAVE_FORMAT_CONTROL_RES_CR10); 00073 WAVE_FORMAT(WAVE_FORMAT_NMS_VBXADPCM); 00074 WAVE_FORMAT(WAVE_FORMAT_G721_ADPCM); 00075 WAVE_FORMAT(WAVE_FORMAT_MPEG); 00076 WAVE_FORMAT(WAVE_FORMAT_MPEGLAYER3); 00077 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_ADPCM); 00078 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH8); 00079 WAVE_FORMAT(WAVE_FORMAT_CREATIVE_FASTSPEECH10); 00080 WAVE_FORMAT(WAVE_FORMAT_FM_TOWNS_SND); 00081 WAVE_FORMAT(WAVE_FORMAT_OLIGSM); 00082 WAVE_FORMAT(WAVE_FORMAT_OLIADPCM); 00083 WAVE_FORMAT(WAVE_FORMAT_OLICELP); 00084 WAVE_FORMAT(WAVE_FORMAT_OLISBC); 00085 WAVE_FORMAT(WAVE_FORMAT_OLIOPR); 00086 WAVE_FORMAT(WAVE_FORMAT_DEVELOPMENT); 00087 WAVE_FORMAT(WAVE_FORMAT_EXTENSIBLE); 00088 } 00089 #undef WAVE_FORMAT 00090 sprintf(msg, "Unknown(0x%04x)", format); 00091 return msg; 00092 } 00093 00094 static char * format_string(WAVEFORMATEX* wfx) 00095 { 00096 static char str[64]; 00097 00098 sprintf(str, "%5ldx%2dx%d %s", 00099 wfx->nSamplesPerSec, wfx->wBitsPerSample, wfx->nChannels, 00100 get_format_str(wfx->wFormatTag)); 00101 00102 return str; 00103 } 00104 00105 static void IDirectSoundCapture_test(LPDIRECTSOUNDCAPTURE dsco, 00106 BOOL initialized, LPCGUID lpGuid) 00107 { 00108 HRESULT rc; 00109 DSCCAPS dsccaps; 00110 int ref; 00111 IUnknown * unknown; 00112 IDirectSoundCapture * dsc; 00113 00114 /* Try to Query for objects */ 00115 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IUnknown, 00116 (LPVOID*)&unknown); 00117 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IUnknown) " 00118 "failed: %s\n", DXGetErrorString8(rc)); 00119 if (rc==DS_OK) 00120 IDirectSoundCapture_Release(unknown); 00121 00122 rc=IDirectSoundCapture_QueryInterface(dsco, &IID_IDirectSoundCapture, 00123 (LPVOID*)&dsc); 00124 ok(rc==DS_OK, "IDirectSoundCapture_QueryInterface(IID_IDirectSoundCapture) " 00125 "failed: %s\n", DXGetErrorString8(rc)); 00126 if (rc==DS_OK) 00127 IDirectSoundCapture_Release(dsc); 00128 00129 if (initialized == FALSE) { 00130 /* try unitialized object */ 00131 rc=IDirectSoundCapture_GetCaps(dsco,0); 00132 ok(rc==DSERR_UNINITIALIZED, "IDirectSoundCapture_GetCaps(NULL) " 00133 "should have returned DSERR_UNINITIALIZED, returned: %s\n", 00134 DXGetErrorString8(rc)); 00135 00136 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps); 00137 ok(rc==DSERR_UNINITIALIZED,"IDirectSoundCapture_GetCaps() " 00138 "should have returned DSERR_UNINITIALIZED, returned: %s\n", 00139 DXGetErrorString8(rc)); 00140 00141 rc=IDirectSoundCapture_Initialize(dsco, lpGuid); 00142 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00143 "IDirectSoundCapture_Initialize() failed: %s\n", 00144 DXGetErrorString8(rc)); 00145 if (rc==DSERR_NODRIVER) { 00146 trace(" No Driver\n"); 00147 goto EXIT; 00148 } else if (rc==E_FAIL) { 00149 trace(" No Device\n"); 00150 goto EXIT; 00151 } else if (rc==DSERR_ALLOCATED) { 00152 trace(" Already In Use\n"); 00153 goto EXIT; 00154 } 00155 } 00156 00157 rc=IDirectSoundCapture_Initialize(dsco, lpGuid); 00158 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSoundCapture_Initialize() " 00159 "should have returned DSERR_ALREADYINITIALIZED: %s\n", 00160 DXGetErrorString8(rc)); 00161 00162 /* DSOUND: Error: Invalid caps buffer */ 00163 rc=IDirectSoundCapture_GetCaps(dsco, 0); 00164 ok(rc==DSERR_INVALIDPARAM, "IDirectSoundCapture_GetCaps(NULL) " 00165 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00166 DXGetErrorString8(rc)); 00167 00168 ZeroMemory(&dsccaps, sizeof(dsccaps)); 00169 00170 /* DSOUND: Error: Invalid caps buffer */ 00171 rc=IDirectSound_GetCaps(dsco, &dsccaps); 00172 ok(rc==DSERR_INVALIDPARAM, "IDirectSound_GetCaps() " 00173 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00174 DXGetErrorString8(rc)); 00175 00176 dsccaps.dwSize=sizeof(dsccaps); 00177 00178 /* DSOUND: Running on a certified driver */ 00179 rc=IDirectSoundCapture_GetCaps(dsco, &dsccaps); 00180 ok(rc==DS_OK, "IDirectSoundCapture_GetCaps() failed: %s\n", 00181 DXGetErrorString8(rc)); 00182 00183 EXIT: 00184 ref=IDirectSoundCapture_Release(dsco); 00185 ok(ref==0, "IDirectSoundCapture_Release() has %d references, " 00186 "should have 0\n", ref); 00187 } 00188 00189 static void IDirectSoundCapture_tests(void) 00190 { 00191 HRESULT rc; 00192 LPDIRECTSOUNDCAPTURE dsco=NULL; 00193 00194 trace("Testing IDirectSoundCapture\n"); 00195 00196 /* try the COM class factory method of creation with no device specified */ 00197 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER, 00198 &IID_IDirectSoundCapture, (void**)&dsco); 00199 ok(rc==S_OK||rc==REGDB_E_CLASSNOTREG,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %s\n", 00200 DXGetErrorString8(rc)); 00201 if (rc==REGDB_E_CLASSNOTREG) { 00202 trace(" Class Not Registered\n"); 00203 return; 00204 } 00205 if (dsco) 00206 IDirectSoundCapture_test(dsco, FALSE, NULL); 00207 00208 /* try the COM class factory method of creation with default capture 00209 * device specified */ 00210 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER, 00211 &IID_IDirectSoundCapture, (void**)&dsco); 00212 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %s\n", 00213 DXGetErrorString8(rc)); 00214 if (dsco) 00215 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultCapture); 00216 00217 /* try the COM class factory method of creation with default voice 00218 * capture device specified */ 00219 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER, 00220 &IID_IDirectSoundCapture, (void**)&dsco); 00221 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSoundCapture) failed: %s\n", 00222 DXGetErrorString8(rc)); 00223 if (dsco) 00224 IDirectSoundCapture_test(dsco, FALSE, &DSDEVID_DefaultVoiceCapture); 00225 00226 /* try the COM class factory method of creation with a bad 00227 * IID specified */ 00228 rc=CoCreateInstance(&CLSID_DirectSoundCapture, NULL, CLSCTX_INPROC_SERVER, 00229 &CLSID_DirectSoundPrivate, (void**)&dsco); 00230 ok(rc==E_NOINTERFACE, 00231 "CoCreateInstance(CLSID_DirectSoundCapture,CLSID_DirectSoundPrivate) " 00232 "should have failed: %s\n",DXGetErrorString8(rc)); 00233 00234 /* try with no device specified */ 00235 rc=pDirectSoundCaptureCreate(NULL,&dsco,NULL); 00236 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00237 "DirectSoundCaptureCreate(NULL) failed: %s\n",DXGetErrorString8(rc)); 00238 if (rc==S_OK && dsco) 00239 IDirectSoundCapture_test(dsco, TRUE, NULL); 00240 00241 /* try with default capture device specified */ 00242 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultCapture,&dsco,NULL); 00243 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00244 "DirectSoundCaptureCreate(DSDEVID_DefaultCapture) failed: %s\n", 00245 DXGetErrorString8(rc)); 00246 if (rc==DS_OK && dsco) 00247 IDirectSoundCapture_test(dsco, TRUE, NULL); 00248 00249 /* try with default voice capture device specified */ 00250 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoiceCapture,&dsco,NULL); 00251 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00252 "DirectSoundCaptureCreate(DSDEVID_DefaultVoiceCapture) failed: %s\n", 00253 DXGetErrorString8(rc)); 00254 if (rc==DS_OK && dsco) 00255 IDirectSoundCapture_test(dsco, TRUE, NULL); 00256 00257 /* try with a bad device specified */ 00258 rc=pDirectSoundCaptureCreate(&DSDEVID_DefaultVoicePlayback,&dsco,NULL); 00259 ok(rc==DSERR_NODRIVER, 00260 "DirectSoundCaptureCreate(DSDEVID_DefaultVoicePlatback) " 00261 "should have failed: %s\n",DXGetErrorString8(rc)); 00262 if (rc==DS_OK && dsco) 00263 IDirectSoundCapture_Release(dsco); 00264 } 00265 00266 typedef struct { 00267 char* wave; 00268 DWORD wave_len; 00269 00270 LPDIRECTSOUNDCAPTUREBUFFER dscbo; 00271 LPWAVEFORMATEX wfx; 00272 DSBPOSITIONNOTIFY posnotify[NOTIFICATIONS]; 00273 HANDLE event[NOTIFICATIONS]; 00274 LPDIRECTSOUNDNOTIFY notify; 00275 00276 DWORD buffer_size; 00277 DWORD read; 00278 DWORD offset; 00279 DWORD size; 00280 00281 DWORD last_pos; 00282 } capture_state_t; 00283 00284 static int capture_buffer_service(capture_state_t* state) 00285 { 00286 HRESULT rc; 00287 LPVOID ptr1,ptr2; 00288 DWORD len1,len2; 00289 DWORD capture_pos,read_pos; 00290 00291 rc=IDirectSoundCaptureBuffer_GetCurrentPosition(state->dscbo,&capture_pos, 00292 &read_pos); 00293 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCurrentPosition() failed: %s\n", 00294 DXGetErrorString8(rc)); 00295 if (rc!=DS_OK) 00296 return 0; 00297 00298 rc=IDirectSoundCaptureBuffer_Lock(state->dscbo,state->offset,state->size, 00299 &ptr1,&len1,&ptr2,&len2,0); 00300 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Lock() failed: %s\n", 00301 DXGetErrorString8(rc)); 00302 if (rc!=DS_OK) 00303 return 0; 00304 00305 rc=IDirectSoundCaptureBuffer_Unlock(state->dscbo,ptr1,len1,ptr2,len2); 00306 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Unlock() failed: %s\n", 00307 DXGetErrorString8(rc)); 00308 if (rc!=DS_OK) 00309 return 0; 00310 00311 state->offset = (state->offset + state->size) % state->buffer_size; 00312 00313 return 1; 00314 } 00315 00316 static void test_capture_buffer(LPDIRECTSOUNDCAPTURE dsco, 00317 LPDIRECTSOUNDCAPTUREBUFFER dscbo, int record) 00318 { 00319 HRESULT rc; 00320 DSCBCAPS dscbcaps; 00321 WAVEFORMATEX wfx; 00322 DWORD size,status; 00323 capture_state_t state; 00324 int i, ref; 00325 00326 /* Private dsound.dll: Error: Invalid caps pointer */ 00327 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,0); 00328 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should " 00329 "have returned DSERR_INVALIDPARAM, returned: %s\n", 00330 DXGetErrorString8(rc)); 00331 00332 /* Private dsound.dll: Error: Invalid caps pointer */ 00333 dscbcaps.dwSize=0; 00334 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps); 00335 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetCaps() should " 00336 "have returned DSERR_INVALIDPARAM, returned: %s\n", 00337 DXGetErrorString8(rc)); 00338 00339 dscbcaps.dwSize=sizeof(dscbcaps); 00340 rc=IDirectSoundCaptureBuffer_GetCaps(dscbo,&dscbcaps); 00341 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetCaps() failed: %s\n", 00342 DXGetErrorString8(rc)); 00343 if (rc==DS_OK && winetest_debug > 1) { 00344 trace(" Caps: size = %ld flags=0x%08lx buffer size=%ld\n", 00345 dscbcaps.dwSize,dscbcaps.dwFlags,dscbcaps.dwBufferBytes); 00346 } 00347 00348 /* Query the format size. Note that it may not match sizeof(wfx) */ 00349 /* Private dsound.dll: Error: Either pwfxFormat or pdwSizeWritten must 00350 * be non-NULL */ 00351 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,NULL); 00352 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetFormat() should " 00353 "have returned DSERR_INVALIDPARAM, returned: %s\n", 00354 DXGetErrorString8(rc)); 00355 00356 size=0; 00357 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,NULL,0,&size); 00358 ok(rc==DS_OK && size!=0,"IDirectSoundCaptureBuffer_GetFormat() should " 00359 "have returned the needed size: rc=%s, size=%ld\n", 00360 DXGetErrorString8(rc),size); 00361 00362 rc=IDirectSoundCaptureBuffer_GetFormat(dscbo,&wfx,sizeof(wfx),NULL); 00363 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetFormat() failed: %s\n", 00364 DXGetErrorString8(rc)); 00365 if (rc==DS_OK && winetest_debug > 1) { 00366 trace(" Format: tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n", 00367 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample, 00368 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign); 00369 } 00370 00371 /* Private dsound.dll: Error: Invalid status pointer */ 00372 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,0); 00373 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCaptureBuffer_GetStatus() should " 00374 "have returned DSERR_INVALIDPARAM, returned: %s\n", 00375 DXGetErrorString8(rc)); 00376 00377 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status); 00378 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %s\n", 00379 DXGetErrorString8(rc)); 00380 if (rc==DS_OK && winetest_debug > 1) { 00381 trace(" Status=0x%04lx\n",status); 00382 } 00383 00384 ZeroMemory(&state, sizeof(state)); 00385 state.dscbo=dscbo; 00386 state.wfx=&wfx; 00387 state.buffer_size = dscbcaps.dwBufferBytes; 00388 for (i = 0; i < NOTIFICATIONS; i++) 00389 state.event[i] = CreateEvent( NULL, FALSE, FALSE, NULL ); 00390 state.size = dscbcaps.dwBufferBytes / NOTIFICATIONS; 00391 00392 rc=IDirectSoundCaptureBuffer_QueryInterface(dscbo,&IID_IDirectSoundNotify, 00393 (void **)&(state.notify)); 00394 ok((rc==DS_OK)&&(state.notify!=NULL), 00395 "IDirectSoundCaptureBuffer_QueryInterface() failed: %s\n", 00396 DXGetErrorString8(rc)); 00397 if (rc!=DS_OK) 00398 return; 00399 00400 for (i = 0; i < NOTIFICATIONS; i++) { 00401 state.posnotify[i].dwOffset = (i * state.size) + state.size - 1; 00402 state.posnotify[i].hEventNotify = state.event[i]; 00403 } 00404 00405 rc=IDirectSoundNotify_SetNotificationPositions(state.notify,NOTIFICATIONS, 00406 state.posnotify); 00407 ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions() failed: %s\n", 00408 DXGetErrorString8(rc)); 00409 if (rc!=DS_OK) 00410 return; 00411 00412 ref=IDirectSoundNotify_Release(state.notify); 00413 ok(ref==0,"IDirectSoundNotify_Release(): has %d references, should have " 00414 "0\n",ref); 00415 if (ref!=0) 00416 return; 00417 00418 if (record) { 00419 rc=IDirectSoundCaptureBuffer_Start(dscbo,DSCBSTART_LOOPING); 00420 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Start() failed: %s\n", 00421 DXGetErrorString8(rc)); 00422 if (rc!=DS_OK) 00423 return; 00424 00425 rc=IDirectSoundCaptureBuffer_GetStatus(dscbo,&status); 00426 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_GetStatus() failed: %s\n", 00427 DXGetErrorString8(rc)); 00428 ok(status==(DSCBSTATUS_CAPTURING|DSCBSTATUS_LOOPING), 00429 "GetStatus: bad status: %lx\n",status); 00430 if (rc!=DS_OK) 00431 return; 00432 00433 /* wait for the notifications */ 00434 for (i = 0; i < (NOTIFICATIONS * 2); i++) { 00435 rc=WaitForMultipleObjects(NOTIFICATIONS,state.event,FALSE,3000); 00436 ok(rc==(WAIT_OBJECT_0+(i%NOTIFICATIONS)), 00437 "WaitForMultipleObjects failed: 0x%lx\n",rc); 00438 if (rc!=(WAIT_OBJECT_0+(i%NOTIFICATIONS))) { 00439 ok((rc==WAIT_TIMEOUT)||(rc==WAIT_FAILED), 00440 "Wrong notification: should be %d, got %ld\n", 00441 i%NOTIFICATIONS,rc-WAIT_OBJECT_0); 00442 } 00443 if (!capture_buffer_service(&state)) 00444 break; 00445 } 00446 00447 rc=IDirectSoundCaptureBuffer_Stop(dscbo); 00448 ok(rc==DS_OK,"IDirectSoundCaptureBuffer_Stop() failed: %s\n", 00449 DXGetErrorString8(rc)); 00450 if (rc!=DS_OK) 00451 return; 00452 } 00453 } 00454 00455 static BOOL WINAPI dscenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription, 00456 LPCSTR lpcstrModule, LPVOID lpContext) 00457 { 00458 HRESULT rc; 00459 LPDIRECTSOUNDCAPTURE dsco=NULL; 00460 LPDIRECTSOUNDCAPTUREBUFFER dscbo=NULL; 00461 DSCBUFFERDESC bufdesc; 00462 WAVEFORMATEX wfx; 00463 DSCCAPS dsccaps; 00464 DWORD f; 00465 int ref; 00466 00467 /* Private dsound.dll: Error: Invalid interface buffer */ 00468 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule); 00469 rc=pDirectSoundCaptureCreate(lpGuid,NULL,NULL); 00470 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCaptureCreate() should have " 00471 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00472 if (rc==DS_OK) { 00473 ref=IDirectSoundCapture_Release(dsco); 00474 ok(ref==0,"IDirectSoundCapture_Release() has %d references, should " 00475 "have 0\n",ref); 00476 } 00477 00478 rc=pDirectSoundCaptureCreate(lpGuid,&dsco,NULL); 00479 ok((rc==DS_OK)||(rc==DSERR_NODRIVER)||(rc==E_FAIL)||(rc==DSERR_ALLOCATED), 00480 "DirectSoundCaptureCreate() failed: %s\n",DXGetErrorString8(rc)); 00481 if (rc!=DS_OK) { 00482 if (rc==DSERR_NODRIVER) 00483 trace(" No Driver\n"); 00484 else if (rc==E_FAIL) 00485 trace(" No Device\n"); 00486 else if (rc==DSERR_ALLOCATED) 00487 trace(" Already In Use\n"); 00488 goto EXIT; 00489 } 00490 00491 /* Private dsound.dll: Error: Invalid caps buffer */ 00492 rc=IDirectSoundCapture_GetCaps(dsco,NULL); 00493 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have " 00494 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00495 00496 /* Private dsound.dll: Error: Invalid caps buffer */ 00497 dsccaps.dwSize=0; 00498 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps); 00499 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_GetCaps() should have " 00500 "returned DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00501 00502 dsccaps.dwSize=sizeof(dsccaps); 00503 rc=IDirectSoundCapture_GetCaps(dsco,&dsccaps); 00504 ok(rc==DS_OK,"IDirectSoundCapture_GetCaps() failed: %s\n", 00505 DXGetErrorString8(rc)); 00506 if (rc==DS_OK && winetest_debug > 1) { 00507 trace(" Caps: size=%ld flags=0x%08lx formats=%05lx channels=%ld\n", 00508 dsccaps.dwSize,dsccaps.dwFlags,dsccaps.dwFormats, 00509 dsccaps.dwChannels); 00510 } 00511 00512 /* Private dsound.dll: Error: Invalid size */ 00513 /* Private dsound.dll: Error: Invalid capture buffer description */ 00514 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00515 bufdesc.dwSize=0; 00516 bufdesc.dwFlags=0; 00517 bufdesc.dwBufferBytes=0; 00518 bufdesc.dwReserved=0; 00519 bufdesc.lpwfxFormat=NULL; 00520 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL); 00521 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() " 00522 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00523 DXGetErrorString8(rc)); 00524 if (rc==DS_OK) { 00525 ref=IDirectSoundCaptureBuffer_Release(dscbo); 00526 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, " 00527 "should have 0\n",ref); 00528 } 00529 00530 /* Private dsound.dll: Error: Invalid buffer size */ 00531 /* Private dsound.dll: Error: Invalid capture buffer description */ 00532 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00533 bufdesc.dwSize=sizeof(bufdesc); 00534 bufdesc.dwFlags=0; 00535 bufdesc.dwBufferBytes=0; 00536 bufdesc.dwReserved=0; 00537 bufdesc.lpwfxFormat=NULL; 00538 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL); 00539 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() " 00540 "should have returned DSERR_INVALIDPARAM, returned %s\n", 00541 DXGetErrorString8(rc)); 00542 if (rc==DS_OK) { 00543 ref=IDirectSoundCaptureBuffer_Release(dscbo); 00544 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, " 00545 "should have 0\n",ref); 00546 } 00547 00548 /* Private dsound.dll: Error: Invalid buffer size */ 00549 /* Private dsound.dll: Error: Invalid capture buffer description */ 00550 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00551 ZeroMemory(&wfx, sizeof(wfx)); 00552 bufdesc.dwSize=sizeof(bufdesc); 00553 bufdesc.dwFlags=0; 00554 bufdesc.dwBufferBytes=0; 00555 bufdesc.dwReserved=0; 00556 bufdesc.lpwfxFormat=&wfx; 00557 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL); 00558 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() " 00559 "should have returned DSERR_INVALIDPARAM, returned :%s\n", 00560 DXGetErrorString8(rc)); 00561 if (rc==DS_OK) { 00562 ref=IDirectSoundCaptureBuffer_Release(dscbo); 00563 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, " 00564 "should have 0\n",ref); 00565 } 00566 00567 /* Private dsound.dll: Error: Invalid buffer size */ 00568 /* Private dsound.dll: Error: Invalid capture buffer description */ 00569 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1); 00570 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00571 bufdesc.dwSize=sizeof(bufdesc); 00572 bufdesc.dwFlags=0; 00573 bufdesc.dwBufferBytes=0; 00574 bufdesc.dwReserved=0; 00575 bufdesc.lpwfxFormat=&wfx; 00576 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL); 00577 ok(rc==DSERR_INVALIDPARAM,"IDirectSoundCapture_CreateCaptureBuffer() " 00578 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00579 DXGetErrorString8(rc)); 00580 if (rc==DS_OK) { 00581 ref=IDirectSoundCaptureBuffer_Release(dscbo); 00582 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, " 00583 "should have 0\n",ref); 00584 } 00585 00586 for (f=0;f<NB_FORMATS;f++) { 00587 dscbo=NULL; 00588 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1], 00589 formats[f][2]); 00590 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00591 bufdesc.dwSize=sizeof(bufdesc); 00592 bufdesc.dwFlags=0; 00593 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec; 00594 bufdesc.dwReserved=0; 00595 bufdesc.lpwfxFormat=&wfx; 00596 if (winetest_interactive) 00597 trace(" Testing the capture buffer at %s\n", format_string(&wfx)); 00598 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL); 00599 ok(((rc==DS_OK)&&(dscbo!=NULL))||(rc==DSERR_BADFORMAT)|| 00600 ((rc==DSERR_NODRIVER))||(rc==DSERR_ALLOCATED)||(rc==E_INVALIDARG), 00601 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a " 00602 "%s capture buffer: %s\n",format_string(&wfx),DXGetErrorString8(rc)); 00603 if (rc==DS_OK) { 00604 test_capture_buffer(dsco, dscbo, winetest_interactive); 00605 ref=IDirectSoundCaptureBuffer_Release(dscbo); 00606 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, " 00607 "should have 0\n",ref); 00608 } else if (rc==DSERR_BADFORMAT) { 00609 ok(!(dsccaps.dwFormats & formats[f][3]), 00610 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a " 00611 "capture buffer: format listed as supported but using it failed\n"); 00612 if (!(dsccaps.dwFormats & formats[f][3])) 00613 trace(" Format not supported: %s\n", format_string(&wfx)); 00614 } else if (rc==DSERR_NODRIVER) { 00615 trace(" No Driver\n"); 00616 } else if (rc==DSERR_ALLOCATED) { 00617 trace(" Already In Use\n"); 00618 } else if (rc==E_INVALIDARG) { /* try the old version struct */ 00619 DSCBUFFERDESC1 bufdesc1; 00620 ZeroMemory(&bufdesc1, sizeof(bufdesc1)); 00621 bufdesc1.dwSize=sizeof(bufdesc1); 00622 bufdesc1.dwFlags=0; 00623 bufdesc1.dwBufferBytes=wfx.nAvgBytesPerSec; 00624 bufdesc1.dwReserved=0; 00625 bufdesc1.lpwfxFormat=&wfx; 00626 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco, 00627 (DSCBUFFERDESC*)&bufdesc1,&dscbo,NULL); 00628 ok(rc==DS_OK, 00629 "IDirectSoundCapture_CreateCaptureBuffer() failed to create a " 00630 "%s capture buffer: %s\n",format_string(&wfx), 00631 DXGetErrorString8(rc)); 00632 if (rc==DS_OK) { 00633 test_capture_buffer(dsco, dscbo, winetest_interactive); 00634 ref=IDirectSoundCaptureBuffer_Release(dscbo); 00635 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d " 00636 "references, should have 0\n",ref); 00637 } 00638 } 00639 } 00640 00641 /* try a non PCM format */ 00642 #if 0 00643 init_format(&wfx,WAVE_FORMAT_MULAW,8000,8,1); 00644 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00645 bufdesc.dwSize=sizeof(bufdesc); 00646 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED; 00647 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec; 00648 bufdesc.dwReserved=0; 00649 bufdesc.lpwfxFormat=&wfx; 00650 if (winetest_interactive) 00651 trace(" Testing the capture buffer at %s\n", format_string(&wfx)); 00652 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL); 00653 ok((rc==DS_OK)&&(dscbo!=NULL),"IDirectSoundCapture_CreateCaptureBuffer() " 00654 "failed to create a capture buffer: %s\n",DXGetErrorString8(rc)); 00655 if ((rc==DS_OK)&&(dscbo!=NULL)) { 00656 test_capture_buffer(dsco, dscbo, winetest_interactive); 00657 ref=IDirectSoundCaptureBuffer_Release(dscbo); 00658 ok(ref==0,"IDirectSoundCaptureBuffer_Release() has %d references, " 00659 "should have 0\n",ref); 00660 } 00661 #endif 00662 00663 /* Try an invalid format to test error handling */ 00664 #if 0 00665 init_format(&wfx,WAVE_FORMAT_PCM,2000000,16,2); 00666 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00667 bufdesc.dwSize=sizeof(bufdesc); 00668 bufdesc.dwFlags=DSCBCAPS_WAVEMAPPED; 00669 bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec; 00670 bufdesc.dwReserved=0; 00671 bufdesc.lpwfxFormat=&wfx; 00672 if (winetest_interactive) 00673 trace(" Testing the capture buffer at %s\n", format_string(&wfx)); 00674 rc=IDirectSoundCapture_CreateCaptureBuffer(dsco,&bufdesc,&dscbo,NULL); 00675 ok(rc!=DS_OK,"IDirectSoundCapture_CreateCaptureBuffer() should have failed " 00676 "at 2 MHz %s\n",DXGetErrorString8(rc)); 00677 #endif 00678 00679 EXIT: 00680 if (dsco!=NULL) { 00681 ref=IDirectSoundCapture_Release(dsco); 00682 ok(ref==0,"IDirectSoundCapture_Release() has %d references, should " 00683 "have 0\n",ref); 00684 } 00685 00686 return TRUE; 00687 } 00688 00689 static void capture_tests(void) 00690 { 00691 HRESULT rc; 00692 rc=pDirectSoundCaptureEnumerateA(&dscenum_callback,NULL); 00693 ok(rc==DS_OK,"DirectSoundCaptureEnumerateA() failed: %s\n", 00694 DXGetErrorString8(rc)); 00695 } 00696 00697 START_TEST(capture) 00698 { 00699 HMODULE hDsound; 00700 00701 CoInitialize(NULL); 00702 00703 hDsound = LoadLibraryA("dsound.dll"); 00704 if (!hDsound) { 00705 trace("dsound.dll not found\n"); 00706 return; 00707 } 00708 00709 trace("DLL Version: %s\n", get_file_version("dsound.dll")); 00710 00711 pDirectSoundCaptureCreate=(void*)GetProcAddress(hDsound,"DirectSoundCaptureCreate"); 00712 pDirectSoundCaptureEnumerateA=(void*)GetProcAddress(hDsound,"DirectSoundCaptureEnumerateA"); 00713 if (!pDirectSoundCaptureCreate || !pDirectSoundCaptureEnumerateA) 00714 { 00715 trace("capture test skipped\n"); 00716 return; 00717 } 00718 00719 IDirectSoundCapture_tests(); 00720 capture_tests(); 00721 00722 CoUninitialize(); 00723 } Generated on Sat May 26 2012 04:20:11 for ReactOS by
1.7.6.1
|