Commit 5d1ef1c2 authored by Ronan's avatar Ronan

chore(CMakeLists.txt): remove app tests and target

parent 87209311
......@@ -26,10 +26,7 @@ project(linphoneqt VERSION 4.1.1)
set(APP_LIBRARY app-library)
set(EXECUTABLE_NAME linphone)
set(TESTER_EXECUTABLE_NAME "${EXECUTABLE_NAME}-tester")
set(TARGET_NAME linphone-qt)
set(TESTER_TARGET_NAME "${TARGET_NAME}-tester")
set(CMAKE_CXX_STANDARD 11)
......@@ -226,19 +223,7 @@ set(HEADERS
src/utils/Utils.hpp
)
set(TESTS
src/tests/assistant-view/AssistantViewTest.cpp
src/tests/assistant-view/AssistantViewTest.hpp
src/tests/main-view/MainViewTest.cpp
src/tests/main-view/MainViewTest.hpp
src/tests/self-test/SelfTest.cpp
src/tests/self-test/SelfTest.hpp
src/tests/TestUtils.cpp
src/tests/TestUtils.hpp
)
set(MAIN_FILE src/app/main.cpp)
set(TESTER_MAIN_FILE src/tests/main.cpp)
if (UNIX AND NOT APPLE)
list(APPEND SOURCES src/components/core/messages-count-notifier/MessagesCountNotifierLinux.cpp)
......@@ -337,7 +322,6 @@ include_directories(src/)
find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED)
find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET)
find_package(Qt5 COMPONENTS Test REQUIRED)
if (CMAKE_INSTALL_RPATH)
get_target_property(LUPDATE_PATH Qt5::lupdate LOCATION)
......@@ -363,17 +347,14 @@ add_dependencies(${APP_LIBRARY} update_translations)
if (WIN32)
add_executable(${TARGET_NAME} WIN32 $<TARGET_OBJECTS:${APP_LIBRARY}> assets/linphone.rc ${MAIN_FILE})
add_executable(${TESTER_TARGET_NAME} WIN32 $<TARGET_OBJECTS:${APP_LIBRARY}> assets/linphone.rc ${TESTER_MAIN_FILE} ${TESTS})
else ()
add_executable(${TARGET_NAME} $<TARGET_OBJECTS:${APP_LIBRARY}> ${MAIN_FILE})
add_executable(${TESTER_TARGET_NAME} $<TARGET_OBJECTS:${APP_LIBRARY}> ${TESTER_MAIN_FILE} ${TESTS})
endif ()
if (NOT WIN32)
add_dependencies(update_translations check_qml)
endif ()
set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME "${EXECUTABLE_NAME}")
set_target_properties(${TESTER_TARGET_NAME} PROPERTIES OUTPUT_NAME "${TESTER_EXECUTABLE_NAME}")
set(INCLUDED_DIRECTORIES "${LINPHONECXX_INCLUDE_DIRS}" "${BELCARD_INCLUDE_DIRS}" "${BCTOOLBOX_INCLUDE_DIRS}" "${MEDIASTREAMER2_INCLUDE_DIRS}" "${MINIZIP_INCLUDE_DIRS}")
set(LIBRARIES ${BCTOOLBOX_CORE_LIBRARIES} ${BELCARD_LIBRARIES} ${LINPHONECXX_LIBRARIES} ${MINIZIP_LIBRARIES})
......@@ -406,12 +387,10 @@ endif ()
target_include_directories(${APP_LIBRARY} SYSTEM PRIVATE ${INCLUDED_DIRECTORIES})
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${INCLUDED_DIRECTORIES})
target_include_directories(${TESTER_TARGET_NAME} SYSTEM PRIVATE ${INCLUDED_DIRECTORIES})
target_link_libraries(${TARGET_NAME} ${LIBRARIES})
target_link_libraries(${TESTER_TARGET_NAME} ${LIBRARIES} Qt5::Test)
foreach (target ${TARGET_NAME} ${TESTER_TARGET_NAME})
foreach (target ${TARGET_NAME})
install(TARGETS ${target}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
......
/*
* TestUtils.cpp
* Copyright (C) 2017-2018 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 18, 2017
* Author: Ronan Abhamon
*/
#ifdef QT_NO_DEBUG
#undef QT_NO_DEBUG
#endif // ifdef QT_NO_DEBUG
#include <QTest>
#include <QtGlobal>
#include "../app/App.hpp"
#include "TestUtils.hpp"
// =============================================================================
void TestUtils::executeKeySequence (QQuickWindow *window, QKeySequence sequence) {
for (int i = 0; i < sequence.count(); ++i) {
uint key = uint(sequence[uint(i)]);
QTest::keyClick(
window,
Qt::Key(key & ~Qt::KeyboardModifierMask),
Qt::KeyboardModifiers(key & Qt::KeyboardModifierMask)
);
}
}
// -----------------------------------------------------------------------------
static void printItemTree (const QQuickItem *item, QString &output, int spaces) {
output.append(QString().leftJustified(spaces, ' '));
output.append(item->metaObject()->className());
output.append("\n");
for (const auto &childItem : item->childItems())
printItemTree(childItem, output, spaces + 2);
}
void TestUtils::printItemTree (const QQuickItem *item) {
QString output;
::printItemTree(item, output, 0);
qInfo().noquote() << output;
}
// -----------------------------------------------------------------------------
QQuickItem *TestUtils::getMainLoaderFromMainWindow () {
QList<QQuickItem *> items = App::getInstance()->getMainWindow()->contentItem()->childItems();
Q_ASSERT(!items.empty());
for (int i = 0; i < 3; ++i) {
items = items.at(0)->childItems();
Q_ASSERT(!items.empty());
}
QQuickItem *loader = items.at(0);
Q_ASSERT(!strcmp(loader->metaObject()->className(), "QQuickLoader"));
return loader;
}
// -----------------------------------------------------------------------------
QQuickItem *TestUtils::getVirtualWindowContent (const QQuickWindow *window) {
Q_CHECK_PTR(window);
QList<QQuickItem *> items = window->contentItem()->childItems();
Q_ASSERT(!items.empty());
items = items.at(0)->childItems();
Q_ASSERT(!items.empty());
items = items.at(0)->childItems();
Q_ASSERT(items.size() == 2);
const char name[] = "VirtualWindow_QMLTYPE_";
QQuickItem *virtualWindow = items.at(1);
Q_ASSERT(!strncmp(virtualWindow->metaObject()->className(), name, sizeof name - 1));
items = virtualWindow->childItems();
Q_ASSERT(items.size() == 2);
items = items.at(1)->childItems();
return items.empty() ? nullptr : items.at(0);
}
/*
* TestUtils.hpp
* Copyright (C) 2017-2018 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 18, 2017
* Author: Ronan Abhamon
*/
#ifndef TEST_UTILS_H_
#define TEST_UTILS_H_
#include <QQuickItem>
#include <QQuickWindow>
// =============================================================================
#define CHECK_VIRTUAL_WINDOW_CONTENT_INFO(WINDOW, TYPE, NAME) \
do { \
QQuickItem *virtualWindowContent = TestUtils::getVirtualWindowContent(WINDOW); \
QVERIFY(virtualWindowContent); \
QVERIFY(!strncmp(virtualWindowContent->metaObject()->className(), TYPE, sizeof TYPE - 1)); \
QCOMPARE(virtualWindowContent->objectName(), QStringLiteral(NAME)); \
} while (0);
#define INIT_GUI_TEST() \
do { \
QQuickWindow *mainWindow = App::getInstance()->getMainWindow(); \
App::smartShowWindow(mainWindow); \
QTest::qWait(100); \
QQuickItem *contentLoader = mainWindow->findChild<QQuickItem *>("__contentLoader"); \
QVERIFY(contentLoader); \
QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(110, 100)); \
} while (0);
namespace TestUtils {
void executeKeySequence (QQuickWindow *window, QKeySequence sequence);
void printItemTree (const QQuickItem *item);
QQuickItem *getMainLoaderFromMainWindow ();
QQuickItem *getVirtualWindowContent (const QQuickWindow *window);
}
#endif // ifndef TEST_UTILS_H_
/*
* AssistantViewTest.cpp
* Copyright (C) 2017-2018 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 20, 2017
* Author: Ronan Abhamon
*/
#include <QQmlProperty>
#include <QSignalSpy>
#include <QTest>
#include "../../app/App.hpp"
#include "../TestUtils.hpp"
#include "AssistantViewTest.hpp"
// =============================================================================
void AssistantViewTest::init () {
INIT_GUI_TEST();
}
void AssistantViewTest::showAssistantView () {
QQuickWindow *mainWindow = App::getInstance()->getMainWindow();
QQuickItem *contentLoader = mainWindow->findChild<QQuickItem *>("__contentLoader");
// Show assistant view.
QSignalSpy spyLoaderReady(contentLoader, SIGNAL(loaded()));
QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(705, 485));
QVERIFY(spyLoaderReady.count() == 1);
QCOMPARE(
QQmlProperty::read(contentLoader, "source").toString(),
QStringLiteral("qrc:/ui/views/App/Main/Assistant.qml")
);
}
/*
* AssistantViewTest.hpp
* Copyright (C) 2017-2018 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 20, 2017
* Author: Ronan Abhamon
*/
#ifndef ASSISTANT_VIEW_TEST_H_
#define ASSISTANT_VIEW_TEST_H_
#include <QObject>
// =============================================================================
class AssistantViewTest : public QObject {
Q_OBJECT;
public:
AssistantViewTest () = default;
~AssistantViewTest () = default;
private slots:
void init ();
void showAssistantView ();
};
#endif // ifndef ASSISTANT_VIEW_TEST_H_
/*
* MainViewTest.cpp
* Copyright (C) 2017-2018 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 18, 2017
* Author: Ronan Abhamon
*/
#include <QQmlProperty>
#include <QSignalSpy>
#include <QTest>
#include "../../app/App.hpp"
#include "../TestUtils.hpp"
#include "MainViewTest.hpp"
// =============================================================================
void MainViewTest::init () {
INIT_GUI_TEST();
}
// -----------------------------------------------------------------------------
void MainViewTest::showAboutPopup () {
QQuickWindow *mainWindow = App::getInstance()->getMainWindow();
// Open popup.
TestUtils::executeKeySequence(mainWindow, QKeySequence::HelpContents);
CHECK_VIRTUAL_WINDOW_CONTENT_INFO(mainWindow, "DialogPlus_QMLTYPE_", "__about");
// Close popup.
QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(476, 392));
QVERIFY(!TestUtils::getVirtualWindowContent(mainWindow));
}
// -----------------------------------------------------------------------------
void MainViewTest::showManageAccountsPopup () {
QQuickWindow *mainWindow = App::getInstance()->getMainWindow();
// Open popup.
QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(100, 35));
CHECK_VIRTUAL_WINDOW_CONTENT_INFO(mainWindow, "DialogPlus_QMLTYPE_", "__manageAccounts");
// Close popup.
QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(476, 392));
QVERIFY(!TestUtils::getVirtualWindowContent(mainWindow));
}
// -----------------------------------------------------------------------------
void MainViewTest::showSettingsWindow () {
App *app = App::getInstance();
// Open window.
QTest::keyClick(app->getMainWindow(), Qt::Key_P, Qt::ControlModifier);
QQuickWindow *settingsWindow = app->getSettingsWindow();
QVERIFY(QTest::qWaitForWindowExposed(settingsWindow));
// Hide window.
TestUtils::executeKeySequence(settingsWindow, QKeySequence::Close);
QVERIFY(!settingsWindow->isVisible());
}
// -----------------------------------------------------------------------------
void MainViewTest::testMainMenuEntries_data () {
QTest::addColumn<int>("y");
QTest::addColumn<QString>("source");
QTest::newRow("home view 1") << 100 << "qrc:/ui/views/App/Main/Home.qml";
QTest::newRow("contacts view 1") << 150 << "qrc:/ui/views/App/Main/Contacts.qml";
QTest::newRow("home view 2") << 100 << "qrc:/ui/views/App/Main/Home.qml";
QTest::newRow("contacts view 2") << 150 << "qrc:/ui/views/App/Main/Contacts.qml";
}
void MainViewTest::testMainMenuEntries () {
QQuickWindow *mainWindow = App::getInstance()->getMainWindow();
QQuickItem *contentLoader = mainWindow->findChild<QQuickItem *>("__contentLoader");
QVERIFY(contentLoader);
QSignalSpy spyLoaderReady(contentLoader, SIGNAL(loaded()));
QFETCH(int, y);
QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(110, y));
QVERIFY(spyLoaderReady.count() == 1);
QFETCH(QString, source);
QCOMPARE(QQmlProperty::read(contentLoader, "source").toString(), source);
}
/*
* MainViewTest.hpp
* Copyright (C) 2017-2018 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 18, 2017
* Author: Ronan Abhamon
*/
#ifndef MAIN_VIEW_TEST_H_
#define MAIN_VIEW_TEST_H_
#include <QObject>
// =============================================================================
class MainViewTest : public QObject {
Q_OBJECT;
public:
MainViewTest () = default;
~MainViewTest () = default;
private slots:
void init ();
void showAboutPopup ();
void showManageAccountsPopup ();
void showSettingsWindow ();
void testMainMenuEntries_data ();
void testMainMenuEntries ();
};
#endif // ifndef MAIN_VIEW_TEST_H_
/*
* main.cpp
* Copyright (C) 2017-2018 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 <QTest>
#include <QTimer>
#include "../app/AppController.hpp"
#include "../utils/Utils.hpp"
#include "assistant-view/AssistantViewTest.hpp"
#include "main-view/MainViewTest.hpp"
#include "self-test/SelfTest.hpp"
// =============================================================================
static QHash<QString, QObject *> initializeTests () {
QHash<QString, QObject *> hash;
hash["assistant-view"] = new AssistantViewTest();
hash["main-view"] = new MainViewTest();
return hash;
}
// -----------------------------------------------------------------------------
int main (int argc, char *argv[]) {
int fakeArgc = 1;
AppController controller(fakeArgc, argv);
App *app = controller.getApp();
if (app->isSecondary())
qFatal("Unable to run test with secondary app.");
int testsRet = 0;
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, &testsRet] {
testsRet = 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, &testsRet, test, argc, argv] {
testsRet = QTest::qExec(new SelfTest(app));
if (!testsRet)
QTest::qExec(test, argc - 1, argv + 1);
QCoreApplication::quit();
});
}
} else
// Execute all tests.
QTimer::singleShot(0, [app, &testsRet, &tests] {
testsRet = QTest::qExec(new SelfTest(app));
if (!testsRet)
for (const auto &test : tests) {
testsRet |= QTest::qExec(test);
}
QCoreApplication::quit();
});
app->initContentApp();
int ret = app->exec();
for (auto &test : tests)
delete test;
if (testsRet)
qWarning() << QStringLiteral("One or many tests are failed. :(");
else
qInfo() << QStringLiteral("Tests seems OK. :)");
return testsRet || ret;
}
/*
* SelfTest.cpp
* Copyright (C) 2017-2018 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 <QQmlProperty>
#include <QSignalSpy>
#include <QTest>
#include "../../app/App.hpp"
#include "../../components/core/CoreManager.hpp"
#include "../TestUtils.hpp"
#include "SelfTest.hpp"
// =============================================================================
void SelfTest::checkAppStartup () {
CoreManager *coreManager = CoreManager::getInstance();
QQuickItem *mainLoader = TestUtils::getMainLoaderFromMainWindow();
QSignalSpy spyCoreStarted(coreManager->getHandlers().get(), &CoreHandlers::coreStarted);
QSignalSpy spyLoaderReady(mainLoader, SIGNAL(loaded()));
if (!coreManager->started())
QVERIFY(spyCoreStarted.wait(5000));
if (!QQmlProperty::read(mainLoader, "item").value<QObject *>())
QVERIFY(spyLoaderReady.wait(1000));
QVERIFY(QTest::qWaitForWindowExposed(App::getInstance()->getMainWindow()));
}
/*
* SelfTest.hpp
* Copyright (C) 2017-2018 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
*/
#ifndef SELF_TEST_H_
#define SELF_TEST_H_
#include <QObject>
// =============================================================================
class SelfTest : public QObject {
Q_OBJECT;
public:
SelfTest (QObject *parent = Q_NULLPTR) : QObject(parent) {}
private slots:
void checkAppStartup ();
};
#endif // ifndef SELF_TEST_H_
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