[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.
main
Adriaan de Groot 5 years ago
parent 1d5c4f13aa
commit 29fd0e0319

@ -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 );
}

@ -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;
}

@ -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.

Loading…
Cancel
Save