Merge branch 'ui-locale'
Add wxUILocale class providing functionality which can be implemented portably for all major platforms, including macOS, and doesn't force the change of the global C locale, unlike wxLocale. See https://github.com/wxWidgets/wxWidgets/pull/2464
This commit is contained in:
@@ -33,6 +33,8 @@
|
||||
#include "wx/stopwatch.h"
|
||||
#endif
|
||||
|
||||
#include "wx/private/localeset.h"
|
||||
|
||||
#include "textentrytest.h"
|
||||
#include "testableframe.h"
|
||||
#include "asserthelper.h"
|
||||
@@ -295,7 +297,7 @@ void TextCtrlTestCase::StreamInput()
|
||||
#ifndef __WXOSX__
|
||||
{
|
||||
// Ensure we use decimal point and not a comma.
|
||||
LocaleSetter setCLocale("C");
|
||||
wxCLocaleSetter setCLocale;
|
||||
|
||||
*m_text << "stringinput"
|
||||
<< 10
|
||||
|
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "wx/wxcrt.h" // for wxStrstr()
|
||||
|
||||
#include "wx/private/localeset.h"
|
||||
|
||||
// to test Today() meaningfully we must be able to change the system date which
|
||||
// is not usually the case, but if we're under Win32 we can try it -- define
|
||||
// the macro below to do it
|
||||
@@ -1304,7 +1306,7 @@ void DateTimeTestCase::TestDateTimeParse()
|
||||
|
||||
// the test strings here use "PM" which is not available in all locales so
|
||||
// we need to use "C" locale for them
|
||||
CLocaleSetter cloc;
|
||||
wxCLocaleSetter cloc;
|
||||
|
||||
wxDateTime dt;
|
||||
for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
|
||||
|
@@ -22,6 +22,8 @@
|
||||
#include "wx/stdpaths.h"
|
||||
#include "wx/scopeguard.h"
|
||||
|
||||
#include "wx/private/localeset.h"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/msw/registry.h"
|
||||
#include "wx/msw/wrapshl.h"
|
||||
@@ -493,7 +495,7 @@ TEST_CASE("wxFileName::GetHumanReadable", "[filename]")
|
||||
{ "304 KB", 304351, 0, wxSIZE_CONV_SI },
|
||||
};
|
||||
|
||||
CLocaleSetter loc; // we want to use "C" locale for LC_NUMERIC
|
||||
wxCLocaleSetter loc; // we want to use "C" locale for LC_NUMERIC
|
||||
// so that regardless of the system's locale
|
||||
// the decimal point used by GetHumanReadableSize()
|
||||
// is always '.'
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/intl.h"
|
||||
#include "wx/uilocale.h"
|
||||
|
||||
#if wxUSE_INTL
|
||||
|
||||
@@ -239,4 +240,17 @@ TEST_CASE("wxLocale::Default", "[locale]")
|
||||
|
||||
#endif // wxUSE_UNICODE
|
||||
|
||||
// This test doesn't run by default as it only works in locales using decimal
|
||||
// point as separator, which doesn't need to be the case.
|
||||
TEST_CASE("wxUILocale::GetInfo", "[.][uilocale]")
|
||||
{
|
||||
REQUIRE( wxUILocale::UseDefault() );
|
||||
|
||||
const wxUILocale& loc = wxUILocale::GetCurrent();
|
||||
|
||||
WARN( "Using locale " << loc.GetName() );
|
||||
|
||||
CHECK( loc.GetInfo(wxLOCALE_DECIMAL_POINT) == "." );
|
||||
}
|
||||
|
||||
#endif // wxUSE_INTL
|
||||
|
@@ -22,6 +22,8 @@
|
||||
#include "wx/txtstrm.h"
|
||||
#include "wx/mstream.h"
|
||||
|
||||
#include "wx/private/localeset.h"
|
||||
|
||||
#if defined wxHAVE_TCHAR_SUPPORT && !defined HAVE_WCHAR_H
|
||||
#define HAVE_WCHAR_H
|
||||
#endif
|
||||
@@ -1106,7 +1108,7 @@ void MBConvTestCase::LibcTests()
|
||||
// supposed to use the same CRT -- no idea why and unfortunately gdb is too
|
||||
// flaky to debug it)
|
||||
#ifdef __VISUALC__
|
||||
LocaleSetter loc("English_United States.1252");
|
||||
wxLocaleSetter loc("English_United States.1252");
|
||||
|
||||
wxMBConvLibc convLibc;
|
||||
TestCoder(
|
||||
|
@@ -24,6 +24,7 @@
|
||||
#include "wx/wxchar.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/private/localeset.h"
|
||||
|
||||
// NOTE: for more info about the specification of wxVsnprintf() behaviour you can
|
||||
// refer to the following page of the GNU libc manual:
|
||||
@@ -85,10 +86,10 @@ wxUnsafeSnprintf(T *buf, size_t len, const wxChar *fmt, ...)
|
||||
|
||||
// Explicitly set C locale to avoid check failures when running on machines
|
||||
// with a locale where the decimal point is not '.'
|
||||
class VsnprintfTestCase : CLocaleSetter
|
||||
class VsnprintfTestCase : wxCLocaleSetter
|
||||
{
|
||||
public:
|
||||
VsnprintfTestCase() : CLocaleSetter() { }
|
||||
VsnprintfTestCase() : wxCLocaleSetter() { }
|
||||
|
||||
protected:
|
||||
template<typename T>
|
||||
|
@@ -148,38 +148,6 @@ extern bool IsAutomaticTest();
|
||||
|
||||
extern bool IsRunningUnderXVFB();
|
||||
|
||||
// Helper class setting the locale to the given one for its lifetime.
|
||||
class LocaleSetter
|
||||
{
|
||||
public:
|
||||
LocaleSetter(const char *loc)
|
||||
: m_locOld(wxStrdupA(setlocale(LC_ALL, NULL)))
|
||||
{
|
||||
setlocale(LC_ALL, loc);
|
||||
}
|
||||
|
||||
~LocaleSetter()
|
||||
{
|
||||
setlocale(LC_ALL, m_locOld);
|
||||
free(m_locOld);
|
||||
}
|
||||
|
||||
private:
|
||||
char * const m_locOld;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(LocaleSetter);
|
||||
};
|
||||
|
||||
// An even simpler helper for setting the locale to "C" one during its lifetime.
|
||||
class CLocaleSetter : private LocaleSetter
|
||||
{
|
||||
public:
|
||||
CLocaleSetter() : LocaleSetter("C") { }
|
||||
|
||||
private:
|
||||
wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
|
||||
};
|
||||
|
||||
#if wxUSE_GUI
|
||||
|
||||
// Return true if the UI tests are enabled, used by WXUISIM_TEST().
|
||||
|
Reference in New Issue
Block a user