Test for wxXLocale availability directly in the unit test

Apparently a locale can be available at MSW level, so that
wxLocale::IsAvailable() returns true, but not supported by the MSVC CRT,
so that constructing the corresponding wxXLocale fails, which resulted
in wxXLocale unit test failures.

Fix them by checking that wxXLocale can be constructed directly instead
of using wxLocale::IsAvailable() as a proxy.

This is not ideal and perhaps wxLocale::IsAvailable() should check that
the locale is supported in wxXLocale too, but should at least allow unit
tests to pass on AppVeyor for now.
This commit is contained in:
Vadim Zeitlin
2017-11-25 12:11:40 +01:00
parent 62f9438ad3
commit 01cd702ee3

View File

@@ -225,17 +225,20 @@ void XLocaleTestCase::TestStdlibFunctionsWith(const wxXLocale& loc)
void XLocaleTestCase::TestCtypeFunctions() void XLocaleTestCase::TestCtypeFunctions()
{ {
SECTION("C")
{
TestCtypeFunctionsWith(wxCLocale); TestCtypeFunctionsWith(wxCLocale);
}
#ifdef wxHAS_XLOCALE_SUPPORT #ifdef wxHAS_XLOCALE_SUPPORT
SECTION("French")
// french {
if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH))
return; // you should have french support installed to continue this test!
wxXLocale locFR(wxLANGUAGE_FRENCH); wxXLocale locFR(wxLANGUAGE_FRENCH);
CPPUNIT_ASSERT( locFR.IsOk() ); // doesn't make sense to continue otherwise if ( !locFR.IsOk() )
{
// Not an error, not all systems have French locale support.
return;
}
TestCtypeFunctionsWith(locFR); TestCtypeFunctionsWith(locFR);
@@ -246,25 +249,26 @@ void XLocaleTestCase::TestCtypeFunctions()
CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe7'), locFR) ); CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe7'), locFR) );
CPPUNIT_ASSERT( wxIslower_l(wxT('\xe7'), locFR) ); CPPUNIT_ASSERT( wxIslower_l(wxT('\xe7'), locFR) );
CPPUNIT_ASSERT( wxIsupper_l(wxT('\xc7'), locFR) ); CPPUNIT_ASSERT( wxIsupper_l(wxT('\xc7'), locFR) );
}
SECTION("Italian")
// italian {
if (!wxLocale::IsAvailable(wxLANGUAGE_ITALIAN))
return; // you should have italian support installed to continue this test!
wxXLocale locIT(wxLANGUAGE_ITALIAN); wxXLocale locIT(wxLANGUAGE_ITALIAN);
CPPUNIT_ASSERT( locIT.IsOk() ); // doesn't make sense to continue otherwise if ( !locIT.IsOk() )
return;
TestCtypeFunctionsWith(locIT); TestCtypeFunctionsWith(locIT);
CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe1'), locIT) ); CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe1'), locIT) );
CPPUNIT_ASSERT( wxIslower_l(wxT('\xe1'), locIT) ); CPPUNIT_ASSERT( wxIslower_l(wxT('\xe1'), locIT) );
#endif }
#endif // wxHAS_XLOCALE_SUPPORT
} }
void XLocaleTestCase::TestStdlibFunctions() void XLocaleTestCase::TestStdlibFunctions()
{ {
SECTION("C")
{
TestStdlibFunctionsWith(wxCLocale); TestStdlibFunctionsWith(wxCLocale);
#if wxUSE_UNICODE #if wxUSE_UNICODE
@@ -280,16 +284,14 @@ void XLocaleTestCase::TestStdlibFunctions()
CPPUNIT_ASSERT_EQUAL( -1.234E-5, wxStrtod_l(wxT("-1.234E-5"), 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( 365.24, wxStrtod_l(wxT("365.24 29.53"), &endptr, wxCLocale) );
CPPUNIT_ASSERT_EQUAL( 29.53, wxStrtod_l(endptr, NULL, wxCLocale) ); CPPUNIT_ASSERT_EQUAL( 29.53, wxStrtod_l(endptr, NULL, wxCLocale) );
}
#ifdef wxHAS_XLOCALE_SUPPORT #ifdef wxHAS_XLOCALE_SUPPORT
SECTION("French")
// french {
if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH))
return; // you should have french support installed to continue this test!
wxXLocale locFR(wxLANGUAGE_FRENCH); wxXLocale locFR(wxLANGUAGE_FRENCH);
CPPUNIT_ASSERT( locFR.IsOk() ); // doesn't make sense to continue otherwise if ( !locFR.IsOk() )
return;
TestCtypeFunctionsWith(locFR); TestCtypeFunctionsWith(locFR);
@@ -298,15 +300,14 @@ void XLocaleTestCase::TestStdlibFunctions()
// space as thousands separator is not recognized by wxStrtod_l(): // space as thousands separator is not recognized by wxStrtod_l():
CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1 234,5"), NULL, locFR) ); CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1 234,5"), NULL, locFR) );
}
// italian SECTION("Italian")
{
if (!wxLocale::IsAvailable(wxLANGUAGE_ITALIAN))
return; // you should have italian support installed to continue this test!
wxXLocale locIT(wxLANGUAGE_ITALIAN); wxXLocale locIT(wxLANGUAGE_ITALIAN);
CPPUNIT_ASSERT( locIT.IsOk() ); // doesn't make sense to continue otherwise if ( !locIT.IsOk() )
return;
TestStdlibFunctionsWith(locIT); TestStdlibFunctionsWith(locIT);
@@ -315,7 +316,8 @@ void XLocaleTestCase::TestStdlibFunctions()
// dot as thousands separator is not recognized by wxStrtod_l(): // dot as thousands separator is not recognized by wxStrtod_l():
CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1.234,5"), NULL, locIT) ); CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1.234,5"), NULL, locIT) );
#endif }
#endif // wxHAS_XLOCALE_SUPPORT
} }
#endif // wxUSE_XLOCALE #endif // wxUSE_XLOCALE