diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -25,6 +25,7 @@ Directory.h DownloadManager.cpp DownloadManager.h + TestDownloadManager.cpp GComprisPlugin.cpp GComprisPlugin.h main.cpp @@ -263,6 +264,10 @@ set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/COPYING") set(CPACK_RESOURCE_FILE_README "${PROJECT_SOURCE_DIR}/README") +find_package(Qt5Test REQUIRED) +enable_testing(true) +add_test(gcompris-qt TestDownloadManager.cpp) + if(WIN32) set(CPACK_PACKAGE_INSTALL_DIRECTORY "${GCOMPRIS_EXECUTABLE_NAME}-Qt") set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${GCOMPRIS_EXECUTABLE_NAME}-Qt") diff --git a/src/core/TestDownloadManager.cpp b/src/core/TestDownloadManager.cpp new file mode 100644 --- /dev/null +++ b/src/core/TestDownloadManager.cpp @@ -0,0 +1,59 @@ +#include "DownloadManager.h" +#include +#include + +// FIXME Each of includes below result in errors. +// #include +// #include +// #include + +class TestDownloadManager : public QObject +{ + Q_OBJECT +public: + explicit TestDownloadManager(QObject *parent = nullptr); + static void Test(); + +private slots: + void initTestCase(); + + void test_getVoicesResourceForLocale(); +private: + DownloadManager * testSubject; +}; + + +TestDownloadManager::TestDownloadManager(QObject *parent) : QObject(parent) +{ } +/*! + * \brief TestDownloadManager::Test Small static function for testing without qt test. + */ +void TestDownloadManager::Test() +{ + TestDownloadManager * myTest = new TestDownloadManager(); + + myTest->initTestCase(); + myTest->test_getVoicesResourceForLocale(); +} +/*! + * \brief TestDownloadManager::initTestCase Test if downloadmanager works at all + */ +void TestDownloadManager::initTestCase() +{ + testSubject = DownloadManager::getInstance(); +} +/*! + * \brief TestDownloadManager::test_getVoicesResourceForLocale Test the corresponding function + */ +void TestDownloadManager::test_getVoicesResourceForLocale() +{ + // We will replace qDebug to QCOMPARE as shown below, currently it doesn't work, due to the lack of QTest + //QCOMPARE(testSubject->getVoicesResourceForLocale("en_US"), ...); + qDebug() << "***: " + testSubject->getVoicesResourceForLocale("ru_RU"); + qDebug() << "***: " + testSubject->getVoicesResourceForLocale("en_US"); + qDebug() << "***: " + testSubject->getVoicesResourceForLocale("en_UK"); +} +// FIXME Also results in errors. + +//QTEST_MAIN(TestDownloadManager); +//#include "TestDownloadManager.moc" diff --git a/src/core/main.cpp b/src/core/main.cpp --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -35,6 +35,11 @@ #include "ActivityInfoTree.h" #include "DownloadManager.h" +#include "TestDownloadManager.cpp" +//#include +//#include +//#include + bool loadAndroidTranslation(QTranslator &translator, const QString &locale) { QFile file("assets:/share/GCompris/gcompris_" + locale + ".qm"); @@ -253,6 +258,10 @@ #endif QQmlApplicationEngine engine(QUrl("qrc:/gcompris/src/core/main.qml")); + // Test the DownloadManager + // QTest::qExec(new TestDownloadManager, argc, argv); + TestDownloadManager::Test(); + QObject::connect(&engine, &QQmlApplicationEngine::quit, DownloadManager::getInstance(), &DownloadManager::shutdown); // add import path for shipped qml modules: