dsound/tests: Make dsound tests call GetFormat() correctly

Donny Yang xiao.tai.lang.de.email at gmail.com
Fri Jul 13 02:51:04 CDT 2012


GetFormat() was originally called with a buffer size of WAVEFORMATEX,
but this is not correct because it can also be larger than it such as
in the case of a WAVEFORMATEXTENSIBLE. This patch fixes it so
GetFormat() correctly gets called first with an NULL buffer to get the
required size, then allocating enough memory to get the entire buffer.
-------------- next part --------------
From 4ccf5367537022ebe46aeeb1466d327faec3bbd2 Mon Sep 17 00:00:00 2001
From: Donny Yang <xiao.tai.lang.de.email at gmail.com>
Date: Fri, 13 Jul 2012 15:24:32 +1000
Subject: dsound/tests: Make dsound tests call GetFormat() correctly

---
 dlls/dsound/tests/ds3d.c    |   85 ++++++++++++++++++++++---------------------
 dlls/dsound/tests/ds3d8.c   |   78 ++++++++++++++++++++-------------------
 dlls/dsound/tests/dsound.c  |   71 +++++++++++++++++++++++-------------
 dlls/dsound/tests/dsound8.c |   58 ++++++++++++++++++-----------
 4 files changed, 167 insertions(+), 125 deletions(-)

diff --git a/dlls/dsound/tests/ds3d.c b/dlls/dsound/tests/ds3d.c
index 86099bf..7689c57 100644
--- a/dlls/dsound/tests/ds3d.c
+++ b/dlls/dsound/tests/ds3d.c
@@ -330,7 +330,7 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
 {
     HRESULT rc;
     DSBCAPS dsbcaps;
-    WAVEFORMATEX wfx,wfx2;
+    WAVEFORMATEX wfx,*pwfx;
     DWORD size,status,freq;
     BOOL ieee = FALSE;
     int ref;
@@ -368,28 +368,20 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
     rc=IDirectSoundBuffer_GetFormat(*dsbo,NULL,0,&size);
     ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
        "returned the needed size: rc=%08x size=%d\n",rc,size);
-
     ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
        "Expected a correct structure size, got %d\n", size);
-
-    if (size == sizeof(WAVEFORMATEX)) {
-        rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,size,NULL);
-        ieee = (wfx.wFormatTag == WAVE_FORMAT_IEEE_FLOAT);
-    }
-    else if (size == sizeof(WAVEFORMATEXTENSIBLE)) {
-        WAVEFORMATEXTENSIBLE wfxe;
-        rc=IDirectSoundBuffer_GetFormat(*dsbo,(WAVEFORMATEX*)&wfxe,size,NULL);
-        wfx = wfxe.Format;
-        ieee = IsEqualGUID(&wfxe.SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
-    }
-    ok(rc==DS_OK,
-        "IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
+    pwfx=HeapAlloc(GetProcessHeap(),0,size);
+    rc=IDirectSoundBuffer_GetFormat(*dsbo,pwfx,size,NULL);
+    ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n",rc);
     if (rc==DS_OK && winetest_debug > 1) {
         trace("    Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
               is_primary ? "Primary" : "Secondary",
-              wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
-              wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
+              pwfx->wFormatTag,pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
+              pwfx->nChannels,pwfx->nAvgBytesPerSec,pwfx->nBlockAlign);
     }
+    ieee = (pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) ||
+           (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
+           IsEqualGUID(&((WAVEFORMATEXTENSIBLE*)pwfx)->SubFormat,&KSDATAFORMAT_SUBTYPE_IEEE_FLOAT));
 
     /* DSOUND: Error: Invalid frequency buffer */
     rc=IDirectSoundBuffer_GetFrequency(*dsbo,0);
@@ -402,7 +394,7 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
        (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
        "IDirectSoundBuffer_GetFrequency() failed: %08x\n",rc);
     if (rc==DS_OK) {
-        DWORD f = set_frequency?frequency:wfx.nSamplesPerSec;
+        DWORD f = set_frequency?frequency:pwfx->nSamplesPerSec;
         ok(freq==f,"The frequency returned by GetFrequency "
            "%d does not match the format %d\n",freq,f);
     }
@@ -430,28 +422,28 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
         ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have "
            "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
 
-        init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
-        rc=IDirectSoundBuffer_SetFormat(*dsbo,&wfx2);
+        init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
+        rc=IDirectSoundBuffer_SetFormat(*dsbo,&wfx);
         ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
-           format_string(&wfx2), rc);
+           format_string(&wfx), rc);
 
         /* There is no guarantee that SetFormat will actually change the
-	 * format to what we asked for. It depends on what the soundcard
-	 * supports. So we must re-query the format.
-	 */
-        rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,sizeof(wfx),NULL);
+	     * format to what we asked for. It depends on what the soundcard
+	     * supports. So we must re-query the format.
+	     */
+        rc=IDirectSoundBuffer_GetFormat(*dsbo,pwfx,size,NULL);
         ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
         if (rc==DS_OK &&
-            (wfx.wFormatTag!=wfx2.wFormatTag ||
-             wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
-             wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
-             wfx.nChannels!=wfx2.nChannels)) {
+            (pwfx->wFormatTag!=wfx.wFormatTag ||
+             pwfx->nSamplesPerSec!=wfx.nSamplesPerSec ||
+             pwfx->wBitsPerSample!=wfx.wBitsPerSample ||
+             pwfx->nChannels!=wfx.nChannels)) {
             trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
-                  wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
-                  wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
-            trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
                   wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
                   wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
+            trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
+                  pwfx->wFormatTag,pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
+                  pwfx->nChannels,pwfx->nAvgBytesPerSec,pwfx->nBlockAlign);
         }
 
         ZeroMemory(&new_dsbcaps, sizeof(new_dsbcaps));
