From 84e89c1e9e00d4fab576b876cfa80e92b5602982 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 12 Jun 2019 18:06:23 +0200 Subject: Convert uses of QTime as a timer to QElapsedTimer Change-Id: I2297f61efa5adf9ea5194c7f3ff68574cbcf452c Reviewed-by: Friedemann Kleint --- tests/auto/corelib/io/qprocess/tst_qprocess.cpp | 7 ++++--- .../kernel/qsharedmemory/tst_qsharedmemory.cpp | 3 ++- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 15 ++++++++------- .../serialization/qtextstream/tst_qtextstream.cpp | 3 ++- .../corelib/thread/qatomicint/tst_qatomicint.cpp | 3 ++- .../thread/qfuturewatcher/tst_qfuturewatcher.cpp | 3 ++- .../thread/qreadwritelock/tst_qreadwritelock.cpp | 19 ++++++++++--------- tests/auto/corelib/thread/qthread/tst_qthread.cpp | 20 +++++++++----------- .../corelib/thread/qthreadpool/tst_qthreadpool.cpp | 8 ++++---- 9 files changed, 43 insertions(+), 38 deletions(-) (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index c51994c1c1..e4ff3c2a08 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -420,7 +421,7 @@ void tst_QProcess::echoTest() process.write(input); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); do { QVERIFY(process.isOpen()); @@ -479,7 +480,7 @@ void tst_QProcess::echoTest2() QVERIFY(spy1.isValid()); QVERIFY(spy2.isValid()); - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); forever { QTestEventLoop::instance().enterLoop(1); @@ -2072,7 +2073,7 @@ void tst_QProcess::fileWriterProcess() stdinStr += line; } - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); const QString fileName = m_temporaryDir.path() + QLatin1String("/fileWriterProcess.txt"); const QString binary = QDir::currentPath() + QLatin1String("/fileWriterProcess/fileWriterProcess"); diff --git a/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp index 55deb8eb1a..fa2d5e3723 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/tst_qsharedmemory.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #define EXISTING_SHARE "existing" #define EXISTING_SIZE 1024 @@ -645,7 +646,7 @@ public: char *memory = (char*)producer.data(); memory[1] = '0'; - QTime timer; + QElapsedTimer timer; timer.start(); int i = 0; while (i < 5 && timer.elapsed() < 5000) { diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index b7c87418c7..262dbea913 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -38,6 +38,7 @@ #include #include +#include #if defined Q_OS_UNIX #include @@ -526,7 +527,7 @@ public: QBasicTimer m_timer; int m_interval; - QTime m_startedTime; + QElapsedTimer m_elapsedTimer; QEventLoop eventLoop; inline RestartedTimerFiresTooSoonObject() @@ -538,7 +539,7 @@ public: static int interval = 1000; m_interval = interval; - m_startedTime.start(); + m_elapsedTimer.start(); m_timer.start(interval, this); // alternate between single-shot and 1 sec @@ -552,7 +553,7 @@ public: m_timer.stop(); - int elapsed = m_startedTime.elapsed(); + int elapsed = m_elapsedTimer.elapsed(); if (elapsed < m_interval / 2) { // severely too early! @@ -590,10 +591,10 @@ public: public slots: void longLastingSlot() { - // Don't use timers for this, because we are testing them. - QTime time; - time.start(); - while (time.elapsed() < 200) { + // Don't use QTimer for this, because we are testing it. + QElapsedTimer control; + control.start(); + while (control.elapsed() < 200) { for (int c = 0; c < 100000; c++) {} // Mindless looping. } if (++count >= 2) { diff --git a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp index c4fb623130..32306e8003 100644 --- a/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/serialization/qtextstream/tst_qtextstream.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -996,7 +997,7 @@ struct CompareIndicesForArray void tst_QTextStream::performance() { // Phase #1 - test speed of reading a huge text file with QFile. - QTime stopWatch; + QElapsedTimer stopWatch; const int N = 3; const char * readMethods[N] = { diff --git a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp index cc197cabba..9b5a273131 100644 --- a/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp +++ b/tests/auto/corelib/thread/qatomicint/tst_qatomicint.cpp @@ -31,6 +31,7 @@ #include #include +#include #include @@ -851,7 +852,7 @@ void tst_QAtomicInt::operators() void tst_QAtomicInt::testAndSet_loop() { - QTime stopWatch; + QElapsedTimer stopWatch; stopWatch.start(); int iterations = 10000000; diff --git a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp index b2ef516b4e..a322a1c11d 100644 --- a/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp +++ b/tests/auto/corelib/thread/qfuturewatcher/tst_qfuturewatcher.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include #include +#include #include #include @@ -878,7 +879,7 @@ void tst_QFutureWatcher::incrementalFilterResults() void tst_QFutureWatcher::qfutureSynchronizer() { int taskCount = 1000; - QTime t; + QElapsedTimer t; t.start(); { diff --git a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp index 8e97229752..45fcf9657d 100644 --- a/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp +++ b/tests/auto/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -237,7 +238,7 @@ void tst_QReadWriteLock::tryReadLock() testsTurn.release(); threadsTurn.acquire(); - QTime timer; + QElapsedTimer timer; timer.start(); QVERIFY(!readWriteLock.tryLockForRead(1000)); QVERIFY(timer.elapsed() >= 1000); @@ -500,7 +501,7 @@ public: int holdTime; int waitTime; bool print; - QTime t; + QElapsedTimer t; inline ReadLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false) :testRwlock(l) ,runTime(runTime) @@ -536,7 +537,7 @@ public: int holdTime; int waitTime; bool print; - QTime t; + QElapsedTimer t; inline WriteLockLoopThread(QReadWriteLock &l, int runTime, int holdTime=0, int waitTime=0, bool print=false) :testRwlock(l) ,runTime(runTime) @@ -574,7 +575,7 @@ public: int runTime; int waitTime; int maxval; - QTime t; + QElapsedTimer t; inline WriteLockCountThread(QReadWriteLock &l, int runTime, int waitTime, int maxval) :testRwlock(l) ,runTime(runTime) @@ -615,7 +616,7 @@ public: QReadWriteLock &testRwlock; int runTime; int waitTime; - QTime t; + QElapsedTimer t; inline ReadLockCountThread(QReadWriteLock &l, int runTime, int waitTime) :testRwlock(l) ,runTime(runTime) @@ -873,7 +874,7 @@ void tst_QReadWriteLock::deleteOnUnlock() DeleteOnUnlockThread thread2(&lock, &startup, &waitMutex); - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() < 4000) { lock = new QReadWriteLock(); @@ -899,7 +900,7 @@ void tst_QReadWriteLock::uncontendedLocks() uint count=0; int millisecs=1000; { - QTime t; + QElapsedTimer t; t.start(); while(t.elapsed() #include -#include +#include #include #include #include @@ -244,8 +244,8 @@ public: QMutexLocker locker(&mutex); elapsed = 0; - QTime time; - time.start(); + QElapsedTimer timer; + timer.start(); switch (sleepType) { case Second: sleep(interval); @@ -257,7 +257,7 @@ public: usleep(interval); break; } - elapsed = time.elapsed(); + elapsed = timer.elapsed(); cond.wakeOne(); } @@ -601,8 +601,7 @@ void tst_QThread::msleep() thread.interval = 120; thread.start(); QVERIFY(thread.wait(five_minutes)); -#if defined (Q_OS_WIN) - // Since the resolution of QTime is so coarse... +#if defined (Q_OS_WIN) // May no longer be needed QVERIFY(thread.elapsed >= 100); #else QVERIFY(thread.elapsed >= 120); @@ -616,8 +615,7 @@ void tst_QThread::usleep() thread.interval = 120000; thread.start(); QVERIFY(thread.wait(five_minutes)); -#if defined (Q_OS_WIN) - // Since the resolution of QTime is so coarse... +#if defined (Q_OS_WIN) // May no longer be needed QVERIFY(thread.elapsed >= 100); #else QVERIFY(thread.elapsed >= 120); @@ -948,9 +946,9 @@ void tst_QThread::stressTest() if (EmulationDetector::isRunningArmOnX86()) QSKIP("Qemu uses too much memory for each thread. Test would run out of memory."); - QTime t; - t.start(); - while (t.elapsed() < one_minute) { + QElapsedTimer timer; + timer.start(); + while (timer.elapsed() < one_minute) { Current_Thread t; t.start(); t.wait(one_minute); diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index 27b49602fc..f41cbe2601 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -27,7 +27,7 @@ ** ****************************************************************************/ #include -#include +#include #include #include #include @@ -882,7 +882,7 @@ void tst_QThreadPool::priorityStart() void tst_QThreadPool::waitForDone() { - QTime total, pass; + QElapsedTimer total, pass; total.start(); QThreadPool threadPool; @@ -1113,7 +1113,7 @@ void tst_QThreadPool::tryTake() void tst_QThreadPool::destroyingWaitsForTasksToFinish() { - QTime total, pass; + QElapsedTimer total, pass; total.start(); while (total.elapsed() < 10000) { @@ -1204,7 +1204,7 @@ void tst_QThreadPool::stressTest() } }; - QTime total; + QElapsedTimer total; total.start(); while (total.elapsed() < 30000) { Task t; -- cgit v1.2.3