summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp')
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
index 5c39fc5d91..2e86d89923 100644
--- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
+++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
@@ -56,6 +56,7 @@ private slots:
void singleShotToFunctors();
void singleShot_chrono();
void singleShot_static();
+ void crossThreadSingleShotToFunctor_data();
void crossThreadSingleShotToFunctor();
void timerOrder();
void timerOrder_data();
@@ -1007,28 +1008,39 @@ void tst_QTimer::postedEventsShouldNotStarveTimers()
struct DummyFunctor {
static QThread *callThread;
- void operator()() { callThread = QThread::currentThread(); }
+ void operator()() {
+ callThread = QThread::currentThread();
+ callThread->quit();
+ }
};
QThread *DummyFunctor::callThread = nullptr;
+void tst_QTimer::crossThreadSingleShotToFunctor_data()
+{
+ QTest::addColumn<int>("timeout");
+
+ QTest::addRow("zero-timer") << 0;
+ QTest::addRow("1ms") << 1;
+}
+
void tst_QTimer::crossThreadSingleShotToFunctor()
{
+ QFETCH(int, timeout);
// We're also testing for crashes here, so the test simply running to
// completion is part of the success
+ DummyFunctor::callThread = nullptr;
+
QThread t;
t.start();
- QObject* o = new QObject();
+ std::unique_ptr<QObject> o(new QObject());
o->moveToThread(&t);
- DummyFunctor::callThread = nullptr;
- for (int i = 0; i < 10000; i++) {
- QTimer::singleShot(0, o, DummyFunctor());
- }
+ for (int i = 0; i < 10000; i++)
+ QTimer::singleShot(timeout, o.get(), DummyFunctor());
- t.quit();
t.wait();
- delete o;
+ o.reset();
QCOMPARE(DummyFunctor::callThread, &t);
}