[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.
This commit is contained in:
Adriaan de Groot 2020-04-14 16:21:24 +02:00
parent 1d5c4f13aa
commit 29fd0e0319
3 changed files with 46 additions and 10 deletions

View File

@ -112,12 +112,34 @@ LocaleTests::testTZImages()
using namespace CalamaresUtils::Locale; using namespace CalamaresUtils::Locale;
const CStringPairList& regions = TZRegion::fromZoneTab(); const CStringPairList& regions = TZRegion::fromZoneTab();
int overlapcount = 0;
for ( const auto* pr : regions ) for ( const auto* pr : regions )
{ {
const TZRegion* region = dynamic_cast< const TZRegion* >( pr ); const TZRegion* region = dynamic_cast< const TZRegion* >( pr );
if ( region ) QVERIFY( region );
{
cDebug() << "Region" << region->region() << "zones #" << region->zones().count(); cDebug() << "Region" << region->region() << "zones #" << region->zones().count();
Logger::setupLogLevel( Logger::LOGERROR );
const auto zones = region->zones();
for ( const auto* pz : zones )
{
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 );
} }

View File

@ -144,12 +144,11 @@ TimeZoneImageList::getLocationPosition( double longitude, double latitude )
static constexpr const int RGB_TRANSPARENT = 0; static constexpr const int RGB_TRANSPARENT = 0;
int int
TimeZoneImageList::index( QPoint pos, int& overlap ) const TimeZoneImageList::index( QPoint pos, int& count ) const
{ {
overlap = 0; count = 0;
#ifdef DEBUG_TIMEZONES #ifdef DEBUG_TIMEZONES
bool found = false;
for ( int i = 0; i < size(); ++i ) for ( int i = 0; i < size(); ++i )
{ {
const QImage& zone = at( 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, // Log *all* the zones that contain this point,
// but only pick the first. // but only pick the first.
if ( !found ) if ( !count )
{ {
found = true;
cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME ); cDebug() << Logger::SubEntry << "First zone found" << i << zone.text( ZONE_NAME );
} }
else else
{ {
cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME ); cDebug() << Logger::SubEntry << "Also in zone" << i << zone.text( ZONE_NAME );
overlap++; }
count++;
} }
} }
} if ( !count )
if ( !found )
{ {
return -1; return -1;
} }

View File

@ -56,8 +56,24 @@ public:
*/ */
static QPoint getLocationPosition( double longitude, double latitude ); 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 ) 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; QImage find( QPoint p ) const;
/// @brief The **expected** number of zones in the list. /// @brief The **expected** number of zones in the list.