[locale] Expand tests for alternate selectors

- Check that the alternate selectors are used
This commit is contained in:
Adriaan de Groot 2018-04-16 05:05:06 -04:00
parent fe20416a54
commit b1b59b27b2
2 changed files with 35 additions and 9 deletions

View File

@ -40,14 +40,14 @@ GeoIPTests::initTestCase()
{ {
} }
static const char json_data_attribute[] =
"{\"time_zone\":\"Europe/Amsterdam\"}";
void void
GeoIPTests::testJSON() GeoIPTests::testJSON()
{ {
static const char data[] =
"{\"time_zone\":\"Europe/Amsterdam\"}";
GeoIPJSON handler; GeoIPJSON handler;
auto tz = handler.processReply( data ); auto tz = handler.processReply( json_data_attribute );
QCOMPARE( tz.first, QLatin1String( "Europe" ) ); QCOMPARE( tz.first, QLatin1String( "Europe" ) );
QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) ); QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) );
@ -60,6 +60,18 @@ GeoIPTests::testJSON()
QCOMPARE( tz.first, "America" ); QCOMPARE( tz.first, "America" );
} }
void GeoIPTests::testJSONalt()
{
GeoIPJSON handler( "zona_de_hora" );
auto tz = handler.processReply( json_data_attribute );
QCOMPARE( tz.first, QString() ); // Not found
tz = handler.processReply( "tarifa: 12\nzona_de_hora: Europe/Madrid" );
QCOMPARE( tz.first, QLatin1String( "Europe" ) );
QCOMPARE( tz.second, QLatin1String( "Madrid" ) );
}
void void
GeoIPTests::testJSONbad() GeoIPTests::testJSONbad()
{ {
@ -82,10 +94,7 @@ GeoIPTests::testJSONbad()
} }
void static const char xml_data_ubiquity[] =
GeoIPTests::testXML()
{
static const char data[] =
R"(<Response> R"(<Response>
<Ip>85.150.1.1</Ip> <Ip>85.150.1.1</Ip>
<Status>OK</Status> <Status>OK</Status>
@ -102,9 +111,12 @@ GeoIPTests::testXML()
<TimeZone>Europe/Amsterdam</TimeZone> <TimeZone>Europe/Amsterdam</TimeZone>
</Response>)"; </Response>)";
void
GeoIPTests::testXML()
{
#ifdef HAVE_XML #ifdef HAVE_XML
GeoIPXML handler; GeoIPXML handler;
auto tz = handler.processReply( data ); auto tz = handler.processReply( xml_data_ubiquity );
QCOMPARE( tz.first, QLatin1String( "Europe" ) ); QCOMPARE( tz.first, QLatin1String( "Europe" ) );
QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) ); QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) );
@ -126,6 +138,18 @@ GeoIPTests::testXML2()
#endif #endif
} }
void GeoIPTests::testXMLalt()
{
#ifdef HAvE_XML
GeoIPXML handler( "ZT" );
auto tz = handler.processReply( "<A><B/><C><ZT>Moon/Dark_side</ZT></C></A>" );
QCOMPARE( tz.first, QLatin1String( "Moon" ) );
QCOMPARE( tz.second, QLatin1String( "Dark_side" ) );
#endif
}
void void
GeoIPTests::testXMLbad() GeoIPTests::testXMLbad()
{ {

View File

@ -31,9 +31,11 @@ public:
private Q_SLOTS: private Q_SLOTS:
void initTestCase(); void initTestCase();
void testJSON(); void testJSON();
void testJSONalt();
void testJSONbad(); void testJSONbad();
void testXML(); void testXML();
void testXML2(); void testXML2();
void testXMLalt();
void testXMLbad(); void testXMLbad();
}; };