mirror of
https://gitlab.linphone.org/BC/public/linphone-desktop.git
synced 2026-05-03 13:56:25 +00:00
feat(App): supports test, self-test is now a test and not a program option
This commit is contained in:
parent
c457fbadc5
commit
4524a4036e
11 changed files with 113 additions and 74 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -40,10 +40,6 @@
|
|||
</context>
|
||||
<context>
|
||||
<name>App</name>
|
||||
<message>
|
||||
<source>selfTestResult</source>
|
||||
<translation>Linphone seems to be running correctly.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionVerbose</source>
|
||||
<translation>log to stdout some debug information while running</translation>
|
||||
|
|
@ -52,10 +48,6 @@
|
|||
<source>commandLineOptionConfig</source>
|
||||
<translation>specify the linphone configuration file to be used</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionSelfTest</source>
|
||||
<translation>run self test and exit 0 if it succeeded</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>applicationDescription</source>
|
||||
<translation>A free (libre) SIP video-phone.</translation>
|
||||
|
|
|
|||
|
|
@ -40,10 +40,6 @@
|
|||
</context>
|
||||
<context>
|
||||
<name>App</name>
|
||||
<message>
|
||||
<source>selfTestResult</source>
|
||||
<translation>Linphone semble fonctionner normalement.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionVerbose</source>
|
||||
<translation>afficher sur stdout les informations de debug</translation>
|
||||
|
|
@ -52,10 +48,6 @@
|
|||
<source>commandLineOptionConfig</source>
|
||||
<translation>spécifier un fichier de configuration à utiliser</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>commandLineOptionSelfTest</source>
|
||||
<translation>éxécuter un test automatique et retourner 0 en cas de succès</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>applicationDescription</source>
|
||||
<translation>Un logiciel libre de voix sur IP SIP.</translation>
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,8 +71,6 @@ public:
|
|||
|
||||
bool hasFocus () const;
|
||||
|
||||
void quit () override;
|
||||
|
||||
static App *getInstance () {
|
||||
return static_cast<App *>(QApplication::instance());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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...");
|
||||
|
||||
|
|
|
|||
|
|
@ -20,22 +20,70 @@
|
|||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include <QTest>
|
||||
#include <QTimer>
|
||||
|
||||
#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[]) {
|
||||
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<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();
|
||||
|
||||
for (auto &test : tests)
|
||||
delete test;
|
||||
|
||||
int ret;
|
||||
do {
|
||||
app->initContentApp();
|
||||
ret = app->exec();
|
||||
} while (ret == APP_CODE_RESTART);
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,17 +20,18 @@
|
|||
* Author: Ronan Abhamon
|
||||
*/
|
||||
|
||||
#include <QSignalSpy>
|
||||
#include <QTest>
|
||||
|
||||
#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));
|
||||
}
|
||||
35
src/tests/self-test/SelfTest.hpp
Normal file
35
src/tests/self-test/SelfTest.hpp
Normal file
|
|
@ -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 <QObject>
|
||||
|
||||
// =============================================================================
|
||||
|
||||
class SelfTest : public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
SelfTest (QObject *parent = Q_NULLPTR) : QObject(parent) {}
|
||||
|
||||
private slots:
|
||||
void checkAppStartup ();
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue