[libcalamares] Refactor test to be data-driven

- this test is going to get a lot more cases, so prepare for that
main
Adriaan de Groot 5 years ago
parent 00626fd96c
commit 6a33e72b58

@ -52,6 +52,7 @@ private Q_SLOTS:
void testComplexZones(); void testComplexZones();
void testTZLookup(); void testTZLookup();
void testTZIterator(); void testTZIterator();
void testLocationLookup_data();
void testLocationLookup(); void testLocationLookup();
}; };
@ -391,23 +392,30 @@ LocaleTests::testTZIterator()
} }
void void
LocaleTests::testLocationLookup() LocaleTests::testLocationLookup_data()
{ {
const CalamaresUtils::Locale::ZonesModel zones; QTest::addColumn< double >( "latitude" );
QTest::addColumn< double >( "longitude" );
QTest::addColumn< QString >( "name" );
const auto* zone = zones.find( 50.0, 0.0 ); QTest::newRow( "London" ) << 50.0 << 0.0 << QString( "London" );
QVERIFY( zone ); QTest::newRow( "Tarawa E" ) << 0.0 << 179.0 << QString( "Tarawa" );
QCOMPARE( zone->zone(), QStringLiteral( "London" ) ); QTest::newRow( "Tarawa W" ) << 0.0 << -179.0 << QString( "Tarawa" );
}
// Tarawa is close to "the other side of the world" from London void
zone = zones.find( 0.0, 179.0 ); LocaleTests::testLocationLookup()
QVERIFY( zone ); {
QCOMPARE( zone->zone(), QStringLiteral( "Tarawa" ) ); const CalamaresUtils::Locale::ZonesModel zones;
QFETCH( double, latitude );
QFETCH( double, longitude );
QFETCH( QString, name );
zone = zones.find( 0.0, -179.0 ); const auto* zone = zones.find( latitude, longitude );
QVERIFY( zone ); QVERIFY( zone );
QCOMPARE( zone->zone(), QStringLiteral( "Tarawa" ) ); QCOMPARE( zone->zone(), name );
} }

Loading…
Cancel
Save