More DSound tests

Francois Gouget fgouget at codeweavers.com
Thu Dec 12 20:36:03 CST 2002


IDirectSoundBuffer.GetCaps is supposed to fail if caps.dwSize is not 
set. It says so in the documentation and does on Windows so I added a 
check for it and I fixed Wine's implementation (trivial fix).
I also added a couple other checks accessing the primary buffer and 
querying its capabilities, changing the format and stuff like that.
The thing is that to change the format of the primary buffer one must 
call SetCooperativeLevel first which requires to provide an hwnd. The 
documentation says to use GetDesktopWindow() if you don't have a window 
you can call your own so that is what I did. However it still means that 
the dsound test now has to link with user32.dll! Oh well.


Changelog:

    Francois Gouget <fgouget at codeweavers.com>

  * dlls/dsound/buffer.c,
    dlls/dsound/primary.c

    IDirectoSoundBuffer.GetCaps should fail if caps.dwSize is not set

  * dlls/dsound/tests/Makefile.in,
    dlls/dsound/tests/dsound.c

    Extend the test by creating a PrimaryBuffer object and perform a few 
basic stests 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.

-- 
Francois Gouget
fgouget at codeweavers.com

-------------- next part --------------
Index: dlls/dsound/buffer.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/buffer.c,v
retrieving revision 1.3
diff -u -r1.3 buffer.c
--- dlls/dsound/buffer.c	12 Sep 2002 22:07:02 -0000	1.3
+++ dlls/dsound/buffer.c	13 Dec 2002 02:20:43 -0000
@@ -766,13 +766,9 @@
 	ICOM_THIS(IDirectSoundBufferImpl,iface);
   	TRACE("(%p)->(%p)\n",This,caps);
 
-	if (caps == NULL)
+	if (caps == NULL || caps->dwSize!=sizeof(*caps))
 		return DSERR_INVALIDPARAM;
 
-	/* I think we should check this value, not set it. See */
-	/* Inside DirectX, p215. That should apply here, too. */
-	caps->dwSize = sizeof(*caps);
-
 	caps->dwFlags = This->dsbd.dwFlags;
 	if (This->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
 	else caps->dwFlags |= DSBCAPS_LOCSOFTWARE;
Index: dlls/dsound/primary.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/primary.c,v
retrieving revision 1.3
diff -u -r1.3 primary.c
--- dlls/dsound/primary.c	12 Sep 2002 22:07:02 -0000	1.3
+++ dlls/dsound/primary.c	13 Dec 2002 02:20:47 -0000
@@ -754,12 +766,8 @@
 	ICOM_THIS(PrimaryBufferImpl,iface);
   	TRACE("(%p)->(%p)\n",This,caps);
 
-	if (caps == NULL)
+	if (caps == NULL || caps->dwSize!=sizeof(*caps))
 		return DSERR_INVALIDPARAM;
-
-	/* I think we should check this value, not set it. See */
-	/* Inside DirectX, p215. That should apply here, too. */
-	caps->dwSize = sizeof(*caps);
 
 	caps->dwFlags = This->dsbd.dwFlags;
 	if (This->dsound->hwbuf) caps->dwFlags |= DSBCAPS_LOCHARDWARE;
Index: dlls/dsound/tests/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/Makefile.in,v
retrieving revision 1.1
diff -u -r1.1 Makefile.in
--- dlls/dsound/tests/Makefile.in	5 Dec 2002 19:19:41 -0000	1.1
+++ dlls/dsound/tests/Makefile.in	13 Dec 2002 02:20:47 -0000
@@ -3,7 +3,7 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 TESTDLL   = dsound.dll
-IMPORTS   = dsound kernel32
+IMPORTS   = dsound kernel32 user32
 
 CTESTS = \
 	dsound.c
Index: dlls/dsound/tests/dsound.c
===================================================================
RCS file: /home/wine/wine/dlls/dsound/tests/dsound.c,v
retrieving revision 1.1
diff -u -r1.1 dsound.c
--- dlls/dsound/tests/dsound.c	5 Dec 2002 19:19:41 -0000	1.1
+++ dlls/dsound/tests/dsound.c	13 Dec 2002 02:20:47 -0000
@@ -21,35 +21,125 @@
 #include "wine/test.h"
 #include "dsound.h"
 
+/* Winelib does not support importing variables so we have to define
+ * our own here
+ */
+const GUID MY_GUID_NULL = { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } };
 
 
 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);
-
-        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);
-        }
+    /* 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;
+
+    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;
+
+    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);
+    }
 
-        IDirectSound_Release(dso);
+    /* 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;
 }
 


More information about the wine-patches mailing list