Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygendsound8.c
Go to the documentation of this file.
00001 /* 00002 * Tests basic sound playback in DirectSound. 00003 * In particular we test each standard Windows sound format to make sure 00004 * we handle the sound card/driver quirks correctly. 00005 * 00006 * Part of this test involves playing test tones. But this only makes 00007 * sense if someone is going to carefully listen to it, and would only 00008 * bother everyone else. 00009 * So this is only done if the test is being run in interactive mode. 00010 * 00011 * Copyright (c) 2002-2004 Francois Gouget 00012 * 00013 * This library is free software; you can redistribute it and/or 00014 * modify it under the terms of the GNU Lesser General Public 00015 * License as published by the Free Software Foundation; either 00016 * version 2.1 of the License, or (at your option) any later version. 00017 * 00018 * This library is distributed in the hope that it will be useful, 00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00021 * Lesser General Public License for more details. 00022 * 00023 * You should have received a copy of the GNU Lesser General Public 00024 * License along with this library; if not, write to the Free Software 00025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00026 */ 00027 00028 #define NONAMELESSSTRUCT 00029 #define NONAMELESSUNION 00030 #include <windows.h> 00031 #include <stdio.h> 00032 00033 #include "wine/test.h" 00034 #include "dsound.h" 00035 #include "dxerr8.h" 00036 #include "dsconf.h" 00037 00038 #include "dsound_test.h" 00039 00040 static HRESULT (WINAPI *pDirectSoundCreate8)(LPCGUID,LPDIRECTSOUND8*,LPUNKNOWN)=NULL; 00041 00042 int align(int length, int align) 00043 { 00044 return (length / align) * align; 00045 } 00046 00047 static void IDirectSound8_test(LPDIRECTSOUND8 dso, BOOL initialized, 00048 LPCGUID lpGuid) 00049 { 00050 HRESULT rc; 00051 DSCAPS dscaps; 00052 int ref; 00053 IUnknown * unknown; 00054 IDirectSound * ds; 00055 IDirectSound8 * ds8; 00056 DWORD speaker_config, new_speaker_config; 00057 DWORD certified; 00058 00059 /* Try to Query for objects */ 00060 rc=IDirectSound8_QueryInterface(dso,&IID_IUnknown,(LPVOID*)&unknown); 00061 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IUnknown) failed: %s\n", 00062 DXGetErrorString8(rc)); 00063 if (rc==DS_OK) 00064 IDirectSound8_Release(unknown); 00065 00066 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound,(LPVOID*)&ds); 00067 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound) failed: %s\n", 00068 DXGetErrorString8(rc)); 00069 if (rc==DS_OK) 00070 IDirectSound_Release(ds); 00071 00072 rc=IDirectSound8_QueryInterface(dso,&IID_IDirectSound8,(LPVOID*)&ds8); 00073 ok(rc==DS_OK,"IDirectSound8_QueryInterface(IID_IDirectSound8) " 00074 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00075 DXGetErrorString8(rc)); 00076 if (rc==DS_OK) 00077 IDirectSound8_Release(ds8); 00078 00079 if (initialized == FALSE) { 00080 /* try unitialized object */ 00081 rc=IDirectSound8_GetCaps(dso,0); 00082 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps(NULL) " 00083 "should have returned DSERR_UNINITIALIZED, returned: %s\n", 00084 DXGetErrorString8(rc)); 00085 00086 rc=IDirectSound8_GetCaps(dso,&dscaps); 00087 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetCaps() " 00088 "should have returned DSERR_UNINITIALIZED, returned: %s\n", 00089 DXGetErrorString8(rc)); 00090 00091 rc=IDirectSound8_Compact(dso); 00092 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_Compact() " 00093 "should have returned DSERR_UNINITIALIZED, returned: %s\n", 00094 DXGetErrorString8(rc)); 00095 00096 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config); 00097 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_GetSpeakerConfig() " 00098 "should have returned DSERR_UNINITIALIZED, returned: %s\n", 00099 DXGetErrorString8(rc)); 00100 00101 rc=IDirectSound8_VerifyCertification(dso, &certified); 00102 ok(rc==DSERR_UNINITIALIZED,"IDirectSound8_VerifyCertification() " 00103 "should have returned DSERR_UNINITIALIZED, returned: %s\n", 00104 DXGetErrorString8(rc)); 00105 00106 rc=IDirectSound8_Initialize(dso,lpGuid); 00107 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00108 "IDirectSound8_Initialize() failed: %s\n",DXGetErrorString8(rc)); 00109 if (rc==DSERR_NODRIVER) { 00110 trace(" No Driver\n"); 00111 goto EXIT; 00112 } else if (rc==E_FAIL) { 00113 trace(" No Device\n"); 00114 goto EXIT; 00115 } else if (rc==DSERR_ALLOCATED) { 00116 trace(" Already In Use\n"); 00117 goto EXIT; 00118 } 00119 } 00120 00121 rc=IDirectSound8_Initialize(dso,lpGuid); 00122 ok(rc==DSERR_ALREADYINITIALIZED, "IDirectSound8_Initialize() " 00123 "should have returned DSERR_ALREADYINITIALIZED: %s\n", 00124 DXGetErrorString8(rc)); 00125 00126 /* DSOUND: Error: Invalid caps buffer */ 00127 rc=IDirectSound8_GetCaps(dso,0); 00128 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() " 00129 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00130 DXGetErrorString8(rc)); 00131 00132 ZeroMemory(&dscaps, sizeof(dscaps)); 00133 00134 /* DSOUND: Error: Invalid caps buffer */ 00135 rc=IDirectSound8_GetCaps(dso,&dscaps); 00136 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetCaps() " 00137 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00138 DXGetErrorString8(rc)); 00139 00140 dscaps.dwSize=sizeof(dscaps); 00141 00142 /* DSOUND: Running on a certified driver */ 00143 rc=IDirectSound8_GetCaps(dso,&dscaps); 00144 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); 00145 00146 rc=IDirectSound8_Compact(dso); 00147 ok(rc==DSERR_PRIOLEVELNEEDED,"IDirectSound8_Compact() failed: %s\n", 00148 DXGetErrorString8(rc)); 00149 00150 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00151 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00152 DXGetErrorString8(rc)); 00153 00154 rc=IDirectSound8_Compact(dso); 00155 ok(rc==DS_OK,"IDirectSound8_Compact() failed: %s\n",DXGetErrorString8(rc)); 00156 00157 rc=IDirectSound8_GetSpeakerConfig(dso,0); 00158 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_GetSpeakerConfig(NULL) " 00159 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00160 DXGetErrorString8(rc)); 00161 00162 rc=IDirectSound8_GetSpeakerConfig(dso,&speaker_config); 00163 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n", 00164 DXGetErrorString8(rc)); 00165 00166 speaker_config = DSSPEAKER_COMBINED(DSSPEAKER_STEREO, 00167 DSSPEAKER_GEOMETRY_WIDE); 00168 rc=IDirectSound8_SetSpeakerConfig(dso,speaker_config); 00169 ok(rc==DS_OK,"IDirectSound8_SetSpeakerConfig() failed: %s\n", 00170 DXGetErrorString8(rc)); 00171 if (rc==DS_OK) { 00172 rc=IDirectSound8_GetSpeakerConfig(dso,&new_speaker_config); 00173 ok(rc==DS_OK,"IDirectSound8_GetSpeakerConfig() failed: %s\n", 00174 DXGetErrorString8(rc)); 00175 if (rc==DS_OK && speaker_config!=new_speaker_config) 00176 trace("IDirectSound8_GetSpeakerConfig() failed to set speaker " 00177 "config: expected 0x%08lx, got 0x%08lx\n", 00178 speaker_config,new_speaker_config); 00179 } 00180 00181 rc=IDirectSound8_VerifyCertification(dso, &certified); 00182 ok(rc==DS_OK||rc==E_NOTIMPL,"IDirectSound8_VerifyCertification() failed: %s\n", 00183 DXGetErrorString8(rc)); 00184 00185 EXIT: 00186 ref=IDirectSound8_Release(dso); 00187 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00188 } 00189 00190 static void IDirectSound8_tests(void) 00191 { 00192 HRESULT rc; 00193 LPDIRECTSOUND8 dso=NULL; 00194 00195 trace("Testing IDirectSound8\n"); 00196 00197 /* try the COM class factory method of creation with no device specified */ 00198 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, 00199 &IID_IDirectSound8, (void**)&dso); 00200 ok(rc==S_OK,"CoCreateInstance() failed: %s\n",DXGetErrorString8(rc)); 00201 if (dso) 00202 IDirectSound8_test(dso, FALSE, NULL); 00203 00204 /* try the COM class factory method of creation with default playback 00205 * device specified */ 00206 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, 00207 &IID_IDirectSound8, (void**)&dso); 00208 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %s\n", 00209 DXGetErrorString8(rc)); 00210 if (dso) 00211 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultPlayback); 00212 00213 /* try the COM class factory method of creation with default voice 00214 * playback device specified */ 00215 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, 00216 &IID_IDirectSound8, (void**)&dso); 00217 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound8) failed: %s\n", 00218 DXGetErrorString8(rc)); 00219 if (dso) 00220 IDirectSound8_test(dso, FALSE, &DSDEVID_DefaultVoicePlayback); 00221 00222 /* try the COM class factory method of creation with a bad 00223 * IID specified */ 00224 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, 00225 &CLSID_DirectSoundPrivate, (void**)&dso); 00226 ok(rc==E_NOINTERFACE, 00227 "CoCreateInstance(CLSID_DirectSound8,CLSID_DirectSoundPrivate) " 00228 "should have failed: %s\n",DXGetErrorString8(rc)); 00229 00230 /* try the COM class factory method of creation with a bad 00231 * GUID and IID specified */ 00232 rc=CoCreateInstance(&CLSID_DirectSoundPrivate, NULL, CLSCTX_INPROC_SERVER, 00233 &IID_IDirectSound8, (void**)&dso); 00234 ok(rc==REGDB_E_CLASSNOTREG, 00235 "CoCreateInstance(CLSID_DirectSoundPrivate,IID_IDirectSound8) " 00236 "should have failed: %s\n",DXGetErrorString8(rc)); 00237 00238 /* try with no device specified */ 00239 rc=pDirectSoundCreate8(NULL,&dso,NULL); 00240 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00241 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00242 if (rc==DS_OK && dso) 00243 IDirectSound8_test(dso, TRUE, NULL); 00244 00245 /* try with default playback device specified */ 00246 rc=pDirectSoundCreate8(&DSDEVID_DefaultPlayback,&dso,NULL); 00247 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00248 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00249 if (rc==DS_OK && dso) 00250 IDirectSound8_test(dso, TRUE, NULL); 00251 00252 /* try with default voice playback device specified */ 00253 rc=pDirectSoundCreate8(&DSDEVID_DefaultVoicePlayback,&dso,NULL); 00254 ok(rc==S_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00255 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00256 if (rc==DS_OK && dso) 00257 IDirectSound8_test(dso, TRUE, NULL); 00258 00259 /* try with a bad device specified */ 00260 rc=pDirectSoundCreate8(&DSDEVID_DefaultVoiceCapture,&dso,NULL); 00261 ok(rc==DSERR_NODRIVER,"DirectSoundCreate8(DSDEVID_DefaultVoiceCapture) " 00262 "should have failed: %s\n",DXGetErrorString8(rc)); 00263 } 00264 00265 static HRESULT test_dsound8(LPGUID lpGuid) 00266 { 00267 HRESULT rc; 00268 LPDIRECTSOUND8 dso=NULL; 00269 int ref; 00270 00271 /* DSOUND: Error: Invalid interface buffer */ 00272 rc=pDirectSoundCreate8(lpGuid,0,NULL); 00273 ok(rc==DSERR_INVALIDPARAM,"DirectSoundCreate8() should have returned " 00274 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00275 00276 /* Create the DirectSound8 object */ 00277 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00278 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED||rc==E_FAIL, 00279 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00280 if (rc!=DS_OK) 00281 return rc; 00282 00283 /* Try the enumerated device */ 00284 IDirectSound8_test(dso, TRUE, lpGuid); 00285 00286 /* Try the COM class factory method of creation with enumerated device */ 00287 rc=CoCreateInstance(&CLSID_DirectSound8, NULL, CLSCTX_INPROC_SERVER, 00288 &IID_IDirectSound8, (void**)&dso); 00289 ok(rc==S_OK,"CoCreateInstance(CLSID_DirectSound) failed: %s\n", 00290 DXGetErrorString8(rc)); 00291 if (dso) 00292 IDirectSound8_test(dso, FALSE, lpGuid); 00293 00294 /* Create a DirectSound8 object */ 00295 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00296 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00297 if (rc==DS_OK) { 00298 LPDIRECTSOUND8 dso1=NULL; 00299 00300 /* Create a second DirectSound8 object */ 00301 rc=pDirectSoundCreate8(lpGuid,&dso1,NULL); 00302 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00303 if (rc==DS_OK) { 00304 /* Release the second DirectSound8 object */ 00305 ref=IDirectSound8_Release(dso1); 00306 ok(ref==0,"IDirectSound8_Release() has %d references, " 00307 "should have 0\n",ref); 00308 ok(dso!=dso1,"DirectSound8 objects should be unique: " 00309 "dso=%p,dso1=%p\n",dso,dso1); 00310 } 00311 00312 /* Release the first DirectSound8 object */ 00313 ref=IDirectSound8_Release(dso); 00314 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n", 00315 ref); 00316 if (ref!=0) 00317 return DSERR_GENERIC; 00318 } else 00319 return rc; 00320 00321 /* Create a DirectSound8 object */ 00322 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00323 ok(rc==DS_OK,"DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00324 if (rc==DS_OK) { 00325 LPDIRECTSOUNDBUFFER secondary; 00326 DSBUFFERDESC bufdesc; 00327 WAVEFORMATEX wfx; 00328 00329 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,1); 00330 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00331 bufdesc.dwSize=sizeof(bufdesc); 00332 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_CTRL3D; 00333 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000, 00334 wfx.nBlockAlign); 00335 bufdesc.lpwfxFormat=&wfx; 00336 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); 00337 ok(rc==DS_OK && secondary!=NULL, 00338 "IDirectSound8_CreateSoundBuffer() failed to create a secondary " 00339 "buffer: %s\n",DXGetErrorString8(rc)); 00340 if (rc==DS_OK && secondary!=NULL) { 00341 LPDIRECTSOUND3DBUFFER buffer3d; 00342 LPDIRECTSOUNDBUFFER8 buffer8; 00343 rc=IDirectSound8_QueryInterface(secondary, 00344 &IID_IDirectSound3DBuffer, 00345 (void **)&buffer3d); 00346 ok(rc==DS_OK && buffer3d!=NULL, 00347 "IDirectSound8_QueryInterface() failed: %s\n", 00348 DXGetErrorString8(rc)); 00349 if (rc==DS_OK && buffer3d!=NULL) { 00350 ref=IDirectSound3DBuffer_AddRef(buffer3d); 00351 ok(ref==2,"IDirectSound3DBuffer_AddRef() has %d references, " 00352 "should have 2\n",ref); 00353 } 00354 rc=IDirectSound8_QueryInterface(secondary, 00355 &IID_IDirectSoundBuffer8, 00356 (void **)&buffer8); 00357 if (rc==DS_OK && buffer8!=NULL) { 00358 ref=IDirectSoundBuffer8_AddRef(buffer8); 00359 ok(ref==3,"IDirectSoundBuffer8_AddRef() has %d references, " 00360 "should have 3\n",ref); 00361 } 00362 ref=IDirectSoundBuffer_AddRef(secondary); 00363 ok(ref==4,"IDirectSoundBuffer_AddRef() has %d references, " 00364 "should have 4\n",ref); 00365 } 00366 /* release with buffer */ 00367 ref=IDirectSound8_Release(dso); 00368 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n", 00369 ref); 00370 if (ref!=0) 00371 return DSERR_GENERIC; 00372 } else 00373 return rc; 00374 00375 return DS_OK; 00376 } 00377 00378 static HRESULT test_primary8(LPGUID lpGuid) 00379 { 00380 HRESULT rc; 00381 LPDIRECTSOUND8 dso=NULL; 00382 LPDIRECTSOUNDBUFFER primary=NULL,second=NULL,third=NULL; 00383 DSBUFFERDESC bufdesc; 00384 DSCAPS dscaps; 00385 WAVEFORMATEX wfx; 00386 int ref; 00387 00388 /* Create the DirectSound object */ 00389 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00390 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED, 00391 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00392 if (rc!=DS_OK) 00393 return rc; 00394 00395 /* Get the device capabilities */ 00396 ZeroMemory(&dscaps, sizeof(dscaps)); 00397 dscaps.dwSize=sizeof(dscaps); 00398 rc=IDirectSound8_GetCaps(dso,&dscaps); 00399 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); 00400 if (rc!=DS_OK) 00401 goto EXIT; 00402 00403 /* DSOUND: Error: Invalid buffer description pointer */ 00404 rc=IDirectSound8_CreateSoundBuffer(dso,0,0,NULL); 00405 ok(rc==DSERR_INVALIDPARAM, 00406 "IDirectSound8_CreateSoundBuffer should have returned " 00407 "DSERR_INVALIDPARAM, returned: %s\n",DXGetErrorString8(rc)); 00408 00409 /* DSOUND: Error: Invalid buffer description pointer */ 00410 rc=IDirectSound8_CreateSoundBuffer(dso,0,&primary,NULL); 00411 ok(rc==DSERR_INVALIDPARAM && primary==0, 00412 "IDirectSound8_CreateSoundBuffer() should have returned " 00413 "DSERR_INVALIDPARAM, returned: rc=%s,dsbo=%p\n", 00414 DXGetErrorString8(rc),primary); 00415 00416 /* DSOUND: Error: Invalid buffer description pointer */ 00417 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,0,NULL); 00418 ok(rc==DSERR_INVALIDPARAM && primary==0, 00419 "IDirectSound8_CreateSoundBuffer() should have failed: rc=%s," 00420 "dsbo=%p\n",DXGetErrorString8(rc),primary); 00421 00422 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00423 00424 /* DSOUND: Error: Invalid size */ 00425 /* DSOUND: Error: Invalid buffer description */ 00426 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00427 ok(rc==DSERR_INVALIDPARAM && primary==0, 00428 "IDirectSound8_CreateSoundBuffer() should have failed: rc=%s," 00429 "primary=%p\n",DXGetErrorString8(rc),primary); 00430 00431 /* We must call SetCooperativeLevel before calling CreateSoundBuffer */ 00432 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00433 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00434 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00435 DXGetErrorString8(rc)); 00436 if (rc!=DS_OK) 00437 goto EXIT; 00438 00439 /* Testing the primary buffer */ 00440 primary=NULL; 00441 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00442 bufdesc.dwSize=sizeof(bufdesc); 00443 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME; 00444 bufdesc.lpwfxFormat = &wfx; 00445 init_format(&wfx,WAVE_FORMAT_PCM,11025,8,2); 00446 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00447 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() should have " 00448 "returned DSERR_INVALIDPARAM, returned: %s\n", DXGetErrorString8(rc)); 00449 if (rc==DS_OK && primary!=NULL) 00450 IDirectSoundBuffer_Release(primary); 00451 00452 primary=NULL; 00453 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00454 bufdesc.dwSize=sizeof(bufdesc); 00455 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER|DSBCAPS_CTRLVOLUME; 00456 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00457 ok((rc==DS_OK && primary!=NULL) || (rc==DSERR_CONTROLUNAVAIL), 00458 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer: " 00459 "%s\n",DXGetErrorString8(rc)); 00460 if (rc==DSERR_CONTROLUNAVAIL) 00461 trace(" No Primary\n"); 00462 else if (rc==DS_OK && primary!=NULL) { 00463 LONG vol; 00464 00465 /* Try to create a second primary buffer */ 00466 /* DSOUND: Error: The primary buffer already exists. 00467 * Any changes made to the buffer description will be ignored. */ 00468 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&second,NULL); 00469 ok(rc==DS_OK && second==primary, 00470 "IDirectSound8_CreateSoundBuffer() should have returned original " 00471 "primary buffer: %s\n",DXGetErrorString8(rc)); 00472 ref=IDirectSoundBuffer_Release(second); 00473 ok(ref==1,"IDirectSoundBuffer_Release() primary has %d references, " 00474 "should have 1\n",ref); 00475 00476 /* Try to duplicate a primary buffer */ 00477 /* DSOUND: Error: Can't duplicate primary buffers */ 00478 rc=IDirectSound8_DuplicateSoundBuffer(dso,primary,&third); 00479 /* rc=0x88780032 */ 00480 ok(rc!=DS_OK,"IDirectSound8_DuplicateSoundBuffer() primary buffer " 00481 "should have failed %s\n",DXGetErrorString8(rc)); 00482 00483 rc=IDirectSoundBuffer_GetVolume(primary,&vol); 00484 ok(rc==DS_OK,"IDirectSoundBuffer_GetVolume() failed: %s\n", 00485 DXGetErrorString8(rc)); 00486 00487 if (winetest_interactive) { 00488 trace("Playing a 5 seconds reference tone at the current volume.\n"); 00489 if (rc==DS_OK) 00490 trace("(the current volume is %ld according to DirectSound)\n", 00491 vol); 00492 trace("All subsequent tones should be identical to this one.\n"); 00493 trace("Listen for stutter, changes in pitch, volume, etc.\n"); 00494 } 00495 test_buffer8(dso,primary,1,FALSE,0,FALSE,0,winetest_interactive && 00496 !(dscaps.dwFlags & DSCAPS_EMULDRIVER),5.0,0,0,0,0); 00497 00498 ref=IDirectSoundBuffer_Release(primary); 00499 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00500 "should have 0\n",ref); 00501 } 00502 00503 /* Set the CooperativeLevel back to normal */ 00504 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00505 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00506 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00507 DXGetErrorString8(rc)); 00508 00509 EXIT: 00510 ref=IDirectSound8_Release(dso); 00511 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00512 if (ref!=0) 00513 return DSERR_GENERIC; 00514 00515 return rc; 00516 } 00517 00518 /* 00519 * Test the primary buffer at different formats while keeping the 00520 * secondary buffer at a constant format. 00521 */ 00522 static HRESULT test_primary_secondary8(LPGUID lpGuid) 00523 { 00524 HRESULT rc; 00525 LPDIRECTSOUND8 dso=NULL; 00526 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL; 00527 DSBUFFERDESC bufdesc; 00528 DSCAPS dscaps; 00529 WAVEFORMATEX wfx, wfx2; 00530 int ref; 00531 unsigned int f; 00532 00533 /* Create the DirectSound object */ 00534 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00535 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED, 00536 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00537 if (rc!=DS_OK) 00538 return rc; 00539 00540 /* Get the device capabilities */ 00541 ZeroMemory(&dscaps, sizeof(dscaps)); 00542 dscaps.dwSize=sizeof(dscaps); 00543 rc=IDirectSound8_GetCaps(dso,&dscaps); 00544 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); 00545 if (rc!=DS_OK) 00546 goto EXIT; 00547 00548 /* We must call SetCooperativeLevel before creating primary buffer */ 00549 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00550 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00551 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00552 DXGetErrorString8(rc)); 00553 if (rc!=DS_OK) 00554 goto EXIT; 00555 00556 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00557 bufdesc.dwSize=sizeof(bufdesc); 00558 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; 00559 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00560 ok(rc==DS_OK && primary!=NULL, 00561 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer " 00562 "%s\n",DXGetErrorString8(rc)); 00563 00564 if (rc==DS_OK && primary!=NULL) { 00565 for (f=0;f<NB_FORMATS;f++) { 00566 /* We must call SetCooperativeLevel to be allowed to call 00567 * SetFormat */ 00568 /* DSOUND: Setting DirectSound cooperative level to 00569 * DSSCL_PRIORITY */ 00570 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00571 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00572 DXGetErrorString8(rc)); 00573 if (rc!=DS_OK) 00574 goto EXIT; 00575 00576 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1], 00577 formats[f][2]); 00578 wfx2=wfx; 00579 rc=IDirectSoundBuffer_SetFormat(primary,&wfx); 00580 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat() failed: %s\n", 00581 DXGetErrorString8(rc)); 00582 00583 /* There is no garantee that SetFormat will actually change the 00584 * format to what we asked for. It depends on what the soundcard 00585 * supports. So we must re-query the format. 00586 */ 00587 rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL); 00588 ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %s\n", 00589 DXGetErrorString8(rc)); 00590 if (rc==DS_OK && 00591 (wfx.wFormatTag!=wfx2.wFormatTag || 00592 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec || 00593 wfx.wBitsPerSample!=wfx2.wBitsPerSample || 00594 wfx.nChannels!=wfx2.nChannels)) { 00595 trace("Requested primary format tag=0x%04x %ldx%dx%d " 00596 "avg.B/s=%ld align=%d\n", 00597 wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample, 00598 wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign); 00599 trace("Got tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n", 00600 wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample, 00601 wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign); 00602 } 00603 00604 /* Set the CooperativeLevel back to normal */ 00605 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00606 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00607 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00608 DXGetErrorString8(rc)); 00609 00610 init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2); 00611 00612 secondary=NULL; 00613 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00614 bufdesc.dwSize=sizeof(bufdesc); 00615 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 00616 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000, 00617 wfx.nBlockAlign); 00618 bufdesc.lpwfxFormat=&wfx2; 00619 if (winetest_interactive) { 00620 trace(" Testing a primary buffer at %ldx%dx%d with a " 00621 "secondary buffer at %ldx%dx%d\n", 00622 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels, 00623 wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels); 00624 } 00625 rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); 00626 ok(rc==DS_OK && secondary!=NULL, 00627 "IDirectSound_CreateSoundBuffer() failed to create a secondary " 00628 "buffer %s\n",DXGetErrorString8(rc)); 00629 00630 if (rc==DS_OK && secondary!=NULL) { 00631 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0, 00632 winetest_interactive,1.0,0,NULL,0,0); 00633 00634 ref=IDirectSoundBuffer_Release(secondary); 00635 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, " 00636 "should have 0\n",ref); 00637 } 00638 } 00639 00640 ref=IDirectSoundBuffer_Release(primary); 00641 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00642 "should have 0\n",ref); 00643 } 00644 00645 /* Set the CooperativeLevel back to normal */ 00646 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00647 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00648 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00649 DXGetErrorString8(rc)); 00650 00651 EXIT: 00652 ref=IDirectSound8_Release(dso); 00653 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00654 if (ref!=0) 00655 return DSERR_GENERIC; 00656 00657 return rc; 00658 } 00659 00660 static HRESULT test_secondary8(LPGUID lpGuid) 00661 { 00662 HRESULT rc; 00663 LPDIRECTSOUND8 dso=NULL; 00664 LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL; 00665 DSBUFFERDESC bufdesc; 00666 DSCAPS dscaps; 00667 WAVEFORMATEX wfx, wfx1; 00668 DWORD f; 00669 int ref; 00670 00671 /* Create the DirectSound object */ 00672 rc=pDirectSoundCreate8(lpGuid,&dso,NULL); 00673 ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED, 00674 "DirectSoundCreate8() failed: %s\n",DXGetErrorString8(rc)); 00675 if (rc!=DS_OK) 00676 return rc; 00677 00678 /* Get the device capabilities */ 00679 ZeroMemory(&dscaps, sizeof(dscaps)); 00680 dscaps.dwSize=sizeof(dscaps); 00681 rc=IDirectSound8_GetCaps(dso,&dscaps); 00682 ok(rc==DS_OK,"IDirectSound8_GetCaps() failed: %s\n",DXGetErrorString8(rc)); 00683 if (rc!=DS_OK) 00684 goto EXIT; 00685 00686 /* We must call SetCooperativeLevel before creating primary buffer */ 00687 /* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */ 00688 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY); 00689 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00690 DXGetErrorString8(rc)); 00691 if (rc!=DS_OK) 00692 goto EXIT; 00693 00694 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00695 bufdesc.dwSize=sizeof(bufdesc); 00696 bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER; 00697 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&primary,NULL); 00698 ok(rc==DS_OK && primary!=NULL, 00699 "IDirectSound8_CreateSoundBuffer() failed to create a primary buffer " 00700 "%s\n",DXGetErrorString8(rc)); 00701 00702 if (rc==DS_OK && primary!=NULL) { 00703 rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL); 00704 ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %s\n", 00705 DXGetErrorString8(rc)); 00706 if (rc!=DS_OK) 00707 goto EXIT1; 00708 00709 for (f=0;f<NB_FORMATS;f++) { 00710 init_format(&wfx,WAVE_FORMAT_PCM,formats[f][0],formats[f][1], 00711 formats[f][2]); 00712 secondary=NULL; 00713 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00714 bufdesc.dwSize=sizeof(bufdesc); 00715 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 00716 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000, 00717 wfx.nBlockAlign); 00718 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); 00719 ok(rc==DSERR_INVALIDPARAM,"IDirectSound8_CreateSoundBuffer() " 00720 "should have returned DSERR_INVALIDPARAM, returned: %s\n", 00721 DXGetErrorString8(rc)); 00722 if (rc==DS_OK && secondary!=NULL) 00723 IDirectSoundBuffer_Release(secondary); 00724 00725 secondary=NULL; 00726 ZeroMemory(&bufdesc, sizeof(bufdesc)); 00727 bufdesc.dwSize=sizeof(bufdesc); 00728 bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2; 00729 bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000, 00730 wfx.nBlockAlign); 00731 bufdesc.lpwfxFormat=&wfx; 00732 if (winetest_interactive) { 00733 trace(" Testing a secondary buffer at %ldx%dx%d " 00734 "with a primary buffer at %ldx%dx%d\n", 00735 wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels, 00736 wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels); 00737 } 00738 rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL); 00739 ok(rc==DS_OK && secondary!=NULL, 00740 "IDirectSound8_CreateSoundBuffer() failed to create a secondary " 00741 "buffer: %s\n",DXGetErrorString8(rc)); 00742 00743 if (rc==DS_OK && secondary!=NULL) { 00744 test_buffer8(dso,secondary,0,FALSE,0,FALSE,0, 00745 winetest_interactive,1.0,0,NULL,0,0); 00746 00747 ref=IDirectSoundBuffer_Release(secondary); 00748 ok(ref==0,"IDirectSoundBuffer_Release() has %d references, " 00749 "should have 0\n",ref); 00750 } 00751 } 00752 EXIT1: 00753 ref=IDirectSoundBuffer_Release(primary); 00754 ok(ref==0,"IDirectSoundBuffer_Release() primary has %d references, " 00755 "should have 0\n",ref); 00756 } 00757 00758 /* Set the CooperativeLevel back to normal */ 00759 /* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */ 00760 rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL); 00761 ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %s\n", 00762 DXGetErrorString8(rc)); 00763 00764 EXIT: 00765 ref=IDirectSound8_Release(dso); 00766 ok(ref==0,"IDirectSound8_Release() has %d references, should have 0\n",ref); 00767 if (ref!=0) 00768 return DSERR_GENERIC; 00769 00770 return rc; 00771 } 00772 00773 static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription, 00774 LPCSTR lpcstrModule, LPVOID lpContext) 00775 { 00776 HRESULT rc; 00777 trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule); 00778 rc = test_dsound8(lpGuid); 00779 if (rc == DSERR_NODRIVER) 00780 trace(" No Driver\n"); 00781 else if (rc == DSERR_ALLOCATED) 00782 trace(" Already In Use\n"); 00783 else if (rc == E_FAIL) 00784 trace(" No Device\n"); 00785 else { 00786 test_primary8(lpGuid); 00787 test_primary_secondary8(lpGuid); 00788 test_secondary8(lpGuid); 00789 } 00790 00791 return 1; 00792 } 00793 00794 static void dsound8_tests(void) 00795 { 00796 HRESULT rc; 00797 rc=DirectSoundEnumerateA(&dsenum_callback,NULL); 00798 ok(rc==DS_OK,"DirectSoundEnumerateA() failed: %s\n",DXGetErrorString8(rc)); 00799 } 00800 00801 const char * get_file_version(const char * file_name) 00802 { 00803 static char version[32]; 00804 DWORD size; 00805 DWORD handle; 00806 00807 size = GetFileVersionInfoSizeA("dsound.dll", &handle); 00808 if (size) { 00809 char * data = HeapAlloc(GetProcessHeap(), 0, size); 00810 if (data) { 00811 if (GetFileVersionInfoA("dsound.dll", handle, size, data)) { 00812 VS_FIXEDFILEINFO *pFixedVersionInfo; 00813 UINT len; 00814 if (VerQueryValueA(data, "\\", (LPVOID *)&pFixedVersionInfo, &len)) { 00815 sprintf(version, "%ld.%ld.%ld.%ld", 00816 pFixedVersionInfo->dwFileVersionMS >> 16, 00817 pFixedVersionInfo->dwFileVersionMS & 0xffff, 00818 pFixedVersionInfo->dwFileVersionLS >> 16, 00819 pFixedVersionInfo->dwFileVersionLS & 0xffff); 00820 } else 00821 sprintf(version, "not available"); 00822 } else 00823 sprintf(version, "failed"); 00824 00825 HeapFree(GetProcessHeap(), 0, data); 00826 } else 00827 sprintf(version, "failed"); 00828 } else 00829 sprintf(version, "not available"); 00830 00831 return version; 00832 } 00833 00834 START_TEST(dsound8) 00835 { 00836 HMODULE hDsound; 00837 00838 CoInitialize(NULL); 00839 00840 hDsound = LoadLibraryA("dsound.dll"); 00841 if (!hDsound) { 00842 trace("dsound.dll not found\n"); 00843 return; 00844 } 00845 00846 trace("DLL Version: %s\n", get_file_version("dsound.dll")); 00847 00848 pDirectSoundCreate8 = (void*)GetProcAddress(hDsound, "DirectSoundCreate8"); 00849 if (!pDirectSoundCreate8) { 00850 trace("dsound8 test skipped\n"); 00851 return; 00852 } 00853 00854 IDirectSound8_tests(); 00855 dsound8_tests(); 00856 00857 CoUninitialize(); 00858 } Generated on Sat May 26 2012 04:20:14 for ReactOS by
1.7.6.1
|