cogl/tests: Fix warning about passing a double to fabs

The warning was in a home baked g_assert_float_with_epsilon(). Change to
use the glib one directly.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2319>
This commit is contained in:
Jonas Ådahl 2022-03-04 20:46:48 +01:00 committed by Marge Bot
parent c9125aba73
commit 63cc69b342

View File

@ -6,11 +6,7 @@
#include "test-declarations.h" #include "test-declarations.h"
#include "test-utils.h" #include "test-utils.h"
#define cogl_assert_float(a, b) \ #define TEST_CASE_EPSILON 0.0001
do { \
if (fabsf ((a) - (b)) >= 0.0001f) \
g_assert_cmpfloat ((a), ==, (b)); \
} while (0)
void void
test_color_hsl (void) test_color_hsl (void)
@ -21,9 +17,9 @@ test_color_hsl (void)
cogl_color_init_from_4ub(&color, 108, 198, 78, 255); cogl_color_init_from_4ub(&color, 108, 198, 78, 255);
cogl_color_to_hsl(&color, &hue, &saturation, &luminance); cogl_color_to_hsl(&color, &hue, &saturation, &luminance);
cogl_assert_float(hue, 105.f); g_assert_cmpfloat_with_epsilon (hue, 105.f, TEST_CASE_EPSILON);
cogl_assert_float(saturation, 0.512821); g_assert_cmpfloat_with_epsilon (saturation, 0.512821, TEST_CASE_EPSILON);
cogl_assert_float(luminance, 0.541176); g_assert_cmpfloat_with_epsilon (luminance, 0.541176, TEST_CASE_EPSILON);
memset(&color, 0, sizeof (CoglColor)); memset(&color, 0, sizeof (CoglColor));
cogl_color_init_from_hsl(&color, hue, saturation, luminance); cogl_color_init_from_hsl(&color, hue, saturation, luminance);
@ -36,10 +32,14 @@ test_color_hsl (void)
memset(&color, 0, sizeof (CoglColor)); memset(&color, 0, sizeof (CoglColor));
cogl_color_init_from_hsl(&color, hue, 0, luminance); cogl_color_init_from_hsl(&color, hue, 0, luminance);
cogl_assert_float (cogl_color_get_red_float (&color), luminance); g_assert_cmpfloat_with_epsilon (cogl_color_get_red_float (&color), luminance,
cogl_assert_float (cogl_color_get_green_float (&color), luminance); TEST_CASE_EPSILON);
cogl_assert_float (cogl_color_get_blue_float (&color), luminance); g_assert_cmpfloat_with_epsilon (cogl_color_get_green_float (&color), luminance,
cogl_assert_float (cogl_color_get_alpha_float (&color), 1.0f); TEST_CASE_EPSILON);
g_assert_cmpfloat_with_epsilon (cogl_color_get_blue_float (&color), luminance,
TEST_CASE_EPSILON);
g_assert_cmpfloat_with_epsilon (cogl_color_get_alpha_float (&color), 1.0,
TEST_CASE_EPSILON);
if (cogl_test_verbose ()) if (cogl_test_verbose ())
g_print ("OK\n"); g_print ("OK\n");