diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-05-19 10:25:45 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-05-26 11:02:48 +0000 |
commit | ae021882330abc5f6fbaadca290e6e5670c89028 (patch) | |
tree | 99821d2caae31319e00a89a5ecf858e38ebf4f6e /src/testlib/qtestcase.h | |
parent | 25a7034d78aeb12726a1052d64c0aa3314a1f69d (diff) |
QTestlib: Add formatting for QObject * in QCOMPARE
Output object name and class in QCOMPARE(). This should help
to debug flaky QWidget tests that for example check on focusWidget().
[ChangeLog][QtTestLib] QCOMPARE() now reports QObject * values by class and objectName().
Task-number: QTBUG-64446
Change-Id: Ife04e89bba04fc78d077c8f0f07af17a17c9cf8c
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/qtestcase.h')
-rw-r--r-- | src/testlib/qtestcase.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 3fe6d2d867..b046232c65 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -297,6 +297,7 @@ namespace QTest Q_TESTLIB_EXPORT char *toString(const char *); Q_TESTLIB_EXPORT char *toString(const volatile void *); Q_TESTLIB_EXPORT char *toString(const void *); // ### FIXME: Qt 7: Remove + Q_TESTLIB_EXPORT char *toString(const volatile QObject *); Q_TESTLIB_EXPORT void qInit(QObject *testObject, int argc = 0, char **argv = nullptr); Q_TESTLIB_EXPORT int qRun(); @@ -421,6 +422,27 @@ namespace QTest toString(t1), toString(t2), actual, expected, file, line); } + inline bool compare_ptr_helper(const volatile QObject *t1, const volatile QObject *t2, const char *actual, + const char *expected, const char *file, int line) + { + return compare_helper(t1 == t2, "Compared QObject pointers are not the same", + toString(t1), toString(t2), actual, expected, file, line); + } + + inline bool compare_ptr_helper(const volatile QObject *t1, std::nullptr_t, const char *actual, + const char *expected, const char *file, int line) + { + return compare_helper(t1 == nullptr, "Compared QObject pointers are not the same", + toString(t1), toString(nullptr), actual, expected, file, line); + } + + inline bool compare_ptr_helper(std::nullptr_t, const volatile QObject *t2, const char *actual, + const char *expected, const char *file, int line) + { + return compare_helper(nullptr == t2, "Compared QObject pointers are not the same", + toString(nullptr), toString(t2), actual, expected, file, line); + } + inline bool compare_ptr_helper(const volatile void *t1, std::nullptr_t, const char *actual, const char *expected, const char *file, int line) { |