@@ -495,11 +487,11 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
             if (set_frequency)
                 trace("    Playing %g second 440Hz tone at %dx%dx%d with a "
                       "frequency of %d (%dHz)\n", duration,
-                      wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels,
-                      frequency, (440 * frequency) / wfx.nSamplesPerSec);
+                      pwfx->nSamplesPerSec, pwfx->wBitsPerSample, pwfx->nChannels,
+                      frequency, (440 * frequency) / pwfx->nSamplesPerSec);
             else
                 trace("    Playing %g second 440Hz tone at %dx%dx%d\n", duration,
-                      wfx.nSamplesPerSec, wfx.wBitsPerSample, wfx.nChannels);
+                      pwfx->nSamplesPerSec, pwfx->wBitsPerSample, pwfx->nChannels);
         }
 
         if (is_primary) {
@@ -618,12 +610,12 @@ void test_buffer(LPDIRECTSOUND dso, LPDIRECTSOUNDBUFFER *dsbo,
            "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
 
         if (set_frequency)
-            state.wave=wave_generate_la(&wfx,(duration*frequency)/wfx.nSamplesPerSec,&state.wave_len,ieee);
+            state.wave=wave_generate_la(pwfx,(duration*frequency)/pwfx->nSamplesPerSec,&state.wave_len,ieee);
         else
-            state.wave=wave_generate_la(&wfx,duration,&state.wave_len,ieee);
+            state.wave=wave_generate_la(pwfx,duration,&state.wave_len,ieee);
 
         state.dsbo=*dsbo;
-        state.wfx=&wfx;
+        state.wfx=pwfx;
         state.buffer_size=dsbcaps.dwBufferBytes;
         state.played=state.written=state.offset=0;
         buffer_refill(&state,state.buffer_size);
@@ -718,7 +710,8 @@ static HRESULT test_secondary(LPGUID lpGuid, int play,
     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
     LPDIRECTSOUND3DLISTENER listener=NULL;
     DSBUFFERDESC bufdesc;
-    WAVEFORMATEX wfx, wfx1;
+    WAVEFORMATEX wfx, *pwfx;
+    DWORD size;
     int ref;
 
     /* Create the DirectSound object */
@@ -747,11 +740,19 @@ static HRESULT test_secondary(LPGUID lpGuid, int play,
     if (rc==DSERR_CONTROLUNAVAIL)
         trace("  No Primary\n");
     else if (rc==DS_OK && primary!=NULL) {
-        rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
+        size=0;
+        rc=IDirectSoundBuffer_GetFormat(primary,NULL,0,&size);
+        ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
+           "returned the needed size: rc=%08x size=%d\n",rc,size);
+        ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
+           "Expected a correct structure size, got %d\n", size);
+        if (rc!=DS_OK || size==0 || (size!=sizeof(WAVEFORMATEX) && size!=sizeof(WAVEFORMATEXTENSIBLE)))
+            goto EXIT1;
+        pwfx=HeapAlloc(GetProcessHeap(),0,size);
+        rc=IDirectSoundBuffer_GetFormat(primary,pwfx,size,NULL);
         ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
         if (rc!=DS_OK)
             goto EXIT1;
-
         if (has_listener) {
             rc=IDirectSoundBuffer_QueryInterface(primary,
                                                  &IID_IDirectSound3DListener,
@@ -820,7 +821,7 @@ static HRESULT test_secondary(LPGUID lpGuid, int play,
                   listener&&move_sound?"and moving sound ":move_sound?
                   "moving sound ":"",
                   wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
-                  wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
+                  pwfx->nSamplesPerSec,pwfx->wBitsPerSample,pwfx->nChannels);
         }
         rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
         ok((rc==DS_OK && secondary!=NULL) || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
diff --git a/dlls/dsound/tests/ds3d8.c b/dlls/dsound/tests/ds3d8.c
index 41de792..6e5287d 100644
--- a/dlls/dsound/tests/ds3d8.c
+++ b/dlls/dsound/tests/ds3d8.c
@@ -181,7 +181,7 @@ void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
 {
     HRESULT rc;
     DSBCAPS dsbcaps;
-    WAVEFORMATEX wfx,wfx2;
+    WAVEFORMATEX wfx,*pwfx;
     DWORD size,status,freq;
     BOOL ieee = FALSE;
     int ref;
@@ -211,26 +211,20 @@ void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
     rc=IDirectSoundBuffer_GetFormat(*dsbo,NULL,0,&size);
     ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
        "returned the needed size: rc=%08x size=%d\n",rc,size);
-
     ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
        "Expected a correct structure size, got %d\n", size);
-
-    if (size == sizeof(WAVEFORMATEX)) {
-        rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,size,NULL);
-        ieee = (wfx.wFormatTag == WAVE_FORMAT_IEEE_FLOAT);
-    } else if (size == sizeof(WAVEFORMATEXTENSIBLE)) {
-        WAVEFORMATEXTENSIBLE wfxe;
-        rc=IDirectSoundBuffer_GetFormat(*dsbo,(WAVEFORMATEX*)&wfxe,size,NULL);
-        wfx = wfxe.Format;
-        ieee = IsEqualGUID(&wfxe.SubFormat, &KSDATAFORMAT_SUBTYPE_IEEE_FLOAT);
-    }
-    ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
+    pwfx=HeapAlloc(GetProcessHeap(),0,size);
+    rc=IDirectSoundBuffer_GetFormat(*dsbo,pwfx,size,NULL);
+    ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n",rc);
     if (rc==DS_OK && winetest_debug > 1) {
         trace("    Format: %s tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
               is_primary ? "Primary" : "Secondary",
-              wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
-              wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
+              pwfx->wFormatTag,pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
+              pwfx->nChannels,pwfx->nAvgBytesPerSec,pwfx->nBlockAlign);
     }
+    ieee = (pwfx->wFormatTag == WAVE_FORMAT_IEEE_FLOAT) ||
+           (pwfx->wFormatTag == WAVE_FORMAT_EXTENSIBLE &&
+           IsEqualGUID(&((WAVEFORMATEXTENSIBLE*)pwfx)->SubFormat,&KSDATAFORMAT_SUBTYPE_IEEE_FLOAT));
 
     /* DSOUND: Error: Invalid frequency buffer */
     rc=IDirectSoundBuffer_GetFrequency(*dsbo,0);
@@ -243,8 +237,8 @@ void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
        (rc==DSERR_CONTROLUNAVAIL&&!(dsbcaps.dwFlags&DSBCAPS_CTRLFREQUENCY)),
        "IDirectSoundBuffer_GetFrequency() failed: %08x\n",rc);
     if (rc==DS_OK) {
-        ok(freq==wfx.nSamplesPerSec,"The frequency returned by GetFrequency "
-           "%d does not match the format %d\n",freq,wfx.nSamplesPerSec);
+        ok(freq==pwfx->nSamplesPerSec,"The frequency returned by GetFrequency "
+           "%d does not match the format %d\n",freq,pwfx->nSamplesPerSec);
     }
 
     /* DSOUND: Error: Invalid status pointer */
@@ -271,28 +265,28 @@ void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
         ok(rc==DSERR_INVALIDPARAM,"IDirectSoundBuffer_SetFormat() should have "
            "returned DSERR_INVALIDPARAM, returned: %08x\n",rc);
 
-        init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
-        rc=IDirectSoundBuffer_SetFormat(*dsbo,&wfx2);
+        init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
+        rc=IDirectSoundBuffer_SetFormat(*dsbo,&wfx);
         ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
-           format_string(&wfx2), rc);
+           format_string(&wfx), rc);
 
         /* There is no guarantee that SetFormat will actually change the
-	 * format to what we asked for. It depends on what the soundcard
-	 * supports. So we must re-query the format.
-	 */
-        rc=IDirectSoundBuffer_GetFormat(*dsbo,&wfx,sizeof(wfx),NULL);
+	     * format to what we asked for. It depends on what the soundcard
+	     * supports. So we must re-query the format.
+	     */
+        rc=IDirectSoundBuffer_GetFormat(*dsbo,pwfx,size,NULL);
         ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
         if (rc==DS_OK &&
-            (wfx.wFormatTag!=wfx2.wFormatTag ||
-             wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
-             wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
-             wfx.nChannels!=wfx2.nChannels)) {
+            (pwfx->wFormatTag!=wfx.wFormatTag ||
+             pwfx->nSamplesPerSec!=wfx.nSamplesPerSec ||
+             pwfx->wBitsPerSample!=wfx.wBitsPerSample ||
+             pwfx->nChannels!=wfx.nChannels)) {
             trace("Requested format tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
-                  wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
-                  wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
-            trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
                   wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
                   wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
+            trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
+                  pwfx->wFormatTag,pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
+                  pwfx->nChannels,pwfx->nAvgBytesPerSec,pwfx->nBlockAlign);
         }
 
         ZeroMemory(&new_dsbcaps, sizeof(new_dsbcaps));
