diff --git a/tests/core/ApplicationInfoTest.cpp b/tests/core/ApplicationInfoTest.cpp index 327f836ab..117711734 100644 --- a/tests/core/ApplicationInfoTest.cpp +++ b/tests/core/ApplicationInfoTest.cpp @@ -1,178 +1,178 @@ /* GCompris - ApplicationInfoTest.cpp * * Copyright (C) 2018 Billy Laws * GCompris (C) 2018 GCompris Developers * * Authors: * Billy Laws * * This program 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. * * This program 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 this program; if not, see . */ #include #include #include "src/core/ApplicationInfo.h" class ApplicationInfoTest : public QObject { public: Q_OBJECT private slots: void LocaleTest_data(); void LocaleTest(); void WindowTest_data(); void WindowTest(); void getVoicesLocaleTest_data(); void getVoicesLocaleTest(); void getAudioFilePathForLocaleTest_data(); void getAudioFilePathForLocaleTest(); }; void ApplicationInfoTest::LocaleTest_data() { QTest::addColumn("localeFull"); QTest::addColumn("localeShort"); QTest::addColumn("higherWord"); QTest::addColumn("lowerWord"); QTest::newRow("British English") << QStringLiteral("en_GB") << QStringLiteral("en") << QStringLiteral("apple") << QStringLiteral("banana"); } void ApplicationInfoTest::LocaleTest() { ApplicationInfo appInfo; ApplicationInfo::getInstance(); QFETCH(QString, localeFull); QFETCH(QString, localeShort); QFETCH(QString, higherWord); QFETCH(QString, lowerWord); QVERIFY(appInfo.localeShort(localeFull) == localeShort); QVERIFY(appInfo.localeCompare(higherWord, lowerWord, localeFull) == -1); QVERIFY(appInfo.localeCompare(lowerWord, higherWord, localeFull) == 1); QVERIFY(appInfo.localeCompare(higherWord, higherWord, localeFull) == 0); QVariantList sortList; sortList.append(QVariant(higherWord)); sortList.append(QVariant(lowerWord)); sortList.append(QVariant(higherWord)); sortList.append(QVariant(lowerWord)); sortList = appInfo.localeSort(sortList, localeFull); QVERIFY(sortList[0] == higherWord); QVERIFY(sortList[1] == higherWord); QVERIFY(sortList[2] == lowerWord); QVERIFY(sortList[3] == lowerWord); } void ApplicationInfoTest::WindowTest_data() { QTest::addColumn("useOpenGL"); QTest::addColumn("applicationWidth"); QTest::addColumn("portraitMode"); QTest::newRow("dummy1") << true << 1920 << true; } void ApplicationInfoTest::WindowTest() { ApplicationInfo appInfo; ApplicationInfo::getInstance(); QFETCH(bool, useOpenGL); QFETCH(int, applicationWidth); QFETCH(bool, portraitMode); appInfo.setApplicationWidth(applicationWidth); appInfo.setIsPortraitMode(portraitMode); appInfo.setUseOpenGL(useOpenGL); QVERIFY(appInfo.useOpenGL() == useOpenGL); QVERIFY(appInfo.applicationWidth() == applicationWidth); QVERIFY(appInfo.isPortraitMode() == portraitMode); } void ApplicationInfoTest::getVoicesLocaleTest_data() { QTest::addColumn("actual"); QTest::addColumn("expected"); QTest::newRow("default") << GC_DEFAULT_LOCALE << "en"; QTest::newRow("en_US") << "en_US" - << "en"; + << "en_US"; QTest::newRow("pt_BR") << "pt_BR" << "pt_BR"; QTest::newRow("pt_PT") << "pt_PT" << "pt"; QTest::newRow("fr_FR") << "fr_FR" << "fr"; } void ApplicationInfoTest::getVoicesLocaleTest() { // Set default locale to "C". ALlows to test GC_DEFAULT_LOCALE QLocale defaultLocale = QLocale::system(); QLocale::setDefault(QLocale::c()); ApplicationInfo appInfo; ApplicationInfo::getInstance(); QFETCH(QString, actual); QFETCH(QString, expected); QCOMPARE(appInfo.getVoicesLocale(actual), expected); QLocale::setDefault(defaultLocale); } void ApplicationInfoTest::getAudioFilePathForLocaleTest_data() { QTest::addColumn("file"); QTest::addColumn("locale"); QTest::addColumn("expected"); QTest::newRow("absolutePath_en") << "/$LOCALE/$CA" << "en" << QString("/en/%1").arg(COMPRESSED_AUDIO); QTest::newRow("absolutePath_pt_BR") << "qrc:/$LOCALE/test" << "pt_BR" << "qrc:/pt_BR/test"; QTest::newRow("absolute_fr") << ":/test/test2" << "unused" << ":/test/test2"; QTest::newRow("relative_fr") << "$LOCALE/$CA" << "fr" << QString("qrc:/gcompris/data/fr/%1").arg(COMPRESSED_AUDIO); } void ApplicationInfoTest::getAudioFilePathForLocaleTest() { ApplicationInfo appInfo; ApplicationInfo::getInstance(); QFETCH(QString, file); QFETCH(QString, locale); QFETCH(QString, expected); QCOMPARE(appInfo.getAudioFilePathForLocale(file, locale), expected); } QTEST_MAIN(ApplicationInfoTest) #include "ApplicationInfoTest.moc" diff --git a/tests/core/DownloadManagerTest.cpp b/tests/core/DownloadManagerTest.cpp index d899243e2..4c4bf71c9 100644 --- a/tests/core/DownloadManagerTest.cpp +++ b/tests/core/DownloadManagerTest.cpp @@ -1,184 +1,184 @@ /* GCompris - DownloadManagerTest.cpp * * Copyright (C) 2018 Alex Kovrigin * GCompris (C) 2018 GCompris Developers * * Authors: * Alex Kovrigin * * This program 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. * * This program 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 this program; if not, see . */ #include #include #include #include "src/core/DownloadManager.h" #include "src/core/ApplicationInfo.h" #include "ApplicationSettingsMock.h" /** * @brief The DownloadManagerTest class Unit tests class for DownloadManager testing * @sa DownloadManager */ class DownloadManagerTest : public QObject { Q_OBJECT private slots: /** * @brief initTestCase Case for basic functionality of DownloadManager */ void initTestCase() { ApplicationSettingsMock::getInstance()->setIsAutomaticDownloadsEnabled(false); downloadManager = DownloadManager::getInstance(); } void test_getVoicesResourceForLocale_data() { QTest::addColumn("locale"); QTest::addColumn("language"); - QTest::newRow("en_US") << "en_US" << "en"; + QTest::newRow("en_US") << "en_US" << "en_US"; QTest::newRow("en_UK") << "en_UK" << "en"; QTest::newRow("ru_RU") << "ru_RU" << "ru"; QTest::newRow("de_DE") << "de_DE" << "de"; QTest::newRow("fr_FR") << "fr_FR" << "fr"; } void test_getVoicesResourceForLocale() { QFETCH(QString, locale); QFETCH(QString, language); QCOMPARE(downloadManager->getVoicesResourceForLocale(locale), QString("data2/voices-%1/voices-%2.rcc").arg(COMPRESSED_AUDIO, language)); } void test_haveLocalResource_data() { QTest::addColumn("resource"); QTest::addColumn("expected_success"); QTest::newRow("invalid.invalid") << "invalid.invalid" << false; QTest::newRow("no.no") << "no.no" << false; QTest::newRow("money.rcc") << "money.rcc" << true; QTest::newRow("penalty.rcc") << "penalty.rcc" << true; } void test_haveLocalResource() { QFETCH(QString, resource); QFETCH(bool, expected_success); QVERIFY(expected_success == downloadManager->haveLocalResource(resource)); } void test_downloadResource_data() { QTest::addColumn("resource"); QTest::newRow("invalid.blabla") << "invalid.blabla"; QTest::newRow("algorithm.rcc") << "algorithm.rcc"; } void test_downloadResource() { QFETCH(QString, resource); QVERIFY(downloadManager->downloadResource(resource)); QVERIFY(!downloadManager->downloadResource(resource)); downloadManager->abortDownloads(); } void test_updateResource_data() { QTest::addColumn("resource"); QTest::addColumn("expected_success"); QTest::newRow("invalid.haha") << "invalid.haha" << false; QTest::newRow("money.rcc") << "money.rcc" << true; } void test_updateResource() { QFETCH(QString, resource); QFETCH(bool, expected_success); QVERIFY(expected_success == downloadManager->updateResource(resource)); } void test_downloadIsRunning_data() { QTest::addColumn("resource"); QTest::newRow("colors.rcc") << "colors.rcc"; } void test_downloadIsRunning() { QFETCH(QString, resource); downloadManager->abortDownloads(); QVERIFY(!downloadManager->downloadIsRunning()); QVERIFY(downloadManager->downloadResource(resource)); QVERIFY(downloadManager->downloadIsRunning()); downloadManager->abortDownloads(); } void test_registerResource_data() { QTest::addColumn("resource"); QTest::addColumn("expected_success"); QTest::newRow("invalid.rcc") << "invalid.rcc" << false; QTest::newRow("money.rcc") << "money.rcc" << true; } void test_registerResource() { QFETCH(QString, resource); QFETCH(bool, expected_success); QVERIFY(expected_success == downloadManager->registerResource(resource)); } void test_isDataRegistered_data() { QTest::addColumn("resource"); QTest::addColumn("register_mode"); QTest::newRow("invalid.rcc") << "invalid.rcc" << "invalid"; QTest::newRow("mosaic.rcc") << "mosaic.rcc" << "not_registered"; } void test_isDataRegistered() { QFETCH(QString, resource); QFETCH(QString, register_mode); if(register_mode == "not_registered") { QVERIFY(!downloadManager->isDataRegistered(resource)); } else if(register_mode == "invalid") { QVERIFY(!downloadManager->registerResource(resource)); QVERIFY(!downloadManager->isDataRegistered(resource)); } else { QVERIFY(false); } } private: /** * @brief downloadManager The DownloadManager object, that is the test downloadManager */ DownloadManager *downloadManager; }; QTEST_MAIN(DownloadManagerTest); #include "DownloadManagerTest.moc"