diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp | 112 |
1 files changed, 82 insertions, 30 deletions
diff --git a/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp b/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp index 1a0532ffa4..301be319bf 100644 --- a/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp +++ b/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -45,6 +20,9 @@ private slots: void testKeys_data(); void testKeys(); void testLineEditContents(); + void testMaximumSequenceLength(); + void testFinishingKeyCombinations_data(); + void testFinishingKeyCombinations(); }; void tst_QKeySequenceEdit::testSetters() @@ -59,7 +37,7 @@ void tst_QKeySequenceEdit::testSetters() edit.clear(); QCOMPARE(edit.keySequence(), QKeySequence()); - QCOMPARE(spy.count(), 2); + QCOMPARE(spy.size(), 2); } void tst_QKeySequenceEdit::testKeys_data() @@ -74,6 +52,42 @@ void tst_QKeySequenceEdit::testKeys_data() QTest::newRow("4") << Qt::Key_N << Qt::KeyboardModifiers(Qt::ControlModifier | Qt::ShiftModifier) << QKeySequence("Ctrl+Shift+N"); } +void tst_QKeySequenceEdit::testMaximumSequenceLength() +{ + // + // GIVEN: + // - A QKeySequenceEdit with maxKeyCount == 1 + // - A QKeySequence with more than one key + // + QKeySequenceEdit edit; + edit.setMaximumSequenceLength(1); + QCOMPARE(edit.maximumSequenceLength(), 1); + + QKeySequence multi("Ctrl+X, S"); + QCOMPARE(multi.count(), 2); + + // + // WHEN: setting the key sequence on the edit + // + QTest::ignoreMessage(QtWarningMsg, + "QKeySequenceEdit: setting a key sequence of length 2 when " + "maximumSequenceLength is 1, truncating."); + edit.setKeySequence(multi); + + // + // THEN: + // - the maxKeyCount property doesn't change + // - the key sequence is truncated to maxKeyCount + // - and won't un-truncate by increasing maxKeyCount + // + QCOMPARE(edit.maximumSequenceLength(), 1); + const auto edited = edit.keySequence(); + QCOMPARE(edited.count(), 1); + QCOMPARE(edited, QKeySequence("Ctrl+X")); + edit.setMaximumSequenceLength(2); + QCOMPARE(edit.keySequence(), edited); +} + void tst_QKeySequenceEdit::testKeys() { QFETCH(Qt::Key, key); @@ -85,9 +99,9 @@ void tst_QKeySequenceEdit::testKeys() QTest::keyPress(&edit, key, modifiers); QTest::keyRelease(&edit, key, modifiers); - QCOMPARE(spy.count(), 0); + QCOMPARE(spy.size(), 0); QCOMPARE(edit.keySequence(), keySequence); - QTRY_COMPARE(spy.count(), 1); + QTRY_COMPARE(spy.size(), 1); } void tst_QKeySequenceEdit::testLineEditContents() @@ -111,5 +125,43 @@ void tst_QKeySequenceEdit::testLineEditContents() QCOMPARE(le->text(), QString()); } +void tst_QKeySequenceEdit::testFinishingKeyCombinations_data() +{ + QTest::addColumn<Qt::Key>("key"); + QTest::addColumn<Qt::KeyboardModifiers>("modifiers"); + QTest::addColumn<QKeySequence>("keySequence"); + + QTest::newRow("1") << Qt::Key_Backtab << Qt::KeyboardModifiers(Qt::NoModifier) << QKeySequence("Backtab"); + QTest::newRow("2") << Qt::Key_Tab << Qt::KeyboardModifiers(Qt::NoModifier) << QKeySequence("Tab"); + QTest::newRow("3") << Qt::Key_Return << Qt::KeyboardModifiers(Qt::NoModifier) << QKeySequence("Return"); + QTest::newRow("4") << Qt::Key_Enter << Qt::KeyboardModifiers(Qt::NoModifier) << QKeySequence("Enter"); + QTest::newRow("5") << Qt::Key_Enter << Qt::KeyboardModifiers(Qt::ShiftModifier) << QKeySequence("Shift+Enter"); +} + +void tst_QKeySequenceEdit::testFinishingKeyCombinations() +{ + QFETCH(Qt::Key, key); + QFETCH(Qt::KeyboardModifiers, modifiers); + QFETCH(QKeySequence, keySequence); + QKeySequenceEdit edit; + + QSignalSpy spy(&edit, SIGNAL(editingFinished())); + QCOMPARE(spy.size(), 0); + + edit.setFinishingKeyCombinations({QKeyCombination(modifiers, key)}); + QTest::keyPress(&edit, key, modifiers); + QTest::keyRelease(&edit, key, modifiers); + + QCOMPARE(edit.keySequence(), QKeySequence()); + QTRY_COMPARE(spy.size(), 1); + + edit.setFinishingKeyCombinations({}); + QTest::keyPress(&edit, key, modifiers); + QTest::keyRelease(&edit, key, modifiers); + + QCOMPARE(edit.keySequence(), keySequence); + QTRY_COMPARE(spy.size(), 2); +} + QTEST_MAIN(tst_QKeySequenceEdit) #include "tst_qkeysequenceedit.moc" |