aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/4WayTest.qml51
-rw-r--r--tests/CNRect.qml12
-rw-r--r--tests/tests.pro4
-rw-r--r--tests/tst_cursornavigation.cpp110
4 files changed, 170 insertions, 7 deletions
diff --git a/tests/4WayTest.qml b/tests/4WayTest.qml
new file mode 100644
index 0000000..2dac77d
--- /dev/null
+++ b/tests/4WayTest.qml
@@ -0,0 +1,51 @@
+import QtQuick 2.0
+import CursorNavigation 1.0
+
+Item {
+ width: 200
+ height: 200
+
+
+ CNRect {
+ objectName: "left"
+ x: 20
+ y: 60
+ CursorNavigation.objectName: "leftAttached"
+ }
+
+ CNRect {
+ objectName: "center"
+ x: 60
+ y: 60
+ }
+
+ CNRect {
+ objectName: "top"
+ x: 60
+ y: 20
+ }
+
+ CNRect {
+ objectName: "bottom"
+ x: 60
+ y: 100
+ }
+
+ CNRect {
+ objectName: "right"
+ x: 100
+ y: 60
+ }
+
+ CNRect {
+ objectName: "right1"
+ x: 140
+ y: 44
+ }
+
+ CNRect {
+ objectName: "right2"
+ x: 141
+ y: 76
+ }
+}
diff --git a/tests/CNRect.qml b/tests/CNRect.qml
new file mode 100644
index 0000000..50ae4fb
--- /dev/null
+++ b/tests/CNRect.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.0
+import CursorNavigation 1.0
+
+//Cursor Navigable rectangle for reusing in tests
+//has visual indication of cursor for running tests manually
+Rectangle {
+ color: CursorNavigation.hasCursor ? "red" : "green"
+ width: 20
+ height: 20
+
+ CursorNavigation.acceptsCursor: true
+}
diff --git a/tests/tests.pro b/tests/tests.pro
index e4f9b88..6654a27 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -11,4 +11,6 @@ SOURCES += \
INCLUDEPATH += ../plugin
DISTFILES += \
- basics.qml
+ basics.qml \
+ CNRect.qml \
+ 4WayTest.qml
diff --git a/tests/tst_cursornavigation.cpp b/tests/tst_cursornavigation.cpp
index c0a6f97..bb810aa 100644
--- a/tests/tst_cursornavigation.cpp
+++ b/tests/tst_cursornavigation.cpp
@@ -19,10 +19,11 @@ public:
private slots:
void test_basics();
void test_callbacks();
- void test_spatial4Directions();
- void test_spatial360();
+ void test_navigation4Directions();
+ void test_navigation360();
void testRedirects();
- void testTargetDeletions();
+ void test_trapping();
+ void test_targetDeletions();
};
TestCursorNavigation::TestCursorNavigation()
@@ -119,6 +120,7 @@ void TestCursorNavigation::test_basics()
//QVERIFY(item2IndirectChild->hasActiveFocus());
QVERIFY(hasCursor2.read().toBool());
+ delete view;
}
void TestCursorNavigation::test_callbacks()
@@ -126,12 +128,103 @@ void TestCursorNavigation::test_callbacks()
}
-void TestCursorNavigation::test_spatial4Directions()
+void TestCursorNavigation::test_navigation4Directions()
{
//test the spatial algorithm in the basic 4 directional case
+ QQuickView *view = new QQuickView;
+ view->setSource(QUrl::fromLocalFile(QFINDTESTDATA("4WayTest.qml")));
+ QVERIFY(view->status() == QQuickView::Ready);
+
+ view->show();
+ view->requestActivate();
+
+ QVERIFY(QTest::qWaitForWindowActive(view));
+ QTRY_COMPARE(view, qGuiApp->focusWindow());
+
+ QQuickItem *root = view->rootObject();
+ QQuickItem *left = root->findChild<QQuickItem*>(QLatin1String("left"));
+ QQuickItem *right = root->findChild<QQuickItem*>(QLatin1String("right"));
+ QQuickItem *right1 = root->findChild<QQuickItem*>(QLatin1String("right1"));
+ QQuickItem *right2 = root->findChild<QQuickItem*>(QLatin1String("right2"));
+ QQuickItem *top = root->findChild<QQuickItem*>(QLatin1String("top"));
+ QQuickItem *bottom = root->findChild<QQuickItem*>(QLatin1String("bottom"));
+ QQuickItem *center = root->findChild<QQuickItem*>(QLatin1String("center"));
+
+ QObject *leftAttached = left->findChild<QObject*>(QLatin1String("leftAttached"));
+
+ QQmlProperty leftHasCursor(left, "CursorNavigation.hasCursor", qmlContext(left));
+ QQmlProperty rightHasCursor(right, "CursorNavigation.hasCursor", qmlContext(right));
+ QQmlProperty right1HasCursor(right1, "CursorNavigation.hasCursor", qmlContext(right1));
+ QQmlProperty right2HasCursor(right2, "CursorNavigation.hasCursor", qmlContext(right2));
+ QQmlProperty topHasCursor(top, "CursorNavigation.hasCursor", qmlContext(top));
+ QQmlProperty bottomHasCursor(bottom, "CursorNavigation.hasCursor", qmlContext(bottom));
+ QQmlProperty centerHasCursor(center, "CursorNavigation.hasCursor", qmlContext(center));
+
+
+ /* test all directions with a direct target ie. in projection,
+ * with the target being out of projection, and without any potential
+ * target in that direction (a miss) */
+ left->forceActiveFocus();
+ QVERIFY(leftHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveLeft"); //miss
+ QVERIFY(leftHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveRight");
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveDown");
+ QVERIFY(bottomHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveDown"); //miss
+ QVERIFY(bottomHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveUp");
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveRight");
+ QVERIFY(rightHasCursor.read().toBool());
+
+ //test that from 2 items within projection, the closest is picked
+ QMetaObject::invokeMethod(leftAttached, "moveRight");
+ QVERIFY(right1HasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveRight"); //miss
+ QVERIFY(right1HasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveLeft");
+ QMetaObject::invokeMethod(leftAttached, "moveLeft");
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveUp");
+ QVERIFY(topHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveUp"); //miss
+ QVERIFY(topHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveDown");
+ QVERIFY(centerHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveLeft");
+ QVERIFY(leftHasCursor.read().toBool());
+
+ //moves to item outside of projection
+ QMetaObject::invokeMethod(leftAttached, "moveDown");
+ QVERIFY(bottomHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveRight");
+ QVERIFY(rightHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveUp");
+ QVERIFY(topHasCursor.read().toBool());
+
+ QMetaObject::invokeMethod(leftAttached, "moveLeft");
+ QVERIFY(leftHasCursor.read().toBool());
+
+ delete view;
}
-void TestCursorNavigation::test_spatial360()
+void TestCursorNavigation::test_navigation360()
{
}
@@ -141,7 +234,12 @@ void TestCursorNavigation::testRedirects()
}
-void TestCursorNavigation::testTargetDeletions()
+void TestCursorNavigation::test_trapping()
+{
+
+}
+
+void TestCursorNavigation::test_targetDeletions()
{
}