summaryrefslogtreecommitdiffstats
path: root/src/testlib/qabstracttestlogger.cpp
diff options
context:
space:
mode:
authorJason McDonald <jason.mcdonald@nokia.com>2011-08-25 18:20:19 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-29 03:45:35 +0200
commite8e9b62f725f2229ae9e6d0218bbcbf7d54425ee (patch)
treebb79546be6e68ed1a53a05cae1d1e6ceb317f719 /src/testlib/qabstracttestlogger.cpp
parentdc7b2b8d9ca1d394d8338ce1c1f51eafac187908 (diff)
Enable multiple instances of QAbstractTestLogger.
Previously QAbstractTestLogger used a global variable for the file pointer to which it was writing test output. This effectively meant that only one instance of this or its derived classes could exist at any time. This commit moves the file pointer inside the class, so that multiple loggers can exist at the same time. This means that the outputString() method can no longer be static, which in turn means that several functions used by QPlainTestLogger need to move from the QTest namespace into the class, and also that QTestBasicStreamer must hold a non-const pointer to its associated logger instead of a const pointer. Task-number: QTBUG-20615 Change-Id: If941f1f9399cf20fb93e3e87f3390bceeca1cbfc Reviewed-on: http://codereview.qt.nokia.com/3576 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Rohan McGovern <rohan.mcgovern@nokia.com>
Diffstat (limited to 'src/testlib/qabstracttestlogger.cpp')
-rw-r--r--src/testlib/qabstracttestlogger.cpp29
1 files changed, 12 insertions, 17 deletions
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp
index 25193c9aed..a5651317e7 100644
--- a/src/testlib/qabstracttestlogger.cpp
+++ b/src/testlib/qabstracttestlogger.cpp
@@ -54,32 +54,27 @@
QT_BEGIN_NAMESPACE
-namespace QTest
-{
- static FILE *stream = 0;
-}
-
void QAbstractTestLogger::outputString(const char *msg)
{
- QTEST_ASSERT(QTest::stream);
+ QTEST_ASSERT(stream);
- ::fputs(msg, QTest::stream);
- ::fflush(QTest::stream);
+ ::fputs(msg, stream);
+ ::fflush(stream);
}
void QAbstractTestLogger::startLogging(const char *filename)
{
- QTEST_ASSERT(!QTest::stream);
+ QTEST_ASSERT(!stream);
if (!filename) {
- QTest::stream = stdout;
+ stream = stdout;
return;
}
#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE)
- if (::fopen_s(&QTest::stream, filename, "wt")) {
+ if (::fopen_s(&stream, filename, "wt")) {
#else
- QTest::stream = ::fopen(filename, "wt");
- if (!QTest::stream) {
+ stream = ::fopen(filename, "wt");
+ if (!stream) {
#endif
printf("Unable to open file for logging: %s", filename);
::exit(1);
@@ -88,9 +83,9 @@ void QAbstractTestLogger::startLogging(const char *filename)
void QAbstractTestLogger::stopLogging()
{
- QTEST_ASSERT(QTest::stream);
- if (QTest::stream != stdout) {
- fclose(QTest::stream);
+ QTEST_ASSERT(stream);
+ if (stream != stdout) {
+ fclose(stream);
} else {
#ifdef Q_OS_SYMBIAN
// Convenience sleep for Symbian and TRK. Without this sleep depending on the timing the
@@ -99,7 +94,7 @@ void QAbstractTestLogger::stopLogging()
User::AfterHighRes(2*1000*1000);
#endif
}
- QTest::stream = 0;
+ stream = 0;
}
namespace QTest