@@ -335,7 +329,7 @@ void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
 
         if (winetest_interactive) {
             trace("    Playing %g second 440Hz tone at %dx%dx%d\n", duration,
-                  wfx.nSamplesPerSec, wfx.wBitsPerSample,wfx.nChannels);
+                  pwfx->nSamplesPerSec, pwfx->wBitsPerSample,pwfx->nChannels);
         }
 
         if (is_primary) {
@@ -452,10 +446,10 @@ void test_buffer8(LPDIRECTSOUND8 dso, LPDIRECTSOUNDBUFFER * dsbo,
         ok(rc==DSERR_INVALIDPARAM, "IDirectSoundBuffer_Lock() should have "
            "returned DSERR_INVALIDPARAM, returned %08x\n", rc);
 
-        state.wave=wave_generate_la(&wfx,duration,&state.wave_len,ieee);
+        state.wave=wave_generate_la(pwfx,duration,&state.wave_len,ieee);
 
         state.dsbo=*dsbo;
-        state.wfx=&wfx;
+        state.wfx=pwfx;
         state.buffer_size=dsbcaps.dwBufferBytes;
         state.played=state.written=state.offset=0;
         buffer_refill8(&state,state.buffer_size);
@@ -549,7 +543,8 @@ static HRESULT test_secondary8(LPGUID lpGuid, int play,
     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
     LPDIRECTSOUND3DLISTENER listener=NULL;
     DSBUFFERDESC bufdesc;
-    WAVEFORMATEX wfx, wfx1;
+    WAVEFORMATEX wfx, *pwfx;
+    DWORD size;
     int ref;
 
     /* Create the DirectSound object */
@@ -578,7 +573,16 @@ static HRESULT test_secondary8(LPGUID lpGuid, int play,
     if (rc == DSERR_CONTROLUNAVAIL)
         trace("  No Primary\n");
     else if (rc==DS_OK && primary!=NULL) {
-        rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
+        size=0;
+        rc=IDirectSoundBuffer_GetFormat(primary,NULL,0,&size);
+        ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
+           "returned the needed size: rc=%08x size=%d\n",rc,size);
+        ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
+           "Expected a correct structure size, got %d\n", size);
+        if (rc!=DS_OK || size==0 || (size!=sizeof(WAVEFORMATEX) && size!=sizeof(WAVEFORMATEXTENSIBLE)))
+            goto EXIT1;
+        pwfx=HeapAlloc(GetProcessHeap(),0,size);
+        rc=IDirectSoundBuffer_GetFormat(primary,pwfx,size,NULL);
         ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
         if (rc!=DS_OK)
             goto EXIT1;
@@ -666,7 +670,7 @@ static HRESULT test_secondary8(LPGUID lpGuid, int play,
                   listener&&move_sound?"and moving sound ":move_sound?
                   "moving sound ":"",
                   wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
-                  wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
+                  pwfx->nSamplesPerSec,pwfx->wBitsPerSample,pwfx->nChannels);
         }
         rc=IDirectSound8_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
         ok(rc==DS_OK && secondary!=NULL,"IDirectSound8_CreateSoundBuffer() "
diff --git a/dlls/dsound/tests/dsound.c b/dlls/dsound/tests/dsound.c
index 4c46f67..74cee0d 100644
--- a/dlls/dsound/tests/dsound.c
+++ b/dlls/dsound/tests/dsound.c
@@ -531,7 +531,8 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
     DSBUFFERDESC bufdesc;
     DSCAPS dscaps;
-    WAVEFORMATEX wfx, wfx2;
+    WAVEFORMATEX wfx, *pwfx;
+    DWORD size;
     int f,ref,tag;
 
     /* Create the DirectSound object */
@@ -581,9 +582,7 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
 
             init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
                         formats[f][2]);
-            wfx2=wfx;
             rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
-
             if (wfx.wBitsPerSample <= 16)
                 ok(rc==DS_OK,"IDirectSoundBuffer_SetFormat(%s) failed: %08x\n",
                    format_string(&wfx), rc);
@@ -595,20 +594,27 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
              * format to what we asked for. It depends on what the soundcard
              * supports. So we must re-query the format.
              */
-            rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
+            size=0;
+            rc=IDirectSoundBuffer_GetFormat(primary,NULL,0,&size);
+            ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
+               "returned the needed size: rc=%08x size=%d\n",rc,size);
+            ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
+               "Expected a correct structure size, got %d\n", size);
+            pwfx=HeapAlloc(GetProcessHeap(),0,size);
+            rc=IDirectSoundBuffer_GetFormat(primary,pwfx,size,NULL);
             ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
             if (rc==DS_OK &&
-                (wfx.wFormatTag!=wfx2.wFormatTag ||
-                 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
-                 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
-                 wfx.nChannels!=wfx2.nChannels)) {
+                (pwfx->wFormatTag!=wfx.wFormatTag ||
+                 pwfx->nSamplesPerSec!=wfx.nSamplesPerSec ||
+                 pwfx->wBitsPerSample!=wfx.wBitsPerSample ||
+                 pwfx->nChannels!=wfx.nChannels)) {
                 trace("Requested primary format tag=0x%04x %dx%dx%d "
                       "avg.B/s=%d align=%d\n",
-                      wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
-                      wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
-                trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
                       wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
                       wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
+                trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
+                      pwfx->wFormatTag,pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
+                      pwfx->nChannels,pwfx->nAvgBytesPerSec,pwfx->nBlockAlign);
             }
 
             /* Set the CooperativeLevel back to normal */
