summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qtimer
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2016-05-30 16:10:08 -0300
committerThiago Macieira <thiago.macieira@intel.com>2016-07-09 02:17:17 +0000
commitd16ba63f5cdf1e6c9dc96200bb80b2155437c4ee (patch)
treed5b5e8586908a7161e3657c427d133277211a60b /tests/auto/corelib/kernel/qtimer
parentb2c0f9713c1c39bc3214df49f0d2b44bcc84d790 (diff)
QTimer: add support for <chrono> functions
[ChangeLog][QtCore][QTimer] Added support for std::chrono duration objects for QTimer methods, like QTimer::singleShot and QTimer::setInterval. Change-Id: I87e17314d8b24ae983b1fffd14536e24d5b12424 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qtimer')
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
index de7a3721d8..28df01cc16 100644
--- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
+++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
@@ -52,6 +52,7 @@ private slots:
void remainingTime();
void remainingTimeDuringActivation_data();
void remainingTimeDuringActivation();
+ void basic_chrono();
void livelock_data();
void livelock();
void timerInfiniteRecursion_data();
@@ -68,6 +69,7 @@ private slots:
void singleShotStaticFunctionZeroTimeout();
void recurseOnTimeoutAndStopTimer();
void singleShotToFunctors();
+ void singleShot_chrono();
void crossThreadSingleShotToFunctor();
void dontBlockEvents();
@@ -214,6 +216,57 @@ void tst_QTimer::remainingTimeDuringActivation()
}
}
+void tst_QTimer::basic_chrono()
+{
+#if !QT_HAS_INCLUDE(<chrono>)
+ QSKIP("This test requires C++11 <chrono> support");
+#else
+ // duplicates zeroTimer, singleShotTimeout, interval and remainingTime
+ using namespace std::chrono;
+ TimerHelper helper;
+ QTimer timer;
+ timer.setInterval(nanoseconds(0));
+ timer.start();
+ QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(0));
+ QCOMPARE(timer.remainingTimeAsDuration().count(), milliseconds::rep(0));
+
+ connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout()));
+
+ QCoreApplication::processEvents();
+
+ QCOMPARE(helper.count, 1);
+
+ helper.count = 0;
+ timer.start(milliseconds(100));
+ QCOMPARE(helper.count, 0);
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QVERIFY(helper.count > 0);
+ int oldCount = helper.count;
+
+ QTest::qWait(TIMEOUT_TIMEOUT);
+ QVERIFY(helper.count > oldCount);
+
+ helper.count = 0;
+ timer.start(microseconds(200000));
+ QCOMPARE(timer.intervalAsDuration().count(), milliseconds::rep(200));
+ QTest::qWait(50);
+ QCOMPARE(helper.count, 0);
+
+ milliseconds rt = timer.remainingTimeAsDuration();
+ QVERIFY2(qAbs(rt.count() - 150) < 50, qPrintable(QString::number(rt.count())));
+
+ helper.count = 0;
+ timer.setSingleShot(true);
+ timer.start(milliseconds(100));
+ QTest::qWait(500);
+ QCOMPARE(helper.count, 1);
+ QTest::qWait(500);
+ QCOMPARE(helper.count, 1);
+ helper.count = 0;
+#endif
+}
+
void tst_QTimer::livelock_data()
{
QTest::addColumn<int>("interval");
@@ -787,6 +840,51 @@ void tst_QTimer::singleShotToFunctors()
_t = Q_NULLPTR;
}
+void tst_QTimer::singleShot_chrono()
+{
+#if !QT_HAS_INCLUDE(<chrono>)
+ QSKIP("This test requires C++11 <chrono> support");
+#else
+ // duplicates singleShotStaticFunctionZeroTimeout and singleShotToFunctors
+ using namespace std::chrono;
+ TimerHelper helper;
+
+ QTimer::singleShot(hours(0), &helper, SLOT(timeout()));
+ QTest::qWait(500);
+ QCOMPARE(helper.count, 1);
+ QTest::qWait(500);
+ QCOMPARE(helper.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;
+ QTimer::singleShot(microseconds(0), CountedStruct(&count));
+ QCoreApplication::processEvents();
+ QCOMPARE(count, 1);
+
+ _e.reset(new QEventLoop);
+ QTimer::singleShot(0, &StaticEventLoop::quitEventLoop);
+ QCOMPARE(_e->exec(), 0);
+
+ QObject c3;
+ QTimer::singleShot(milliseconds(500), &c3, CountedStruct(&count));
+ QTest::qWait(800);
+ QCOMPARE(count, 2);
+
+ QTimer::singleShot(0, [&count] { ++count; });
+ QCoreApplication::processEvents();
+ QCOMPARE(count, 3);
+
+ _e.reset();
+#endif
+}
+
class DontBlockEvents : public QObject
{
Q_OBJECT