void wxLocale::DoCommonInit()
{
- m_pszOldLocale = NULL;
+ // Store the current locale in order to be able to restore it in the dtor.
+ m_pszOldLocale = wxSetlocale(LC_ALL, NULL);
+ if ( m_pszOldLocale )
+ m_pszOldLocale = wxStrdup(m_pszOldLocale);
+
m_pOldLocale = wxSetLocale(this);
wxS("no locale to set in wxLocale::Init()") );
}
- const char *oldLocale = wxSetlocale(LC_ALL, szLocale);
- if ( oldLocale )
- m_pszOldLocale = wxStrdup(oldLocale);
- else
- m_pszOldLocale = NULL;
-
- if ( m_pszOldLocale == NULL )
+ if ( !wxSetlocale(LC_ALL, szLocale) )
{
wxLogError(_("locale '%s' cannot be set."), szLocale);
}
private:
CPPUNIT_TEST_SUITE( IntlTestCase );
+ CPPUNIT_TEST( RestoreLocale );
CPPUNIT_TEST( Domain );
CPPUNIT_TEST( Headers );
CPPUNIT_TEST( DateTimeFmtFrench );
CPPUNIT_TEST( IsAvailable );
CPPUNIT_TEST_SUITE_END();
+ void RestoreLocale();
void Domain();
void Headers();
void DateTimeFmtFrench();
void DateTimeFmtC();
void IsAvailable();
+ static wxString GetDecimalPoint()
+ {
+ return wxLocale::GetInfo(wxLOCALE_DECIMAL_POINT, wxLOCALE_CAT_NUMBER);
+ }
+
wxLocale *m_locale;
DECLARE_NO_COPY_CLASS(IntlTestCase)
}
}
+void IntlTestCase::RestoreLocale()
+{
+ if ( !m_locale )
+ return;
+
+ // We must be using the French locale now, it was changed in setUp().
+ CPPUNIT_ASSERT_EQUAL( ",", GetDecimalPoint() );
+
+ // Switch to the English locale.
+ {
+ wxLocale locEn(wxLANGUAGE_ENGLISH);
+ CPPUNIT_ASSERT_EQUAL( ".", GetDecimalPoint() );
+ }
+
+ // Verify that after destroying the English locale object, French locale is
+ // restored.
+ CPPUNIT_ASSERT_EQUAL( ",", GetDecimalPoint() );
+}
+
void IntlTestCase::Domain()
{
if (!m_locale)