diff --git a/CMakeLists.txt b/CMakeLists.txt index d49b1ddd2..d89e22a17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,6 +213,8 @@ set(HEADERS ) 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 diff --git a/src/tests/TestUtils.hpp b/src/tests/TestUtils.hpp index a6372a86a..75ba72d8f 100644 --- a/src/tests/TestUtils.hpp +++ b/src/tests/TestUtils.hpp @@ -20,6 +20,9 @@ * Author: Ronan Abhamon */ +#ifndef TEST_UTILS_H_ +#define TEST_UTILS_H_ + #include #include @@ -42,3 +45,5 @@ namespace TestUtils { QQuickItem *getVirtualWindowContent (const QQuickWindow *window); } + +#endif // ifndef TEST_UTILS_H_ diff --git a/src/tests/assistant-view/AssistantViewTest.cpp b/src/tests/assistant-view/AssistantViewTest.cpp new file mode 100644 index 000000000..f883814d4 --- /dev/null +++ b/src/tests/assistant-view/AssistantViewTest.cpp @@ -0,0 +1,50 @@ +/* + * AssistantViewTest.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 20, 2017 + * Author: Ronan Abhamon + */ + +#include +#include +#include +#include + +#include "../../app/App.hpp" + +#include "AssistantViewTest.hpp" + +// ============================================================================= + +void AssistantViewTest::showAssistantView () { + QQuickWindow *mainWindow = App::getInstance()->getMainWindow(); + + // Ensure home view is selected. + QQuickItem *contentLoader = mainWindow->findChild("__contentLoader"); + QVERIFY(contentLoader); + QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(110, 100)); + + // 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") + ); +} diff --git a/src/tests/assistant-view/AssistantViewTest.hpp b/src/tests/assistant-view/AssistantViewTest.hpp new file mode 100644 index 000000000..de660577c --- /dev/null +++ b/src/tests/assistant-view/AssistantViewTest.hpp @@ -0,0 +1,41 @@ +/* + * AssistantViewTest.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 20, 2017 + * Author: Ronan Abhamon + */ + +#ifndef ASSISTANT_VIEW_TEST_H_ +#define ASSISTANT_VIEW_TEST_H_ + +#include + +// ============================================================================= + +class AssistantViewTest : public QObject { + Q_OBJECT; + +public: + AssistantViewTest () = default; + ~AssistantViewTest () = default; + +private slots: + void showAssistantView (); +}; + +#endif // ifndef ASSISTANT_VIEW_TEST_H_ diff --git a/src/tests/main-view/MainViewTest.cpp b/src/tests/main-view/MainViewTest.cpp index 5c691dc76..e5520b790 100644 --- a/src/tests/main-view/MainViewTest.cpp +++ b/src/tests/main-view/MainViewTest.cpp @@ -88,13 +88,15 @@ void MainViewTest::testMainMenuEntries_data () { } void MainViewTest::testMainMenuEntries () { - QQuickItem *contentLoader = App::getInstance()->getMainWindow()->findChild("__contentLoader"); + QQuickWindow *mainWindow = App::getInstance()->getMainWindow(); + + QQuickItem *contentLoader = mainWindow->findChild("__contentLoader"); QVERIFY(contentLoader); QSignalSpy spyLoaderReady(contentLoader, SIGNAL(loaded())); QFETCH(int, y); - QTest::mouseClick(App::getInstance()->getMainWindow(), Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(110, y)); + QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(110, y)); QVERIFY(spyLoaderReady.count() == 1); QFETCH(QString, source); diff --git a/src/tests/main-view/MainViewTest.hpp b/src/tests/main-view/MainViewTest.hpp index cf00d9bec..82d37e0c6 100644 --- a/src/tests/main-view/MainViewTest.hpp +++ b/src/tests/main-view/MainViewTest.hpp @@ -20,6 +20,9 @@ * Author: Ronan Abhamon */ +#ifndef MAIN_VIEW_TEST_H_ +#define MAIN_VIEW_TEST_H_ + #include // ============================================================================= @@ -39,3 +42,5 @@ private slots: void testMainMenuEntries_data (); void testMainMenuEntries (); }; + +#endif // ifndef MAIN_VIEW_TEST_H_ diff --git a/src/tests/main.cpp b/src/tests/main.cpp index 1433f6de8..8aa02129e 100644 --- a/src/tests/main.cpp +++ b/src/tests/main.cpp @@ -26,6 +26,7 @@ #include "../app/AppController.hpp" #include "../utils/Utils.hpp" +#include "assistant-view/AssistantViewTest.hpp" #include "main-view/MainViewTest.hpp" #include "self-test/SelfTest.hpp" @@ -33,6 +34,7 @@ static QHash initializeTests () { QHash hash; + hash["assistant-view"] = new AssistantViewTest(); hash["main-view"] = new MainViewTest(); return hash; } diff --git a/src/tests/self-test/SelfTest.hpp b/src/tests/self-test/SelfTest.hpp index 978dc2b39..3eab7c6c6 100644 --- a/src/tests/self-test/SelfTest.hpp +++ b/src/tests/self-test/SelfTest.hpp @@ -20,6 +20,9 @@ * Author: Ronan Abhamon */ +#ifndef SELF_TEST_H_ +#define SELF_TEST_H_ + #include // ============================================================================= @@ -33,3 +36,5 @@ public: private slots: void checkAppStartup (); }; + +#endif // ifndef SELF_TEST_H_