Add a pseudo test to show system locale and language

This can be useful to compare the results of calling
wxUILocale::GetSystemLanguage() and the function with the same name in
wxLocale (which actually corresponds to wxUILocale::GetSystemLocale()).
This commit is contained in:
Vadim Zeitlin 2023-01-06 03:20:57 +01:00
parent 8b696319e7
commit 4c23721743

View file

@ -430,4 +430,73 @@ TEST_CASE("wxUILocale::FromTag", "[.]")
WARN("Locale \"" << tag << "\" supported: " << loc.IsSupported() );
}
namespace
{
const wxString GetLangName(int lang)
{
switch ( lang )
{
case wxLANGUAGE_DEFAULT:
return "DEFAULT";
case wxLANGUAGE_UNKNOWN:
return "UNKNOWN";
default:
return wxUILocale::GetLanguageName(lang);
}
}
wxString GetLocaleDesc(const char* when)
{
const wxUILocale& curloc = wxUILocale::GetCurrent();
const wxLocaleIdent locid = curloc.GetLocaleId();
// Make the output slightly more readable.
wxString decsep = curloc.GetInfo(wxLOCALE_DECIMAL_POINT);
if ( decsep == "." )
decsep = "point";
else if ( decsep == "," )
decsep = "comma";
else
decsep = wxString::Format("UNKNOWN (%s)", decsep);
return wxString::Format("%s\ncurrent locale:\t%s (decimal separator: %s)",
when,
locid.IsEmpty() ? wxString("NONE") : locid.GetTag(),
decsep);
}
} // anonymous namespace
// Test to show information about the system locale and the effects of various
// ways to change the current locale.
TEST_CASE("wxUILocale::ShowSystem", "[.]")
{
WARN("System locale:\t"
<< GetLangName(wxUILocale::GetSystemLocale()) << "\n"
"System language:\t"
<< GetLangName(wxUILocale::GetSystemLanguage()));
WARN(GetLocaleDesc("Before calling any locale functions"));
wxLocale locDef;
CHECK( locDef.Init(wxLANGUAGE_DEFAULT, wxLOCALE_DONT_LOAD_DEFAULT) );
WARN(GetLocaleDesc("After wxLocale::Init(wxLANGUAGE_DEFAULT)"));
REQUIRE( wxUILocale::UseDefault() );
WARN(GetLocaleDesc("After wxUILocale::UseDefault()"));
wxString preferredLangsStr;
const auto preferredLangs = wxUILocale::GetPreferredUILanguages();
for (const auto& lang: preferredLangs)
{
if ( !preferredLangsStr.empty() )
preferredLangsStr += ", ";
preferredLangsStr += lang;
}
WARN("Preferred UI languages:\n" << preferredLangsStr);
}
#endif // wxUSE_INTL