dsound/tests: Add tests to check notifications after duplicate.

This commit is contained in:
Akihiro Sagawa 2011-07-21 21:53:43 +09:00 committed by Alexandre Julliard
parent adf1310f4a
commit 223406fa17
1 changed files with 186 additions and 0 deletions

View File

@ -1039,6 +1039,191 @@ EXIT:
return rc;
}
static HRESULT test_notify(LPDIRECTSOUNDBUFFER dsb,
DWORD count, LPHANDLE event,
DWORD expected)
{
HRESULT rc;
DWORD ret;
rc=IDirectSoundBuffer_SetCurrentPosition(dsb,0);
ok(rc==DS_OK,
"IDirectSoundBuffer_SetCurrentPosition failed %08x\n",rc);
if(rc!=DS_OK)
return rc;
rc=IDirectSoundBuffer_Play(dsb,0,0,0);
ok(rc==DS_OK,"IDirectSoundBuffer_Play failed %08x\n",rc);
if(rc!=DS_OK)
return rc;
rc=IDirectSoundBuffer_Stop(dsb);
ok(rc==DS_OK,"IDirectSoundBuffer_Stop failed %08x\n",rc);
if(rc!=DS_OK)
return rc;
ret=WaitForMultipleObjects(count,event,FALSE,0);
if (expected != WAIT_OBJECT_0+1) {
todo_wine
ok(ret==expected,"expected %d. got %d\n",expected,ret);
}
else
ok(ret==expected,"expected %d. got %d\n",expected,ret);
return rc;
}
static HRESULT test_duplicate(LPGUID lpGuid)
{
HRESULT rc;
LPDIRECTSOUND dso=NULL;
LPDIRECTSOUNDBUFFER primary=NULL;
DSBUFFERDESC bufdesc;
int ref;
/* Create the DirectSound object */
rc=pDirectSoundCreate(lpGuid,&dso,NULL);
ok(rc==DS_OK||rc==DSERR_NODRIVER||rc==DSERR_ALLOCATED,
"DirectSoundCreate() failed: %08x\n",rc);
if (rc!=DS_OK)
return rc;
/* We must call SetCooperativeLevel before creating primary buffer */
/* DSOUND: Setting DirectSound cooperative level to DSSCL_PRIORITY */
rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_PRIORITY);
ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
if (rc!=DS_OK)
goto EXIT;
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_PRIMARYBUFFER;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&primary,NULL);
ok(rc==DS_OK && primary!=NULL,"IDirectSound_CreateSoundBuffer() failed "
"to create a primary buffer %08x\n",rc);
if (rc==DS_OK && primary!=NULL) {
LPDIRECTSOUNDBUFFER original=NULL;
WAVEFORMATEX wfx;
init_format(&wfx,WAVE_FORMAT_PCM,22050,16,1);
ZeroMemory(&bufdesc, sizeof(bufdesc));
bufdesc.dwSize=sizeof(bufdesc);
bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_CTRLPOSITIONNOTIFY;
bufdesc.dwBufferBytes=wfx.nAvgBytesPerSec/100; /* very short buffer */
bufdesc.lpwfxFormat=&wfx;
rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&original,NULL);
ok(rc==DS_OK && original!=NULL,
"IDirectSound_CreateSoundBuffer() failed to create a original "
"buffer %08x\n",rc);
if (rc==DS_OK && original!=NULL) {
LPDIRECTSOUNDBUFFER duplicated=NULL;
LPDIRECTSOUNDNOTIFY notify=NULL;
HANDLE event[2];
LPVOID buf=NULL;
DWORD bufsize;
int i;
/* Prepare notify events */
for (i=0;i<sizeof(event)/sizeof(event[0]);i++) {
event[i] = CreateEvent(NULL,FALSE,FALSE,NULL);
}
/* Make silent buffer */
rc=IDirectSoundBuffer_Lock(original,0,0,&buf,&bufsize,
NULL,NULL,DSBLOCK_ENTIREBUFFER);
ok(rc==DS_OK && buf!=NULL,
"IDirectSoundBuffer_Lock failed to lock the buffer %08x\n",rc);
if (rc==DS_OK && buf!=NULL) {
ZeroMemory(buf,bufsize);
rc=IDirectSoundBuffer_Unlock(original,buf,bufsize,
NULL,0);
ok(rc==DS_OK,"IDirectSoundBuffer_Unlock failed to unlock "
"%08x\n",rc);
}
rc=IDirectSoundBuffer_QueryInterface(original,
&IID_IDirectSoundNotify,
(void**)&notify);
ok(rc==DS_OK && notify!=NULL,
"IDirectSoundBuffer_QueryInterface() failed to create a "
"notification %08x\n",rc);
if (rc==DS_OK && notify!=NULL) {
DSBPOSITIONNOTIFY dsbpn;
LPDIRECTSOUNDNOTIFY dup_notify=NULL;
dsbpn.dwOffset=DSBPN_OFFSETSTOP;
dsbpn.hEventNotify=event[0];
rc=IDirectSoundNotify_SetNotificationPositions(notify,
1,&dsbpn);
ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions "
"failed %08x\n",rc);
rc=IDirectSound_DuplicateSoundBuffer(dso,original,&duplicated);
ok(rc==DS_OK && duplicated!=NULL,
"IDirectSound_DuplicateSoundBuffer failed %08x\n",rc);
trace("testing duplicated buffer without notifications.\n");
test_notify(duplicated,sizeof(event)/sizeof(event[0]),
event,WAIT_TIMEOUT);
rc=IDirectSoundBuffer_QueryInterface(duplicated,
&IID_IDirectSoundNotify,
(void**)&dup_notify);
ok(rc==DS_OK&&dup_notify!=NULL,
"IDirectSoundBuffer_QueryInterface() failed to create a "
"notification %08x\n",rc);
if(rc==DS_OK&&dup_notify!=NULL) {
dsbpn.dwOffset=DSBPN_OFFSETSTOP;
dsbpn.hEventNotify=event[1];
rc=IDirectSoundNotify_SetNotificationPositions(dup_notify,
1,&dsbpn);
ok(rc==DS_OK,"IDirectSoundNotify_SetNotificationPositions "
"failed %08x\n",rc);
trace("testing duplicated buffer with a notification.\n");
test_notify(duplicated,sizeof(event)/sizeof(event[0]),
event,WAIT_OBJECT_0+1);
ref=IDirectSoundNotify_Release(dup_notify);
todo_wine
ok(ref==0,"IDirectSoundNotify_Release() has %d references, "
"should have 0\n",ref);
}
ref=IDirectSoundNotify_Release(notify);
ok(ref==0,"IDirectSoundNotify_Release() has %d references, "
"should have 0\n",ref);
trace("testing original buffer with a notification.\n");
test_notify(original,sizeof(event)/sizeof(event[0]),
event,WAIT_OBJECT_0);
ref=IDirectSoundBuffer_Release(duplicated);
ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
"should have 0\n",ref);
}
ref=IDirectSoundBuffer_Release(original);
ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
"should have 0\n",ref);
}
ref=IDirectSoundBuffer_Release(primary);
ok(ref==0,"IDirectSoundBuffer_Release() has %d references, "
"should have 0\n",ref);
}
/* Set the CooperativeLevel back to normal */
/* DSOUND: Setting DirectSound cooperative level to DSSCL_NORMAL */
rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
EXIT:
ref=IDirectSound_Release(dso);
ok(ref==0,"IDirectSound_Release() has %d references, should have 0\n",ref);
if (ref!=0)
return DSERR_GENERIC;
return rc;
}
static unsigned int number;
static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
@ -1067,6 +1252,7 @@ static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription,
test_primary_secondary(lpGuid);
test_secondary(lpGuid);
test_frequency(lpGuid);
test_duplicate(lpGuid);
}
return 1;