diff options
author | Samuel Rødal <samuel.rodal@nokia.com> | 2011-08-29 12:11:53 +0200 |
---|---|---|
committer | Samuel Rødal <samuel.rodal@nokia.com> | 2011-08-29 12:11:53 +0200 |
commit | d0c48efbae386dc88ea2313264e739715d9154b4 (patch) | |
tree | 97a30a0c58c8ecb8a9a58ae892f53c6e9efe03d7 /src/testlib | |
parent | e35a83b293e6b38f6060895262b5494d36515e6e (diff) | |
parent | d7305c10948f501450b6b3358d261217d13c6d6e (diff) |
Merge remote branch 'gerrit/master' into refactor
Conflicts:
src/gui/accessible/qaccessible.h
src/gui/kernel/qapplication.cpp
src/gui/kernel/qapplication.h
src/gui/kernel/qapplication_mac.mm
src/gui/kernel/qapplication_qws.cpp
src/gui/kernel/qapplication_s60.cpp
src/gui/kernel/qapplication_win.cpp
src/gui/kernel/qapplication_x11.cpp
src/gui/kernel/qdnd_x11.cpp
src/gui/kernel/qwidget.cpp
src/gui/widgets/qlabel.cpp
Change-Id: Ief9c75724d2cff89ed45f009bdee2ffc5e4395ba
Diffstat (limited to 'src/testlib')
26 files changed, 303 insertions, 735 deletions
diff --git a/src/testlib/qabstracttestlogger.cpp b/src/testlib/qabstracttestlogger.cpp index 735ad0122a..d71addb655 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" @@ -55,57 +54,38 @@ 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); } -bool QAbstractTestLogger::isTtyOutput() -{ - QTEST_ASSERT(QTest::stream); - -#if defined(Q_OS_WIN) || defined(Q_OS_INTEGRITY) - return true; -#else - static bool ttyoutput = isatty(fileno(QTest::stream)); - return ttyoutput; -#endif -} - - -void QAbstractTestLogger::startLogging() +void QAbstractTestLogger::startLogging(const char *filename) { - QTEST_ASSERT(!QTest::stream); + QTEST_ASSERT(!stream); - const char *out = QTestLog::outputFileName(); - if (!out) { - QTest::stream = stdout; + if (!filename) { + stream = stdout; return; } #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, out, "wt")) { + if (::fopen_s(&stream, filename, "wt")) { #else - QTest::stream = ::fopen(out, "wt"); - if (!QTest::stream) { + stream = ::fopen(filename, "wt"); + if (!stream) { #endif - printf("Unable to open file for logging: %s", out); + fprintf(stderr, "Unable to open file for logging: %s", filename); ::exit(1); } } 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 @@ -114,7 +94,7 @@ void QAbstractTestLogger::stopLogging() User::AfterHighRes(2*1000*1000); #endif } - QTest::stream = 0; + stream = 0; } namespace QTest diff --git a/src/testlib/qabstracttestlogger_p.h b/src/testlib/qabstracttestlogger_p.h index 847c14453a..e592249e71 100644 --- a/src/testlib/qabstracttestlogger_p.h +++ b/src/testlib/qabstracttestlogger_p.h @@ -54,6 +54,7 @@ // #include <qglobal.h> +#include <stdio.h> QT_BEGIN_NAMESPACE @@ -79,10 +80,10 @@ public: Info }; - QAbstractTestLogger() {} + QAbstractTestLogger() : stream(0) {} virtual ~QAbstractTestLogger() {} - virtual void startLogging(); + virtual void startLogging(const char *filename); virtual void stopLogging(); virtual void enterTestFunction(const char *function) = 0; @@ -97,8 +98,10 @@ public: virtual void registerRandomSeed(unsigned int seed) = 0; - static void outputString(const char *msg); - static bool isTtyOutput(); + void outputString(const char *msg); + +private: + FILE *stream; }; struct QTestCharBuffer diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index 5656ac60c5..44ec792400 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -71,164 +71,50 @@ QT_BEGIN_NAMESPACE namespace QTest { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - static CRITICAL_SECTION outputCriticalSection; - static HANDLE hConsole = INVALID_HANDLE_VALUE; - static WORD consoleAttributes = 0; - - static const char *qWinColoredMsg(int prefix, int color, const char *msg) - { - if (!hConsole) - return msg; - - WORD attr = consoleAttributes & ~(FOREGROUND_GREEN | FOREGROUND_BLUE - | FOREGROUND_RED | FOREGROUND_INTENSITY); - if (prefix) - attr |= FOREGROUND_INTENSITY; - if (color == 32) - attr |= FOREGROUND_GREEN; - if (color == 36) - attr |= FOREGROUND_BLUE | FOREGROUND_GREEN; - if (color == 31) - attr |= FOREGROUND_RED | FOREGROUND_INTENSITY; - if (color == 37) - attr |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; - if (color == 33) - attr |= FOREGROUND_RED | FOREGROUND_GREEN; - SetConsoleTextAttribute(hConsole, attr); - printf(msg); - SetConsoleTextAttribute(hConsole, consoleAttributes); - return ""; - } - -# define COLORED_MSG(prefix, color, msg) colored ? qWinColoredMsg(prefix, color, msg) : msg -#else -# define COLORED_MSG(prefix, color, msg) colored && QAbstractTestLogger::isTtyOutput() ? "\033["#prefix";"#color"m" msg "\033[0m" : msg #endif static const char *incidentType2String(QAbstractTestLogger::IncidentTypes type) { - static bool colored = (!qgetenv("QTEST_COLORED").isEmpty()); switch (type) { case QAbstractTestLogger::Pass: - return COLORED_MSG(0, 32, "PASS "); //green + return "PASS "; case QAbstractTestLogger::XFail: - return COLORED_MSG(1, 32, "XFAIL "); //light green + return "XFAIL "; case QAbstractTestLogger::Fail: - return COLORED_MSG(0, 31, "FAIL! "); //red + return "FAIL! "; case QAbstractTestLogger::XPass: - return COLORED_MSG(0, 31, "XPASS "); //red, too + return "XPASS "; } return "??????"; } static const char *benchmarkResult2String() { - static bool colored = (!qgetenv("QTEST_COLORED").isEmpty()); - return COLORED_MSG(0, 36, "RESULT "); // cyan + return "RESULT "; } static const char *messageType2String(QAbstractTestLogger::MessageTypes type) { -#ifdef Q_OS_WIN - static bool colored = (!qgetenv("QTEST_COLORED").isEmpty()); -#else - static bool colored = ::getenv("QTEST_COLORED"); -#endif switch (type) { case QAbstractTestLogger::Skip: - return COLORED_MSG(0, 37, "SKIP "); //white + return "SKIP "; case QAbstractTestLogger::Warn: - return COLORED_MSG(0, 33, "WARNING"); // yellow + return "WARNING"; case QAbstractTestLogger::QWarning: - return COLORED_MSG(1, 33, "QWARN "); + return "QWARN "; case QAbstractTestLogger::QDebug: - return COLORED_MSG(1, 33, "QDEBUG "); + return "QDEBUG "; case QAbstractTestLogger::QSystem: - return COLORED_MSG(1, 33, "QSYSTEM"); + return "QSYSTEM"; case QAbstractTestLogger::QFatal: - return COLORED_MSG(0, 31, "QFATAL "); // red + return "QFATAL "; case QAbstractTestLogger::Info: - return "INFO "; // no coloring + return "INFO "; } return "??????"; } - static void outputMessage(const char *str) - { -#if defined(Q_OS_WINCE) - QString strUtf16 = QString::fromLatin1(str); - const int maxOutputLength = 255; - do { - QString tmp = strUtf16.left(maxOutputLength); - OutputDebugString((wchar_t*)tmp.utf16()); - strUtf16.remove(0, maxOutputLength); - } while (!strUtf16.isEmpty()); - if (QTestLog::outputFileName()) -#elif defined(Q_OS_WIN) - EnterCriticalSection(&outputCriticalSection); - // OutputDebugString is not threadsafe - OutputDebugStringA(str); - LeaveCriticalSection(&outputCriticalSection); -#elif defined(Q_OS_SYMBIAN) - // RDebug::Print has a cap of 256 characters so break it up - TPtrC8 ptr(reinterpret_cast<const TUint8*>(str)); - _LIT(format, "[QTestLib] %S"); - const int maxBlockSize = 256 - ((const TDesC &)format).Length(); - HBufC* hbuffer = HBufC::New(maxBlockSize); - if(hbuffer) { - for (int i = 0; i < ptr.Length(); i += maxBlockSize) { - int size = Min(maxBlockSize, ptr.Length() - i); - hbuffer->Des().Copy(ptr.Mid(i, size)); - RDebug::Print(format, hbuffer); - } - delete hbuffer; - } - else { - // fast, no allocations, but truncates silently - RDebug::RawPrint(format); - TPtrC8 ptr(reinterpret_cast<const TUint8*>(str)); - RDebug::RawPrint(ptr); - RDebug::RawPrint(_L8("\n")); - } -#endif - QAbstractTestLogger::outputString(str); - } - - static void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0) - { - QTEST_ASSERT(type); - QTEST_ASSERT(msg); - - QTestCharBuffer buf; - - const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() - : "UnknownTestFunc"; - const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : ""; - const char *gtag = QTestResult::currentGlobalDataTag() - ? QTestResult::currentGlobalDataTag() - : ""; - const char *filler = (tag[0] && gtag[0]) ? ":" : ""; - if (file) { - QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n" -#ifdef Q_OS_WIN - "%s(%d) : failure location\n" -#else - " Loc: [%s(%d)]\n" -#endif - , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, - msg[0] ? " " : "", msg, file, line); - } else { - QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n", - type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, - msg[0] ? " " : "", msg); - } - // In colored mode, printf above stripped our nonprintable control characters. - // Put them back. - memcpy(buf.data(), type, strlen(type)); - outputMessage(buf.data()); - } - template <typename T> static int countSignificantDigits(T num) { @@ -313,74 +199,149 @@ namespace QTest { int size = result.count(); return size; } +} -// static void printBenchmarkResult(const char *bmtag, int value, int iterations) - static void printBenchmarkResult(const QBenchmarkResult &result) - { - const char *bmtag = QTest::benchmarkResult2String(); - - char buf1[1024]; - QTest::qt_snprintf( - buf1, sizeof(buf1), "%s: %s::%s", - bmtag, - QTestResult::currentTestObjectName(), - result.context.slotName.toAscii().data()); - - char bufTag[1024]; - bufTag[0] = 0; - QByteArray tag = result.context.tag.toAscii(); - if (tag.isEmpty() == false) { - QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); +void QPlainTestLogger::outputMessage(const char *str) +{ +#if defined(Q_OS_WINCE) + QString strUtf16 = QString::fromLatin1(str); + const int maxOutputLength = 255; + do { + QString tmp = strUtf16.left(maxOutputLength); + OutputDebugString((wchar_t*)tmp.utf16()); + strUtf16.remove(0, maxOutputLength); + } while (!strUtf16.isEmpty()); + if (QTestLog::outputFileName()) +#elif defined(Q_OS_WIN) + EnterCriticalSection(&QTest::outputCriticalSection); + // OutputDebugString is not threadsafe + OutputDebugStringA(str); + LeaveCriticalSection(&QTest::outputCriticalSection); +#elif defined(Q_OS_SYMBIAN) + // RDebug::Print has a cap of 256 characters so break it up + TPtrC8 ptr(reinterpret_cast<const TUint8*>(str)); + _LIT(format, "[QTestLib] %S"); + const int maxBlockSize = 256 - ((const TDesC &)format).Length(); + HBufC* hbuffer = HBufC::New(maxBlockSize); + if (hbuffer) { + for (int i = 0; i < ptr.Length(); i += maxBlockSize) { + int size = Min(maxBlockSize, ptr.Length() - i); + hbuffer->Des().Copy(ptr.Mid(i, size)); + RDebug::Print(format, hbuffer); } + delete hbuffer; + } + else { + // fast, no allocations, but truncates silently + RDebug::RawPrint(format); + TPtrC8 ptr(reinterpret_cast<const TUint8*>(str)); + RDebug::RawPrint(ptr); + RDebug::RawPrint(_L8("\n")); + } +#endif + outputString(str); +} +void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line) +{ + QTEST_ASSERT(type); + QTEST_ASSERT(msg); + + QTestCharBuffer buf; + + const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() + : "UnknownTestFunc"; + const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : ""; + const char *gtag = QTestResult::currentGlobalDataTag() + ? QTestResult::currentGlobalDataTag() + : ""; + const char *filler = (tag[0] && gtag[0]) ? ":" : ""; + if (file) { + QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n" +#ifdef Q_OS_WIN + "%s(%d) : failure location\n" +#else + " Loc: [%s(%d)]\n" +#endif + , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, + msg[0] ? " " : "", msg, file, line); + } else { + QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n", + type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, + msg[0] ? " " : "", msg); + } + // In colored mode, printf above stripped our nonprintable control characters. + // Put them back. + memcpy(buf.data(), type, strlen(type)); + outputMessage(buf.data()); +} - char fillFormat[8]; - int fillLength = 5; - QTest::qt_snprintf( - fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength); - char fill[1024]; - QTest::qt_snprintf(fill, sizeof(fill), fillFormat, ""); - - const char * unitText = QTest::benchmarkMetricUnit(result.metric); +//void QPlainTestLogger::printBenchmarkResult(const char *bmtag, int value, int iterations) +void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) +{ + const char *bmtag = QTest::benchmarkResult2String(); + + char buf1[1024]; + QTest::qt_snprintf( + buf1, sizeof(buf1), "%s: %s::%s", + bmtag, + QTestResult::currentTestObjectName(), + result.context.slotName.toAscii().data()); + + char bufTag[1024]; + bufTag[0] = 0; + QByteArray tag = result.context.tag.toAscii(); + if (tag.isEmpty() == false) { + QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); + } - qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); - char resultBuffer[100] = ""; - formatResult(resultBuffer, 100, valuePerIteration, countSignificantDigits(result.value)); - char buf2[1024]; - QTest::qt_snprintf( - buf2, sizeof(buf2), "%s %s", - resultBuffer, - unitText); + char fillFormat[8]; + int fillLength = 5; + QTest::qt_snprintf( + fillFormat, sizeof(fillFormat), ":\n%%%ds", fillLength); + char fill[1024]; + QTest::qt_snprintf(fill, sizeof(fill), fillFormat, ""); + + const char * unitText = QTest::benchmarkMetricUnit(result.metric); + + qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); + char resultBuffer[100] = ""; + QTest::formatResult(resultBuffer, 100, valuePerIteration, QTest::countSignificantDigits(result.value)); + + char buf2[1024]; + QTest::qt_snprintf( + buf2, sizeof(buf2), "%s %s", + resultBuffer, + unitText); + + char buf2_[1024]; + QByteArray iterationText = " per iteration"; + Q_ASSERT(result.iterations > 0); + QTest::qt_snprintf( + buf2_, + sizeof(buf2_), "%s", + iterationText.data()); + + char buf3[1024]; + Q_ASSERT(result.iterations > 0); + QTest::formatResult(resultBuffer, 100, result.value, QTest::countSignificantDigits(result.value)); + QTest::qt_snprintf( + buf3, sizeof(buf3), " (total: %s, iterations: %d)", + resultBuffer, + result.iterations); - char buf2_[1024]; - QByteArray iterationText = " per iteration"; - Q_ASSERT(result.iterations > 0); - QTest::qt_snprintf( - buf2_, - sizeof(buf2_), "%s", - iterationText.data()); + char buf[1024]; - char buf3[1024]; - Q_ASSERT(result.iterations > 0); - formatResult(resultBuffer, 100, result.value, countSignificantDigits(result.value)); + if (result.setByMacro) { QTest::qt_snprintf( - buf3, sizeof(buf3), " (total: %s, iterations: %d)", - resultBuffer, - result.iterations); - - char buf[1024]; - - if (result.setByMacro) { - QTest::qt_snprintf( - buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3); - } else { - QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2); - } - - memcpy(buf, bmtag, strlen(bmtag)); - outputMessage(buf); + buf, sizeof(buf), "%s%s%s%s%s%s\n", buf1, bufTag, fill, buf2, buf2_, buf3); + } else { + QTest::qt_snprintf(buf, sizeof(buf), "%s%s%s%s\n", buf1, bufTag, fill, buf2); } + + memcpy(buf, bmtag, strlen(bmtag)); + outputMessage(buf); } QPlainTestLogger::QPlainTestLogger() @@ -388,15 +349,6 @@ QPlainTestLogger::QPlainTestLogger() { #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) InitializeCriticalSection(&QTest::outputCriticalSection); - QTest::hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - if (QTest::hConsole != INVALID_HANDLE_VALUE) { - CONSOLE_SCREEN_BUFFER_INFO info; - if (GetConsoleScreenBufferInfo(QTest::hConsole, &info)) { - QTest::consoleAttributes = info.wAttributes; - } else { - QTest::hConsole = INVALID_HANDLE_VALUE; - } - } #endif } @@ -407,9 +359,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) { @@ -428,7 +380,7 @@ void QPlainTestLogger::startLogging() ", Qt %s\n", QTestResult::currentTestObjectName(), qVersion()); } } - QTest::outputMessage(buf); + outputMessage(buf); } void QPlainTestLogger::stopLogging() @@ -445,7 +397,7 @@ void QPlainTestLogger::stopLogging() QTestResult::passCount(), QTestResult::failCount(), QTestResult::skipCount(), QTestResult::currentTestObjectName()); } - QTest::outputMessage(buf); + outputMessage(buf); QAbstractTestLogger::stopLogging(); } @@ -454,7 +406,7 @@ void QPlainTestLogger::stopLogging() void QPlainTestLogger::enterTestFunction(const char * /*function*/) { if (QTestLog::verboseLevel() >= 1) - QTest::printMessage(QTest::messageType2String(Info), "entering"); + printMessage(QTest::messageType2String(Info), "entering"); } void QPlainTestLogger::leaveTestFunction() @@ -468,13 +420,13 @@ void QPlainTestLogger::addIncident(IncidentTypes type, const char *description, if (type == QAbstractTestLogger::Pass && QTestLog::verboseLevel() < 0) return; - QTest::printMessage(QTest::incidentType2String(type), description, file, line); + printMessage(QTest::incidentType2String(type), description, file, line); } void QPlainTestLogger::addBenchmarkResult(const QBenchmarkResult &result) { -// QTest::printBenchmarkResult(QTest::benchmarkResult2String(), value, iterations); - QTest::printBenchmarkResult(result); +// printBenchmarkResult(QTest::benchmarkResult2String(), value, iterations); + printBenchmarkResult(result); } void QPlainTestLogger::addMessage(MessageTypes type, const char *message, @@ -485,7 +437,7 @@ void QPlainTestLogger::addMessage(MessageTypes type, const char *message, && QTestLog::verboseLevel() < 0) return; - QTest::printMessage(QTest::messageType2String(type), message, file, line); + printMessage(QTest::messageType2String(type), message, file, line); } void QPlainTestLogger::registerRandomSeed(unsigned int seed) diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h index aa9df834eb..5fa33e6b51 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); @@ -79,6 +79,10 @@ public: private: unsigned int randomSeed; bool hasRandomSeed; + + void printMessage(const char *type, const char *msg, const char *file = 0, int line = 0); + void outputMessage(const char *str); + void printBenchmarkResult(const QBenchmarkResult &result); }; QT_END_NAMESPACE diff --git a/src/testlib/qtest_global.h b/src/testlib/qtest_global.h index 85b9d6e1c1..b7479a8102 100644 --- a/src/testlib/qtest_global.h +++ b/src/testlib/qtest_global.h @@ -50,9 +50,7 @@ QT_BEGIN_NAMESPACE QT_MODULE(Test) -#ifdef QTEST_EMBED -# define Q_TESTLIB_EXPORT -#elif !defined(QT_SHARED) && !(defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)) +#if !defined(QT_SHARED) && !(defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT)) # define Q_TESTLIB_EXPORT #else # ifdef QTESTLIB_MAKEDLL diff --git a/src/testlib/qtestbasicstreamer.cpp b/src/testlib/qtestbasicstreamer.cpp index 25e48ee4d5..d371b4d08e 100644 --- a/src/testlib/qtestbasicstreamer.cpp +++ b/src/testlib/qtestbasicstreamer.cpp @@ -43,7 +43,6 @@ #include "qtestlogger_p.h" #include "qtestelement.h" #include "qtestelementattribute.h" -#include "QtTest/private/qtestlog_p.h" #include "qtestassert.h" #include <stdio.h> @@ -55,14 +54,10 @@ QT_BEGIN_NAMESPACE -namespace QTest -{ - static FILE *stream = 0; -} - -QTestBasicStreamer::QTestBasicStreamer() - :testLogger(0) +QTestBasicStreamer::QTestBasicStreamer(QTestLogger *logger) + :testLogger(logger) { + QTEST_ASSERT(testLogger); } QTestBasicStreamer::~QTestBasicStreamer() @@ -158,59 +153,10 @@ void QTestBasicStreamer::outputElementAttributes(const QTestElement* element, QT void QTestBasicStreamer::outputString(const char *msg) const { - QTEST_ASSERT(QTest::stream); - - ::fputs(msg, QTest::stream); - ::fflush(QTest::stream); -} - -void QTestBasicStreamer::startStreaming() -{ - QTEST_ASSERT(!QTest::stream); - - const char *out = QTestLog::outputFileName(); - if (!out) { - QTest::stream = stdout; - return; - } - #if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, out, "wt")) { - #else - QTest::stream = ::fopen(out, "wt"); - if (!QTest::stream) { - #endif - printf("Unable to open file for logging: %s", out); - ::exit(1); - } -} - -bool QTestBasicStreamer::isTtyOutput() -{ - QTEST_ASSERT(QTest::stream); - -#if defined(Q_OS_WIN) || defined(Q_OS_INTEGRITY) - return true; -#else - static bool ttyoutput = isatty(fileno(QTest::stream)); - return ttyoutput; -#endif -} - -void QTestBasicStreamer::stopStreaming() -{ - QTEST_ASSERT(QTest::stream); - if (QTest::stream != stdout) - fclose(QTest::stream); - - QTest::stream = 0; -} - -void QTestBasicStreamer::setLogger(const QTestLogger *tstLogger) -{ - testLogger = tstLogger; + testLogger->outputString(msg); } -const QTestLogger *QTestBasicStreamer::logger() const +QTestLogger *QTestBasicStreamer::logger() const { return testLogger; } diff --git a/src/testlib/qtestbasicstreamer.h b/src/testlib/qtestbasicstreamer.h index 867c1f1d7d..04bc40638f 100644 --- a/src/testlib/qtestbasicstreamer.h +++ b/src/testlib/qtestbasicstreamer.h @@ -58,18 +58,14 @@ struct QTestCharBuffer; class QTestBasicStreamer { public: - QTestBasicStreamer(); + QTestBasicStreamer(QTestLogger *logger); virtual ~QTestBasicStreamer(); virtual void output(QTestElement *element) const; void outputString(const char *msg) const; - bool isTtyOutput(); - void startStreaming(); - void stopStreaming(); - void setLogger(const QTestLogger *tstLogger); - const QTestLogger *logger() const; + QTestLogger *logger() const; protected: virtual void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; @@ -81,7 +77,7 @@ class QTestBasicStreamer virtual void outputElementAttributes(const QTestElement *element, QTestElementAttribute *attribute) const; private: - const QTestLogger *testLogger; + QTestLogger *testLogger; }; QT_END_NAMESPACE diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 27a897c263..b6aaa34756 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -972,12 +972,6 @@ void seedRandom() } } -int qTestRandomSeed() -{ - Q_ASSERT(QTest::seedSet); - return QTest::seed; -} - template<typename T> void swap(T * array, int pos, int otherPos) { @@ -1018,12 +1012,12 @@ Q_TESTLIB_EXPORT bool printAvailableFunctions = false; Q_TESTLIB_EXPORT QStringList testFunctions; Q_TESTLIB_EXPORT QStringList testTags; -static void qPrintTestSlots() +static void qPrintTestSlots(FILE *stream) { for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) { QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i); if (isValidSlot(sl)) - printf("%s\n", sl.signature()); + fprintf(stream, "%s\n", sl.signature()); } } @@ -1032,7 +1026,7 @@ static int qToInt(char *str) char *pEnd; int l = (int)strtol(str, &pEnd, 10); if (*pEnd != 0) { - printf("Invalid numeric parameter: '%s'\n", str); + fprintf(stderr, "Invalid numeric parameter: '%s'\n", str); exit(1); } return l; @@ -1100,7 +1094,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) if (qml) { QTest::printAvailableFunctions = true; } else { - qPrintTestSlots(); + qPrintTestSlots(stdout); exit(0); } } else if(strcmp(argv[i], "-xunitxml") == 0){ @@ -1109,8 +1103,8 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTestLog::setLogMode(QTestLog::XML); } else if (strcmp(argv[i], "-lightxml") == 0) { QTestLog::setLogMode(QTestLog::LightXML); - }else if(strcmp(argv[i], "-flush") == 0){ - QTestLog::setFlushMode(QTestLog::FLushOn); + } else if (strcmp(argv[i], "-flush") == 0){ + QTestLog::setFlushMode(QTestLog::FlushOn); } else if (strcmp(argv[i], "-silent") == 0) { QTestLog::setVerboseLevel(-1); } else if (strcmp(argv[i], "-v1") == 0) { @@ -1121,35 +1115,35 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QSignalDumper::startDump(); } else if (strcmp(argv[i], "-o") == 0) { if (i + 1 >= argc) { - printf("-o needs an extra parameter specifying the filename\n"); + fprintf(stderr, "-o needs an extra parameter specifying the filename\n"); exit(1); } else { QTestLog::redirectOutput(argv[++i]); } } else if (strcmp(argv[i], "-eventdelay") == 0) { if (i + 1 >= argc) { - printf("-eventdelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-eventdelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::eventDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-keydelay") == 0) { if (i + 1 >= argc) { - printf("-keydelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-keydelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::keyDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-mousedelay") == 0) { if (i + 1 >= argc) { - printf("-mousedelay needs an extra parameter to indicate the delay(ms)\n"); + fprintf(stderr, "-mousedelay needs an extra parameter to indicate the delay(ms)\n"); exit(1); } else { QTest::mouseDelay = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-maxwarnings") == 0) { if (i + 1 >= argc) { - printf("-maxwarnings needs an extra parameter with the amount of warnings\n"); + fprintf(stderr, "-maxwarnings needs an extra parameter with the amount of warnings\n"); exit(1); } else { QTestLog::setMaxWarnings(qToInt(argv[++i])); @@ -1166,10 +1160,10 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) if (QFileInfo(QDir::currentPath()).isWritable()) { QBenchmarkGlobalData::current->setMode(QBenchmarkGlobalData::CallgrindParentProcess); } else { - printf("WARNING: Current directory not writable. Using the walltime measurer.\n"); + fprintf(stderr, "WARNING: Current directory not writable. Using the walltime measurer.\n"); } else { - printf("WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " + fprintf(stderr, "WARNING: Valgrind not found or too old. Make sure it is installed and in your path. " "Using the walltime measurer.\n"); } } else if (strcmp(argv[i], "-callgrindchild") == 0) { // "private" option @@ -1194,28 +1188,28 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTest::seed = longSeed; } if (!argumentOk) { - printf("-seed needs an extra positive integer parameter to specify the seed\n"); + fprintf(stderr, "-seed needs an extra positive integer parameter to specify the seed\n"); exit(1); } else { QTest::seedSet = true; } } else if (strcmp(argv[i], "-minimumvalue") == 0) { if (i + 1 >= argc) { - printf("-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); + fprintf(stderr, "-minimumvalue needs an extra parameter to indicate the minimum time(ms)\n"); exit(1); } else { QBenchmarkGlobalData::current->walltimeMinimum = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-iterations") == 0) { if (i + 1 >= argc) { - printf("-iterations needs an extra parameter to indicate the number of iterations\n"); + fprintf(stderr, "-iterations needs an extra parameter to indicate the number of iterations\n"); exit(1); } else { QBenchmarkGlobalData::current->iterationCount = qToInt(argv[++i]); } } else if (strcmp(argv[i], "-median") == 0) { if (i + 1 >= argc) { - printf("-median needs an extra parameter to indicate the number of median iterations\n"); + fprintf(stderr, "-median needs an extra parameter to indicate the number of median iterations\n"); exit(1); } else { QBenchmarkGlobalData::current->medianIterationCount = qToInt(argv[++i]); @@ -1223,30 +1217,28 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) } else if (strcmp(argv[i], "-vb") == 0) { QBenchmarkGlobalData::current->verboseOutput = true; - } else if (strcmp(argv[i], "-chart") == 0) { - fprintf(stderr, "Warning: `-chart' option is not available\n"); } else if (strcmp(argv[i], "-qws") == 0) { // do nothing } else if (strcmp(argv[i], "-graphicssystem") == 0) { // do nothing if (i + 1 >= argc) { - printf("-graphicssystem needs an extra parameter specifying the graphics system\n"); + fprintf(stderr, "-graphicssystem needs an extra parameter specifying the graphics system\n"); exit(1); } else { ++i; } } else if (argv[i][0] == '-') { - printf("Unknown option: '%s'\n\n%s", argv[i], testOptions); + fprintf(stderr, "Unknown option: '%s'\n\n%s", argv[i], testOptions); if (qml) { - printf ("\nqmltest related options:\n" - " -import : Specify an import directory.\n" - " -input : Specify the root directory for test cases.\n" - " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" - ); + fprintf(stderr, "\nqmltest related options:\n" + " -import : Specify an import directory.\n" + " -input : Specify the root directory for test cases.\n" + " -qtquick1 : Run with QtQuick 1 rather than QtQuick 2.\n" + ); } - printf("\n" - " -help : This help\n"); + fprintf(stderr, "\n" + " -help : This help\n"); exit(1); } else if (qml) { // We can't check the availability of test functions until @@ -1275,9 +1267,9 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QString::fromLatin1(argv[i] + colon + 1); } } else { - if (!QTest::testFuncs) { - QTest::testFuncs = new QTest::TestFunction[512]; - } + if (!QTest::testFuncs) { + QTest::testFuncs = new QTest::TestFunction[512]; + } int colon = -1; char buf[512], *data=0; @@ -1295,19 +1287,19 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml) QTest::qt_snprintf(buf + off, qMin(512 - off, 3), "()"); // append "()" int idx = QTest::currentTestObject->metaObject()->indexOfMethod(buf); if (idx < 0 || !isValidSlot(QTest::currentTestObject->metaObject()->method(idx))) { - printf("Unknown testfunction: '%s'\n", buf); - printf("Available testfunctions:\n"); - qPrintTestSlots(); + fprintf(stderr, "Unknown testfunction: '%s'\n", buf); + fprintf(stderr, "Available testfunctions:\n"); + qPrintTestSlots(stderr); exit(1); } testFuncs[testFuncCount].set(idx, data); - testFuncCount++; - QTEST_ASSERT(QTest::testFuncCount < 512); + testFuncCount++; + QTEST_ASSERT(QTest::testFuncCount < 512); } } if (QTest::seedSet && !QTest::randomOrder) { - printf("-seed requires -random\n"); + fprintf(stderr, "-seed requires -random\n"); exit(1); } } @@ -1466,8 +1458,8 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0) if (!*data) data = 0; else { - printf("Unknown testdata for function %s: '%s'\n", slotName, data); - printf("Function has no testdata.\n"); + fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); + fprintf(stderr, "Function has no testdata.\n"); return false; } } @@ -1492,10 +1484,10 @@ static bool qInvokeTestMethod(const char *slotName, const char *data=0) } if (data && !foundFunction) { - printf("Unknown testdata for function %s: '%s'\n", slotName, data); - printf("Available testdata:\n"); + fprintf(stderr, "Unknown testdata for function %s: '%s'\n", slotName, data); + fprintf(stderr, "Available testdata:\n"); for(int i = 0; i < table.dataCount(); ++i) - printf("%s\n", table.testData(i)->dataTag()); + fprintf(stderr, "%s\n", table.testData(i)->dataTag()); return false; } @@ -1899,10 +1891,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) } #endif -#if defined(QTEST_NOEXITCODE) - return 0; -#else - #ifdef QTESTLIB_USE_VALGRIND if (QBenchmarkGlobalData::current->mode() == QBenchmarkGlobalData::CallgrindParentProcess) return callgrindChildExitCode; @@ -1910,8 +1898,6 @@ int QTest::qExec(QObject *testObject, int argc, char **argv) // make sure our exit code is never going above 127 // since that could wrap and indicate 0 test fails return qMin(QTestResult::failCount(), 127); - -#endif } /*! @@ -1959,7 +1945,7 @@ bool QTest::qVerify(bool statement, const char *statementStr, const char *descri void QTest::qSkip(const char *message, QTest::SkipMode mode, const char *file, int line) { - QTestResult::addSkip(message, mode, file, line); + QTestResult::addSkip(message, file, line); if (mode == QTest::SkipAll) QTestResult::setSkipCurrentTest(true); } @@ -2195,7 +2181,7 @@ Q_TESTLIB_EXPORT bool QTest::qCompare<double>(double const &t1, double const &t2 toString(t1), toString(t2), actual, expected, file, line); } -#define COMPARE_IMPL2(TYPE, FORMAT) \ +#define TO_STRING_IMPL(TYPE, FORMAT) \ template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ { \ char *msg = new char[128]; \ @@ -2203,23 +2189,23 @@ template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \ return msg; \ } -COMPARE_IMPL2(short, %hd) -COMPARE_IMPL2(ushort, %hu) -COMPARE_IMPL2(int, %d) -COMPARE_IMPL2(uint, %u) -COMPARE_IMPL2(long, %ld) -COMPARE_IMPL2(ulong, %lu) +TO_STRING_IMPL(short, %hd) +TO_STRING_IMPL(ushort, %hu) +TO_STRING_IMPL(int, %d) +TO_STRING_IMPL(uint, %u) +TO_STRING_IMPL(long, %ld) +TO_STRING_IMPL(ulong, %lu) #if defined(Q_OS_WIN) -COMPARE_IMPL2(qint64, %I64d) -COMPARE_IMPL2(quint64, %I64u) +TO_STRING_IMPL(qint64, %I64d) +TO_STRING_IMPL(quint64, %I64u) #else -COMPARE_IMPL2(qint64, %lld) -COMPARE_IMPL2(quint64, %llu) +TO_STRING_IMPL(qint64, %lld) +TO_STRING_IMPL(quint64, %llu) #endif -COMPARE_IMPL2(bool, %d) -COMPARE_IMPL2(char, %c) -COMPARE_IMPL2(float, %g) -COMPARE_IMPL2(double, %lg) +TO_STRING_IMPL(bool, %d) +TO_STRING_IMPL(char, %c) +TO_STRING_IMPL(float, %g) +TO_STRING_IMPL(double, %lg) /*! \internal */ diff --git a/src/testlib/qtestdata.h b/src/testlib/qtestdata.h index b964ec1dcc..02ee03ff7d 100644 --- a/src/testlib/qtestdata.h +++ b/src/testlib/qtestdata.h @@ -69,7 +69,7 @@ public: private: friend class QTestTable; - QTestData(const char *tag = 0, QTestTable *parent = 0); + QTestData(const char *tag, QTestTable *parent); Q_DISABLE_COPY(QTestData) diff --git a/src/testlib/qtestfilelogger.cpp b/src/testlib/qtestfilelogger.cpp deleted file mode 100644 index 2349ca3cd5..0000000000 --- a/src/testlib/qtestfilelogger.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtestfilelogger.h" -#include "qtestassert.h" -#include "QtTest/private/qtestlog_p.h" -#include "QtTest/private/qtestresult_p.h" - -#include <QtCore/qdir.h> - -#include <stdlib.h> -#include <stdio.h> - -QT_BEGIN_NAMESPACE - -namespace QTest -{ - static FILE *stream = 0; -} - -QTestFileLogger::QTestFileLogger() -{ -} - -QTestFileLogger::~QTestFileLogger() -{ - if(QTest::stream) - fclose(QTest::stream); - - QTest::stream = 0; -} - -void QTestFileLogger::init() -{ - char filename[100]; - int index = 0; -#if defined(Q_OS_SYMBIAN) - QByteArray ba(QDir::toNativeSeparators(QString(QDir::homePath()+QDir::separator())).toUtf8()); - index = ba.length(); - QTest::qt_snprintf(filename, sizeof(filename), "%s%s.log", - ba.constData(), QTestResult::currentTestObjectName()); -#else - QTest::qt_snprintf(filename, sizeof(filename), "%s.log", - QTestResult::currentTestObjectName()); -#endif - - // Keep filenames simple - for (uint i = index; i < sizeof(filename) && filename[i]; ++i) { - char& c = filename[i]; - if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') - || (c >= '0' && c <= '9') || c == '-' || c == '.')) { - c = '_'; - } - } - -#if defined(_MSC_VER) && _MSC_VER >= 1400 && !defined(Q_OS_WINCE) - if (::fopen_s(&QTest::stream, filename, "wt")) { -#else - QTest::stream = ::fopen(filename, "wt"); - if (!QTest::stream) { -#endif - printf("Unable to open file for simple logging: %s", filename); - ::exit(1); - } -} - -void QTestFileLogger::flush(const char *msg) -{ - QTEST_ASSERT(QTest::stream); - - ::fputs(msg, QTest::stream); - ::fflush(QTest::stream); -} - -QT_END_NAMESPACE - diff --git a/src/testlib/qtestfilelogger.h b/src/testlib/qtestfilelogger.h deleted file mode 100644 index 9b10a49539..0000000000 --- a/src/testlib/qtestfilelogger.h +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTESTFILELOGGER_H -#define QTESTFILELOGGER_H - -#include <QtCore/qglobal.h> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Test) - -class QTestFileLogger -{ - public: - QTestFileLogger(); - ~QTestFileLogger(); - - void init(); - void flush(const char *msg); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QTESTFILELOGGER_H diff --git a/src/testlib/qtestlightxmlstreamer.cpp b/src/testlib/qtestlightxmlstreamer.cpp index 5a8f96d068..8ac4e03d77 100644 --- a/src/testlib/qtestlightxmlstreamer.cpp +++ b/src/testlib/qtestlightxmlstreamer.cpp @@ -52,8 +52,8 @@ QT_BEGIN_NAMESPACE -QTestLightXmlStreamer::QTestLightXmlStreamer() - :QTestBasicStreamer() +QTestLightXmlStreamer::QTestLightXmlStreamer(QTestLogger *logger) + : QTestBasicStreamer(logger) { } diff --git a/src/testlib/qtestlightxmlstreamer.h b/src/testlib/qtestlightxmlstreamer.h index c8ac68146d..b3076c1623 100644 --- a/src/testlib/qtestlightxmlstreamer.h +++ b/src/testlib/qtestlightxmlstreamer.h @@ -56,7 +56,7 @@ class QTestElementAttribute; class QTestLightXmlStreamer: public QTestBasicStreamer { public: - QTestLightXmlStreamer(); + QTestLightXmlStreamer(QTestLogger *logger); ~QTestLightXmlStreamer(); void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; diff --git a/src/testlib/qtestlog.cpp b/src/testlib/qtestlog.cpp index 8a2d5596f3..36b69e1155 100644 --- a/src/testlib/qtestlog.cpp +++ b/src/testlib/qtestlog.cpp @@ -45,6 +45,7 @@ #include "QtTest/private/qtestresult_p.h" #include "QtTest/private/qabstracttestlogger_p.h" #include "QtTest/private/qplaintestlogger_p.h" +#include "QtTest/private/qtestlogger_p.h" #include "QtTest/private/qxmltestlogger_p.h" #include <QtCore/qatomic.h> #include <QtCore/qbytearray.h> @@ -53,9 +54,6 @@ #include <string.h> #include <limits.h> - -#include "qtestlogger_p.h" - QT_BEGIN_NAMESPACE namespace QTest { @@ -168,37 +166,29 @@ namespace QTest { } } -void initLogger() -{ - switch (QTest::logMode) { + void initLogger() + { + switch (QTest::logMode) { case QTestLog::Plain: QTest::testLogger = new QPlainTestLogger; break; - case QTestLog::XML:{ - if(QTest::flushMode == QTestLog::FLushOn) + case QTestLog::XML: + if (QTest::flushMode == QTestLog::FlushOn) QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete); else QTest::testLogger = new QTestLogger(QTestLogger::TLF_XML); break; - }case QTestLog::LightXML:{ - if(QTest::flushMode == QTestLog::FLushOn) + case QTestLog::LightXML: + if (QTest::flushMode == QTestLog::FlushOn) QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light); else QTest::testLogger = new QTestLogger(QTestLogger::TLF_LightXml); break; - }case QTestLog::XunitXML: + case QTestLog::XunitXML: QTest::testLogger = new QTestLogger(QTestLogger::TLF_XunitXml); } -} - -} - -QTestLog::QTestLog() -{ -} + } -QTestLog::~QTestLog() -{ } void QTestLog::enterTestFunction(const char* function) @@ -253,6 +243,7 @@ void QTestLog::addPass(const char *msg) void QTestLog::addFail(const char *msg, const char *file, int line) { QTEST_ASSERT(QTest::testLogger); + QTEST_ASSERT(msg); QTest::testLogger->addIncident(QAbstractTestLogger::Fail, msg, file, line); } @@ -275,8 +266,7 @@ void QTestLog::addXPass(const char *msg, const char *file, int line) QTest::testLogger->addIncident(QAbstractTestLogger::XPass, msg, file, line); } -void QTestLog::addSkip(const char *msg, QTest::SkipMode /*mode*/, - const char *file, int line) +void QTestLog::addSkip(const char *msg, const char *file, int line) { QTEST_ASSERT(QTest::testLogger); QTEST_ASSERT(msg); @@ -296,7 +286,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 +294,7 @@ void QTestLog::startLogging() { QTEST_ASSERT(!QTest::testLogger); QTest::initLogger(); - QTest::testLogger->startLogging(); + QTest::testLogger->startLogging(QTest::outFile); QTest::oldMessageHandler = qInstallMsgHandler(QTest::messageHandler); } @@ -356,6 +346,8 @@ int QTestLog::verboseLevel() void QTestLog::addIgnoreMessage(QtMsgType type, const char *msg) { + QTEST_ASSERT(msg); + QTest::IgnoreResultList *item = new QTest::IgnoreResultList(type, msg); QTest::IgnoreResultList *list = QTest::ignoreResultList; diff --git a/src/testlib/qtestlog_p.h b/src/testlib/qtestlog_p.h index 20c731fee6..006b3ac12f 100644 --- a/src/testlib/qtestlog_p.h +++ b/src/testlib/qtestlog_p.h @@ -63,7 +63,7 @@ class Q_TESTLIB_EXPORT QTestLog { public: enum LogMode { Plain = 0, XML, LightXML, XunitXML }; - enum FlushMode { NoFlush = 0, FLushOn }; + enum FlushMode { NoFlush = 0, FlushOn }; static void enterTestFunction(const char* function); static void leaveTestFunction(); @@ -72,8 +72,7 @@ public: static void addFail(const char *msg, const char *file, int line); static void addXFail(const char *msg, const char *file, int line); static void addXPass(const char *msg, const char *file, int line); - static void addSkip(const char *msg, QTest::SkipMode mode, - const char *file, int line); + static void addSkip(const char *msg, const char *file, int line); static void addBenchmarkResult(const QBenchmarkResult &result); static void addIgnoreMessage(QtMsgType type, const char *msg); static int unhandledIgnoreMessages(); diff --git a/src/testlib/qtestlogger.cpp b/src/testlib/qtestlogger.cpp index 2c81a4bec7..d53a968719 100644 --- a/src/testlib/qtestlogger.cpp +++ b/src/testlib/qtestlogger.cpp @@ -44,7 +44,6 @@ #include "qtestxunitstreamer.h" #include "qtestxmlstreamer.h" #include "qtestlightxmlstreamer.h" -#include "qtestfilelogger.h" #include "QtTest/qtestcase.h" #include "QtTest/private/qtestresult_p.h" @@ -55,15 +54,16 @@ QT_BEGIN_NAMESPACE QTestLogger::QTestLogger(int fm) - :listOfTestcases(0), currentLogElement(0), errorLogElement(0), - logFormatter(0), format( (TestLoggerFormat)fm ), filelogger(new QTestFileLogger), - testCounter(0), passCounter(0), - failureCounter(0), errorCounter(0), - warningCounter(0), skipCounter(0), - systemCounter(0), qdebugCounter(0), - qwarnCounter(0), qfatalCounter(0), - infoCounter(0), randomSeed_(0), - hasRandomSeed_(false) + : listOfTestcases(0) + , currentLogElement(0) + , errorLogElement(0) + , logFormatter(0) + , format( (TestLoggerFormat)fm ) + , testCounter(0) + , failureCounter(0) + , errorCounter(0) + , randomSeed_(0) + , hasRandomSeed_(false) { } @@ -75,31 +75,25 @@ QTestLogger::~QTestLogger() delete listOfTestcases; delete logFormatter; - delete filelogger; } -void QTestLogger::startLogging() +void QTestLogger::startLogging(const char *filename) { + QAbstractTestLogger::startLogging(filename); + switch(format){ - case TLF_LightXml:{ - logFormatter = new QTestLightXmlStreamer; - filelogger->init(); + case TLF_LightXml: + logFormatter = new QTestLightXmlStreamer(this); break; - }case TLF_XML:{ - logFormatter = new QTestXmlStreamer; - filelogger->init(); + case TLF_XML: + logFormatter = new QTestXmlStreamer(this); break; - }case TLF_XunitXml:{ - logFormatter = new QTestXunitStreamer; + case TLF_XunitXml: + logFormatter = new QTestXunitStreamer(this); delete errorLogElement; errorLogElement = new QTestElement(QTest::LET_SystemError); - filelogger->init(); break; } - } - - logFormatter->setLogger(this); - logFormatter->startStreaming(); } void QTestLogger::stopLogging() @@ -161,15 +155,11 @@ void QTestLogger::stopLogging() logFormatter->output(iterator); } - logFormatter->stopStreaming(); + QAbstractTestLogger::stopLogging(); } void QTestLogger::enterTestFunction(const char *function) { - char buf[1024]; - QTest::qt_snprintf(buf, sizeof(buf), "Entered test-function: %s\n", function); - filelogger->flush(buf); - currentLogElement = new QTestElement(QTest::LET_TestCase); currentLogElement->addAttribute(QTest::AI_Name, function); currentLogElement->addToList(&listOfTestcases); @@ -193,11 +183,9 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, typeBuf = "xpass"; break; case QAbstractTestLogger::Pass: - ++passCounter; typeBuf = "pass"; break; case QAbstractTestLogger::XFail: - ++passCounter; typeBuf = "xfail"; break; case QAbstractTestLogger::Fail: @@ -271,7 +259,6 @@ void QTestLogger::addIncident(IncidentTypes type, const char *description, void QTestLogger::addBenchmarkResult(const QBenchmarkResult &result) { QTestElement *benchmarkElement = new QTestElement(QTest::LET_Benchmark); -// printf("element %i", benchmarkElement->elementType()); benchmarkElement->addAttribute( QTest::AI_Metric, @@ -313,31 +300,24 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char switch (type) { case QAbstractTestLogger::Warn: - ++warningCounter; typeBuf = "warn"; break; case QAbstractTestLogger::QSystem: - ++systemCounter; typeBuf = "system"; break; case QAbstractTestLogger::QDebug: - ++qdebugCounter; typeBuf = "qdebug"; break; case QAbstractTestLogger::QWarning: - ++qwarnCounter; typeBuf = "qwarn"; break; case QAbstractTestLogger::QFatal: - ++qfatalCounter; typeBuf = "qfatal"; break; case QAbstractTestLogger::Skip: - ++skipCounter; typeBuf = "skip"; break; case QAbstractTestLogger::Info: - ++infoCounter; typeBuf = "info"; break; default: @@ -369,66 +349,6 @@ void QTestLogger::addMessage(MessageTypes type, const char *message, const char } } -void QTestLogger::setLogFormat(TestLoggerFormat fm) -{ - format = fm; -} - -QTestLogger::TestLoggerFormat QTestLogger::logFormat() -{ - return format; -} - -int QTestLogger::passCount() const -{ - return passCounter; -} - -int QTestLogger::failureCount() const -{ - return failureCounter; -} - -int QTestLogger::errorCount() const -{ - return errorCounter; -} - -int QTestLogger::warningCount() const -{ - return warningCounter; -} - -int QTestLogger::skipCount() const -{ - return skipCounter; -} - -int QTestLogger::systemCount() const -{ - return systemCounter; -} - -int QTestLogger::qdebugCount() const -{ - return qdebugCounter; -} - -int QTestLogger::qwarnCount() const -{ - return qwarnCounter; -} - -int QTestLogger::qfatalCount() const -{ - return qfatalCounter; -} - -int QTestLogger::infoCount() const -{ - return infoCounter; -} - void QTestLogger::registerRandomSeed(unsigned int seed) { randomSeed_ = seed; diff --git a/src/testlib/qtestlogger_p.h b/src/testlib/qtestlogger_p.h index 1d27b63e21..eef5b92d2b 100644 --- a/src/testlib/qtestlogger_p.h +++ b/src/testlib/qtestlogger_p.h @@ -59,7 +59,6 @@ QT_BEGIN_NAMESPACE class QTestBasicStreamer; class QTestElement; -class QTestFileLogger; class QTestLogger : public QAbstractTestLogger { @@ -74,7 +73,7 @@ class QTestLogger : public QAbstractTestLogger TLF_XunitXml = 2 }; - void startLogging(); + void startLogging(const char *filename); void stopLogging(); void enterTestFunction(const char *function); @@ -88,19 +87,6 @@ class QTestLogger : public QAbstractTestLogger void addMessage(MessageTypes type, const char *message, const char *file = 0, int line = 0); - void setLogFormat(TestLoggerFormat fm); - TestLoggerFormat logFormat(); - - int passCount() const; - int failureCount() const; - int errorCount() const; - int warningCount() const; - int skipCount() const; - int systemCount() const; - int qdebugCount() const; - int qwarnCount() const; - int qfatalCount() const; - int infoCount() const; void registerRandomSeed(unsigned int seed); unsigned int randomSeed() const; bool hasRandomSeed() const; @@ -111,19 +97,10 @@ class QTestLogger : public QAbstractTestLogger QTestElement *errorLogElement; QTestBasicStreamer *logFormatter; TestLoggerFormat format; - QTestFileLogger *filelogger; int testCounter; - int passCounter; int failureCounter; int errorCounter; - int warningCounter; - int skipCounter; - int systemCounter; - int qdebugCounter; - int qwarnCounter; - int qfatalCounter; - int infoCounter; unsigned int randomSeed_; bool hasRandomSeed_; }; diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index 7fb0208bb3..4a6764b115 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -285,12 +285,11 @@ void QTestResult::addFailure(const char *message, const char *file, int line) ++QTest::fails; } -void QTestResult::addSkip(const char *message, QTest::SkipMode mode, - const char *file, int line) +void QTestResult::addSkip(const char *message, const char *file, int line) { clearExpectFail(); - QTestLog::addSkip(message, mode, file, line); + QTestLog::addSkip(message, file, line); ++QTest::skips; } diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h index a3e265ffac..1ce81854b5 100644 --- a/src/testlib/qtestresult_p.h +++ b/src/testlib/qtestresult_p.h @@ -93,8 +93,7 @@ public: static void setCurrentTestFunction(const char *func); static void setCurrentTestLocation(TestLocation loc); static void setCurrentTestObject(const char *name); - static void addSkip(const char *message, QTest::SkipMode mode, - const char *file, int line); + static void addSkip(const char *message, const char *file, int line); static bool expectFail(const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line); static bool verify(bool statement, const char *statementStr, const char *extraInfo, diff --git a/src/testlib/qtestxmlstreamer.cpp b/src/testlib/qtestxmlstreamer.cpp index 6a7f9ae8f7..7a4115262b 100644 --- a/src/testlib/qtestxmlstreamer.cpp +++ b/src/testlib/qtestxmlstreamer.cpp @@ -53,8 +53,8 @@ QT_BEGIN_NAMESPACE -QTestXmlStreamer::QTestXmlStreamer() - :QTestBasicStreamer() +QTestXmlStreamer::QTestXmlStreamer(QTestLogger *logger) + : QTestBasicStreamer(logger) { } diff --git a/src/testlib/qtestxmlstreamer.h b/src/testlib/qtestxmlstreamer.h index 46318a9d18..96e8246779 100644 --- a/src/testlib/qtestxmlstreamer.h +++ b/src/testlib/qtestxmlstreamer.h @@ -40,7 +40,7 @@ ****************************************************************************/ #ifndef QTESTXMLSTREAMER_H -#define QTESXMLSTREAMER_H +#define QTESTXMLSTREAMER_H #include <QtTest/qtestbasicstreamer.h> @@ -56,7 +56,7 @@ class QTestElementAttribute; class QTestXmlStreamer: public QTestBasicStreamer { public: - QTestXmlStreamer(); + QTestXmlStreamer(QTestLogger *logger); ~QTestXmlStreamer(); void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; diff --git a/src/testlib/qtestxunitstreamer.cpp b/src/testlib/qtestxunitstreamer.cpp index c4b3192c5a..fb9699eef1 100644 --- a/src/testlib/qtestxunitstreamer.cpp +++ b/src/testlib/qtestxunitstreamer.cpp @@ -48,8 +48,8 @@ QT_BEGIN_NAMESPACE -QTestXunitStreamer::QTestXunitStreamer() - :QTestBasicStreamer() +QTestXunitStreamer::QTestXunitStreamer(QTestLogger *logger) + : QTestBasicStreamer(logger) {} QTestXunitStreamer::~QTestXunitStreamer() diff --git a/src/testlib/qtestxunitstreamer.h b/src/testlib/qtestxunitstreamer.h index f99e231f8d..4d1cb2734a 100644 --- a/src/testlib/qtestxunitstreamer.h +++ b/src/testlib/qtestxunitstreamer.h @@ -55,7 +55,7 @@ class QTestLogger; class QTestXunitStreamer: public QTestBasicStreamer { public: - QTestXunitStreamer(); + QTestXunitStreamer(QTestLogger *logger); ~QTestXunitStreamer(); void formatStart(const QTestElement *element, QTestCharBuffer *formatted) const; diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp index 2c8ba6c0a7..15b5c84fd5 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 dc2f4b8aa1..ad510d5ce0 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); diff --git a/src/testlib/testlib.pro b/src/testlib/testlib.pro index a017d33b4a..a65510f567 100644 --- a/src/testlib/testlib.pro +++ b/src/testlib/testlib.pro @@ -27,7 +27,6 @@ HEADERS = qbenchmark.h \ qtestelement.h \ qtestevent.h \ qtesteventloop.h \ - qtestfilelogger.h \ qtest_global.h \ qtest_gui.h \ qtest.h \ @@ -60,8 +59,7 @@ SOURCES = qtestcase.cpp \ qtestxunitstreamer.cpp \ qtestxmlstreamer.cpp \ qtestlightxmlstreamer.cpp \ - qtestlogger.cpp \ - qtestfilelogger.cpp + qtestlogger.cpp DEFINES *= QT_NO_CAST_TO_ASCII \ QT_NO_CAST_FROM_ASCII \ QTESTLIB_MAKEDLL \ |