[pango/matthiasc/for-master: 1/2] tests: Locale handling fixes




commit 5d8694fd3085ce6d870d49f96f9cdd07de151f8e
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Jul 10 17:14:39 2021 -0400

    tests: Locale handling fixes
    
    The return value of setlocale is only good until
    the next call. Also, consistently use en_US.UTF-8.

 tests/meson.build    |  1 +
 tests/test-break.c   |  2 +-
 tests/test-font.c    |  1 -
 tests/test-itemize.c |  6 ++++--
 tests/test-layout.c  | 10 ++++++----
 tests/test-shape.c   |  1 -
 6 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index baf5ad6b..841a78eb 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -16,6 +16,7 @@ test_env = environment()
 test_env.set('srcdir', meson.current_source_dir())
 test_env.set('G_TEST_SRCDIR', meson.current_source_dir())
 test_env.set('G_TEST_BUILDDIR', meson.current_build_dir())
+test_env.set('LC_ALL', 'en_US.UTF-8')
 
 tests = [
   [ 'test-bidi' ],
diff --git a/tests/test-break.c b/tests/test-break.c
index 0158bd40..66c207a5 100644
--- a/tests/test-break.c
+++ b/tests/test-break.c
@@ -292,7 +292,7 @@ test_break (gconstpointer d)
   gchar *diff;
 
   char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
-  setlocale (LC_ALL, "en_US.utf8");
+  setlocale (LC_ALL, "en_US.UTF-8");
   if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL)
     {
       char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping break %s", filename);
diff --git a/tests/test-font.c b/tests/test-font.c
index 3c5f3070..f291cec8 100644
--- a/tests/test-font.c
+++ b/tests/test-font.c
@@ -463,7 +463,6 @@ test_match (void)
 int
 main (int argc, char *argv[])
 {
-  g_setenv ("LC_ALL", "C", TRUE);
   setlocale (LC_ALL, "");
 
   g_test_init (&argc, &argv, NULL);
diff --git a/tests/test-itemize.c b/tests/test-itemize.c
index d1447a0f..52556284 100644
--- a/tests/test-itemize.c
+++ b/tests/test-itemize.c
@@ -237,13 +237,14 @@ test_itemize (gconstpointer d)
   GString *dump;
   gchar *diff;
 
-  const char *old_locale = setlocale (LC_ALL, NULL);
-  setlocale (LC_ALL, "en_US.utf8");
+  char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
+  setlocale (LC_ALL, "en_US.UTF-8");
   if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL)
     {
       char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping itemization %s", filename);
       g_test_skip (msg);
       g_free (msg);
+      g_free (old_locale);
       return;
     }
 
@@ -259,6 +260,7 @@ test_itemize (gconstpointer d)
   g_assert_no_error (error);
 
   setlocale (LC_ALL, old_locale);
+  g_free (old_locale);
 
   if (diff && diff[0])
     {
diff --git a/tests/test-layout.c b/tests/test-layout.c
index ca9e5da5..502bc98a 100644
--- a/tests/test-layout.c
+++ b/tests/test-layout.c
@@ -703,13 +703,14 @@ test_layout (gconstpointer d)
   GString *dump;
   gchar *diff;
 
-  const char *old_locale = setlocale (LC_ALL, NULL);
-  setlocale (LC_ALL, "en_US.utf8");
+  char *old_locale = g_strdup (setlocale (LC_ALL, NULL));
+  setlocale (LC_ALL, "en_US.UTF-8");
   if (strstr (setlocale (LC_ALL, NULL), "en_US") == NULL)
     {
       char *msg = g_strdup_printf ("Locale en_US.UTF-8 not available, skipping layout %s", filename);
       g_test_skip (msg);
       g_free (msg);
+      g_free (old_locale);
       return;
     }
 
@@ -726,6 +727,7 @@ test_layout (gconstpointer d)
   g_assert_no_error (error);
 
   setlocale (LC_ALL, old_locale);
+  g_free (old_locale);
 
   if (diff && diff[0])
     {
@@ -755,6 +757,8 @@ main (int argc, char *argv[])
   const gchar *name;
   gchar *path;
 
+  setlocale (LC_ALL, "");
+
   if (g_getenv ("PANGO_TEST_SHOW_FONT"))
     opt_show_font = TRUE;
 
@@ -763,8 +767,6 @@ main (int argc, char *argv[])
     {
       GString *string;
 
-      setlocale (LC_ALL, "en_US.utf8");
-
       string = g_string_sized_new (0);
       test_file (argv[1], string);
       g_print ("%s", string->str);
diff --git a/tests/test-shape.c b/tests/test-shape.c
index be3e4415..a04291e4 100644
--- a/tests/test-shape.c
+++ b/tests/test-shape.c
@@ -337,7 +337,6 @@ main (int argc, char *argv[])
   const gchar *name;
   gchar *path;
 
-  g_setenv ("LC_ALL", "en_US.UTF-8", TRUE);
   setlocale (LC_ALL, "");
 
   g_test_init (&argc, &argv, NULL);


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