diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f37878ce..1b7ec363c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,8 @@ set(HEADERS ) set(TESTS - src/tests/SelfTest.cpp + src/tests/self-test/SelfTest.cpp + src/tests/self-test/SelfTest.hpp ) set(MAIN_FILE src/app/main.cpp) diff --git a/assets/languages/en.ts b/assets/languages/en.ts index 6b7d385cc..281b50462 100644 --- a/assets/languages/en.ts +++ b/assets/languages/en.ts @@ -40,10 +40,6 @@ App - - selfTestResult - Linphone seems to be running correctly. - commandLineOptionVerbose log to stdout some debug information while running @@ -52,10 +48,6 @@ commandLineOptionConfig specify the linphone configuration file to be used - - commandLineOptionSelfTest - run self test and exit 0 if it succeeded - applicationDescription A free (libre) SIP video-phone. diff --git a/assets/languages/fr.ts b/assets/languages/fr.ts index 350620590..0c9f5defa 100644 --- a/assets/languages/fr.ts +++ b/assets/languages/fr.ts @@ -40,10 +40,6 @@ App - - selfTestResult - Linphone semble fonctionner normalement. - commandLineOptionVerbose afficher sur stdout les informations de debug @@ -52,10 +48,6 @@ commandLineOptionConfig spécifier un fichier de configuration à utiliser - - commandLineOptionSelfTest - éxécuter un test automatique et retourner 0 en cas de succès - applicationDescription Un logiciel libre de voix sur IP SIP. diff --git a/src/app/App.cpp b/src/app/App.cpp index f6b684171..9a6f4df3c 100644 --- a/src/app/App.cpp +++ b/src/app/App.cpp @@ -55,8 +55,6 @@ #define QML_VIEW_SPLASH_SCREEN "qrc:/ui/views/App/SplashScreen/SplashScreen.qml" -#define SELF_TEST_DELAY 300000 - #define VERSION_UPDATE_CHECK_INTERVAL 86400000 // 24 hours in milliseconds. using namespace std; @@ -202,19 +200,12 @@ void App::initContentApp () { mNotifier = new Notifier(mEngine); // Load splashscreen. - bool selfTest = mParser->isSet("self-test"); - if (!selfTest) { - #ifdef Q_OS_MACOS + #ifdef Q_OS_MACOS + ::activeSplashScreen(mEngine); + #else + if (!mParser->isSet("iconified")) ::activeSplashScreen(mEngine); - #else - if (!mParser->isSet("iconified")) - ::activeSplashScreen(mEngine); - #endif // ifdef Q_OS_MACOS - } else - // Set a self test limit. - QTimer::singleShot(SELF_TEST_DELAY, this, [] { - qFatal("Self test failed. :("); - }); + #endif // ifdef Q_OS_MACOS // Load main view. qInfo() << QStringLiteral("Loading main view..."); @@ -225,7 +216,7 @@ void App::initContentApp () { QObject::connect( CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted, - this, selfTest ? &App::quit : &App::openAppAfterInit + this, &App::openAppAfterInit ); } @@ -308,7 +299,6 @@ void App::createParser () { #ifndef Q_OS_MACOS { "iconified", tr("commandLineOptionIconified") }, #endif // ifndef Q_OS_MACOS - { "self-test", tr("commandLineOptionSelfTest") }, { { "V", "verbose" }, tr("commandLineOptionVerbose") } // TODO: Enable me in future version! // , @@ -569,12 +559,3 @@ void App::checkForUpdate () { ::Utils::appStringToCoreString(applicationVersion()) ); } - -// ----------------------------------------------------------------------------- - -void App::quit () { - if (mParser->isSet("self-test")) - cout << tr("selfTestResult").toStdString() << endl; - - QApplication::quit(); -} diff --git a/src/app/App.hpp b/src/app/App.hpp index 8bfa69522..06d825e40 100644 --- a/src/app/App.hpp +++ b/src/app/App.hpp @@ -71,8 +71,6 @@ public: bool hasFocus () const; - void quit () override; - static App *getInstance () { return static_cast(QApplication::instance()); } diff --git a/src/app/AppController.cpp b/src/app/AppController.cpp index f0f607c55..7453b3e6f 100644 --- a/src/app/AppController.cpp +++ b/src/app/AppController.cpp @@ -39,15 +39,9 @@ using namespace std; // ============================================================================= -#ifndef QT_NO_DEBUG - bool AppController::mCreated = false; -#endif // ifndef QT_NO_DEBUG - AppController::AppController (int &argc, char *argv[]) { - Q_ASSERT(!mCreated); - mCreated = true; - QT_REQUIRE_VERSION(argc, argv, APPLICATION_MINIMAL_QT_VERSION); + Q_ASSERT(!mApp); // Disable QML cache. Avoid malformed cache. qputenv("QML_DISABLE_DISK_CACHE", "true"); diff --git a/src/app/AppController.hpp b/src/app/AppController.hpp index 4711e0c5a..2fe9729c2 100644 --- a/src/app/AppController.hpp +++ b/src/app/AppController.hpp @@ -30,13 +30,10 @@ public: ~AppController (); App *getApp () const { + Q_CHECK_PTR(mApp); return mApp; } private: App *mApp = nullptr; - - #ifndef QT_NO_DEBUG - static bool mCreated; - #endif // ifndef QT_NO_DEBUG }; diff --git a/src/app/main.cpp b/src/app/main.cpp index f3394c8fa..9d483face 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -28,7 +28,7 @@ int main (int argc, char *argv[]) { AppController controller(argc, argv); App *app = controller.getApp(); if (app->isSecondary()) - return 0; + return EXIT_SUCCESS; qInfo() << QStringLiteral("Running app..."); diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 3c0050fd1..a39fa6ca8 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -20,22 +20,70 @@ * Author: Ronan Abhamon */ +#include +#include + #include "../app/AppController.hpp" +#include "../utils/Utils.hpp" + +#include "self-test/SelfTest.hpp" // ============================================================================= +static QHash initializeTests () { + QHash hash; + // TODO: Add tests here. + return hash; +} + +// ----------------------------------------------------------------------------- + int main (int argc, char *argv[]) { - AppController controller(argc, argv); + int fakeArgc = 1; + AppController controller(fakeArgc, argv); App *app = controller.getApp(); if (app->isSecondary()) - return 0; + qFatal("Unable to run test with secondary app."); - qInfo() << QStringLiteral("Running test..."); + const QHash tests = initializeTests(); + + QObject *test = nullptr; + if (argc > 1) { + if (!strcmp(argv[1], "self-test")) + // Execute only self-test. + QTimer::singleShot(0, [app] { + QTest::qExec(new SelfTest(app)); + QCoreApplication::quit(); + }); + else { + // Execute only one test. + const QString testName = ::Utils::coreStringToAppString(argv[1]); + test = tests[testName]; + if (!test) { + qWarning() << QStringLiteral("Unable to run invalid test: `%1`.").arg(testName); + return EXIT_FAILURE; + } + + QTimer::singleShot(0, [app, test, argc, argv] { + QTest::qExec(new SelfTest(app)); + QTest::qExec(test, argc - 1, argv + 1); + QCoreApplication::quit(); + }); + } + } else + // Execute all tests. + QTimer::singleShot(0, [app, &tests] { + QTest::qExec(new SelfTest(app)); + for (const auto &test : tests) + QTest::qExec(test); + QCoreApplication::quit(); + }); + + app->initContentApp(); + int ret = app->exec(); + + for (auto &test : tests) + delete test; - int ret; - do { - app->initContentApp(); - ret = app->exec(); - } while (ret == APP_CODE_RESTART); return ret; } diff --git a/src/tests/SelfTest.cpp b/src/tests/self-test/SelfTest.cpp similarity index 76% rename from src/tests/SelfTest.cpp rename to src/tests/self-test/SelfTest.cpp index 0daf4bcd4..65acfef8d 100644 --- a/src/tests/SelfTest.cpp +++ b/src/tests/self-test/SelfTest.cpp @@ -20,17 +20,18 @@ * Author: Ronan Abhamon */ +#include #include +#include "../../components/core/CoreManager.hpp" + +#include "SelfTest.hpp" + +#define SELF_TEST_DELAY 5000 + // ============================================================================= -class SelfTest : public QObject { - Q_OBJECT; - -private slots: - void t1 () { - QVERIFY(true); - } -}; - -#include "SelfTest.moc" +void SelfTest::checkAppStartup () { + QSignalSpy spy(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted); + QVERIFY(spy.wait(SELF_TEST_DELAY)); +} diff --git a/src/tests/self-test/SelfTest.hpp b/src/tests/self-test/SelfTest.hpp new file mode 100644 index 000000000..978dc2b39 --- /dev/null +++ b/src/tests/self-test/SelfTest.hpp @@ -0,0 +1,35 @@ +/* + * SelfTest.hpp + * Copyright (C) 2017 Belledonne Communications, Grenoble, France + * + * 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 2 + * 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * Created on: July 17, 2017 + * Author: Ronan Abhamon + */ + +#include + +// ============================================================================= + +class SelfTest : public QObject { + Q_OBJECT; + +public: + SelfTest (QObject *parent = Q_NULLPTR) : QObject(parent) {} + +private slots: + void checkAppStartup (); +};