From 65e5a6ac8848750e94e35ec65ac37d0d4a8638cd Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 19 Jan 2015 19:22:16 +0100 Subject: Async: Error continuation. --- async/autotests/asynctest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'async/autotests') 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: void testNestedAsync(); void testSyncEach(); void testSyncReduce(); + void testErrorHandler(); }; void AsyncTest::testSyncPromises() @@ -195,6 +196,26 @@ void AsyncTest::testSyncReduce() QCOMPARE(future.value(), 10); } +void AsyncTest::testErrorHandler() +{ + int error = 0; + auto job = Async::start( + [](Async::Future &f) { + f.setError(1, "error"); + }) + .then( + [](int v, Async::Future &f) { + f.setFinished(); + }, + [&error](int errorCode, const QString &errorMessage) { + error = errorCode; + } + ); + auto future = job.exec(); + future.waitForFinished(); + QVERIFY(error == 1); + QVERIFY(future.isFinished()); +} QTEST_MAIN(AsyncTest); -- cgit v1.2.3