2020-08-25 16:05:56 +02:00
|
|
|
/* === This file is part of Calamares - <https://calamares.io> ===
|
2020-08-04 12:59:55 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
* SPDX-FileCopyrightText: 2019 Adriaan de Groot <groot@kde.org>
|
2020-08-04 12:59:55 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2019-06-18 15:27:59 +02:00
|
|
|
*
|
2020-08-25 16:05:56 +02:00
|
|
|
* Calamares is Free Software: see the License-Identifier above.
|
2019-06-18 15:27:59 +02:00
|
|
|
*
|
2020-05-30 16:15:03 +02:00
|
|
|
*
|
2019-06-18 15:27:59 +02:00
|
|
|
*/
|
|
|
|
|
2020-09-03 20:15:28 +02:00
|
|
|
#include "locale/Global.h"
|
2019-06-18 15:27:59 +02:00
|
|
|
#include "locale/LabelModel.h"
|
2019-11-26 11:19:30 +01:00
|
|
|
#include "locale/TimeZone.h"
|
2019-08-05 17:57:32 +02:00
|
|
|
#include "locale/TranslatableConfiguration.h"
|
|
|
|
|
|
|
|
#include "CalamaresVersion.h"
|
2020-09-03 20:15:28 +02:00
|
|
|
#include "GlobalStorage.h"
|
2019-06-18 15:27:59 +02:00
|
|
|
#include "utils/Logger.h"
|
2021-04-18 13:19:55 +02:00
|
|
|
#include "utils/Retranslator.h"
|
2019-06-18 15:27:59 +02:00
|
|
|
|
|
|
|
#include <QtTest/QtTest>
|
|
|
|
|
2020-08-04 12:59:55 +02:00
|
|
|
class LocaleTests : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
LocaleTests();
|
|
|
|
~LocaleTests() override;
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase();
|
|
|
|
|
|
|
|
void testLanguageModelCount();
|
|
|
|
void testTranslatableLanguages();
|
|
|
|
void testTranslatableConfig1();
|
|
|
|
void testTranslatableConfig2();
|
2021-04-18 13:19:55 +02:00
|
|
|
void testTranslatableConfigContext();
|
2020-08-04 13:21:08 +02:00
|
|
|
void testLanguageScripts();
|
|
|
|
|
|
|
|
void testEsperanto();
|
|
|
|
void testInterlingue();
|
2020-08-04 12:59:55 +02:00
|
|
|
|
|
|
|
// TimeZone testing
|
2020-08-05 15:17:09 +02:00
|
|
|
void testRegions();
|
2020-08-04 12:59:55 +02:00
|
|
|
void testSimpleZones();
|
|
|
|
void testComplexZones();
|
2020-08-05 22:30:04 +02:00
|
|
|
void testTZLookup();
|
2020-08-05 23:46:14 +02:00
|
|
|
void testTZIterator();
|
2020-08-08 15:14:20 +02:00
|
|
|
void testLocationLookup_data();
|
2020-08-06 01:52:50 +02:00
|
|
|
void testLocationLookup();
|
2020-08-08 16:20:04 +02:00
|
|
|
void testLocationLookup2();
|
2020-09-03 20:15:28 +02:00
|
|
|
|
|
|
|
// Global Storage updates
|
|
|
|
void testGSUpdates();
|
2020-08-04 12:59:55 +02:00
|
|
|
};
|
2019-06-18 15:27:59 +02:00
|
|
|
|
2019-08-04 22:17:12 +02:00
|
|
|
LocaleTests::LocaleTests() {}
|
2019-06-18 15:27:59 +02:00
|
|
|
|
2019-08-04 22:17:12 +02:00
|
|
|
LocaleTests::~LocaleTests() {}
|
2019-06-18 15:27:59 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::initTestCase()
|
|
|
|
{
|
2020-08-04 13:21:08 +02:00
|
|
|
Logger::setupLogLevel( Logger::LOGDEBUG );
|
|
|
|
|
2019-08-07 12:31:52 +02:00
|
|
|
// Otherwise plain get() is dubious in the TranslatableConfiguration tests
|
2020-04-21 13:41:04 +02:00
|
|
|
QLocale::setDefault( QLocale( QStringLiteral( "en_US" ) ) );
|
2019-08-07 12:31:52 +02:00
|
|
|
QVERIFY( ( QLocale().name() == "C" ) || ( QLocale().name() == "en_US" ) );
|
2019-06-18 15:27:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testLanguageModelCount()
|
|
|
|
{
|
|
|
|
const auto* m = CalamaresUtils::Locale::availableTranslations();
|
|
|
|
|
|
|
|
QVERIFY( m );
|
|
|
|
QVERIFY( m->rowCount( QModelIndex() ) > 1 );
|
|
|
|
|
|
|
|
int dutch = m->find( QLocale( "nl_NL" ) );
|
|
|
|
QVERIFY( dutch > 0 );
|
|
|
|
QCOMPARE( m->find( "NL" ), dutch );
|
|
|
|
// must be capitals
|
|
|
|
QCOMPARE( m->find( "nl" ), -1 );
|
|
|
|
QCOMPARE( m->find( QLocale( "nl" ) ), dutch );
|
|
|
|
|
|
|
|
// Belgium speaks Dutch as well
|
|
|
|
QCOMPARE( m->find( "BE" ), dutch );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-08-04 13:21:08 +02:00
|
|
|
LocaleTests::testLanguageScripts()
|
2019-06-18 15:27:59 +02:00
|
|
|
{
|
|
|
|
const auto* m = CalamaresUtils::Locale::availableTranslations();
|
|
|
|
|
|
|
|
QVERIFY( m );
|
|
|
|
|
|
|
|
// Cursory test that all the locales found have a sensible language,
|
|
|
|
// and that some specific languages have sensible corresponding data.
|
|
|
|
//
|
|
|
|
// This fails on Esperanto (or, if Esperanto is added to Qt, then
|
|
|
|
// this will pass and the test after the loop will fail.
|
|
|
|
for ( int i = 0; i < m->rowCount( QModelIndex() ); ++i )
|
|
|
|
{
|
|
|
|
const auto& label = m->locale( i );
|
|
|
|
const auto locale = label.locale();
|
|
|
|
cDebug() << label.label() << locale;
|
|
|
|
|
|
|
|
QVERIFY( locale.language() == QLocale::Greek ? locale.script() == QLocale::GreekScript : true );
|
|
|
|
QVERIFY( locale.language() == QLocale::Korean ? locale.script() == QLocale::KoreanScript : true );
|
|
|
|
QVERIFY( locale.language() == QLocale::Lithuanian ? locale.country() == QLocale::Lithuania : true );
|
|
|
|
QVERIFY( locale.language() != QLocale::C );
|
|
|
|
}
|
2020-08-04 13:21:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testEsperanto()
|
|
|
|
{
|
2019-08-05 18:30:50 +02:00
|
|
|
#if QT_VERSION < QT_VERSION_CHECK( 5, 12, 2 )
|
2019-06-18 15:27:59 +02:00
|
|
|
QCOMPARE( QLocale( "eo" ).language(), QLocale::C );
|
2020-08-09 22:35:10 +02:00
|
|
|
QCOMPARE( QLocale( QLocale::Esperanto ).language(), QLocale::English );
|
2019-08-05 18:30:50 +02:00
|
|
|
#else
|
|
|
|
QCOMPARE( QLocale( "eo" ).language(), QLocale::Esperanto );
|
2020-08-04 13:21:08 +02:00
|
|
|
QCOMPARE( QLocale( QLocale::Esperanto ).language(), QLocale::Esperanto ); // Probably fails on 5.12, too
|
2020-08-09 22:35:10 +02:00
|
|
|
#endif
|
2019-06-18 15:27:59 +02:00
|
|
|
}
|
2019-08-05 17:57:32 +02:00
|
|
|
|
2020-08-04 13:21:08 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testInterlingue()
|
|
|
|
{
|
|
|
|
// ie / Interlingue is borked (is "ie" even the right name?)
|
|
|
|
QCOMPARE( QLocale( "ie" ).language(), QLocale::C );
|
|
|
|
QCOMPARE( QLocale( QLocale::Interlingue ).language(), QLocale::English );
|
|
|
|
|
|
|
|
// "ia" exists (post-war variant of Interlingue)
|
|
|
|
QCOMPARE( QLocale( "ia" ).language(), QLocale::Interlingua );
|
|
|
|
// "bork" does not exist
|
|
|
|
QCOMPARE( QLocale( "bork" ).language(), QLocale::C );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-08-05 17:57:32 +02:00
|
|
|
static const QStringList&
|
|
|
|
someLanguages()
|
|
|
|
{
|
2019-08-05 23:54:53 +02:00
|
|
|
static QStringList languages { "nl", "de", "da", "nb", "sr@latin", "ar", "ru" };
|
2019-08-05 17:57:32 +02:00
|
|
|
return languages;
|
2019-08-05 23:54:53 +02:00
|
|
|
}
|
2019-08-05 17:57:32 +02:00
|
|
|
|
2019-08-05 23:54:53 +02:00
|
|
|
|
2019-08-06 11:53:35 +02:00
|
|
|
/** @brief Check consistency of test data
|
|
|
|
* Check that all the languages used in testing, are actually enabled
|
|
|
|
* in Calamares translations.
|
|
|
|
*/
|
2019-08-05 23:54:53 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testTranslatableLanguages()
|
2019-08-05 17:57:32 +02:00
|
|
|
{
|
|
|
|
QStringList availableLanguages = QString( CALAMARES_TRANSLATION_LANGUAGES ).split( ';' );
|
|
|
|
cDebug() << "Translation languages:" << availableLanguages;
|
2019-08-05 23:54:53 +02:00
|
|
|
for ( const auto& language : someLanguages() )
|
2019-08-05 17:57:32 +02:00
|
|
|
{
|
|
|
|
// Could be QVERIFY, but then we don't see what language code fails
|
|
|
|
QCOMPARE( availableLanguages.contains( language ) ? language : QString(), language );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 11:53:35 +02:00
|
|
|
/** @brief Test strings with no translations
|
|
|
|
*/
|
2019-08-05 23:54:53 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testTranslatableConfig1()
|
2019-08-05 17:57:32 +02:00
|
|
|
{
|
2019-08-06 11:53:35 +02:00
|
|
|
CalamaresUtils::Locale::TranslatedString ts0;
|
|
|
|
QVERIFY( ts0.isEmpty() );
|
|
|
|
QCOMPARE( ts0.count(), 1 ); // the empty string
|
|
|
|
|
2019-08-05 17:57:32 +02:00
|
|
|
CalamaresUtils::Locale::TranslatedString ts1( "Hello" );
|
|
|
|
QCOMPARE( ts1.count(), 1 );
|
2019-08-06 11:53:35 +02:00
|
|
|
QVERIFY( !ts1.isEmpty() );
|
2019-08-05 23:54:53 +02:00
|
|
|
|
2020-02-21 17:58:55 +01:00
|
|
|
QCOMPARE( ts1.get(), QStringLiteral( "Hello" ) );
|
|
|
|
QCOMPARE( ts1.get( QLocale( "nl" ) ), QStringLiteral( "Hello" ) );
|
2019-08-05 23:54:53 +02:00
|
|
|
|
2019-08-05 17:57:32 +02:00
|
|
|
QVariantMap map;
|
|
|
|
map.insert( "description", "description (no language)" );
|
2019-08-05 23:54:53 +02:00
|
|
|
CalamaresUtils::Locale::TranslatedString ts2( map, "description" );
|
2019-08-05 17:57:32 +02:00
|
|
|
QCOMPARE( ts2.count(), 1 );
|
2019-08-06 11:53:35 +02:00
|
|
|
QVERIFY( !ts2.isEmpty() );
|
2019-08-05 23:54:53 +02:00
|
|
|
|
2020-02-21 17:58:55 +01:00
|
|
|
QCOMPARE( ts2.get(), QStringLiteral( "description (no language)" ) );
|
|
|
|
QCOMPARE( ts2.get( QLocale( "nl" ) ), QStringLiteral( "description (no language)" ) );
|
2019-08-05 17:57:32 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 11:53:35 +02:00
|
|
|
/** @bref Test strings with translations.
|
|
|
|
*/
|
2019-08-05 23:54:53 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testTranslatableConfig2()
|
2019-08-05 17:57:32 +02:00
|
|
|
{
|
|
|
|
QVariantMap map;
|
2019-08-05 23:54:53 +02:00
|
|
|
|
|
|
|
for ( const auto& language : someLanguages() )
|
2019-08-05 17:57:32 +02:00
|
|
|
{
|
2019-08-05 23:54:53 +02:00
|
|
|
map.insert( QString( "description[%1]" ).arg( language ),
|
|
|
|
QString( "description (language %1)" ).arg( language ) );
|
2019-08-05 23:30:51 +02:00
|
|
|
if ( language != "nl" )
|
|
|
|
{
|
2019-08-05 23:54:53 +02:00
|
|
|
map.insert( QString( "name[%1]" ).arg( language ), QString( "name (language %1)" ).arg( language ) );
|
2019-08-05 23:30:51 +02:00
|
|
|
}
|
2019-08-05 17:57:32 +02:00
|
|
|
}
|
2019-08-05 23:54:53 +02:00
|
|
|
|
2019-08-06 11:53:35 +02:00
|
|
|
// If there's no untranslated string in the map, it is considered empty
|
|
|
|
CalamaresUtils::Locale::TranslatedString ts0( map, "description" );
|
|
|
|
QVERIFY( ts0.isEmpty() ); // Because no untranslated string
|
|
|
|
QCOMPARE( ts0.count(),
|
|
|
|
someLanguages().count() + 1 ); // But there are entries for the translations, plus an empty string
|
|
|
|
|
|
|
|
// expand the map with untranslated entries
|
|
|
|
map.insert( QString( "description" ), "description (no language)" );
|
|
|
|
map.insert( QString( "name" ), "name (no language)" );
|
|
|
|
|
2019-08-05 23:54:53 +02:00
|
|
|
CalamaresUtils::Locale::TranslatedString ts1( map, "description" );
|
2019-08-05 17:57:32 +02:00
|
|
|
// The +1 is because "" is always also inserted
|
2019-08-05 23:54:53 +02:00
|
|
|
QCOMPARE( ts1.count(), someLanguages().count() + 1 );
|
2019-08-06 11:53:35 +02:00
|
|
|
QVERIFY( !ts1.isEmpty() );
|
2019-08-05 23:54:53 +02:00
|
|
|
|
2020-02-21 17:58:55 +01:00
|
|
|
QCOMPARE( ts1.get(), QStringLiteral( "description (no language)" ) ); // it wasn't set
|
|
|
|
QCOMPARE( ts1.get( QLocale( "nl" ) ), QStringLiteral( "description (language nl)" ) );
|
2019-08-06 00:05:24 +02:00
|
|
|
for ( const auto& language : someLanguages() )
|
|
|
|
{
|
|
|
|
// Skip Serbian (latin) because QLocale() constructed with it
|
|
|
|
// doesn't retain the @latin part.
|
|
|
|
if ( language == "sr@latin" )
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Could be QVERIFY, but then we don't see what language code fails
|
|
|
|
QCOMPARE( ts1.get( language ) == QString( "description (language %1)" ).arg( language ) ? language : QString(),
|
|
|
|
language );
|
|
|
|
}
|
|
|
|
QCOMPARE( ts1.get( QLocale( QLocale::Language::Serbian, QLocale::Script::LatinScript, QLocale::Country::Serbia ) ),
|
2020-02-21 17:58:55 +01:00
|
|
|
QStringLiteral( "description (language sr@latin)" ) );
|
2019-08-05 23:37:25 +02:00
|
|
|
|
2019-08-05 23:54:53 +02:00
|
|
|
CalamaresUtils::Locale::TranslatedString ts2( map, "name" );
|
2019-08-05 23:30:51 +02:00
|
|
|
// We skipped dutch this time
|
|
|
|
QCOMPARE( ts2.count(), someLanguages().count() );
|
2019-08-06 11:53:35 +02:00
|
|
|
QVERIFY( !ts2.isEmpty() );
|
|
|
|
|
|
|
|
// This key doesn't exist
|
|
|
|
CalamaresUtils::Locale::TranslatedString ts3( map, "front" );
|
|
|
|
QVERIFY( ts3.isEmpty() );
|
|
|
|
QCOMPARE( ts3.count(), 1 ); // The empty string
|
2019-08-05 17:57:32 +02:00
|
|
|
}
|
2019-11-26 11:19:30 +01:00
|
|
|
|
2021-04-18 13:19:55 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testTranslatableConfigContext()
|
|
|
|
{
|
|
|
|
using TS = CalamaresUtils::Locale::TranslatedString;
|
|
|
|
|
|
|
|
const QString original( "Quit" );
|
|
|
|
TS quitUntranslated( original );
|
|
|
|
TS quitTranslated( original, metaObject()->className() );
|
|
|
|
|
|
|
|
QCOMPARE( quitUntranslated.get(), original );
|
|
|
|
QCOMPARE( quitTranslated.get(), original );
|
|
|
|
|
|
|
|
// Load translation data from QRC
|
|
|
|
QVERIFY( QFile::exists( ":/lang/localetest_nl.qm" ) );
|
|
|
|
QTranslator t;
|
|
|
|
QVERIFY( t.load( QString( ":/lang/localetest_nl" ) ) );
|
|
|
|
QCoreApplication::installTranslator( &t );
|
|
|
|
|
|
|
|
// Translation doesn't affect the one without context
|
|
|
|
QCOMPARE( quitUntranslated.get(), original );
|
|
|
|
// But the translation **does** affect this class' context
|
|
|
|
QCOMPARE( quitTranslated.get(), QStringLiteral( "Ophouden" ) );
|
|
|
|
QCOMPARE( tr( "Quit" ), QStringLiteral( "Ophouden" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-05 15:17:09 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testRegions()
|
|
|
|
{
|
2020-08-05 16:45:41 +02:00
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
RegionsModel regions;
|
2020-08-05 15:17:09 +02:00
|
|
|
|
|
|
|
QVERIFY( regions.rowCount( QModelIndex() ) > 3 ); // Africa, America, Asia
|
2020-08-05 16:25:45 +02:00
|
|
|
|
|
|
|
QStringList names;
|
|
|
|
for ( int i = 0; i < regions.rowCount( QModelIndex() ); ++i )
|
|
|
|
{
|
2020-08-05 16:45:41 +02:00
|
|
|
QVariant name = regions.data( regions.index( i ), RegionsModel::NameRole );
|
2020-08-05 16:25:45 +02:00
|
|
|
QVERIFY( name.isValid() );
|
|
|
|
QVERIFY( !name.toString().isEmpty() );
|
|
|
|
names.append( name.toString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY( names.contains( "America" ) );
|
2020-08-05 16:36:00 +02:00
|
|
|
QVERIFY( !names.contains( "UTC" ) );
|
2020-08-05 15:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-05 17:14:13 +02:00
|
|
|
static void
|
|
|
|
displayedNames( QAbstractItemModel& model, QStringList& names )
|
|
|
|
{
|
|
|
|
names.clear();
|
|
|
|
for ( int i = 0; i < model.rowCount( QModelIndex() ); ++i )
|
|
|
|
{
|
|
|
|
QVariant name = model.data( model.index( i, 0 ), Qt::DisplayRole );
|
|
|
|
QVERIFY( name.isValid() );
|
|
|
|
QVERIFY( !name.toString().isEmpty() );
|
|
|
|
names.append( name.toString() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-26 11:19:30 +01:00
|
|
|
void
|
|
|
|
LocaleTests::testSimpleZones()
|
|
|
|
{
|
2020-08-05 16:45:41 +02:00
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
ZonesModel zones;
|
2020-08-05 16:21:05 +02:00
|
|
|
|
|
|
|
QVERIFY( zones.rowCount( QModelIndex() ) > 24 );
|
2020-08-05 16:45:41 +02:00
|
|
|
|
|
|
|
QStringList names;
|
2020-08-05 17:14:13 +02:00
|
|
|
displayedNames( zones, names );
|
2020-08-05 16:45:41 +02:00
|
|
|
QVERIFY( names.contains( "Amsterdam" ) );
|
|
|
|
if ( !names.contains( "New York" ) )
|
|
|
|
{
|
|
|
|
for ( const auto& s : names )
|
|
|
|
{
|
|
|
|
if ( s.startsWith( 'N' ) )
|
|
|
|
{
|
|
|
|
cDebug() << s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QVERIFY( names.contains( "New York" ) );
|
|
|
|
QVERIFY( !names.contains( "America" ) );
|
|
|
|
QVERIFY( !names.contains( "New_York" ) );
|
2019-11-26 11:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LocaleTests::testComplexZones()
|
|
|
|
{
|
2019-11-26 12:28:41 +01:00
|
|
|
using namespace CalamaresUtils::Locale;
|
2020-08-05 17:14:13 +02:00
|
|
|
ZonesModel zones;
|
|
|
|
RegionalZonesModel europe( &zones );
|
|
|
|
|
|
|
|
QStringList names;
|
|
|
|
displayedNames( zones, names );
|
|
|
|
QVERIFY( names.contains( "New York" ) );
|
|
|
|
QVERIFY( names.contains( "Prague" ) );
|
|
|
|
QVERIFY( names.contains( "Abidjan" ) );
|
|
|
|
|
|
|
|
// No region set
|
|
|
|
displayedNames( europe, names );
|
|
|
|
QVERIFY( names.contains( "New York" ) );
|
|
|
|
QVERIFY( names.contains( "Prague" ) );
|
|
|
|
QVERIFY( names.contains( "Abidjan" ) );
|
|
|
|
|
|
|
|
// Now filter
|
|
|
|
europe.setRegion( "Europe" );
|
|
|
|
displayedNames( europe, names );
|
|
|
|
QVERIFY( !names.contains( "New York" ) );
|
|
|
|
QVERIFY( names.contains( "Prague" ) );
|
|
|
|
QVERIFY( !names.contains( "Abidjan" ) );
|
|
|
|
|
|
|
|
europe.setRegion( "America" );
|
|
|
|
displayedNames( europe, names );
|
|
|
|
QVERIFY( names.contains( "New York" ) );
|
|
|
|
QVERIFY( !names.contains( "Prague" ) );
|
|
|
|
QVERIFY( !names.contains( "Abidjan" ) );
|
|
|
|
|
|
|
|
europe.setRegion( "Africa" );
|
|
|
|
displayedNames( europe, names );
|
|
|
|
QVERIFY( !names.contains( "New York" ) );
|
|
|
|
QVERIFY( !names.contains( "Prague" ) );
|
|
|
|
QVERIFY( names.contains( "Abidjan" ) );
|
2019-11-26 11:19:30 +01:00
|
|
|
}
|
2020-08-04 12:59:55 +02:00
|
|
|
|
2020-08-05 22:30:04 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testTZLookup()
|
|
|
|
{
|
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
ZonesModel zones;
|
|
|
|
|
|
|
|
QVERIFY( zones.find( "America", "New_York" ) );
|
|
|
|
QCOMPARE( zones.find( "America", "New_York" )->zone(), QStringLiteral( "New_York" ) );
|
|
|
|
QCOMPARE( zones.find( "America", "New_York" )->tr(), QStringLiteral( "New York" ) );
|
|
|
|
|
|
|
|
QVERIFY( !zones.find( "Europe", "New_York" ) );
|
|
|
|
QVERIFY( !zones.find( "America", "New York" ) );
|
|
|
|
}
|
|
|
|
|
2020-08-05 23:46:14 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testTZIterator()
|
|
|
|
{
|
|
|
|
using namespace CalamaresUtils::Locale;
|
|
|
|
const ZonesModel zones;
|
|
|
|
|
|
|
|
QVERIFY( zones.find( "Europe", "Rome" ) );
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
bool seenRome = false;
|
|
|
|
bool seenGnome = false;
|
|
|
|
for ( auto it = zones.begin(); it; ++it )
|
|
|
|
{
|
|
|
|
QVERIFY( *it );
|
|
|
|
QVERIFY( !( *it )->zone().isEmpty() );
|
|
|
|
seenRome |= ( *it )->zone() == QStringLiteral( "Rome" );
|
|
|
|
seenGnome |= ( *it )->zone() == QStringLiteral( "Gnome" );
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
QVERIFY( seenRome );
|
|
|
|
QVERIFY( !seenGnome );
|
|
|
|
QCOMPARE( count, zones.rowCount( QModelIndex() ) );
|
2020-08-06 00:56:13 +02:00
|
|
|
|
|
|
|
QCOMPARE( zones.data( zones.index( 0 ), ZonesModel::RegionRole ).toString(), QStringLiteral( "Africa" ) );
|
|
|
|
QCOMPARE( ( *zones.begin() )->zone(), QStringLiteral( "Abidjan" ) );
|
2020-08-05 23:46:14 +02:00
|
|
|
}
|
|
|
|
|
2020-08-06 01:52:50 +02:00
|
|
|
void
|
2020-08-08 15:14:20 +02:00
|
|
|
LocaleTests::testLocationLookup_data()
|
2020-08-06 01:52:50 +02:00
|
|
|
{
|
2020-08-08 15:14:20 +02:00
|
|
|
QTest::addColumn< double >( "latitude" );
|
|
|
|
QTest::addColumn< double >( "longitude" );
|
|
|
|
QTest::addColumn< QString >( "name" );
|
2020-08-06 01:52:50 +02:00
|
|
|
|
2020-08-08 15:14:20 +02:00
|
|
|
QTest::newRow( "London" ) << 50.0 << 0.0 << QString( "London" );
|
|
|
|
QTest::newRow( "Tarawa E" ) << 0.0 << 179.0 << QString( "Tarawa" );
|
|
|
|
QTest::newRow( "Tarawa W" ) << 0.0 << -179.0 << QString( "Tarawa" );
|
2020-08-06 11:57:05 +02:00
|
|
|
|
2020-08-08 15:40:13 +02:00
|
|
|
QTest::newRow( "Johannesburg" ) << -26.0 << 28.0 << QString( "Johannesburg" ); // South Africa
|
|
|
|
QTest::newRow( "Maseru" ) << -29.0 << 27.0 << QString( "Maseru" ); // Lesotho
|
|
|
|
QTest::newRow( "Windhoek" ) << -22.0 << 17.0 << QString( "Windhoek" ); // Namibia
|
|
|
|
QTest::newRow( "Port Elisabeth" ) << -33.0 << 25.0 << QString( "Johannesburg" ); // South Africa
|
|
|
|
QTest::newRow( "Cape Town" ) << -33.0 << 18.0 << QString( "Johannesburg" ); // South Africa
|
2020-08-08 15:14:20 +02:00
|
|
|
}
|
2020-08-06 11:57:05 +02:00
|
|
|
|
2020-08-08 15:14:20 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testLocationLookup()
|
|
|
|
{
|
|
|
|
const CalamaresUtils::Locale::ZonesModel zones;
|
|
|
|
|
|
|
|
QFETCH( double, latitude );
|
|
|
|
QFETCH( double, longitude );
|
|
|
|
QFETCH( QString, name );
|
2020-08-06 11:57:05 +02:00
|
|
|
|
2020-08-08 15:14:20 +02:00
|
|
|
const auto* zone = zones.find( latitude, longitude );
|
2020-08-06 11:57:05 +02:00
|
|
|
QVERIFY( zone );
|
2020-08-08 15:14:20 +02:00
|
|
|
QCOMPARE( zone->zone(), name );
|
2020-08-06 01:52:50 +02:00
|
|
|
}
|
|
|
|
|
2020-08-08 16:20:04 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testLocationLookup2()
|
|
|
|
{
|
|
|
|
// Official
|
|
|
|
// ZA -2615+02800 Africa/Johannesburg
|
|
|
|
// Spot patch
|
|
|
|
// "ZA -3230+02259 Africa/Johannesburg\n";
|
|
|
|
|
|
|
|
const CalamaresUtils::Locale::ZonesModel zones;
|
|
|
|
const auto* zone = zones.find( -26.15, 28.00 );
|
|
|
|
QCOMPARE( zone->zone(), QString( "Johannesburg" ) );
|
|
|
|
// The TZ data sources use minutes-and-seconds notation,
|
|
|
|
// so "2615" is 26 degrees, 15 minutes, and 15 minutes is
|
|
|
|
// one-quarter of a degree.
|
|
|
|
QCOMPARE( zone->latitude(), -26.25 );
|
|
|
|
QCOMPARE( zone->longitude(), 28.00 );
|
|
|
|
|
|
|
|
// Elsewhere in South Africa
|
|
|
|
const auto* altzone = zones.find( -32.0, 22.0 );
|
|
|
|
QCOMPARE( altzone, zone ); // same pointer
|
|
|
|
QCOMPARE( altzone->zone(), QString( "Johannesburg" ) );
|
|
|
|
QCOMPARE( altzone->latitude(), -26.25 );
|
|
|
|
QCOMPARE( altzone->longitude(), 28.00 );
|
|
|
|
|
|
|
|
altzone = zones.find( -29.0, 27.0 );
|
|
|
|
QCOMPARE( altzone->zone(), QString( "Maseru" ) );
|
|
|
|
// -2928, that's -29 and 28/60 of a degree, is almost half, but we don't want
|
|
|
|
// to fall foul of variations in double-precision
|
|
|
|
QCOMPARE( trunc( altzone->latitude() * 1000.0 ), -29466 );
|
|
|
|
}
|
|
|
|
|
2020-09-03 20:15:28 +02:00
|
|
|
void
|
|
|
|
LocaleTests::testGSUpdates()
|
|
|
|
{
|
|
|
|
Calamares::GlobalStorage gs;
|
|
|
|
|
|
|
|
const QString gsKey( "localeConf" );
|
|
|
|
|
|
|
|
QCOMPARE( gs.value( gsKey ), QVariant() );
|
|
|
|
|
|
|
|
// Insert one
|
|
|
|
{
|
|
|
|
CalamaresUtils::Locale::insertGS( gs, "LANG", "en_US" );
|
|
|
|
auto map = gs.value( gsKey ).toMap();
|
|
|
|
QCOMPARE( map.count(), 1 );
|
|
|
|
QCOMPARE( map.value( "LANG" ).toString(), QString( "en_US" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overwrite one
|
|
|
|
{
|
|
|
|
CalamaresUtils::Locale::insertGS( gs, "LANG", "nl_BE" );
|
|
|
|
auto map = gs.value( gsKey ).toMap();
|
|
|
|
QCOMPARE( map.count(), 1 );
|
|
|
|
QCOMPARE( map.value( "LANG" ).toString(), QString( "nl_BE" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert a second value
|
|
|
|
{
|
|
|
|
CalamaresUtils::Locale::insertGS( gs, "LC_TIME", "UTC" );
|
|
|
|
auto map = gs.value( gsKey ).toMap();
|
|
|
|
QCOMPARE( map.count(), 2 );
|
|
|
|
QCOMPARE( map.value( "LANG" ).toString(), QString( "nl_BE" ) );
|
|
|
|
QCOMPARE( map.value( "LC_TIME" ).toString(), QString( "UTC" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overwrite parts
|
|
|
|
{
|
|
|
|
QMap< QString, QString > kv;
|
|
|
|
kv.insert( "LANG", "en_SU" );
|
|
|
|
kv.insert( "LC_CURRENCY", "rbl" );
|
|
|
|
|
|
|
|
// Overwrite one, add one
|
|
|
|
CalamaresUtils::Locale::insertGS( gs, kv, CalamaresUtils::Locale::InsertMode::Merge );
|
|
|
|
auto map = gs.value( gsKey ).toMap();
|
|
|
|
QCOMPARE( map.count(), 3 );
|
|
|
|
QCOMPARE( map.value( "LANG" ).toString(), QString( "en_SU" ) );
|
|
|
|
QCOMPARE( map.value( "LC_TIME" ).toString(), QString( "UTC" ) ); // unchanged
|
|
|
|
QCOMPARE( map.value( "LC_CURRENCY" ).toString(), QString( "rbl" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overwrite with clear
|
|
|
|
{
|
|
|
|
QMap< QString, QString > kv;
|
|
|
|
kv.insert( "LANG", "en_US" );
|
|
|
|
kv.insert( "LC_CURRENCY", "peso" );
|
|
|
|
|
|
|
|
// Overwrite one, add one
|
|
|
|
CalamaresUtils::Locale::insertGS( gs, kv, CalamaresUtils::Locale::InsertMode::Overwrite );
|
|
|
|
auto map = gs.value( gsKey ).toMap();
|
|
|
|
QCOMPARE( map.count(), 2 ); // the rest were cleared
|
|
|
|
QCOMPARE( map.value( "LANG" ).toString(), QString( "en_US" ) );
|
|
|
|
QVERIFY( !map.contains( "LC_TIME" ) );
|
|
|
|
QCOMPARE( map.value( "LC_TIME" ).toString(), QString() ); // removed
|
|
|
|
QCOMPARE( map.value( "LC_CURRENCY" ).toString(), QString( "peso" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-05 22:30:04 +02:00
|
|
|
|
2020-08-04 12:59:55 +02:00
|
|
|
QTEST_GUILESS_MAIN( LocaleTests )
|
|
|
|
|
|
|
|
#include "utils/moc-warnings.h"
|
|
|
|
|
|
|
|
#include "Tests.moc"
|