From 03883c22264df65586db0a603569c9d196e06034 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Wed, 15 Feb 2012 13:20:56 +1000 Subject: [PATCH] Improve test coverage for QQuickItem. Change-Id: I1a49fd44ba85e0fa87a76c07e39cb603cd4f12e7 Reviewed-by: Yann Bodson --- tests/auto/qtquick2/qquickitem2/data/keysim.qml | 11 ++++ .../qtquick2/qquickitem2/data/keyspriority.qml | 2 + .../auto/qtquick2/qquickitem2/data/parentLoop.qml | 14 +++++ tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp | 68 ++++++++++++++++++++++ 4 files changed, 95 insertions(+) create mode 100644 tests/auto/qtquick2/qquickitem2/data/keysim.qml create mode 100644 tests/auto/qtquick2/qquickitem2/data/parentLoop.qml diff --git a/tests/auto/qtquick2/qquickitem2/data/keysim.qml b/tests/auto/qtquick2/qquickitem2/data/keysim.qml new file mode 100644 index 0000000..7da8a47 --- /dev/null +++ b/tests/auto/qtquick2/qquickitem2/data/keysim.qml @@ -0,0 +1,11 @@ +import QtQuick 2.0 + +Item { + focus: true + + Keys.forwardTo: [ item2 ] + + TextInput { + id: item2 + } +} diff --git a/tests/auto/qtquick2/qquickitem2/data/keyspriority.qml b/tests/auto/qtquick2/qquickitem2/data/keyspriority.qml index 114cf04..ae51aae 100644 --- a/tests/auto/qtquick2/qquickitem2/data/keyspriority.qml +++ b/tests/auto/qtquick2/qquickitem2/data/keyspriority.qml @@ -6,4 +6,6 @@ KeyTestItem { Keys.onPressed: keysTestObject.keyPress(event.key, event.text, event.modifiers) Keys.onReleased: { keysTestObject.keyRelease(event.key, event.text, event.modifiers); event.accepted = true; } Keys.priority: keysTestObject.processLast ? Keys.AfterItem : Keys.BeforeItem + + property int priorityTest: Keys.priority } diff --git a/tests/auto/qtquick2/qquickitem2/data/parentLoop.qml b/tests/auto/qtquick2/qquickitem2/data/parentLoop.qml new file mode 100644 index 0000000..7b6560f --- /dev/null +++ b/tests/auto/qtquick2/qquickitem2/data/parentLoop.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Item { + Item { + id: item1 + objectName: "item1" + + Item { + id: item2 + objectName: "item2" + } + } + Component.onCompleted: item1.parent = item2 +} diff --git a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp index c26fc94..9891b87 100644 --- a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp @@ -44,10 +44,13 @@ #include #include #include +#include #include +#include #include #include "../../shared/util.h" #include "../shared/visualtestutil.h" +#include "../../shared/platforminputcontext.h" using namespace QQuickVisualTestUtil; @@ -59,8 +62,11 @@ public: private slots: void initTestCase(); + void cleanup(); + void keys(); void keysProcessingOrder(); + void keysim(); void keyNavigation(); void keyNavigation_RightToLeft(); void keyNavigation_skipNotVisible(); @@ -86,6 +92,7 @@ private slots: void implicitSize(); void qtbug_16871(); void visibleChildren(); + void parentLoop(); private: QDeclarativeEngine engine; }; @@ -182,6 +189,12 @@ void tst_QQuickItem::initTestCase() qmlRegisterType("Test",1,0,"KeyTestItem"); } +void tst_QQuickItem::cleanup() +{ + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = 0; +} + void tst_QQuickItem::keys() { QQuickView *canvas = new QQuickView(0); @@ -320,6 +333,8 @@ void tst_QQuickItem::keysProcessingOrder() KeyTestItem *testItem = qobject_cast(canvas->rootObject()); QVERIFY(testItem); + QCOMPARE(testItem->property("priorityTest").toInt(), 0); + QKeyEvent key(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "A", false, 1); QGuiApplication::sendEvent(canvas, &key); QCOMPARE(testObject->mKey, int(Qt::Key_A)); @@ -331,6 +346,8 @@ void tst_QQuickItem::keysProcessingOrder() testObject->setProcessLast(true); + QCOMPARE(testItem->property("priorityTest").toInt(), 1); + key = QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "A", false, 1); QGuiApplication::sendEvent(canvas, &key); QCOMPARE(testObject->mKey, 0); @@ -356,6 +373,36 @@ void tst_QQuickItem::keysProcessingOrder() delete testObject; } +void tst_QQuickItem::keysim() +{ + PlatformInputContext platformInputContext; + QInputMethodPrivate *inputMethodPrivate = QInputMethodPrivate::get(qApp->inputMethod()); + inputMethodPrivate->testContext = &platformInputContext; + + QQuickView *canvas = new QQuickView(0); + canvas->setBaseSize(QSize(240,320)); + + canvas->setSource(testFileUrl("keysim.qml")); + canvas->show(); + canvas->requestActivateWindow(); + QTest::qWaitForWindowShown(canvas); + QTRY_VERIFY(QGuiApplication::focusWindow() == canvas); + + QVERIFY(canvas->rootObject()); + QVERIFY(canvas->rootObject()->hasFocus() && canvas->rootObject()->hasActiveFocus()); + + QQuickTextInput *input = canvas->rootObject()->findChild(); + QVERIFY(input); + + QInputMethodEvent ev("Hello world!", QList()); + QGuiApplication::sendEvent(qGuiApp->focusObject(), &ev); + + QEXPECT_FAIL("", "QTBUG-24280", Continue); + QCOMPARE(input->text(), QLatin1String("Hello world!")); + + delete canvas; +} + QQuickItemPrivate *childPrivate(QQuickItem *rootItem, const char * itemString) { QQuickItem *item = findItem(rootItem, QString(QLatin1String(itemString))); @@ -1307,6 +1354,27 @@ void tst_QQuickItem::visibleChildren() delete canvas; } +void tst_QQuickItem::parentLoop() +{ + QQuickView *canvas = new QQuickView(0); + + QTest::ignoreMessage(QtWarningMsg, "QQuickItem::setParentItem: Parent is already part of this items subtree."); + canvas->setSource(testFileUrl("parentLoop.qml")); + + QQuickItem *root = qobject_cast(canvas->rootObject()); + QVERIFY(root); + + QQuickItem *item1 = root->findChild("item1"); + QVERIFY(item1); + QCOMPARE(item1->parentItem(), root); + + QQuickItem *item2 = root->findChild("item2"); + QVERIFY(item2); + QCOMPARE(item2->parentItem(), item1); + + delete canvas; +} + QTEST_MAIN(tst_QQuickItem) #include "tst_qquickitem.moc" -- 2.7.4