tests/dimensions.c: Use our own macros instead of g_assert_cmpfloat_with_epsilon()

That macro appeared in glib 2.58, but we require only glib 2.48.
Maybe we can update this in the near future.
parent 9725c843
......@@ -22,6 +22,23 @@ typedef struct
gboolean has_logical_dimensions;
} FixtureData;
/* The following are stolen from g_assert_cmpfloat_with_epsilon() and
* G_APPROX_VALUE(), which only appeared in glib 2.58. When we can update the
* glib version, we can remove these.
*/
#define MY_APPROX_VALUE(a, b, epsilon) \
(((a) > (b) ? (a) - (b) : (b) - (a)) < (epsilon))
#define my_assert_cmpfloat_with_epsilon(n1,n2,epsilon) \
G_STMT_START { \
double __n1 = (n1), __n2 = (n2), __epsilon = (epsilon); \
if (MY_APPROX_VALUE (__n1, __n2, __epsilon)) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#n1 " == " #n2 " (+/- " #epsilon ")", __n1, "==", __n2, 'f'); \
} G_STMT_END
static void
test_dimensions (FixtureData *fixture)
{
......@@ -55,21 +72,21 @@ test_dimensions (FixtureData *fixture)
g_assert_cmpint (fixture->x, ==, position.x);
g_assert_cmpint (fixture->y, ==, position.y);
g_assert_cmpfloat_with_epsilon (fixture->x, ink_rect.x, 0.01);
g_assert_cmpfloat_with_epsilon (fixture->y, ink_rect.y, 0.01);
my_assert_cmpfloat_with_epsilon (fixture->x, ink_rect.x, 0.01);
my_assert_cmpfloat_with_epsilon (fixture->y, ink_rect.y, 0.01);
}
if (fixture->has_dimensions) {
g_assert_cmpint (fixture->width, ==, dimension.width);
g_assert_cmpint (fixture->height, ==, dimension.height);
g_assert_cmpfloat_with_epsilon (fixture->width, ink_rect.width, 0.01);
g_assert_cmpfloat_with_epsilon (fixture->height, ink_rect.height, 0.01);
my_assert_cmpfloat_with_epsilon (fixture->width, ink_rect.width, 0.01);
my_assert_cmpfloat_with_epsilon (fixture->height, ink_rect.height, 0.01);
}
if (fixture->has_logical_dimensions) {
g_assert_cmpfloat_with_epsilon (fixture->logical_width, logical_rect.width, 0.01);
g_assert_cmpfloat_with_epsilon (fixture->logical_height, logical_rect.height, 0.01);
my_assert_cmpfloat_with_epsilon (fixture->logical_width, logical_rect.width, 0.01);
my_assert_cmpfloat_with_epsilon (fixture->logical_height, logical_rect.height, 0.01);
}
g_object_unref (handle);
......
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