winmm/tests: Introduce compare_uint helper.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2020-05-27 23:55:44 +02:00 committed by Alexandre Julliard
parent 0c9f9efda0
commit 72a36736a9
1 changed files with 10 additions and 4 deletions

View File

@ -36,6 +36,12 @@
#include "winmm_test.h" #include "winmm_test.h"
static BOOL compare_uint(unsigned int x, unsigned int y, unsigned int max_diff)
{
unsigned int diff = x > y ? x - y : y - x;
return diff <= max_diff;
}
static const char * line_flags(DWORD fdwLine) static const char * line_flags(DWORD fdwLine)
{ {
static char flags[100]; static char flags[100];
@ -253,11 +259,11 @@ static void mixer_test_controlA(HMIXEROBJ mix, MIXERCONTROLA *control)
mmsys_error(rc)); mmsys_error(rc));
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
/* result may not match exactly because of rounding */ /* result may not match exactly because of rounding */
ok(abs(ret_value.dwValue-new_value.dwValue)<=1, ok(compare_uint(ret_value.dwValue, new_value.dwValue, 1),
"Couldn't change value from %d to %d, returned %d\n", "Couldn't change value from %d to %d, returned %d\n",
value.dwValue,new_value.dwValue,ret_value.dwValue); value.dwValue,new_value.dwValue,ret_value.dwValue);
if (abs(ret_value.dwValue-new_value.dwValue)<=1) { if (compare_uint(ret_value.dwValue, new_value.dwValue, 1)) {
details.cbStruct = sizeof(MIXERCONTROLDETAILS); details.cbStruct = sizeof(MIXERCONTROLDETAILS);
details.dwControlID = control->dwControlID; details.dwControlID = control->dwControlID;
details.cChannels = 1; details.cChannels = 1;
@ -632,11 +638,11 @@ static void mixer_test_controlW(HMIXEROBJ mix, MIXERCONTROLW *control)
mmsys_error(rc)); mmsys_error(rc));
if (rc==MMSYSERR_NOERROR) { if (rc==MMSYSERR_NOERROR) {
/* result may not match exactly because of rounding */ /* result may not match exactly because of rounding */
ok(abs(ret_value.dwValue-new_value.dwValue)<=1, ok(compare_uint(ret_value.dwValue, new_value.dwValue, 1),
"Couldn't change value from %d to %d, returned %d\n", "Couldn't change value from %d to %d, returned %d\n",
value.dwValue,new_value.dwValue,ret_value.dwValue); value.dwValue,new_value.dwValue,ret_value.dwValue);
if (abs(ret_value.dwValue-new_value.dwValue)<=1) { if (compare_uint(ret_value.dwValue, new_value.dwValue, 1)) {
details.cbStruct = sizeof(MIXERCONTROLDETAILS); details.cbStruct = sizeof(MIXERCONTROLDETAILS);
details.dwControlID = control->dwControlID; details.dwControlID = control->dwControlID;
details.cChannels = 1; details.cChannels = 1;