summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib/selftests/sleep
diff options
context:
space:
mode:
authorKonstantin Shegunov <kshegunov@gmail.com>2018-08-01 00:50:14 +0300
committerKonstantin Shegunov <kshegunov@gmail.com>2019-05-08 17:19:44 +0000
commitc6bee8e4b2c48775247c67ef8e7569f623655c61 (patch)
treea3bfc28da2b37935129ebf16425de58336e3a0e6 /tests/auto/testlib/selftests/sleep
parent8adcfa8b240876236f08ad826e6d77ff1f5e9a96 (diff)
Fix integer overflows in QDeadlineTimer
If the deadline is far in the future, the conversions to nanoseconds or internal arithmetic may overflow and give an invalid object, thus the deadline may end up in the past. Added a test to the testlib selftest for sleep. [ChangeLog][QtCore][QDeadlineTimer] Fixed integer overflows leading to immediate timeouts. Task-number: QTBUG-69750 Change-Id: I9814eccdf9f9b3add9ca66ec3e27e10cd5ad54a8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/testlib/selftests/sleep')
-rw-r--r--tests/auto/testlib/selftests/sleep/tst_sleep.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/sleep/tst_sleep.cpp b/tests/auto/testlib/selftests/sleep/tst_sleep.cpp
index afe6e22120..b7b141afd0 100644
--- a/tests/auto/testlib/selftests/sleep/tst_sleep.cpp
+++ b/tests/auto/testlib/selftests/sleep/tst_sleep.cpp
@@ -36,6 +36,7 @@ class tst_Sleep: public QObject
private slots:
void sleep();
+ void wait();
};
void tst_Sleep::sleep()
@@ -53,6 +54,24 @@ void tst_Sleep::sleep()
QVERIFY(t.elapsed() > 1000 * 10);
}
+void tst_Sleep::wait()
+{
+ QElapsedTimer t;
+ t.start();
+
+ QTest::qWait(1);
+ QVERIFY(t.elapsed() >= 1);
+
+ QTest::qWait(10);
+ QVERIFY(t.elapsed() >= 11);
+
+ QTest::qWait(100);
+ QVERIFY(t.elapsed() >= 111);
+
+ QTest::qWait(1000);
+ QVERIFY(t.elapsed() >= 1111);
+}
+
QTEST_MAIN(tst_Sleep)
#include "tst_sleep.moc"