Fix qlogging test for release configuration
authorMiikka Heikkinen <miikka.heikkinen@digia.com>
Thu, 16 Feb 2012 12:20:57 +0000 (14:20 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 17 Feb 2012 04:26:58 +0000 (05:26 +0100)
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>
tests/auto/corelib/global/qlogging/app/app.pro
tests/auto/corelib/global/qlogging/tst_qlogging.cpp

index a167cc4..1088d08 100644 (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
index 11949cf..aaec46f 100644 (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();