Fix qlogging test for release configuration

The helper process 'app' wasn't built in release configuration.

Also improved finding the helper executable to utilize
QFINDTESTDATA and print out a proper errors if it could not be
found or started.

Note that adding ".exe" to process name in Windows is unnecessary
as QProcess already does that for you, so removed the ifdeffing.

Task-number: QTBUG-24330
Change-Id: Ibe75e0ecd24181ab623d0a60f17ecaf92052b0dd
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
bb10
Miikka Heikkinen 2012-02-16 14:20:57 +02:00 committed by Qt by Nokia
parent 3b5f6f7647
commit 7c081ba942
2 changed files with 26 additions and 12 deletions

View File

@ -3,7 +3,9 @@ TEMPLATE = app
TARGET = app
QT = core
CONFIG -= debug_and_release app_bundle
CONFIG += debug console
DESTDIR = ./
CONFIG -= app_bundle
CONFIG += console
SOURCES += main.cpp

View File

@ -47,6 +47,9 @@
class tst_qmessagehandler : public QObject
{
Q_OBJECT
public slots:
void initTestCase();
private slots:
void cleanup();
@ -59,6 +62,9 @@ private slots:
void cleanupFuncinfo();
void qMessagePattern();
private:
QString m_appDir;
};
static QtMsgType s_type;
@ -85,6 +91,13 @@ void customMsgHandler(QtMsgType type, const char *msg)
s_message = QString::fromLocal8Bit(msg);
}
void tst_qmessagehandler::initTestCase()
{
m_appDir = QFINDTESTDATA("app");
QVERIFY2(!m_appDir.isEmpty(), qPrintable(
QString::fromLatin1("Couldn't find helper app dir starting from %1.").arg(QDir::currentPath())));
}
void tst_qmessagehandler::cleanup()
{
qInstallMsgHandler(0);
@ -622,11 +635,11 @@ void tst_qmessagehandler::qMessagePattern()
// %{file} is tricky because of shadow builds
environment.prepend("QT_MESSAGE_PATTERN=\"%{type} %{appname} %{line} %{function} %{message}\"");
process.setEnvironment(environment);
#ifdef Q_OS_WIN
process.start("app/app.exe");
#else
process.start("app/app");
#endif
QString appExe = m_appDir + "/app";
process.start(appExe);
QVERIFY2(process.waitForStarted(), qPrintable(
QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
process.waitForFinished();
QByteArray output = process.readAllStandardError();
@ -643,11 +656,10 @@ void tst_qmessagehandler::qMessagePattern()
environment = QProcess::systemEnvironment();
environment.prepend("QT_MESSAGE_PATTERN=\"PREFIX: %{unknown} %{message}\"");
process.setEnvironment(environment);
#ifdef Q_OS_WIN
process.start("app/app.exe");
#else
process.start("app/app");
#endif
process.start(appExe);
QVERIFY2(process.waitForStarted(), qPrintable(
QString::fromLatin1("Could not start %1: %2").arg(appExe, process.errorString())));
process.waitForFinished();
output = process.readAllStandardError();