diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-11-18 14:32:38 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-01-11 03:40:38 +0100 |
commit | 2c01d402e19b6137cf24794cbc4533a2b8b2d816 (patch) | |
tree | d0c0aaa93128a007b604fa3fcd25b8d9c5008723 /tests/auto/corelib/io/qdebug/tst_qdebug.cpp | |
parent | e00d8ad86b8961e514fc91534127f5aa62c3b22f (diff) |
QDebug: pretty-print QStrings and QStringRefs
[ChangeLog][QtCore][QDebug] Printing of QStrings and QStringRefs
whenever "noquote" is not active now prints the strings in a format that
can be copied back to C++ code. All characters that aren't printable in
US-ASCII are escaped (this includes printable Unicode characters outside
of US-ASCII). Pretty-printing will not respect QTextFormat padding or
field widths.
Change-Id: I169a8a0508e24693f5652f0129defe7f709e5d08
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io/qdebug/tst_qdebug.cpp')
-rw-r--r-- | tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 015a13775d..63de953437 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -52,6 +52,7 @@ private slots: void stateSaver() const; void veryLongWarningMessage() const; void qDebugQChar() const; + void qDebugQString() const; void qDebugQStringRef() const; void qDebugQLatin1String() const; void qDebugQByteArray() const; @@ -344,6 +345,54 @@ void tst_QDebug::qDebugQChar() const } +void tst_QDebug::qDebugQString() const +{ + /* Use a basic string. */ + { + QString file, function; + int line = 0; + const QString in(QLatin1String("input")); + const QStringRef inRef(&in); + + MessageHandlerSetter mhs(myMessageHandler); + { qDebug() << inRef; } +#ifndef QT_NO_MESSAGELOGCONTEXT + file = __FILE__; line = __LINE__ - 2; function = Q_FUNC_INFO; +#endif + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("\"input\"")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); + } + + /* simpler tests from now on */ + MessageHandlerSetter mhs(myMessageHandler); + + QString string = "Hello"; + qDebug() << string; + QCOMPARE(s_msg, QString("\"Hello\"")); + + qDebug().noquote().nospace() << string; + QCOMPARE(s_msg, string); + + qDebug().noquote().nospace() << qSetFieldWidth(8) << string; + QCOMPARE(s_msg, " " + string); + + string = QLatin1String("\nSm\xF8rg\xE5sbord\\"); + qDebug().noquote().nospace() << string; + QCOMPARE(s_msg, string); + + qDebug() << string; + QCOMPARE(s_msg, QString("\"\\nSm\\u00F8rg\\u00E5sbord\\\\\"")); + + // surrogate pairs (including broken pairings) + ushort utf16[] = { 0xDC00, 0xD800, 0xDC00, 'x', 0xD800, 0xDC00, 0xD800, 0 }; + string = QString::fromUtf16(utf16); + qDebug() << string; + QCOMPARE(s_msg, QString("\"\\uDC00\\U00010000x\\U00010000\\uD800\"")); +} + void tst_QDebug::qDebugQStringRef() const { /* Use a basic string. */ @@ -403,6 +452,24 @@ void tst_QDebug::qDebugQLatin1String() const QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); + + /* simpler tests from now on */ + QLatin1String string("\"Hello\""); + qDebug() << string; + QCOMPARE(s_msg, QString("\"\\\"Hello\\\"\"")); + + qDebug().noquote().nospace() << string; + QCOMPARE(s_msg, QString(string)); + + qDebug().noquote().nospace() << qSetFieldWidth(8) << string; + QCOMPARE(s_msg, " " + QString(string)); + + string = QLatin1String("\nSm\xF8rg\xE5sbord\\"); + qDebug().noquote().nospace() << string; + QCOMPARE(s_msg, QString(string)); + + qDebug() << string; + QCOMPARE(s_msg, QString("\"\\nSm\\u00F8rg\\u00E5sbord\\\\\"")); } void tst_QDebug::qDebugQByteArray() const |