summaryrefslogtreecommitdiffstats
path: root/async/autotests/asynctest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r--async/autotests/asynctest.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp
index 7aedfc4..000bb2a 100644
--- a/async/autotests/asynctest.cpp
+++ b/async/autotests/asynctest.cpp
@@ -37,6 +37,19 @@ public:
37 ~AsyncTest() 37 ~AsyncTest()
38 {} 38 {}
39 39
40private:
41 template<typename T>
42 bool waitForFuture(const Async::Future<T> &f)
43 {
44 QEventLoop eventLoop;
45 Async::FutureWatcher<T> watcher;
46 connect(&watcher, &Async::FutureWatcher<T>::futureReady,
47 &eventLoop, &QEventLoop::quit);
48 watcher.setFuture(f);
49 eventLoop.exec();
50 return true;
51 }
52
40private Q_SLOTS: 53private Q_SLOTS:
41 void testSyncPromises(); 54 void testSyncPromises();
42 void testAsyncPromises(); 55 void testAsyncPromises();
@@ -63,8 +76,7 @@ void AsyncTest::testSyncPromises()
63 f.setFinished(); 76 f.setFinished();
64 }); 77 });
65 78
66 job.exec(); 79 Async::Future<QString> future = job.exec();
67 Async::Future<QString> future = job.result();
68 80
69 QVERIFY(future.isFinished()); 81 QVERIFY(future.isFinished());
70 QCOMPARE(future.value(), QString::fromLatin1("RESULT IS 42")); 82 QCOMPARE(future.value(), QString::fromLatin1("RESULT IS 42"));
@@ -86,9 +98,9 @@ void AsyncTest::testAsyncPromises()
86 timer->start(200); 98 timer->start(200);
87 }); 99 });
88 100
89 job.exec(); 101 Async::Future<int> future = job.exec();
90 Async::Future<int> future = job.result(); 102
91 QVERIFY(future.isFinished()); 103 QVERIFY(waitForFuture<int>(future));
92 QCOMPARE(future.value(), 42); 104 QCOMPARE(future.value(), 42);
93} 105}
94 106
@@ -105,8 +117,8 @@ void AsyncTest::testSyncEach()
105 future.setFinished(); 117 future.setFinished();
106 }); 118 });
107 119
108 job.exec(); 120 Async::Future<QList<int>> future = job.exec();
109 Async::Future<QList<int>> future = job.result(); 121
110 const QList<int> expected({ 2, 3, 4, 5 }); 122 const QList<int> expected({ 2, 3, 4, 5 });
111 QVERIFY(future.isFinished()); 123 QVERIFY(future.isFinished());
112 QCOMPARE(future.value(), expected); 124 QCOMPARE(future.value(), expected);
@@ -127,8 +139,8 @@ void AsyncTest::testSyncReduce()
127 future.setFinished(); 139 future.setFinished();
128 }); 140 });
129 141
130 job.exec(); 142 Async::Future<int> future = job.exec();
131 Async::Future<int> future = job.result(); 143
132 QVERIFY(future.isFinished()); 144 QVERIFY(future.isFinished());
133 QCOMPARE(future.value(), 10); 145 QCOMPARE(future.value(), 10);
134} 146}