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



commit dadea7534f55ce257e8ccd0811c7440cedcbfdfc
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Dec 4 09:47:45 2018 -0600

    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.

 tests/dimensions.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/tests/dimensions.c b/tests/dimensions.c
index 9edad448..1928d44e 100644
--- a/tests/dimensions.c
+++ b/tests/dimensions.c
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]