Commit a542770c authored by Francois Gouget's avatar Francois Gouget Committed by Alexandre Julliard

Extend the test by creating a PrimaryBuffer object and perform a few

basic tests such as querying its characteristics and changing its format. Changing the format requires that we call SetcooperativeLevel first, which means we need an hwnd. So the test must now link with user32.dll.
parent 78561f3e
......@@ -3,7 +3,7 @@ TOPOBJDIR = ../../..
SRCDIR = @srcdir@
VPATH = @srcdir@
TESTDLL = dsound.dll
IMPORTS = dsound kernel32
IMPORTS = dsound user32 kernel32
CTESTS = \
dsound.c
......
......@@ -27,29 +27,115 @@ BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
LPCSTR lpcstrModule, LPVOID lpContext)
{
HRESULT rc;
LPDIRECTSOUND dso;
LPDIRECTSOUND dso=NULL;
LPDIRECTSOUNDBUFFER dsbo=NULL;
DSCAPS dscaps;
DSBCAPS dsbcaps;
DSBUFFERDESC bufdesc;
WAVEFORMATEX wfx,wfx2;
DWORD size,status,freq;
winetest_trace("Testing %s - %s\n",lpcstrDescription,lpcstrModule);
trace("Testing %s - %s\n",lpcstrDescription,lpcstrModule);
rc=DirectSoundCreate(lpGuid,&dso,NULL);
ok(rc==DS_OK,"DirectSoundCreate failed: %lx\n",rc);
ok(rc==DS_OK,"DirectSoundCreate failed: 0x%lx\n",rc);
if (rc!=DS_OK)
goto EXIT;
dscaps.dwSize=0;
rc=IDirectSound_GetCaps(dso,&dscaps);
ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc);
dscaps.dwSize=sizeof(dscaps);
rc=IDirectSound_GetCaps(dso,&dscaps);
ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
if (rc==DS_OK) {
DSCAPS caps;
trace(" DirectSound Caps: flags=0x%08lx secondary min=%ld max=%ld\n",
dscaps.dwFlags,dscaps.dwMinSecondarySampleRate,
dscaps.dwMaxSecondarySampleRate);
}
caps.dwSize=0;
rc=IDirectSound_GetCaps(dso,&caps);
ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: %lx\n",rc);
/* Testing the primary buffers */
rc=IDirectSound_SetCooperativeLevel(dso,GetDesktopWindow(),DSSCL_PRIORITY);
ok(rc==DS_OK,"SetCooperativeLevel failed: 0x%lx\n",rc);
if (rc!=DS_OK)
goto EXIT;
caps.dwSize=sizeof(caps);
rc=IDirectSound_GetCaps(dso,&caps);
ok(rc==DS_OK,"GetCaps failed: %lx\n",rc);
if (rc==DS_OK) {
winetest_trace(" flags=%lx secondary min=%ld max=%ld\n",
caps.dwFlags,caps.dwMinSecondarySampleRate,
caps.dwMaxSecondarySampleRate);
}
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
bufdesc.dwBufferBytes=0;
bufdesc.dwReserved=0;
bufdesc.lpwfxFormat=NULL;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&dsbo,NULL);
ok(rc==DS_OK,"CreateSoundBuffer failed to create a primary buffer 0x%lx\n",rc);
if (rc!=DS_OK)
goto EXIT;
IDirectSound_Release(dso);
dsbcaps.dwSize=0;
rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
ok(rc==DSERR_INVALIDPARAM,"GetCaps should have failed: 0x%lx\n",rc);
dsbcaps.dwSize=sizeof(dsbcaps);
rc=IDirectSoundBuffer_GetCaps(dsbo,&dsbcaps);
ok(rc==DS_OK,"GetCaps failed: 0x%lx\n",rc);
if (rc==DS_OK) {
trace(" PrimaryBuffer Caps: flags=0x%08lx size=%ld\n",dsbcaps.dwFlags,dsbcaps.dwBufferBytes);
}
/* Query the format size. Note that it may not match sizeof(wfx) */
size=0;
rc=IDirectSoundBuffer_GetFormat(dsbo,NULL,0,&size);
ok(rc==DS_OK && size!=0,
"GetFormat should have returned the needed size: rc=0x%lx size=%ld\n",
rc,size);
rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
if (rc==DS_OK) {
trace(" tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
wfx.nAvgBytesPerSec,wfx.nBlockAlign);
}
rc=IDirectSoundBuffer_GetFrequency(dsbo,&freq);
ok(rc==DS_OK || rc==DSERR_CONTROLUNAVAIL,"GetFrequency failed: 0x%lx\n",rc);
if (rc==DS_OK) {
ok(freq==wfx.nSamplesPerSec,
"The frequency returned by GetFrequency %ld does not match the format %ld\n",
freq,wfx.nSamplesPerSec);
}
rc=IDirectSoundBuffer_GetStatus(dsbo,&status);
ok(rc==DS_OK,"GetStatus failed: 0x%lx\n",rc);
if (rc==DS_OK) {
trace(" status=0x%04lx\n",status);
}
wfx2.wFormatTag=WAVE_FORMAT_PCM;
wfx2.nChannels=2;
wfx2.wBitsPerSample=16;
wfx2.nSamplesPerSec=11025;
wfx2.nBlockAlign=wfx2.nChannels*wfx2.wBitsPerSample/8;
wfx2.nAvgBytesPerSec=wfx2.nSamplesPerSec*wfx2.nBlockAlign;
wfx2.cbSize=0;
rc=IDirectSoundBuffer_SetFormat(dsbo,&wfx2);
ok(rc==DS_OK,"SetFormat failed: 0x%lx\n",rc);
rc=IDirectSoundBuffer_GetFormat(dsbo,&wfx,sizeof(wfx),NULL);
ok(rc==DS_OK,"GetFormat failed: 0x%lx\n",rc);
if (rc==DS_OK) {
ok(wfx.wFormatTag==wfx2.wFormatTag && wfx.nChannels==wfx2.nChannels &&
wfx.wBitsPerSample==wfx2.wBitsPerSample && wfx.nSamplesPerSec==wfx2.nSamplesPerSec &&
wfx.nBlockAlign==wfx2.nBlockAlign && wfx.nAvgBytesPerSec==wfx2.nAvgBytesPerSec,
"SetFormat did not work right: tag=0x%04x %ldx%dx%d avg.B/s=%ld align=%d\n",
wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
wfx.nAvgBytesPerSec,wfx.nBlockAlign);
}
EXIT:
if (dsbo!=NULL)
IDirectSoundBuffer_Release(dsbo);
if (dso!=NULL)
IDirectSound_Release(dso);
return 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment