X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f9727b1be58d5cc9be85d12f8d47f3544f881b97..6bd1764f2716e8d0814edd6374b20960bba23579:/tests/xlocale/xlocale.cpp diff --git a/tests/xlocale/xlocale.cpp b/tests/xlocale/xlocale.cpp index d0502e4887..9feddf9a2c 100644 --- a/tests/xlocale/xlocale.cpp +++ b/tests/xlocale/xlocale.cpp @@ -40,12 +40,15 @@ private: CPPUNIT_TEST_SUITE( XLocaleTestCase ); CPPUNIT_TEST( TestCtor ); CPPUNIT_TEST( TestCtypeFunctions ); + CPPUNIT_TEST( TestStdlibFunctions ); CPPUNIT_TEST_SUITE_END(); void TestCtor(); void TestCtypeFunctions(); + void TestStdlibFunctions(); void TestCtypeFunctionsWith(const wxXLocale& loc); + void TestStdlibFunctionsWith(const wxXLocale& loc); DECLARE_NO_COPY_CLASS(XLocaleTestCase) }; @@ -63,6 +66,11 @@ void XLocaleTestCase::TestCtor() CPPUNIT_ASSERT( !wxXLocale().IsOk() ); CPPUNIT_ASSERT( wxCLocale.IsOk() ); CPPUNIT_ASSERT( wxXLocale("C").IsOk() ); + CPPUNIT_ASSERT( !wxXLocale("bloordyblop").IsOk() ); + + if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH)) + return; // you should have french support installed to continue this test! + #ifdef wxHAS_XLOCALE_SUPPORT CPPUNIT_ASSERT( wxXLocale(wxLANGUAGE_FRENCH).IsOk() ); #ifdef __WXMSW__ @@ -71,12 +79,15 @@ void XLocaleTestCase::TestCtor() CPPUNIT_ASSERT( wxXLocale("fr_FR").IsOk() ); #endif #endif - CPPUNIT_ASSERT( !wxXLocale("bloordyblop").IsOk() ); } // test the ctype functions with the given locale void XLocaleTestCase::TestCtypeFunctionsWith(const wxXLocale& loc) { + // NOTE: here go the checks which must pass under _any_ locale "loc"; + // checks for specific locales are in TestCtypeFunctions() + + // isalnum CPPUNIT_ASSERT( wxIsalnum_l('0', loc) ); CPPUNIT_ASSERT( wxIsalnum_l('9', loc) ); @@ -167,20 +178,132 @@ void XLocaleTestCase::TestCtypeFunctionsWith(const wxXLocale& loc) CPPUNIT_ASSERT_EQUAL( '9', (char)wxToupper_l('9', loc) ); } +// test the stdlib functions with the given locale +void XLocaleTestCase::TestStdlibFunctionsWith(const wxXLocale& loc) +{ + // NOTE: here go the checks which must pass under _any_ locale "loc"; + // checks for specific locales are in TestStdlibFunctions() + +#if wxUSE_UNICODE + wchar_t* endptr; +#else + char* endptr; +#endif + + // strtod (don't use decimal separator as it's locale-specific) + CPPUNIT_ASSERT_EQUAL( 0.0, wxStrtod_l(wxT("0"), NULL, loc) ); + CPPUNIT_ASSERT_EQUAL( 1234.0, wxStrtod_l(wxT("1234"), NULL, loc) ); + + // strtol + endptr = NULL; + CPPUNIT_ASSERT_EQUAL( 100, wxStrtol_l(wxT("100"), NULL, 0, loc) ); + CPPUNIT_ASSERT_EQUAL( 0xFF, wxStrtol_l(wxT("0xFF"), NULL, 0, loc) ); + CPPUNIT_ASSERT_EQUAL( 2001, wxStrtol_l(wxT("2001 60c0c0 -1101110100110100100000 0x6fffff"), &endptr, 10, loc) ); + CPPUNIT_ASSERT_EQUAL( 0x60c0c0, wxStrtol_l(endptr, &endptr, 16, loc) ); + CPPUNIT_ASSERT_EQUAL( -0x374D20, wxStrtol_l(endptr, &endptr, 2, loc) ); + CPPUNIT_ASSERT_EQUAL( 0x6fffff, wxStrtol_l(endptr, NULL, 0, loc) ); + + // strtoul + // NOTE: 3147483647 and 0xEE6B2800 are greater than LONG_MAX (on 32bit machines) but + // smaller than ULONG_MAX + CPPUNIT_ASSERT_EQUAL( 3147483647ul, wxStrtoul_l(wxT("3147483647"), NULL, 0, loc) ); + CPPUNIT_ASSERT_EQUAL( 0xEE6B2800ul, wxStrtoul_l(wxT("0xEE6B2800"), NULL, 0, loc) ); + + // TODO: test for "failure" behaviour of the functions above +} + void XLocaleTestCase::TestCtypeFunctions() { TestCtypeFunctionsWith(wxCLocale); #ifdef wxHAS_XLOCALE_SUPPORT + + // french + + if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH)) + return; // you should have french support installed to continue this test! + + wxXLocale locFR(wxLANGUAGE_FRENCH); + CPPUNIT_ASSERT( locFR.IsOk() ); // doesn't make sense to continue otherwise + + TestCtypeFunctionsWith(locFR); + + CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe9'), locFR) ); + CPPUNIT_ASSERT( wxIslower_l(wxT('\xe9'), locFR) ); + CPPUNIT_ASSERT( !wxIslower_l(wxT('\xc9'), locFR) ); + CPPUNIT_ASSERT( wxIsupper_l(wxT('\xc9'), locFR) ); + CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe7'), locFR) ); + CPPUNIT_ASSERT( wxIslower_l(wxT('\xe7'), locFR) ); + CPPUNIT_ASSERT( wxIsupper_l(wxT('\xc7'), locFR) ); + + + // italian + + if (!wxLocale::IsAvailable(wxLANGUAGE_ITALIAN)) + return; // you should have italian support installed to continue this test! + + wxXLocale locIT(wxLANGUAGE_ITALIAN); + CPPUNIT_ASSERT( locIT.IsOk() ); // doesn't make sense to continue otherwise + + TestCtypeFunctionsWith(locIT); + + CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe1'), locIT) ); + CPPUNIT_ASSERT( wxIslower_l(wxT('\xe1'), locIT) ); +#endif +} + +void XLocaleTestCase::TestStdlibFunctions() +{ + TestStdlibFunctionsWith(wxCLocale); + +#if wxUSE_UNICODE + wchar_t* endptr; +#else + char* endptr; +#endif + + // strtod checks specific for C locale + endptr = NULL; + CPPUNIT_ASSERT_EQUAL( 0.0, wxStrtod_l(wxT("0.000"), NULL, wxCLocale) ); + CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1.234"), NULL, wxCLocale) ); + CPPUNIT_ASSERT_EQUAL( -1.234E-5, wxStrtod_l(wxT("-1.234E-5"), NULL, wxCLocale) ); + CPPUNIT_ASSERT_EQUAL( 365.24, wxStrtod_l(wxT("365.24 29.53"), &endptr, wxCLocale) ); + CPPUNIT_ASSERT_EQUAL( 29.53, wxStrtod_l(endptr, NULL, wxCLocale) ); + +#ifdef wxHAS_XLOCALE_SUPPORT + + // french + + if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH)) + return; // you should have french support installed to continue this test! + wxXLocale locFR(wxLANGUAGE_FRENCH); CPPUNIT_ASSERT( locFR.IsOk() ); // doesn't make sense to continue otherwise TestCtypeFunctionsWith(locFR); - CPPUNIT_ASSERT( wxIsalpha_l('é', locFR) ); - CPPUNIT_ASSERT( wxIslower_l('é', locFR) ); - CPPUNIT_ASSERT( !wxIslower_l('É', locFR) ); - CPPUNIT_ASSERT( wxIsupper_l('É', locFR) ); + // comma as decimal point: + CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1,234"), NULL, locFR) ); + + // space as thousands separator is not recognized by wxStrtod_l(): + CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1 234,5"), NULL, locFR) ); + + + // italian + + if (!wxLocale::IsAvailable(wxLANGUAGE_ITALIAN)) + return; // you should have italian support installed to continue this test! + + wxXLocale locIT(wxLANGUAGE_ITALIAN); + CPPUNIT_ASSERT( locIT.IsOk() ); // doesn't make sense to continue otherwise + + TestStdlibFunctionsWith(locIT); + + // comma as decimal point: + CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1,234"), NULL, locIT) ); + + // dot as thousands separator is not recognized by wxStrtod_l(): + CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1.234,5"), NULL, locIT) ); #endif }