QMessageLogger: test that QT_FATAL_{WARNINGS,CRITICALS} work
Pick-to: 6.8 Change-Id: I8a7f56d67043bae14e10fffdfbaf3060486edbf1 Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> (cherry picked from commit 1dcc5a6dd28606c7959d0626f74f8c05e112b1fc) Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
e70fcdfe5b
commit
00ef067a2d
@ -10,7 +10,7 @@ endif()
|
||||
qt_internal_add_executable(qlogging_helper
|
||||
NO_INSTALL
|
||||
OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||
SOURCES qlogging_helper.cpp
|
||||
SOURCES qlogging_helper.cpp ../../../../shared/disablecoredumps.cpp
|
||||
DEFINES QT_MESSAGELOGCONTEXT
|
||||
LIBRARIES Qt::Core)
|
||||
|
||||
|
@ -11,6 +11,11 @@
|
||||
#include <QtTest/QTest>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QScopeGuard>
|
||||
|
||||
#ifdef Q_OS_UNIX
|
||||
# include <signal.h>
|
||||
#endif
|
||||
|
||||
class tst_qmessagehandler : public QObject
|
||||
{
|
||||
@ -38,6 +43,9 @@ private slots:
|
||||
void qMessagePattern();
|
||||
void setMessagePattern();
|
||||
|
||||
void fatalWarnings_data();
|
||||
void fatalWarnings();
|
||||
|
||||
void formatLogMessage_data();
|
||||
void formatLogMessage();
|
||||
|
||||
@ -917,6 +925,78 @@ void tst_qmessagehandler::setMessagePattern()
|
||||
#endif // QT_CONFIG(process)
|
||||
}
|
||||
|
||||
void tst_qmessagehandler::fatalWarnings_data()
|
||||
{
|
||||
QTest::addColumn<QString>("varName");
|
||||
QTest::addColumn<QString>("varValue");
|
||||
QTest::addColumn<QByteArray>("presentOutput");
|
||||
QTest::addColumn<QByteArray>("absentOutput");
|
||||
|
||||
QTest::newRow("QT_FATAL_WARNINGS=1")
|
||||
<< "QT_FATAL_WARNINGS" << "1"
|
||||
<< QByteArray("[warning] qWarning") << QByteArray("[critical] qCritical");
|
||||
QTest::newRow("QT_FATAL_CRITICALS=1")
|
||||
<< "QT_FATAL_CRITICALS" << "1"
|
||||
<< QByteArray("[critical] qCritical") << QByteArray("[warning] qDebug with category");
|
||||
QTest::newRow("QT_FATAL_WARNINGS=2")
|
||||
<< "QT_FATAL_WARNINGS" << "2"
|
||||
<< QByteArray("[warning] qDebug with category") << QByteArray("[debug] qDebug2");
|
||||
|
||||
#if !QT_CONFIG(process)
|
||||
QSKIP("This test requires QProcess support");
|
||||
#endif
|
||||
}
|
||||
|
||||
void tst_qmessagehandler::fatalWarnings()
|
||||
{
|
||||
#ifdef Q_OS_ANDROID
|
||||
QSKIP("This test is disabled on Android");
|
||||
#endif
|
||||
#if QT_CONFIG(process)
|
||||
QFETCH(QString, varName);
|
||||
QFETCH(QString, varValue);
|
||||
QFETCH(QByteArray, presentOutput);
|
||||
QFETCH(QByteArray, absentOutput);
|
||||
|
||||
QProcess process;
|
||||
const QString appExe(backtraceHelperPath());
|
||||
|
||||
//
|
||||
// test QT_FATAL_WARNINGS / QT_FATAL_CRITICALS
|
||||
//
|
||||
QProcessEnvironment environment = m_baseEnvironment;
|
||||
environment.insert(varName, varValue);
|
||||
process.setProcessEnvironment(environment);
|
||||
|
||||
process.start(appExe, {}, QIODevice::Text | QIODevice::ReadWrite);
|
||||
QVERIFY2(process.waitForStarted(), qPrintable(
|
||||
QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
|
||||
process.waitForFinished();
|
||||
|
||||
QCOMPARE(process.exitStatus(), QProcess::CrashExit);
|
||||
# ifdef Q_OS_UNIX
|
||||
QCOMPARE(process.exitCode(), SIGABRT);
|
||||
# elif defined(Q_CC_MSVC)
|
||||
// __fastfail produces STATUS_STACK_BUFFER_OVERRUN
|
||||
QCOMPARE(process.exitCode(), int(0xc0000409));
|
||||
# else
|
||||
// RaiseFastFail produces STATUS_FAIL_FAST_EXCEPTION
|
||||
QCOMPARE(process.exitCode(), int(0xc0000602));
|
||||
# endif
|
||||
|
||||
QList<QByteArray> lines = process.readAllStandardError().split('\n');
|
||||
auto outputOnError = qScopeGuard([&lines] {
|
||||
qDebug("Output was:\n");
|
||||
for (const QByteArray &line : lines)
|
||||
qDebug() << line;
|
||||
});
|
||||
|
||||
QVERIFY2(lines.contains(presentOutput), presentOutput);
|
||||
QVERIFY2(!lines.contains(absentOutput), absentOutput);
|
||||
outputOnError.dismiss();
|
||||
#endif // QT_CONFIG(process)
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QtMsgType)
|
||||
|
||||
void tst_qmessagehandler::formatLogMessage_data()
|
||||
|
Loading…
x
Reference in New Issue
Block a user