tst_QTimer: Replace unconditional qWait()s with QSignalSpy
Where possible. Sometimes the replacement is QTRY_COMPARE instead. Also don't use QTestEventLoop directly when it can also be replaced with QSignalSpy use. Remove the TimerHelper class, since its uses can be done with QSignalSpy (and a lambda when remainingTime is checked). Although checking static single-shot timers still needs a target object, so use a stripped down version in those tests. remainingTimeDuringActivation() was not actually testing the repeating case, but single-shot case twice, so fix that. In the repeating case the remaining time is exactly 20 ms on my machine, but QEMU emulation seems to be slow enough for time to advance before the lambda is executed, so relax the conditions. Task-number: QTBUG-63992 Change-Id: Iae92ff7862a13d36e695eec63b54403ec872f2b4 Reviewed-by: Sami Nurmenniemi <sami.nurmenniemi@qt.io> Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io> Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
This commit is contained in:
parent
c5307203f5
commit
1049d3f9db
@ -77,102 +77,65 @@ private slots:
|
|||||||
void postedEventsShouldNotStarveTimers();
|
void postedEventsShouldNotStarveTimers();
|
||||||
};
|
};
|
||||||
|
|
||||||
class TimerHelper : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
TimerHelper() : QObject(), count(0), remainingTime(-1)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int count;
|
|
||||||
int remainingTime;
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void timeout();
|
|
||||||
void fetchRemainingTime();
|
|
||||||
};
|
|
||||||
|
|
||||||
void TimerHelper::timeout()
|
|
||||||
{
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TimerHelper::fetchRemainingTime()
|
|
||||||
{
|
|
||||||
QTimer *timer = static_cast<QTimer *>(sender());
|
|
||||||
remainingTime = timer->remainingTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
void tst_QTimer::zeroTimer()
|
void tst_QTimer::zeroTimer()
|
||||||
{
|
{
|
||||||
TimerHelper helper;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
timer.setInterval(0);
|
timer.setInterval(0);
|
||||||
timer.start();
|
|
||||||
|
|
||||||
connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout()));
|
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||||
|
timer.start();
|
||||||
|
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(timeoutSpy.count(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QTimer::singleShotTimeout()
|
void tst_QTimer::singleShotTimeout()
|
||||||
{
|
{
|
||||||
TimerHelper helper;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
|
|
||||||
connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout()));
|
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||||
timer.start(100);
|
timer.start(100);
|
||||||
|
|
||||||
|
QVERIFY(timeoutSpy.wait(500));
|
||||||
|
QCOMPARE(timeoutSpy.count(), 1);
|
||||||
QTest::qWait(500);
|
QTest::qWait(500);
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(timeoutSpy.count(), 1);
|
||||||
QTest::qWait(500);
|
|
||||||
QCOMPARE(helper.count, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TIMEOUT_TIMEOUT 200
|
#define TIMEOUT_TIMEOUT 200
|
||||||
|
|
||||||
void tst_QTimer::timeout()
|
void tst_QTimer::timeout()
|
||||||
{
|
{
|
||||||
TimerHelper helper;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||||
connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout()));
|
|
||||||
timer.start(100);
|
timer.start(100);
|
||||||
|
|
||||||
QCOMPARE(helper.count, 0);
|
QCOMPARE(timeoutSpy.count(), 0);
|
||||||
|
|
||||||
QTRY_VERIFY_WITH_TIMEOUT(helper.count > 0, TIMEOUT_TIMEOUT);
|
QTRY_VERIFY_WITH_TIMEOUT(timeoutSpy.count() > 0, TIMEOUT_TIMEOUT);
|
||||||
int oldCount = helper.count;
|
int oldCount = timeoutSpy.count();
|
||||||
|
|
||||||
QTRY_VERIFY_WITH_TIMEOUT(helper.count > oldCount, TIMEOUT_TIMEOUT);
|
QTRY_VERIFY_WITH_TIMEOUT(timeoutSpy.count() > oldCount, TIMEOUT_TIMEOUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QTimer::remainingTime()
|
void tst_QTimer::remainingTime()
|
||||||
{
|
{
|
||||||
TimerHelper helper;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||||
connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout()));
|
|
||||||
timer.setTimerType(Qt::PreciseTimer);
|
timer.setTimerType(Qt::PreciseTimer);
|
||||||
timer.start(200);
|
timer.start(200);
|
||||||
|
|
||||||
QCOMPARE(helper.count, 0);
|
QCOMPARE(timeoutSpy.count(), 0);
|
||||||
|
|
||||||
QTest::qWait(50);
|
QTest::qWait(50);
|
||||||
QCOMPARE(helper.count, 0);
|
QCOMPARE(timeoutSpy.count(), 0);
|
||||||
|
|
||||||
int remainingTime = timer.remainingTime();
|
int remainingTime = timer.remainingTime();
|
||||||
QVERIFY2(qAbs(remainingTime - 150) < 50, qPrintable(QString::number(remainingTime)));
|
QVERIFY2(qAbs(remainingTime - 150) < 50, qPrintable(QString::number(remainingTime)));
|
||||||
|
|
||||||
// wait for the timer to actually fire now
|
QVERIFY(timeoutSpy.wait());
|
||||||
connect(&timer, SIGNAL(timeout()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
QCOMPARE(timeoutSpy.count(), 1);
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
|
||||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
|
||||||
QCOMPARE(helper.count, 1);
|
|
||||||
|
|
||||||
// the timer is still active, so it should have a non-zero remaining time
|
// the timer is still active, so it should have a non-zero remaining time
|
||||||
remainingTime = timer.remainingTime();
|
remainingTime = timer.remainingTime();
|
||||||
@ -182,7 +145,7 @@ void tst_QTimer::remainingTime()
|
|||||||
void tst_QTimer::remainingTimeDuringActivation_data()
|
void tst_QTimer::remainingTimeDuringActivation_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<bool>("singleShot");
|
QTest::addColumn<bool>("singleShot");
|
||||||
QTest::newRow("repeating") << true;
|
QTest::newRow("repeating") << false;
|
||||||
QTest::newRow("single-shot") << true;
|
QTest::newRow("single-shot") << true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,29 +153,31 @@ void tst_QTimer::remainingTimeDuringActivation()
|
|||||||
{
|
{
|
||||||
QFETCH(bool, singleShot);
|
QFETCH(bool, singleShot);
|
||||||
|
|
||||||
TimerHelper helper;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
|
||||||
const int timeout = 20; // 20 ms is short enough and should not round down to 0 in any timer mode
|
|
||||||
|
|
||||||
connect(&timer, SIGNAL(timeout()), &helper, SLOT(fetchRemainingTime()));
|
|
||||||
connect(&timer, SIGNAL(timeout()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
|
||||||
timer.start(timeout);
|
|
||||||
timer.setSingleShot(singleShot);
|
timer.setSingleShot(singleShot);
|
||||||
|
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
int remainingTime = 0; // not the expected value in either case
|
||||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
connect(&timer, &QTimer::timeout,
|
||||||
|
[&]() {
|
||||||
|
remainingTime = timer.remainingTime();
|
||||||
|
});
|
||||||
|
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||||
|
const int timeout = 20; // 20 ms is short enough and should not round down to 0 in any timer mode
|
||||||
|
timer.start(timeout);
|
||||||
|
|
||||||
|
QVERIFY(timeoutSpy.wait());
|
||||||
if (singleShot)
|
if (singleShot)
|
||||||
QCOMPARE(helper.remainingTime, -1); // timer not running
|
QCOMPARE(remainingTime, -1); // timer not running
|
||||||
else
|
else
|
||||||
QCOMPARE(helper.remainingTime, timeout);
|
QVERIFY2(remainingTime <= timeout && remainingTime > 0,
|
||||||
|
qPrintable(QString::number(remainingTime)));
|
||||||
|
|
||||||
if (!singleShot) {
|
if (!singleShot) {
|
||||||
// do it again - see QTBUG-46940
|
// do it again - see QTBUG-46940
|
||||||
helper.remainingTime = -1;
|
remainingTime = -1;
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
QVERIFY(timeoutSpy.wait());
|
||||||
QVERIFY(!QTestEventLoop::instance().timeout());
|
QVERIFY2(remainingTime <= timeout && remainingTime > 0,
|
||||||
QCOMPARE(helper.remainingTime, timeout);
|
qPrintable(QString::number(remainingTime)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,47 +198,44 @@ void tst_QTimer::basic_chrono()
|
|||||||
#else
|
#else
|
||||||
// duplicates zeroTimer, singleShotTimeout, interval and remainingTime
|
// duplicates zeroTimer, singleShotTimeout, interval and remainingTime
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
TimerHelper helper;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||||
timer.setInterval(to_ms(nanoseconds(0)));
|
timer.setInterval(to_ms(nanoseconds(0)));
|
||||||
timer.start();
|
timer.start();
|
||||||
QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(0));
|
QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(0));
|
||||||
QCOMPARE(timer.remainingTimeAsDuration().count(), milliseconds::rep(0));
|
QCOMPARE(timer.remainingTimeAsDuration().count(), milliseconds::rep(0));
|
||||||
|
|
||||||
connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout()));
|
|
||||||
|
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(timeoutSpy.count(), 1);
|
||||||
|
|
||||||
helper.count = 0;
|
timeoutSpy.clear();
|
||||||
timer.start(milliseconds(100));
|
timer.start(milliseconds(100));
|
||||||
QCOMPARE(helper.count, 0);
|
QCOMPARE(timeoutSpy.count(), 0);
|
||||||
|
|
||||||
QTest::qWait(TIMEOUT_TIMEOUT);
|
QVERIFY(timeoutSpy.wait(TIMEOUT_TIMEOUT));
|
||||||
QVERIFY(helper.count > 0);
|
QVERIFY(timeoutSpy.count() > 0);
|
||||||
int oldCount = helper.count;
|
int oldCount = timeoutSpy.count();
|
||||||
|
|
||||||
QTest::qWait(TIMEOUT_TIMEOUT);
|
QVERIFY(timeoutSpy.wait(TIMEOUT_TIMEOUT));
|
||||||
QVERIFY(helper.count > oldCount);
|
QVERIFY(timeoutSpy.count() > oldCount);
|
||||||
|
|
||||||
helper.count = 0;
|
timeoutSpy.clear();
|
||||||
timer.start(to_ms(microseconds(200000)));
|
timer.start(to_ms(microseconds(200000)));
|
||||||
QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(200));
|
QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(200));
|
||||||
QTest::qWait(50);
|
QTest::qWait(50);
|
||||||
QCOMPARE(helper.count, 0);
|
QCOMPARE(timeoutSpy.count(), 0);
|
||||||
|
|
||||||
milliseconds rt = timer.remainingTimeAsDuration();
|
milliseconds rt = timer.remainingTimeAsDuration();
|
||||||
QVERIFY2(qAbs(rt.count() - 150) < 50, qPrintable(QString::number(rt.count())));
|
QVERIFY2(qAbs(rt.count() - 150) < 50, qPrintable(QString::number(rt.count())));
|
||||||
|
|
||||||
helper.count = 0;
|
timeoutSpy.clear();
|
||||||
timer.setSingleShot(true);
|
timer.setSingleShot(true);
|
||||||
timer.start(milliseconds(100));
|
timer.start(milliseconds(100));
|
||||||
|
QVERIFY(timeoutSpy.wait(TIMEOUT_TIMEOUT));
|
||||||
|
QCOMPARE(timeoutSpy.count(), 1);
|
||||||
QTest::qWait(500);
|
QTest::qWait(500);
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(timeoutSpy.count(), 1);
|
||||||
QTest::qWait(500);
|
|
||||||
QCOMPARE(helper.count, 1);
|
|
||||||
helper.count = 0;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,47 +410,40 @@ signals:
|
|||||||
void tst_QTimer::recurringTimer_data()
|
void tst_QTimer::recurringTimer_data()
|
||||||
{
|
{
|
||||||
QTest::addColumn<int>("interval");
|
QTest::addColumn<int>("interval");
|
||||||
QTest::newRow("zero timer") << 0;
|
QTest::addColumn<bool>("recurse");
|
||||||
QTest::newRow("non-zero timer") << 1;
|
// make sure that eventloop recursion doesn't affect timer recurrence
|
||||||
|
QTest::newRow("zero timer, don't recurse") << 0 << false;
|
||||||
|
QTest::newRow("zero timer, recurse") << 0 << true;
|
||||||
|
QTest::newRow("non-zero timer, don't recurse") << 1 << false;
|
||||||
|
QTest::newRow("non-zero timer, recurse") << 1 << true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QTimer::recurringTimer()
|
void tst_QTimer::recurringTimer()
|
||||||
{
|
{
|
||||||
const int target = 5;
|
const int target = 5;
|
||||||
QFETCH(int, interval);
|
QFETCH(int, interval);
|
||||||
|
QFETCH(bool, recurse);
|
||||||
|
|
||||||
{
|
|
||||||
RecurringTimerObject object(target);
|
RecurringTimerObject object(target);
|
||||||
QObject::connect(&object, SIGNAL(done()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
object.recurse = recurse;
|
||||||
|
QSignalSpy doneSpy(&object, &RecurringTimerObject::done);
|
||||||
|
|
||||||
(void) object.startTimer(interval);
|
(void) object.startTimer(interval);
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
QVERIFY(doneSpy.wait());
|
||||||
|
|
||||||
QCOMPARE(object.times, target);
|
QCOMPARE(object.times, target);
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
// make sure that eventloop recursion doesn't effect timer recurrance
|
|
||||||
RecurringTimerObject object(target);
|
|
||||||
object.recurse = true;
|
|
||||||
|
|
||||||
QObject::connect(&object, SIGNAL(done()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
|
||||||
(void) object.startTimer(interval);
|
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
|
||||||
|
|
||||||
QCOMPARE(object.times, target);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QTimer::deleteLaterOnQTimer()
|
void tst_QTimer::deleteLaterOnQTimer()
|
||||||
{
|
{
|
||||||
QTimer *timer = new QTimer;
|
QTimer *timer = new QTimer;
|
||||||
connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater()));
|
connect(timer, SIGNAL(timeout()), timer, SLOT(deleteLater()));
|
||||||
connect(timer, SIGNAL(destroyed()), &QTestEventLoop::instance(), SLOT(exitLoop()));
|
QSignalSpy destroyedSpy(timer, &QObject::destroyed);
|
||||||
timer->setInterval(1);
|
timer->setInterval(1);
|
||||||
timer->setSingleShot(true);
|
timer->setSingleShot(true);
|
||||||
timer->start();
|
timer->start();
|
||||||
QPointer<QTimer> pointer = timer;
|
QPointer<QTimer> pointer = timer;
|
||||||
QTestEventLoop::instance().enterLoop(5);
|
QVERIFY(destroyedSpy.wait());
|
||||||
QVERIFY(pointer.isNull());
|
QVERIFY(pointer.isNull());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,23 +645,34 @@ void tst_QTimer::cancelLongTimer()
|
|||||||
QVERIFY(!timer.isActive());
|
QVERIFY(!timer.isActive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TimeoutCounter : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public slots:
|
||||||
|
void timeout() { ++count; };
|
||||||
|
public:
|
||||||
|
int count = 0;
|
||||||
|
};
|
||||||
|
|
||||||
void tst_QTimer::singleShotStaticFunctionZeroTimeout()
|
void tst_QTimer::singleShotStaticFunctionZeroTimeout()
|
||||||
{
|
{
|
||||||
TimerHelper helper;
|
{
|
||||||
|
TimeoutCounter counter;
|
||||||
|
|
||||||
QTimer::singleShot(0, &helper, SLOT(timeout()));
|
QTimer::singleShot(0, &counter, SLOT(timeout()));
|
||||||
|
QTRY_COMPARE(counter.count, 1);
|
||||||
QTest::qWait(500);
|
QTest::qWait(500);
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(counter.count, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
TimeoutCounter counter;
|
||||||
|
|
||||||
|
QTimer::singleShot(0, &counter, &TimeoutCounter::timeout);
|
||||||
|
QTRY_COMPARE(counter.count, 1);
|
||||||
QTest::qWait(500);
|
QTest::qWait(500);
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(counter.count, 1);
|
||||||
|
}
|
||||||
TimerHelper nhelper;
|
|
||||||
|
|
||||||
QTimer::singleShot(0, &nhelper, &TimerHelper::timeout);
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
QCOMPARE(nhelper.count, 1);
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
QCOMPARE(nhelper.count, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class RecursOnTimeoutAndStopTimerTimer : public QObject
|
class RecursOnTimeoutAndStopTimerTimer : public QObject
|
||||||
@ -807,8 +773,7 @@ void tst_QTimer::singleShotToFunctors()
|
|||||||
QCOMPARE(e.exec(), 0);
|
QCOMPARE(e.exec(), 0);
|
||||||
|
|
||||||
QTimer::singleShot(0, &c1, CountedStruct(&count, &t1));
|
QTimer::singleShot(0, &c1, CountedStruct(&count, &t1));
|
||||||
QTest::qWait(500);
|
QTRY_COMPARE(count, 2);
|
||||||
QCOMPARE(count, 2);
|
|
||||||
|
|
||||||
t1.quit();
|
t1.quit();
|
||||||
t1.wait();
|
t1.wait();
|
||||||
@ -833,12 +798,11 @@ void tst_QTimer::singleShotToFunctors()
|
|||||||
QObject c3;
|
QObject c3;
|
||||||
QTimer::singleShot(500, &c3, CountedStruct(&count));
|
QTimer::singleShot(500, &c3, CountedStruct(&count));
|
||||||
}
|
}
|
||||||
QTest::qWait(800);
|
QTest::qWait(800); // Wait until the singleshot timer would have timed out
|
||||||
QCOMPARE(count, 2);
|
QCOMPARE(count, 2);
|
||||||
|
|
||||||
QTimer::singleShot(0, [&count] { ++count; });
|
QTimer::singleShot(0, [&count] { ++count; });
|
||||||
QCoreApplication::processEvents();
|
QTRY_COMPARE(count, 3);
|
||||||
QCOMPARE(count, 3);
|
|
||||||
|
|
||||||
QObject context;
|
QObject context;
|
||||||
QThread thread;
|
QThread thread;
|
||||||
@ -849,8 +813,7 @@ void tst_QTimer::singleShotToFunctors()
|
|||||||
QCOMPARE(e.exec(), 0);
|
QCOMPARE(e.exec(), 0);
|
||||||
|
|
||||||
QTimer::singleShot(0, &context, [&count, &thread] { ++count; QCOMPARE(QThread::currentThread(), &thread); });
|
QTimer::singleShot(0, &context, [&count, &thread] { ++count; QCOMPARE(QThread::currentThread(), &thread); });
|
||||||
QTest::qWait(500);
|
QTRY_COMPARE(count, 4);
|
||||||
QCOMPARE(count, 4);
|
|
||||||
|
|
||||||
thread.quit();
|
thread.quit();
|
||||||
thread.wait();
|
thread.wait();
|
||||||
@ -861,8 +824,7 @@ void tst_QTimer::singleShotToFunctors()
|
|||||||
MoveOnly(int *c) : CountedStruct(c) {}
|
MoveOnly(int *c) : CountedStruct(c) {}
|
||||||
};
|
};
|
||||||
QTimer::singleShot(0, MoveOnly(&count));
|
QTimer::singleShot(0, MoveOnly(&count));
|
||||||
QCoreApplication::processEvents();
|
QTRY_COMPARE(count, 5);
|
||||||
QCOMPARE(count, 5);
|
|
||||||
|
|
||||||
_e.reset();
|
_e.reset();
|
||||||
_t = nullptr;
|
_t = nullptr;
|
||||||
@ -875,26 +837,27 @@ void tst_QTimer::singleShot_chrono()
|
|||||||
#else
|
#else
|
||||||
// duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors
|
// duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
TimerHelper helper;
|
{
|
||||||
|
TimeoutCounter counter;
|
||||||
|
|
||||||
QTimer::singleShot(hours(0), &helper, SLOT(timeout()));
|
QTimer::singleShot(hours(0), &counter, SLOT(timeout()));
|
||||||
|
QTRY_COMPARE(counter.count, 1);
|
||||||
QTest::qWait(500);
|
QTest::qWait(500);
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(counter.count, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
TimeoutCounter counter;
|
||||||
|
|
||||||
|
QTimer::singleShot(hours(0), &counter, &TimeoutCounter::timeout);
|
||||||
|
QTRY_COMPARE(counter.count, 1);
|
||||||
QTest::qWait(500);
|
QTest::qWait(500);
|
||||||
QCOMPARE(helper.count, 1);
|
QCOMPARE(counter.count, 1);
|
||||||
|
}
|
||||||
TimerHelper nhelper;
|
|
||||||
|
|
||||||
QTimer::singleShot(seconds(0), &nhelper, &TimerHelper::timeout);
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
QCOMPARE(nhelper.count, 1);
|
|
||||||
QCoreApplication::processEvents();
|
|
||||||
QCOMPARE(nhelper.count, 1);
|
|
||||||
|
|
||||||
int count = 0;
|
int count = 0;
|
||||||
QTimer::singleShot(to_ms(microseconds(0)), CountedStruct(&count));
|
QTimer::singleShot(to_ms(microseconds(0)), CountedStruct(&count));
|
||||||
QCoreApplication::processEvents();
|
QTRY_COMPARE(count, 1);
|
||||||
QCOMPARE(count, 1);
|
|
||||||
|
|
||||||
_e.reset(new QEventLoop);
|
_e.reset(new QEventLoop);
|
||||||
QTimer::singleShot(0, &StaticEventLoop::quitEventLoop);
|
QTimer::singleShot(0, &StaticEventLoop::quitEventLoop);
|
||||||
@ -902,12 +865,10 @@ void tst_QTimer::singleShot_chrono()
|
|||||||
|
|
||||||
QObject c3;
|
QObject c3;
|
||||||
QTimer::singleShot(milliseconds(500), &c3, CountedStruct(&count));
|
QTimer::singleShot(milliseconds(500), &c3, CountedStruct(&count));
|
||||||
QTest::qWait(800);
|
QTRY_COMPARE(count, 2);
|
||||||
QCOMPARE(count, 2);
|
|
||||||
|
|
||||||
QTimer::singleShot(0, [&count] { ++count; });
|
QTimer::singleShot(0, [&count] { ++count; });
|
||||||
QCoreApplication::processEvents();
|
QTRY_COMPARE(count, 3);
|
||||||
QCOMPARE(count, 3);
|
|
||||||
|
|
||||||
_e.reset();
|
_e.reset();
|
||||||
#endif
|
#endif
|
||||||
@ -985,16 +946,14 @@ public slots:
|
|||||||
|
|
||||||
void tst_QTimer::postedEventsShouldNotStarveTimers()
|
void tst_QTimer::postedEventsShouldNotStarveTimers()
|
||||||
{
|
{
|
||||||
TimerHelper timerHelper;
|
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
connect(&timer, SIGNAL(timeout()), &timerHelper, SLOT(timeout()));
|
|
||||||
timer.setInterval(0);
|
timer.setInterval(0);
|
||||||
timer.setSingleShot(false);
|
timer.setSingleShot(false);
|
||||||
|
QSignalSpy timeoutSpy(&timer, &QTimer::timeout);
|
||||||
timer.start();
|
timer.start();
|
||||||
SlotRepeater slotRepeater;
|
SlotRepeater slotRepeater;
|
||||||
slotRepeater.repeatThisSlot();
|
slotRepeater.repeatThisSlot();
|
||||||
QTest::qWait(100);
|
QTRY_VERIFY_WITH_TIMEOUT(timeoutSpy.count() > 5, 100);
|
||||||
QVERIFY(timerHelper.count > 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DummyFunctor {
|
struct DummyFunctor {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user