summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/thread/qresultstore.cpp1
-rw-r--r--src/corelib/thread/qresultstore.h7
-rw-r--r--tests/auto/corelib/thread/qfuture/tst_qfuture.cpp20
-rw-r--r--tests/auto/corelib/thread/qresultstore/tst_qresultstore.cpp16
4 files changed, 44 insertions, 0 deletions
diff --git a/src/corelib/thread/qresultstore.cpp b/src/corelib/thread/qresultstore.cpp
index a239954dbe..5982ae5454 100644
--- a/src/corelib/thread/qresultstore.cpp
+++ b/src/corelib/thread/qresultstore.cpp
@@ -235,6 +235,7 @@ int ResultStoreBase::addResult(int index, const void *result)
int ResultStoreBase::addResults(int index, const void *results, int vectorSize, int totalCount)
{
if (m_filterMode == false || vectorSize == totalCount) {
+ Q_ASSERT(vectorSize != 0);
ResultItem resultItem(results, vectorSize);
return insertResultItem(index, resultItem);
} else {
diff --git a/src/corelib/thread/qresultstore.h b/src/corelib/thread/qresultstore.h
index 0a1382fd79..0967b89123 100644
--- a/src/corelib/thread/qresultstore.h
+++ b/src/corelib/thread/qresultstore.h
@@ -193,6 +193,9 @@ public:
template<typename T>
int addResults(int index, const QList<T> *results)
{
+ if (results->empty()) // reject if results are empty
+ return -1;
+
if (containsValidResultItem(index)) // reject if already present
return -1;
@@ -202,6 +205,10 @@ public:
template<typename T>
int addResults(int index, const QList<T> *results, int totalCount)
{
+ // reject if results are empty, and nothing is filtered away
+ if ((m_filterMode == false || results->count() == totalCount) && results->empty())
+ return -1;
+
if (containsValidResultItem(index)) // reject if already present
return -1;
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<int> fi;
+ fi.reportStarted();
+ QVERIFY(!fi.reportResults(QList<int> {}));
+ fi.reportFinished();
+
+ QVERIFY(fi.results().empty());
+ }
+
+ {
+ QFutureInterface<int> fi;
+ fi.reportStarted();
+ QList<int> values = { 1, 2, 3 };
+ QVERIFY(fi.reportResults(values));
+ QVERIFY(!fi.reportResults(QList<int> {}));
+ fi.reportFinished();
+
+ QCOMPARE(fi.results(), values);
+ }
}
template <typename T>
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<int> 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<int> 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()