@@ -616,20 +622,20 @@ static HRESULT test_primary_secondary(LPGUID lpGuid)
             rc=IDirectSound_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
             ok(rc==DS_OK,"IDirectSound_SetCooperativeLevel() failed: %08x\n", rc);
 
-            init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
+            init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
 
             secondary=NULL;
             ZeroMemory(&bufdesc, sizeof(bufdesc));
             bufdesc.dwSize=sizeof(bufdesc);
             bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
-            bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
-                                        wfx.nBlockAlign);
-            bufdesc.lpwfxFormat=&wfx2;
+            bufdesc.dwBufferBytes=align(pwfx->nAvgBytesPerSec*BUFFER_LEN/1000,
+                                        pwfx->nBlockAlign);
+            bufdesc.lpwfxFormat=&wfx;
             if (winetest_interactive) {
                 trace("  Testing a primary buffer at %dx%dx%d (fmt=%d) with a "
                       "secondary buffer at %dx%dx%d\n",
-                      wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
-                      wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
+                      pwfx->nSamplesPerSec,pwfx->wBitsPerSample,pwfx->nChannels,format_tags[tag],
+                      wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
             }
             rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
             ok((rc==DS_OK && secondary!=NULL) || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
@@ -675,8 +681,8 @@ static HRESULT test_secondary(LPGUID lpGuid)
     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
     DSBUFFERDESC bufdesc;
     DSCAPS dscaps;
-    WAVEFORMATEX wfx, wfx1;
-    DWORD f, tag;
+    WAVEFORMATEX wfx, *pwfx;
+    DWORD f, tag, size;
     int ref;
 
     /* Create the DirectSound object */
@@ -709,7 +715,16 @@ static HRESULT test_secondary(LPGUID lpGuid)
        "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc);
 
     if (rc==DS_OK && primary!=NULL) {
-        rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
+        size=0;
+        rc=IDirectSoundBuffer_GetFormat(primary,NULL,0,&size);
+        ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
+           "returned the needed size: rc=%08x size=%d\n",rc,size);
+        ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
+           "Expected a correct structure size, got %d\n", size);
+        if (rc!=DS_OK || size==0 || (size!=sizeof(WAVEFORMATEX) && size!=sizeof(WAVEFORMATEXTENSIBLE)))
+            goto EXIT1;
+        pwfx=HeapAlloc(GetProcessHeap(),0,size);
+        rc=IDirectSoundBuffer_GetFormat(primary,pwfx,size,NULL);
         ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
         if (rc!=DS_OK)
             goto EXIT1;
@@ -852,7 +867,7 @@ no_wfe:
                     trace("  Testing a secondary buffer at %dx%dx%d (fmt=%d) "
                         "with a primary buffer at %dx%dx%d\n",
                         wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
-                        wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
+                        pwfx->nSamplesPerSec,pwfx->wBitsPerSample,pwfx->nChannels);
                 }
                 test_buffer(dso,&secondary,0,FALSE,0,FALSE,0,
                             winetest_interactive,1.0,0,NULL,0,0,FALSE,0);
