[pango/pango2-windows: 49/50] testattributes: Fix test on Windows




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

    testattributes: Fix test on Windows
    
    The %p format indentifier is handled differently at least on Windows
    due to the underlying system CRT implementation, so check for 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 numerical value.

 tests/testattributes.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
---
diff --git a/tests/testattributes.c b/tests/testattributes.c
index 63f37bdd..6b22734e 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,15 @@ 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 Visual Studio CRT handles the format of the output produced by %p differently... */
+/* 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, 10), ==, 43);
+  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]