From 13427797da2464f60412b80b2ad2c4559fc63711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antti=20H=C3=B6ltt=C3=A4?= Date: Tue, 5 Mar 2019 16:16:25 +0100 Subject: Add test for 4 way navigation --- tests/4WayTest.qml | 51 +++++++++++++++++++ tests/CNRect.qml | 12 +++++ tests/tests.pro | 4 +- tests/tst_cursornavigation.cpp | 110 ++++++++++++++++++++++++++++++++++++++--- 4 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 tests/4WayTest.qml create mode 100644 tests/CNRect.qml 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(QLatin1String("left")); + QQuickItem *right = root->findChild(QLatin1String("right")); + QQuickItem *right1 = root->findChild(QLatin1String("right1")); + QQuickItem *right2 = root->findChild(QLatin1String("right2")); + QQuickItem *top = root->findChild(QLatin1String("top")); + QQuickItem *bottom = root->findChild(QLatin1String("bottom")); + QQuickItem *center = root->findChild(QLatin1String("center")); + + QObject *leftAttached = left->findChild(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() { } -- cgit v1.2.3