diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickshortcut/data/multiple.qml | 45 | ||||
-rw-r--r-- | tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp | 45 |
2 files changed, 90 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickshortcut/data/multiple.qml b/tests/auto/quick/qquickshortcut/data/multiple.qml new file mode 100644 index 0000000000..2b58327cf0 --- /dev/null +++ b/tests/auto/quick/qquickshortcut/data/multiple.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtQuick module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.9 +import QtQuick.Window 2.2 + +Window { + id: window + + width: 300 + height: 300 + + property bool activated: false + property alias shortcut: shortcut + + Shortcut { + id: shortcut + onActivated: window.activated = true + } +} diff --git a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp index 2df94bb84a..75ccf26af9 100644 --- a/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp +++ b/tests/auto/quick/qquickshortcut/tst_qquickshortcut.cpp @@ -45,6 +45,8 @@ private slots: void context(); void matcher_data(); void matcher(); + void multiple_data(); + void multiple(); }; Q_DECLARE_METATYPE(Qt::Key) @@ -408,6 +410,49 @@ void tst_QQuickShortcut::matcher() qt_quick_set_shortcut_context_matcher(defaultMatcher); } +void tst_QQuickShortcut::multiple_data() +{ + QTest::addColumn<QStringList>("sequences"); + QTest::addColumn<Qt::Key>("key"); + QTest::addColumn<Qt::KeyboardModifiers>("modifiers"); + QTest::addColumn<bool>("enabled"); + QTest::addColumn<bool>("activated"); + + // first + QTest::newRow("Ctrl+X,(Shift+Del)") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_X << Qt::KeyboardModifiers(Qt::ControlModifier) << true << true; + // second + QTest::newRow("(Ctrl+X),Shift+Del") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_Delete << Qt::KeyboardModifiers(Qt::ShiftModifier) << true << true; + // disabled + QTest::newRow("(Ctrl+X,Shift+Del)") << (QStringList() << "Ctrl+X" << "Shift+Del") << Qt::Key_X << Qt::KeyboardModifiers(Qt::ControlModifier) << false << false; +} + +void tst_QQuickShortcut::multiple() +{ + QFETCH(QStringList, sequences); + QFETCH(Qt::Key, key); + QFETCH(Qt::KeyboardModifiers, modifiers); + QFETCH(bool, enabled); + QFETCH(bool, activated); + + QQmlApplicationEngine engine; + + engine.load(testFileUrl("multiple.qml")); + QQuickWindow *window = qobject_cast<QQuickWindow *>(engine.rootObjects().value(0)); + QVERIFY(window); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QObject *shortcut = window->property("shortcut").value<QObject *>(); + QVERIFY(shortcut); + + shortcut->setProperty("enabled", enabled); + shortcut->setProperty("sequences", sequences); + + QTest::keyPress(window, key, modifiers); + + QCOMPARE(window->property("activated").toBool(), activated); +} + QTEST_MAIN(tst_QQuickShortcut) #include "tst_qquickshortcut.moc" |