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-14 15:10:04 +02:00
|
|
|
QTEST_MAIN( LocaleTests )
|
2019-01-08 11:30:49 +01:00
|
|
|
|
|
|
|
|
2019-09-07 16:58:37 +02:00
|
|
|
LocaleTests::LocaleTests() {}
|
2019-01-08 11:30:49 +01:00
|
|
|
|
2019-09-07 16:58:37 +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()
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
|
|
|
cDebug() << "Region" << region->region() << "zones #" << region->zones().count();
|
|
|
|
Logger::setupLogLevel( Logger::LOGERROR );
|
|
|
|
|
|
|
|
const auto zones = region->zones();
|
|
|
|
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 );
|
|
|
|
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
|
|
|
|
|
|
|
QCOMPARE( overlapcount, 0 );
|
2020-04-14 11:59:45 +02:00
|
|
|
}
|