diff options
Diffstat (limited to 'tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp')
-rw-r--r-- | tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp index 35a1aa8757..2df94bb84a 100644 --- a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp +++ b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp @@ -43,6 +43,8 @@ private slots: void sequence(); void context_data(); void context(); + void matcher_data(); + void matcher(); }; Q_DECLARE_METATYPE(Qt::Key) @@ -344,6 +346,68 @@ void tst_QQuickShortcut::context() || inactiveWindow->property("ambiguousShortcut").toString() == ambiguousShortcut); } +typedef bool (*ShortcutContextMatcher)(QObject *, Qt::ShortcutContext); +extern ShortcutContextMatcher qt_quick_shortcut_context_matcher(); +extern void qt_quick_set_shortcut_context_matcher(ShortcutContextMatcher matcher); + +static ShortcutContextMatcher lastMatcher = nullptr; + +static bool trueMatcher(QObject *, Qt::ShortcutContext) +{ + lastMatcher = trueMatcher; + return true; +} + +static bool falseMatcher(QObject *, Qt::ShortcutContext) +{ + lastMatcher = falseMatcher; + return false; +} + +Q_DECLARE_METATYPE(ShortcutContextMatcher) + +void tst_QQuickShortcut::matcher_data() +{ + QTest::addColumn<ShortcutContextMatcher>("matcher"); + QTest::addColumn<Qt::Key>("key"); + QTest::addColumn<QVariant>("shortcut"); + QTest::addColumn<QString>("activatedShortcut"); + + ShortcutContextMatcher tm = trueMatcher; + ShortcutContextMatcher fm = falseMatcher; + + QTest::newRow("F1") << tm << Qt::Key_F1 << shortcutMap("F1", Qt::ApplicationShortcut) << "F1"; + QTest::newRow("F2") << fm << Qt::Key_F2 << shortcutMap("F2", Qt::ApplicationShortcut) << ""; +} + +void tst_QQuickShortcut::matcher() +{ + QFETCH(ShortcutContextMatcher, matcher); + QFETCH(Qt::Key, key); + QFETCH(QVariant, shortcut); + QFETCH(QString, activatedShortcut); + + ShortcutContextMatcher defaultMatcher = qt_quick_shortcut_context_matcher(); + QVERIFY(defaultMatcher); + + qt_quick_set_shortcut_context_matcher(matcher); + QVERIFY(qt_quick_shortcut_context_matcher() == matcher); + + QQmlApplicationEngine engine(testFileUrl("shortcuts.qml")); + QQuickWindow *window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0)); + QVERIFY(window); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + window->setProperty("shortcuts", QVariantList() << shortcut); + QTest::keyClick(window, key); + + QVERIFY(lastMatcher == matcher); + QCOMPARE(window->property("activatedShortcut").toString(), activatedShortcut); + + qt_quick_set_shortcut_context_matcher(defaultMatcher); +} + QTEST_MAIN(tst_QQuickShortcut) #include "tst_qquickshortcut.moc" |