summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml9
-rw-r--r--tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp131
-rw-r--r--tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp14
-rw-r--r--tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp27
4 files changed, 168 insertions, 13 deletions
diff --git a/tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml b/tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml
new file mode 100644
index 0000000..171536b
--- /dev/null
+++ b/tests/auto/declarative/qdeclarativeitem/data/keyspriority.qml
@@ -0,0 +1,9 @@
+import Qt 4.7
+import Test 1.0
+
+KeyTestItem {
+ focus: true
+ 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
+}
diff --git a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
index f4edeb2..ecc813e 100644
--- a/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
+++ b/tests/auto/declarative/qdeclarativeitem/tst_qdeclarativeitem.cpp
@@ -55,7 +55,9 @@ public:
tst_QDeclarativeItem();
private slots:
+ void initTestCase();
void keys();
+ void keysProcessingOrder();
void keyNavigation();
void smooth();
void clip();
@@ -79,8 +81,11 @@ private:
class KeysTestObject : public QObject
{
Q_OBJECT
+
+ Q_PROPERTY(bool processLast READ processLast NOTIFY processLastChanged)
+
public:
- KeysTestObject() : mKey(0), mModifiers(0), mForwardedKey(0) {}
+ KeysTestObject() : mKey(0), mModifiers(0), mForwardedKey(0), mLast(false) {}
void reset() {
mKey = 0;
@@ -89,6 +94,14 @@ public:
mForwardedKey = 0;
}
+ bool processLast() const { return mLast; }
+ void setProcessLast(bool b) {
+ if (b != mLast) {
+ mLast = b;
+ emit processLastChanged();
+ }
+ }
+
public slots:
void keyPress(int key, QString text, int modifiers) {
mKey = key;
@@ -104,20 +117,73 @@ public slots:
mForwardedKey = key;
}
+signals:
+ void processLastChanged();
+
public:
int mKey;
QString mText;
int mModifiers;
int mForwardedKey;
+ bool mLast;
private:
};
+class KeyTestItem : public QDeclarativeItem
+{
+ Q_OBJECT
+public:
+ KeyTestItem(QDeclarativeItem *parent=0) : QDeclarativeItem(parent), mKey(0) {}
+
+protected:
+ void keyPressEvent(QKeyEvent *e) {
+ keyPressPreHandler(e);
+ if (e->isAccepted())
+ return;
+
+ mKey = e->key();
+
+ if (e->key() == Qt::Key_A)
+ e->accept();
+ else
+ e->ignore();
+
+ if (!e->isAccepted())
+ QDeclarativeItem::keyPressEvent(e);
+ }
+
+ void keyReleaseEvent(QKeyEvent *e) {
+ keyReleasePreHandler(e);
+
+ if (e->isAccepted())
+ return;
+
+ if (e->key() == Qt::Key_B)
+ e->accept();
+ else
+ e->ignore();
+
+ if (!e->isAccepted())
+ QDeclarativeItem::keyReleaseEvent(e);
+ }
+
+public:
+ int mKey;
+};
+
+QML_DECLARE_TYPE(KeyTestItem);
+
tst_QDeclarativeItem::tst_QDeclarativeItem()
{
}
+void tst_QDeclarativeItem::initTestCase()
+{
+ qmlRegisterType<KeyTestItem>("Test",1,0,"KeyTestItem");
+}
+
void tst_QDeclarativeItem::keys()
{
QDeclarativeView *canvas = new QDeclarativeView(0);
@@ -214,6 +280,69 @@ void tst_QDeclarativeItem::keys()
QCOMPARE(testObject->mKey, 0);
QVERIFY(!key.isAccepted());
+ canvas->rootContext()->setContextProperty("enableKeyHanding", QVariant(true));
+
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier, "", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, int(Qt::Key_Return));
+ QVERIFY(key.isAccepted());
+
+ delete canvas;
+ delete testObject;
+}
+
+void tst_QDeclarativeItem::keysProcessingOrder()
+{
+ QDeclarativeView *canvas = new QDeclarativeView(0);
+ canvas->setFixedSize(240,320);
+
+ KeysTestObject *testObject = new KeysTestObject;
+ canvas->rootContext()->setContextProperty("keysTestObject", testObject);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/keyspriority.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ KeyTestItem *testItem = qobject_cast<KeyTestItem*>(canvas->rootObject());
+ QVERIFY(testItem);
+
+ QEvent wa(QEvent::WindowActivate);
+ QApplication::sendEvent(canvas, &wa);
+ QFocusEvent fe(QEvent::FocusIn);
+ QApplication::sendEvent(canvas, &fe);
+
+ QKeyEvent key(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "A", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, int(Qt::Key_A));
+ QCOMPARE(testObject->mText, QLatin1String("A"));
+ QVERIFY(testObject->mModifiers == Qt::NoModifier);
+ QVERIFY(key.isAccepted());
+
+ testObject->reset();
+
+ testObject->setProcessLast(true);
+
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier, "A", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, 0);
+ QVERIFY(key.isAccepted());
+
+ testObject->reset();
+
+ key = QKeyEvent(QEvent::KeyPress, Qt::Key_B, Qt::NoModifier, "B", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, int(Qt::Key_B));
+ QCOMPARE(testObject->mText, QLatin1String("B"));
+ QVERIFY(testObject->mModifiers == Qt::NoModifier);
+ QVERIFY(!key.isAccepted());
+
+ testObject->reset();
+
+ key = QKeyEvent(QEvent::KeyRelease, Qt::Key_B, Qt::NoModifier, "B", false, 1);
+ QApplication::sendEvent(canvas, &key);
+ QCOMPARE(testObject->mKey, 0);
+ QVERIFY(key.isAccepted());
+
delete canvas;
delete testObject;
}
diff --git a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
index aed4781..26a12f0 100644
--- a/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
+++ b/tests/auto/declarative/qdeclarativelistmodel/tst_qdeclarativelistmodel.cpp
@@ -184,8 +184,8 @@ void tst_qdeclarativelistmodel::dynamic_data()
QTest::newRow("count") << "count" << 0 << "";
- QTest::newRow("get1") << "{get(0)}" << 0 << "<Unknown File>: QML ListModel: get: index 0 out of range";
- QTest::newRow("get2") << "{get(-1)}" << 0 << "<Unknown File>: QML ListModel: get: index -1 out of range";
+ QTest::newRow("get1") << "{get(0)}" << 0 << "";
+ QTest::newRow("get2") << "{get(-1)}" << 0 << "";
QTest::newRow("append1") << "{append({'foo':123});count}" << 1 << "";
QTest::newRow("append2") << "{append({'foo':123,'bar':456});count}" << 1 << "";
@@ -196,13 +196,13 @@ void tst_qdeclarativelistmodel::dynamic_data()
QTest::newRow("clear1") << "{append({'foo':456});clear();count}" << 0 << "";
QTest::newRow("clear2") << "{append({'foo':123});append({'foo':456});clear();count}" << 0 << "";
- QTest::newRow("clear3") << "{append({'foo':123});clear();get(0).foo}" << 0 << "<Unknown File>: QML ListModel: get: index 0 out of range";
+ QTest::newRow("clear3") << "{append({'foo':123});clear()}" << 0 << "";
QTest::newRow("remove1") << "{append({'foo':123});remove(0);count}" << 0 << "";
QTest::newRow("remove2a") << "{append({'foo':123});append({'foo':456});remove(0);count}" << 1 << "";
QTest::newRow("remove2b") << "{append({'foo':123});append({'foo':456});remove(0);get(0).foo}" << 456 << "";
QTest::newRow("remove2c") << "{append({'foo':123});append({'foo':456});remove(1);get(0).foo}" << 123 << "";
- QTest::newRow("remove3") << "{append({'foo':123});remove(0);get(0).foo}" << 0 << "<Unknown File>: QML ListModel: get: index 0 out of range";
+ QTest::newRow("remove3") << "{append({'foo':123});remove(0)}" << 0 << "";
QTest::newRow("remove3a") << "{append({'foo':123});remove(-1);count}" << 1 << "<Unknown File>: QML ListModel: remove: index -1 out of range";
QTest::newRow("remove4a") << "{remove(0)}" << 0 << "<Unknown File>: QML ListModel: remove: index 0 out of range";
QTest::newRow("remove4b") << "{append({'foo':123});remove(0);remove(0);count}" << 0 << "<Unknown File>: QML ListModel: remove: index 0 out of range";
@@ -328,12 +328,6 @@ void tst_qdeclarativelistmodel::dynamic_worker()
if (QByteArray(QTest::currentDataTag()).startsWith("nested"))
QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML ListModel: Cannot add nested list values when modifying or after modification from a worker script");
- if (QByteArray(QTest::currentDataTag()).startsWith("nested-append")) {
- int callsToGet = script.count(QLatin1String(";get("));
- for (int i=0; i<callsToGet; i++)
- QTest::ignoreMessage(QtWarningMsg, "<Unknown File>: QML ListModel: get: index 0 out of range");
- }
-
QVERIFY(QMetaObject::invokeMethod(item, "evalExpressionViaWorker",
Q_ARG(QVariant, operations.mid(0, operations.length()-1))));
waitForWorker(item);
diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
index 7a23773..e639014 100644
--- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
+++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp
@@ -687,7 +687,13 @@ void tst_QDeclarativePositioners::test_conflictinganchors()
component.setData("import Qt 4.7\nColumn { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
item = qobject_cast<QDeclarativeItem*>(component.create());
QVERIFY(item);
- QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom or verticalCenter anchors for items inside Column"));
+ QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
+ warningMessage.clear();
+
+ component.setData("import Qt 4.7\nColumn { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Column: Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column"));
warningMessage.clear();
component.setData("import Qt 4.7\nColumn { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
@@ -699,7 +705,13 @@ void tst_QDeclarativePositioners::test_conflictinganchors()
component.setData("import Qt 4.7\nRow { Item { anchors.left: parent.left } }", QUrl::fromLocalFile(""));
item = qobject_cast<QDeclarativeItem*>(component.create());
QVERIFY(item);
- QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right or horizontalCenter anchors for items inside Row"));
+ QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
+ warningMessage.clear();
+
+ component.setData("import Qt 4.7\nRow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row"));
warningMessage.clear();
component.setData("import Qt 4.7\nRow { Item { anchors.top: parent.top } }", QUrl::fromLocalFile(""));
@@ -714,10 +726,21 @@ void tst_QDeclarativePositioners::test_conflictinganchors()
QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
warningMessage.clear();
+ component.setData("import Qt 4.7\nGrid { Item { anchors.centerIn: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Grid: Cannot specify anchors for items inside Grid"));
+ warningMessage.clear();
+
component.setData("import Qt 4.7\nFlow { Item { anchors.verticalCenter: parent.verticalCenter } }", QUrl::fromLocalFile(""));
item = qobject_cast<QDeclarativeItem*>(component.create());
QVERIFY(item);
QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
+
+ component.setData("import Qt 4.7\nFlow { Item { anchors.fill: parent } }", QUrl::fromLocalFile(""));
+ item = qobject_cast<QDeclarativeItem*>(component.create());
+ QVERIFY(item);
+ QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow"));
}
QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename)