diff options
author | Friedemann Kleint <Friedemann.Kleint@theqtcompany.com> | 2015-06-08 12:21:30 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-06-12 07:48:22 +0000 |
commit | d0f64542c8e6ec272d3fa19cf25ffe7ac33a99bc (patch) | |
tree | 934d26f4257490d01e2524b76ebf9db7a87944f5 /src | |
parent | ca22a022967848358e1b2f0eec9588a0cb12a5e5 (diff) |
Output registered enumeration names in QCOMPARE.
Produces output:
FAIL! : tst_qquickwindow::cursor() Compared values are not the same
Actual (clippedItem.cursor().shape()): ForbiddenCursor
Expected (Qt::ArrowCursor) : ArrowCursor
Loc: [tst_qquickwindow.cpp(1465)]
Change-Id: I8a9dfa099a6011cbe0c07da683d4be3d07e22d5d
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/testlib/qtestcase.h | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 2c6a94faa1..4996931975 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -39,6 +39,7 @@ #include <QtCore/qstring.h> #include <QtCore/qnamespace.h> #include <QtCore/qmetatype.h> +#include <QtCore/qmetaobject.h> #include <QtCore/qtypetraits.h> #include <string.h> @@ -220,12 +221,28 @@ class QTestData; namespace QTest { - template <typename T> - inline char *toString(const T &) + namespace Internal { + + template<typename T> // Output registered enums + inline typename QtPrivate::QEnableIf<QtPrivate::IsQEnumHelper<T>::Value, char*>::Type toString(T e) + { + QMetaEnum me = QMetaEnum::fromType<T>(); + return qstrdup(me.key(e)); + } + + template <typename T> // Fallback + inline typename QtPrivate::QEnableIf<!QtPrivate::IsQEnumHelper<T>::Value, char*>::Type toString(const T &) { return 0; } + } // namespace Internal + + template<typename T> + inline char *toString(const T &t) + { + return Internal::toString(t); + } Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, int length); Q_TESTLIB_EXPORT char *toPrettyCString(const char *unicode, int length); |