diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2012-04-02 13:48:06 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-20 08:37:06 +0200 |
commit | d9a1c2dff85635076ecaee3507427d750846c85c (patch) | |
tree | 5c60ddcb7815b6ea1789c84c7972ddda2e0a4e85 /tests/auto/corelib/io | |
parent | a3f90fd44f822ae9d77c9d115934e18a9c7466fd (diff) |
Logging: Change arguments of message handler to avoid conversions
Introduce a new QtMessageHandler that takes QString instead of
char *: This avoids converting to local8bit , only to convert it back
to utf16 for Windows.
The old QMessageHandler is kept for a transition period, but will
be removed before Qt 5.0.
Also fix qEmergencyOut (that is called in OOM situations) to not rely
on the default message handler.
Change-Id: Iee0ce5838f97175c98788b847964273dd22d4a37
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r-- | tests/auto/corelib/io/qdebug/tst_qdebug.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 12f7e28a1d..035c781e4a 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -74,12 +74,12 @@ void tst_QDebug::assignment() const } static QtMsgType s_msgType; -static QByteArray s_msg; +static QString s_msg; static QByteArray s_file; static int s_line; static QByteArray s_function; -static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const char *msg) +static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { s_msg = msg; s_msgType = type; @@ -94,7 +94,7 @@ static void myMessageHandler(QtMsgType type, const QMessageLogContext &context, class MessageHandlerSetter { public: - MessageHandlerSetter(QMessageHandler newMessageHandler) + MessageHandlerSetter(QtMessageHandler newMessageHandler) : oldMessageHandler(qInstallMessageHandler(newMessageHandler)) { } @@ -104,7 +104,7 @@ public: } private: - QMessageHandler oldMessageHandler; + QtMessageHandler oldMessageHandler; }; /*! \internal @@ -116,7 +116,7 @@ void tst_QDebug::warningWithoutDebug() const { qWarning() << "A qWarning() message"; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtWarningMsg); - QCOMPARE(QString::fromLatin1(s_msg.data()), QString::fromLatin1("A qWarning() message ")); + QCOMPARE(s_msg, QString::fromLatin1("A qWarning() message ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -131,7 +131,7 @@ void tst_QDebug::criticalWithoutDebug() const { qCritical() << "A qCritical() message"; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtCriticalMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("A qCritical() message ")); + QCOMPARE(s_msg, QString::fromLatin1("A qCritical() message ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -143,7 +143,7 @@ void tst_QDebug::debugWithBool() const { qDebug() << false << true; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("false true ")); + QCOMPARE(s_msg, QString::fromLatin1("false true ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -161,7 +161,7 @@ void tst_QDebug::veryLongWarningMessage() const } QString file = __FILE__; int line = __LINE__ - 2; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtWarningMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("Test output:\n")+test+QString::fromLatin1("\nend")); + QCOMPARE(s_msg, QString::fromLatin1("Test output:\n")+test+QString::fromLatin1("\nend")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -178,7 +178,7 @@ void tst_QDebug::qDebugQStringRef() const { qDebug() << inRef; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("\"input\" ")); + QCOMPARE(s_msg, QString::fromLatin1("\"input\" ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -192,7 +192,7 @@ void tst_QDebug::qDebugQStringRef() const { qDebug() << inRef; } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("\"\" ")); + QCOMPARE(s_msg, QString::fromLatin1("\"\" ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -205,7 +205,7 @@ void tst_QDebug::qDebugQLatin1String() const { qDebug() << QLatin1String("foo") << QLatin1String("") << QLatin1String("barbaz", 3); } QString file = __FILE__; int line = __LINE__ - 1; QString function = Q_FUNC_INFO; QCOMPARE(s_msgType, QtDebugMsg); - QCOMPARE(QString::fromLatin1(s_msg), QString::fromLatin1("\"foo\" \"\" \"bar\" ")); + QCOMPARE(s_msg, QString::fromLatin1("\"foo\" \"\" \"bar\" ")); QCOMPARE(QString::fromLatin1(s_file), file); QCOMPARE(s_line, line); QCOMPARE(QString::fromLatin1(s_function), function); @@ -214,11 +214,11 @@ void tst_QDebug::qDebugQLatin1String() const void tst_QDebug::defaultMessagehandler() const { MessageHandlerSetter mhs(0); - QMessageHandler defaultMessageHandler1 = qInstallMessageHandler(0); - QMessageHandler defaultMessageHandler2 = qInstallMessageHandler(myMessageHandler); + QtMessageHandler defaultMessageHandler1 = qInstallMessageHandler((QtMessageHandler)0); + QtMessageHandler defaultMessageHandler2 = qInstallMessageHandler(myMessageHandler); bool same = (*defaultMessageHandler1 == *defaultMessageHandler2); QVERIFY(same); - QMessageHandler messageHandler = qInstallMessageHandler(0); + QtMessageHandler messageHandler = qInstallMessageHandler((QtMessageHandler)0); same = (*messageHandler == *myMessageHandler); QVERIFY(same); } |