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 <qt_sanity_bot@ovi.com>
Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
This commit is contained in:
Jason McDonald 2011-08-24 17:14:21 +10:00 committed by Qt by Nokia
parent 14c2d4700c
commit 865c27460e
9 changed files with 17 additions and 19 deletions

View 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);
}
}

View 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;

View 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) {

View File

@ -63,7 +63,7 @@ public:
QPlainTestLogger();
~QPlainTestLogger();
void startLogging();
void startLogging(const char *filename);
void stopLogging();
void enterTestFunction(const char *function);

View 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);
}

View 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:{

View 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);

View 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) {

View 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);