[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.
This commit is contained in:
Adriaan de Groot 2020-04-16 15:48:17 +02:00
parent 2633cf1ef6
commit 3db901bd09
2 changed files with 70 additions and 3 deletions

View File

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

View File

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