summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2012-04-13 13:37:56 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-24 17:12:46 +0200
commitc0d249019b098890fb8e5e9e144c2dd8029a670c (patch)
treec65c071920b8e8ebb3b1ad65ae1f5df7851ddcf3 /tests/auto/corelib/global/qlogging/tst_qlogging.cpp
parente92e5fda44602d7595aca329a3133ecb9991a6dd (diff)
Allow qDebug output to be configured by qSetMessagePattern()
Add qSetMessagePattern() to configure the default message pattern. This one can still be overwritten by setting the QT_MESSAGE_PATTERN environment variable. Without this method, there's actually no way to change the default output programatically. Since QT_MESSAGE_PATTERN is evaluated when the first message arrives, setting it via e.g. qputenv might have no effect/be too late. Change-Id: I115e0c30606f128fdbf5c169a951ffa2a6a48517 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/global/qlogging/tst_qlogging.cpp')
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp38
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index 1d6aa89035..5474b9aa3b 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -630,13 +630,16 @@ void tst_qmessagehandler::cleanupFuncinfo()
void tst_qmessagehandler::qMessagePattern()
{
QProcess process;
+ const QString appExe = m_appDir + "/app";
+ //
+ // test QT_MESSAGE_PATTERN
+ //
QStringList environment = QProcess::systemEnvironment();
// %{file} is tricky because of shadow builds
environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{appname} %{line} %{function} %{message}\"");
process.setEnvironment(environment);
- QString appExe = m_appDir + "/app";
process.start(appExe);
QVERIFY2(process.waitForStarted(), qPrintable(
QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
@@ -649,9 +652,10 @@ void tst_qmessagehandler::qMessagePattern()
QVERIFY(output.contains("debug 45 T::T static constructor"));
// we can't be sure whether the QT_MESSAGE_PATTERN is already destructed
QVERIFY(output.contains("static destructor"));
- QVERIFY(output.contains("debug tst_qlogging 54 main qDebug"));
- QVERIFY(output.contains("warning tst_qlogging 55 main qWarning"));
- QVERIFY(output.contains("critical tst_qlogging 56 main qCritical"));
+ QVERIFY(output.contains("debug tst_qlogging 56 main qDebug"));
+ QVERIFY(output.contains("warning tst_qlogging 57 main qWarning"));
+ QVERIFY(output.contains("critical tst_qlogging 58 main qCritical"));
+ QVERIFY(output.contains("debug tst_qlogging 62 main qDebug2"));
environment = QProcess::systemEnvironment();
environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{message}\"");
@@ -668,6 +672,32 @@ void tst_qmessagehandler::qMessagePattern()
QVERIFY(output.contains("QT_MESSAGE_PATTERN: Unknown placeholder %{unknown}"));
QVERIFY(output.contains("PREFIX: qDebug"));
+
+ //
+ // test qSetMessagePattern
+ //
+ QMutableListIterator<QString> iter(environment);
+ while (iter.hasNext()) {
+ if (iter.next().startsWith("QT_MESSAGE_PATTERN"))
+ iter.remove();
+ }
+ process.setEnvironment(environment);
+
+ process.start(appExe);
+ QVERIFY2(process.waitForStarted(), qPrintable(
+ QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
+ process.waitForFinished();
+
+ output = process.readAllStandardError();
+ //qDebug() << output;
+ QByteArray expected = "static constructor\n"
+ "[debug] qDebug\n"
+ "[warning] qWarning\n"
+ "[critical] qCritical\n";
+#ifdef Q_OS_WIN
+ output.replace("\r\n", "\n");
+#endif
+ QCOMPARE(QString::fromLatin1(output), QString::fromLatin1(expected));
}
QTEST_MAIN(tst_qmessagehandler)