From 62b752b3a2c9a69b5eb9a41b98293e83de347958 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 18 Nov 2014 15:20:21 -0800 Subject: Do the same for qDebug of QByteArray and QLatin1String QLatin1String are actually Unicode, so print them with \uXXXX sequences. QByteArray are binary (arbitrary), so print as hex. Since hex escape sequences in C are not limited in length (\x00000F is a valid hex sequence), we need to insert "" if the next character is a valid hex digit. [ChangeLog][QtCore][QDebug] Similarly, printing of QByteArrays whenever "noquote" is not active now prints the arrays in a format consumable in C++, with all non-printable characters printed in hex escape sequences. Change-Id: Ibd0c1a97cbac98610c65c1091bfbcf5581c835db Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 63de953437..4718b83df0 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -490,6 +490,28 @@ void tst_QDebug::qDebugQByteArray() const QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); + + /* simpler tests from now on */ + QByteArray ba = "\"Hello\""; + qDebug() << ba; + QCOMPARE(s_msg, QString("\"\\\"Hello\\\"\"")); + + qDebug().noquote().nospace() << ba; + QCOMPARE(s_msg, QString::fromLatin1(ba)); + + qDebug().noquote().nospace() << qSetFieldWidth(8) << ba; + QCOMPARE(s_msg, " " + QString::fromLatin1(ba)); + + ba = "\nSm\xC3\xB8rg\xC3\xA5sbord\\"; + qDebug().noquote().nospace() << ba; + QCOMPARE(s_msg, QString::fromUtf8(ba)); + + qDebug() << ba; + QCOMPARE(s_msg, QString("\"\\nSm\\xC3\\xB8rg\\xC3\\xA5sbord\\\\\"")); + + // ensure that it closes hex escape sequences correctly + qDebug() << QByteArray("\377FFFF"); + QCOMPARE(s_msg, QString("\"\\xFF\"\"FFFF\"")); } enum TestEnum { -- cgit v1.2.3