summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Hölttä <AHoelttae@luxoft.com>2019-03-12 16:04:36 +0100
committerAntti Hölttä <AHoelttae@luxoft.com>2019-03-18 16:43:04 +0100
commit00a273acef3cb084e7a9725c9ecc60c3aa3556da (patch)
treee363a51689e72510ef3d6d45de178d8bc4c43b99
parent3b2cbd9016158a6511bd2f9699d095dd60c8fc66 (diff)
Add test for 360 navigation. Not complete, fails with 360 degrees.
-rw-r--r--tests/360Test.qml62
-rw-r--r--tests/tests.pro3
-rw-r--r--tests/tst_cursornavigation.cpp80
3 files changed, 144 insertions, 1 deletions
diff --git a/tests/360Test.qml b/tests/360Test.qml
new file mode 100644
index 0000000..77b3ecf
--- /dev/null
+++ b/tests/360Test.qml
@@ -0,0 +1,62 @@
+import QtQuick 2.0
+import CursorNavigation 1.0
+
+Item {
+ width: 300
+ height: 300
+
+ CNRect {
+ objectName: "center"
+ CursorNavigation.objectName: "centerAttached"
+ x: 140
+ y: 140
+ }
+
+ CNRect {
+ objectName: "d0"
+ x: 270
+ y: 140
+ }
+
+ CNRect {
+ objectName: "d45"
+ x: 270
+ y: 270
+ }
+
+ CNRect {
+ objectName: "d90"
+ x: 140
+ y: 270
+ }
+
+ CNRect {
+ objectName: "d135"
+ x: 10
+ y: 270
+ }
+
+ CNRect {
+ objectName: "d180"
+ x: 10
+ y: 140
+ }
+
+ CNRect {
+ objectName: "d225"
+ x: 10
+ y: 10
+ }
+
+ CNRect {
+ objectName: "d270"
+ x: 140
+ y: 10
+ }
+
+ CNRect {
+ objectName: "d315"
+ x: 270
+ y: 10
+ }
+}
diff --git a/tests/tests.pro b/tests/tests.pro
index ed92176..7bf1cf7 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -15,4 +15,5 @@ DISTFILES += \
CNRect.qml \
4WayTest.qml \
reparenting.qml \
- reparenting2.qml
+ reparenting2.qml \
+ 360Test.qml
diff --git a/tests/tst_cursornavigation.cpp b/tests/tst_cursornavigation.cpp
index e02df40..60ff6ef 100644
--- a/tests/tst_cursornavigation.cpp
+++ b/tests/tst_cursornavigation.cpp
@@ -228,7 +228,87 @@ void TestCursorNavigation::test_navigation4Directions()
void TestCursorNavigation::test_navigation360()
{
+ //test the spatial algorithm in the 360 case
+ QQuickView *view = new QQuickView;
+ view->setSource(QUrl::fromLocalFile(QFINDTESTDATA("360Test.qml")));
+ QVERIFY(view->status() == QQuickView::Ready);
+
+ view->show();
+ view->requestActivate();
+
+ QVERIFY(QTest::qWaitForWindowActive(view));
+ QTRY_COMPARE(view, qGuiApp->focusWindow());
+
+ QQuickItem *root = view->rootObject();
+ QQuickItem *center = root->findChild<QQuickItem*>(QLatin1String("center"));
+ QQuickItem *d0 = root->findChild<QQuickItem*>(QLatin1String("d0"));
+ QQuickItem *d45 = root->findChild<QQuickItem*>(QLatin1String("d45"));
+ QQuickItem *d90 = root->findChild<QQuickItem*>(QLatin1String("d90"));
+ QQuickItem *d135 = root->findChild<QQuickItem*>(QLatin1String("d135"));
+ QQuickItem *d180 = root->findChild<QQuickItem*>(QLatin1String("d180"));
+ QQuickItem *d225 = root->findChild<QQuickItem*>(QLatin1String("d225"));
+ QQuickItem *d270 = root->findChild<QQuickItem*>(QLatin1String("d270"));
+ QQuickItem *d315 = root->findChild<QQuickItem*>(QLatin1String("d315"));
+
+ QQmlProperty centerHasCursor(center, "CursorNavigation.hasCursor", qmlContext(center));
+ QQmlProperty d0HasCursor(d0, "CursorNavigation.hasCursor", qmlContext(d0));
+ QQmlProperty d45HasCursor(d45, "CursorNavigation.hasCursor", qmlContext(d45));
+ QQmlProperty d90HasCursor(d90, "CursorNavigation.hasCursor", qmlContext(d90));
+ QQmlProperty d135HasCursor(d135, "CursorNavigation.hasCursor", qmlContext(d135));
+ QQmlProperty d180HasCursor(d180, "CursorNavigation.hasCursor", qmlContext(d180));
+ QQmlProperty d225HasCursor(d225, "CursorNavigation.hasCursor", qmlContext(d225));
+ QQmlProperty d270HasCursor(d270, "CursorNavigation.hasCursor", qmlContext(d270));
+ QQmlProperty d315HasCursor(d315, "CursorNavigation.hasCursor", qmlContext(d315));
+
+ QObject *centerAttached = center->findChild<QObject*>(QLatin1String("centerAttached"));
+
+ center->forceActiveFocus();
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 0), Q_ARG(qreal, 0));
+ QVERIFY(d0HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, -180), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 45), Q_ARG(qreal, 0));
+ QVERIFY(d45HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, -135), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 90), Q_ARG(qreal, 0));
+ QVERIFY(d90HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, -90), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 135), Q_ARG(qreal, 0));
+ QVERIFY(d135HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, -45), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 180), Q_ARG(qreal, 0));
+ QVERIFY(d180HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 0), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 225), Q_ARG(qreal, 0));
+ QVERIFY(d225HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, -315), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 270), Q_ARG(qreal, 0));
+ QVERIFY(d270HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, -270), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 315), Q_ARG(qreal, 0));
+ QVERIFY(d315HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, -225), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 360), Q_ARG(qreal, 0));
+ QVERIFY(d0HasCursor.read().toBool());
+ QMetaObject::invokeMethod(centerAttached, "move", Q_ARG(qreal, 180), Q_ARG(qreal, 0));
+ QVERIFY(centerHasCursor.read().toBool());
}
void TestCursorNavigation::test_redirects()