X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d8a696fb5f4b7968fcfb3f81e139c6038007cea1..fdb97de42b8a1491257566fb7bbd343916f1f2b8:/tests/intl/intltest.cpp diff --git a/tests/intl/intltest.cpp b/tests/intl/intltest.cpp index 40f31f06bd..094d6bedf5 100644 --- a/tests/intl/intltest.cpp +++ b/tests/intl/intltest.cpp @@ -41,12 +41,14 @@ private: CPPUNIT_TEST_SUITE( IntlTestCase ); CPPUNIT_TEST( Domain ); CPPUNIT_TEST( Headers ); - CPPUNIT_TEST( DateTimeFmt ); + CPPUNIT_TEST( DateTimeFmtFrench ); + CPPUNIT_TEST( DateTimeFmtC ); CPPUNIT_TEST_SUITE_END(); void Domain(); void Headers(); - void DateTimeFmt(); + void DateTimeFmtFrench(); + void DateTimeFmtC(); wxLocale *m_locale; @@ -123,26 +125,26 @@ void IntlTestCase::Headers() CPPUNIT_ASSERT_EQUAL( "", m_locale->GetHeaderValue("X-Not-Here") ); } -static void -CompareFormats(const char *msg, const wxString& expected, wxString actual) +static wxString +NormalizeFormat(const wxString& fmtOrig) { - if ( actual.empty() ) - { - // this means that GetInfo() failed which can happen, just ignore - return; - } + wxString fmt(fmtOrig); #ifdef __GLIBC__ // glibc uses some extensions in its formats which we need to convert to // standard form - actual.Replace("%T", "%H:%M:%S"); - actual.Replace("%e", "%d"); + fmt.Replace("%T", "%H:%M:%S"); + fmt.Replace("%e", "%d"); #endif // __GLIBC__ - CPPUNIT_ASSERT_EQUAL_MESSAGE( msg, expected, actual ); + return fmt; } -void IntlTestCase::DateTimeFmt() +#define WX_ASSERT_EQUAL_FORMAT(msg, expected, actual) \ + if ( !actual.empty() ) \ + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg, expected, NormalizeFormat(actual)) + +void IntlTestCase::DateTimeFmtFrench() { if ( !m_locale ) return; @@ -151,29 +153,54 @@ void IntlTestCase::DateTimeFmt() // glibc also uses dots for French locale separator for some reason (the // standard format uses slashes) static const char *FRENCH_DATE_FMT = "%d.%m.%Y"; + static const char *FRENCH_LONG_DATE_FMT = "%a %d %b %Y"; + static const char *FRENCH_DATE_TIME_FMT = "%a %d %b %Y %H:%M:%S %Z"; #else - static const char *FRENCH_DATE_FMT = "%d/%m/%y"; + static const char *FRENCH_DATE_FMT = "%d/%m/%Y"; + static const char *FRENCH_LONG_DATE_FMT = "%A %d %B %Y"; +#ifdef __WXOSX__ + static const char *FRENCH_DATE_TIME_FMT = "%A %d %B %Y %H:%M:%S"; +#else + static const char *FRENCH_DATE_TIME_FMT = "%d/%m/%Y %H:%M:%S"; +#endif #endif - CompareFormats( "French short date", FRENCH_DATE_FMT, + WX_ASSERT_EQUAL_FORMAT( "French short date", FRENCH_DATE_FMT, m_locale->GetInfo(wxLOCALE_SHORT_DATE_FMT) ); - CompareFormats( "French long date", "%a %d %b %Y", + WX_ASSERT_EQUAL_FORMAT( "French long date", FRENCH_LONG_DATE_FMT, m_locale->GetInfo(wxLOCALE_LONG_DATE_FMT) ); - CompareFormats( "French date and time", "%a %d %b %Y %H:%M:%S %Z", + WX_ASSERT_EQUAL_FORMAT( "French date and time", FRENCH_DATE_TIME_FMT, m_locale->GetInfo(wxLOCALE_DATE_TIME_FMT) ); - CompareFormats( "French time", "%H:%M:%S", + WX_ASSERT_EQUAL_FORMAT( "French time", "%H:%M:%S", m_locale->GetInfo(wxLOCALE_TIME_FMT) ); +} + +void IntlTestCase::DateTimeFmtC() +{ + // again, glibc uses different defaults +#ifdef __GLIBC__ + static const char *C_DATE_FMT = "%m/%d/%y"; + static const char *C_LONG_DATE_FMT = "%a %b %d %Y"; + static const char *C_DATE_TIME_FMT = "%a %b %d %H:%M:%S %Y"; +#else + static const char *C_DATE_FMT = "%d/%m/%Y"; + static const char *C_LONG_DATE_FMT = "%A %d %B %Y"; +#ifdef __WXOSX__ + static const char *C_DATE_TIME_FMT = "%A %d %B %Y %H:%M:%S"; +#else + static const char *C_DATE_TIME_FMT = "%d/%m/%Y %H:%M:%S"; +#endif +#endif - // also test for "C" locale setlocale(LC_ALL, "C"); - CompareFormats( "C short date", "%m/%d/%y", + WX_ASSERT_EQUAL_FORMAT( "C short date", C_DATE_FMT, m_locale->GetInfo(wxLOCALE_SHORT_DATE_FMT) ); - CompareFormats( "C long date", "%a %b %d %Y", + WX_ASSERT_EQUAL_FORMAT( "C long date", C_LONG_DATE_FMT, m_locale->GetInfo(wxLOCALE_LONG_DATE_FMT) ); - CompareFormats( "C date and time", "%a %b %d %H:%M:%S %Y", + WX_ASSERT_EQUAL_FORMAT( "C date and time", C_DATE_TIME_FMT, m_locale->GetInfo(wxLOCALE_DATE_TIME_FMT) ); - CompareFormats( "C time", "%H:%M:%S", + WX_ASSERT_EQUAL_FORMAT( "C time", "%H:%M:%S", m_locale->GetInfo(wxLOCALE_TIME_FMT) ); }