diff options
Diffstat (limited to 'async/autotests/asynctest.cpp')
-rw-r--r-- | async/autotests/asynctest.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/async/autotests/asynctest.cpp b/async/autotests/asynctest.cpp index 61ab8bc..7b8d430 100644 --- a/async/autotests/asynctest.cpp +++ b/async/autotests/asynctest.cpp | |||
@@ -60,6 +60,7 @@ private Q_SLOTS: | |||
60 | void testJoinedReduce(); | 60 | void testJoinedReduce(); |
61 | void testVoidReduce(); | 61 | void testVoidReduce(); |
62 | 62 | ||
63 | void testProgressReporting(); | ||
63 | void testErrorHandler(); | 64 | void testErrorHandler(); |
64 | 65 | ||
65 | void testChainingRunningJob(); | 66 | void testChainingRunningJob(); |
@@ -69,6 +70,7 @@ private Q_SLOTS: | |||
69 | void testLifetimeWithHandle(); | 70 | void testLifetimeWithHandle(); |
70 | 71 | ||
71 | void benchmarkSyncThenExecutor(); | 72 | void benchmarkSyncThenExecutor(); |
73 | void benchmarkAllTests(); | ||
72 | 74 | ||
73 | private: | 75 | private: |
74 | template<typename T> | 76 | template<typename T> |
@@ -471,6 +473,40 @@ void AsyncTest::testVoidReduce() | |||
471 | } | 473 | } |
472 | 474 | ||
473 | 475 | ||
476 | void AsyncTest::testProgressReporting() | ||
477 | { | ||
478 | static int progress; | ||
479 | progress = 0; | ||
480 | |||
481 | auto job = Async::start<void>( | ||
482 | [](Async::Future<void> &f) { | ||
483 | QTimer *timer = new QTimer(); | ||
484 | connect(timer, &QTimer::timeout, | ||
485 | [&f, timer]() { | ||
486 | f.setProgress(++progress); | ||
487 | if (progress == 100) { | ||
488 | timer->stop(); | ||
489 | timer->deleteLater(); | ||
490 | f.setFinished(); | ||
491 | } | ||
492 | }); | ||
493 | timer->start(1); | ||
494 | }); | ||
495 | |||
496 | int progressCheck = 0; | ||
497 | Async::FutureWatcher<void> watcher; | ||
498 | connect(&watcher, &Async::FutureWatcher<void>::futureProgress, | ||
499 | [&progressCheck](qreal progress) { | ||
500 | progressCheck++; | ||
501 | // FIXME: Don't use Q_ASSERT in unit tests | ||
502 | Q_ASSERT((int) progress == progressCheck); | ||
503 | }); | ||
504 | watcher.setFuture(job.exec()); | ||
505 | watcher.future().waitForFinished(); | ||
506 | |||
507 | QVERIFY(watcher.future().isFinished()); | ||
508 | QCOMPARE(progressCheck, 100); | ||
509 | } | ||
474 | 510 | ||
475 | void AsyncTest::testErrorHandler() | 511 | void AsyncTest::testErrorHandler() |
476 | { | 512 | { |
@@ -634,6 +670,32 @@ void AsyncTest::benchmarkSyncThenExecutor() | |||
634 | } | 670 | } |
635 | } | 671 | } |
636 | 672 | ||
673 | void AsyncTest::benchmarkAllTests() | ||
674 | { | ||
675 | QBENCHMARK { | ||
676 | testSyncPromises(); | ||
677 | testAsyncPromises(); | ||
678 | testAsyncPromises2(); | ||
679 | testNestedAsync(); | ||
680 | testStartValue(); | ||
681 | |||
682 | testAsyncThen(); | ||
683 | testSyncThen(); | ||
684 | testJoinedThen(); | ||
685 | testVoidThen(); | ||
686 | |||
687 | testAsyncEach(); | ||
688 | testSyncEach(); | ||
689 | testJoinedEach(); | ||
690 | testVoidEach(); | ||
691 | |||
692 | testAsyncReduce(); | ||
693 | testSyncReduce(); | ||
694 | testJoinedReduce(); | ||
695 | testVoidReduce(); | ||
696 | } | ||
697 | } | ||
698 | |||
637 | 699 | ||
638 | 700 | ||
639 | QTEST_MAIN(AsyncTest); | 701 | QTEST_MAIN(AsyncTest); |