From 87aceebf42af5bbc7ea96ac1a60a7ba030ad3e3f Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 20 Jun 2014 14:44:48 +0200 Subject: QDebug: Add resetFormat() Similar to QTextStream::reset(), this resets the stream format to the defaults. Its primary use is inside custom operator<< implementations, where you'd want to have a fixed format regardless of the current stream state. Change-Id: I421d76c61f164579bb90cf4195cc5376e2dcf0f3 Reviewed-by: Oswald Buddenhagen --- tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tests/auto/corelib/io/qdebug/tst_qdebug.cpp') diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 9b761bc63d..2143a8874c 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -64,6 +64,7 @@ private slots: void qDebugQLatin1String() const; void qDebugQByteArray() const; void textStreamModifiers() const; + void resetFormat() const; void defaultMessagehandler() const; void threadSafety() const; }; @@ -383,6 +384,22 @@ void tst_QDebug::textStreamModifiers() const QCOMPARE(QString::fromLatin1(s_function), function); } +void tst_QDebug::resetFormat() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + d.nospace().noquote() << hex << int(0xf); + d.resetFormat() << int(0xf) << QStringLiteral("foo"); + } + QString file = __FILE__; int line = __LINE__ - 4; QString function = Q_FUNC_INFO; + QCOMPARE(s_msgType, QtDebugMsg); + QCOMPARE(s_msg, QString::fromLatin1("f15 \"foo\"")); + QCOMPARE(QString::fromLatin1(s_file), file); + QCOMPARE(s_line, line); + QCOMPARE(QString::fromLatin1(s_function), function); +} + void tst_QDebug::defaultMessagehandler() const { MessageHandlerSetter mhs(0); // set 0, should set default handler -- cgit v1.2.3