diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-05-30 17:06:58 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-07-01 18:02:33 +0200 |
commit | ea045d82a3a837f83fec82462feebf2bc262f9d9 (patch) | |
tree | 5236ec962b89f3fdc883fc2fa813bdbe9317ba81 /tests/auto/quick/qquickitem2/tst_qquickitem.cpp | |
parent | 101a5185138f4eb4d1ed0e69065d8e4c30a7fff7 (diff) |
Add bool QQuickKeyEvent::matches(QKeySequence::StandardKey)
Change-Id: Iaa8392c1b113856fa80cd2507f8640050eb9bec2
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'tests/auto/quick/qquickitem2/tst_qquickitem.cpp')
-rw-r--r-- | tests/auto/quick/qquickitem2/tst_qquickitem.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp index 992e81aa64..d15a46feca 100644 --- a/tests/auto/quick/qquickitem2/tst_qquickitem.cpp +++ b/tests/auto/quick/qquickitem2/tst_qquickitem.cpp @@ -78,6 +78,8 @@ private slots: void nextItemInFocusChain2(); void keys(); + void standardKeys_data(); + void standardKeys(); void keysProcessingOrder(); void keysim(); void keyNavigation(); @@ -1089,6 +1091,64 @@ void tst_QQuickItem::keys() delete testObject; } +Q_DECLARE_METATYPE(QEvent::Type); +Q_DECLARE_METATYPE(QKeySequence::StandardKey); + +void tst_QQuickItem::standardKeys_data() +{ + QTest::addColumn<QKeySequence::StandardKey>("standardKey"); + QTest::addColumn<QKeySequence::StandardKey>("contextProperty"); + QTest::addColumn<QEvent::Type>("eventType"); + QTest::addColumn<bool>("pressed"); + QTest::addColumn<bool>("released"); + + QTest::newRow("Press: Open") << QKeySequence::Open << QKeySequence::Open << QEvent::KeyPress << true << false; + QTest::newRow("Press: Close") << QKeySequence::Close << QKeySequence::Close << QEvent::KeyPress << true << false; + QTest::newRow("Press: Save") << QKeySequence::Save << QKeySequence::Save << QEvent::KeyPress << true << false; + QTest::newRow("Press: Quit") << QKeySequence::Quit << QKeySequence::Quit << QEvent::KeyPress << true << false; + + QTest::newRow("Release: New") << QKeySequence::New << QKeySequence::New << QEvent::KeyRelease << false << true; + QTest::newRow("Release: Delete") << QKeySequence::Delete << QKeySequence::Delete << QEvent::KeyRelease << false << true; + QTest::newRow("Release: Undo") << QKeySequence::Undo << QKeySequence::Undo << QEvent::KeyRelease << false << true; + QTest::newRow("Release: Redo") << QKeySequence::Redo << QKeySequence::Redo << QEvent::KeyRelease << false << true; + + QTest::newRow("Mismatch: Cut") << QKeySequence::Cut << QKeySequence::Copy << QEvent::KeyPress << false << false; + QTest::newRow("Mismatch: Copy") << QKeySequence::Copy << QKeySequence::Paste << QEvent::KeyPress << false << false; + QTest::newRow("Mismatch: Paste") << QKeySequence::Paste << QKeySequence::Cut << QEvent::KeyRelease << false << false; + QTest::newRow("Mismatch: Quit") << QKeySequence::Quit << QKeySequence::New << QEvent::KeyRelease << false << false; +} + +void tst_QQuickItem::standardKeys() +{ + QFETCH(QKeySequence::StandardKey, standardKey); + QFETCH(QKeySequence::StandardKey, contextProperty); + QFETCH(QEvent::Type, eventType); + QFETCH(bool, pressed); + QFETCH(bool, released); + + QKeySequence keySequence(standardKey); + if (keySequence.isEmpty()) + QSKIP("Undefined key sequence."); + + QQuickView view; + view.rootContext()->setContextProperty("standardKey", contextProperty); + view.setSource(testFileUrl("standardkeys.qml")); + view.show(); + view.requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(&view)); + + QQuickItem *item = qobject_cast<QQuickItem*>(view.rootObject()); + QVERIFY(item); + + const int key = keySequence[0] & Qt::Key_unknown; + const int modifiers = keySequence[0] & Qt::KeyboardModifierMask; + QKeyEvent keyEvent(eventType, key, static_cast<Qt::KeyboardModifiers>(modifiers)); + QGuiApplication::sendEvent(&view, &keyEvent); + + QCOMPARE(item->property("pressed").toBool(), pressed); + QCOMPARE(item->property("released").toBool(), released); +} + void tst_QQuickItem::keysProcessingOrder() { QQuickView *window = new QQuickView(0); |