diff options
author | Laszlo Papp <lpapp@kde.org> | 2022-07-01 06:15:17 +0100 |
---|---|---|
committer | Laszlo Papp <lpapp@kde.org> | 2022-07-09 21:08:10 +0100 |
commit | 07ada0b971a84483f3676b5fef46ff2bd6d26dbb (patch) | |
tree | bf1980cbbe1563f1e34425c97c6c38206cfa5590 /src | |
parent | 14ce67629bd36f75b2a9a0b3caf5c4c5d59abeac (diff) |
QTest: Support QKeySequence compare
Add a QTest::toString() override for QKeySequence. This is just calling
QKeySequence::toString(). The default format is PortableText, which
should be ascii. Deliberately avoided NativeText as it can return
unicode, e.g. on Mac.
This is necessary to get helpful information for test failures when
using QCOMPARE for QKeySequence instances.
Currently, the returned output would not only be not helpful, but even
misleading:
Actual (edit.keySequence()): <null>
Expected (QKeySequence()) : <null>
After adding the override, the output is neither misleading nor
unhelpful:
Actual (edit.keySequence()): ""
Expected (keySequence) : "Return"
Some special characters would be escaped in the output, like the literal
double quote:
Actual (edit.keySequence()): "Ctrl+N"
Expected (QKeySequence("\"")): "\""
Change-Id: Ib4b28fca30f6f2ad86c62530767f94a151332e0a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qtest_gui.h | 6 | ||||
-rw-r--r-- | src/testlib/qtestcase.qdoc | 7 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/testlib/qtest_gui.h b/src/testlib/qtest_gui.h index 26cf17c6ef..d68324d91e 100644 --- a/src/testlib/qtest_gui.h +++ b/src/testlib/qtest_gui.h @@ -22,6 +22,7 @@ #include <QtGui/qcolor.h> #include <QtGui/qpixmap.h> #include <QtGui/qimage.h> +#include <QtGui/qkeysequence.h> #include <QtGui/qregion.h> #include <QtGui/qvector2d.h> #include <QtGui/qvector3d.h> @@ -103,6 +104,11 @@ template<> inline char *toString(const QVector4D &v) } #endif // !QT_NO_VECTOR4D +template<> inline char *toString(const QKeySequence &keySequence) +{ + return toString(keySequence.toString()); +} + inline bool qCompare(QIcon const &t1, QIcon const &t2, const char *actual, const char *expected, const char *file, int line) { diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc index 2c46453968..654687c880 100644 --- a/src/testlib/qtestcase.qdoc +++ b/src/testlib/qtestcase.qdoc @@ -1597,6 +1597,13 @@ */ /*! + \fn char *QTest::toString(const QKeySequence &ks) + \overload + \since 6.5 + Returns a textual representation of the key sequence \a ks. +*/ + +/*! \fn template <typename Tuple, int... I> char *QTest::toString(const Tuple &tuple, QtPrivate::IndexesList<I...> ) \internal \since 5.12 |