@@ -959,8 +974,8 @@ static HRESULT test_frequency(LPGUID lpGuid)
     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
     DSBUFFERDESC bufdesc;
     DSCAPS dscaps;
-    WAVEFORMATEX wfx, wfx1;
-    DWORD f, r;
+    WAVEFORMATEX wfx, *pwfx;
+    DWORD f, r, size;
     int ref;
     int rates[] = { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100,
                     48000, 96000 };
@@ -995,7 +1010,13 @@ static HRESULT test_frequency(LPGUID lpGuid)
        "IDirectSound_CreateSoundBuffer() failed to create a primary buffer %08x\n",rc);
 
     if (rc==DS_OK && primary!=NULL) {
-        rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
+        rc=IDirectSoundBuffer_GetFormat(primary,NULL,0,&size);
+        ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
+            "returned the needed size: rc=%08x size=%u\n",rc,size);
+        if (rc!=DS_OK)
+            goto EXIT1;
+        pwfx=HeapAlloc(GetProcessHeap(),0,size);
+        rc=IDirectSoundBuffer_GetFormat(primary,pwfx,size,NULL);
         ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
         if (rc!=DS_OK)
             goto EXIT1;
@@ -1015,7 +1036,7 @@ static HRESULT test_frequency(LPGUID lpGuid)
                 trace("  Testing a secondary buffer at %dx%dx%d "
                       "with a primary buffer at %dx%dx%d\n",
                       wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,
-                      wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
+                      pwfx->nSamplesPerSec,pwfx->wBitsPerSample,pwfx->nChannels);
             }
             rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
             ok((rc==DS_OK && secondary!=NULL) || broken(rc == DSERR_CONTROLUNAVAIL), /* vmware drivers on w2k */
diff --git a/dlls/dsound/tests/dsound8.c b/dlls/dsound/tests/dsound8.c
index c1e672f..e3f9726 100644
--- a/dlls/dsound/tests/dsound8.c
+++ b/dlls/dsound/tests/dsound8.c
@@ -543,7 +543,8 @@ static HRESULT test_primary_secondary8(LPGUID lpGuid)
     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
     DSBUFFERDESC bufdesc;
     DSCAPS dscaps;
-    WAVEFORMATEX wfx, wfx2;
+    WAVEFORMATEX wfx, *pwfx;
+    DWORD size;
     int ref;
     unsigned int f, tag;
 
@@ -595,7 +596,6 @@ static HRESULT test_primary_secondary8(LPGUID lpGuid)
 
             init_format(&wfx,format_tags[tag],formats[f][0],formats[f][1],
                         formats[f][2]);
-            wfx2=wfx;
             rc=IDirectSoundBuffer_SetFormat(primary,&wfx);
             ok(rc==DS_OK
                || rc==DSERR_INVALIDPARAM, /* 2003 */
@@ -604,22 +604,29 @@ static HRESULT test_primary_secondary8(LPGUID lpGuid)
 
             /* There is no guarantee that SetFormat will actually change the
              * format to what we asked for. It depends on what the soundcard
-             * supports. So we must re-query the format.
+             * supports. So we must re-query the format. XXX
              */
-            rc=IDirectSoundBuffer_GetFormat(primary,&wfx,sizeof(wfx),NULL);
+            size=0;
+            rc=IDirectSoundBuffer_GetFormat(primary,NULL,0,&size);
+            ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
+               "returned the needed size: rc=%08x size=%d\n",rc,size);
+            ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
+               "Expected a correct structure size, got %d\n", size);
+            pwfx=HeapAlloc(GetProcessHeap(),0,size);
+            rc=IDirectSoundBuffer_GetFormat(primary,pwfx,size,NULL);
             ok(rc==DS_OK,"IDirectSoundBuffer_GetFormat() failed: %08x\n", rc);
             if (rc==DS_OK &&
-                (wfx.wFormatTag!=wfx2.wFormatTag ||
-                 wfx.nSamplesPerSec!=wfx2.nSamplesPerSec ||
-                 wfx.wBitsPerSample!=wfx2.wBitsPerSample ||
-                 wfx.nChannels!=wfx2.nChannels)) {
+                (pwfx->wFormatTag!=wfx.wFormatTag ||
+                 pwfx->nSamplesPerSec!=wfx.nSamplesPerSec ||
+                 pwfx->wBitsPerSample!=wfx.wBitsPerSample ||
+                 pwfx->nChannels!=wfx.nChannels)) {
                 trace("Requested primary format tag=0x%04x %dx%dx%d "
                       "avg.B/s=%d align=%d\n",
-                      wfx2.wFormatTag,wfx2.nSamplesPerSec,wfx2.wBitsPerSample,
-                      wfx2.nChannels,wfx2.nAvgBytesPerSec,wfx2.nBlockAlign);
-                trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
                       wfx.wFormatTag,wfx.nSamplesPerSec,wfx.wBitsPerSample,
                       wfx.nChannels,wfx.nAvgBytesPerSec,wfx.nBlockAlign);
