diff options
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r-- | async/autotests/asynctest.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index 1ee3843..6c4bbeb 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp | |||
@@ -44,6 +44,7 @@ private Q_SLOTS: | |||
44 | void testNestedAsync(); | 44 | void testNestedAsync(); |
45 | void testSyncEach(); | 45 | void testSyncEach(); |
46 | void testSyncReduce(); | 46 | void testSyncReduce(); |
47 | void testErrorHandler(); | ||
47 | }; | 48 | }; |
48 | 49 | ||
49 | void AsyncTest::testSyncPromises() | 50 | void AsyncTest::testSyncPromises() |
@@ -195,6 +196,26 @@ void AsyncTest::testSyncReduce() | |||
195 | QCOMPARE(future.value(), 10); | 196 | QCOMPARE(future.value(), 10); |
196 | } | 197 | } |
197 | 198 | ||
199 | void AsyncTest::testErrorHandler() | ||
200 | { | ||
201 | int error = 0; | ||
202 | auto job = Async::start<int>( | ||
203 | [](Async::Future<int> &f) { | ||
204 | f.setError(1, "error"); | ||
205 | }) | ||
206 | .then<int, int>( | ||
207 | [](int v, Async::Future<int> &f) { | ||
208 | f.setFinished(); | ||
209 | }, | ||
210 | [&error](int errorCode, const QString &errorMessage) { | ||
211 | error = errorCode; | ||
212 | } | ||
213 | ); | ||
214 | auto future = job.exec(); | ||
215 | future.waitForFinished(); | ||
216 | QVERIFY(error == 1); | ||
217 | QVERIFY(future.isFinished()); | ||
218 | } | ||
198 | 219 | ||
199 | 220 | ||
200 | QTEST_MAIN(AsyncTest); | 221 | QTEST_MAIN(AsyncTest); |