[PATCH v2 2/5] ddraw/tests: Fix absolute value warnings. (Clang)
Chip Davis
cdavis at codeweavers.com
Mon Mar 30 01:53:03 CDT 2020
Signed-off-by: Chip Davis <cdavis at codeweavers.com>
---
I wanted to teach Clang not to emit these warnings, but they insisted
that yes, Clang really should warn on absolute values of differences. So
I gave up on that.
v2: Fold absdiff() into a compare_uint() helper.
---
dlls/ddraw/tests/ddraw1.c | 17 ++++++++++++-----
dlls/ddraw/tests/ddraw2.c | 19 +++++++++++++------
dlls/ddraw/tests/ddraw4.c | 19 +++++++++++++------
dlls/ddraw/tests/ddraw7.c | 19 +++++++++++++------
dlls/ddraw/tests/visual.c | 15 +++++++++++----
5 files changed, 62 insertions(+), 27 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index ff100c64aa0..7157592c705 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -49,15 +49,22 @@ struct create_window_thread_param
HANDLE thread;
};
+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;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
return TRUE;
}
@@ -11770,7 +11777,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..c089713d7bc 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -50,15 +50,22 @@ struct create_window_thread_param
HANDLE thread;
};
+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;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
return TRUE;
}
@@ -12749,10 +12756,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..ae616ed68c5 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -80,15 +80,22 @@ 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;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
return TRUE;
}
@@ -15282,10 +15289,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..578745271aa 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -87,15 +87,22 @@ 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;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
return TRUE;
}
@@ -14726,11 +14733,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..a2f2f3cb04e 100644
--- a/dlls/ddraw/tests/visual.c
+++ b/dlls/ddraw/tests/visual.c
@@ -45,15 +45,22 @@ 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;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
c1 >>= 8; c2 >>= 8;
- if (abs((c1 & 0xff) - (c2 & 0xff)) > max_diff) return FALSE;
+ if (!compare_uint(c1 & 0xff, c2 & 0xff, max_diff)) return FALSE;
return TRUE;
}
--
2.24.0
More information about the wine-devel
mailing list