[libcalamares] Apply coding style to remainder of geoip/

This commit is contained in:
Adriaan de Groot 2019-08-08 12:41:41 +02:00
parent 839e496fcb
commit 115f5bfd82

View File

@ -34,21 +34,16 @@ QTEST_GUILESS_MAIN( GeoIPTests )
using namespace CalamaresUtils::GeoIP; using namespace CalamaresUtils::GeoIP;
GeoIPTests::GeoIPTests() GeoIPTests::GeoIPTests() {}
{
}
GeoIPTests::~GeoIPTests() GeoIPTests::~GeoIPTests() {}
{
}
void void
GeoIPTests::initTestCase() GeoIPTests::initTestCase()
{ {
} }
static const char json_data_attribute[] = static const char json_data_attribute[] = "{\"time_zone\":\"Europe/Amsterdam\"}";
"{\"time_zone\":\"Europe/Amsterdam\"}";
void void
GeoIPTests::testJSON() GeoIPTests::testJSON()
@ -67,7 +62,8 @@ GeoIPTests::testJSON()
QCOMPARE( tz.first, QStringLiteral( "America" ) ); QCOMPARE( tz.first, QStringLiteral( "America" ) );
} }
void GeoIPTests::testJSONalt() void
GeoIPTests::testJSONalt()
{ {
GeoIPJSON handler( "zona_de_hora" ); GeoIPJSON handler( "zona_de_hora" );
@ -102,7 +98,7 @@ GeoIPTests::testJSONbad()
static const char xml_data_ubiquity[] = static const char xml_data_ubiquity[] =
R"(<Response> R"(<Response>
<Ip>85.150.1.1</Ip> <Ip>85.150.1.1</Ip>
<Status>OK</Status> <Status>OK</Status>
<CountryCode>NL</CountryCode> <CountryCode>NL</CountryCode>
@ -133,8 +129,8 @@ GeoIPTests::testXML()
void void
GeoIPTests::testXML2() GeoIPTests::testXML2()
{ {
static const char data[] = static const char data[]
"<Response><TimeZone>America/North Dakota/Beulah</TimeZone></Response>"; // With a space! = "<Response><TimeZone>America/North Dakota/Beulah</TimeZone></Response>"; // With a space!
#ifdef QT_XML_LIB #ifdef QT_XML_LIB
GeoIPXML handler; GeoIPXML handler;
@ -146,7 +142,8 @@ GeoIPTests::testXML2()
} }
void GeoIPTests::testXMLalt() void
GeoIPTests::testXMLalt()
{ {
#ifdef QT_XML_LIB #ifdef QT_XML_LIB
GeoIPXML handler( "ZT" ); GeoIPXML handler( "ZT" );
@ -173,29 +170,30 @@ GeoIPTests::testXMLbad()
#endif #endif
} }
void GeoIPTests::testSplitTZ() void
GeoIPTests::testSplitTZ()
{ {
using namespace CalamaresUtils::GeoIP; using namespace CalamaresUtils::GeoIP;
auto tz = splitTZString( QStringLiteral("Moon/Dark_side") ); auto tz = splitTZString( QStringLiteral( "Moon/Dark_side" ) );
QCOMPARE( tz.first, QStringLiteral("Moon") ); QCOMPARE( tz.first, QStringLiteral( "Moon" ) );
QCOMPARE( tz.second, QStringLiteral("Dark_side") ); QCOMPARE( tz.second, QStringLiteral( "Dark_side" ) );
// Some providers return weirdly escaped data // Some providers return weirdly escaped data
tz = splitTZString( QStringLiteral("America\\/NewYork") ); tz = splitTZString( QStringLiteral( "America\\/NewYork" ) );
QCOMPARE( tz.first, QStringLiteral("America") ); QCOMPARE( tz.first, QStringLiteral( "America" ) );
QCOMPARE( tz.second, QStringLiteral("NewYork") ); // That's not actually the zone name QCOMPARE( tz.second, QStringLiteral( "NewYork" ) ); // That's not actually the zone name
// Check that bogus data fails // Check that bogus data fails
tz = splitTZString( QString() ); tz = splitTZString( QString() );
QCOMPARE( tz.first, QString() ); QCOMPARE( tz.first, QString() );
tz = splitTZString( QStringLiteral("America.NewYork") ); tz = splitTZString( QStringLiteral( "America.NewYork" ) );
QCOMPARE( tz.first, QString() ); QCOMPARE( tz.first, QString() );
// Check that three-level is split properly and space is replaced // Check that three-level is split properly and space is replaced
tz = splitTZString( QStringLiteral("America/North Dakota/Beulah") ); tz = splitTZString( QStringLiteral( "America/North Dakota/Beulah" ) );
QCOMPARE( tz.first, QStringLiteral("America") ); QCOMPARE( tz.first, QStringLiteral( "America" ) );
QCOMPARE( tz.second, QStringLiteral("North_Dakota/Beulah") ); QCOMPARE( tz.second, QStringLiteral( "North_Dakota/Beulah" ) );
} }
@ -217,19 +215,20 @@ synchronous_get( const char* urlstring )
return reply->readAll(); return reply->readAll();
} }
#define CHECK_GET(t, selector, url) \ #define CHECK_GET( t, selector, url ) \
{ \ { \
auto tz = GeoIP##t( selector ).processReply( synchronous_get( url ) ); \ auto tz = GeoIP##t( selector ).processReply( synchronous_get( url ) ); \
qDebug() << tz; \ qDebug() << tz; \
QCOMPARE( default_tz, tz ); \ QCOMPARE( default_tz, tz ); \
auto tz2 = CalamaresUtils::GeoIP::Handler( ""#t, url, selector ).get(); \ auto tz2 = CalamaresUtils::GeoIP::Handler( "" #t, url, selector ).get(); \
qDebug() << tz2; \ qDebug() << tz2; \
QCOMPARE( default_tz, tz2 ); \ QCOMPARE( default_tz, tz2 ); \
} }
void GeoIPTests::testGet() void
GeoIPTests::testGet()
{ {
if ( !QProcessEnvironment::systemEnvironment().contains( QStringLiteral("TEST_HTTP_GET") ) ) if ( !QProcessEnvironment::systemEnvironment().contains( QStringLiteral( "TEST_HTTP_GET" ) ) )
{ {
qDebug() << "Skipping HTTP GET tests, set TEST_HTTP_GET environment variable to enable"; qDebug() << "Skipping HTTP GET tests, set TEST_HTTP_GET environment variable to enable";
return; return;
@ -248,14 +247,14 @@ void GeoIPTests::testGet()
// Each expansion of CHECK_GET does a synchronous GET, then checks that // Each expansion of CHECK_GET does a synchronous GET, then checks that
// the TZ data is the same as the default_tz; this is fragile if the // the TZ data is the same as the default_tz; this is fragile if the
// services don't agree on the location of where the test is run. // services don't agree on the location of where the test is run.
CHECK_GET( JSON, QString(), "https://geoip.kde.org/v1/calamares" ) // Check it's consistent CHECK_GET( JSON, QString(), "https://geoip.kde.org/v1/calamares" ) // Check it's consistent
CHECK_GET( JSON, QStringLiteral("timezone"), "https://ipapi.co/json" ) // Different JSON CHECK_GET( JSON, QStringLiteral( "timezone" ), "https://ipapi.co/json" ) // Different JSON
CHECK_GET( JSON, QStringLiteral("timezone"), "http://ip-api.com/json" ) CHECK_GET( JSON, QStringLiteral( "timezone" ), "http://ip-api.com/json" )
CHECK_GET( JSON, QStringLiteral("Location.TimeZone"), "https://geoip.kde.org/debug" ) // 2-level JSON CHECK_GET( JSON, QStringLiteral( "Location.TimeZone" ), "https://geoip.kde.org/debug" ) // 2-level JSON
#ifdef QT_XML_LIB #ifdef QT_XML_LIB
CHECK_GET( XML, QString(), "http://geoip.ubuntu.com/lookup" ) // Ubiquity's XML format CHECK_GET( XML, QString(), "http://geoip.ubuntu.com/lookup" ) // Ubiquity's XML format
CHECK_GET( XML, QString(), "https://geoip.kde.org/v1/ubiquity" ) // Temporary KDE service CHECK_GET( XML, QString(), "https://geoip.kde.org/v1/ubiquity" ) // Temporary KDE service
#endif #endif
} }