X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8e18d24865ffe4d060a07c929e005e6588569dae..ac448bc0a009d4fe37a21ef75c79eb827e5e740a:/tests/xlocale/xlocale.cpp diff --git a/tests/xlocale/xlocale.cpp b/tests/xlocale/xlocale.cpp index 56c955367c..d2e8b68bb1 100644 --- a/tests/xlocale/xlocale.cpp +++ b/tests/xlocale/xlocale.cpp @@ -3,7 +3,6 @@ // Purpose: wxXLocale & related unit test // Author: Brian Vanderburg II, Vadim Zeitlin // Created: 2008-01-16 -// RCS-ID: $Id$ // Copyright: (c) 2008 Brian Vanderburg II // 2008 Vadim Zeitlin // Licence: wxWindows licence @@ -39,11 +38,13 @@ public: private: CPPUNIT_TEST_SUITE( XLocaleTestCase ); CPPUNIT_TEST( TestCtor ); + CPPUNIT_TEST( PreserveLocale ); CPPUNIT_TEST( TestCtypeFunctions ); CPPUNIT_TEST( TestStdlibFunctions ); CPPUNIT_TEST_SUITE_END(); void TestCtor(); + void PreserveLocale(); void TestCtypeFunctions(); void TestStdlibFunctions(); @@ -56,7 +57,7 @@ private: // register in the unnamed registry so that these tests are run by default CPPUNIT_TEST_SUITE_REGISTRATION( XLocaleTestCase ); -// also include in it's own registry so that these tests can be run alone +// also include in its own registry so that these tests can be run alone CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XLocaleTestCase, "XLocaleTestCase" ); @@ -73,7 +74,7 @@ void XLocaleTestCase::TestCtor() #ifdef wxHAS_XLOCALE_SUPPORT CPPUNIT_ASSERT( wxXLocale(wxLANGUAGE_FRENCH).IsOk() ); -#ifdef __WXMSW__ +#ifdef __WINDOWS__ CPPUNIT_ASSERT( wxXLocale("french").IsOk() ); #else CPPUNIT_ASSERT( wxXLocale("fr_FR").IsOk() ); @@ -81,6 +82,16 @@ void XLocaleTestCase::TestCtor() #endif } +void XLocaleTestCase::PreserveLocale() +{ + // Test that using locale functions doesn't change the global C locale. + const wxString origLocale(setlocale(LC_ALL, NULL)); + + wxStrtod_l(wxT("1.234"), NULL, wxCLocale); + + CPPUNIT_ASSERT_EQUAL( origLocale, setlocale(LC_ALL, NULL) ); +} + // test the ctype functions with the given locale void XLocaleTestCase::TestCtypeFunctionsWith(const wxXLocale& loc) { @@ -202,12 +213,12 @@ void XLocaleTestCase::TestStdlibFunctionsWith(const wxXLocale& 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( (unsigned long)3147483647, wxStrtoul_l(wxT("3147483647"), NULL, 0, loc) ); - CPPUNIT_ASSERT_EQUAL( (unsigned long)0xEE6B2800, wxStrtoul_l(wxT("0xEE6B2800"), NULL, 0, loc) ); + 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 } @@ -246,7 +257,7 @@ void XLocaleTestCase::TestCtypeFunctions() 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 @@ -284,11 +295,11 @@ void XLocaleTestCase::TestStdlibFunctions() // 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)) @@ -301,7 +312,7 @@ void XLocaleTestCase::TestStdlibFunctions() // 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