diff options
author | Kai Koehne <kai.koehne@digia.com> | 2014-06-19 11:09:47 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@digia.com> | 2014-07-10 09:27:44 +0200 |
commit | 6d166c88220ee09821b65fb2b711fa77a5312971 (patch) | |
tree | 78f69bc74ba66f8a7d8a97db4cae8fd21b70992e /tests | |
parent | 27797cb37a63eceed77e9b6c790eaaf9c438b360 (diff) |
Add QDebug::noquote() stream modifier
Allow the user to disable the quoting of QString, QByteArray,
QStringLiteral by passing a "noquote()" stream modifier.
This requires another flag to be added to QDebug::Stream. To
keep BC we're using the QMessageLogContext::version field
to differentiate between QDebug streams created by earlier
versions.
Task-number: QTBUG-37146
Change-Id: I9b215eabfcfd754af16ea87f3ef928d698e37d77
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 82 |
1 files changed, 79 insertions, 3 deletions
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 38b6e9ab50..9b761bc63d 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -56,10 +56,13 @@ private slots: void criticalWithoutDebug() const; void debugWithBool() const; void debugSpaceHandling() const; + void debugNoQuotes() const; void stateSaver() const; void veryLongWarningMessage() const; + void qDebugQChar() const; void qDebugQStringRef() const; void qDebugQLatin1String() const; + void qDebugQByteArray() const; void textStreamModifiers() const; void defaultMessagehandler() const; void threadSafety() const; @@ -219,6 +222,32 @@ void tst_QDebug::debugSpaceHandling() const QCOMPARE(s_msg, QString::fromLatin1("QMimeType(invalid) QMimeType(\"application/pdf\") foo")); } +void tst_QDebug::debugNoQuotes() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << QStringLiteral("Hello"); + d.noquote(); + d << QStringLiteral("Hello"); + d.quote(); + d << QStringLiteral("Hello"); + } + QCOMPARE(s_msg, QString::fromLatin1("\"Hello\" Hello \"Hello\"")); + + { + QDebug d = qDebug(); + d << QChar('H'); + d << QLatin1String("Hello"); + d << QByteArray("Hello"); + d.noquote(); + d << QChar('H'); + d << QLatin1String("Hello"); + d << QByteArray("Hello"); + } + QCOMPARE(s_msg, QString::fromLatin1("'H' \"Hello\" \"Hello\" H Hello Hello")); +} + void tst_QDebug::stateSaver() const { MessageHandlerSetter mhs(myMessageHandler); @@ -231,6 +260,16 @@ void tst_QDebug::stateSaver() const d << 42; } QCOMPARE(s_msg, QString::fromLatin1("02a 42")); + + { + QDebug d = qDebug(); + { + QDebugStateSaver saver(d); + d.nospace().noquote() << QStringLiteral("Hello"); + } + d << QStringLiteral("World"); + } + QCOMPARE(s_msg, QString::fromLatin1("Hello \"World\"")); } void tst_QDebug::veryLongWarningMessage() const @@ -251,6 +290,23 @@ void tst_QDebug::veryLongWarningMessage() const QCOMPARE(QString::fromLatin1(s_function), function); } +void tst_QDebug::qDebugQChar() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << QChar('f'); + d.nospace().noquote() << QChar('o') << QChar('o'); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("'f' oo")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); + +} + void tst_QDebug::qDebugQStringRef() const { /* Use a basic string. */ @@ -286,10 +342,30 @@ void tst_QDebug::qDebugQStringRef() const void tst_QDebug::qDebugQLatin1String() const { MessageHandlerSetter mhs(myMessageHandler); - { qDebug() << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3); } - QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; + { + QDebug d = qDebug(); + d << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3); + d.nospace().noquote() << QLatin1String("baz"); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\" baz")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); +} + +void tst_QDebug::qDebugQByteArray() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << QByteArrayLiteral("foo") << QByteArrayLiteral("") << QByteArray("barbaz", 3); + d.nospace().noquote() << QByteArrayLiteral("baz"); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\"")); + QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\" baz")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); |