2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2019-01-08 11:30:49 +01:00
|
|
|
*
|
2020-08-17 15:09:20 +02:00
|
|
|
* SPDX-FileCopyrightText: 2019-2020 Adriaan de Groot <groot@kde.org>
|
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2019-01-08 11:30:49 +01:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2019-01-08 11:30:49 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-08-06 12:32:48 +02:00
|
|
|
#include "Config.h"
|
2019-01-08 11:30:49 +01:00
|
|
|
#include "LocaleConfiguration.h"
|
2020-04-14 15:10:04 +02:00
|
|
|
#include "timezonewidget/TimeZoneImage.h"
|
2019-01-08 11:30:49 +01:00
|
|
|
|
2022-07-19 18:05:24 +02:00
|
|
|
#include "Settings.h"
|
2020-04-14 11:59:45 +02:00
|
|
|
#include "locale/TimeZone.h"
|
2022-07-19 18:05:24 +02:00
|
|
|
#include "locale/TranslationsModel.h"
|
2020-08-06 01:27:03 +02:00
|
|
|
#include "utils/Logger.h"
|
2020-04-14 11:59:45 +02:00
|
|
|
|
2019-01-08 11:30:49 +01:00
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2020-04-21 12:43:45 +02:00
|
|
|
#include <set>
|
|
|
|
|
2020-08-06 12:14:15 +02:00
|
|
|
class LocaleTests : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
LocaleTests();
|
|
|
|
~LocaleTests() override;
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
// Check the sample config file is processed correctly
|
|
|
|
void testEmptyLocaleConfiguration();
|
|
|
|
void testDefaultLocaleConfiguration();
|
|
|
|
void testSplitLocaleConfiguration();
|
|
|
|
|
|
|
|
// Check the TZ images for consistency
|
2020-08-17 15:09:20 +02:00
|
|
|
void testTZSanity();
|
2020-08-06 12:14:15 +02:00
|
|
|
void testTZImages(); // No overlaps in images
|
|
|
|
void testTZLocations(); // No overlaps in locations
|
|
|
|
void testSpecificLocations();
|
2020-08-06 12:32:48 +02:00
|
|
|
|
|
|
|
// Check the Config loading
|
|
|
|
void testConfigInitialization();
|
2022-06-18 12:33:02 +02:00
|
|
|
void testLanguageDetection_data();
|
|
|
|
void testLanguageDetection();
|
2022-06-19 14:37:54 +02:00
|
|
|
void testLanguageDetectionValencia();
|
2022-07-19 18:05:24 +02:00
|
|
|
|
|
|
|
// Check realistic language mapping for issue 2008
|
|
|
|
void testKDENeonLanguageData();
|
|
|
|
void testLanguageMapping_data();
|
|
|
|
void testLanguageMapping();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QStringList m_KDEneonLocales;
|
|
|
|
QStringList m_FreeBSDLocales;
|
2020-08-06 12:14:15 +02:00
|
|
|
};
|
|
|
|
|
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
|
|
|
{
|
2022-07-19 18:05:24 +02:00
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
const auto* settings = Calamares::Settings::instance();
|
|
|
|
if ( !settings )
|
|
|
|
{
|
|
|
|
(void)new Calamares::Settings( true );
|
|
|
|
}
|
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
|
|
|
|
2020-08-17 15:09:20 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testTZSanity()
|
|
|
|
{
|
|
|
|
// Data source for all TZ info
|
|
|
|
QVERIFY( QFile( "/usr/share/zoneinfo/zone.tab" ).exists() );
|
|
|
|
|
|
|
|
// Contains a sensible number of total zones
|
|
|
|
const CalamaresUtils::Locale::ZonesModel zones;
|
|
|
|
QVERIFY( zones.rowCount( QModelIndex() ) > 100 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
2020-08-06 01:27:03 +02:00
|
|
|
const ZonesModel m;
|
2020-04-14 11:59:45 +02:00
|
|
|
|
2020-04-14 16:21:24 +02:00
|
|
|
int overlapcount = 0;
|
2020-08-06 01:27:03 +02:00
|
|
|
for ( auto it = m.begin(); it; ++it )
|
2020-04-14 11:59:45 +02:00
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
QString region = m.data( m.index( it.index() ), ZonesModel::RegionRole ).toString();
|
|
|
|
QString zoneName = m.data( m.index( it.index() ), ZonesModel::KeyRole ).toString();
|
|
|
|
QVERIFY( !region.isEmpty() );
|
|
|
|
QVERIFY( !zoneName.isEmpty() );
|
|
|
|
const auto* zone = m.find( region, zoneName );
|
|
|
|
const auto* iterzone = *it;
|
|
|
|
|
|
|
|
QVERIFY( iterzone );
|
|
|
|
QVERIFY( zone );
|
|
|
|
QCOMPARE( zone, iterzone );
|
|
|
|
QCOMPARE( zone->zone(), zoneName );
|
|
|
|
QCOMPARE( zone->region(), region );
|
|
|
|
|
|
|
|
int overlap = 0;
|
|
|
|
auto pos = images.getLocationPosition( zone->longitude(), zone->latitude() );
|
|
|
|
QVERIFY( images.index( pos, overlap ) >= 0 );
|
|
|
|
QVERIFY( overlap > 0 ); // At least one image contains the spot
|
|
|
|
if ( overlap > 1 )
|
2020-04-14 11:59:45 +02:00
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
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-21 15:35:10 +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
|
2020-08-06 01:27:03 +02:00
|
|
|
listAll( const QPoint& p, const CalamaresUtils::Locale::ZonesModel& zones )
|
2020-04-16 15:48:17 +02:00
|
|
|
{
|
|
|
|
using namespace CalamaresUtils::Locale;
|
2020-08-06 01:27:03 +02:00
|
|
|
for ( auto it = zones.begin(); it; ++it )
|
2020-04-16 15:48:17 +02:00
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
const auto* zone = *it;
|
|
|
|
if ( !zone )
|
|
|
|
{
|
|
|
|
cError() << Logger::SubEntry << "NULL zone";
|
|
|
|
return;
|
|
|
|
}
|
2020-04-16 15:48:17 +02:00
|
|
|
if ( p == TimeZoneImageList::getLocationPosition( zone->longitude(), zone->latitude() ) )
|
|
|
|
{
|
|
|
|
cError() << Logger::SubEntry << zone->zone();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testTZLocations()
|
|
|
|
{
|
|
|
|
using namespace CalamaresUtils::Locale;
|
2020-08-06 01:27:03 +02:00
|
|
|
ZonesModel zones;
|
2020-04-16 15:48:17 +02:00
|
|
|
|
2020-08-06 12:14:15 +02:00
|
|
|
QVERIFY( zones.rowCount( QModelIndex() ) > 100 );
|
|
|
|
|
2020-04-16 15:48:17 +02:00
|
|
|
int overlapcount = 0;
|
2020-08-06 12:14:15 +02:00
|
|
|
std::set< QPoint > occupied;
|
2020-08-06 01:27:03 +02:00
|
|
|
for ( auto it = zones.begin(); it; ++it )
|
2020-04-16 15:48:17 +02:00
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
const auto* zone = *it;
|
|
|
|
QVERIFY( zone );
|
|
|
|
|
|
|
|
auto pos = TimeZoneImageList::getLocationPosition( zone->longitude(), zone->latitude() );
|
|
|
|
if ( occupied.find( pos ) != occupied.end() )
|
2020-04-16 15:48:17 +02:00
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
cError() << "Zone" << zone->zone() << "occupies same spot as ..";
|
|
|
|
listAll( pos, zones );
|
|
|
|
overlapcount++;
|
2020-04-16 15:48:17 +02:00
|
|
|
}
|
2020-08-06 01:27:03 +02:00
|
|
|
occupied.insert( pos );
|
2020-04-16 15:48:17 +02:00
|
|
|
}
|
2020-04-21 12:43:45 +02:00
|
|
|
|
2020-04-21 15:35:10 +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
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testSpecificLocations()
|
|
|
|
{
|
2020-08-06 01:27:03 +02:00
|
|
|
CalamaresUtils::Locale::ZonesModel zones;
|
|
|
|
const auto* gibraltar = zones.find( "Europe", "Gibraltar" );
|
|
|
|
const auto* ceuta = zones.find( "Africa", "Ceuta" );
|
2020-04-16 17:59:12 +02:00
|
|
|
QVERIFY( gibraltar );
|
|
|
|
QVERIFY( ceuta );
|
|
|
|
|
|
|
|
auto gpos = TimeZoneImageList::getLocationPosition( gibraltar->longitude(), gibraltar->latitude() );
|
|
|
|
auto cpos = TimeZoneImageList::getLocationPosition( ceuta->longitude(), ceuta->latitude() );
|
2020-04-21 15:35:10 +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 15:35:10 +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
|
|
|
|
}
|
2020-08-06 12:14:15 +02:00
|
|
|
|
2020-08-06 12:32:48 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testConfigInitialization()
|
|
|
|
{
|
|
|
|
Config c;
|
|
|
|
|
|
|
|
QVERIFY( !c.currentLocation() );
|
|
|
|
QVERIFY( !c.currentLocationStatus().isEmpty() );
|
|
|
|
}
|
|
|
|
|
2022-06-18 12:33:02 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testLanguageDetection_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn< QString >( "locale" );
|
|
|
|
QTest::addColumn< QString >( "country" );
|
|
|
|
QTest::addColumn< QString >( "expected" );
|
|
|
|
|
2022-06-19 15:25:23 +02:00
|
|
|
QTest::newRow( "english (US)" ) << QStringLiteral( "en" ) << QStringLiteral( "US" )
|
|
|
|
<< QStringLiteral( "en_US.UTF-8" );
|
|
|
|
QTest::newRow( "english (CA)" ) << QStringLiteral( "en" ) << QStringLiteral( "CA" )
|
|
|
|
<< QStringLiteral( "en" ); // because it's first in the list
|
|
|
|
QTest::newRow( "english (GB)" ) << QStringLiteral( "en" ) << QStringLiteral( "GB" )
|
|
|
|
<< QStringLiteral( "en_GB.UTF-8" );
|
2022-06-18 12:33:02 +02:00
|
|
|
QTest::newRow( "english (NL)" ) << QStringLiteral( "en" ) << QStringLiteral( "NL" ) << QStringLiteral( "en" );
|
|
|
|
|
2022-06-19 15:25:23 +02:00
|
|
|
QTest::newRow( "portuguese (PT)" ) << QStringLiteral( "pt" ) << QStringLiteral( "PT" )
|
|
|
|
<< QStringLiteral( "pt_PT.UTF-8" );
|
|
|
|
QTest::newRow( "portuguese (NL)" ) << QStringLiteral( "pt" ) << QStringLiteral( "NL" )
|
|
|
|
<< QStringLiteral( "pt_BR.UTF-8" ); // first
|
|
|
|
QTest::newRow( "portuguese (BR)" ) << QStringLiteral( "pt" ) << QStringLiteral( "BR" )
|
|
|
|
<< QStringLiteral( "pt_BR.UTF-8" );
|
2022-06-18 12:33:02 +02:00
|
|
|
|
|
|
|
QTest::newRow( "catalan ()" ) << QStringLiteral( "ca" ) << QStringLiteral( "" )
|
2022-06-19 15:25:23 +02:00
|
|
|
<< QStringLiteral( "ca_AD.UTF-8" ); // no country given? Matches first
|
|
|
|
QTest::newRow( "catalan (ES)" ) << QStringLiteral( "ca" ) << QStringLiteral( "ES" )
|
|
|
|
<< QStringLiteral( "ca_ES.UTF-8" );
|
|
|
|
QTest::newRow( "catalan (NL)" ) << QStringLiteral( "ca" ) << QStringLiteral( "NL" )
|
|
|
|
<< QStringLiteral( "ca_AD.UTF-8" );
|
|
|
|
QTest::newRow( "catalan (@valencia)" ) << QStringLiteral( "ca@valencia" ) << QStringLiteral( "ES" )
|
|
|
|
<< QStringLiteral( "ca_ES@valencia" ); // Prefers regional variant
|
2022-06-18 12:33:02 +02:00
|
|
|
QTest::newRow( "catalan (@valencia_NL)" )
|
2022-06-19 15:25:23 +02:00
|
|
|
<< QStringLiteral( "ca@valencia" ) << QStringLiteral( "NL" ) << QStringLiteral( "ca_ES@valencia" );
|
2022-06-18 12:33:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-19 15:25:23 +02:00
|
|
|
/*
|
|
|
|
* This list of available locales was created by grepping `/etc/locale.gen`
|
|
|
|
* on an EndeavourOS ISO image for a handful of representative locales.
|
|
|
|
*/
|
|
|
|
static const QStringList availableLocales {
|
|
|
|
"nl_AW", "nl_BE.UTF-8", "nl_NL.UTF-8", "en", "en_AU.UTF-8", "en_US.UTF-8", "en_GB.UTF-8",
|
|
|
|
"ca_AD.UTF-8", "ca_ES.UTF-8", "ca_ES@valencia", "sr_ME", "sr_RS", "sr_RS@latin", "pt_BR.UTF-8",
|
|
|
|
"pt_PT.UTF-8", "es_AR.UTF-8", "es_ES.UTF-8", "es_MX.UTF-8",
|
|
|
|
};
|
|
|
|
|
2022-06-18 12:33:02 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testLanguageDetection()
|
|
|
|
{
|
|
|
|
QFETCH( QString, locale );
|
|
|
|
QFETCH( QString, country );
|
|
|
|
QFETCH( QString, expected );
|
|
|
|
|
|
|
|
auto r = LocaleConfiguration::fromLanguageAndLocation( locale, availableLocales, country );
|
2022-06-19 15:25:23 +02:00
|
|
|
QCOMPARE( r.language(), expected );
|
2022-06-18 12:33:02 +02:00
|
|
|
}
|
|
|
|
|
2022-06-19 14:37:54 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testLanguageDetectionValencia()
|
|
|
|
{
|
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
|
|
|
|
{
|
|
|
|
auto r = LocaleConfiguration::fromLanguageAndLocation(
|
|
|
|
QStringLiteral( "nl" ), availableLocales, QStringLiteral( "NL" ) );
|
|
|
|
QCOMPARE( r.language(), "nl_NL.UTF-8" );
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto r = LocaleConfiguration::fromLanguageAndLocation(
|
|
|
|
QStringLiteral( "ca@valencia" ), availableLocales, QStringLiteral( "NL" ) );
|
2022-06-19 15:25:23 +02:00
|
|
|
QCOMPARE( r.language(), "ca_ES@valencia" );
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto r = LocaleConfiguration::fromLanguageAndLocation(
|
|
|
|
QStringLiteral( "sr" ), availableLocales, QStringLiteral( "NL" ) );
|
|
|
|
QCOMPARE( r.language(), "sr_ME" ); // Because that one is first in the list
|
|
|
|
}
|
|
|
|
{
|
|
|
|
auto r = LocaleConfiguration::fromLanguageAndLocation(
|
|
|
|
QStringLiteral( "sr@latin" ), availableLocales, QStringLiteral( "NL" ) );
|
|
|
|
QCOMPARE( r.language(), "sr_RS@latin" );
|
2022-06-19 14:37:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 18:05:24 +02:00
|
|
|
static QStringList
|
|
|
|
splitTestFileIntoLines( const QString& filename )
|
|
|
|
{
|
|
|
|
// BUILD_AS_TEST is the source-directory path
|
|
|
|
const QFileInfo fi( QString( "%1/tests/%2" ).arg( BUILD_AS_TEST, filename ) );
|
|
|
|
const QString path = fi.absoluteFilePath();
|
|
|
|
QFile testData( path );
|
|
|
|
if ( testData.open( QIODevice::ReadOnly ) )
|
|
|
|
{
|
|
|
|
return QString::fromUtf8( testData.readAll() ).split( '\n', Qt::SkipEmptyParts );
|
|
|
|
}
|
|
|
|
return QStringList {};
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testKDENeonLanguageData()
|
|
|
|
{
|
|
|
|
const QStringList neonLocales = splitTestFileIntoLines( QStringLiteral( "locale-data-neon" ) );
|
|
|
|
cDebug() << "Loaded KDE neon locales test data" << neonLocales.front() << "to" << neonLocales.back();
|
|
|
|
QCOMPARE( neonLocales.length(), 318 ); // wc -l tells me 318 lines
|
|
|
|
|
|
|
|
m_KDEneonLocales = neonLocales;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testLanguageMapping_data()
|
|
|
|
{
|
|
|
|
QTest::addColumn< QString >( "selectedLanguage" );
|
|
|
|
QTest::addColumn< QString >( "KDEneonLanguage" );
|
|
|
|
|
|
|
|
// Tired of writing QString or QStringLiteral all the time.
|
|
|
|
auto l = []( const char* p ) { return QString::fromUtf8( p ); };
|
|
|
|
|
|
|
|
// The KDEneon columns include the .UTF-8 from the source data
|
|
|
|
//
|
|
|
|
// Each column shows how a language -- which can be selected from the
|
|
|
|
// welcome page, and is inserted into GS as the language key that
|
|
|
|
// Calamares knows -- should be mapped to a supported system locale.
|
|
|
|
//
|
|
|
|
// All the mappings are for ".. in NL", which can trigger minor variation
|
|
|
|
// if there are languages with a _NL variant (e.g. nl_NL and nl_BE).
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
QTest::newRow( "en " ) << l( "en" ) << l( "en_US.UTF-8" );
|
|
|
|
QTest::newRow( "en_GB" ) << l( "en_GB" ) << l( "en_GB.UTF-8" );
|
|
|
|
QTest::newRow( "ca " ) << l( "ca" ) << l( "ca_ES.UTF-8" );
|
|
|
|
QTest::newRow( "ca@vl" ) << l( "ca@valencia" ) << l( "ca_ES@valencia" );
|
|
|
|
QTest::newRow( "sr " ) << l( "sr" ) << l( "sr_RS" );
|
|
|
|
QTest::newRow( "sr@lt" ) << l( "sr@latin" ) << l( "sr_RS@latin" );
|
|
|
|
QTest::newRow( "pt_PT" ) << l( "pt_PT" ) << l( "pt_PT.UTF-8" );
|
|
|
|
QTest::newRow( "pt_BR" ) << l( "pt_BR" ) << l( "pt_BR.UTF-8" );
|
|
|
|
QTest::newRow( "nl " ) << l( "nl" ) << l( "nl_NL.UTF-8" );
|
|
|
|
QTest::newRow( "zh_TW" ) << l( "zh_TW" ) << l( "zh_TW.UTF-8" );
|
|
|
|
// clang-format on
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testLanguageMapping()
|
|
|
|
{
|
|
|
|
QVERIFY( !m_KDEneonLocales.isEmpty() );
|
|
|
|
|
|
|
|
QFETCH( QString, selectedLanguage );
|
|
|
|
QFETCH( QString, KDEneonLanguage );
|
|
|
|
|
|
|
|
QVERIFY( Calamares::Locale::availableLanguages().contains( selectedLanguage ) );
|
|
|
|
|
|
|
|
const auto r = LocaleConfiguration::fromLanguageAndLocation(
|
|
|
|
( selectedLanguage ), m_KDEneonLocales, QStringLiteral( "NL" ) );
|
|
|
|
QCOMPARE( r.language(), KDEneonLanguage );
|
|
|
|
}
|
|
|
|
|
2020-08-06 12:32:48 +02:00
|
|
|
|
2020-08-06 12:14:15 +02:00
|
|
|
#include "utils/moc-warnings.h"
|
|
|
|
|
|
|
|
#include "Tests.moc"
|