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,97 +225,99 @@ void XLocaleTestCase::TestStdlibFunctionsWith(const wxXLocale& loc)
void XLocaleTestCase::TestCtypeFunctions() void XLocaleTestCase::TestCtypeFunctions()
{ {
TestCtypeFunctionsWith(wxCLocale); SECTION("C")
{
TestCtypeFunctionsWith(wxCLocale);
}
#ifdef wxHAS_XLOCALE_SUPPORT #ifdef wxHAS_XLOCALE_SUPPORT
SECTION("French")
{
wxXLocale locFR(wxLANGUAGE_FRENCH);
if ( !locFR.IsOk() )
{
// Not an error, not all systems have French locale support.
return;
}
// french TestCtypeFunctionsWith(locFR);
if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH)) CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe9'), locFR) );
return; // you should have french support installed to continue this test! 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) );
}
wxXLocale locFR(wxLANGUAGE_FRENCH); SECTION("Italian")
CPPUNIT_ASSERT( locFR.IsOk() ); // doesn't make sense to continue otherwise {
wxXLocale locIT(wxLANGUAGE_ITALIAN);
if ( !locIT.IsOk() )
return;
TestCtypeFunctionsWith(locFR); TestCtypeFunctionsWith(locIT);
CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe9'), locFR) ); CPPUNIT_ASSERT( wxIsalpha_l(wxT('\xe1'), locIT) );
CPPUNIT_ASSERT( wxIslower_l(wxT('\xe9'), locFR) ); CPPUNIT_ASSERT( wxIslower_l(wxT('\xe1'), locIT) );
CPPUNIT_ASSERT( !wxIslower_l(wxT('\xc9'), locFR) ); }
CPPUNIT_ASSERT( wxIsupper_l(wxT('\xc9'), locFR) ); #endif // wxHAS_XLOCALE_SUPPORT
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() void XLocaleTestCase::TestStdlibFunctions()
{ {
TestStdlibFunctionsWith(wxCLocale); SECTION("C")
{
TestStdlibFunctionsWith(wxCLocale);
#if wxUSE_UNICODE #if wxUSE_UNICODE
wchar_t* endptr; wchar_t* endptr;
#else #else
char* endptr; char* endptr;
#endif #endif
// strtod checks specific for C locale // strtod checks specific for C locale
endptr = NULL; endptr = NULL;
CPPUNIT_ASSERT_EQUAL( 0.0, wxStrtod_l(wxT("0.000"), NULL, wxCLocale) ); 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.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( -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")
{
wxXLocale locFR(wxLANGUAGE_FRENCH);
if ( !locFR.IsOk() )
return;
// french TestCtypeFunctionsWith(locFR);
if (!wxLocale::IsAvailable(wxLANGUAGE_FRENCH)) // comma as decimal point:
return; // you should have french support installed to continue this test! CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1,234"), NULL, locFR) );
wxXLocale locFR(wxLANGUAGE_FRENCH); // space as thousands separator is not recognized by wxStrtod_l():
CPPUNIT_ASSERT( locFR.IsOk() ); // doesn't make sense to continue otherwise CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1 234,5"), NULL, locFR) );
}
TestCtypeFunctionsWith(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 SECTION("Italian")
{
wxXLocale locIT(wxLANGUAGE_ITALIAN);
if ( !locIT.IsOk() )
return;
if (!wxLocale::IsAvailable(wxLANGUAGE_ITALIAN)) TestStdlibFunctionsWith(locIT);
return; // you should have italian support installed to continue this test!
wxXLocale locIT(wxLANGUAGE_ITALIAN); // comma as decimal point:
CPPUNIT_ASSERT( locIT.IsOk() ); // doesn't make sense to continue otherwise CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1,234"), NULL, locIT) );
TestStdlibFunctionsWith(locIT); // dot as thousands separator is not recognized by wxStrtod_l():
CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1.234,5"), NULL, locIT) );
// comma as decimal point: }
CPPUNIT_ASSERT_EQUAL( 1.234, wxStrtod_l(wxT("1,234"), NULL, locIT) ); #endif // wxHAS_XLOCALE_SUPPORT
// dot as thousands separator is not recognized by wxStrtod_l():
CPPUNIT_ASSERT( 1234.5 != wxStrtod_l(wxT("1.234,5"), NULL, locIT) );
#endif
} }
#endif // wxUSE_XLOCALE #endif // wxUSE_XLOCALE