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.
This commit is contained in:
Chun-wei Fan 2023-02-21 15:31:22 +08:00
parent a8e8b742e7
commit 601fce37cb

View File

@ -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
}