diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2020-07-24 12:30:00 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2020-08-03 16:47:31 +0200 |
commit | b3c1093751072110d34b9746d419e8070c80fc3f (patch) | |
tree | 6efa2be54684b03d57f3f299247f0a14f144d82e /tests/auto/corelib/thread/qpromise/tst_qpromise.cpp | |
parent | fddb0c895f9a12d61bbc4cf33149a8d1a93eaf19 (diff) |
Introduce swap functions for QPromise/QFutureInterface
Made QPromise::swap public, added free standing swap() for
QFutureInterface and QPromise. Updated QPromise special member
functions. Extended tests
Task-number: QTBUG-84977
Change-Id: I5daf6876df306d082441dbcdf5ae4dee3bfc0ead
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/corelib/thread/qpromise/tst_qpromise.cpp')
-rw-r--r-- | tests/auto/corelib/thread/qpromise/tst_qpromise.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp index 02c5b6a8bd..2b8853ccd7 100644 --- a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp +++ b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp @@ -64,7 +64,7 @@ private slots: void cancelWhenDestroyed(); #endif void cancelWhenReassigned(); - void finishWhenMoved(); + void finishWhenSwapped(); void cancelWhenMoved(); void waitUntilResumed(); void waitUntilCanceled(); @@ -470,7 +470,7 @@ void tst_QPromise::cancelWhenReassigned() QCOMPARE(f.isCanceled(), true); } -void tst_QPromise::finishWhenMoved() +void tst_QPromise::finishWhenSwapped() { QPromise<int> promise1; auto f1 = promise1.future(); @@ -482,8 +482,11 @@ void tst_QPromise::finishWhenMoved() ThreadWrapper thr([&promise1, &promise2] () mutable { QThread::msleep(100); - // There is swap semantics in move, so promise #1 and #2 just swap - promise1 = std::move(promise2); + promise1.addResult(0); + promise2.addResult(1); + swap(promise1, promise2); // ADL must resolve this + promise1.addResult(2); + promise2.addResult(3); promise1.reportFinished(); // this finish is for future #2 promise2.reportFinished(); // this finish is for future #1 }); @@ -497,6 +500,12 @@ void tst_QPromise::finishWhenMoved() QCOMPARE(f2.isFinished(), true); QCOMPARE(f2.isCanceled(), false); + + QCOMPARE(f1.resultAt(0), 0); + QCOMPARE(f1.resultAt(1), 3); + + QCOMPARE(f2.resultAt(0), 1); + QCOMPARE(f2.resultAt(1), 2); } void tst_QPromise::cancelWhenMoved() @@ -512,7 +521,6 @@ void tst_QPromise::cancelWhenMoved() // Move promises to local scope to test cancellation behavior ThreadWrapper thr([p1 = std::move(promise1), p2 = std::move(promise2)] () mutable { QThread::msleep(100); - // There is swap semantics in move, so promise #1 and #2 just swap p1 = std::move(p2); p1.reportFinished(); // this finish is for future #2 }); |