diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-11-23 09:25:56 +0100 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2020-11-23 10:59:49 +0100 |
commit | 57d7cb697e3d8f2caf4690411bdccb208107dcc9 (patch) | |
tree | c97bcdbadfa0232cadcba05dbe826f3ca984faac /tests/auto/quick | |
parent | 755a4bac045ffdad8f7f00805406eef66b57d3f4 (diff) |
tst_qquicktextinput: Do not construct illegal QChar
This change does the minimal amount of work to get the test to run
without crashing due to triggering a QChar assert.
Note that Key::toString does not check whether the QChar value it tries
to construct is actually valid; but all values in the test case are.
Fixes: QTBUG-88712
Change-Id: Ie484e66de46ad1d78573c31d90d40c99b8fd7caa
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto/quick')
-rw-r--r-- | tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp index c7609623c9..d176da4449 100644 --- a/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp +++ b/tests/auto/quick/qquicktextinput/tst_qquicktextinput.cpp @@ -87,7 +87,20 @@ template <typename T> static T evaluate(QObject *scope, const QString &expressio template<typename T, int N> int lengthOf(const T (&)[N]) { return N; } -typedef QPair<int, QChar> Key; +struct Key { + Key() = default; + Key(int key, Qt::Key keyAsCharacter) : key(key), character(keyAsCharacter <= 0xffff ? keyAsCharacter : 0) {} + Key(int key, QChar character) : key(key), character(character) {} + + QString toString() const { + if (character == 0) + return {}; + return character; + } + + int key; // a Qt::Key + QChar character; // the character corresponding to the key (if any) +}; class tst_qquicktextinput : public QQmlDataTest @@ -258,9 +271,9 @@ Q_DECLARE_METATYPE(KeyList) void tst_qquicktextinput::simulateKeys(QWindow *window, const QList<Key> &keys) { for (int i = 0; i < keys.count(); ++i) { - const int key = keys.at(i).first & ~Qt::KeyboardModifierMask; - const int modifiers = keys.at(i).first & Qt::KeyboardModifierMask; - const QString text = !keys.at(i).second.isNull() ? QString(keys.at(i).second) : QString(); + const int key = keys.at(i).key & ~Qt::KeyboardModifierMask; + const int modifiers = keys.at(i).key & Qt::KeyboardModifierMask; + const QString text = keys.at(i).toString(); QKeyEvent press(QEvent::KeyPress, Qt::Key(key), Qt::KeyboardModifiers(modifiers), text); QKeyEvent release(QEvent::KeyRelease, Qt::Key(key), Qt::KeyboardModifiers(modifiers), text); |