From: Jason McDonald Date: Wed, 24 Aug 2011 07:14:21 +0000 (+1000) Subject: Remove circular dependency in testlib logging code X-Git-Tag: qt-v5.0.0-alpha1~3758 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=865c27460e9779e7e4cafea84db843c3c5b26765;p=profile%2Fivi%2Fqtbase.git Remove circular dependency in testlib logging code Pass the output file name from the QTestLog to the test logger when commencing logging rather than having the logger call back into the QTestLog. Change-Id: Id484635f9fcfca08a66c92f3442887e9473b6f9b Reviewed-on: http://codereview.qt.nokia.com/3454 Reviewed-by: Qt Sanity Bot Reviewed-by: Rohan McGovern --- diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index 735ad01..1e95471 100644 --- a/src/testlib/qabstracttestlogger.cpp +++ b/src/testlib/qabstracttestlogger.cpp @@ -40,7 +40,6 @@ ****************************************************************************/ #include "QtTest/private/qabstracttestlogger_p.h" -#include "QtTest/private/qtestlog_p.h" #include "QtTest/qtestassert.h" #include "QtCore/qbytearray.h" @@ -81,22 +80,21 @@ bool QAbstractTestLogger::isTtyOutput() } -void QAbstractTestLogger::startLogging() +void QAbstractTestLogger::startLogging(const char *filename) { QTEST_ASSERT(!QTest::stream); - const char *out = QTestLog::outputFileName(); - if (!out) { + if (!filename) { QTest::stream = stdout; return; } #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, out, "wt")) { + if (::fopen_s(&QTest::stream, filename, "wt")) { #else - QTest::stream = ::fopen(out, "wt"); + QTest::stream = ::fopen(filename, "wt"); if (!QTest::stream) { #endif - printf("Unable to open file for logging: %s", out); + printf("Unable to open file for logging: %s", filename); ::exit(1); } } diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h index 847c144..20b212a 100644 --- a/src/testlib/qabstracttestlogger_p.h +++ b/src/testlib/qabstracttestlogger_p.h @@ -82,7 +82,7 @@ public: QAbstractTestLogger() {} virtual ~QAbstractTestLogger() {} - virtual void startLogging(); + virtual void startLogging(const char *filename); virtual void stopLogging(); virtual void enterTestFunction(const char *function) = 0; diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index 5656ac6..daa4405 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -407,9 +407,9 @@ QPlainTestLogger::~QPlainTestLogger() #endif } -void QPlainTestLogger::startLogging() +void QPlainTestLogger::startLogging(const char *filename) { - QAbstractTestLogger::startLogging(); + QAbstractTestLogger::startLogging(filename); char buf[1024]; if (QTestLog::verboseLevel() < 0) { diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h index aa9df83..1784e3b 100644 --- a/src/testlib/qplaintestlogger_p.h +++ b/src/testlib/qplaintestlogger_p.h @@ -63,7 +63,7 @@ public: QPlainTestLogger(); ~QPlainTestLogger(); - void startLogging(); + void startLogging(const char *filename); void stopLogging(); void enterTestFunction(const char *function); diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 8a2d559..a438da2 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -296,7 +296,7 @@ void QTestLog::startLogging(unsigned int randomSeed) QTEST_ASSERT(!QTest::testLogger); QTest::initLogger(); QTest::testLogger->registerRandomSeed(randomSeed); - QTest::testLogger->startLogging(); + QTest::testLogger->startLogging(QTest::outFile); QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler); } @@ -304,7 +304,7 @@ void QTestLog::startLogging() { QTEST_ASSERT(!QTest::testLogger); QTest::initLogger(); - QTest::testLogger->startLogging(); + QTest::testLogger->startLogging(QTest::outFile); QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler); } diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 316e89f..9cf4320 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -78,9 +78,9 @@ QTestLogger::~QTestLogger() delete filelogger; } -void QTestLogger::startLogging() +void QTestLogger::startLogging(const char *filename) { - QAbstractTestLogger::startLogging(); + QAbstractTestLogger::startLogging(filename); switch(format){ case TLF_LightXml:{ diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index 1d27b63..5793537 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -74,7 +74,7 @@ class QTestLogger : public QAbstractTestLogger TLF_XunitXml = 2 }; - void startLogging(); + void startLogging(const char *filename); void stopLogging(); void enterTestFunction(const char *function); diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp index 2c8ba6c..15b5c84 100644 --- a/src/testlib/qxmltestlogger.cpp +++ b/src/testlib/qxmltestlogger.cpp @@ -102,9 +102,9 @@ QXmlTestLogger::~QXmlTestLogger() { } -void QXmlTestLogger::startLogging() +void QXmlTestLogger::startLogging(const char *filename) { - QAbstractTestLogger::startLogging(); + QAbstractTestLogger::startLogging(filename); QTestCharBuffer buf; if (xmlmode == QXmlTestLogger::Complete) { diff --git a/src/testlib/qxmltestlogger_p.h b/src/testlib/qxmltestlogger_p.h index dc2f4b8..ad510d5 100644 --- a/src/testlib/qxmltestlogger_p.h +++ b/src/testlib/qxmltestlogger_p.h @@ -66,7 +66,7 @@ public: QXmlTestLogger(XmlMode mode = Complete); ~QXmlTestLogger(); - void startLogging(); + void startLogging(const char *filename); void stopLogging(); void enterTestFunction(const char *function);