From: Chip Davis <cdavis(a)codeweavers.com>
Analogous to compare_float().
Signed-off-by: Chip Davis <cdavis(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/ddraw/tests/ddraw1.c | 29 ++++++++++++++++-------------
dlls/ddraw/tests/ddraw2.c | 31 +++++++++++++++++--------------
dlls/ddraw/tests/ddraw4.c | 23 +++++++++++++----------
dlls/ddraw/tests/ddraw7.c | 23 +++++++++++++----------
dlls/ddraw/tests/visual.c | 19 +++++++++++--------
5 files changed, 70 insertions(+), 55 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index ff100c64aa0..96e5555d9fc 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -49,18 +49,6 @@ struct create_window_thread_param
HANDLE thread;
};
-static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
-{
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- return TRUE;
-}
-
static BOOL compare_float(float f, float g, unsigned int ulps)
{
int x = *(int *)&f;
@@ -85,6 +73,21 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
+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 BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
+{
+ return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
+ && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
+ && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
+ && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
+}
+
static BOOL ddraw_get_identifier(IDirectDraw *ddraw, DDDEVICEIDENTIFIER *identifier)
{
IDirectDraw4 *ddraw4;
@@ -11770,7 +11773,7 @@ static void test_depth_readback(void)
depth = *((DWORD *)ptr) & z_mask;
expected_depth = (x * (0.9 / 640.0) + y * (0.1 / 480.0)) * z_mask;
max_diff = ((0.5f * 0.9f) / 640.0f) * z_mask;
- ok(abs(expected_depth - depth) <= max_diff,
+ ok(compare_uint(expected_depth, depth, max_diff),
"z_depth %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
z_depth, depth, expected_depth - depth, expected_depth, max_diff, x, y);
}
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 5bb5b1baadf..389f33408fe 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -50,18 +50,6 @@ struct create_window_thread_param
HANDLE thread;
};
-static BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
-{
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- return TRUE;
-}
-
static BOOL compare_float(float f, float g, unsigned int ulps)
{
int x = *(int *)&f;
@@ -86,6 +74,21 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
+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 BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
+{
+ return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
+ && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
+ && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
+ && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
+}
+
static BOOL ddraw_get_identifier(IDirectDraw2 *ddraw, DDDEVICEIDENTIFIER *identifier)
{
IDirectDraw4 *ddraw4;
@@ -12749,10 +12752,10 @@ static void test_depth_readback(void)
/* The ddraw2 version of this test behaves similarly to the ddraw7 version on Nvidia GPUs,
* except that we only have D16 (broken on geforce 9) and D24X8 (broken on geforce 7) available.
* Accept all nvidia GPUs as broken here, but still expect one of the formats to pass. */
- ok(abs(expected_depth - depth) <= max_diff || ddraw_is_nvidia(ddraw),
+ ok(compare_uint(expected_depth, depth, max_diff) || ddraw_is_nvidia(ddraw),
"Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
- if (abs(expected_depth - depth) > max_diff)
+ if (!compare_uint(expected_depth, depth, max_diff))
all_pass = FALSE;
}
}
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index fc3a415433d..b10c157c236 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -80,16 +80,19 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
+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 BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- return TRUE;
+ return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
+ && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
+ && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
+ && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static BOOL ddraw_get_identifier(IDirectDraw4 *ddraw, DDDEVICEIDENTIFIER *identifier)
@@ -15282,10 +15285,10 @@ static void test_depth_readback(void)
* returns 0 for that format. Give up on pre-filtering formats, accept Nvidia as generally
* broken here, but still expect at least one format (D16 or D24X8 in practise) to pass. */
todo_wine_if(tests[i].todo)
- ok(abs(expected_depth - depth) <= max_diff || ddraw_is_nvidia(ddraw),
+ ok(compare_uint(expected_depth, depth, max_diff) || ddraw_is_nvidia(ddraw),
"Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
- if (abs(expected_depth - depth) > max_diff)
+ if (!compare_uint(expected_depth, depth, max_diff))
all_pass = FALSE;
hr = IDirectDrawSurface4_Unlock(ds, &r);
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index abe5249cc06..11aca6d2da1 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -87,16 +87,19 @@ static BOOL compare_vec4(const struct vec4 *vec, float x, float y, float z, floa
&& compare_float(vec->w, w, ulps);
}
+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 BOOL compare_color(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- return TRUE;
+ return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
+ && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
+ && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
+ && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static ULONG get_refcount(IUnknown *iface)
@@ -14726,11 +14729,11 @@ static void test_depth_readback(void)
* Arx Fatalis is broken on the Geforce 9 in the same way it was broken in Wine (bug 43654).
* The !tests[i].s_depth is supposed to rule out D16 on GF9 and D24X8 on GF7. */
todo_wine_if(tests[i].todo)
- ok(abs(expected_depth - depth) <= max_diff
+ ok(compare_uint(expected_depth, depth, max_diff)
|| (ddraw_is_nvidia(ddraw) && (all_zero || all_one || !tests[i].s_depth)),
"Test %u: Got depth 0x%08x (diff %d), expected 0x%08x+/-%u, at %u, %u.\n",
i, depth, expected_depth - depth, expected_depth, max_diff, x, y);
- if (abs(expected_depth - depth) > max_diff)
+ if (!compare_uint(expected_depth, depth, max_diff))
all_pass = FALSE;
hr = IDirectDrawSurface7_Unlock(ds, &r);
diff --git a/dlls/ddraw/tests/visual.c b/dlls/ddraw/tests/visual.c
index 2cb1c892314..e2a0c7a2a74 100644
--- a/dlls/ddraw/tests/visual.c
+++ b/dlls/ddraw/tests/visual.c
@@ -45,16 +45,19 @@ static BOOL refdevice = FALSE;
static HRESULT (WINAPI *pDirectDrawCreateEx)(GUID *driver_guid,
void **ddraw, REFIID interface_iid, IUnknown *outer);
+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 BOOL color_match(D3DCOLOR c1, D3DCOLOR c2, BYTE max_diff)
{
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
- return TRUE;
+ return compare_uint(c1 & 0xff, c2 & 0xff, max_diff)
+ && compare_uint((c1 >> 8) & 0xff, (c2 >> 8) & 0xff, max_diff)
+ && compare_uint((c1 >> 16) & 0xff, (c2 >> 16) & 0xff, max_diff)
+ && compare_uint((c1 >> 24) & 0xff, (c2 >> 24) & 0xff, max_diff);
}
static HRESULT WINAPI enum_z_fmt(DDPIXELFORMAT *fmt, void *ctx)
--
2.20.1