Changeset 561 for trunk/src/testlib


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:
43 edited
21 copied

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/testlib/3rdparty/cycle_p.h

    r2 r561  
    191191
    192192/* Visual C++ -- thanks to Morten Nissov for his help with this */
     193#if defined(_MSC_VER)
    193194#if _MSC_VER >= 1200 && (_M_IX86 >= 500 || (defined(_WIN32_WCE) && defined(_X86_))) && !defined(HAVE_TICK_COUNTER)
    194195#include <windows.h>
     
    216217#define TIME_MIN 5000.0   /* unreliable pentium IV cycle counter */
    217218#endif
     219#endif
    218220
    219221#if _MSC_VER >= 1400 && defined(_WIN32_WCE) && !defined(HAVE_TICK_COUNTER)
     
    492494#endif
    493495
     496/*----------------------------------------------------------------*/
     497/* Symbian */
     498#if defined(__SYMBIAN32__) && !defined(HAVE_TICK_COUNTER)
     499#include <e32std.h>
     500
     501typedef TUint32 CycleCounterTicks;
     502
     503static inline CycleCounterTicks getticks(void)
     504{
     505    return User::FastCounter();
     506}
     507
     508INLINE_ELAPSED(inline)
     509
     510#define HAVE_TICK_COUNTER
     511#endif
     512
    494513#endif // QBENCHLIB_CYCLE_H
  • trunk/src/testlib/qabstracttestlogger.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**
     
    4444#include "QtTest/qtestassert.h"
    4545
     46#include "QtCore/qbytearray.h"
     47
    4648#include <stdio.h>
    4749#include <stdlib.h>
     50#include <stdarg.h>
    4851
    4952#ifndef Q_OS_WIN
     
    7881}
    7982
     83
    8084void QAbstractTestLogger::startLogging()
    8185{
     
    106110}
    107111
     112namespace QTest
     113{
     114
     115extern void filter_unprintable(char *str);
     116
     117/*!
     118    \fn int QTest::qt_asprintf(QTestCharBuffer *buf, const char *format, ...);
     119    \internal
     120 */
     121int qt_asprintf(QTestCharBuffer *str, const char *format, ...)
     122{
     123    static const int MAXSIZE = 1024*1024*2;
     124
     125    Q_ASSERT(str);
     126
     127    int size = str->size();
     128
     129    va_list ap;
     130    int res = 0;
     131
     132    for (;;) {
     133        va_start(ap, format);
     134        res = qvsnprintf(str->data(), size, format, ap);
     135        va_end(ap);
     136        str->data()[size - 1] = '\0';
     137        if (res >= 0 && res < size) {
     138            // We succeeded
     139            break;
     140        }
     141        // buffer wasn't big enough, try again.
     142        // Note, we're assuming that a result of -1 is always due to running out of space.
     143        size *= 2;
     144        if (size > MAXSIZE) {
     145            break;
     146        }
     147        if (!str->reset(size))
     148            break; // out of memory - take what we have
     149    }
     150
     151    filter_unprintable(str->data());
     152
     153    return res;
     154}
     155
     156}
     157
    108158QT_END_NAMESPACE
  • trunk/src/testlib/qabstracttestlogger_p.h

    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**
     
    100100};
    101101
     102struct QTestCharBuffer
     103{
     104    enum { InitialSize = 512 };
     105
     106    inline QTestCharBuffer()
     107            : _size(InitialSize), buf(staticBuf)
     108    {
     109        staticBuf[0] = '\0';
     110    }
     111
     112    inline ~QTestCharBuffer()
     113    {
     114        if (buf != staticBuf)
     115            qFree(buf);
     116    }
     117
     118    inline char *data()
     119    {
     120        return buf;
     121    }
     122
     123    inline char **buffer()
     124    {
     125        return &buf;
     126    }
     127
     128    inline const char* constData() const
     129    {
     130        return buf;
     131    }
     132
     133    inline int size() const
     134    {
     135        return _size;
     136    }
     137
     138    inline bool reset(int newSize)
     139    {
     140        char *newBuf = 0;
     141        if (buf == staticBuf) {
     142            // if we point to our internal buffer, we need to malloc first
     143            newBuf = reinterpret_cast<char *>(qMalloc(newSize));
     144        } else {
     145            // if we already malloc'ed, just realloc
     146            newBuf = reinterpret_cast<char *>(qRealloc(buf, newSize));
     147        }
     148
     149        // if the allocation went wrong (newBuf == 0), we leave the object as is
     150        if (!newBuf)
     151            return false;
     152
     153        _size = newSize;
     154        buf = newBuf;
     155        return true;
     156    }
     157
     158private:
     159    int _size;
     160    char* buf;
     161    char staticBuf[InitialSize];
     162};
     163
     164namespace QTest
     165{
     166    int qt_asprintf(QTestCharBuffer *buf, const char *format, ...);
     167}
     168
     169
    102170QT_END_NAMESPACE
    103171
  • trunk/src/testlib/qasciikey.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**
  • trunk/src/testlib/qbenchmark.cpp

    r2 r561  
    1 
    21/****************************************************************************
    32**
    43** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    5 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    66**
    77** This file is part of the QtTest module of the Qt Toolkit.
     
    2222** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2323**
    24 ** In addition, as a special exception, Nokia gives you certain
    25 ** additional rights. These rights are described in the Nokia Qt LGPL
    26 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    27 ** 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.
    2827**
    2928** GNU General Public License Usage
     
    3534** met: http://www.gnu.org/copyleft/gpl.html.
    3635**
    37 ** If you are unsure which license is appropriate for your use, please
    38 ** 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.
    3938** $QT_END_LICENSE$
    4039**
     
    118117
    119118QBenchmarkTestMethodData::QBenchmarkTestMethodData()
    120 :resultAccepted(false), iterationCount(-1)
     119:resultAccepted(false), runOnce(false), iterationCount(-1)
    121120{
    122121   
     
    159158        accepted = true;
    160159
     160    if (QBenchmarkTestMethodData::current->runOnce) {
     161        iterationCount = 1;
     162        accepted = true;
     163    }
     164   
    161165    // Test the result directly without calling the measurer if the minimum time
    162166    // has been specifed on the command line with -minimumvalue.
     
    176180}
    177181
    178 /*! \internal
     182/*!
     183    \class QTest::QBenchmarkIterationController
     184    \internal
     185
    179186    The QBenchmarkIterationController class is used by the QBENCHMARK macro to
    180187    drive the benchmarking loop. It is repsonsible for starting and stopping
    181188    the timing measurements as well as calling the result reporting functions.
    182189*/
     190
     191/*! \internal
     192*/
     193QTest::QBenchmarkIterationController::QBenchmarkIterationController(RunMode runMode)
     194{
     195    i = 0;
     196    if (runMode == RunOnce)
     197        QBenchmarkTestMethodData::current->runOnce = true;   
     198    QTest::beginBenchmarkMeasurement();
     199}
     200
    183201QTest::QBenchmarkIterationController::QBenchmarkIterationController()
    184202{
     203    i = 0;
    185204    QTest::beginBenchmarkMeasurement();
    186     i = 0;
    187 }
     205}
     206
    188207/*! \internal
    189208*/
     
    197216bool QTest::QBenchmarkIterationController::isDone()
    198217{
     218    if (QBenchmarkTestMethodData::current->runOnce)
     219        return i > 0;
    199220    return i >= QTest::iterationCount();
    200221}
     
    220241    QBenchmarkTestMethodData::current->adjustIterationCount(count);
    221242}
     243
    222244/*! \internal
    223245*/
  • trunk/src/testlib/qbenchmark.h

    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**
     
    6565{
    6666public:
     67    enum RunMode { RepeatUntilValidMeasurement, RunOnce };
    6768    QBenchmarkIterationController();
     69    QBenchmarkIterationController(RunMode runMode);
    6870    ~QBenchmarkIterationController();
    6971    bool isDone();
     
    7577
    7678#define QBENCHMARK \
    77     for (QTest::QBenchmarkIterationController __iteration_controller; __iteration_controller.isDone() == false; __iteration_controller.next())
     79    for (QTest::QBenchmarkIterationController __iteration_controller; \
     80            __iteration_controller.isDone() == false; __iteration_controller.next())
     81
     82#define QBENCHMARK_ONCE \
     83    for (QTest::QBenchmarkIterationController __iteration_controller(QTest::QBenchmarkIterationController::RunOnce); \
     84            __iteration_controller.isDone() == false; __iteration_controller.next())
    7885
    7986QT_END_NAMESPACE
  • trunk/src/testlib/qbenchmark_p.h

    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**
     
    5656#include <QtCore/qglobal.h>
    5757
    58 #if defined(Q_OS_LINUX) && !defined(QT_NO_PROCESS)
     58#if (defined(Q_OS_LINUX) || defined Q_OS_MAC) && !defined(QT_NO_PROCESS)
    5959#define QTESTLIB_USE_VALGRIND
    6060#else
     
    8282    QString toString() const
    8383    {
    84         QString s = QString(QLatin1String("%1,%2,%3")).arg(slotName).arg(tag).arg(checkpointIndex);
     84        QString s = QString::fromLatin1("%1,%2,%3").arg(slotName).arg(tag).arg(checkpointIndex);
    8585        return s;
    8686    }
     
    172172    QBenchmarkResult result;
    173173    bool resultAccepted;
     174    bool runOnce;
    174175    int iterationCount;
    175176};
  • trunk/src/testlib/qbenchmarkevent.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**
  • trunk/src/testlib/qbenchmarkevent_p.h

    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**
  • trunk/src/testlib/qbenchmarkmeasurement.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**
  • trunk/src/testlib/qbenchmarkmeasurement_p.h

    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**
  • trunk/src/testlib/qbenchmarkvalgrind.cpp

    r2 r561  
    1 
    21/****************************************************************************
    32**
    43** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    5 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    66**
    77** This file is part of the QtTest module of the Qt Toolkit.
     
    2222** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2323**
    24 ** In addition, as a special exception, Nokia gives you certain
    25 ** additional rights. These rights are described in the Nokia Qt LGPL
    26 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    27 ** 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.
    2827**
    2928** GNU General Public License Usage
     
    3534** met: http://www.gnu.org/copyleft/gpl.html.
    3635**
    37 ** If you are unsure which license is appropriate for your use, please
    38 ** 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.
    3938** $QT_END_LICENSE$
    4039**
     
    5251#include <QtCore/qset.h>
    5352#include "3rdparty/callgrind_p.h"
     53
     54QT_BEGIN_NAMESPACE
    5455
    5556// Returns true iff a sufficiently recent valgrind is available.
     
    114115        const QString line(QLatin1String(file.readLine()));
    115116        if (rxValue.indexIn(line) != -1) {
    116             Q_ASSERT(rxValue.numCaptures() == 1);
     117            Q_ASSERT(rxValue.captureCount() == 1);
    117118            bool ok;
    118119            val = rxValue.cap(1).toLongLong(&ok);
     
    133134    Q_ASSERT(!base.isEmpty());
    134135
    135     nameFilters << QString(QLatin1String("%1.*")).arg(base);
     136    nameFilters << QString::fromLatin1("%1.*").arg(base);
    136137    QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
    137138    Q_ASSERT(!fiList.empty());
    138139    int hiSuffix = -1;
    139140    QFileInfo lastFileInfo;
    140     const QString pattern = QString(QLatin1String("%1.(\\d+)")).arg(base);
     141    const QString pattern = QString::fromLatin1("%1.(\\d+)").arg(base);
    141142    const QRegExp rx(pattern);
    142143    foreach (QFileInfo fileInfo, fiList) {
     
    168169    Q_ASSERT(!base.isEmpty());
    169170    nameFilters
    170         << QString(QLatin1String("%1")).arg(base) // overall summary
    171         << QString(QLatin1String("%1.*")).arg(base); // individual dumps
     171        << base // overall summary
     172        << QString::fromLatin1("%1.*").arg(base); // individual dumps
    172173    QFileInfoList fiList = QDir().entryInfoList(nameFilters, QDir::Files | QDir::Readable);
    173174    foreach (QFileInfo fileInfo, fiList) {
     
    180181QString QBenchmarkValgrindUtils::outFileBase(qint64 pid)
    181182{
    182     return QString(QLatin1String("callgrind.out.%1")).arg(
     183    return QString::fromLatin1("callgrind.out.%1").arg(
    183184        pid != -1 ? pid : QCoreApplication::applicationPid());
    184185}
     
    273274}
    274275
     276QT_END_NAMESPACE
     277
    275278#endif // QTESTLIB_USE_VALGRIND
  • trunk/src/testlib/qbenchmarkvalgrind_p.h

    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**
  • 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];
  • trunk/src/testlib/qplaintestlogger_p.h

    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**
  • trunk/src/testlib/qsignaldumper.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**
     
    8888    str += "Signal: ";
    8989    str += mo->className();
    90     str += "(";
     90    str += '(';
    9191
    9292    QString objname = caller->objectName();
     
    115115        } else if (typeId != QMetaType::Void) {
    116116            str.append(arg)
    117                 .append("(")
     117                .append('(')
    118118                .append(QVariant(typeId, argv[i + 1]).toString().toLocal8Bit())
    119                 .append(")");
     119                .append(')');
    120120        }
    121121        str.append(", ");
     
    123123    if (str.endsWith(", "))
    124124        str.chop(2);
    125     str.append(")");
     125    str.append(')');
    126126    qPrintMessage(str);
    127127}
     
    144144    str += "Slot: ";
    145145    str += mo->className();
    146     str += "(";
     146    str += '(';
    147147
    148148    QString objname = caller->objectName();
  • trunk/src/testlib/qsignaldumper_p.h

    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**
  • trunk/src/testlib/qsignalspy.h

    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**
  • trunk/src/testlib/qtest.h

    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**
     
    5454#include <QtCore/qdatetime.h>
    5555#include <QtCore/qobject.h>
     56#include <QtCore/qvariant.h>
    5657#include <QtCore/qurl.h>
    5758
     
    8889{
    8990    return time.isValid()
    90         ? qstrdup(time.toString(QLatin1String("hh:mm:ss.zzz")).toLatin1())
     91        ? qstrdup(time.toString(QLatin1String("hh:mm:ss.zzz")).toLatin1().constData())
    9192        : qstrdup("Invalid QTime");
    9293}
     
    9596{
    9697    return date.isValid()
    97         ? qstrdup(date.toString(QLatin1String("yyyy/MM/dd")).toLatin1())
     98        ? qstrdup(date.toString(QLatin1String("yyyy/MM/dd")).toLatin1().constData())
    9899        : qstrdup("Invalid QDate");
    99100}
     
    103104    return dateTime.isValid()
    104105        ? qstrdup((dateTime.toString(QLatin1String("yyyy/MM/dd hh:mm:ss.zzz")) +
    105                   (dateTime.timeSpec() == Qt::LocalTime ? QLatin1String("[local time]") : QLatin1String("[UTC]"))).toLatin1())
     106                  (dateTime.timeSpec() == Qt::LocalTime ? QLatin1String("[local time]") : QLatin1String("[UTC]"))).toLatin1().constData())
    106107        : qstrdup("Invalid QDateTime");
    107108}
     
    145146{
    146147    return qstrdup(uri.toEncoded().constData());
     148}
     149
     150template<> inline char *toString(const QVariant &v)
     151{
     152    QByteArray vstring("QVariant(");
     153    if (v.isValid()) {
     154        QByteArray type(v.typeName());
     155        if (type.isEmpty()) {
     156            type = QByteArray::number(v.userType());
     157        }
     158        vstring.append(type);
     159        if (!v.isNull()) {
     160            vstring.append(',');
     161            if (v.canConvert(QVariant::String)) {
     162                vstring.append(qVariantValue<QString>(v).toLatin1());
     163            }
     164            else {
     165                vstring.append("<value not representable as string>");
     166            }
     167        }
     168    }
     169    vstring.append(')');
     170
     171    return qstrdup(vstring.constData());
    147172}
    148173
     
    227252#include <QtTest/qtest_gui.h>
    228253
     254#ifdef QT_KEYPAD_NAVIGATION
     255#  define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeNone);
     256#else
     257#  define QTEST_DISABLE_KEYPAD_NAVIGATION
     258#endif
     259
    229260#define QTEST_MAIN(TestObject) \
    230261int main(int argc, char *argv[]) \
    231262{ \
    232263    QApplication app(argc, argv); \
     264    QTEST_DISABLE_KEYPAD_NAVIGATION \
    233265    TestObject tc; \
    234266    return QTest::qExec(&tc, argc, argv); \
  • trunk/src/testlib/qtest_global.h

    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 QTEST_EMBED
    5454# define Q_TESTLIB_EXPORT
    55 #elif !defined(QT_SHARED)
     55#elif !defined(QT_SHARED) && !(defined(Q_OS_SYMBIAN) && defined(Q_CC_RVCT))
    5656# define Q_TESTLIB_EXPORT
    5757#else
     
    6363#endif
    6464
    65 #if (defined (Q_CC_MSVC) && _MSC_VER < 1310) || defined (Q_CC_SUN) || defined (Q_CC_XLC) || (defined (Q_CC_GNU) && (__GNUC__ - 0 < 3))
     65#if (defined (Q_CC_MSVC) && _MSC_VER < 1310) || defined (Q_CC_SUN) || defined (Q_CC_XLC) || (defined (Q_CC_GNU) && (__GNUC__ - 0 < 3)) || defined (Q_CC_NOKIAX86)
    6666# define QTEST_NO_SPECIALIZATIONS
    6767#endif
     68
    6869
    6970#if (defined Q_CC_HPACC) && (defined __ia64)
  • trunk/src/testlib/qtest_gui.h

    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**
     
    4343#define QTEST_GUI_H
    4444
     45// enable GUI features
     46#ifndef QT_GUI_LIB
     47#define QT_GUI_LIB
     48#endif
     49#if 0
     50#pragma qt_class(QtTestGui)
     51#endif
     52
    4553#include <QtTest/qtestassert.h>
    4654#include <QtTest/qtest.h>
    4755#include <QtTest/qtestevent.h>
    4856#include <QtTest/qtestmouse.h>
     57#include <QtTest/qtesttouch.h>
    4958#include <QtTest/qtestkeyboard.h>
    5059
  • trunk/src/testlib/qtestaccessible.h

    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**
  • trunk/src/testlib/qtestassert.h

    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**
  • trunk/src/testlib/qtestcase.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**
     
    5555#include <QtCore/qprocess.h>
    5656#include <QtCore/qdebug.h>
     57#include <QtCore/qlibraryinfo.h>
    5758
    5859#include "QtTest/private/qtestlog_p.h"
     
    7273#endif
    7374#ifdef Q_OS_UNIX
     75#include <errno.h>
     76#include <signal.h>
    7477#include <time.h>
    7578#endif
     
    301304    Use this macro to build stand-alone executables.
    302305
     306    \bold {Note:} On platforms that have keypad navigation enabled by default (eg: Symbian),
     307    this macro will forcfully disable it to simplify the usage of key events when writing
     308    autotests. If you wish to write a test case that uses keypad navigation, you should
     309    enable it either in the \c {initTestCase()} or \c {init()} functions of your test case.
     310
    303311    Example:
    304312    \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 11
    305313
    306     \sa QTEST_APPLESS_MAIN(), QTest::qExec()
     314    \sa QTEST_APPLESS_MAIN(), QTest::qExec(), QApplication::setNavigationMode()
    307315*/
    308316
     
    348356        {Chapter 5: Writing a Benchmark}{Writing a Benchmark}
    349357*/
     358
     359/*!
     360    \macro QBENCHMARK_ONCE
     361    \since 4.6
     362
     363    \relates QTest
     364
     365    \brief The QBENCHMARK_ONCE macro is for measuring performance of a
     366    code block by running it once.
     367
     368    This macro is used to measure the performance of code within a test.
     369    The code to be benchmarked is contained within a code block following
     370    this macro.
     371
     372    Unlike QBENCHMARK, the contents of the contained code block is only run
     373    once. The elapsed time will be reported as "0" if it's to short to
     374    be measured by the selected backend. (Use)
     375
     376    \sa {QTestLib Manual#Creating a Benchmark}{Creating a Benchmark},
     377    {Chapter 5: Writing a Benchmark}{Writing a Benchmark}
     378*/
     379
     380
    350381
    351382/*! \enum QTest::SkipMode
     
    401432    \overload
    402433
    403     Simulates clicking of \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds.
     434    Simulates clicking of \a key with an optional \a modifier on a \a widget.
     435    If \a delay is larger than 0, the test will wait for \a delay milliseconds.
    404436
    405437    Example:
     
    414446/*! \fn void QTest::keyClick(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
    415447
    416     Simulates clicking of \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds.
     448    Simulates clicking of \a key with an optional \a modifier on a \a widget.
     449    If \a delay is larger than 0, the test will wait for \a delay milliseconds.
    417450
    418451    Examples:
     
    429462/*! \fn void QTest::keyEvent(KeyAction action, QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
    430463
    431     Sends a Qt key event to \a widget with the given \a key and an associated \a action. Optionally, a keyboard \a modifier can be specified, as well as a \a delay (in milliseconds) of the test before sending the event.
     464    Sends a Qt key event to \a widget with the given \a key and an associated \a action.
     465    Optionally, a keyboard \a modifier can be specified, as well as a \a delay
     466    (in milliseconds) of the test before sending the event.
    432467*/
    433468
     
    436471    \overload
    437472
    438     Sends a Qt key event to \a widget with the given key \a ascii and an associated \a action. Optionally, a keyboard \a modifier can be specified, as well as a \a delay (in milliseconds) of the test before sending the event.
     473    Sends a Qt key event to \a widget with the given key \a ascii and an associated \a action.
     474    Optionally, a keyboard \a modifier can be specified, as well as a \a delay
     475    (in milliseconds) of the test before sending the event.
    439476
    440477*/
     
    442479/*! \fn void QTest::keyPress(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
    443480
    444     Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds.
     481    Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay
     482    is larger than 0, the test will wait for \a delay milliseconds.
    445483
    446484    \bold {Note:} At some point you should release the key using \l keyRelease().
     
    453491    \overload
    454492
    455     Simulates pressing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds.
     493    Simulates pressing a \a key with an optional \a modifier on a \a widget.
     494    If \a delay is larger than 0, the test will wait for \a delay milliseconds.
    456495
    457496    \bold {Note:} At some point you should release the key using \l keyRelease().
     
    462501/*! \fn void QTest::keyRelease(QWidget *widget, Qt::Key key, Qt::KeyboardModifiers modifier = Qt::NoModifier, int delay=-1)
    463502
    464     Simulates releasing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds.
     503    Simulates releasing a \a key with an optional \a modifier on a \a widget.
     504    If \a delay is larger than 0, the test will wait for \a delay milliseconds.
    465505
    466506    \sa QTest::keyPress(), QTest::keyClick()
     
    471511    \overload
    472512
    473     Simulates releasing a \a key with an optional \a modifier on a \a widget. If \a delay is larger than 0, the test will wait for \a delay milliseconds.
     513    Simulates releasing a \a key with an optional \a modifier on a \a widget.
     514    If \a delay is larger than 0, the test will wait for \a delay milliseconds.
    474515
    475516    \sa QTest::keyClick()
     
    673714*/
    674715
     716/*!
     717    \fn char *QTest::toString(const QVariant &variant)
     718    \overload
     719
     720    Returns a textual representation of the given \a variant.
     721*/
     722
    675723/*! \fn void QTest::qWait(int ms)
    676724
     
    687735*/
    688736
     737/*! \fn bool QTest::qWaitForWindowShown(QWidget *window)
     738    \since 4.6
     739
     740    Waits until the \a window is shown in the screen. This is mainly useful for
     741    asynchronous systems like X11, where a window will be mapped to screen some
     742    time after being asked to show itself on the screen. Returns true.
     743
     744    Example:
     745    \snippet doc/src/snippets/code/src_qtestlib_qtestcase.cpp 24
     746*/
     747
     748/*!
     749    \class QTest::QTouchEventSequence
     750    \inmodule QtTest
     751    \since 4.6
     752
     753    \brief The QTouchEventSequence class is used to simulate a sequence of touch events.
     754
     755    To simulate a sequence of touch events on a specific device for a widget, call
     756    QTest::touchEvent to create a QTouchEventSequence instance. Add touch events to
     757    the sequence by calling press(), move(), release() and stationary(), and let the
     758    instance run out of scope to commit the sequence to the event system.
     759*/
     760
     761/*!
     762    \fn QTest::QTouchEventSequence::~QTouchEventSequence()
     763
     764    Commits this sequence of touch events and frees allocated resources.
     765*/
     766
     767/*!
     768    \fn QTouchEventSequence &QTest::QTouchEventSequence::press(int touchId, const QPoint &pt, QWidget *widget)
     769
     770    Adds a press event for touchpoint \a touchId at position \a pt to this sequence and returns
     771    a reference to this QTouchEventSequence.
     772
     773    The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then
     774    \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence.
     775
     776    Simulates that the user pressed the touch screen or pad with the finger identified by \a touchId.
     777*/
     778
     779/*!
     780    \fn QTouchEventSequence &QTest::QTouchEventSequence::move(int touchId, const QPoint &pt, QWidget *widget)
     781
     782    Adds a move event for touchpoint \a touchId at position \a pt to this sequence and returns
     783    a reference to this QTouchEventSequence.
     784
     785    The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then
     786    \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence.
     787
     788    Simulates that the user moved the finger identified by \a touchId.
     789*/
     790
     791/*!
     792    \fn QTouchEventSequence &QTest::QTouchEventSequence::release(int touchId, const QPoint &pt, QWidget *widget)
     793
     794    Adds a release event for touchpoint \a touchId at position \a pt to this sequence and returns
     795    a reference to this QTouchEventSequence.
     796
     797    The position \a pt is interpreted as relative to \a widget. If \a widget is the null pointer, then
     798    \a pt is interpreted as relative to the widget provided when instantiating this QTouchEventSequence.
     799
     800    Simulates that the user lifted the finger identified by \a touchId.
     801*/
     802
     803/*!
     804    \fn QTouchEventSequence &QTest::QTouchEventSequence::stationary(int touchId)
     805
     806    Adds a stationary event for touchpoint \a touchId to this sequence and returns
     807    a reference to this QTouchEventSequence.
     808
     809    Simulates that the user did not move the finger identified by \a touchId.
     810*/
     811
     812/*!
     813    \fn QTouchEventSequence QTest::touchEvent(QWidget *widget, QTouchEvent::DeviceType deviceType)
     814
     815    Creates and returns a QTouchEventSequence for the device \a deviceType to
     816    simulate events for \a widget.
     817
     818    When adding touch events to the sequence, \a widget will also be used to translate
     819    the position provided to screen coordinates, unless another widget is provided in the
     820    respective calls to press(), move() etc.
     821
     822    The touch events are committed to the event system when the destructor of the
     823    QTouchEventSequence is called (ie when the object returned runs out of scope).
     824*/
     825
    689826namespace QTest
    690827{
    691828    static QObject *currentTestObject = 0;
    692829
    693     struct TestFunction {
     830    static struct TestFunction {
    694831        TestFunction():function(0), data(0) {}
    695832        ~TestFunction() { delete [] data; }
    696833        int function;
    697834        char *data;
    698     } testFuncs[512];
     835    } *testFuncs;
    699836
    700837    /**
     
    711848    static int keyVerbose = -1;
    712849
    713 /*! \internal
    714  */
    715 int qt_snprintf(char *str, int size, const char *format, ...)
    716 {
    717     va_list ap;
    718     int res = 0;
    719 
    720     va_start(ap, format);
    721     qvsnprintf(str, size, format, ap);
    722     va_end(ap);
    723     str[size - 1] = '\0';
    724 
     850void filter_unprintable(char *str)
     851{
    725852    char *idx = str;
    726853    while (*idx) {
     
    729856        ++idx;
    730857    }
     858}
     859
     860/*! \internal
     861 */
     862int qt_snprintf(char *str, int size, const char *format, ...)
     863{
     864    va_list ap;
     865    int res = 0;
     866
     867    va_start(ap, format);
     868    qvsnprintf(str, size, format, ap);
     869    va_end(ap);
     870    str[size - 1] = '\0';
     871
     872    filter_unprintable(str);
     873
    731874    return res;
    732875}
     
    819962         " options:\n"
    820963         " -functions : Returns a list of current testfunctions\n"
     964         " -xunitxml  : Outputs results as XML XUnit document\n"
    821965         " -xml       : Outputs results as XML document\n"
    822966         " -lightxml  : Outputs results as stream of XML tags\n"
     967         " -flush     : Flushes the resutls\n"
    823968         " -o filename: Writes all output into a file\n"
    824969         " -silent    : Only outputs warnings and failures\n"
     
    845990        " -median  n      : Sets the number of median iterations.\n"
    846991        " -vb             : Print out verbose benchmarking information.\n"
    847 #ifndef QT_NO_PROCESS
    848 // Will be enabled when tools are integrated.   
    849 //        " -chart          : Runs the chart generator after the test. No output is printed to the console\n"
     992#if !defined(QT_NO_PROCESS) && !defined(QT_NO_SETTINGS)
     993        " -chart          : Create chart based on the benchmark result.\n"
    850994#endif
    851995         "\n"
     
    8621006            qPrintTestSlots();
    8631007            exit(0);
     1008        } else if(strcmp(argv[i], "-xunitxml") == 0){
     1009            QTestLog::setLogMode(QTestLog::XunitXML);
    8641010        } else if (strcmp(argv[i], "-xml") == 0) {
    8651011            QTestLog::setLogMode(QTestLog::XML);
    8661012        } else if (strcmp(argv[i], "-lightxml") == 0) {
    8671013            QTestLog::setLogMode(QTestLog::LightXML);
     1014        }else if(strcmp(argv[i], "-flush") == 0){
     1015            QTestLog::setFlushMode(QTestLog::FLushOn);
    8681016        } else if (strcmp(argv[i], "-silent") == 0) {
    8691017            QTestLog::setVerboseLevel(-1);
     
    9581106        } else if (strcmp(argv[i], "-vb") == 0) {
    9591107            QBenchmarkGlobalData::current->verboseOutput = true;
    960 #ifndef QT_NO_PROCESS
     1108#if !defined(QT_NO_PROCESS) && !defined(QT_NO_SETTINGS)
    9611109        } else if (strcmp(argv[i], "-chart") == 0) {
    9621110            QBenchmarkGlobalData::current->createChart = true;
     
    9921140            }
    9931141            ++QTest::lastTestFuncIdx;
     1142            if (!QTest::testFuncs) {
     1143                struct Cleanup { ~Cleanup() { delete[] QTest::testFuncs; } };
     1144                static Cleanup cleanup;
     1145                QTest::testFuncs = new TestFunction[512];
     1146            }
    9941147            QTest::testFuncs[QTest::lastTestFuncIdx].function = idx;
    9951148            QTest::testFuncs[QTest::lastTestFuncIdx].data = data;
     
    10071160    if (count == 1)
    10081161        return container.at(0);
    1009    
     1162
    10101163    QList<QBenchmarkResult> containerCopy = container;
    10111164    qSort(containerCopy);
     
    10571210                    ? QTestResult::currentDataTag() : "");
    10581211
    1059             invokeOk = QMetaObject::invokeMethod(QTest::currentTestObject, slot, 
     1212            invokeOk = QMetaObject::invokeMethod(QTest::currentTestObject, slot,
    10601213                                                 Qt::DirectConnection);
    10611214            if (!invokeOk)
     
    10781231            results.append(QBenchmarkTestMethodData::current->result);
    10791232
    1080         if (QBenchmarkTestMethodData::current->isBenchmark() && 
     1233        if (QBenchmarkTestMethodData::current->isBenchmark() &&
    10811234            QBenchmarkGlobalData::current->verboseOutput) {
    10821235                if (i == -1) {
     
    12091362/*!
    12101363  \fn char* QTest::toHexRepresentation(const char *ba, int length)
    1211  
     1364
    12121365  Returns a pointer to a string that is the string \a ba represented
    12131366  as a space-separated sequence of hex characters. If the input is
     
    12151368  the returned string as an ellipsis at the end.
    12161369
    1217   \a length is the length of the string \a ba. 
     1370  \a length is the length of the string \a ba.
    12181371 */
    12191372char *toHexRepresentation(const char *ba, int length)
     
    12741427}
    12751428
    1276 static void qInvokeTestMethods(QObject *testObject)
    1277 {
    1278     const QMetaObject *metaObject = testObject->metaObject();
    1279     QTEST_ASSERT(metaObject);
    1280  
    1281     QTestLog::startLogging();
    1282  
    1283     QTestResult::setCurrentTestFunction("initTestCase");
    1284     QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
    1285     QTestTable::globalTestTable();
    1286     QMetaObject::invokeMethod(testObject, "initTestCase_data", Qt::DirectConnection);
    1287  
    1288     if (!QTestResult::skipCurrentTest() && !QTest::currentTestFailed()) {
    1289         QTestResult::setCurrentTestLocation(QTestResult::InitFunc);
    1290         QMetaObject::invokeMethod(testObject, "initTestCase");
    1291  
    1292         // finishedCurrentTestFunction() resets QTestResult::testFailed(), so use a local copy.
    1293         const bool previousFailed = QTestResult::testFailed();
    1294         QTestResult::finishedCurrentTestFunction();
    1295  
    1296         if(!QTestResult::skipCurrentTest() && !previousFailed) {
    1297  
    1298             if (lastTestFuncIdx >= 0) {
    1299                 for (int i = 0; i <= lastTestFuncIdx; ++i) {
    1300                     if (!qInvokeTestMethod(metaObject->method(testFuncs[i].function).signature(),
    1301                                            testFuncs[i].data))
    1302                         break;
    1303                 }
    1304             } else {
    1305                 int methodCount = metaObject->methodCount();
    1306                 for (int i = 0; i < methodCount; ++i) {
    1307                     QMetaMethod slotMethod = metaObject->method(i);
    1308                     if (!isValidSlot(slotMethod))
    1309                         continue;
    1310                     if (!qInvokeTestMethod(slotMethod.signature()))
    1311                         break;
    1312                 }
    1313             }
    1314         }
    1315  
    1316         QTestResult::setSkipCurrentTest(false);
    1317         QTestResult::setCurrentTestFunction("cleanupTestCase");
    1318         QMetaObject::invokeMethod(testObject, "cleanupTestCase");
    1319     }
    1320     QTestResult::finishedCurrentTestFunction();
    1321     QTestResult::setCurrentTestFunction(0);
    1322     QTestTable::clearGlobalTestTable();
    1323  
    1324     QTestLog::stopLogging();
    1325 }
     1429static void qInvokeTestMethods(QObject *testObject)
     1430{
     1431    const QMetaObject *metaObject = testObject->metaObject();
     1432    QTEST_ASSERT(metaObject);
     1433
     1434    QTestLog::startLogging();
     1435
     1436    QTestResult::setCurrentTestFunction("initTestCase");
     1437    QTestResult::setCurrentTestLocation(QTestResult::DataFunc);
     1438    QTestTable::globalTestTable();
     1439    QMetaObject::invokeMethod(testObject, "initTestCase_data", Qt::DirectConnection);
     1440
     1441    if (!QTestResult::skipCurrentTest() && !QTest::currentTestFailed()) {
     1442        QTestResult::setCurrentTestLocation(QTestResult::InitFunc);
     1443        QMetaObject::invokeMethod(testObject, "initTestCase");
     1444
     1445        // finishedCurrentTestFunction() resets QTestResult::testFailed(), so use a local copy.
     1446        const bool previousFailed = QTestResult::testFailed();
     1447        QTestResult::finishedCurrentTestFunction();
     1448
     1449        if(!QTestResult::skipCurrentTest() && !previousFailed) {
     1450
     1451            if (lastTestFuncIdx >= 0) {
     1452                for (int i = 0; i <= lastTestFuncIdx; ++i) {
     1453                    if (!qInvokeTestMethod(metaObject->method(testFuncs[i].function).signature(),
     1454                                           testFuncs[i].data))
     1455                        break;
     1456                }
     1457            } else {
     1458                int methodCount = metaObject->methodCount();
     1459                for (int i = 0; i < methodCount; ++i) {
     1460                    QMetaMethod slotMethod = metaObject->method(i);
     1461                    if (!isValidSlot(slotMethod))
     1462                        continue;
     1463                    if (!qInvokeTestMethod(slotMethod.signature()))
     1464                        break;
     1465                }
     1466            }
     1467        }
     1468
     1469        QTestResult::setSkipCurrentTest(false);
     1470        QTestResult::setCurrentTestFunction("cleanupTestCase");
     1471        QMetaObject::invokeMethod(testObject, "cleanupTestCase");
     1472    }
     1473    QTestResult::finishedCurrentTestFunction();
     1474    QTestResult::setCurrentTestFunction(0);
     1475    QTestTable::clearGlobalTestTable();
     1476
     1477    QTestLog::stopLogging();
     1478}
     1479
     1480#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
     1481class FatalSignalHandler
     1482{
     1483public:
     1484    FatalSignalHandler();
     1485    ~FatalSignalHandler();
     1486
     1487private:
     1488    static void signal(int);
     1489    sigset_t handledSignals;
     1490};
     1491
     1492void FatalSignalHandler::signal(int signum)
     1493{
     1494    qFatal("Received signal %d", signum);
     1495}
     1496
     1497FatalSignalHandler::FatalSignalHandler()
     1498{
     1499    sigemptyset(&handledSignals);
     1500
     1501    const int fatalSignals[] = {
     1502         SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, 0 };
     1503
     1504    struct sigaction act;
     1505    memset(&act, 0, sizeof(act));
     1506    act.sa_handler = FatalSignalHandler::signal;
     1507
     1508    // Remove the handler after it is invoked.
     1509    act.sa_flags = SA_RESETHAND;
     1510
     1511    // Block all fatal signals in our signal handler so we don't try to close
     1512    // the testlog twice.
     1513    sigemptyset(&act.sa_mask);
     1514    for (int i = 0; fatalSignals[i]; ++i)
     1515        sigaddset(&act.sa_mask, fatalSignals[i]);
     1516
     1517    struct sigaction oldact;
     1518
     1519    for (int i = 0; fatalSignals[i]; ++i) {
     1520        sigaction(fatalSignals[i], &act, &oldact);
     1521#ifndef Q_WS_QWS
     1522        // Don't overwrite any non-default handlers
     1523        // however, we need to replace the default QWS handlers
     1524        if (oldact.sa_flags & SA_SIGINFO || oldact.sa_handler != SIG_DFL) {
     1525            sigaction(fatalSignals[i], &oldact, 0);
     1526        } else
     1527#endif
     1528        {
     1529            sigaddset(&handledSignals, fatalSignals[i]);
     1530        }
     1531    }
     1532}
     1533
     1534
     1535FatalSignalHandler::~FatalSignalHandler()
     1536{
     1537    // Unregister any of our remaining signal handlers
     1538    struct sigaction act;
     1539    memset(&act, 0, sizeof(act));
     1540    act.sa_handler = SIG_DFL;
     1541
     1542    struct sigaction oldact;
     1543
     1544    for (int i = 1; i < 32; ++i) {
     1545        if (!sigismember(&handledSignals, i))
     1546            continue;
     1547        sigaction(i, &act, &oldact);
     1548
     1549        // If someone overwrote it in the mean time, put it back
     1550        if (oldact.sa_handler != FatalSignalHandler::signal)
     1551            sigaction(i, &oldact, 0);
     1552    }
     1553}
     1554
     1555#endif
     1556
    13261557
    13271558} // namespace
     
    14001631#endif
    14011632
     1633#if defined(Q_OS_SYMBIAN) && defined(Q_CC_NOKIAX86)
     1634    // Delay execution of tests in Symbian emulator.
     1635    // Needed to allow worst of other higher priority apps and services launched by emulator
     1636    // to get out of the way before we run our test. Otherwise some of the timing sensitive tests
     1637    // will not work properly.
     1638    qSleep(3000);
     1639#endif
     1640
    14021641    QTestResult::reset();
    14031642
     
    14191658        QBenchmarkValgrindUtils::cleanup();
    14201659
    1421     } else {
    1422 #endif
    1423 
     1660    } else
     1661#endif
     1662    {
     1663#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN)
     1664        FatalSignalHandler handler;
     1665#endif
    14241666        qInvokeTestMethods(testObject);
    1425 
    1426 #ifdef QTESTLIB_USE_VALGRIND
    14271667    }
    1428 #endif
    1429 
    1430  #ifndef QT_NO_EXCEPTIONS
     1668
     1669#ifndef QT_NO_EXCEPTIONS
    14311670     } catch (...) {
    14321671         QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__);
     
    14421681         }
    14431682#endif
    1444  #ifdef Q_OS_WIN
    1445          // rethrow exception to make debugging easier
     1683         // Rethrow exception to make debugging easier.
    14461684         throw;
    1447  #endif
    1448          return -1;
     1685         return 1;
    14491686     }
    1450  #endif
     1687endif
    14511688
    14521689    currentTestObject = 0;
     
    14581695
    14591696
    1460 #ifndef QT_NO_PROCESS
     1697#if !defined(QT_NO_PROCESS) && !defined(QT_NO_SETTINGS)
    14611698    if (QBenchmarkGlobalData::current->createChart) {
    1462 
    1463 #define XSTR(s) STR(s)
    1464 #define STR(s) #s
     1699        QString chartLocation = QLibraryInfo::location(QLibraryInfo::BinariesPath);
    14651700#ifdef Q_OS_WIN
    1466     const char * path = XSTR(QBENCHLIB_BASE) "/tools/generatereport/generatereport.exe";
     1701        chartLocation += QLatin1String("/../tools/qtestlib/chart/release/chart.exe");
    14671702#else
    1468     const char * path = XSTR(QBENCHLIB_BASE) "/tools/generatereport/generatereport";
    1469 #endif
    1470 #undef XSTR
    1471 #undef STR
    1472 
    1473         if (QFile::exists(QLatin1String(path))) {
     1703        chartLocation += QLatin1String("/../tools/qtestlib/chart/chart");
     1704#endif
     1705        if (QFile::exists(chartLocation)) {
    14741706            QProcess p;
    14751707            p.setProcessChannelMode(QProcess::ForwardedChannels);
    1476             p.start(QLatin1String(path), QStringList() << QLatin1String("results.xml"));
     1708            p.start(chartLocation, QStringList() << QLatin1String("results.xml"));
    14771709            p.waitForFinished(-1);
    14781710        } else {
    1479             qWarning("Could not find %s, please make sure it is compiled.", path);
     1711            qDebug() << QLatin1String("Could not find the chart tool in ") + chartLocation + QLatin1String(", please make sure it is compiled.");
    14801712        }
    14811713    }
    14821714#endif
    14831715
    1484 #if defined(QTEST_NOEXITCODE) || (defined(QT_BUILD_INTERNAL) && !defined(QTEST_FORCE_EXITCODE))
     1716#if defined(QTEST_NOEXITCODE)
    14851717    return 0;
    14861718#else
     
    17561988 */
    17571989template <>
    1758 bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected,
     1990Q_TESTLIB_EXPORT bool QTest::qCompare<float>(float const &t1, float const &t2, const char *actual, const char *expected,
    17591991                    const char *file, int line)
    17601992{
     
    17692001 */
    17702002template <>
    1771 bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected,
     2003Q_TESTLIB_EXPORT bool QTest::qCompare<double>(double const &t1, double const &t2, const char *actual, const char *expected,
    17722004                    const char *file, int line)
    17732005{
     
    17792011
    17802012#define COMPARE_IMPL2(TYPE, FORMAT) \
    1781 template <> char *QTest::toString<TYPE >(const TYPE &t) \
     2013template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE >(const TYPE &t) \
    17822014{ \
    17832015    char *msg = new char[128]; \
     
    18012033COMPARE_IMPL2(bool, %d)
    18022034COMPARE_IMPL2(char, %c)
    1803 COMPARE_IMPL2(float, %g);
    1804 COMPARE_IMPL2(double, %lg);
     2035COMPARE_IMPL2(float, %g)
     2036COMPARE_IMPL2(double, %lg)
    18052037
    18062038/*! \internal
     
    19112143*/
    19122144
     2145/*! \fn bool QTest::qCompare(bool const &t1, int const &t2, const char *actual, const char *expected, const char *file, int line)
     2146  \internal
     2147 */
     2148
    19132149/*! \fn bool QTest::qTest(const T& actual, const char *elementName, const char *actualStr, const char *expected, const char *file, int line)
    19142150    \internal
     
    19272163*/
    19282164
    1929 /*! \fn int QTest::qt_snprintf(char *str, int size, const char *format, ...)
    1930     \internal
    1931 */
    1932 
    19332165QT_END_NAMESPACE
  • trunk/src/testlib/qtestcase.h

    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**
     
    125125        return 0;
    126126    }
     127
    127128
    128129    Q_TESTLIB_EXPORT char *toHexRepresentation(const char *ba, int length);
     
    178179                             toString<T>(t1), toString<T>(t2), actual, expected, file, line);
    179180    }
     181
    180182
    181183    template <>
     
    219221    bool qCompare(T1 const &, T2 const &, const char *, const char *, const char *, int);
    220222
    221 #if defined(QT_ARCH_WINDOWSCE) && defined(QT_COORD_TYPE)
     223#if defined(QT_COORD_TYPE) && (defined(QT_ARCH_ARM) || defined(QT_NO_FPU) || defined(QT_ARCH_WINDOWSCE))
    222224    template <>
    223225    inline bool qCompare<qreal, float>(qreal const &t1, float const &t2, const char *actual,
     
    234236    }
    235237
    236 #elif defined(QT_COORD_TYPE) || defined(QT_ARCH_ARM) || defined(QT_NO_FPU) || defined(QT_ARCH_WINDOWSCE)
     238#elif defined(QT_COORD_TYPE) || defined(QT_ARCH_ARM) || defined(QT_NO_FPU) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN)
    237239    template <>
    238240    inline bool qCompare<qreal, double>(qreal const &t1, double const &t2, const char *actual,
     
    290292    }
    291293#else  /* QTEST_NO_SPECIALIZATIONS */
     294
     295// In Symbian we have QTEST_NO_SPECIALIZATIONS defined, but still float related specialization
     296// should be used. If QTEST_NO_SPECIALIZATIONS is enabled we get ambiguous overload errors.
     297#if defined(QT_ARCH_SYMBIAN)
     298    template <typename T1, typename T2>
     299    bool qCompare(T1 const &, T2 const &, const char *, const char *, const char *, int);
     300
     301    template <>
     302    inline bool qCompare<qreal, double>(qreal const &t1, double const &t2, const char *actual,
     303                                 const char *expected, const char *file, int line)
     304    {
     305        return qCompare<float>(float(t1), float(t2), actual, expected, file, line);
     306    }
     307
     308    template <>
     309    inline bool qCompare<double, qreal>(double const &t1, qreal const &t2, const char *actual,
     310                                 const char *expected, const char *file, int line)
     311    {
     312        return qCompare<float>(float(t1), float(t2), actual, expected, file, line);
     313    }
     314#endif
     315
    292316    inline bool qCompare(const char *t1, const char *t2, const char *actual,
    293317                         const char *expected, const char *file, int line)
     
    323347    }
    324348
     349    // NokiaX86 and RVCT do not like implicitly comparing bool with int
     350#ifndef QTEST_NO_SPECIALIZATIONS
     351    template <>
     352#endif
     353    inline bool qCompare(bool const &t1, int const &t2,
     354                    const char *actual, const char *expected, const char *file, int line)
     355    {
     356        return qCompare<int>(int(t1), t2, actual, expected, file, line);
     357    }
     358
     359
    325360    template <class T>
    326361    inline bool qTest(const T& actual, const char *elementName, const char *actualStr,
  • trunk/src/testlib/qtestdata.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**
  • trunk/src/testlib/qtestdata.h

    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**
  • trunk/src/testlib/qtestevent.h

    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**
     
    4949
    5050#include <QtTest/qtest_global.h>
     51#ifdef QT_GUI_LIB
    5152#include <QtTest/qtestkeyboard.h>
    5253#include <QtTest/qtestmouse.h>
     54#endif
    5355#include <QtTest/qtestsystem.h>
    5456
     
    7274};
    7375
     76#ifdef QT_GUI_LIB
    7477class QTestKeyEvent: public QTestEvent
    7578{
     
    136139    int _delay;
    137140};
     141#endif //QT_GUI_LIB
     142
    138143
    139144class QTestDelayEvent: public QTestEvent
     
    160165    { qDeleteAll(*this); QList<QTestEvent *>::clear(); }
    161166
     167#ifdef QT_GUI_LIB
    162168    inline void addKeyClick(Qt::Key qtKey, Qt::KeyboardModifiers modifiers = Qt::NoModifier, int msecs = -1)
    163169    { addKeyEvent(QTest::Click, qtKey, modifiers, msecs); }
     
    195201    inline void addMouseMove(QPoint pos = QPoint(), int delay=-1)
    196202    { append(new QTestMouseEvent(QTest::MouseMove, Qt::NoButton, 0, pos, delay)); }
     203#endif //QT_GUI_LIB
    197204
    198205    inline void addDelay(int msecs)
  • trunk/src/testlib/qtesteventloop.h

    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**
  • trunk/src/testlib/qtestkeyboard.h

    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**
    4040****************************************************************************/
    4141
    42 #ifndef QTESTKEYBOARD_H
     42#if !defined(QTESTKEYBOARD_H)
    4343#define QTESTKEYBOARD_H
    4444
  • trunk/src/testlib/qtestlog.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**
     
    4747#include "QtTest/private/qplaintestlogger_p.h"
    4848#include "QtTest/private/qxmltestlogger_p.h"
    49 
    5049#include <QtCore/qatomic.h>
    5150#include <QtCore/qbytearray.h>
     
    5453#include <string.h>
    5554#include <limits.h>
     55
     56
     57#include "qtestlogger_p.h"
    5658
    5759QT_BEGIN_NAMESPACE
     
    8486
    8587    static QTestLog::LogMode logMode = QTestLog::Plain;
     88    static QTestLog::FlushMode flushMode = QTestLog::NoFlush;
    8689    static int verbosity = 0;
    8790    static int maxWarnings = 2002;
     
    137140            if (!counter.deref()) {
    138141                QTest::testLogger->addMessage(QAbstractTestLogger::QSystem,
    139                         "Maximum amount of warnings exceeded.");
     142                        "Maximum amount of warnings exceeded. Use -maxwarnings to override.");
    140143                return;
    141144            }
     
    271274
    272275    switch (QTest::logMode) {
    273     case QTestLog::Plain:
    274         QTest::testLogger = new QPlainTestLogger();
    275         break;
    276     case QTestLog::XML:
    277         QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete);
    278         break;
    279     case QTestLog::LightXML:
    280         QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light);
    281     }
     276        case QTestLog::Plain:
     277            QTest::testLogger = new QPlainTestLogger;
     278            break;
     279        case QTestLog::XML:{
     280            if(QTest::flushMode == QTestLog::FLushOn)
     281                QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Complete);
     282            else
     283                QTest::testLogger = new QTestLogger(QTestLogger::TLF_XML);
     284            break;
     285        }case QTestLog::LightXML:{
     286            if(QTest::flushMode == QTestLog::FLushOn)
     287                QTest::testLogger = new QXmlTestLogger(QXmlTestLogger::Light);
     288            else
     289                QTest::testLogger = new QTestLogger(QTestLogger::TLF_LightXml);
     290            break;
     291        }case QTestLog::XunitXML:
     292            QTest::testLogger = new QTestLogger(QTestLogger::TLF_XunitXml);
     293        }
    282294
    283295    QTest::testLogger->startLogging();
     
    298310void QTestLog::warn(const char *msg)
    299311{
     312    QTEST_ASSERT(QTest::testLogger);
    300313    QTEST_ASSERT(msg);
    301314
     
    308321
    309322    if (QTest::testLogger)
    310     QTest::testLogger->addMessage(QAbstractTestLogger::Info, msg, file, line);
     323        QTest::testLogger->addMessage(QAbstractTestLogger::Info, msg, file, line);
    311324}
    312325
     
    362375}
    363376
     377void QTestLog::setFlushMode(FlushMode mode)
     378{
     379    QTest::flushMode = mode;
     380}
     381
    364382QT_END_NAMESPACE
  • trunk/src/testlib/qtestlog_p.h

    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**
     
    6363{
    6464public:
    65     enum LogMode { Plain = 0, XML, LightXML };
     65    enum LogMode { Plain = 0, XML, LightXML, XunitXML };
     66    enum FlushMode { NoFlush = 0, FLushOn };
    6667
    6768    static void enterTestFunction(const char* function);
     
    9697    static void setMaxWarnings(int max);
    9798
     99    static void setFlushMode(FlushMode mode);
     100
    98101private:
    99102    QTestLog();
  • trunk/src/testlib/qtestmouse.h

    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**
    4040****************************************************************************/
    4141
    42 #ifndef QTESTMOUSE_H
     42#if !defined(QTESTMOUSE_H)
    4343#define QTESTMOUSE_H
    4444
     
    114114        }
    115115        QSpontaneKeyEvent::setSpontaneous(&me);
    116         if (!qApp->notify(widget, &me))
    117             QTest::qWarn("Mouse event not accepted by receiving widget");
     116        if (!qApp->notify(widget, &me)) {
     117            static const char *mouseActionNames[] =
     118                { "MousePress", "MouseRelease", "MouseClick", "MouseDClick", "MouseMove" };
     119            QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
     120            QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toAscii().data());
     121        }
    118122
    119123    }
  • trunk/src/testlib/qtestresult.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**
     
    6969    static const char *expectFailComment = 0;
    7070    static int expectFailMode = 0;
    71 };
     71}
    7272
    7373void QTestResult::reset()
  • trunk/src/testlib/qtestresult_p.h

    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**
  • trunk/src/testlib/qtestspontaneevent.h

    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**
     
    7575{
    7676public:
    77     void setSpontaneous() { spont = 1; };
    78     bool spontaneous() { return spont; };
    79     virtual void dummyFunc() {  };
     77    void setSpontaneous() { spont = 1; }
     78    bool spontaneous() { return spont; }
     79    virtual void dummyFunc() {}
    8080    virtual ~QSpontaneKeyEvent() {}
    8181
  • trunk/src/testlib/qtestsystem.h

    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**
     
    5353QT_MODULE(Test)
    5454
     55class QWidget;
     56#ifdef Q_WS_X11
     57extern void qt_x11_wait_for_window_manager(QWidget *w);
     58#endif
     59
    5560namespace QTest
    5661{
     
    6671        } while (timer.elapsed() < ms);
    6772    }
     73
     74    inline static bool qWaitForWindowShown(QWidget *window)
     75    {
     76#if defined(Q_WS_X11)
     77        qt_x11_wait_for_window_manager(window);
     78        QCoreApplication::processEvents();
     79#elif defined(Q_WS_QWS)
     80        Q_UNUSED(window);
     81        qWait(100);
     82#else
     83        Q_UNUSED(window);
     84        qWait(50);
     85#endif
     86        return true;
     87    }
     88
    6889}
    6990
  • trunk/src/testlib/qtesttable.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**
  • trunk/src/testlib/qtesttable_p.h

    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**
  • trunk/src/testlib/qxmltestlogger.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**
     
    4747#include "QtTest/private/qtestresult_p.h"
    4848#include "QtTest/private/qbenchmark_p.h"
     49#include "QtTest/qtestcase.h"
    4950
    5051QT_BEGIN_NAMESPACE
     
    9192
    9293
    93 QXmlTestLogger::QXmlTestLogger(XmlMode mode ):
    94     xmlmode(mode)
     94QXmlTestLogger::QXmlTestLogger(XmlMode mode )
     95    :xmlmode(mode)
    9596{
    9697
     
    99100QXmlTestLogger::~QXmlTestLogger()
    100101{
    101 
    102 }
    103 
     102}
    104103
    105104void QXmlTestLogger::startLogging()
    106105{
    107106    QAbstractTestLogger::startLogging();
    108     char buf[1024];
     107    QTestCharBuffer buf;
    109108
    110109    if (xmlmode == QXmlTestLogger::Complete) {
    111         QTest::qt_snprintf(buf, sizeof(buf),
     110        QTestCharBuffer quotedTc;
     111        xmlQuote(&quotedTc, QTestResult::currentTestObjectName());
     112        QTest::qt_asprintf(&buf,
    112113                "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
    113                 "<TestCase name=\"%s\">\n", QTestResult::currentTestObjectName());
    114         outputString(buf);
    115     }
    116 
    117     QTest::qt_snprintf(buf, sizeof(buf),
     114                "<TestCase name=\"%s\">\n", quotedTc.constData());
     115        outputString(buf.constData());
     116    }
     117
     118    QTest::qt_asprintf(&buf,
    118119            "<Environment>\n"
    119120            "    <QtVersion>%s</QtVersion>\n"
    120121            "    <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n"
    121122            "</Environment>\n", qVersion());
    122     outputString(buf);
     123    outputString(buf.constData());
    123124}
    124125
     
    134135void QXmlTestLogger::enterTestFunction(const char *function)
    135136{
    136     char buf[1024];
    137     QTest::qt_snprintf(buf, sizeof(buf), "<TestFunction name=\"%s\">\n", function);
    138     outputString(buf);
     137    QTestCharBuffer buf;
     138    QTestCharBuffer quotedFunction;
     139    xmlQuote(&quotedFunction, function);
     140    QTest::qt_asprintf(&buf, "<TestFunction name=\"%s\">\n", quotedFunction.constData());
     141    outputString(buf.constData());
    139142}
    140143
     
    159162        else
    160163            return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
    161                    "    <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
    162                    "</Incident>\n";
     164                "    <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
     165                "</Incident>\n";
    163166    } else {
    164167        if (noTag)
    165168            return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
    166                    "    <Description><![CDATA[%s%s%s%s]]></Description>\n"
    167                    "</Incident>\n";
     169                "    <Description><![CDATA[%s%s%s%s]]></Description>\n"
     170                "</Incident>\n";
    168171        else
    169172            return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
    170                    "    <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
    171                    "    <Description><![CDATA[%s]]></Description>\n"
    172                    "</Incident>\n";
     173                "    <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
     174                "    <Description><![CDATA[%s]]></Description>\n"
     175                "</Incident>\n";
    173176    }
    174177}
     
    186189        else
    187190            return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
    188                    "    <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
    189                    "</Message>\n";
     191                "    <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
     192                "</Message>\n";
    190193    } else {
    191194        if (noTag)
    192195            return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
    193                    "    <Description><![CDATA[%s%s%s%s]]></Description>\n"
    194                    "</Message>\n";
     196                "    <Description><![CDATA[%s%s%s%s]]></Description>\n"
     197                "</Message>\n";
    195198        else
    196199            return "<Message type=\"%s\" file=\"%s\" line=\"%d\">\n"
    197                    "    <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
    198                    "    <Description><![CDATA[%s]]></Description>\n"
    199                    "</Message>\n";
     200                "    <DataTag><![CDATA[%s%s%s]]></DataTag>\n"
     201                "    <Description><![CDATA[%s]]></Description>\n"
     202                "</Message>\n";
    200203    }
    201204}
     
    204207
    205208void QXmlTestLogger::addIncident(IncidentTypes type, const char *description,
    206                                  const char *file, int line)
    207 {
    208     char buf[1536];
     209                                const char *file, int line)
     210{
     211    QTestCharBuffer buf;
    209212    const char *tag = QTestResult::currentDataTag();
    210213    const char *gtag = QTestResult::currentGlobalDataTag();
     
    212215    const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
    213216
    214     QTest::qt_snprintf(buf, sizeof(buf),
     217    QTestCharBuffer quotedFile;
     218    QTestCharBuffer cdataGtag;
     219    QTestCharBuffer cdataTag;
     220    QTestCharBuffer cdataDescription;
     221
     222    xmlQuote(&quotedFile, file);
     223    xmlCdata(&cdataGtag, gtag);
     224    xmlCdata(&cdataTag, tag);
     225    xmlCdata(&cdataDescription, description);
     226
     227    QTest::qt_asprintf(&buf,
    215228            QTest::incidentFormatString(QTest::isEmpty(description), notag),
    216229            QTest::xmlIncidentType2String(type),
    217             file ? file : "", line,
    218             gtag ? gtag : "",
     230            quotedFile.constData(), line,
     231            cdataGtag.constData(),
    219232            filler,
    220             tag ? tag : "",
    221             description ? description : "");
    222 
    223     outputString(buf);
     233            cdataTag.constData(),
     234            cdataDescription.constData());
     235
     236    outputString(buf.constData());
    224237}
    225238
    226239void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result)
    227240{
    228     char buf[1536];
    229     QTest::qt_snprintf(
    230         buf, sizeof(buf),
     241    QTestCharBuffer buf;
     242    QTestCharBuffer quotedMetric;
     243    QTestCharBuffer quotedTag;
     244
     245    xmlQuote(&quotedMetric,
     246        QBenchmarkGlobalData::current->measurer->metricText().toAscii().constData());
     247    xmlQuote(&quotedTag, result.context.tag.toAscii().constData());
     248
     249    QTest::qt_asprintf(
     250        &buf,
    231251        QTest::benchmarkResultFormatString(),
    232         QBenchmarkGlobalData::current->measurer->metricText().toAscii().data(),
    233         result.context.tag.toAscii().data(),
     252        quotedMetric.constData(),
     253        quotedTag.constData(),
    234254        QByteArray::number(result.value).constData(),  //no 64-bit qt_snprintf support
    235         result.iterations); 
    236     outputString(buf);
     255        result.iterations);
     256    outputString(buf.constData());
    237257}
    238258
     
    240260                                const char *file, int line)
    241261{
    242     char buf[1536];
    243     char msgbuf[1024];
     262    QTestCharBuffer buf;
    244263    const char *tag = QTestResult::currentDataTag();
    245264    const char *gtag = QTestResult::currentGlobalDataTag();
     
    247266    const bool notag = QTest::isEmpty(tag) && QTest::isEmpty(gtag);
    248267
    249     QTest::qt_snprintf(msgbuf, sizeof(msgbuf), "%s",
    250                         message ? message : "");
    251 
    252     QTest::qt_snprintf(buf, sizeof(buf),
     268    QTestCharBuffer quotedFile;
     269    QTestCharBuffer cdataGtag;
     270    QTestCharBuffer cdataTag;
     271    QTestCharBuffer cdataDescription;
     272
     273    xmlQuote(&quotedFile, file);
     274    xmlCdata(&cdataGtag, gtag);
     275    xmlCdata(&cdataTag, tag);
     276    xmlCdata(&cdataDescription, message);
     277
     278    QTest::qt_asprintf(&buf,
    253279            QTest::messageFormatString(QTest::isEmpty(message), notag),
    254280            QTest::xmlMessageType2String(type),
    255             file ? file : "", line,
    256             gtag ? gtag : "",
     281            quotedFile.constData(), line,
     282            cdataGtag.constData(),
    257283            filler,
    258             tag ? tag : "",
    259             msgbuf);
    260 
    261     outputString(buf);
     284            cdataTag.constData(),
     285            cdataDescription.constData());
     286
     287    outputString(buf.constData());
     288}
     289
     290/*
     291    Copy up to n characters from the src string into dest, escaping any special
     292    XML characters as necessary so that dest is suitable for use in an XML
     293    quoted attribute string.
     294*/
     295int QXmlTestLogger::xmlQuote(QTestCharBuffer* destBuf, char const* src, size_t n)
     296{
     297    if (n == 0) return 0;
     298
     299    char *dest = destBuf->data();
     300    *dest = 0;
     301    if (!src) return 0;
     302
     303    char* begin = dest;
     304    char* end = dest + n;
     305
     306    while (dest < end) {
     307        switch (*src) {
     308
     309#define MAP_ENTITY(chr, ent) \
     310            case chr:                                   \
     311                if (dest + sizeof(ent) < end) {         \
     312                    strcpy(dest, ent);                  \
     313                    dest += sizeof(ent) - 1;            \
     314                }                                       \
     315                else {                                  \
     316                    *dest = 0;                          \
     317                    return (dest+sizeof(ent)-begin);    \
     318                }                                       \
     319                ++src;                                  \
     320                break;
     321
     322            MAP_ENTITY('>', "&gt;");
     323            MAP_ENTITY('<', "&lt;");
     324            MAP_ENTITY('\'', "&apos;");
     325            MAP_ENTITY('"', "&quot;");
     326            MAP_ENTITY('&', "&amp;");
     327
     328            // not strictly necessary, but allows handling of comments without
     329            // having to explicitly look for `--'
     330            MAP_ENTITY('-', "&#x002D;");
     331
     332#undef MAP_ENTITY
     333
     334            case 0:
     335                *dest = 0;
     336                return (dest-begin);
     337
     338            default:
     339                *dest = *src;
     340                ++dest;
     341                ++src;
     342                break;
     343        }
     344    }
     345
     346    // If we get here, dest was completely filled (dest == end)
     347    *(dest-1) = 0;
     348    return (dest-begin);
     349}
     350
     351/*
     352    Copy up to n characters from the src string into dest, escaping any
     353    special strings such that dest is suitable for use in an XML CDATA section.
     354*/
     355int QXmlTestLogger::xmlCdata(QTestCharBuffer *destBuf, char const* src, size_t n)
     356{
     357    if (!n) return 0;
     358
     359    char *dest = destBuf->data();
     360
     361    if (!src || n == 1) {
     362        *dest = 0;
     363        return 0;
     364    }
     365
     366    static char const CDATA_END[] = "]]>";
     367    static char const CDATA_END_ESCAPED[] = "]]]><![CDATA[]>";
     368
     369    char* begin = dest;
     370    char* end = dest + n;
     371    while (dest < end) {
     372        if (!*src) {
     373            *dest = 0;
     374            return (dest-begin);
     375        }
     376
     377        if (!strncmp(src, CDATA_END, sizeof(CDATA_END)-1)) {
     378            if (dest + sizeof(CDATA_END_ESCAPED) < end) {
     379                strcpy(dest, CDATA_END_ESCAPED);
     380                src += sizeof(CDATA_END)-1;
     381                dest += sizeof(CDATA_END_ESCAPED) - 1;
     382            }
     383            else {
     384                *dest = 0;
     385                return (dest+sizeof(CDATA_END_ESCAPED)-begin);
     386            }
     387            continue;
     388        }
     389
     390        *dest = *src;
     391        ++src;
     392        ++dest;
     393    }
     394
     395    // If we get here, dest was completely filled (dest == end)
     396    *(dest-1) = 0;
     397    return (dest-begin);
     398}
     399
     400typedef int (*StringFormatFunction)(QTestCharBuffer*,char const*,size_t);
     401
     402/*
     403    A wrapper for string functions written to work with a fixed size buffer so they can be called
     404    with a dynamically allocated buffer.
     405*/
     406int allocateStringFn(QTestCharBuffer* str, char const* src, StringFormatFunction func)
     407{
     408    static const int MAXSIZE = 1024*1024*2;
     409
     410    int size = str->size();
     411
     412    int res = 0;
     413
     414    for (;;) {
     415        res = func(str, src, size);
     416        str->data()[size - 1] = '\0';
     417        if (res < size) {
     418            // We succeeded or fatally failed
     419            break;
     420        }
     421        // buffer wasn't big enough, try again
     422        size *= 2;
     423        if (size > MAXSIZE) {
     424            break;
     425        }
     426        if (!str->reset(size))
     427            break; // ran out of memory - bye
     428    }
     429
     430    return res;
     431}
     432
     433int QXmlTestLogger::xmlQuote(QTestCharBuffer* str, char const* src)
     434{
     435    return allocateStringFn(str, src, QXmlTestLogger::xmlQuote);
     436}
     437
     438int QXmlTestLogger::xmlCdata(QTestCharBuffer* str, char const* src)
     439{
     440    return allocateStringFn(str, src, QXmlTestLogger::xmlCdata);
    262441}
    263442
  • trunk/src/testlib/qxmltestlogger_p.h

    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**
     
    8080                    const char *file = 0, int line = 0);
    8181
     82    static int xmlCdata(QTestCharBuffer *dest, char const* src);
     83    static int xmlQuote(QTestCharBuffer *dest, char const* src);
     84    static int xmlCdata(QTestCharBuffer *dest, char const* src, size_t n);
     85    static int xmlQuote(QTestCharBuffer *dest, char const* src, size_t n);
     86
    8287private:
    8388    XmlMode xmlmode;
  • trunk/src/testlib/testlib.pro

    r2 r561  
    1 TARGET   = QtTest
     1TARGET = QtTest
    22QPRO_PWD = $$PWD
    3 QT       = core
     3QT = core
    44INCLUDEPATH += .
    5 
    6 unix:!embedded {
    7    QMAKE_PKGCONFIG_DESCRIPTION = Qt Unit Testing Library
    8    QMAKE_PKGCONFIG_REQUIRES = QtCore
    9 }
     5unix:!embedded:QMAKE_PKGCONFIG_DESCRIPTION = Qt \
     6    Unit \
     7    Testing \
     8    Library
    109
    1110# Input
    12 HEADERS = qtest_global.h qtestcase.h qtestdata.h qtesteventloop.h
    13 SOURCES = qtestcase.cpp qtestlog.cpp qtesttable.cpp qtestdata.cpp qtestresult.cpp qasciikey.cpp qplaintestlogger.cpp qxmltestlogger.cpp qsignaldumper.cpp qabstracttestlogger.cpp qbenchmark.cpp qbenchmarkmeasurement.cpp qbenchmarkvalgrind.cpp qbenchmarkevent.cpp
    14 
    15 DEFINES += QT_NO_CAST_TO_ASCII QT_NO_CAST_FROM_ASCII QTESTLIB_MAKEDLL QT_NO_DATASTREAM
    16 
    17 wince*:{
    18    LIBS += libcmt.lib corelibc.lib ole32.lib oleaut32.lib uuid.lib commctrl.lib coredll.lib winsock.lib
    19 }
    20 
    21 mac {
    22     LIBS += -framework IOKit -framework Security
    23 }
    24 
     11HEADERS = qbenchmark.h \
     12    qsignalspy.h \
     13    qtestaccessible.h \
     14    qtestassert.h \
     15    qtestbasicstreamer.h \
     16    qtestcase.h \
     17    qtestcoreelement.h \
     18    qtestcorelist.h \
     19    qtestdata.h \
     20    qtestelementattribute.h \
     21    qtestelement.h \
     22    qtestevent.h \
     23    qtesteventloop.h \
     24    qtestfilelogger.h \
     25    qtest_global.h \
     26    qtest_gui.h \
     27    qtest.h \
     28    qtestkeyboard.h \
     29    qtestlightxmlstreamer.h \
     30    qtestmouse.h \
     31    qtestspontaneevent.h \
     32    qtestsystem.h \
     33    qtesttouch.h \
     34    qtestxmlstreamer.h \
     35    qtestxunitstreamer.h
     36SOURCES = qtestcase.cpp \
     37    qtestlog.cpp \
     38    qtesttable.cpp \
     39    qtestdata.cpp \
     40    qtestresult.cpp \
     41    qasciikey.cpp \
     42    qplaintestlogger.cpp \
     43    qxmltestlogger.cpp \
     44    qsignaldumper.cpp \
     45    qabstracttestlogger.cpp \
     46    qbenchmark.cpp \
     47    qbenchmarkmeasurement.cpp \
     48    qbenchmarkvalgrind.cpp \
     49    qbenchmarkevent.cpp \
     50    qtestelement.cpp \
     51    qtestelementattribute.cpp \
     52    qtestbasicstreamer.cpp \
     53    qtestxunitstreamer.cpp \
     54    qtestxmlstreamer.cpp \
     55    qtestlightxmlstreamer.cpp \
     56    qtestlogger.cpp \
     57    qtestfilelogger.cpp
     58DEFINES *= QT_NO_CAST_TO_ASCII \
     59    QT_NO_CAST_FROM_ASCII \
     60    QTESTLIB_MAKEDLL \
     61    QT_NO_DATASTREAM
     62embedded:QMAKE_CXXFLAGS += -fno-rtti
     63wince*::LIBS += libcmt.lib \
     64    corelibc.lib \
     65    ole32.lib \
     66    oleaut32.lib \
     67    uuid.lib \
     68    commctrl.lib \
     69    coredll.lib \
     70    winsock.lib
     71mac:LIBS += -framework IOKit \
     72    -framework ApplicationServices \
     73    -framework Security
    2574include(../qbase.pri)
    2675QMAKE_TARGET_PRODUCT = QTestLib
    27 QMAKE_TARGET_DESCRIPTION = Qt Unit Testing Library
     76QMAKE_TARGET_DESCRIPTION = Qt \
     77    Unit \
     78    Testing \
     79    Library
     80symbian:TARGET.UID3=0x2001B2DF
Note: See TracChangeset for help on using the changeset viewer.