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

waveOutGetDevCaps(-1...) must return the capabilities of the Wave

mapper. DRV_QUERYDEVICEINTERFACE is not supported on all Windows versions. Check the length returned by DRV_QUERYDEVICEINTERFACESIZE and fix memory leak. Some Windows sound drivers allow wild frequencies such as the 2MHz one. So modify this test to use an invalid number of bits per sample instead (hopefully that will fail really everywhere).
parent 977d863c
...@@ -258,7 +258,7 @@ static void wave_out_tests() ...@@ -258,7 +258,7 @@ static void wave_out_tests()
MMRESULT rc; MMRESULT rc;
UINT ndev,d,f; UINT ndev,d,f;
WCHAR * wname; WCHAR * wname;
CHAR * name=NULL; CHAR * name;
DWORD size; DWORD size;
ndev=waveOutGetNumDevs(); ndev=waveOutGetNumDevs();
...@@ -268,6 +268,10 @@ static void wave_out_tests() ...@@ -268,6 +268,10 @@ static void wave_out_tests()
ok(rc==MMSYSERR_BADDEVICEID, ok(rc==MMSYSERR_BADDEVICEID,
"waveOutGetDevCapsA: MMSYSERR_BADDEVICEID expected, got %d\n",rc); "waveOutGetDevCapsA: MMSYSERR_BADDEVICEID expected, got %d\n",rc);
rc=waveOutGetDevCapsA(-1,&caps,sizeof(caps));
ok(rc==MMSYSERR_NOERROR,
"waveOutGetDevCapsA: MMSYSERR_NOERROR expected, got %d\n",rc);
format.wFormatTag=WAVE_FORMAT_PCM; format.wFormatTag=WAVE_FORMAT_PCM;
format.nChannels=2; format.nChannels=2;
format.wBitsPerSample=16; format.wBitsPerSample=16;
...@@ -286,23 +290,32 @@ static void wave_out_tests() ...@@ -286,23 +290,32 @@ static void wave_out_tests()
if (rc==MMSYSERR_BADDEVICEID) if (rc==MMSYSERR_BADDEVICEID)
continue; continue;
name=NULL;
rc=waveOutMessage((HWAVEOUT)d, DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&size, 0); rc=waveOutMessage((HWAVEOUT)d, DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&size, 0);
ok(rc==MMSYSERR_NOERROR, "waveOutMessage: failed to get interface size for device: %d rc=%d\n",d,rc); ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
"waveOutMessage: failed to get interface size for device: %d rc=%d\n",d,rc);
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
wname = (WCHAR *)malloc(size); wname = (WCHAR *)malloc(size);
rc=waveOutMessage((HWAVEOUT)d, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)wname, size); rc=waveOutMessage((HWAVEOUT)d, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)wname, size);
ok(rc==MMSYSERR_NOERROR,"waveOutMessage: failed to get interface name for device:: %d rc=%d\n",d,rc); ok(rc==MMSYSERR_NOERROR,"waveOutMessage: failed to get interface name for device: %d rc=%d\n",d,rc);
ok(lstrlenW(wname)+1==size/sizeof(WCHAR),"got an incorrect size: %ld instead of %d\n",size,(lstrlenW(wname)+1)*sizeof(WCHAR));
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
name = malloc(size/sizeof(WCHAR)); name = malloc(size/sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, wname, size/sizeof(WCHAR), name, size/sizeof(WCHAR), NULL, NULL); WideCharToMultiByte(CP_ACP, 0, wname, size/sizeof(WCHAR), name, size/sizeof(WCHAR), NULL, NULL);
} }
free(wname);
}
else if (rc==MMSYSERR_NOTSUPPORTED)
{
name=strdup("not supported");
} }
trace(" %d: \"%s\" (%s) %d.%d (%d:%d): channels=%d formats=%05lx support=%04lx\n", trace(" %d: \"%s\" (%s) %d.%d (%d:%d): channels=%d formats=%05lx support=%04lx\n",
d,caps.szPname,name,caps.vDriverVersion >> 8, d,caps.szPname,(name?name:"failed"),caps.vDriverVersion >> 8,
caps.vDriverVersion & 0xff, caps.vDriverVersion & 0xff,
caps.wMid,caps.wPid, caps.wMid,caps.wPid,
caps.wChannels,caps.dwFormats,caps.dwSupport); caps.wChannels,caps.dwFormats,caps.dwSupport);
free(name);
for (f=0;f<NB_WIN_FORMATS;f++) { for (f=0;f<NB_WIN_FORMATS;f++) {
if (caps.dwFormats & win_formats[f][0]) { if (caps.dwFormats & win_formats[f][0]) {
...@@ -312,18 +325,18 @@ static void wave_out_tests() ...@@ -312,18 +325,18 @@ static void wave_out_tests()
} }
/* Try an invalid format to test error handling */ /* Try an invalid format to test error handling */
trace("Testing invalid 2MHz format\n"); trace("Testing invalid format\n");
format.wFormatTag=WAVE_FORMAT_PCM; format.wFormatTag=WAVE_FORMAT_PCM;
format.nChannels=2; format.nChannels=2;
format.wBitsPerSample=16; format.wBitsPerSample=11;
format.nSamplesPerSec=2000000; /* 2MHz! */ format.nSamplesPerSec=8000;
format.nBlockAlign=format.nChannels*format.wBitsPerSample/8; format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign; format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
format.cbSize=0; format.cbSize=0;
oformat=format; oformat=format;
rc=waveOutOpen(&wout,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT); rc=waveOutOpen(&wout,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
ok(rc==WAVERR_BADFORMAT, ok(rc==WAVERR_BADFORMAT || rc==MMSYSERR_INVALFLAG,
"waveOutOpen: opening the device at 2MHz should fail %d: rc=%d\n",d,rc); "waveOutOpen: opening the device in 11 bits mode should fail %d: rc=%d\n",d,rc);
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
trace(" got %ldx%2dx%d for %ldx%2dx%d\n", trace(" got %ldx%2dx%d for %ldx%2dx%d\n",
format.nSamplesPerSec, format.wBitsPerSample, format.nSamplesPerSec, format.wBitsPerSample,
...@@ -332,25 +345,6 @@ static void wave_out_tests() ...@@ -332,25 +345,6 @@ static void wave_out_tests()
oformat.nChannels); oformat.nChannels);
waveOutClose(wout); waveOutClose(wout);
} }
format.wFormatTag=WAVE_FORMAT_PCM;
format.nChannels=2;
format.wBitsPerSample=16;
format.nSamplesPerSec=2000000; /* 2MHz! */
format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
format.cbSize=0;
rc=waveOutOpen(&wout,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
ok(rc==WAVERR_BADFORMAT || rc==MMSYSERR_INVALFLAG,
"waveOutOpen: opening the device at 2MHz should fail %d: rc=%d\n",d,rc);
if (rc==MMSYSERR_NOERROR) {
trace(" got %ldx%2dx%d for %dx%2dx%d\n",
format.nSamplesPerSec, format.wBitsPerSample,
format.nChannels,
win_formats[f][1], win_formats[f][2],
win_formats[f][3]);
waveOutClose(wout);
}
} }
} }
...@@ -465,7 +459,7 @@ static void wave_in_tests() ...@@ -465,7 +459,7 @@ static void wave_in_tests()
MMRESULT rc; MMRESULT rc;
UINT ndev,d,f; UINT ndev,d,f;
WCHAR * wname; WCHAR * wname;
CHAR * name=NULL; CHAR * name;
DWORD size; DWORD size;
ndev=waveInGetNumDevs(); ndev=waveInGetNumDevs();
...@@ -475,6 +469,10 @@ static void wave_in_tests() ...@@ -475,6 +469,10 @@ static void wave_in_tests()
ok(rc==MMSYSERR_BADDEVICEID, ok(rc==MMSYSERR_BADDEVICEID,
"waveInGetDevCapsA: MMSYSERR_BADDEVICEID expected, got %d(%s)\n",rc,wave_in_error(rc)); "waveInGetDevCapsA: MMSYSERR_BADDEVICEID expected, got %d(%s)\n",rc,wave_in_error(rc));
rc=waveInGetDevCapsA(-1,&caps,sizeof(caps));
ok(rc==MMSYSERR_NOERROR,
"waveInGetDevCapsA: MMSYSERR_NOERROR expected, got %d\n",rc);
format.wFormatTag=WAVE_FORMAT_PCM; format.wFormatTag=WAVE_FORMAT_PCM;
format.nChannels=2; format.nChannels=2;
format.wBitsPerSample=16; format.wBitsPerSample=16;
...@@ -493,23 +491,32 @@ static void wave_in_tests() ...@@ -493,23 +491,32 @@ static void wave_in_tests()
if (rc==MMSYSERR_BADDEVICEID) if (rc==MMSYSERR_BADDEVICEID)
continue; continue;
name=NULL;
rc=waveInMessage((HWAVEIN)d, DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&size, 0); rc=waveInMessage((HWAVEIN)d, DRV_QUERYDEVICEINTERFACESIZE, (DWORD_PTR)&size, 0);
ok(rc==MMSYSERR_NOERROR, "waveInMessage: failed to get interface size for device: %d rc=%d(%s)\n",d,rc,wave_in_error(rc)); ok(rc==MMSYSERR_NOERROR || rc==MMSYSERR_INVALPARAM || rc==MMSYSERR_NOTSUPPORTED,
"waveInMessage: failed to get interface size for device: %d rc=%d(%s)\n",d,rc,wave_in_error(rc));
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
wname = (WCHAR *)malloc(size); wname = (WCHAR *)malloc(size);
rc=waveInMessage((HWAVEIN)d, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)wname, size); rc=waveInMessage((HWAVEIN)d, DRV_QUERYDEVICEINTERFACE, (DWORD_PTR)wname, size);
ok(rc==MMSYSERR_NOERROR,"waveInMessage: failed to get interface name for device:: %d rc=%d(%s)\n",d,rc,wave_in_error(rc)); ok(rc==MMSYSERR_NOERROR,"waveInMessage: failed to get interface name for device: %d rc=%d(%s)\n",d,rc,wave_in_error(rc));
ok(lstrlenW(wname)+1==size/sizeof(WCHAR),"got an incorrect size: %ld instead of %d\n",size,(lstrlenW(wname)+1)*sizeof(WCHAR));
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
name = malloc(size/sizeof(WCHAR)); name = malloc(size/sizeof(WCHAR));
WideCharToMultiByte(CP_ACP, 0, wname, size/sizeof(WCHAR), name, size/sizeof(WCHAR), NULL, NULL); WideCharToMultiByte(CP_ACP, 0, wname, size/sizeof(WCHAR), name, size/sizeof(WCHAR), NULL, NULL);
} }
free(wname);
}
else if (rc==MMSYSERR_NOTSUPPORTED)
{
name=strdup("not supported");
} }
trace(" %d: \"%s\" (%s) %d.%d (%d:%d): channels=%d formats=%05lx\n", trace(" %d: \"%s\" (%s) %d.%d (%d:%d): channels=%d formats=%05lx\n",
d,caps.szPname,name,caps.vDriverVersion >> 8, d,caps.szPname,(name?name:"failed"),caps.vDriverVersion >> 8,
caps.vDriverVersion & 0xff, caps.vDriverVersion & 0xff,
caps.wMid,caps.wPid, caps.wMid,caps.wPid,
caps.wChannels,caps.dwFormats); caps.wChannels,caps.dwFormats);
free(name);
for (f=0;f<NB_WIN_FORMATS;f++) { for (f=0;f<NB_WIN_FORMATS;f++) {
if (caps.dwFormats & win_formats[f][0]) { if (caps.dwFormats & win_formats[f][0]) {
...@@ -519,18 +526,18 @@ static void wave_in_tests() ...@@ -519,18 +526,18 @@ static void wave_in_tests()
} }
/* Try an invalid format to test error handling */ /* Try an invalid format to test error handling */
trace("Testing invalid 2MHz format\n"); trace("Testing invalid format\n");
format.wFormatTag=WAVE_FORMAT_PCM; format.wFormatTag=WAVE_FORMAT_PCM;
format.nChannels=2; format.nChannels=2;
format.wBitsPerSample=16; format.wBitsPerSample=11;
format.nSamplesPerSec=2000000; /* 2MHz! */ format.nSamplesPerSec=8000;
format.nBlockAlign=format.nChannels*format.wBitsPerSample/8; format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign; format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
format.cbSize=0; format.cbSize=0;
oformat=format; oformat=format;
rc=waveInOpen(&win,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT); rc=waveInOpen(&win,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
ok(rc==WAVERR_BADFORMAT, ok(rc==WAVERR_BADFORMAT || rc==MMSYSERR_INVALFLAG,
"waveInOpen: opening the device at 2MHz should fail %d: rc=%d\n",d,rc); "waveInOpen: opening the device in 11 bit mode should fail %d: rc=%d\n",d,rc);
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
trace(" got %ldx%2dx%d for %ldx%2dx%d\n", trace(" got %ldx%2dx%d for %ldx%2dx%d\n",
format.nSamplesPerSec, format.wBitsPerSample, format.nSamplesPerSec, format.wBitsPerSample,
...@@ -539,25 +546,6 @@ static void wave_in_tests() ...@@ -539,25 +546,6 @@ static void wave_in_tests()
oformat.nChannels); oformat.nChannels);
waveInClose(win); waveInClose(win);
} }
format.wFormatTag=WAVE_FORMAT_PCM;
format.nChannels=2;
format.wBitsPerSample=16;
format.nSamplesPerSec=2000000; /* 2MHz! */
format.nBlockAlign=format.nChannels*format.wBitsPerSample/8;
format.nAvgBytesPerSec=format.nSamplesPerSec*format.nBlockAlign;
format.cbSize=0;
rc=waveInOpen(&win,d,&format,0,0,CALLBACK_NULL|WAVE_FORMAT_DIRECT);
ok(rc==WAVERR_BADFORMAT || rc==MMSYSERR_INVALFLAG,
"waveInOpen: opening the device at 2MHz should fail %d: rc=%d\n",d,rc);
if (rc==MMSYSERR_NOERROR) {
trace(" got %ldx%2dx%d for %dx%2dx%d\n",
format.nSamplesPerSec, format.wBitsPerSample,
format.nChannels,
win_formats[f][1], win_formats[f][2],
win_formats[f][3]);
waveInClose(win);
}
} }
} }
......
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