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,85 @@ +#include +#include +#include +#include + +#include "src/core/DownloadManager.h" + +class TestDownloadManager : public QObject +{ + Q_OBJECT +public: + explicit TestDownloadManager(QObject *parent = nullptr) : QObject(parent) + { } +private slots: + /*! + * \brief TestDownloadManager::test_getVoicesResourceForLocale Test the corresponding function + */ + void initTestCase() + { + subject = DownloadManager::getInstance(); + } + void test_downloadManagerProvider() + { + QObject * result = DownloadManager::downloadManagerProvider(new QQmlEngine(), new QJSEngine()); + QVERIFY(result->objectName().isEmpty()); + // TODO do a better test than this... + } + void test_getVoicesResourceForLocale() + { + QCOMPARE(subject->getVoicesResourceForLocale("en_US"), QString("data2/voices-ogg/voices-en.rcc")); + QCOMPARE(subject->getVoicesResourceForLocale("en_UK"), QString("data2/voices-ogg/voices-en.rcc")); + QCOMPARE(subject->getVoicesResourceForLocale("ru_RU"), QString("data2/voices-ogg/voices-ru.rcc")); + QCOMPARE(subject->getVoicesResourceForLocale("de_DE"), QString("data2/voices-ogg/voices-de.rcc")); + QCOMPARE(subject->getVoicesResourceForLocale("fr_FR"), QString("data2/voices-ogg/voices-fr.rcc")); + } + void test_haveLocalResource() + { + QVERIFY(!subject->haveLocalResource("invalid.invalid")); + QVERIFY(!subject->haveLocalResource("no.no")); + + QVERIFY(subject->haveLocalResource("money.rcc")); + QVERIFY(subject->haveLocalResource("penalty.rcc")); + } + void test_downloadResource() + { + // FIXME always results in true + QVERIFY(subject->downloadResource("algorithm.rcc")); + QVERIFY(!subject->downloadResource("invalid.blabla")); + } + void test_updateResource() + { + // FIXME always results in true + QVERIFY(subject->updateResource("money.rcc")); + QVERIFY(!subject->updateResource("invalid.haha")); + } + void test_downloadIsRunning() + { + subject->abortDownloads(); + QVERIFY(!subject->downloadIsRunning()); + QVERIFY(subject->downloadResource("colors.rcc")); + QVERIFY(subject->downloadIsRunning()); + subject->abortDownloads(); + } + void test_registerResource() + { + QVERIFY(subject->registerResource("money.rcc")); + QVERIFY(!subject->registerResource("invalid.rcc")); + } + void test_isDataRegistered() + { + // FIXME always results in false (probably, because nothing was registered yet) + QVERIFY(subject->isDataRegistered("words")); + QVERIFY(!subject->isDataRegistered("invalid")); + } + void test_areVoicesRegistered() + { + // FIXME always results in false + QVERIFY(subject->areVoicesRegistered()); + } +private: + DownloadManager * subject; +}; + +QTEST_MAIN(TestDownloadManager); +#include "DownloadManagerTest.moc"