Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/testlib/qplaintestlogger.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtTest module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5353#ifdef Q_OS_WIN
    5454#include "windows.h"
     55#endif
     56
     57#if defined(Q_OS_SYMBIAN)
     58#include <e32debug.h>
    5559#endif
    5660
     
    126130    static const char *messageType2String(QAbstractTestLogger::MessageTypes type)
    127131    {
     132#ifdef Q_OS_WIN
    128133        static bool colored = (!qgetenv("QTEST_COLORED").isEmpty());
     134#else
     135        static bool colored = ::getenv("QTEST_COLORED");
     136#endif
    129137        switch (type) {
    130138        case QAbstractTestLogger::Skip:
     
    149157    {
    150158#if defined(Q_OS_WINCE)
    151         int length = strlen(str);
    152         for (int pos = 0; pos < length; pos +=255) {
    153             QString uniText = QString::fromLatin1(str + pos, 255);
    154             OutputDebugStringW((const LPCWSTR) uniText.utf16());
    155         }
     159        QString strUtf16 = QString::fromLatin1(str);
     160        const int maxOutputLength = 255;
     161        do {
     162            QString tmp = strUtf16.left(maxOutputLength);
     163            OutputDebugString((wchar_t*)tmp.utf16());
     164            strUtf16.remove(0, maxOutputLength);
     165        } while (!strUtf16.isEmpty());
    156166        if (QTestLog::outputFileName())
    157167#elif defined(Q_OS_WIN)
     
    160170        OutputDebugStringA(str);
    161171        LeaveCriticalSection(&outputCriticalSection);
     172#elif defined(Q_OS_SYMBIAN)
     173        // RDebug::Print has a cap of 256 characters so break it up
     174        TPtrC8 ptr(reinterpret_cast<const TUint8*>(str));
     175        _LIT(format, "[QTestLib] %S");
     176        const int maxBlockSize = 256 - ((const TDesC &)format).Length();
     177        HBufC* hbuffer = HBufC::New(maxBlockSize);
     178        if(hbuffer) {
     179            for (int i = 0; i < ptr.Length(); i += maxBlockSize) {
     180                int size = Min(maxBlockSize, ptr.Length() - i);
     181                hbuffer->Des().Copy(ptr.Mid(i, size));
     182                RDebug::Print(format, hbuffer);
     183            }
     184        }
     185        else {
     186            // fast, no allocations, but truncates silently
     187            RDebug::RawPrint(format);
     188            TPtrC8 ptr(reinterpret_cast<const TUint8*>(str));
     189            RDebug::RawPrint(ptr);
     190            RDebug::RawPrint(_L8("\n"));
     191        }
    162192#endif
    163193        QAbstractTestLogger::outputString(str);
     
    169199        QTEST_ASSERT(msg);
    170200
    171         char buf[1024];
     201        QTestCharBuffer buf;
    172202
    173203        const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction()
     
    179209        const char *filler = (tag[0] && gtag[0]) ? ":" : "";
    180210        if (file) {
    181             QTest::qt_snprintf(buf, sizeof(buf), "%s: %s::%s(%s%s%s)%s%s\n"
     211            QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n"
    182212#ifdef Q_OS_WIN
    183213                          "%s(%d) : failure location\n"
     
    188218                          msg[0] ? " " : "", msg, file, line);
    189219        } else {
    190             QTest::qt_snprintf(buf, sizeof(buf), "%s: %s::%s(%s%s%s)%s%s\n",
     220            QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n",
    191221                    type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag,
    192222                    msg[0] ? " " : "", msg);
    193223        }
    194         memcpy(buf, type, strlen(type));
    195         outputMessage(buf);
     224        // In colored mode, printf above stripped our nonprintable control characters.
     225        // Put them back.
     226        memcpy(buf.data(), type, strlen(type));
     227        outputMessage(buf.data());
    196228    }
    197229
     
    204236        int digits = 0;
    205237        qreal divisor = 1;
    206        
     238
    207239        while (num / divisor >= 1) {
    208240            divisor *= 10;
     
    217249    {
    218250        if (number < T(0))
    219             return QString(QLatin1String("NAN"));
     251            return QLatin1String("NAN");
    220252        if (number == T(0))
    221             return QString(QLatin1String("0"));
     253            return QLatin1String("0");
    222254
    223255        QString beforeDecimalPoint = QString::number(qint64(number), 'f', 0);
    224256        QString afterDecimalPoint = QString::number(number, 'f', 20);
    225257        afterDecimalPoint.remove(0, beforeDecimalPoint.count() + 1);
    226        
     258
    227259        int beforeUse = qMin(beforeDecimalPoint.count(), significantDigits);
    228260        int beforeRemove = beforeDecimalPoint.count() - beforeUse;
    229        
     261
    230262        // Replace insignificant digits before the decimal point with zeros.
    231263        beforeDecimalPoint.chop(beforeRemove);
     
    265297        if (afterUse > 0)
    266298            print.append(decimalPoint);
    267          
     299
    268300        print += afterDecimalPoint;
    269301
    270            
     302
    271303        return print;
    272304    }
     
    289321        QTest::qt_snprintf(
    290322            buf1, sizeof(buf1), "%s: %s::%s",
    291             bmtag, 
     323            bmtag,
    292324            QTestResult::currentTestObjectName(),
    293325            result.context.slotName.toAscii().data());
     
    300332            QTest::qt_snprintf(bufTag, sizeof(bufTag), ":\"%s\"", tag.data());
    301333        }
    302        
     334
    303335
    304336        char fillFormat[8];
Note: See TracChangeset for help on using the changeset viewer.