[pango/pango2-windows: 1/3] testattributes: Fix test on Windows




commit 1b975368d42061845f2c206583e9aab4af7214ef
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 | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/tests/testattributes.c b/tests/testattributes.c
index 63f37bdd..abe83b15 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 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 */
+/* Also see 
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/strtol-wcstol-strtol-l-wcstol-l?view=msvc-170
+for how strtol (str, NULL, 0) is handled on Windows, under "Remarks" */
+  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");
+  if (str_split[3][0] == '0' && str_split[3][1] != '0')
+    g_assert_cmpint (strtol (str_split[3], NULL, 0), ==, 43);
+  else
+    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]