path: root/src/testlib/qtest.h
diff options
authorThiago Macieira <>2014-01-20 16:03:30 -0800
committerThe Qt Project <>2014-02-16 06:54:18 +0100
commit579526cfec082679241548a0fca1ff9ba2c350a7 (patch)
tree46062137fa4749fdc19793d13a4def2e4dab62d7 /src/testlib/qtest.h
parent19c70982517e76d89bb3da931e1390a6386603da (diff)
Make the printing of complex Unicode in a QString prettier
This also has the advantage of not requiring the use of the locale codec. Quite an advantage if you're debugging the locale codec. But it's mostly so that we don't get question marks that hide the difference we were trying to locate. [ChangeLog][QtTest] QtTest now prints an escaped version of QStrings that failed to compare with QCOMPARE. That is, instead of converting non-printable characters to question marks, QtTest will print the Unicode representation of the character in question. Change-Id: I44c1ef3246b188c913dacd3ca4df02581356ea41 Reviewed-by: Lars Knoll <>
Diffstat (limited to 'src/testlib/qtest.h')
1 files changed, 8 insertions, 8 deletions
diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h
index ac1d6cc9ef..7c9a7b2b3f 100644
--- a/src/testlib/qtest.h
+++ b/src/testlib/qtest.h
@@ -66,14 +66,14 @@ QT_BEGIN_NAMESPACE
namespace QTest
-template<> inline char *toString(const QLatin1String &str)
+template<> inline char *toString(const QString &str)
- return qstrdup(qPrintable(QString(str)));
+ return QTest::toPrettyUnicode(reinterpret_cast<const ushort *>(str.constData()), str.length());
-template<> inline char *toString(const QString &str)
+template<> inline char *toString(const QLatin1String &str)
- return qstrdup(qPrintable(str));
+ return toString(QString(str));
template<> inline char *toString(const QByteArray &ba)
@@ -195,15 +195,15 @@ inline bool qCompare(QList<T> const &t1, QList<T> const &t2, const char *actual,
const int expectedSize = t2.count();
if (actualSize != expectedSize) {
qsnprintf(msg, sizeof(msg), "Compared lists have different sizes.\n"
- " Actual (%s) size: '%d'\n"
- " Expected (%s) size: '%d'", actual, actualSize, expected, expectedSize);
+ " Actual (%s) size: %d\n"
+ " Expected (%s) size: %d", actual, actualSize, expected, expectedSize);
isOk = false;
for (int i = 0; isOk && i < actualSize; ++i) {
if (!( == {
qsnprintf(msg, sizeof(msg), "Compared lists differ at index %d.\n"
- " Actual (%s): '%s'\n"
- " Expected (%s): '%s'", i, actual, toString(,
+ " Actual (%s): %s\n"
+ " Expected (%s): %s", i, actual, toString(,
expected, toString(;
isOk = false;