enforce "C" locale for tests which can't work in any other (because test data is in English)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59797 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2009-03-23 23:29:10 +00:00
parent 3aa3163f66
commit 34d4d2864c

View File

@ -83,6 +83,19 @@ private:
#endif // CHANGE_SYSTEM_DATE #endif // CHANGE_SYSTEM_DATE
// helper class setting the locale to "C" for its lifetime
class CLocaleSetter
{
public:
CLocaleSetter() : m_locOld(setlocale(LC_ALL, "C")) { }
~CLocaleSetter() { setlocale(LC_ALL, m_locOld); }
private:
const char * const m_locOld;
wxDECLARE_NO_COPY_CLASS(CLocaleSetter);
};
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// broken down date representation used for testing // broken down date representation used for testing
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -905,6 +918,10 @@ void DateTimeTestCase::TestDateParse()
CPPUNIT_ASSERT( dt.ParseDate(_T("today")) ); CPPUNIT_ASSERT( dt.ParseDate(_T("today")) );
CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), dt ); CPPUNIT_ASSERT_EQUAL( wxDateTime::Today(), dt );
// the other test strings use "C" locale so set it for the duration of this
// test
CLocaleSetter cloc;
for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ ) for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
{ {
const char * const datestr = parseTestDates[n].str; const char * const datestr = parseTestDates[n].str;
@ -1016,7 +1033,9 @@ void DateTimeTestCase::TestDateTimeParse()
{ 22, wxDateTime::Nov, 2007, 19, 40, 0}, true }, { 22, wxDateTime::Nov, 2007, 19, 40, 0}, true },
}; };
// special cases // the test strings use "C" locale so set it for the duration of this test
CLocaleSetter cloc;
wxDateTime dt; wxDateTime dt;
for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ ) for ( size_t n = 0; n < WXSIZEOF(parseTestDates); n++ )
{ {