summaryrefslogtreecommitdiffstats
path: root/tests/auto/concurrent
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2020-12-01 19:22:16 +0100
committerIvan Solovev <ivan.solovev@qt.io>2020-12-04 15:36:50 +0100
commit3d780c0d7068a6a6876d058314b1970810008c1f (patch)
tree86f3abfbdb95e0f414ebb1d7757108631652ca39 /tests/auto/concurrent
parent0c19e3f703a7c3fd59e6db8a9d4ac7091674b552 (diff)
QtConcurrent: filter/map reduction without default ctor
Previously a default constructor was required for the result type of mappedReduced() and filteredReduced(), even if a default value was provided. This patch fixes the problem. The issue was in the ResultReporter type, that was calling QList::resize() to adjust the size of expected reported results. A default-value parameter was added to the class, so that a corresponding overload of QList::resize could be invoked. Task-number: QTBUG-88452 Change-Id: I51113753e314d76aa74d201b5a7e327a6ca75f47 Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
Diffstat (limited to 'tests/auto/concurrent')
-rw-r--r--tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp76
-rw-r--r--tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h2
2 files changed, 78 insertions, 0 deletions
diff --git a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp
index ebe6dba70e..6b72648720 100644
--- a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp
+++ b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrent_selected_tests.cpp
@@ -294,3 +294,79 @@ void tst_QtConcurrentFilterMapGenerated::moveOnlyReductionItem()
QCOMPARE(result, expected_result);*/
}
+
+void tst_QtConcurrentFilterMapGenerated::noDefaultConstructorItemMapped()
+{
+ /* test for
+ template<typename typename ResultType, typename Sequence, typename MapFunctor, typename
+ ReduceFunctor, typename reductionitemtype> ResultType blockingMappedReduced(QThreadPool* pool,
+ const Sequence & sequence, MapFunctor function, ReduceFunctor reduceFunction, reductionitemtype
+ && initialValue, ReduceOptions);
+
+ with
+ inputsequence=standard
+ inputsequencepassing=lvalue
+ inputitemtype=standard
+ maptype=same
+ mappeditemtype=standard
+ reductiontype=different
+ reductionitemtype=noconstruct
+ mapfunction=functor
+ mapfunctionpassing=lvalue
+ reductionfunction=function
+ reductionfunctionpassing=lvalue
+ reductioninitialvaluepassing=lvalue
+ reductionoptions=unspecified
+ */
+
+ QThreadPool pool;
+ pool.setMaxThreadCount(1);
+ auto input_sequence = []() {
+ std::vector<SequenceItem<tag_input>> result;
+ result.push_back(SequenceItem<tag_input>(1, true));
+ result.push_back(SequenceItem<tag_input>(2, true));
+ result.push_back(SequenceItem<tag_input>(3, true));
+ result.push_back(SequenceItem<tag_input>(4, true));
+ result.push_back(SequenceItem<tag_input>(5, true));
+ result.push_back(SequenceItem<tag_input>(6, true));
+ return result;
+ }();
+
+ auto map = MyMap<SequenceItem<tag_input>, SequenceItem<tag_input>> {};
+ auto reductor = myReduce<SequenceItem<tag_input>, NoConstructSequenceItem<tag_reduction>>;
+ auto initialvalue = NoConstructSequenceItem<tag_reduction>(0, true);
+
+ auto result =
+ QtConcurrent::blockingMappedReduced(&pool, input_sequence, map, reductor, initialvalue);
+
+ auto expected_result = NoConstructSequenceItem<tag_reduction>(42, true);
+
+ QCOMPARE(result, expected_result);
+}
+
+void tst_QtConcurrentFilterMapGenerated::noDefaultConstructorItemFiltered()
+{
+ QThreadPool pool;
+ pool.setMaxThreadCount(1);
+ auto input_sequence = []() {
+ std::vector<SequenceItem<tag_input>> result;
+ result.push_back(SequenceItem<tag_input>(1, true));
+ result.push_back(SequenceItem<tag_input>(2, true));
+ result.push_back(SequenceItem<tag_input>(3, true));
+ result.push_back(SequenceItem<tag_input>(4, true));
+ result.push_back(SequenceItem<tag_input>(5, true));
+ result.push_back(SequenceItem<tag_input>(6, true));
+ return result;
+ }();
+
+ auto filter = MyFilter<SequenceItem<tag_input>> {};
+ auto reductor = myReduce<SequenceItem<tag_input>, NoConstructSequenceItem<tag_reduction>>;
+ auto initialvalue = NoConstructSequenceItem<tag_reduction>(0, true);
+
+ auto result = QtConcurrent::blockingFilteredReduced(&pool, input_sequence, filter, reductor,
+ initialvalue);
+
+ auto expected_result = NoConstructSequenceItem<tag_reduction>(9, true);
+
+ QCOMPARE(result, expected_result);
+}
diff --git a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h
index 9a32f53499..e6229236a3 100644
--- a/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h
+++ b/tests/auto/concurrent/qtconcurrentfiltermapgenerated/tst_qtconcurrentfiltermapgenerated.h
@@ -44,6 +44,8 @@ private slots:
void moveOnlyReduceObject();
void functorAsReduction();
void moveOnlyReductionItem();
+ void noDefaultConstructorItemMapped();
+ void noDefaultConstructorItemFiltered();
// START_GENERATED_SLOTS (see generate_tests.py)
void test1();
// END_GENERATED_SLOTS (see generate_tests.py)