Commit 4524a403 authored by Wescoeur's avatar Wescoeur

feat(App): supports test, `self-test` is now a test and not a program option

parent c457fbad
...@@ -213,7 +213,8 @@ set(HEADERS ...@@ -213,7 +213,8 @@ set(HEADERS
) )
set(TESTS 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) set(MAIN_FILE src/app/main.cpp)
......
...@@ -40,10 +40,6 @@ ...@@ -40,10 +40,6 @@
</context> </context>
<context> <context>
<name>App</name> <name>App</name>
<message>
<source>selfTestResult</source>
<translation>Linphone seems to be running correctly.</translation>
</message>
<message> <message>
<source>commandLineOptionVerbose</source> <source>commandLineOptionVerbose</source>
<translation>log to stdout some debug information while running</translation> <translation>log to stdout some debug information while running</translation>
...@@ -52,10 +48,6 @@ ...@@ -52,10 +48,6 @@
<source>commandLineOptionConfig</source> <source>commandLineOptionConfig</source>
<translation>specify the linphone configuration file to be used</translation> <translation>specify the linphone configuration file to be used</translation>
</message> </message>
<message>
<source>commandLineOptionSelfTest</source>
<translation>run self test and exit 0 if it succeeded</translation>
</message>
<message> <message>
<source>applicationDescription</source> <source>applicationDescription</source>
<translation>A free (libre) SIP video-phone.</translation> <translation>A free (libre) SIP video-phone.</translation>
......
...@@ -40,10 +40,6 @@ ...@@ -40,10 +40,6 @@
</context> </context>
<context> <context>
<name>App</name> <name>App</name>
<message>
<source>selfTestResult</source>
<translation>Linphone semble fonctionner normalement.</translation>
</message>
<message> <message>
<source>commandLineOptionVerbose</source> <source>commandLineOptionVerbose</source>
<translation>afficher sur stdout les informations de debug</translation> <translation>afficher sur stdout les informations de debug</translation>
...@@ -52,10 +48,6 @@ ...@@ -52,10 +48,6 @@
<source>commandLineOptionConfig</source> <source>commandLineOptionConfig</source>
<translation>spécifier un fichier de configuration à utiliser</translation> <translation>spécifier un fichier de configuration à utiliser</translation>
</message> </message>
<message>
<source>commandLineOptionSelfTest</source>
<translation>éxécuter un test automatique et retourner 0 en cas de succès</translation>
</message>
<message> <message>
<source>applicationDescription</source> <source>applicationDescription</source>
<translation>Un logiciel libre de voix sur IP SIP.</translation> <translation>Un logiciel libre de voix sur IP SIP.</translation>
......
...@@ -55,8 +55,6 @@ ...@@ -55,8 +55,6 @@
#define QML_VIEW_SPLASH_SCREEN "qrc:/ui/views/App/SplashScreen/SplashScreen.qml" #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. #define VERSION_UPDATE_CHECK_INTERVAL 86400000 // 24 hours in milliseconds.
using namespace std; using namespace std;
...@@ -202,19 +200,12 @@ void App::initContentApp () { ...@@ -202,19 +200,12 @@ void App::initContentApp () {
mNotifier = new Notifier(mEngine); mNotifier = new Notifier(mEngine);
// Load splashscreen. // Load splashscreen.
bool selfTest = mParser->isSet("self-test"); #ifdef Q_OS_MACOS
if (!selfTest) { ::activeSplashScreen(mEngine);
#ifdef Q_OS_MACOS #else
if (!mParser->isSet("iconified"))
::activeSplashScreen(mEngine); ::activeSplashScreen(mEngine);
#else #endif // ifdef Q_OS_MACOS
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. :(");
});
// Load main view. // Load main view.
qInfo() << QStringLiteral("Loading main view..."); qInfo() << QStringLiteral("Loading main view...");
...@@ -225,7 +216,7 @@ void App::initContentApp () { ...@@ -225,7 +216,7 @@ void App::initContentApp () {
QObject::connect( QObject::connect(
CoreManager::getInstance()->getHandlers().get(), CoreManager::getInstance()->getHandlers().get(),
&CoreHandlers::coreStarted, &CoreHandlers::coreStarted,
this, selfTest ? &App::quit : &App::openAppAfterInit this, &App::openAppAfterInit
); );
} }
...@@ -308,7 +299,6 @@ void App::createParser () { ...@@ -308,7 +299,6 @@ void App::createParser () {
#ifndef Q_OS_MACOS #ifndef Q_OS_MACOS
{ "iconified", tr("commandLineOptionIconified") }, { "iconified", tr("commandLineOptionIconified") },
#endif // ifndef Q_OS_MACOS #endif // ifndef Q_OS_MACOS
{ "self-test", tr("commandLineOptionSelfTest") },
{ { "V", "verbose" }, tr("commandLineOptionVerbose") } { { "V", "verbose" }, tr("commandLineOptionVerbose") }
// TODO: Enable me in future version! // TODO: Enable me in future version!
// , // ,
...@@ -569,12 +559,3 @@ void App::checkForUpdate () { ...@@ -569,12 +559,3 @@ void App::checkForUpdate () {
::Utils::appStringToCoreString(applicationVersion()) ::Utils::appStringToCoreString(applicationVersion())
); );
} }
// -----------------------------------------------------------------------------
void App::quit () {
if (mParser->isSet("self-test"))
cout << tr("selfTestResult").toStdString() << endl;
QApplication::quit();
}
...@@ -71,8 +71,6 @@ public: ...@@ -71,8 +71,6 @@ public:
bool hasFocus () const; bool hasFocus () const;
void quit () override;
static App *getInstance () { static App *getInstance () {
return static_cast<App *>(QApplication::instance()); return static_cast<App *>(QApplication::instance());
} }
......
...@@ -39,15 +39,9 @@ using namespace std; ...@@ -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[]) { AppController::AppController (int &argc, char *argv[]) {
Q_ASSERT(!mCreated);
mCreated = true;
QT_REQUIRE_VERSION(argc, argv, APPLICATION_MINIMAL_QT_VERSION); QT_REQUIRE_VERSION(argc, argv, APPLICATION_MINIMAL_QT_VERSION);
Q_ASSERT(!mApp);
// Disable QML cache. Avoid malformed cache. // Disable QML cache. Avoid malformed cache.
qputenv("QML_DISABLE_DISK_CACHE", "true"); qputenv("QML_DISABLE_DISK_CACHE", "true");
......
...@@ -30,13 +30,10 @@ public: ...@@ -30,13 +30,10 @@ public:
~AppController (); ~AppController ();
App *getApp () const { App *getApp () const {
Q_CHECK_PTR(mApp);
return mApp; return mApp;
} }
private: private:
App *mApp = nullptr; App *mApp = nullptr;
#ifndef QT_NO_DEBUG
static bool mCreated;
#endif // ifndef QT_NO_DEBUG
}; };
...@@ -28,7 +28,7 @@ int main (int argc, char *argv[]) { ...@@ -28,7 +28,7 @@ int main (int argc, char *argv[]) {
AppController controller(argc, argv); AppController controller(argc, argv);
App *app = controller.getApp(); App *app = controller.getApp();
if (app->isSecondary()) if (app->isSecondary())
return 0; return EXIT_SUCCESS;
qInfo() << QStringLiteral("Running app..."); qInfo() << QStringLiteral("Running app...");
......
...@@ -20,22 +20,70 @@ ...@@ -20,22 +20,70 @@
* Author: Ronan Abhamon * Author: Ronan Abhamon
*/ */
#include <QTest>
#include <QTimer>
#include "../app/AppController.hpp" #include "../app/AppController.hpp"
#include "../utils/Utils.hpp"
#include "self-test/SelfTest.hpp"
// ============================================================================= // =============================================================================
static QHash<QString, QObject *> initializeTests () {
QHash<QString, QObject *> hash;
// TODO: Add tests here.
return hash;
}
// -----------------------------------------------------------------------------
int main (int argc, char *argv[]) { int main (int argc, char *argv[]) {
AppController controller(argc, argv); int fakeArgc = 1;
AppController controller(fakeArgc, argv);
App *app = controller.getApp(); App *app = controller.getApp();
if (app->isSecondary()) if (app->isSecondary())
return 0; qFatal("Unable to run test with secondary app.");
const QHash<QString, QObject *> 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();
qInfo() << QStringLiteral("Running test..."); for (auto &test : tests)
delete test;
int ret;
do {
app->initContentApp();
ret = app->exec();
} while (ret == APP_CODE_RESTART);
return ret; return ret;
} }
/*
* SelfTest.cpp
* 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 <QSignalSpy>
#include <QTest>
#include "../../components/core/CoreManager.hpp"
#include "SelfTest.hpp"
#define SELF_TEST_DELAY 5000
// =============================================================================
void SelfTest::checkAppStartup () {
QSignalSpy spy(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted);
QVERIFY(spy.wait(SELF_TEST_DELAY));
}
/* /*
* SelfTest.cpp * SelfTest.hpp
* Copyright (C) 2017 Belledonne Communications, Grenoble, France * Copyright (C) 2017 Belledonne Communications, Grenoble, France
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
...@@ -20,17 +20,16 @@ ...@@ -20,17 +20,16 @@
* Author: Ronan Abhamon * Author: Ronan Abhamon
*/ */
#include <QTest> #include <QObject>
// ============================================================================= // =============================================================================
class SelfTest : public QObject { class SelfTest : public QObject {
Q_OBJECT; Q_OBJECT;
public:
SelfTest (QObject *parent = Q_NULLPTR) : QObject(parent) {}
private slots: private slots:
void t1 () { void checkAppStartup ();
QVERIFY(true);
}
}; };
#include "SelfTest.moc"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment