From 7f3c9feaaf67ce7e89cd2f9df2155c61a58acaed Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 26 Feb 2010 15:02:56 +0100 Subject: Rename the files too --- src/corelib/tools/qelapsedtimer.cpp | 65 ++++++++++ src/corelib/tools/qelapsedtimer.h | 85 +++++++++++++ src/corelib/tools/qelapsedtimer_generic.cpp | 91 +++++++++++++ src/corelib/tools/qelapsedtimer_mac.cpp | 115 +++++++++++++++++ src/corelib/tools/qelapsedtimer_symbian.cpp | 106 ++++++++++++++++ src/corelib/tools/qelapsedtimer_unix.cpp | 169 +++++++++++++++++++++++++ src/corelib/tools/qelapsedtimer_win.cpp | 129 +++++++++++++++++++ src/corelib/tools/qtimestamp.cpp | 65 ---------- src/corelib/tools/qtimestamp.h | 85 ------------- src/corelib/tools/qtimestamp_generic.cpp | 91 ------------- src/corelib/tools/qtimestamp_mac.cpp | 115 ----------------- src/corelib/tools/qtimestamp_symbian.cpp | 106 ---------------- src/corelib/tools/qtimestamp_unix.cpp | 169 ------------------------- src/corelib/tools/qtimestamp_win.cpp | 129 ------------------- tests/auto/qelapsedtimer/qelapsedtimer.pro | 13 ++ tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp | 94 ++++++++++++++ tests/auto/qtimestamp/qtimestamp.pro | 13 -- tests/auto/qtimestamp/tst_qtimestamp.cpp | 94 -------------- 18 files changed, 867 insertions(+), 867 deletions(-) create mode 100644 src/corelib/tools/qelapsedtimer.cpp create mode 100644 src/corelib/tools/qelapsedtimer.h create mode 100644 src/corelib/tools/qelapsedtimer_generic.cpp create mode 100644 src/corelib/tools/qelapsedtimer_mac.cpp create mode 100644 src/corelib/tools/qelapsedtimer_symbian.cpp create mode 100644 src/corelib/tools/qelapsedtimer_unix.cpp create mode 100644 src/corelib/tools/qelapsedtimer_win.cpp delete mode 100644 src/corelib/tools/qtimestamp.cpp delete mode 100644 src/corelib/tools/qtimestamp.h delete mode 100644 src/corelib/tools/qtimestamp_generic.cpp delete mode 100644 src/corelib/tools/qtimestamp_mac.cpp delete mode 100644 src/corelib/tools/qtimestamp_symbian.cpp delete mode 100644 src/corelib/tools/qtimestamp_unix.cpp delete mode 100644 src/corelib/tools/qtimestamp_win.cpp create mode 100644 tests/auto/qelapsedtimer/qelapsedtimer.pro create mode 100644 tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp delete mode 100644 tests/auto/qtimestamp/qtimestamp.pro delete mode 100644 tests/auto/qtimestamp/tst_qtimestamp.cpp diff --git a/src/corelib/tools/qelapsedtimer.cpp b/src/corelib/tools/qelapsedtimer.cpp new file mode 100644 index 0000000..220b108 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer.cpp @@ -0,0 +1,65 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" + +QT_BEGIN_NAMESPACE + +static const qint64 invalidData = Q_INT64_C(0x8000000000000000); + +void QElapsedTimer::invalidate() +{ + t1 = t2 = invalidData; +} + +bool QElapsedTimer::isValid() const +{ + return t1 != invalidData && t2 != invalidData; +} + +bool QElapsedTimer::hasExpired(qint64 timeout) const +{ + // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be + // considered as never expired + return quint64(elapsed()) > quint64(timeout); +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer.h b/src/corelib/tools/qelapsedtimer.h new file mode 100644 index 0000000..4fa0ca5 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTIMESTAMP_H +#define QTIMESTAMP_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Core) + +class Q_CORE_EXPORT QElapsedTimer +{ +public: + static bool isMonotonic(); + + void start(); + qint64 restart(); + void invalidate(); + bool isValid() const; + + qint64 elapsed() const; + bool hasExpired(qint64 timeout) const; + + qint64 msecsTo(const QElapsedTimer &other) const; + qint64 secsTo(const QElapsedTimer &other) const; + + bool operator==(const QElapsedTimer &other) const + { return t1 == other.t1 && t2 == other.t2; } + bool operator!=(const QElapsedTimer &other) const + { return !(*this == other); } + + friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2); + +private: + qint64 t1; + qint64 t2; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QTIMESTAMP_H diff --git a/src/corelib/tools/qelapsedtimer_generic.cpp b/src/corelib/tools/qelapsedtimer_generic.cpp new file mode 100644 index 0000000..a9c2233 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_generic.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include "qdatetime.h" + +QT_BEGIN_NAMESPACE + +bool QElapsedTimer::isMonotonic() +{ + return false; +} + +void QElapsedTimer::start() +{ + QTime t = QTime::currentTime(); + t1 = t.mds; + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + QTime t = QTime::currentTime(); + qint64 old = t1; + t1 = t.mds; + return t1 - old; +} + +qint64 QElapsedTimer::elapsed() const +{ + QTime t = QTime::currentTime(); + return t.mds - t1; +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + qint64 diff = other.t1 - t1; + if (diff < 0) // passed midnight + diff += 86400 * 1000; + return diff; +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return v1.t1 < v2.t1; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_mac.cpp b/src/corelib/tools/qelapsedtimer_mac.cpp new file mode 100644 index 0000000..21a6d1b --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_mac.cpp @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +bool QElapsedTimer::isMonotonic() +{ + return true; +} + +static mach_timebase_info_data_t info = {0,0}; +static qint64 absoluteToNSecs(qint64 cpuTime) +{ + if (info.denom == 0) + mach_timebase_info(&info); + qint64 nsecs = cpuTime * info.numer / info.denom; + return nsecs; +} + +static qint64 absoluteToMSecs(qint64 cpuTime) +{ + return absoluteToNSecs(cpuTime) / 1000000; +} + +timeval qt_gettime() +{ + timeval tv; + + uint64_t cpu_time = mach_absolute_time(); + uint64_t nsecs = absoluteToNSecs(cpu_time); + tv.tv_sec = nsecs / 1000000000ull; + tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); + return tv; +} + +void QElapsedTimer::start() +{ + t1 = mach_absolute_time(); + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + qint64 old = t1; + t1 = mach_absolute_time(); + + return absoluteToMSecs(t1 - old); +} + +qint64 QElapsedTimer::elapsed() const +{ + uint64_t cpu_time = mach_absolute_time(); + return absoluteToMSecs(cpu_time - t1); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + return absoluteToMSecs(other.t1 - t1); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return v1.t1 < v2.t1; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_symbian.cpp b/src/corelib/tools/qelapsedtimer_symbian.cpp new file mode 100644 index 0000000..1fbba65 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_symbian.cpp @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include + +QT_BEGIN_NAMESPACE + +// return quint64 to avoid sign-extension +static quint64 getMillisecondFromTick() +{ + static TInt nanokernel_tick_period; + if (!nanokernel_tick_period) + HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); + return nanokernel_tick_period * User::NTickCount(); +} + +static qint64 difference(qint64 a, qint64 b) +{ + qint64 retval = a - b; + // there can be 32-bit rollover + // assume there were rollovers if the difference is negative by more than + // 75% of the 32-bit range + + if (retval < Q_INT64_C(-0xc0000000)) + retval += Q_UINT64_C(0x100000000); + return retval; +} + +bool QElapsedTimer::isMonotonic() +{ + return true; +} + +void QElapsedTimer::start() +{ + t1 = getMillisecondFromTick(); + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + qint64 oldt1 = t1; + t1 = getMillisecondFromTick(); + return difference(t1, oldt1); +} + +qint64 QElapsedTimer::elapsed() const +{ + return difference(getMillisecondFromTick(), t1); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + return difference(other.t1, t1); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return difference(v1.t1, v2.t1) < 0; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_unix.cpp b/src/corelib/tools/qelapsedtimer_unix.cpp new file mode 100644 index 0000000..b8215f4 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_unix.cpp @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include "qpair.h" +#include +#include +#include + +#if !defined(QT_NO_CLOCK_MONOTONIC) +# if defined(QT_BOOTSTRAPPED) +# define QT_NO_CLOCK_MONOTONIC +# endif +#endif + +QT_BEGIN_NAMESPACE + +static qint64 fractionAdjustment() +{ + if (QElapsedTimer::isMonotonic()) { + // the monotonic timer is measured in nanoseconds + // 1 ms = 1000000 ns + return 1000*1000ull; + } else { + // gettimeofday is measured in microseconds + // 1 ms = 1000 us + return 1000; + } +} + +bool QElapsedTimer::isMonotonic() +{ +#if (_POSIX_MONOTONIC_CLOCK-0 > 0) + return true; +#else + static int returnValue = 0; + + if (returnValue == 0) { +# if (_POSIX_MONOTONIC_CLOCK-0 < 0) + returnValue = -1; +# elif (_POSIX_MONOTONIC_CLOCK == 0) + // detect if the system support monotonic timers + long x = sysconf(_SC_MONOTONIC_CLOCK); + returnValue = (x >= 200112L) ? 1 : -1; +# endif + } + + return returnValue != -1; +#endif +} + +static inline QPair do_gettime() +{ +#if (_POSIX_MONOTONIC_CLOCK-0 > 0) + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return qMakePair(ts.tv_sec, ts.tv_nsec); +#else +# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) + if (QElapsedTimer::isMonotonic()) { + timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return qMakePair(ts.tv_sec, ts.tv_nsec); + } +# endif + // use gettimeofday + timeval tv; + ::gettimeofday(&tv, 0); + return qMakePair(tv.tv_sec, tv.tv_usec); +#endif +} + +// used in qcore_unix.cpp and qeventdispatcher_unix.cpp +timeval qt_gettime() +{ + QPair r = do_gettime(); + + timeval tv; + tv.tv_sec = r.first; + tv.tv_usec = r.second; + if (QElapsedTimer::isMonotonic()) + tv.tv_usec /= 1000; + + return tv; +} + +void QElapsedTimer::start() +{ + QPair r = do_gettime(); + t1 = r.first; + t2 = r.second; +} + +qint64 QElapsedTimer::restart() +{ + QPair r = do_gettime(); + qint64 oldt1 = t1; + qint64 oldt2 = t2; + t1 = r.first; + t2 = r.second; + + r.first -= oldt1; + r.second -= oldt2; + return r.first * 1000 + r.second / fractionAdjustment(); +} + +qint64 QElapsedTimer::elapsed() const +{ + QElapsedTimer now; + now.start(); + return msecsTo(now); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + qint64 secs = other.t1 - t1; + qint64 fraction = other.t2 - t2; + return secs * 1000 + fraction / fractionAdjustment(); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return other.t1 - t1; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qelapsedtimer_win.cpp b/src/corelib/tools/qelapsedtimer_win.cpp new file mode 100644 index 0000000..e384dd8 --- /dev/null +++ b/src/corelib/tools/qelapsedtimer_win.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qelapsedtimer.h" +#include + +typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); +static PtrGetTickCount64 ptrGetTickCount64 = 0; + +QT_BEGIN_NAMESPACE + +static void resolveLibs() +{ + static bool done = false; + if (done) + return; + + // try to get GetTickCount64 from the system + HMODULE kernel32 = GetModuleHandleW(L"kernel32"); + if (!kernel32) + return; + +#if defined(Q_OS_WINCE) + // does this function exist on WinCE, or will ever exist? + ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, L"GetTickCount64"); +#else + ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64"); +#endif + + done = true; +} + +static quint64 getTickCount() +{ + resolveLibs(); + if (ptrGetTickCount64) + return ptrGetTickCount64(); + return GetTickCount(); +} + +static qint64 difference(qint64 a, qint64 b) +{ + qint64 retval = a - b; + // if we're not using GetTickCount64, then there can be 32-bit rollover + // assume there were rollovers if the difference is negative by more than + // 75% of the 32-bit range + + if (!ptrGetTickCount64 && retval < Q_INT64_C(-0xc0000000)) + retval += Q_UINT64_C(0x100000000); + return retval; +} + +bool QElapsedTimer::isMonotonic() +{ + return true; +} + +void QElapsedTimer::start() +{ + t1 = getTickCount(); + t2 = 0; +} + +qint64 QElapsedTimer::restart() +{ + qint64 oldt1 = t1; + t1 = getTickCount(); + return difference(t1, oldt1); +} + +qint64 QElapsedTimer::elapsed() const +{ + return difference(getTickCount(), t1); +} + +qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const +{ + return difference(other.t1, t1); +} + +qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const +{ + return msecsTo(other) / 1000; +} + +bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) +{ + return difference(v1.t1, v2.t1) < 0; +} + +QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp.cpp b/src/corelib/tools/qtimestamp.cpp deleted file mode 100644 index 220b108..0000000 --- a/src/corelib/tools/qtimestamp.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" - -QT_BEGIN_NAMESPACE - -static const qint64 invalidData = Q_INT64_C(0x8000000000000000); - -void QElapsedTimer::invalidate() -{ - t1 = t2 = invalidData; -} - -bool QElapsedTimer::isValid() const -{ - return t1 != invalidData && t2 != invalidData; -} - -bool QElapsedTimer::hasExpired(qint64 timeout) const -{ - // if timeout is -1, quint64(timeout) is LLINT_MAX, so this will be - // considered as never expired - return quint64(elapsed()) > quint64(timeout); -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp.h b/src/corelib/tools/qtimestamp.h deleted file mode 100644 index 4fa0ca5..0000000 --- a/src/corelib/tools/qtimestamp.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTIMESTAMP_H -#define QTIMESTAMP_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Core) - -class Q_CORE_EXPORT QElapsedTimer -{ -public: - static bool isMonotonic(); - - void start(); - qint64 restart(); - void invalidate(); - bool isValid() const; - - qint64 elapsed() const; - bool hasExpired(qint64 timeout) const; - - qint64 msecsTo(const QElapsedTimer &other) const; - qint64 secsTo(const QElapsedTimer &other) const; - - bool operator==(const QElapsedTimer &other) const - { return t1 == other.t1 && t2 == other.t2; } - bool operator!=(const QElapsedTimer &other) const - { return !(*this == other); } - - friend bool Q_CORE_EXPORT operator<(const QElapsedTimer &v1, const QElapsedTimer &v2); - -private: - qint64 t1; - qint64 t2; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QTIMESTAMP_H diff --git a/src/corelib/tools/qtimestamp_generic.cpp b/src/corelib/tools/qtimestamp_generic.cpp deleted file mode 100644 index a9c2233..0000000 --- a/src/corelib/tools/qtimestamp_generic.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include "qdatetime.h" - -QT_BEGIN_NAMESPACE - -bool QElapsedTimer::isMonotonic() -{ - return false; -} - -void QElapsedTimer::start() -{ - QTime t = QTime::currentTime(); - t1 = t.mds; - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - QTime t = QTime::currentTime(); - qint64 old = t1; - t1 = t.mds; - return t1 - old; -} - -qint64 QElapsedTimer::elapsed() const -{ - QTime t = QTime::currentTime(); - return t.mds - t1; -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - qint64 diff = other.t1 - t1; - if (diff < 0) // passed midnight - diff += 86400 * 1000; - return diff; -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return v1.t1 < v2.t1; -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_mac.cpp b/src/corelib/tools/qtimestamp_mac.cpp deleted file mode 100644 index 21a6d1b..0000000 --- a/src/corelib/tools/qtimestamp_mac.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include -#include - -#include - -QT_BEGIN_NAMESPACE - -bool QElapsedTimer::isMonotonic() -{ - return true; -} - -static mach_timebase_info_data_t info = {0,0}; -static qint64 absoluteToNSecs(qint64 cpuTime) -{ - if (info.denom == 0) - mach_timebase_info(&info); - qint64 nsecs = cpuTime * info.numer / info.denom; - return nsecs; -} - -static qint64 absoluteToMSecs(qint64 cpuTime) -{ - return absoluteToNSecs(cpuTime) / 1000000; -} - -timeval qt_gettime() -{ - timeval tv; - - uint64_t cpu_time = mach_absolute_time(); - uint64_t nsecs = absoluteToNSecs(cpu_time); - tv.tv_sec = nsecs / 1000000000ull; - tv.tv_usec = (nsecs / 1000) - (tv.tv_sec * 1000000); - return tv; -} - -void QElapsedTimer::start() -{ - t1 = mach_absolute_time(); - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - qint64 old = t1; - t1 = mach_absolute_time(); - - return absoluteToMSecs(t1 - old); -} - -qint64 QElapsedTimer::elapsed() const -{ - uint64_t cpu_time = mach_absolute_time(); - return absoluteToMSecs(cpu_time - t1); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - return absoluteToMSecs(other.t1 - t1); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return v1.t1 < v2.t1; -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_symbian.cpp b/src/corelib/tools/qtimestamp_symbian.cpp deleted file mode 100644 index 1fbba65..0000000 --- a/src/corelib/tools/qtimestamp_symbian.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include - -QT_BEGIN_NAMESPACE - -// return quint64 to avoid sign-extension -static quint64 getMillisecondFromTick() -{ - static TInt nanokernel_tick_period; - if (!nanokernel_tick_period) - HAL::Get(HAL::ENanoTickPeriod, nanokernel_tick_period); - return nanokernel_tick_period * User::NTickCount(); -} - -static qint64 difference(qint64 a, qint64 b) -{ - qint64 retval = a - b; - // there can be 32-bit rollover - // assume there were rollovers if the difference is negative by more than - // 75% of the 32-bit range - - if (retval < Q_INT64_C(-0xc0000000)) - retval += Q_UINT64_C(0x100000000); - return retval; -} - -bool QElapsedTimer::isMonotonic() -{ - return true; -} - -void QElapsedTimer::start() -{ - t1 = getMillisecondFromTick(); - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - qint64 oldt1 = t1; - t1 = getMillisecondFromTick(); - return difference(t1, oldt1); -} - -qint64 QElapsedTimer::elapsed() const -{ - return difference(getMillisecondFromTick(), t1); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - return difference(other.t1, t1); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return difference(v1.t1, v2.t1) < 0; -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_unix.cpp b/src/corelib/tools/qtimestamp_unix.cpp deleted file mode 100644 index b8215f4..0000000 --- a/src/corelib/tools/qtimestamp_unix.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include "qpair.h" -#include -#include -#include - -#if !defined(QT_NO_CLOCK_MONOTONIC) -# if defined(QT_BOOTSTRAPPED) -# define QT_NO_CLOCK_MONOTONIC -# endif -#endif - -QT_BEGIN_NAMESPACE - -static qint64 fractionAdjustment() -{ - if (QElapsedTimer::isMonotonic()) { - // the monotonic timer is measured in nanoseconds - // 1 ms = 1000000 ns - return 1000*1000ull; - } else { - // gettimeofday is measured in microseconds - // 1 ms = 1000 us - return 1000; - } -} - -bool QElapsedTimer::isMonotonic() -{ -#if (_POSIX_MONOTONIC_CLOCK-0 > 0) - return true; -#else - static int returnValue = 0; - - if (returnValue == 0) { -# if (_POSIX_MONOTONIC_CLOCK-0 < 0) - returnValue = -1; -# elif (_POSIX_MONOTONIC_CLOCK == 0) - // detect if the system support monotonic timers - long x = sysconf(_SC_MONOTONIC_CLOCK); - returnValue = (x >= 200112L) ? 1 : -1; -# endif - } - - return returnValue != -1; -#endif -} - -static inline QPair do_gettime() -{ -#if (_POSIX_MONOTONIC_CLOCK-0 > 0) - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return qMakePair(ts.tv_sec, ts.tv_nsec); -#else -# if !defined(QT_NO_CLOCK_MONOTONIC) && !defined(QT_BOOTSTRAPPED) - if (QElapsedTimer::isMonotonic()) { - timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return qMakePair(ts.tv_sec, ts.tv_nsec); - } -# endif - // use gettimeofday - timeval tv; - ::gettimeofday(&tv, 0); - return qMakePair(tv.tv_sec, tv.tv_usec); -#endif -} - -// used in qcore_unix.cpp and qeventdispatcher_unix.cpp -timeval qt_gettime() -{ - QPair r = do_gettime(); - - timeval tv; - tv.tv_sec = r.first; - tv.tv_usec = r.second; - if (QElapsedTimer::isMonotonic()) - tv.tv_usec /= 1000; - - return tv; -} - -void QElapsedTimer::start() -{ - QPair r = do_gettime(); - t1 = r.first; - t2 = r.second; -} - -qint64 QElapsedTimer::restart() -{ - QPair r = do_gettime(); - qint64 oldt1 = t1; - qint64 oldt2 = t2; - t1 = r.first; - t2 = r.second; - - r.first -= oldt1; - r.second -= oldt2; - return r.first * 1000 + r.second / fractionAdjustment(); -} - -qint64 QElapsedTimer::elapsed() const -{ - QElapsedTimer now; - now.start(); - return msecsTo(now); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - qint64 secs = other.t1 - t1; - qint64 fraction = other.t2 - t2; - return secs * 1000 + fraction / fractionAdjustment(); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return other.t1 - t1; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return v1.t1 < v2.t1 || (v1.t1 == v2.t1 && v1.t2 < v2.t2); -} - -QT_END_NAMESPACE diff --git a/src/corelib/tools/qtimestamp_win.cpp b/src/corelib/tools/qtimestamp_win.cpp deleted file mode 100644 index e384dd8..0000000 --- a/src/corelib/tools/qtimestamp_win.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qelapsedtimer.h" -#include - -typedef ULONGLONG (WINAPI *PtrGetTickCount64)(void); -static PtrGetTickCount64 ptrGetTickCount64 = 0; - -QT_BEGIN_NAMESPACE - -static void resolveLibs() -{ - static bool done = false; - if (done) - return; - - // try to get GetTickCount64 from the system - HMODULE kernel32 = GetModuleHandleW(L"kernel32"); - if (!kernel32) - return; - -#if defined(Q_OS_WINCE) - // does this function exist on WinCE, or will ever exist? - ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, L"GetTickCount64"); -#else - ptrGetTickCount64 = (PtrGetTickCount64)GetProcAddress(kernel32, "GetTickCount64"); -#endif - - done = true; -} - -static quint64 getTickCount() -{ - resolveLibs(); - if (ptrGetTickCount64) - return ptrGetTickCount64(); - return GetTickCount(); -} - -static qint64 difference(qint64 a, qint64 b) -{ - qint64 retval = a - b; - // if we're not using GetTickCount64, then there can be 32-bit rollover - // assume there were rollovers if the difference is negative by more than - // 75% of the 32-bit range - - if (!ptrGetTickCount64 && retval < Q_INT64_C(-0xc0000000)) - retval += Q_UINT64_C(0x100000000); - return retval; -} - -bool QElapsedTimer::isMonotonic() -{ - return true; -} - -void QElapsedTimer::start() -{ - t1 = getTickCount(); - t2 = 0; -} - -qint64 QElapsedTimer::restart() -{ - qint64 oldt1 = t1; - t1 = getTickCount(); - return difference(t1, oldt1); -} - -qint64 QElapsedTimer::elapsed() const -{ - return difference(getTickCount(), t1); -} - -qint64 QElapsedTimer::msecsTo(const QElapsedTimer &other) const -{ - return difference(other.t1, t1); -} - -qint64 QElapsedTimer::secsTo(const QElapsedTimer &other) const -{ - return msecsTo(other) / 1000; -} - -bool operator<(const QElapsedTimer &v1, const QElapsedTimer &v2) -{ - return difference(v1.t1, v2.t1) < 0; -} - -QT_END_NAMESPACE diff --git a/tests/auto/qelapsedtimer/qelapsedtimer.pro b/tests/auto/qelapsedtimer/qelapsedtimer.pro new file mode 100644 index 0000000..3a06390 --- /dev/null +++ b/tests/auto/qelapsedtimer/qelapsedtimer.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +QT -= gui + +SOURCES += tst_qtimestamp.cpp +wince* { + DEFINES += SRCDIR=\\\"\\\" +} else:symbian { + # do not define SRCDIR at all + TARGET.EPOCHEAPSIZE = 0x100000 0x3000000 +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + diff --git a/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp new file mode 100644 index 0000000..79138ce --- /dev/null +++ b/tests/auto/qelapsedtimer/tst_qelapsedtimer.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +static const int minResolution = 50; // the minimum resolution for the tests + +class tst_QTimestamp : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void validity(); + void basics(); + void elapsed(); +}; + +void tst_QTimestamp::validity() +{ + QTimestamp t; + + t.invalidate(); + QVERIFY(!t.isValid()); + + t.start(); + QVERIFY(t.isValid()); + + t.invalidate(); + QVERIFY(!t.isValid()); +} + +void tst_QTimestamp::basics() +{ + QTimestamp t1; + t1.start(); + + QCOMPARE(t1, t1); + QVERIFY(!(t1 != t1)); + QVERIFY(!(t1 < t1)); + QCOMPARE(t1.msecsTo(t1), qint64(0)); + QCOMPARE(t1.secsTo(t1), qint64(0)); + QCOMPARE(t1 + 0, t1); + QCOMPARE(t1 - 0, t1); + + QTimestamp t2 = t1; + t2 += 1000; // so we can use secsTo + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + QVERIFY(!(t2 < t1)); + QCOMPARE(t1.msecsTo(t2), qint64(1000)); + QCOMPARE(t1.secsTo(t2), qint64(1)); + QCOMPARE(t2 - t1, qint64(1000)); + QCOMPARE(t1 - t2, qint64(-1000)); + + qint64 elapsed = t1.restart(); + QVERIFY(elapsed < minResolution); +} + +void tst_QTimestamp::elapsed() +{ + QTimestamp t1; + t1.start(); + + QTest::qSleep(4*minResolution); + QTimestamp t2; + t2.start(); + + QVERIFY(t1 != t2); + QVERIFY(!(t1 == t2)); + QVERIFY(t1 < t2); + QVERIFY(t1.msecsTo(t2) > 0); + // don't check: t1.secsTo(t2) + QVERIFY(t1 - t2 < 0); + + QVERIFY(t1.elapsed() > 0); + QVERIFY(t1.hasExpired(minResolution)); + QVERIFY(!t1.hasExpired(8*minResolution)); + QVERIFY(!t2.hasExpired(minResolution)); + + QVERIFY(!t1.hasExpired(-1)); + QVERIFY(!t2.hasExpired(-1)); + + qint64 elapsed = t1.restart(); + QVERIFY(elapsed > 3*minResolution); + QVERIFY(elapsed < 5*minResolution); + qint64 diff = t1 - t2; + QVERIFY(diff < minResolution); +} + +QTEST_MAIN(tst_QTimestamp); + +#include "tst_qtimestamp.moc" diff --git a/tests/auto/qtimestamp/qtimestamp.pro b/tests/auto/qtimestamp/qtimestamp.pro deleted file mode 100644 index 3a06390..0000000 --- a/tests/auto/qtimestamp/qtimestamp.pro +++ /dev/null @@ -1,13 +0,0 @@ -load(qttest_p4) -QT -= gui - -SOURCES += tst_qtimestamp.cpp -wince* { - DEFINES += SRCDIR=\\\"\\\" -} else:symbian { - # do not define SRCDIR at all - TARGET.EPOCHEAPSIZE = 0x100000 0x3000000 -} else { - DEFINES += SRCDIR=\\\"$$PWD/\\\" -} - diff --git a/tests/auto/qtimestamp/tst_qtimestamp.cpp b/tests/auto/qtimestamp/tst_qtimestamp.cpp deleted file mode 100644 index 79138ce..0000000 --- a/tests/auto/qtimestamp/tst_qtimestamp.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include -#include -#include -#include - -static const int minResolution = 50; // the minimum resolution for the tests - -class tst_QTimestamp : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void validity(); - void basics(); - void elapsed(); -}; - -void tst_QTimestamp::validity() -{ - QTimestamp t; - - t.invalidate(); - QVERIFY(!t.isValid()); - - t.start(); - QVERIFY(t.isValid()); - - t.invalidate(); - QVERIFY(!t.isValid()); -} - -void tst_QTimestamp::basics() -{ - QTimestamp t1; - t1.start(); - - QCOMPARE(t1, t1); - QVERIFY(!(t1 != t1)); - QVERIFY(!(t1 < t1)); - QCOMPARE(t1.msecsTo(t1), qint64(0)); - QCOMPARE(t1.secsTo(t1), qint64(0)); - QCOMPARE(t1 + 0, t1); - QCOMPARE(t1 - 0, t1); - - QTimestamp t2 = t1; - t2 += 1000; // so we can use secsTo - - QVERIFY(t1 != t2); - QVERIFY(!(t1 == t2)); - QVERIFY(t1 < t2); - QVERIFY(!(t2 < t1)); - QCOMPARE(t1.msecsTo(t2), qint64(1000)); - QCOMPARE(t1.secsTo(t2), qint64(1)); - QCOMPARE(t2 - t1, qint64(1000)); - QCOMPARE(t1 - t2, qint64(-1000)); - - qint64 elapsed = t1.restart(); - QVERIFY(elapsed < minResolution); -} - -void tst_QTimestamp::elapsed() -{ - QTimestamp t1; - t1.start(); - - QTest::qSleep(4*minResolution); - QTimestamp t2; - t2.start(); - - QVERIFY(t1 != t2); - QVERIFY(!(t1 == t2)); - QVERIFY(t1 < t2); - QVERIFY(t1.msecsTo(t2) > 0); - // don't check: t1.secsTo(t2) - QVERIFY(t1 - t2 < 0); - - QVERIFY(t1.elapsed() > 0); - QVERIFY(t1.hasExpired(minResolution)); - QVERIFY(!t1.hasExpired(8*minResolution)); - QVERIFY(!t2.hasExpired(minResolution)); - - QVERIFY(!t1.hasExpired(-1)); - QVERIFY(!t2.hasExpired(-1)); - - qint64 elapsed = t1.restart(); - QVERIFY(elapsed > 3*minResolution); - QVERIFY(elapsed < 5*minResolution); - qint64 diff = t1 - t2; - QVERIFY(diff < minResolution); -} - -QTEST_MAIN(tst_QTimestamp); - -#include "tst_qtimestamp.moc" -- cgit v0.12