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, 28 insertions, 2 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp
index d709567..9789950 100644
--- a/async/autotests/asynctest.cpp
+++ b/async/autotests/asynctest.cpp
@@ -55,7 +55,8 @@ private Q_SLOTS:
55 void testAsyncEach(); 55 void testAsyncEach();
56 void testSyncEach(); 56 void testSyncEach();
57 void testJoinedEach(); 57 void testJoinedEach();
58 void testVoidEach(); 58 void testVoidEachThen();
59 void testAsyncVoidEachThen();
59 60
60 void testAsyncReduce(); 61 void testAsyncReduce();
61 void testSyncReduce(); 62 void testSyncReduce();
@@ -382,7 +383,7 @@ void AsyncTest::testJoinedEach()
382 QCOMPARE(future.value(), expected); 383 QCOMPARE(future.value(), expected);
383} 384}
384 385
385void AsyncTest::testVoidEach() 386void AsyncTest::testVoidEachThen()
386{ 387{
387 QList<int> check; 388 QList<int> check;
388 auto job = Async::start<QList<int>>( 389 auto job = Async::start<QList<int>>(
@@ -391,12 +392,37 @@ void AsyncTest::testVoidEach()
391 }).each<void, int>( 392 }).each<void, int>(
392 [&check](const int &v) { 393 [&check](const int &v) {
393 check << v; 394 check << v;
395 }).then<void>([](){});
396
397 auto future = job.exec();
398
399 const QList<int> expected({ 1, 2, 3, 4 });
400 QVERIFY(future.isFinished());
401 QCOMPARE(check, expected);
402}
403
404void AsyncTest::testAsyncVoidEachThen()
405{
406 bool completedJob = false;
407 QList<int> check;
408 auto job = Async::start<QList<int>>(
409 [](Async::Future<QList<int> > &future) {
410 new AsyncSimulator<QList<int>>(future, { 1, 2, 3, 4 });
411 }).each<void, int>(
412 [&check](const int &v, Async::Future<void> &future) {
413 check << v;
414 new AsyncSimulator<void>(future);
415 }).then<void>([&completedJob](Async::Future<void> &future) {
416 completedJob = true;
417 future.setFinished();
394 }); 418 });
395 419
396 auto future = job.exec(); 420 auto future = job.exec();
421 future.waitForFinished();
397 422
398 const QList<int> expected({ 1, 2, 3, 4 }); 423 const QList<int> expected({ 1, 2, 3, 4 });
399 QVERIFY(future.isFinished()); 424 QVERIFY(future.isFinished());
425 QVERIFY(completedJob);
400 QCOMPARE(check, expected); 426 QCOMPARE(check, expected);
401} 427}
402 428