diff options
Diffstat (limited to 'src/testlib/qplaintestlogger.cpp')
-rw-r--r-- | src/testlib/qplaintestlogger.cpp | 78 |
1 files changed, 55 insertions, 23 deletions
diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index b6b60ae..d07c8ef 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2009 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. @@ -21,9 +20,10 @@ ** 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. +** 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. ** ** If you have questions regarding the use of this file, please contact ** Nokia at qt-info@nokia.com. @@ -54,6 +54,10 @@ #include "windows.h" #endif +#if defined(Q_OS_SYMBIAN) +#include <e32debug.h> +#endif + #ifdef Q_OS_WINCE #include <QtCore/QString> #endif @@ -125,7 +129,11 @@ namespace QTest { 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 @@ -148,17 +156,39 @@ namespace QTest { static void outputMessage(const char *str) { #if defined(Q_OS_WINCE) - int length = strlen(str); - for (int pos = 0; pos < length; pos +=255) { - QString uniText = QString::fromLatin1(str + pos, 255); - OutputDebugStringW((const LPCWSTR) uniText.utf16()); - } + 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); + } + } + 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); } @@ -168,7 +198,7 @@ namespace QTest { QTEST_ASSERT(type); QTEST_ASSERT(msg); - char buf[1024]; + QTestCharBuffer buf; const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() : "UnknownTestFunc"; @@ -178,7 +208,7 @@ namespace QTest { : ""; const char *filler = (tag[0] && gtag[0]) ? ":" : ""; if (file) { - QTest::qt_snprintf(buf, sizeof(buf), "%s: %s::%s(%s%s%s)%s%s\n" + QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n" #ifdef Q_OS_WIN "%s(%d) : failure location\n" #else @@ -187,12 +217,14 @@ namespace QTest { , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, msg[0] ? " " : "", msg, file, line); } else { - QTest::qt_snprintf(buf, sizeof(buf), "%s: %s::%s(%s%s%s)%s%s\n", + QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n", type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, msg[0] ? " " : "", msg); } - memcpy(buf, type, strlen(type)); - outputMessage(buf); + // 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> @@ -203,7 +235,7 @@ namespace QTest { int digits = 0; qreal divisor = 1; - + while (num / divisor >= 1) { divisor *= 10; ++digits; @@ -216,17 +248,17 @@ namespace QTest { template <typename T> QString formatResult(T number, int significantDigits) { if (number < T(0)) - return QString(QLatin1String("NAN")); + return QLatin1String("NAN"); if (number == T(0)) - return QString(QLatin1String("0")); + return QLatin1String("0"); QString beforeDecimalPoint = QString::number(qint64(number), 'f', 0); QString afterDecimalPoint = QString::number(number, 'f', 20); afterDecimalPoint.remove(0, beforeDecimalPoint.count() + 1); - + int beforeUse = qMin(beforeDecimalPoint.count(), significantDigits); int beforeRemove = beforeDecimalPoint.count() - beforeUse; - + // Replace insignificant digits before the decimal point with zeros. beforeDecimalPoint.chop(beforeRemove); for (int i = 0; i < beforeRemove; ++i) { @@ -264,10 +296,10 @@ namespace QTest { print = beforeDecimalPoint; if (afterUse > 0) print.append(decimalPoint); - + print += afterDecimalPoint; - + return print; } @@ -288,7 +320,7 @@ namespace QTest { char buf1[1024]; QTest::qt_snprintf( buf1, sizeof(buf1), "%s: %s::%s", - bmtag, + bmtag, QTestResult::currentTestObjectName(), result.context.slotName.toAscii().data()); @@ -299,7 +331,7 @@ namespace QTest { if (tag.isEmpty() == false) { QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data()); } - + char fillFormat[8]; int fillLength = 5; |