diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b7ec363c..d49b1ddd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,8 +213,12 @@ set(HEADERS ) set(TESTS + 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) diff --git a/src/components/notifier/Notifier.cpp b/src/components/notifier/Notifier.cpp index d06657bd4..cffdae7cc 100644 --- a/src/components/notifier/Notifier.cpp +++ b/src/components/notifier/Notifier.cpp @@ -43,7 +43,7 @@ #define NOTIFICATION_PROPERTY_X "popupX" #define NOTIFICATION_PROPERTY_Y "popupY" -#define NOTIFICATION_PROPERTY_WINDOW "__internalWindow" +#define NOTIFICATION_PROPERTY_WINDOW "internalWindow" #define NOTIFICATION_PROPERTY_TIMER "__timer" diff --git a/src/tests/TestUtils.cpp b/src/tests/TestUtils.cpp new file mode 100644 index 000000000..4fe2be7c6 --- /dev/null +++ b/src/tests/TestUtils.cpp @@ -0,0 +1,103 @@ +/* + * TestUtils.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 18, 2017 + * Author: Ronan Abhamon + */ + +#ifdef QT_NO_DEBUG + #undef QT_NO_DEBUG +#endif // ifdef QT_NO_DEBUG + +#include + +#include "../app/App.hpp" + +#include "TestUtils.hpp" + +// ============================================================================= + +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 () { + QQuickWindow *window = App::getInstance()->getMainWindow(); + Q_CHECK_PTR(window); + + QList items = window->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::getVirtualWindow (const QQuickWindow *window) { + Q_CHECK_PTR(window); + + QList 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)); + + return virtualWindow; +} + +// ----------------------------------------------------------------------------- + +QQuickItem *TestUtils::getVirtualWindowContainer (const QQuickItem *virtualWindow) { + Q_CHECK_PTR(virtualWindow); + + QList items = virtualWindow->childItems(); + Q_ASSERT(items.size() == 2); + + QQuickItem *container = items.at(1); + Q_ASSERT(!container->childItems().empty()); + + return container; +} diff --git a/src/tests/TestUtils.hpp b/src/tests/TestUtils.hpp new file mode 100644 index 000000000..3a3d6eb0c --- /dev/null +++ b/src/tests/TestUtils.hpp @@ -0,0 +1,34 @@ +/* + * TestUtils.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 18, 2017 + * Author: Ronan Abhamon + */ + +#include +#include + +// ============================================================================= + +namespace TestUtils { + void printItemTree (const QQuickItem *item); + + QQuickItem *getMainLoaderFromMainWindow (); + QQuickItem *getVirtualWindow (const QQuickWindow *window); + QQuickItem *getVirtualWindowContainer (const QQuickItem *virtualWindow); +} diff --git a/src/tests/main-view/MainViewTest.cpp b/src/tests/main-view/MainViewTest.cpp new file mode 100644 index 000000000..2ecd50e5b --- /dev/null +++ b/src/tests/main-view/MainViewTest.cpp @@ -0,0 +1,45 @@ +/* + * MainViewTest.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 18, 2017 + * Author: Ronan Abhamon + */ + +#include + +#include "../../app/App.hpp" +#include "../TestUtils.hpp" + +#include "MainViewTest.hpp" + +// ============================================================================= + +void MainViewTest::showManageAccountsPopup () { + QQuickWindow *mainWindow = App::getInstance()->getMainWindow(); + + QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(100, 35)); + QTest::qWait(1000); + + const char name[] = "DialogPlus_QMLTYPE_"; + QQuickItem *virtualWindowContent = TestUtils::getVirtualWindowContainer( + TestUtils::getVirtualWindow(mainWindow) + )->childItems().at(0); + + QVERIFY(!strncmp(virtualWindowContent->metaObject()->className(), name, sizeof name - 1)); + QVERIFY(virtualWindowContent->objectName() == "manageAccounts"); +} diff --git a/src/tests/main-view/MainViewTest.hpp b/src/tests/main-view/MainViewTest.hpp new file mode 100644 index 000000000..6d08745ec --- /dev/null +++ b/src/tests/main-view/MainViewTest.hpp @@ -0,0 +1,35 @@ +/* + * MainViewTest.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 18, 2017 + * Author: Ronan Abhamon + */ + +#include + +// ============================================================================= + +class MainViewTest : public QObject { + Q_OBJECT; + +public: + MainViewTest () = default; + +private slots: + void showManageAccountsPopup (); +}; diff --git a/src/tests/main.cpp b/src/tests/main.cpp index a39fa6ca8..3b6984afb 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -26,13 +26,14 @@ #include "../app/AppController.hpp" #include "../utils/Utils.hpp" +#include "main-view/MainViewTest.hpp" #include "self-test/SelfTest.hpp" // ============================================================================= static QHash initializeTests () { QHash hash; - // TODO: Add tests here. + hash["main-view"] = new MainViewTest(); return hash; } diff --git a/src/tests/self-test/SelfTest.cpp b/src/tests/self-test/SelfTest.cpp index 65acfef8d..f8e23b8c2 100644 --- a/src/tests/self-test/SelfTest.cpp +++ b/src/tests/self-test/SelfTest.cpp @@ -24,14 +24,20 @@ #include #include "../../components/core/CoreManager.hpp" +#include "../TestUtils.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)); + QSignalSpy spyCoreStarted(CoreManager::getInstance()->getHandlers().get(), &CoreHandlers::coreStarted); + QSignalSpy spyLoaderReady(TestUtils::getMainLoaderFromMainWindow(), SIGNAL(loaded())); + + QVERIFY(spyCoreStarted.wait(5000)); + + if (spyLoaderReady.count() == 1) + return; + + QVERIFY(spyLoaderReady.wait(1000)); } diff --git a/ui/modules/Common/Popup/DesktopPopup.qml b/ui/modules/Common/Popup/DesktopPopup.qml index d641d0002..7f7374fce 100644 --- a/ui/modules/Common/Popup/DesktopPopup.qml +++ b/ui/modules/Common/Popup/DesktopPopup.qml @@ -48,7 +48,7 @@ Item { id: window // Used for internal purposes only. Like Notifications. - objectName: '__internalWindow' + objectName: 'internalWindow' flags: wrapper.flags opacity: 0 diff --git a/ui/modules/Linphone/Notifications/Notification.spec.qml b/ui/modules/Linphone/Notifications/Notification.spec.qml index 4a74fa077..ffbd5b540 100644 --- a/ui/modules/Linphone/Notifications/Notification.spec.qml +++ b/ui/modules/Linphone/Notifications/Notification.spec.qml @@ -39,6 +39,6 @@ TestCase { var window = notification.data[0] compare(Utils.qmlTypeof(window, 'QQuickWindowQmlImpl'), true) - compare(window.objectName === '__internalWindow', true) + compare(window.objectName === 'internalWindow', true) } } diff --git a/ui/views/App/Main/Dialogs/ManageAccounts.qml b/ui/views/App/Main/Dialogs/ManageAccounts.qml index 98f6319fe..83e2ddcaa 100644 --- a/ui/views/App/Main/Dialogs/ManageAccounts.qml +++ b/ui/views/App/Main/Dialogs/ManageAccounts.qml @@ -18,6 +18,7 @@ DialogPlus { ] centeredButtons: true + objectName: 'manageAccounts' height: ManageAccountsStyle.height width: ManageAccountsStyle.width