2019-01-08 11:30:49 +01:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
2020-04-14 11:59:45 +02:00
|
|
|
* Copyright 2019-2020, Adriaan de Groot <groot@kde.org>
|
2019-01-08 11:30:49 +01:00
|
|
|
*
|
|
|
|
* Calamares is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "Tests.h"
|
|
|
|
#include "LocaleConfiguration.h"
|
2020-04-14 15:10:04 +02:00
|
|
|
#include "timezonewidget/TimeZoneImage.h"
|
2019-01-08 11:30:49 +01:00
|
|
|
|
2020-04-14 11:59:45 +02:00
|
|
|
#include "locale/TimeZone.h"
|
|
|
|
|
2019-01-08 11:30:49 +01:00
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2020-04-21 12:43:45 +02:00
|
|
|
#include <set>
|
|
|
|
|
2020-04-14 15:10:04 +02:00
|
|
|
QTEST_MAIN( LocaleTests )
|
2019-01-08 11:30:49 +01:00
|
|
|
|
|
|
|
|
2020-04-16 15:48:17 +02:00
|
|
|
LocaleTests::LocaleTests() {}
|
2019-01-08 11:30:49 +01:00
|
|
|
|
2020-04-16 15:48:17 +02:00
|
|
|
LocaleTests::~LocaleTests() {}
|
2019-01-08 11:30:49 +01:00
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
void
|
|
|
|
LocaleTests::initTestCase()
|
2019-01-08 11:30:49 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testEmptyLocaleConfiguration()
|
2019-01-08 11:30:49 +01:00
|
|
|
{
|
|
|
|
LocaleConfiguration lc;
|
|
|
|
|
|
|
|
QVERIFY( lc.isEmpty() );
|
|
|
|
QCOMPARE( lc.toBcp47(), QString() );
|
|
|
|
}
|
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testDefaultLocaleConfiguration()
|
2019-01-08 11:30:49 +01:00
|
|
|
{
|
|
|
|
LocaleConfiguration lc( "en_US.UTF-8" );
|
|
|
|
QVERIFY( !lc.isEmpty() );
|
2020-02-21 18:24:39 +01:00
|
|
|
QCOMPARE( lc.language(), QStringLiteral( "en_US.UTF-8" ) );
|
|
|
|
QCOMPARE( lc.toBcp47(), QStringLiteral( "en" ) );
|
2019-01-08 13:23:16 +01:00
|
|
|
|
|
|
|
LocaleConfiguration lc2( "de_DE.UTF-8" );
|
|
|
|
QVERIFY( !lc2.isEmpty() );
|
2020-02-21 18:24:39 +01:00
|
|
|
QCOMPARE( lc2.language(), QStringLiteral( "de_DE.UTF-8" ) );
|
|
|
|
QCOMPARE( lc2.toBcp47(), QStringLiteral( "de" ) );
|
2019-01-08 13:23:16 +01:00
|
|
|
}
|
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testSplitLocaleConfiguration()
|
2019-01-08 13:23:16 +01:00
|
|
|
{
|
|
|
|
LocaleConfiguration lc( "en_US.UTF-8", "de_DE.UTF-8" );
|
|
|
|
QVERIFY( !lc.isEmpty() );
|
2020-02-21 18:24:39 +01:00
|
|
|
QCOMPARE( lc.language(), QStringLiteral( "en_US.UTF-8" ) );
|
|
|
|
QCOMPARE( lc.toBcp47(), QStringLiteral( "en" ) );
|
2019-01-08 13:23:16 +01:00
|
|
|
QCOMPARE( lc.lc_numeric, QStringLiteral( "de_DE.UTF-8" ) );
|
|
|
|
|
|
|
|
LocaleConfiguration lc2( "de_DE.UTF-8", "da_DK.UTF-8" );
|
|
|
|
QVERIFY( !lc2.isEmpty() );
|
2020-02-21 18:24:39 +01:00
|
|
|
QCOMPARE( lc2.language(), QStringLiteral( "de_DE.UTF-8" ) );
|
|
|
|
QCOMPARE( lc2.toBcp47(), QStringLiteral( "de" ) );
|
|
|
|
QCOMPARE( lc2.lc_numeric, QStringLiteral( "da_DK.UTF-8" ) );
|
2019-01-08 13:23:16 +01:00
|
|
|
|
|
|
|
LocaleConfiguration lc3( "da_DK.UTF-8", "de_DE.UTF-8" );
|
|
|
|
QVERIFY( !lc3.isEmpty() );
|
2020-02-21 18:24:39 +01:00
|
|
|
QCOMPARE( lc3.toBcp47(), QStringLiteral( "da" ) );
|
|
|
|
QCOMPARE( lc3.lc_numeric, QStringLiteral( "de_DE.UTF-8" ) );
|
2019-01-08 11:30:49 +01:00
|
|
|
}
|
2020-04-14 11:59:45 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testTZImages()
|
|
|
|
{
|
2020-04-14 16:24:56 +02:00
|
|
|
// This test messes around with log-levels a lot so
|
|
|
|
// that it produces useful output (e.g. listing the problems,
|
|
|
|
// not every check it ever does).
|
2020-04-14 11:59:45 +02:00
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
2020-04-14 15:10:04 +02:00
|
|
|
|
|
|
|
// Number of zone images
|
|
|
|
//
|
|
|
|
//
|
|
|
|
auto images = TimeZoneImageList::fromDirectory( SOURCE_DIR );
|
2020-04-14 15:24:05 +02:00
|
|
|
QCOMPARE( images.count(), images.zoneCount );
|
2020-04-14 15:10:04 +02:00
|
|
|
|
|
|
|
// All image sizes consistent
|
|
|
|
//
|
|
|
|
//
|
|
|
|
const QSize windowSize( 780, 340 );
|
|
|
|
{
|
|
|
|
QImage background( SOURCE_DIR "/bg.png" );
|
|
|
|
QVERIFY( !background.isNull() );
|
|
|
|
QCOMPARE( background.size(), windowSize );
|
|
|
|
}
|
|
|
|
for ( const auto& image : images )
|
|
|
|
{
|
|
|
|
QCOMPARE( image.size(), windowSize );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check zones are uniquely-claimed
|
|
|
|
//
|
|
|
|
//
|
2020-04-14 11:59:45 +02:00
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
const CStringPairList& regions = TZRegion::fromZoneTab();
|
|
|
|
|
2020-04-14 16:21:24 +02:00
|
|
|
int overlapcount = 0;
|
2020-04-14 11:59:45 +02:00
|
|
|
for ( const auto* pr : regions )
|
|
|
|
{
|
|
|
|
const TZRegion* region = dynamic_cast< const TZRegion* >( pr );
|
2020-04-14 16:21:24 +02:00
|
|
|
QVERIFY( region );
|
|
|
|
|
2020-04-14 16:24:56 +02:00
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
2020-04-14 16:21:24 +02:00
|
|
|
cDebug() << "Region" << region->region() << "zones #" << region->zones().count();
|
|
|
|
Logger::setupLogLevel( Logger::LOGERROR );
|
|
|
|
|
|
|
|
const auto zones = region->zones();
|
2020-04-15 14:30:10 +02:00
|
|
|
QVERIFY( zones.count() > 0 );
|
2020-04-14 16:21:24 +02:00
|
|
|
for ( const auto* pz : zones )
|
2020-04-14 11:59:45 +02:00
|
|
|
{
|
2020-04-14 16:21:24 +02:00
|
|
|
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 );
|
2020-04-15 14:30:10 +02:00
|
|
|
QVERIFY( overlap > 0 ); // At least one image contains the spot
|
2020-04-14 16:21:24 +02:00
|
|
|
if ( overlap > 1 )
|
|
|
|
{
|
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
cDebug() << Logger::SubEntry << "Zone" << zone->zone() << pos;
|
|
|
|
(void)images.index( pos, overlap );
|
|
|
|
Logger::setupLogLevel( Logger::LOGERROR );
|
|
|
|
overlapcount++;
|
|
|
|
}
|
2020-04-14 11:59:45 +02:00
|
|
|
}
|
|
|
|
}
|
2020-04-14 16:21:24 +02:00
|
|
|
|
2020-04-17 13:06:05 +02:00
|
|
|
QEXPECT_FAIL("", "TZ Images not yet all fixed", Continue);
|
2020-04-14 16:21:24 +02:00
|
|
|
QCOMPARE( overlapcount, 0 );
|
2020-04-14 11:59:45 +02:00
|
|
|
}
|
2020-04-16 15:48:17 +02:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
2020-04-21 12:43:45 +02:00
|
|
|
|
|
|
|
QEXPECT_FAIL("", "TZ Images contain pixel-overlaps", Continue);
|
2020-04-16 15:48:17 +02:00
|
|
|
QCOMPARE( overlapcount, 0 );
|
|
|
|
}
|
2020-04-16 17:59:12 +02:00
|
|
|
|
|
|
|
const CalamaresUtils::Locale::TZZone*
|
|
|
|
findZone( const QString& name )
|
|
|
|
{
|
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
const CStringPairList& regions = TZRegion::fromZoneTab();
|
|
|
|
|
|
|
|
for ( const auto* pr : regions )
|
|
|
|
{
|
|
|
|
const TZRegion* region = dynamic_cast< const TZRegion* >( pr );
|
|
|
|
if ( !region )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto zones = region->zones();
|
|
|
|
for ( const auto* pz : zones )
|
|
|
|
{
|
|
|
|
const TZZone* zone = dynamic_cast< const TZZone* >( pz );
|
|
|
|
if ( !zone )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( zone->zone() == name )
|
|
|
|
{
|
|
|
|
return zone;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testSpecificLocations()
|
|
|
|
{
|
|
|
|
const auto* gibraltar = findZone( "Gibraltar" );
|
|
|
|
const auto* ceuta = findZone( "Ceuta" );
|
|
|
|
QVERIFY( gibraltar );
|
|
|
|
QVERIFY( ceuta );
|
|
|
|
|
|
|
|
auto gpos = TimeZoneImageList::getLocationPosition( gibraltar->longitude(), gibraltar->latitude() );
|
|
|
|
auto cpos = TimeZoneImageList::getLocationPosition( ceuta->longitude(), ceuta->latitude() );
|
2020-04-21 12:43:45 +02:00
|
|
|
QEXPECT_FAIL("", "Gibraltar and Ceuta are really close", Continue);
|
2020-04-16 17:59:12 +02:00
|
|
|
QVERIFY( gpos != cpos );
|
|
|
|
QVERIFY( gibraltar->latitude() > ceuta->latitude() );
|
2020-04-21 12:43:45 +02:00
|
|
|
QEXPECT_FAIL("", "Gibraltar and Ceuta are really close", Continue);
|
2020-04-16 17:59:12 +02:00
|
|
|
QVERIFY( gpos.y() < cpos.y() ); // Gibraltar is north of Ceuta
|
|
|
|
}
|