From e668837b9c3faa5c0fc29c0bac71247eb9975746 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 22 Jul 2014 11:58:55 +0200 Subject: QDebugStateSaver: Fix trailing space issues ~QDebug() removes any trailing space if autoInsertSpaces() is true. However, if one uses QDebugStateSaver the global autoInsertSpaces might be false, but a space was added by a custom operator<<. Explicitly check for this in QDebugStateSaverPrivate::restoreState. Remove any trailing space if the local state asks for adding trailing spaces, but the original one doesn't. Add a trailing space if the local state doesn't ask for one, but the global state does. Change-Id: I243b5c76d5ed2c1ec4820da35ab6e254da1551d9 Reviewed-by: David Faure --- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/auto/corelib/io/qdebug') diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 2143a8874c..767fde7f6c 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -252,6 +252,17 @@ void tst_QDebug::debugNoQuotes() const void tst_QDebug::stateSaver() const { MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d << 42; + { + QDebugStateSaver saver(d); + d << 43; + } + d << 44; + } + QCOMPARE(s_msg, QString::fromLatin1("42 43 44")); + { QDebug d = qDebug(); { @@ -271,6 +282,18 @@ void tst_QDebug::stateSaver() const d << QStringLiteral("World"); } QCOMPARE(s_msg, QString::fromLatin1("Hello \"World\"")); + + { + QDebug d = qDebug(); + d.noquote().nospace() << QStringLiteral("Hello") << hex << 42; + { + QDebugStateSaver saver(d); + d.resetFormat(); + d << QStringLiteral("World") << 42; + } + d << QStringLiteral("!") << 42; + } + QCOMPARE(s_msg, QString::fromLatin1("Hello2a\"World\" 42!2a")); } void tst_QDebug::veryLongWarningMessage() const -- cgit v1.2.3