From 3db901bd09ab94e4123c316e908cd919a97cc4d3 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Thu, 16 Apr 2020 15:48:17 +0200 Subject: [PATCH] [locale] Expand tests to show overlapping locations - This isn't something that Calamares can acutally fix, so the test will be disabled later. After all, if Brazzaville and Kinshasa are close enough that on the map they are the same pixel, we can't move the cities. --- src/modules/locale/Tests.cpp | 70 ++++++++++++++++++++++++++++++++++-- src/modules/locale/Tests.h | 3 +- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index 8104966a4..daa585e3d 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -28,9 +28,9 @@ QTEST_MAIN( LocaleTests ) -LocaleTests::LocaleTests() { } +LocaleTests::LocaleTests() {} -LocaleTests::~LocaleTests() { } +LocaleTests::~LocaleTests() {} void LocaleTests::initTestCase() @@ -149,3 +149,69 @@ LocaleTests::testTZImages() QCOMPARE( overlapcount, 0 ); } + +bool +operator<( const QPoint& l, const QPoint& r ) +{ + if ( l.x() < r.x() ) + { + return true; + } + if ( l.x() > r.x() ) + { + return false; + } + return l.y() < r.y(); +} + +void +listAll( const QPoint& p, const CalamaresUtils::Locale::CStringPairList& zones ) +{ + using namespace CalamaresUtils::Locale; + for ( const auto* pz : zones ) + { + const TZZone* zone = dynamic_cast< const TZZone* >( pz ); + if ( p == TimeZoneImageList::getLocationPosition( zone->longitude(), zone->latitude() ) ) + { + cError() << Logger::SubEntry << zone->zone(); + } + } +} + +void +LocaleTests::testTZLocations() +{ + using namespace CalamaresUtils::Locale; + const CStringPairList& regions = TZRegion::fromZoneTab(); + + int overlapcount = 0; + for ( const auto* pr : regions ) + { + const TZRegion* region = dynamic_cast< const TZRegion* >( pr ); + QVERIFY( region ); + + Logger::setupLogLevel( Logger::LOGDEBUG ); + cDebug() << "Region" << region->region() << "zones #" << region->zones().count(); + Logger::setupLogLevel( Logger::LOGERROR ); + + std::set< QPoint > occupied; + + const auto zones = region->zones(); + QVERIFY( zones.count() > 0 ); + for ( const auto* pz : zones ) + { + const TZZone* zone = dynamic_cast< const TZZone* >( pz ); + QVERIFY( zone ); + + auto pos = TimeZoneImageList::getLocationPosition( zone->longitude(), zone->latitude() ); + if ( occupied.find( pos ) != occupied.end() ) + { + cError() << "Zone" << zone->zone() << "occupies same spot as .."; + listAll( pos, zones ); + overlapcount++; + } + occupied.insert( pos ); + } + } + QCOMPARE( overlapcount, 0 ); +} diff --git a/src/modules/locale/Tests.h b/src/modules/locale/Tests.h index e0ca7ad0b..20ef86442 100644 --- a/src/modules/locale/Tests.h +++ b/src/modules/locale/Tests.h @@ -37,7 +37,8 @@ private Q_SLOTS: void testSplitLocaleConfiguration(); // Check the TZ images for consistency - void testTZImages(); + void testTZImages(); // No overlaps in images + void testTZLocations(); // No overlaps in locations }; #endif