summaryrefslogtreecommitdiff
path: root/glib/tests
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2023-02-21 15:31:22 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2023-02-21 16:34:31 +0800
commit601fce37cb4a10b96f1594d8976ee3de9bd6259a (patch)
tree8229448286f835d8ca489cb935242fd23ba16e36 /glib/tests
parenta8e8b742e7926e33eb635a8edceac74cf239d6ed (diff)
downloadglib-601fce37cb4a10b96f1594d8976ee3de9bd6259a.tar.gz
spawn-test: Fix running on non-English Windows
Use SetThreadUILocale() to set the UI locale to English (United States) (en-US), and use SetConsoleOutputCP() to set the code page to en-US (codepage 437) so that g_win32_error_message() will always return the error messages in English and ensure that the program runs in English as well, so that we can ensure that the expected error message string can match up regardless of the languge version of Windows that is running.
Diffstat (limited to 'glib/tests')
-rw-r--r--glib/tests/spawn-test.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/glib/tests/spawn-test.c b/glib/tests/spawn-test.c
index 4e887af1e..b1b2eac0f 100644
--- a/glib/tests/spawn-test.c
+++ b/glib/tests/spawn-test.c
@@ -76,9 +76,11 @@ test_spawn_basics (void)
gchar *system_directory;
gchar spawn_binary[1000] = {0};
gchar full_cmdline[1000] = {0};
-#endif
+ const LCID old_lcid = GetThreadUILanguage ();
+ const unsigned int initial_cp = GetConsoleOutputCP ();
-#ifdef G_OS_WIN32
+ SetConsoleOutputCP (437); /* 437 means en-US codepage */
+ SetThreadUILanguage (MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT));
system_directory = get_system_directory ();
g_snprintf (spawn_binary, sizeof (spawn_binary),
@@ -254,6 +256,8 @@ test_spawn_basics (void)
#endif
#ifdef G_OS_WIN32
+ SetThreadUILanguage (old_lcid);
+ SetConsoleOutputCP (initial_cp); /* 437 means en-US codepage */
g_free (system_directory);
#endif
}