From a5cef2175e27add57fa761ebdd045e7323adfbd8 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 18 Jun 2019 15:27:59 +0200 Subject: [PATCH] [libcalamares] Add tests for the locale service - Minimal tests just check that all the availableTranslations() entries have a reasonable language setting. - Checks that Esperanto is still broken as a locale in Qt. --- src/libcalamares/CMakeLists.txt | 14 ++++- src/libcalamares/locale/Tests.cpp | 87 +++++++++++++++++++++++++++++++ src/libcalamares/locale/Tests.h | 38 ++++++++++++++ 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 src/libcalamares/locale/Tests.cpp create mode 100644 src/libcalamares/locale/Tests.h diff --git a/src/libcalamares/CMakeLists.txt b/src/libcalamares/CMakeLists.txt index b414887c4..f74c11b0c 100644 --- a/src/libcalamares/CMakeLists.txt +++ b/src/libcalamares/CMakeLists.txt @@ -167,16 +167,26 @@ if ( ECM_FOUND AND BUILD_TESTING ) ${YAMLCPP_LIBRARY} ) calamares_automoc( geoiptest ) - + ecm_add_test( partition/Tests.cpp TEST_NAME libcalamarespartitiontest LINK_LIBRARIES - calamares + calamares Qt5::Test ) calamares_automoc( libcalamarespartitiontest ) + + ecm_add_test( + locale/Tests.cpp + TEST_NAME + libcalamareslocaletest + LINK_LIBRARIES + calamares + Qt5::Test + ) + calamares_automoc( libcalamareslocaletest ) endif() if( BUILD_TESTING ) diff --git a/src/libcalamares/locale/Tests.cpp b/src/libcalamares/locale/Tests.cpp new file mode 100644 index 000000000..6fd0f3e61 --- /dev/null +++ b/src/libcalamares/locale/Tests.cpp @@ -0,0 +1,87 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * 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 . + */ + +#include "Tests.h" + +#include "locale/LabelModel.h" +#include "utils/Logger.h" + +#include + +QTEST_GUILESS_MAIN( LocaleTests ) + +LocaleTests::LocaleTests() +{ +} + +LocaleTests::~LocaleTests() +{ +} + +void +LocaleTests::initTestCase() +{ +} + +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 +LocaleTests::testEsperanto() +{ + Logger::setupLogLevel( Logger::LOGDEBUG ); + + 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 ); + } + + QCOMPARE( QLocale( "eo" ).language(), QLocale::C ); +} diff --git a/src/libcalamares/locale/Tests.h b/src/libcalamares/locale/Tests.h new file mode 100644 index 000000000..be712388f --- /dev/null +++ b/src/libcalamares/locale/Tests.h @@ -0,0 +1,38 @@ +/* === This file is part of Calamares - === + * + * Copyright 2019, Adriaan de Groot + * + * 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 . + */ + +#ifndef LIBCALAMARES_LOCALE_TESTS_H +#define LIBCALAMARES_LOCALE_TESTS_H + +#include + +class LocaleTests : public QObject +{ + Q_OBJECT +public: + LocaleTests(); + ~LocaleTests() override; + +private Q_SLOTS: + void initTestCase(); + + void testLanguageModelCount(); + void testEsperanto(); +}; + +#endif