From 29fd0e03196c5c9037c3f744f2575e42652feaf5 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 14 Apr 2020 16:21:24 +0200 Subject: [PATCH] [locale] Expand test to check zones-overlap - Document index and find methods, - Check that each location is claimed by only one image (e.g. by one zone). This is currently false. --- src/modules/locale/Tests.cpp | 26 +++++++++++++++++-- .../locale/timezonewidget/TimeZoneImage.cpp | 12 ++++----- .../locale/timezonewidget/TimeZoneImage.h | 18 ++++++++++++- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/modules/locale/Tests.cpp b/src/modules/locale/Tests.cpp index 3c08ccef5..b429c6560 100644 --- a/src/modules/locale/Tests.cpp +++ b/src/modules/locale/Tests.cpp @@ -112,12 +112,34 @@ LocaleTests::testTZImages() 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 ); - if ( region ) + QVERIFY( region ); + + cDebug() << "Region" << region->region() << "zones #" << region->zones().count(); + Logger::setupLogLevel( Logger::LOGERROR ); + + const auto zones = region->zones(); + for ( const auto* pz : zones ) { - cDebug() << "Region" << region->region() << "zones #" << region->zones().count(); + const TZZone* zone = dynamic_cast< const TZZone* >( pz ); + QVERIFY( zone ); + + int overlap = 0; + auto pos = images.getLocationPosition( zone->longitude(), zone->latitude() ); + QVERIFY( images.index( pos, overlap ) >= 0 ); + if ( overlap > 1 ) + { + Logger::setupLogLevel( Logger::LOGDEBUG ); + cDebug() << Logger::SubEntry << "Zone" << zone->zone() << pos; + (void)images.index( pos, overlap ); + Logger::setupLogLevel( Logger::LOGERROR ); + overlapcount++; + } } } + + QCOMPARE( overlapcount, 0 ); } diff --git a/src/modules/locale/timezonewidget/TimeZoneImage.cpp b/src/modules/locale/timezonewidget/TimeZoneImage.cpp index e1bc6c6fd..a406bd0d7 100644 --- a/src/modules/locale/timezonewidget/TimeZoneImage.cpp +++ b/src/modules/locale/timezonewidget/TimeZoneImage.cpp @@ -144,12 +144,11 @@ TimeZoneImageList::getLocationPosition( double longitude, double latitude ) static constexpr const int RGB_TRANSPARENT = 0; int -TimeZoneImageList::index( QPoint pos, int& overlap ) const +TimeZoneImageList::index( QPoint pos, int& count ) const { - overlap = 0; + count = 0; #ifdef DEBUG_TIMEZONES - bool found = false; for ( int i = 0; i < size(); ++i ) { const QImage& zone = at( i ); @@ -159,19 +158,18 @@ TimeZoneImageList::index( QPoint pos, int& overlap ) const { // Log *all* the zones that contain this point, // but only pick the first. - if ( !found ) + if ( !count ) { - found = true; cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME ); } else { cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME ); - overlap++; } + count++; } } - if ( !found ) + if ( !count ) { return -1; } diff --git a/src/modules/locale/timezonewidget/TimeZoneImage.h b/src/modules/locale/timezonewidget/TimeZoneImage.h index 5ed163fd7..0a3aea145 100644 --- a/src/modules/locale/timezonewidget/TimeZoneImage.h +++ b/src/modules/locale/timezonewidget/TimeZoneImage.h @@ -56,8 +56,24 @@ public: */ static QPoint getLocationPosition( double longitude, double latitude ); + /** @brief Find the index of the image claiming point @p p + * + * This maps a point (presumably from getLocationPosition(), so + * originating from a longitude and latitude) to a specific zone + * image index. Returns -1 if no image claims the point (e.g. if + * it is out of bounds). + */ int index( QPoint p ) const; - int index( QPoint p, int& overlap ) const; + /** @brief Find the index of the image claiming point @p p + * + * As `index(p)`, but also fills in @p count with the number of + * zones that claim the point. + */ + int index( QPoint p, int& count ) const; + /** @brief Get image of the zone claiming @p p + * + * Can return a null image, if the point is unclaimed or invalid. + */ QImage find( QPoint p ) const; /// @brief The **expected** number of zones in the list.