diff options
author | Ivan Solovev <ivan.solovev@qt.io> | 2020-11-09 14:19:02 +0100 |
---|---|---|
committer | Ivan Solovev <ivan.solovev@qt.io> | 2020-11-17 16:16:31 +0100 |
commit | 1d8dd9a02c9715561b365007f1520e41fe64e703 (patch) | |
tree | e3f023e6cdc9896e0fe8376e4cbd3f795332ba91 /tests | |
parent | e0248ddc5c90b53a20f2546d60f8f91c974bc1a3 (diff) |
Track progress range in QFutureInterface::setProgressValue
Previously QFutureInterface::setProgressValue was silently ignoring
the progress range and allowed to set any progress value.
Also no checks were performed in QFutureInterface::setProgressRange,
which allowed the user to set minimum > maximum.
Add checking of the current progress range, when settings the
progress value.
Add checks for minimum and maximum values while setting the progress
range.
The implementation of the checks is mostly based on the logic
that is used in QProgressBar.
- If maximum is smaller than minimum, minimum becomes the only legal
value.
- If the current progress value falls outside the new range, the
progress value is set to be minimum.
- If both progressMinimum() and progressMaximum() return 0, the
current progress range is considered to be unused, and any progress
value can be set.
- When setting the value using setProgressValue(), if the value falls
out of the progress range, the method has no effect.
Task-number: QTBUG-84729
Change-Id: I29cf4f94b8e98e1af30dd46fbdba39c421cf66bf
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/thread/qfuture/tst_qfuture.cpp | 51 | ||||
-rw-r--r-- | tests/auto/corelib/thread/qpromise/tst_qpromise.cpp | 1 |
2 files changed, 51 insertions, 1 deletions
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index e2c81840cb..0d1097ce1c 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -107,6 +107,8 @@ private slots: void multipleResults(); void indexedResults(); void progress(); + void setProgressRange(); + void progressWithRange(); void progressText(); void resultsAfterFinished(); void resultsAsList(); @@ -1000,6 +1002,55 @@ void tst_QFuture::progress() QCOMPARE (f.progressValue(), 50); } +void tst_QFuture::setProgressRange() +{ + QFutureInterface<int> i; + + QCOMPARE(i.progressMinimum(), 0); + QCOMPARE(i.progressMaximum(), 0); + + i.setProgressRange(10, 5); + + QCOMPARE(i.progressMinimum(), 10); + QCOMPARE(i.progressMaximum(), 10); + + i.setProgressRange(5, 10); + + QCOMPARE(i.progressMinimum(), 5); + QCOMPARE(i.progressMaximum(), 10); +} + +void tst_QFuture::progressWithRange() +{ + QFutureInterface<int> i; + QFuture<int> f; + + i.reportStarted(); + f = i.future(); + + QCOMPARE(i.progressValue(), 0); + + i.setProgressRange(5, 10); + + QCOMPARE(i.progressValue(), 5); + + i.setProgressValue(20); + + QCOMPARE(i.progressValue(), 5); + + i.setProgressValue(9); + + QCOMPARE(i.progressValue(), 9); + + i.setProgressRange(5, 7); + + QCOMPARE(i.progressValue(), 5); + + i.reportFinished(); + + QCOMPARE(f.progressValue(), 5); +} + void tst_QFuture::progressText() { QFutureInterface<void> i; diff --git a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp index d8f321215b..82a359451d 100644 --- a/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp +++ b/tests/auto/corelib/thread/qpromise/tst_qpromise.cpp @@ -310,7 +310,6 @@ void tst_QPromise::progress() promise.setProgressValue(0); // decrement QCOMPARE(f.progressValue(), 1); promise.setProgressValue(10); // out of range - QEXPECT_FAIL("", "Out of range value is set - QTBUG-84729", Continue); QCOMPARE(f.progressValue(), 1); promise.setProgressRange(0, 100); |