From 21b605ed610b7f70035d1e104a9924524df27a1e Mon Sep 17 00:00:00 2001
From: =?utf-8?q?J=C3=B6rg=20H=C3=B6hle?= <hoehle@users.sourceforge.net>
Date: Thu, 17 Sep 2009 16:14:47 +0200
Subject: [PATCH] winmm/tests: test some inconsistent WAVEFORMAT descriptions

The tests show that MS-Windows ignores a broken nBlockAlign and nAvgBytesPerSec.
---
 dlls/winmm/tests/wave.c |   65 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/dlls/winmm/tests/wave.c b/dlls/winmm/tests/wave.c
index 98a16f5..5f2b003 100644
--- a/dlls/winmm/tests/wave.c
+++ b/dlls/winmm/tests/wave.c
@@ -603,9 +603,7 @@ static void wave_out_test_deviceOut(int device, double duration,
     WAVEHDR *frags = 0;
     MMRESULT rc;
     DWORD volume;
-    WORD nChannels = pwfx->nChannels;
-    WORD wBitsPerSample = pwfx->wBitsPerSample;
-    DWORD nSamplesPerSec = pwfx->nSamplesPerSec;
+    PCMWAVEFORMAT oformat = *(LPPCMWAVEFORMAT)pwfx;
     BOOL has_volume = pcaps->dwSupport & WAVECAPS_VOLUME ? TRUE : FALSE;
     double paused = 0.0;
     DWORD_PTR callback = 0;
@@ -686,12 +684,22 @@ static void wave_out_test_deviceOut(int device, double duration,
 
     WaitForSingleObject(hevent,10000);
 
-    ok(pwfx->nChannels==nChannels &&
-       pwfx->wBitsPerSample==wBitsPerSample &&
-       pwfx->nSamplesPerSec==nSamplesPerSec,
+    ok(pwfx->nChannels==oformat.wf.nChannels &&
+       pwfx->wBitsPerSample==oformat.wBitsPerSample &&
+       pwfx->nSamplesPerSec==oformat.wf.nSamplesPerSec,
        "got the wrong format: %dx%2dx%d instead of %dx%2dx%d\n",
        pwfx->nSamplesPerSec, pwfx->wBitsPerSample,
-       pwfx->nChannels, nSamplesPerSec, wBitsPerSample, nChannels);
+       pwfx->nChannels, oformat.wf.nSamplesPerSec, oformat.wBitsPerSample, oformat.wf.nChannels);
+    ok(pwfx->nBlockAlign    ==oformat.wf.nBlockAlign, "Changed nBlockAlign\n");
+    ok(pwfx->nAvgBytesPerSec==oformat.wf.nAvgBytesPerSec, "Changed nAvgBytesPerSec\n");
+
+    if (pwfx->wFormatTag==WAVE_FORMAT_PCM) {
+        /* Let wave_generate_* and check_position operate on a sane copy */
+        pwfx = (LPWAVEFORMATEX)&oformat;
+        /* set consistent values for them */
+        pwfx->nBlockAlign=pwfx->nChannels*pwfx->wBitsPerSample/8;
+        pwfx->nAvgBytesPerSec=pwfx->nSamplesPerSec*pwfx->nBlockAlign;
+    }
 
     frags = HeapAlloc(GetProcessHeap(), 0, headers * sizeof(WAVEHDR));
 
@@ -987,6 +995,34 @@ static void wave_out_test_device(UINT_PTR device)
                                 CALLBACK_EVENT,&capsA,TRUE,FALSE,FALSE);
     }
 
+    /* Testing inconsistent format: bad BlockAlign */
+    format.wFormatTag=WAVE_FORMAT_PCM;
+    format.nChannels=1;
+    format.wBitsPerSample=8;
+    format.nSamplesPerSec=22050;
+    format.nBlockAlign=format.nChannels*format.wBitsPerSample/8 *4;
+    format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign /4;
+    format.cbSize=0;
+    oformat=format;
+    wave_out_test_deviceOut(device,2.0,1,0,&format,WAVE_FORMAT_2M08,
+                            CALLBACK_EVENT,&capsA,TRUE,winetest_interactive,FALSE);
+    ok(format.nBlockAlign == oformat.nBlockAlign, "Fixed broken nBlockAlign\n");
+    ok(format.nAvgBytesPerSec == oformat.nAvgBytesPerSec, "Fixed broken nAvgBytesPerSec\n");
+
+    /* Testing inconsistent format: bad AvgBytePerSec */
+    format.wFormatTag=WAVE_FORMAT_PCM;
+    format.nChannels=1;
+    format.wBitsPerSample=8;
+    format.nSamplesPerSec=22050;
+    format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
+    format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign *4;
+    format.cbSize=0;
+    oformat=format;
+    wave_out_test_deviceOut(device,2.0,1,0,&format,WAVE_FORMAT_2M08,
+                            CALLBACK_EVENT,&capsA,TRUE,winetest_interactive,FALSE);
+    ok(format.nBlockAlign == oformat.nBlockAlign, "Fixed broken nBlockAlign\n");
+    ok(format.nAvgBytesPerSec == oformat.nAvgBytesPerSec, "Fixed broken nAvgBytesPerSec\n");
+
     for (f=0;f<NB_WIN_FORMATS;f++) {
         format.wFormatTag=WAVE_FORMAT_PCM;
         format.nChannels=win_formats[f][3];
@@ -1158,6 +1194,21 @@ static void wave_out_test_device(UINT_PTR device)
         waveOutClose(wout);
     }
 
+    /* Try unusual frequency */
+    format.wFormatTag=WAVE_FORMAT_PCM;
+    format.nChannels=1;
+    format.wBitsPerSample=8;
+    format.nSamplesPerSec=19000;
+    format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
+    format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
+    format.cbSize=0;
+    wave_out_test_deviceOut(device,2.0,1,0,&format,0,
+                            CALLBACK_EVENT,&capsA,
+                            TRUE,winetest_interactive,FALSE);
+    wave_out_test_deviceOut(device,2.0,1,0,&format,0,
+                            CALLBACK_EVENT|WAVE_FORMAT_DIRECT,&capsA,
+                            TRUE,winetest_interactive,FALSE);
+
     /* try some non PCM formats */
     format.wFormatTag=WAVE_FORMAT_MULAW;
     format.nChannels=1;
-- 
1.5.6.3

