From d54f9df1bd2d83aa259e2597bbdacd98216574d8 Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Mon, 26 Jul 2021 17:03:37 +0200 Subject: Don't report results when the results list is empty MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When inserting items into the result store, a ResultItem is created, which stores a pointer to the results list and their size. If the size of the ResultItem is set to 0, it means that a single result is stored. In case of trying to report results via an empty list, the size is 0, so result store treats it as a single result. Added checks before storing the results to make sure that the result list isn't empty. Note that empty lists are allowed in some cases for the filter mode, because ResultStoreBase::addResults() knows how to handle those cases correctly. Task-number: QTBUG-80957 Change-Id: I399af4c3eef6adf82fea5df031fe9a9075006b1f Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 08de1fb28153d8170b592796a84032897afa4206) Reviewed-by: Qt Cherry-pick Bot --- tests/auto/corelib/thread/qfuture/tst_qfuture.cpp | 20 ++++++++++++++++++++ .../corelib/thread/qresultstore/tst_qresultstore.cpp | 16 ++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp index 5f6267ec7d..435e44c05b 100644 --- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp +++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp @@ -730,6 +730,26 @@ void tst_QFuture::futureInterface() QCOMPARE(i1.resultReference(0), 2); QCOMPARE(i2.resultReference(0), 1); } + + { + QFutureInterface fi; + fi.reportStarted(); + QVERIFY(!fi.reportResults(QList {})); + fi.reportFinished(); + + QVERIFY(fi.results().empty()); + } + + { + QFutureInterface fi; + fi.reportStarted(); + QList values = { 1, 2, 3 }; + QVERIFY(fi.reportResults(values)); + QVERIFY(!fi.reportResults(QList {})); + fi.reportFinished(); + + QCOMPARE(fi.results(), values); + } } template diff --git a/tests/auto/corelib/thread/qresultstore/tst_qresultstore.cpp b/tests/auto/corelib/thread/qresultstore/tst_qresultstore.cpp index 10ac19137e..48b0eaf1eb 100644 --- a/tests/auto/corelib/thread/qresultstore/tst_qresultstore.cpp +++ b/tests/auto/corelib/thread/qresultstore/tst_qresultstore.cpp @@ -177,6 +177,14 @@ void tst_QtConcurrentResultStore::addResults() ++it; QCOMPARE(it, store.end()); + + QList empty; + const auto countBefore = store.count(); + QCOMPARE(store.addResults(countBefore, &empty), -1); + QCOMPARE(store.count(), countBefore); + + QCOMPARE(store.addResults(countBefore, &vec1), countBefore); + QCOMPARE(store.count(), countBefore + vec1.size()); } void tst_QtConcurrentResultStore::resultIndex() @@ -340,6 +348,14 @@ void tst_QtConcurrentResultStore::filterMode() QCOMPARE(store.contains(6), true); QCOMPARE(store.contains(7), true); QCOMPARE(store.contains(8), false); + + QList empty; + const auto countBefore = store.count(); + QCOMPARE(store.addResults(countBefore, &empty), -1); + QCOMPARE(store.count(), countBefore); + + QCOMPARE(store.addResult(countBefore, &int2), countBefore); + QCOMPARE(store.count(), countBefore + 1); } void tst_QtConcurrentResultStore::addCanceledResult() -- cgit v1.2.3