[glib: 3/7] glib/tests: fix test_turkish_strupdown




commit 4403704826c99b0b032d143c2d63d9e501b0aa74
Author: Marc-André Lureau <marcandre lureau redhat com>
Date:   Tue Jan 25 16:08:28 2022 +0400

    glib/tests: fix test_turkish_strupdown
    
    Signed-off-by: Marc-André Lureau <marcandre lureau redhat com>

 glib/tests/unicode.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/glib/tests/unicode.c b/glib/tests/unicode.c
index 61e835a4ed..6932140970 100644
--- a/glib/tests/unicode.c
+++ b/glib/tests/unicode.c
@@ -493,15 +493,29 @@ test_turkish_strupdown (void)
                     "\xcc\x87"  /* COMBINING DOT ABOVE (U+307) */
                     "\xc4\xb1"  /* LATIN SMALL LETTER DOTLESS I (U+131) */
                     "\xc4\xb0"; /* LATIN CAPITAL LETTER I WITH DOT ABOVE (U+130) */
+  char *oldlocale;
+  char *old_lc_all, *old_lc_messages, *old_lang;
+#ifdef G_OS_WIN32
+  LCID old_lcid;
+#endif
 
-  char *oldlocale = g_strdup (setlocale (LC_ALL, "tr_TR"));
+  /* interferes with g_win32_getlocale() */
+  save_and_clear_env ("LC_ALL", &old_lc_all);
+  save_and_clear_env ("LC_MESSAGES", &old_lc_messages);
+  save_and_clear_env ("LANG", &old_lang);
 
+  oldlocale = g_strdup (setlocale (LC_ALL, "tr_TR"));
   if (oldlocale == NULL)
     {
       g_test_skip ("locale tr_TR not available");
       return;
     }
 
+#ifdef G_OS_WIN32
+  old_lcid = GetThreadLocale ();
+  SetThreadLocale (MAKELCID (MAKELANGID (LANG_TURKISH, SUBLANG_TURKISH_TURKEY), SORT_DEFAULT));
+#endif
+
   str_up = g_utf8_strup (str, strlen (str));
   str_down = g_utf8_strdown (str, strlen (str));
   /* i => LATIN CAPITAL LETTER I WITH DOT ABOVE,
@@ -520,7 +534,19 @@ test_turkish_strupdown (void)
   g_free (str_down);
 
   setlocale (LC_ALL, oldlocale);
+#ifdef G_OS_WIN32
+  SetThreadLocale (old_lcid);
+#endif
   g_free (oldlocale);
+  if (old_lc_all)
+    g_setenv ("LC_ALL", old_lc_all, TRUE);
+  if (old_lc_messages)
+    g_setenv ("LC_MESSAGES", old_lc_messages, TRUE);
+  if (old_lang)
+    g_setenv ("LANG", old_lang, TRUE);
+  g_free (old_lc_all);
+  g_free (old_lc_messages);
+  g_free (old_lang);
 }
 
 /* Test that g_utf8_casefold() returns the correct value for various


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