Remove circular dependency in testlib logging code
authorJason McDonald <jason.mcdonald@nokia.com>
Wed, 24 Aug 2011 07:14:21 +0000 (17:14 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 29 Aug 2011 01:40:27 +0000 (03:40 +0200)
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 <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
src/testlib/qabstracttestlogger.cpp
src/testlib/qabstracttestlogger_p.h
src/testlib/qplaintestlogger.cpp
src/testlib/qplaintestlogger_p.h
src/testlib/qtestlog.cpp
src/testlib/qtestlogger.cpp
src/testlib/qtestlogger_p.h
src/testlib/qxmltestlogger.cpp
src/testlib/qxmltestlogger_p.h

index 735ad01..1e95471 100644 (file)
@@ -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);
     }
 }
index 847c144..20b212a 100644 (file)
@@ -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;
index 5656ac6..daa4405 100644 (file)
@@ -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) {
index aa9df83..1784e3b 100644 (file)
@@ -63,7 +63,7 @@ public:
     QPlainTestLogger();
     ~QPlainTestLogger();
 
-    void startLogging();
+    void startLogging(const char *filename);
     void stopLogging();
 
     void enterTestFunction(const char *function);
index 8a2d559..a438da2 100644 (file)
@@ -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);
 }
 
index 316e89f..9cf4320 100644 (file)
@@ -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:{
index 1d27b63..5793537 100644 (file)
@@ -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);
index 2c8ba6c..15b5c84 100644 (file)
@@ -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) {
index dc2f4b8..ad510d5 100644 (file)
@@ -66,7 +66,7 @@ public:
     QXmlTestLogger(XmlMode mode = Complete);
     ~QXmlTestLogger();
 
-    void startLogging();
+    void startLogging(const char *filename);
     void stopLogging();
 
     void enterTestFunction(const char *function);