From 601fce37cb4a10b96f1594d8976ee3de9bd6259a Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Tue, 21 Feb 2023 15:31:22 +0800 Subject: [PATCH] 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. --- glib/tests/spawn-test.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/glib/tests/spawn-test.c b/glib/tests/spawn-test.c index 4e887af1ec..b1b2eac0ff 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 } -- GitLab