summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2012-02-15 13:20:56 +1000
committerQt by Nokia <qt-info@nokia.com>2012-02-15 06:28:08 +0100
commit03883c22264df65586db0a603569c9d196e06034 (patch)
treefe46676a095876e176dffecc2a100bffabb42fc2
parent732a86a11dbc20079e33c289af72762ce0125ced (diff)
Improve test coverage for QQuickItem.
Change-Id: I1a49fd44ba85e0fa87a76c07e39cb603cd4f12e7 Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
-rw-r--r--tests/auto/qtquick2/qquickitem2/data/keysim.qml11
-rw-r--r--tests/auto/qtquick2/qquickitem2/data/keyspriority.qml2
-rw-r--r--tests/auto/qtquick2/qquickitem2/data/parentLoop.qml14
-rw-r--r--tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp68
4 files changed, 95 insertions, 0 deletions
diff --git a/tests/auto/qtquick2/qquickitem2/data/keysim.qml b/tests/auto/qtquick2/qquickitem2/data/keysim.qml
new file mode 100644
index 0000000000..7da8a47681
--- /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 114cf0488a..ae51aae776 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 0000000000..7b6560fbf7
--- /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 c26fc94178..9891b8718a 100644
--- a/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp
+++ b/tests/auto/qtquick2/qquickitem2/tst_qquickitem.cpp
@@ -44,10 +44,13 @@
#include <QtDeclarative/qdeclarativecomponent.h>
#include <QtDeclarative/qdeclarativecontext.h>
#include <QtQuick/qquickview.h>
+#include <QtGui/private/qinputmethod_p.h>
#include <QtQuick/private/qquickrectangle_p.h>
+#include <QtQuick/private/qquicktextinput_p.h>
#include <private/qquickitem_p.h>
#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<KeyTestItem>("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<KeyTestItem*>(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<QQuickTextInput*>();
+ QVERIFY(input);
+
+ QInputMethodEvent ev("Hello world!", QList<QInputMethodEvent::Attribute>());
+ 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<QQuickItem>(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<QQuickItem*>(canvas->rootObject());
+ QVERIFY(root);
+
+ QQuickItem *item1 = root->findChild<QQuickItem*>("item1");
+ QVERIFY(item1);
+ QCOMPARE(item1->parentItem(), root);
+
+ QQuickItem *item2 = root->findChild<QQuickItem*>("item2");
+ QVERIFY(item2);
+ QCOMPARE(item2->parentItem(), item1);
+
+ delete canvas;
+}
+
QTEST_MAIN(tst_QQuickItem)
#include "tst_qquickitem.moc"