From 82ba4be5e72bd89d23fd8b787be1531b298a7155 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 16 Apr 2020 17:59:12 +0200 Subject: [PATCH] [locale] Test for pixel-perfect location of Gibraltar and Ceuta - Can't get Gibraltar (and Ceuta) to be distinguished --- src/modules/locale/Tests.cpp | 46 ++++++++++++++++++++++++++++++++++++ src/modules/locale/Tests.h | 1 + 2 files changed, 47 insertions(+) diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index daa585e3d..53cae3fb4 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -215,3 +215,49 @@ LocaleTests::testTZLocations() } QCOMPARE( overlapcount, 0 ); } + +const CalamaresUtils::Locale::TZZone* +findZone( const QString& name ) +{ + using namespace CalamaresUtils::Locale; + const CStringPairList& regions = TZRegion::fromZoneTab(); + + for ( const auto* pr : regions ) + { + const TZRegion* region = dynamic_cast< const TZRegion* >( pr ); + if ( !region ) + { + continue; + } + const auto zones = region->zones(); + for ( const auto* pz : zones ) + { + const TZZone* zone = dynamic_cast< const TZZone* >( pz ); + if ( !zone ) + { + continue; + } + + if ( zone->zone() == name ) + { + return zone; + } + } + } + return nullptr; +} + +void +LocaleTests::testSpecificLocations() +{ + const auto* gibraltar = findZone( "Gibraltar" ); + const auto* ceuta = findZone( "Ceuta" ); + QVERIFY( gibraltar ); + QVERIFY( ceuta ); + + auto gpos = TimeZoneImageList::getLocationPosition( gibraltar->longitude(), gibraltar->latitude() ); + auto cpos = TimeZoneImageList::getLocationPosition( ceuta->longitude(), ceuta->latitude() ); + QVERIFY( gpos != cpos ); + QVERIFY( gibraltar->latitude() > ceuta->latitude() ); + QVERIFY( gpos.y() < cpos.y() ); // Gibraltar is north of Ceuta +} diff --git a/src/modules/locale/Tests.h b/src/modules/locale/Tests.h index 20ef86442..e01b1a25c 100644 --- a/src/modules/locale/Tests.h +++ b/src/modules/locale/Tests.h @@ -39,6 +39,7 @@ private Q_SLOTS: // Check the TZ images for consistency void testTZImages(); // No overlaps in images void testTZLocations(); // No overlaps in locations + void testSpecificLocations(); }; #endif