Always call QFutureWatcher::setFuture after connects

This commit is contained in:
Jonas Kvinge
2021-06-16 00:30:21 +02:00
parent d2d3f58a14
commit 8699790e78
15 changed files with 27 additions and 27 deletions

View File

@@ -19,9 +19,9 @@ TEST(ConcurrentRunTest, ConcurrentRun0StartAndWait) {
QThreadPool threadpool;
QFuture<int> future = QtConcurrent::run(&threadpool, &f);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, watcher.result());
@@ -38,9 +38,9 @@ TEST(ConcurrentRunTest, ConcurrentRun1StartAndWait) {
int i = 1336;
QFuture<int> future = QtConcurrent::run(&threadpool, &g, i);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, watcher.result());
@@ -58,9 +58,9 @@ TEST(ConcurrentRunTest, ConcurrentRun2StartAndWait) {
QThreadPool threadpool;
QFuture<int> future = QtConcurrent::run(&threadpool, &max, i, j);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(42, watcher.result());
@@ -79,9 +79,9 @@ TEST(ConcurrentRunTest, ConcurrentRun3StartAndWait) {
QThreadPool threadpool;
QFuture<int> future = QtConcurrent::run(&threadpool, &sum, i, j, k);
QFutureWatcher<int> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(102, watcher.result());
@@ -111,9 +111,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidFunction1Start) {
int n = 10;
QFuture<void> future = QtConcurrent::run(&threadpool, &aFunction, &n);
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, n);
@@ -126,9 +126,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidFunction2Start) {
int n = 10, m = 11;
QFuture<void> future = QtConcurrent::run(&threadpool, &bFunction, &n, &m);
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, n);
EXPECT_EQ(1338, m);
@@ -142,9 +142,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidFunction3Start) {
int n = 10, m = 11, o = 12;
QFuture<void> future = QtConcurrent::run(&threadpool, &cFunction, &n, &m, &o);
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(1337, n);
EXPECT_EQ(1338, m);
@@ -167,9 +167,9 @@ TEST(ConcurrentRunTest, ConcurrentRunVoidBindFunctionStart) {
int nb = 10;
QFuture<void> future = QtConcurrent::run(&threadpool, std::bind(&A::f, &a, &nb));
QFutureWatcher<void> watcher;
watcher.setFuture(future);
QEventLoop loop;
QObject::connect(&watcher, &QFutureWatcher<int>::finished, &loop, &QEventLoop::quit);
watcher.setFuture(future);
loop.exec();
EXPECT_EQ(11, nb);