diff options
Diffstat (limited to 'tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp')
-rw-r--r-- | tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp b/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp index 14649fc345..d372505f8c 100644 --- a/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp +++ b/tests/auto/widgets/widgets/qkeysequenceedit/tst_qkeysequenceedit.cpp @@ -20,6 +20,7 @@ private slots: void testKeys_data(); void testKeys(); void testLineEditContents(); + void testMaximumSequenceLength(); }; void tst_QKeySequenceEdit::testSetters() @@ -49,6 +50,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); |