+                trace("Got tag=0x%04x %dx%dx%d avg.B/s=%d align=%d\n",
+                      pwfx->wFormatTag,pwfx->nSamplesPerSec,pwfx->wBitsPerSample,
+                      pwfx->nChannels,pwfx->nAvgBytesPerSec,pwfx->nBlockAlign);
             }
 
             /* Set the CooperativeLevel back to normal */
@@ -627,20 +634,20 @@ static HRESULT test_primary_secondary8(LPGUID lpGuid)
             rc=IDirectSound8_SetCooperativeLevel(dso,get_hwnd(),DSSCL_NORMAL);
             ok(rc==DS_OK,"IDirectSound8_SetCooperativeLevel() failed: %08x\n", rc);
 
-            init_format(&wfx2,WAVE_FORMAT_PCM,11025,16,2);
+            init_format(&wfx,WAVE_FORMAT_PCM,11025,16,2);
 
             secondary=NULL;
             ZeroMemory(&bufdesc, sizeof(bufdesc));
             bufdesc.dwSize=sizeof(bufdesc);
             bufdesc.dwFlags=DSBCAPS_GETCURRENTPOSITION2;
-            bufdesc.dwBufferBytes=align(wfx.nAvgBytesPerSec*BUFFER_LEN/1000,
-                                        wfx.nBlockAlign);
-            bufdesc.lpwfxFormat=&wfx2;
+            bufdesc.dwBufferBytes=align(pwfx->nAvgBytesPerSec*BUFFER_LEN/1000,
+                                        pwfx->nBlockAlign);
+            bufdesc.lpwfxFormat=&wfx;
             if (winetest_interactive) {
                 trace("  Testing a primary buffer at %dx%dx%d (fmt=%d) with a "
                       "secondary buffer at %dx%dx%d\n",
-                      wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
-                      wfx2.nSamplesPerSec,wfx2.wBitsPerSample,wfx2.nChannels);
+                      pwfx->nSamplesPerSec,pwfx->wBitsPerSample,pwfx->nChannels,format_tags[tag],
+                      wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels);
             }
             rc=IDirectSound_CreateSoundBuffer(dso,&bufdesc,&secondary,NULL);
             ok(rc==DS_OK && secondary!=NULL,
@@ -687,8 +694,8 @@ static HRESULT test_secondary8(LPGUID lpGuid)
     LPDIRECTSOUNDBUFFER primary=NULL,secondary=NULL;
     DSBUFFERDESC bufdesc;
     DSCAPS dscaps;
-    WAVEFORMATEX wfx, wfx1;
-    DWORD f, tag;
+    WAVEFORMATEX wfx, *pwfx;
+    DWORD f, tag, size;
     int ref;
 
     /* Create the DirectSound object */
@@ -722,7 +729,16 @@ static HRESULT test_secondary8(LPGUID lpGuid)
        "%08x\n",rc);
 
     if (rc==DS_OK && primary!=NULL) {
-        rc=IDirectSoundBuffer_GetFormat(primary,&wfx1,sizeof(wfx1),NULL);
+        size=0;
+        rc=IDirectSoundBuffer_GetFormat(primary,NULL,0,&size);
+        ok(rc==DS_OK && size!=0,"IDirectSoundBuffer_GetFormat() should have "
+           "returned the needed size: rc=%08x size=%d\n",rc,size);
+        ok(size == sizeof(WAVEFORMATEX) || size == sizeof(WAVEFORMATEXTENSIBLE),
+           "Expected a correct structure size, got %d\n", size);
+        if (rc!=DS_OK || size==0 || (size!=sizeof(WAVEFORMATEX) && size!=sizeof(WAVEFORMATEXTENSIBLE)))
+            goto EXIT1;
+        pwfx=HeapAlloc(GetProcessHeap(),0,size);
+        rc=IDirectSoundBuffer_GetFormat(primary,pwfx,size,NULL);
         ok(rc==DS_OK,"IDirectSoundBuffer8_Getformat() failed: %08x\n", rc);
         if (rc!=DS_OK)
             goto EXIT1;
@@ -883,7 +899,7 @@ static HRESULT test_secondary8(LPGUID lpGuid)
                     trace("  Testing a secondary buffer at %dx%dx%d (fmt=%d) "
                         "with a primary buffer at %dx%dx%d\n",
                         wfx.nSamplesPerSec,wfx.wBitsPerSample,wfx.nChannels,format_tags[tag],
-                        wfx1.nSamplesPerSec,wfx1.wBitsPerSample,wfx1.nChannels);
+                        pwfx->nSamplesPerSec,pwfx->wBitsPerSample,pwfx->nChannels);
                 }
                 test_buffer8(dso,&secondary,0,FALSE,0,FALSE,0,
                              winetest_interactive,1.0,0,NULL,0,0);
-- 
1.7.9.5


More information about the wine-patches mailing list