aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAntti Hölttä <AHoelttae@luxoft.com>2019-02-27 15:37:07 +0100
committerAntti Hölttä <AHoelttae@luxoft.com>2019-03-18 16:42:32 +0100
commit61e8f03d59cfd748b2a1f83dd51bbb90acd8c7cc (patch)
treee2bba83ae9e9b9bdac10c282db3106d93717ab4f /tests
parent8489f36322c585ec78199e6eb183000c74afae19 (diff)
Start tests, basic case pretty complete
Diffstat (limited to 'tests')
-rw-r--r--tests/basics.qml64
-rw-r--r--tests/tests.pro8
-rw-r--r--tests/tst_cursornavigation.cpp130
3 files changed, 178 insertions, 24 deletions
diff --git a/tests/basics.qml b/tests/basics.qml
new file mode 100644
index 0000000..a089174
--- /dev/null
+++ b/tests/basics.qml
@@ -0,0 +1,64 @@
+import QtQuick 2.12
+import CursorNavigation 1.0
+
+Rectangle {
+ id: root
+
+ width: 150
+ height: 100
+
+ Row {
+
+ Rectangle {
+ objectName: "cnItem0"
+
+ width: 50
+ height: 50
+
+ //only set the object name to create a default constructed attachment
+ CursorNavigation.objectName: "cnItem0Attached"
+
+ }
+
+ Rectangle {
+ objectName: "cnItem1"
+
+ width: 50
+ height: 50
+
+ CursorNavigation.objectName: "cnItem1Attached"
+ CursorNavigation.acceptsCursor: true
+
+ Rectangle {
+ width: 20
+ height: 20
+ objectName: "cnItem1Child"
+ }
+
+ }
+
+ Rectangle {
+ objectName: "cnItem2"
+
+ width: 50
+ height: 50
+
+ CursorNavigation.objectName: "cnItem2Attached"
+ CursorNavigation.acceptsCursor: true
+
+ Rectangle {
+ width: 20
+ height: 20
+
+ Rectangle {
+ width: 10
+ height: 10
+ objectName: "cnItem2IndirectChild"
+ }
+ }
+
+ }
+
+ }
+
+}
diff --git a/tests/tests.pro b/tests/tests.pro
index 2e9bc7e..e4f9b88 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -1,5 +1,5 @@
-QT += testlib
-QT -= gui
+QT += testlib quick
+#QT -= gui
CONFIG += qt console warn_on depend_includepath testcase
CONFIG -= app_bundle
@@ -8,3 +8,7 @@ TEMPLATE = app
SOURCES += \
tst_cursornavigation.cpp
+INCLUDEPATH += ../plugin
+
+DISTFILES += \
+ basics.qml
diff --git a/tests/tst_cursornavigation.cpp b/tests/tst_cursornavigation.cpp
index 0001f77..c0a6f97 100644
--- a/tests/tst_cursornavigation.cpp
+++ b/tests/tst_cursornavigation.cpp
@@ -1,6 +1,12 @@
#include <QtTest>
-// add necessary includes here
+#include "cursornavigationattached.h"
+#include <QSignalSpy>
+#include <QtQml/qqmlengine.h>
+#include <QtQml/qqmlcomponent.h>
+#include <QtQuick/qquickview.h>
+#include <QtQuick/QQuickItem>
+#include <QQmlProperty>
class TestCursorNavigation : public QObject
{
@@ -11,12 +17,12 @@ public:
~TestCursorNavigation();
private slots:
- void test_pluginLoading();
- void test_registering();
- void test_followsFocus();
- void test_withKeyNavigation();
+ void test_basics();
+ void test_callbacks();
void test_spatial4Directions();
-
+ void test_spatial360();
+ void testRedirects();
+ void testTargetDeletions();
};
TestCursorNavigation::TestCursorNavigation()
@@ -29,37 +35,117 @@ TestCursorNavigation::~TestCursorNavigation()
}
-void TestCursorNavigation::test_pluginLoading()
+
+
+void TestCursorNavigation::test_basics()
{
//test that the plugin loads and is available for use and a element with an attached property can be set
+ QQuickView *view = new QQuickView;
+ view->setSource(QUrl::fromLocalFile(QFINDTESTDATA("basics.qml")));
+ QVERIFY(view->status() == QQuickView::Ready);
+
+ view->show();
+ view->requestActivate();
+
+ QVERIFY(QTest::qWaitForWindowActive(view));
+ QTRY_COMPARE(view, qGuiApp->focusWindow());
+
+ QQuickItem *root = view->rootObject();
+ QQuickItem *item0 = root->findChild<QQuickItem*>(QLatin1String("cnItem0"));
+ QQuickItem *item1 = root->findChild<QQuickItem*>(QLatin1String("cnItem1"));
+ QQuickItem *item2 = root->findChild<QQuickItem*>(QLatin1String("cnItem2"));
+ QQuickItem *item1Child = root->findChild<QQuickItem*>(QLatin1String("cnItem1Child"));
+ QQuickItem *item2IndirectChild = root->findChild<QQuickItem*>(QLatin1String("cnItem2IndirectChild"));
+ QObject *item0Attached = item0->findChild<QObject*>(QLatin1String("cnItem0Attached"));
+ QVERIFY(item0 != nullptr);
+ QVERIFY(item1 != nullptr);
+ QVERIFY(item0Attached != nullptr);
+
+ //check initial property values
+ QQmlProperty acceptsCursor0(item0, "CursorNavigation.acceptsCursor", qmlContext(item0));
+ QQmlProperty hasCursor0(item0, "CursorNavigation.hasCursor", qmlContext(item0));
+ QQmlProperty trapsCursor0(item0, "CursorNavigation.trapsCursor", qmlContext(item0));
+ QQmlProperty escapeTarget0(item0, "CursorNavigation.escapeTarget", qmlContext(item0));
+ QQmlProperty redirects0(item0, "CursorNavigation.redirects", qmlContext(item0));
+ QVERIFY(acceptsCursor0.isValid());
+ QVERIFY(hasCursor0.isValid());
+ QVERIFY(trapsCursor0.isValid());
+ QVERIFY(escapeTarget0.isValid());
+ QVERIFY(redirects0.isValid());
+
+ QVERIFY(!acceptsCursor0.read().toBool());
+ QVERIFY(!hasCursor0.read().toBool());
+ QVERIFY(!hasCursor0.read().toBool());
+ QVERIFY(escapeTarget0.read().value<QQuickItem*>() == nullptr);
+ //TODO check that redirects is empty
+
+ QSignalSpy acceptsCursorSpy0(item0Attached, SIGNAL(acceptsCursorChanged(bool)));
+ QSignalSpy hasCursorSpy0(item0Attached, SIGNAL(hasCursorChanged(bool)));
+
+ acceptsCursor0.write(true);
+
+ QVERIFY(acceptsCursorSpy0.count()==1);
+ QVERIFY(acceptsCursor0.read().toBool());
+
+ QVERIFY(view->isTopLevel());
+
+ //check that cursor follows the active focus
+ item0->forceActiveFocus();
+ QVERIFY(item0->hasActiveFocus());
+ QVERIFY(hasCursor0.read().toBool());
+ QVERIFY(hasCursorSpy0.count()==1);
+
+
+ //check, that when a non-navigable item receives the active focus, the cursor is set on its closest navigable parent
+ QQmlProperty hasCursor1(item1, "CursorNavigation.hasCursor", qmlContext(item1));
+ QVERIFY(!item1->hasActiveFocus());
+ QVERIFY(!hasCursor1.read().toBool());
+
+ item1Child->forceActiveFocus();
+ //TODO this will not be true. should it be?
+ //QVERIFY(item1Child->hasActiveFocus());
+ QVERIFY(hasCursor1.read().toBool());
+
+ QVERIFY(!hasCursor0.read().toBool());
+ QVERIFY(hasCursorSpy0.count()==2);
+
+ //...and the same with an indirect child
+ QQmlProperty hasCursor2(item2, "CursorNavigation.hasCursor", qmlContext(item2));
+ QVERIFY(!item2->hasActiveFocus());
+ QVERIFY(!hasCursor2.read().toBool());
+
+ item2IndirectChild->forceActiveFocus();
+ //TODO this will not be true. should it be?
+ //QVERIFY(item2IndirectChild->hasActiveFocus());
+ QVERIFY(hasCursor2.read().toBool());
+
}
-void TestCursorNavigation::test_registering()
+void TestCursorNavigation::test_callbacks()
{
- //see that elements marked for accepting cursor are added to the engines element register
- //adding the property should add item to the register
- //deleting the item should unregister the item
- //unsetting the property should unregister the item
+
}
-void TestCursorNavigation::test_followsFocus()
+void TestCursorNavigation::test_spatial4Directions()
{
- //test that the cursor follows focus; means cursor is moved between the
- //items when the focus is changed some other way
+ //test the spatial algorithm in the basic 4 directional case
}
-void TestCursorNavigation::test_withKeyNavigation()
+void TestCursorNavigation::test_spatial360()
{
- //test that element that additionally uses KeyNavigation, behaves primarily according to the KeyNavigation
- //ie Cursor navigation plugin should not override KeyNavigation
- //arrows + tab/backtab
+
}
-void TestCursorNavigation::test_spatial4Directions()
+void TestCursorNavigation::testRedirects()
{
- //test the spatial algorithm in the basic 4 directional case
+
+}
+
+void TestCursorNavigation::testTargetDeletions()
+{
+
}
-QTEST_APPLESS_MAIN(TestCursorNavigation)
+QTEST_MAIN(TestCursorNavigation)
#include "tst_cursornavigation.moc"