[pango/pango2-windows: 15/17] testattributes: Fix test on Windows




commit 97c8e9284f8b619fed735f369dc9f6a1350500a3
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Wed Jun 15 18:00:55 2022 +0800

    testattributes: Fix test on Windows
    
    The output produced by the %p format indentifier is platform dependent,
    so check the resulting string to see whether we have the desired results
    by calling g_strplit() on it and check whether the parts of the string
    match what we expect.  For the %p part, we use strtol() to see whether we
    have the expected hex value.
    
    See: https://stackoverflow.com/questions/2369541/where-is-p-useful-with-printf

 tests/testattributes.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/tests/testattributes.c b/tests/testattributes.c
index ef7eea20..0579ac9d 100644
--- a/tests/testattributes.c
+++ b/tests/testattributes.c
@@ -21,6 +21,8 @@
 
 #include <pango/pango.h>
 
+#include <stdlib.h>
+
 static void
 test_copy (PangoAttribute *attr)
 {
@@ -126,6 +128,7 @@ test_attributes_register (void)
   gboolean ret;
   PangoAttrList *list;
   char *str;
+  char **str_split;
 
   type = pango_attr_type_register ("my-attribute",
                                    PANGO_ATTR_VALUE_POINTER,
@@ -155,7 +158,20 @@ test_attributes_register (void)
   pango_attr_list_insert (list, attr2);
 
   str = pango_attr_list_to_string (list);
-  g_assert_cmpstr (str, ==, "0 4294967295 my-attribute 0x43");
+
+/*
+ * The output of %p format identifer is platform-dependent, so check individual
+ * segments of the output string, and check whether the value that is output by %p
+ * match the hex value that we expect.
+ *
+ * See: https://stackoverflow.com/questions/2369541/where-is-p-useful-with-printf
+ */
+  str_split = g_strsplit (str, " ", 0);
+  g_assert_cmpstr (str_split[0], ==, "0");
+  g_assert_cmpstr (str_split[1], ==, "4294967295");
+  g_assert_cmpstr (str_split[2], ==, "my-attribute");
+  g_assert_cmpint (strtol (str_split[3], NULL, 16), ==, 0x43);
+  g_strfreev (str_split);
   g_free (str);
 
   pango_attr_list_unref (list);


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