diff --git a/src/core/DownloadManager.h b/src/core/DownloadManager.h --- a/src/core/DownloadManager.h +++ b/src/core/DownloadManager.h @@ -268,7 +268,7 @@ */ Q_INVOKABLE bool areVoicesRegistered() const; - /* + /** * Registers a rcc resource file given by a relative resource path * * @param filename Relative resource path. diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -13,6 +13,7 @@ DirectoryTest.cpp FileTest.cpp ApplicationInfoTest.cpp + DownloadManagerTest.cpp # add new test file here NAME_PREFIX Core LINK_LIBRARIES ${CORE_TEST_LIBRARIES}) diff --git a/tests/core/DownloadManagerTest.cpp b/tests/core/DownloadManagerTest.cpp new file mode 100644 --- /dev/null +++ b/tests/core/DownloadManagerTest.cpp @@ -0,0 +1,195 @@ +/* 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 + +#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 +public: + explicit DownloadManagerTest(QObject *parent = nullptr) : QObject(parent) + { } +private slots: + /** + * @brief initTestCase Case for basic functonality of DownloadManager + */ + void initTestCase() + { + ApplicationSettingsMock::getInstance()->setIsAutomaticDownloadsEnabled(false); + subject = DownloadManager::getInstance(); + } + + void test_getVoicesResourceForLocale_data() + { + QTest::addColumn("locale"); + QTest::addColumn("language"); + + QTest::newRow("en_US") << "en_US" << "en"; + 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( subject->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 == subject->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(subject->downloadResource(resource)); + QVERIFY(!subject->downloadResource(resource)); + } + + 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 == subject->updateResource(resource)); + } + + void test_downloadIsRunning_data() + { + QTest::addColumn("resource"); + + QTest::newRow("colors.rcc") << "colors.rcc"; + } + void test_downloadIsRunning() + { + QFETCH(QString, resource); + + subject->abortDownloads(); + QVERIFY(!subject->downloadIsRunning()); + QVERIFY(subject->downloadResource(resource)); + QVERIFY(subject->downloadIsRunning()); + subject->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 == subject->registerResource(resource)); + } + + void test_isDataRegistered_data() + { + QTest::addColumn("resource"); + QTest::addColumn("register_mode"); + + QTest::newRow("invalid.rcc") << "invalid.rcc" << "invalid"; + QTest::newRow("money.rcc") << "money.rcc" << "register"; + QTest::newRow("mosaic.rcc") << "mosaic.rcc" << "no_register"; + QTest::newRow("money.rcc") << "money.rcc" << "register"; + } + void test_isDataRegistered() + { + QFETCH(QString, resource); + QFETCH(QString, register_mode); + + if(register_mode == "register") { + QVERIFY(QResource::registerResource( + QString("./%1/rcc/%2").arg(GCOMPRIS_DATA_FOLDER, resource), + QString(":/gcompris/data/%1").arg(resource))); + + QVERIFY(subject->isDataRegistered(resource)); + } + else if(register_mode == "no_register") { + QVERIFY(!subject->isDataRegistered(resource)); + } + else if(register_mode == "invalid") { + QVERIFY(!subject->registerResource(resource)); + QVERIFY(!subject->isDataRegistered(resource)); + } + else { + qDebug() << "Incorrect register_mode!"; + QVERIFY(false); + } + } +private: + /** + * @brief subject The DownloadManager object, that is the test subject + */ + DownloadManager * subject; +}; + +QTEST_MAIN(DownloadManagerTest); +#include "DownloadManagerTest.moc"