author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 12:15:23 +0300 | |
branch | RCL_3 |
changeset 12 | cc75c76972ee |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
#include <qtconcurrentmap.h> |
|
42 |
#include <qtconcurrentexception.h> |
|
43 |
||
44 |
#include <qdebug.h> |
|
45 |
#include <QThread> |
|
46 |
||
47 |
#include <QtTest/QtTest> |
|
48 |
||
49 |
#include "functions.h" |
|
50 |
#include "../qfuture/versioncheck.h" |
|
51 |
||
52 |
Q_DECLARE_METATYPE(QVector<int>); |
|
53 |
Q_DECLARE_METATYPE(QVector<double>); |
|
54 |
Q_DECLARE_METATYPE(QVector<QString>); |
|
55 |
Q_DECLARE_METATYPE(QList<int>); |
|
56 |
Q_DECLARE_METATYPE(QList<double>); |
|
57 |
Q_DECLARE_METATYPE(QList<QString>); |
|
58 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
59 |
class tst_QtConcurrentMap: public QObject |
0 | 60 |
{ |
61 |
Q_OBJECT |
|
62 |
private slots: |
|
63 |
void map(); |
|
64 |
void blocking_map(); |
|
65 |
void mapped(); |
|
66 |
void blocking_mapped(); |
|
67 |
void mappedReduced(); |
|
68 |
void blocking_mappedReduced(); |
|
69 |
void assignResult(); |
|
70 |
void functionOverloads(); |
|
71 |
#ifndef QT_NO_EXCEPTIONS |
|
72 |
void exceptions(); |
|
73 |
#endif |
|
74 |
void incrementalResults(); |
|
75 |
void noDetatch(); |
|
76 |
void stlContainers(); |
|
77 |
void qFutureAssignmentLeak(); |
|
78 |
void stressTest(); |
|
79 |
public slots: |
|
80 |
void throttling(); |
|
81 |
}; |
|
82 |
||
83 |
#if !defined (QT_NO_CONCURRENT_TEST) && !defined(QT_NO_CONCURRENT_MAP) |
|
84 |
||
85 |
using namespace QtConcurrent; |
|
86 |
||
87 |
void multiplyBy2Immutable(int x) |
|
88 |
{ |
|
89 |
x *= 2; |
|
90 |
} |
|
91 |
||
92 |
class MultiplyBy2Immutable |
|
93 |
{ |
|
94 |
public: |
|
95 |
void operator()(int x) |
|
96 |
{ |
|
97 |
x *= 2; |
|
98 |
} |
|
99 |
}; |
|
100 |
||
101 |
void multiplyBy2InPlace(int &x) |
|
102 |
{ |
|
103 |
x *= 2; |
|
104 |
} |
|
105 |
||
106 |
class MultiplyBy2InPlace |
|
107 |
{ |
|
108 |
public: |
|
109 |
void operator()(int &x) |
|
110 |
{ |
|
111 |
x *= 2; |
|
112 |
} |
|
113 |
}; |
|
114 |
||
115 |
Q_DECLARE_METATYPE(QList<Number>); |
|
116 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
117 |
void tst_QtConcurrentMap::map() |
0 | 118 |
{ |
119 |
// functors take arguments by reference, modifying the sequence in place |
|
120 |
{ |
|
121 |
QList<int> list; |
|
122 |
list << 1 << 2 << 3; |
|
123 |
||
124 |
// functor |
|
125 |
QtConcurrent::map(list, MultiplyBy2InPlace()).waitForFinished(); |
|
126 |
QCOMPARE(list, QList<int>() << 2 << 4 << 6); |
|
127 |
QtConcurrent::map(list.begin(), list.end(), MultiplyBy2InPlace()).waitForFinished(); |
|
128 |
QCOMPARE(list, QList<int>() << 4 << 8 << 12); |
|
129 |
||
130 |
// function |
|
131 |
QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished(); |
|
132 |
QCOMPARE(list, QList<int>() << 8 << 16 << 24); |
|
133 |
QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished(); |
|
134 |
QCOMPARE(list, QList<int>() << 16 << 32 << 48); |
|
135 |
||
136 |
// bound function |
|
137 |
QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished(); |
|
138 |
QCOMPARE(list, QList<int>() << 32 << 64 << 96); |
|
139 |
QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished(); |
|
140 |
QCOMPARE(list, QList<int>() << 64 << 128 << 192); |
|
141 |
||
142 |
// member function |
|
143 |
QList<Number> numberList; |
|
144 |
numberList << 1 << 2 << 3; |
|
145 |
QtConcurrent::map(numberList, &Number::multiplyBy2).waitForFinished(); |
|
146 |
QCOMPARE(numberList, QList<Number>() << 2 << 4 << 6); |
|
147 |
QtConcurrent::map(numberList.begin(), numberList.end(), &Number::multiplyBy2).waitForFinished(); |
|
148 |
QCOMPARE(numberList, QList<Number>() << 4 << 8 << 12); |
|
149 |
} |
|
150 |
||
151 |
// functors don't take arguments by reference, making these no-ops |
|
152 |
{ |
|
153 |
QList<int> list; |
|
154 |
list << 1 << 2 << 3; |
|
155 |
||
156 |
// functor |
|
157 |
QtConcurrent::map(list, MultiplyBy2Immutable()).waitForFinished(); |
|
158 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
159 |
QtConcurrent::map(list.begin(), list.end(), MultiplyBy2Immutable()).waitForFinished(); |
|
160 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
161 |
||
162 |
// function |
|
163 |
QtConcurrent::map(list, multiplyBy2Immutable).waitForFinished(); |
|
164 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
165 |
QtConcurrent::map(list.begin(), list.end(), multiplyBy2Immutable).waitForFinished(); |
|
166 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
167 |
||
168 |
// bound function |
|
169 |
QtConcurrent::map(list, multiplyBy2Immutable).waitForFinished(); |
|
170 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
171 |
QtConcurrent::map(list.begin(), list.end(), multiplyBy2Immutable).waitForFinished(); |
|
172 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
173 |
} |
|
174 |
||
175 |
// Linked lists and forward iterators |
|
176 |
{ |
|
177 |
QLinkedList<int> list; |
|
178 |
list << 1 << 2 << 3; |
|
179 |
||
180 |
// functor |
|
181 |
QtConcurrent::map(list, MultiplyBy2InPlace()).waitForFinished(); |
|
182 |
QCOMPARE(list, QLinkedList<int>() << 2 << 4 << 6); |
|
183 |
QtConcurrent::map(list.begin(), list.end(), MultiplyBy2InPlace()).waitForFinished(); |
|
184 |
QCOMPARE(list, QLinkedList<int>() << 4 << 8 << 12); |
|
185 |
||
186 |
// function |
|
187 |
QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished(); |
|
188 |
QCOMPARE(list, QLinkedList<int>() << 8 << 16 << 24); |
|
189 |
QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished(); |
|
190 |
QCOMPARE(list, QLinkedList<int>() << 16 << 32 << 48); |
|
191 |
||
192 |
// bound function |
|
193 |
QtConcurrent::map(list, multiplyBy2InPlace).waitForFinished(); |
|
194 |
QCOMPARE(list, QLinkedList<int>() << 32 << 64 << 96); |
|
195 |
QtConcurrent::map(list.begin(), list.end(), multiplyBy2InPlace).waitForFinished(); |
|
196 |
QCOMPARE(list, QLinkedList<int>() << 64 << 128 << 192); |
|
197 |
||
198 |
// member function |
|
199 |
QLinkedList<Number> numberList; |
|
200 |
numberList << 1 << 2 << 3; |
|
201 |
QtConcurrent::map(numberList, &Number::multiplyBy2).waitForFinished(); |
|
202 |
QCOMPARE(numberList, QLinkedList<Number>() << 2 << 4 << 6); |
|
203 |
QtConcurrent::map(numberList.begin(), numberList.end(), &Number::multiplyBy2).waitForFinished(); |
|
204 |
QCOMPARE(numberList, QLinkedList<Number>() << 4 << 8 << 12); |
|
205 |
} |
|
206 |
||
207 |
#if 0 |
|
208 |
// not allowed: map() with immutable sequences makes no sense |
|
209 |
{ |
|
210 |
const QList<int> list = QList<int>() << 1 << 2 << 3; |
|
211 |
||
212 |
QtConcurrent::map(list, MultiplyBy2Immutable()); |
|
213 |
QtConcurrent::map(list, multiplyBy2Immutable); |
|
214 |
QtConcurrent::map(list, multiplyBy2Immutable); |
|
215 |
} |
|
216 |
#endif |
|
217 |
||
218 |
#if 0 |
|
219 |
// not allowed: in place modification of a temp copy (since temp copy goes out of scope) |
|
220 |
{ |
|
221 |
QList<int> list; |
|
222 |
list << 1 << 2 << 3; |
|
223 |
||
224 |
QtConcurrent::map(QList<int>(list), MultiplyBy2InPlace()); |
|
225 |
QtConcurrent::map(QList<int>(list), multiplyBy2); |
|
226 |
QtConcurrent::map(QList<int>(list), multiplyBy2InPlace); |
|
227 |
||
228 |
QList<Number> numberList; |
|
229 |
numberList << 1 << 2 << 3; |
|
230 |
QtConcurrent::map(QList<Number>(numberList), &Number::multiplyBy2); |
|
231 |
} |
|
232 |
#endif |
|
233 |
||
234 |
#if 0 |
|
235 |
// not allowed: map() on a const list, where functors try to modify the items in the list |
|
236 |
{ |
|
237 |
const QList<int> list = QList<int>() << 1 << 2 << 3;; |
|
238 |
||
239 |
QtConcurrent::map(list, MultiplyBy2InPlace()); |
|
240 |
QtConcurrent::map(list, multiplyBy2InPlace); |
|
241 |
QtConcurrent::map(list, multiplyBy2InPlace); |
|
242 |
||
243 |
const QList<Number> numberList = QList<Number>() << 1 << 2 << 3; |
|
244 |
QtConcurrent::map(numberList, &Number::multiplyBy2); |
|
245 |
} |
|
246 |
#endif |
|
247 |
} |
|
248 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
249 |
void tst_QtConcurrentMap::blocking_map() |
0 | 250 |
{ |
251 |
// functors take arguments by reference, modifying the sequence in place |
|
252 |
{ |
|
253 |
QList<int> list; |
|
254 |
list << 1 << 2 << 3; |
|
255 |
||
256 |
// functor |
|
257 |
QtConcurrent::blockingMap(list, MultiplyBy2InPlace()); |
|
258 |
QCOMPARE(list, QList<int>() << 2 << 4 << 6); |
|
259 |
QtConcurrent::blockingMap(list.begin(), list.end(), MultiplyBy2InPlace()); |
|
260 |
QCOMPARE(list, QList<int>() << 4 << 8 << 12); |
|
261 |
||
262 |
// function |
|
263 |
QtConcurrent::blockingMap(list, multiplyBy2InPlace); |
|
264 |
QCOMPARE(list, QList<int>() << 8 << 16 << 24); |
|
265 |
QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace); |
|
266 |
QCOMPARE(list, QList<int>() << 16 << 32 << 48); |
|
267 |
||
268 |
// bound function |
|
269 |
QtConcurrent::blockingMap(list, multiplyBy2InPlace); |
|
270 |
QCOMPARE(list, QList<int>() << 32 << 64 << 96); |
|
271 |
QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace); |
|
272 |
QCOMPARE(list, QList<int>() << 64 << 128 << 192); |
|
273 |
||
274 |
// member function |
|
275 |
QList<Number> numberList; |
|
276 |
numberList << 1 << 2 << 3; |
|
277 |
QtConcurrent::blockingMap(numberList, &Number::multiplyBy2); |
|
278 |
QCOMPARE(numberList, QList<Number>() << 2 << 4 << 6); |
|
279 |
QtConcurrent::blockingMap(numberList.begin(), numberList.end(), &Number::multiplyBy2); |
|
280 |
QCOMPARE(numberList, QList<Number>() << 4 << 8 << 12); |
|
281 |
} |
|
282 |
||
283 |
// functors don't take arguments by reference, making these no-ops |
|
284 |
{ |
|
285 |
QList<int> list; |
|
286 |
list << 1 << 2 << 3; |
|
287 |
||
288 |
// functor |
|
289 |
QtConcurrent::blockingMap(list, MultiplyBy2Immutable()); |
|
290 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
291 |
QtConcurrent::blockingMap(list.begin(), list.end(), MultiplyBy2Immutable()); |
|
292 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
293 |
||
294 |
// function |
|
295 |
QtConcurrent::blockingMap(list, multiplyBy2Immutable); |
|
296 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
297 |
QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2Immutable); |
|
298 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
299 |
||
300 |
// bound function |
|
301 |
QtConcurrent::blockingMap(list, multiplyBy2Immutable); |
|
302 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
303 |
QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2Immutable); |
|
304 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
305 |
} |
|
306 |
||
307 |
// Linked lists and forward iterators |
|
308 |
{ |
|
309 |
QLinkedList<int> list; |
|
310 |
list << 1 << 2 << 3; |
|
311 |
||
312 |
// functor |
|
313 |
QtConcurrent::blockingMap(list, MultiplyBy2InPlace()); |
|
314 |
QCOMPARE(list, QLinkedList<int>() << 2 << 4 << 6); |
|
315 |
QtConcurrent::blockingMap(list.begin(), list.end(), MultiplyBy2InPlace()); |
|
316 |
QCOMPARE(list, QLinkedList<int>() << 4 << 8 << 12); |
|
317 |
||
318 |
// function |
|
319 |
QtConcurrent::blockingMap(list, multiplyBy2InPlace); |
|
320 |
QCOMPARE(list, QLinkedList<int>() << 8 << 16 << 24); |
|
321 |
QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace); |
|
322 |
QCOMPARE(list, QLinkedList<int>() << 16 << 32 << 48); |
|
323 |
||
324 |
// bound function |
|
325 |
QtConcurrent::blockingMap(list, multiplyBy2InPlace); |
|
326 |
QCOMPARE(list, QLinkedList<int>() << 32 << 64 << 96); |
|
327 |
QtConcurrent::blockingMap(list.begin(), list.end(), multiplyBy2InPlace); |
|
328 |
QCOMPARE(list, QLinkedList<int>() << 64 << 128 << 192); |
|
329 |
||
330 |
// member function |
|
331 |
QLinkedList<Number> numberList; |
|
332 |
numberList << 1 << 2 << 3; |
|
333 |
QtConcurrent::blockingMap(numberList, &Number::multiplyBy2); |
|
334 |
QCOMPARE(numberList, QLinkedList<Number>() << 2 << 4 << 6); |
|
335 |
QtConcurrent::blockingMap(numberList.begin(), numberList.end(), &Number::multiplyBy2); |
|
336 |
QCOMPARE(numberList, QLinkedList<Number>() << 4 << 8 << 12); |
|
337 |
} |
|
338 |
||
339 |
#if 0 |
|
340 |
// not allowed: map() with immutable sequences makes no sense |
|
341 |
{ |
|
342 |
const QList<int> list = QList<int>() << 1 << 2 << 3; |
|
343 |
||
344 |
QtConcurrent::blockingMap(list, MultiplyBy2Immutable()); |
|
345 |
QtConcurrent::blockkng::map(list, multiplyBy2Immutable); |
|
346 |
QtConcurrent::blockingMap(list, multiplyBy2Immutable); |
|
347 |
} |
|
348 |
#endif |
|
349 |
||
350 |
#if 0 |
|
351 |
// not allowed: in place modification of a temp copy (since temp copy goes out of scope) |
|
352 |
{ |
|
353 |
QList<int> list; |
|
354 |
list << 1 << 2 << 3; |
|
355 |
||
356 |
QtConcurrent::blockingMap(QList<int>(list), MultiplyBy2InPlace()); |
|
357 |
QtConcurrent::blockingMap(QList<int>(list), multiplyBy2); |
|
358 |
QtConcurrent::blockingMap(QList<int>(list), multiplyBy2InPlace); |
|
359 |
||
360 |
QList<Number> numberList; |
|
361 |
numberList << 1 << 2 << 3; |
|
362 |
QtConcurrent::blockingMap(QList<Number>(numberList), &Number::multiplyBy2); |
|
363 |
} |
|
364 |
#endif |
|
365 |
||
366 |
#if 0 |
|
367 |
// not allowed: map() on a const list, where functors try to modify the items in the list |
|
368 |
{ |
|
369 |
const QList<int> list = QList<int>() << 1 << 2 << 3;; |
|
370 |
||
371 |
QtConcurrent::blockingMap(list, MultiplyBy2InPlace()); |
|
372 |
QtConcurrent::blockingMap(list, multiplyBy2InPlace); |
|
373 |
QtConcurrent::blockingMap(list, multiplyBy2InPlace); |
|
374 |
||
375 |
const QList<Number> numberList = QList<Number>() << 1 << 2 << 3; |
|
376 |
QtConcurrent::blockingMap(numberList, &Number::multiplyBy2); |
|
377 |
} |
|
378 |
#endif |
|
379 |
} |
|
380 |
||
381 |
int multiplyBy2(int x) |
|
382 |
{ |
|
383 |
int y = x * 2; |
|
384 |
return y; |
|
385 |
} |
|
386 |
||
387 |
class MultiplyBy2 |
|
388 |
{ |
|
389 |
public: |
|
390 |
typedef int result_type; |
|
391 |
||
392 |
int operator()(int x) const |
|
393 |
{ |
|
394 |
int y = x * 2; |
|
395 |
return y; |
|
396 |
} |
|
397 |
}; |
|
398 |
||
399 |
double intToDouble(int x) |
|
400 |
{ |
|
401 |
return double(x); |
|
402 |
} |
|
403 |
||
404 |
class IntToDouble |
|
405 |
{ |
|
406 |
public: |
|
407 |
typedef double result_type; |
|
408 |
||
409 |
double operator()(int x) const |
|
410 |
{ |
|
411 |
return double(x); |
|
412 |
} |
|
413 |
}; |
|
414 |
||
415 |
int stringToInt(const QString &string) |
|
416 |
{ |
|
417 |
return string.toInt(); |
|
418 |
} |
|
419 |
||
420 |
class StringToInt |
|
421 |
{ |
|
422 |
public: |
|
423 |
typedef int result_type; |
|
424 |
||
425 |
int operator()(const QString &string) const |
|
426 |
{ |
|
427 |
return string.toInt(); |
|
428 |
} |
|
429 |
}; |
|
430 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
431 |
void tst_QtConcurrentMap::mapped() |
0 | 432 |
{ |
433 |
QList<int> list; |
|
434 |
list << 1 << 2 << 3; |
|
435 |
QLinkedList<int> linkedList; |
|
436 |
linkedList << 1 << 2 << 3; |
|
437 |
QList<Number> numberList; |
|
438 |
numberList << 1 << 2 << 3; |
|
439 |
QLinkedList<Number> numberLinkedList; |
|
440 |
numberLinkedList << 1 << 2 << 3; |
|
441 |
||
442 |
// functor |
|
443 |
{ |
|
444 |
QList<int> list2 = QtConcurrent::mapped(list, MultiplyBy2()).results(); |
|
445 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
446 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
447 |
||
448 |
QList<int> list3 = QtConcurrent::mapped(list.constBegin(), |
|
449 |
list.constEnd(), |
|
450 |
MultiplyBy2()).results(); |
|
451 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
452 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
453 |
||
454 |
QList<int> list4 = QtConcurrent::mapped(QList<int>(list), MultiplyBy2()).results(); |
|
455 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
456 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
457 |
} |
|
458 |
{ |
|
459 |
QList<int> list2 = QtConcurrent::mapped(linkedList, MultiplyBy2()).results(); |
|
460 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
461 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
462 |
||
463 |
QList<int> list3 = QtConcurrent::mapped(linkedList.constBegin(), |
|
464 |
linkedList.constEnd(), |
|
465 |
MultiplyBy2()).results(); |
|
466 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
467 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
468 |
||
469 |
QList<int> list4 = |
|
470 |
QtConcurrent::mapped(QLinkedList<int>(linkedList), MultiplyBy2()).results(); |
|
471 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
472 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
473 |
} |
|
474 |
||
475 |
// function |
|
476 |
{ |
|
477 |
QList<int> list2 = QtConcurrent::mapped(list, multiplyBy2).results(); |
|
478 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
479 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
480 |
||
481 |
QList<int> list3 = QtConcurrent::mapped(list.constBegin(), |
|
482 |
list.constEnd(), |
|
483 |
multiplyBy2).results(); |
|
484 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
485 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
486 |
||
487 |
QList<int> list4 = QtConcurrent::mapped(QList<int>(list), multiplyBy2).results(); |
|
488 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
489 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
490 |
} |
|
491 |
{ |
|
492 |
QList<int> list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results(); |
|
493 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
494 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
495 |
||
496 |
QList<int> list3 = QtConcurrent::mapped(linkedList.constBegin(), |
|
497 |
linkedList.constEnd(), |
|
498 |
multiplyBy2).results(); |
|
499 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
500 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
501 |
||
502 |
QList<int> list4 = |
|
503 |
QtConcurrent::mapped(QLinkedList<int>(linkedList), multiplyBy2).results(); |
|
504 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
505 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
506 |
} |
|
507 |
||
508 |
// bound function |
|
509 |
{ |
|
510 |
QList<int> list2 = QtConcurrent::mapped(list, multiplyBy2).results(); |
|
511 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
512 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
513 |
||
514 |
QList<int> list3 = QtConcurrent::mapped(list.constBegin(), |
|
515 |
list.constEnd(), |
|
516 |
multiplyBy2).results(); |
|
517 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
518 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
519 |
||
520 |
QList<int> list4 = QtConcurrent::mapped(QList<int>(list), multiplyBy2).results(); |
|
521 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
522 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
523 |
} |
|
524 |
{ |
|
525 |
QList<int> list2 = QtConcurrent::mapped(linkedList, multiplyBy2).results(); |
|
526 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
527 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
528 |
||
529 |
QList<int> list3 = QtConcurrent::mapped(linkedList.constBegin(), |
|
530 |
linkedList.constEnd(), |
|
531 |
multiplyBy2) |
|
532 |
.results(); |
|
533 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
534 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
535 |
||
536 |
QList<int> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList), multiplyBy2) |
|
537 |
.results(); |
|
538 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
539 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
540 |
} |
|
541 |
||
542 |
// const member function |
|
543 |
{ |
|
544 |
QList<Number> numberList2 = QtConcurrent::mapped(numberList, &Number::multipliedBy2) |
|
545 |
.results(); |
|
546 |
QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3); |
|
547 |
QCOMPARE(numberList2, QList<Number>() << 2 << 4 << 6); |
|
548 |
||
549 |
QList<Number> numberList3 = QtConcurrent::mapped(numberList.constBegin(), |
|
550 |
numberList.constEnd(), |
|
551 |
&Number::multipliedBy2) |
|
552 |
.results(); |
|
553 |
QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3); |
|
554 |
QCOMPARE(numberList3, QList<Number>() << 2 << 4 << 6); |
|
555 |
||
556 |
QList<Number> numberList4 = QtConcurrent::mapped(QList<Number>(numberList), |
|
557 |
&Number::multipliedBy2) |
|
558 |
.results(); |
|
559 |
QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3); |
|
560 |
QCOMPARE(numberList4, QList<Number>() << 2 << 4 << 6); |
|
561 |
} |
|
562 |
{ |
|
563 |
QList<Number> numberList2 = QtConcurrent::mapped(numberLinkedList, &Number::multipliedBy2) |
|
564 |
.results(); |
|
565 |
QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3); |
|
566 |
QCOMPARE(numberList2, QList<Number>() << 2 << 4 << 6); |
|
567 |
||
568 |
QList<Number> numberList3 = QtConcurrent::mapped(numberLinkedList.constBegin(), |
|
569 |
numberLinkedList.constEnd(), |
|
570 |
&Number::multipliedBy2) |
|
571 |
.results(); |
|
572 |
QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3); |
|
573 |
QCOMPARE(numberList3, QList<Number>() << 2 << 4 << 6); |
|
574 |
||
575 |
QList<Number> numberList4 = QtConcurrent::mapped(QLinkedList<Number>(numberLinkedList), |
|
576 |
&Number::multipliedBy2) |
|
577 |
.results(); |
|
578 |
QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3); |
|
579 |
QCOMPARE(numberList4, QList<Number>() << 2 << 4 << 6); |
|
580 |
} |
|
581 |
||
582 |
// change the value_type, same container |
|
583 |
||
584 |
// functor |
|
585 |
{ |
|
586 |
QList<double> list2 = QtConcurrent::mapped(list, IntToDouble()).results(); |
|
587 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
588 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
589 |
||
590 |
QList<double> list3 = QtConcurrent::mapped(list.constBegin(), |
|
591 |
list.constEnd(), |
|
592 |
IntToDouble()) |
|
593 |
.results(); |
|
594 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
595 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
596 |
||
597 |
QList<double> list4 = QtConcurrent::mapped(QList<int>(list), |
|
598 |
IntToDouble()) |
|
599 |
.results(); |
|
600 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
601 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
602 |
} |
|
603 |
{ |
|
604 |
QList<double> list2 = QtConcurrent::mapped(linkedList, IntToDouble()).results(); |
|
605 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
606 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
607 |
||
608 |
QList<double> list3 = QtConcurrent::mapped(linkedList.constBegin(), |
|
609 |
linkedList.constEnd(), |
|
610 |
IntToDouble()) |
|
611 |
.results(); |
|
612 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
613 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
614 |
||
615 |
QList<double> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList), |
|
616 |
IntToDouble()) |
|
617 |
.results(); |
|
618 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
619 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
620 |
} |
|
621 |
||
622 |
// function |
|
623 |
{ |
|
624 |
QList<double> list2 = QtConcurrent::mapped(list, intToDouble).results(); |
|
625 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
626 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
627 |
||
628 |
QList<double> list3 = QtConcurrent::mapped(list.constBegin(), |
|
629 |
list.constEnd(), |
|
630 |
intToDouble) |
|
631 |
.results(); |
|
632 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
633 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
634 |
||
635 |
QList<double> list4 = QtConcurrent::mapped(QList<int>(list), intToDouble).results(); |
|
636 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
637 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
638 |
} |
|
639 |
{ |
|
640 |
QList<double> list2 = QtConcurrent::mapped(linkedList, intToDouble).results(); |
|
641 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
642 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
643 |
||
644 |
QList<double> list3 = QtConcurrent::mapped(linkedList.constBegin(), |
|
645 |
linkedList.constEnd(), |
|
646 |
intToDouble) |
|
647 |
.results(); |
|
648 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
649 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
650 |
||
651 |
QList<double> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList), intToDouble) |
|
652 |
.results(); |
|
653 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
654 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
655 |
} |
|
656 |
||
657 |
// bound function |
|
658 |
{ |
|
659 |
QList<double> list2 = QtConcurrent::mapped(list, intToDouble).results(); |
|
660 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
661 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
662 |
||
663 |
QList<double> list3 = QtConcurrent::mapped(list.constBegin(), |
|
664 |
list.constEnd(), |
|
665 |
intToDouble) |
|
666 |
.results(); |
|
667 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
668 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
669 |
||
670 |
||
671 |
QList<double> list4 = QtConcurrent::mapped(QList<int>(list), |
|
672 |
intToDouble) |
|
673 |
.results(); |
|
674 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
675 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
676 |
} |
|
677 |
{ |
|
678 |
QList<double> list2 = QtConcurrent::mapped(linkedList, intToDouble).results(); |
|
679 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
680 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
681 |
||
682 |
QList<double> list3 = QtConcurrent::mapped(linkedList.constBegin(), |
|
683 |
linkedList.constEnd(), |
|
684 |
intToDouble) |
|
685 |
.results(); |
|
686 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
687 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
688 |
||
689 |
||
690 |
QList<double> list4 = QtConcurrent::mapped(QLinkedList<int>(linkedList), |
|
691 |
intToDouble) |
|
692 |
.results(); |
|
693 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
694 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
695 |
} |
|
696 |
||
697 |
// const member function |
|
698 |
{ |
|
699 |
QList<QString> list2 = QtConcurrent::mapped(numberList, &Number::toString).results(); |
|
700 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
701 |
QCOMPARE(list2, QList<QString>() << "1" << "2" << "3"); |
|
702 |
||
703 |
QList<QString> list3 = QtConcurrent::mapped(numberList.constBegin(), |
|
704 |
numberList.constEnd(), |
|
705 |
&Number::toString) |
|
706 |
.results(); |
|
707 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
708 |
QCOMPARE(list3, QList<QString>() << "1" << "2" << "3"); |
|
709 |
||
710 |
QList<QString> list4 = QtConcurrent::mapped(QList<Number>(numberList), &Number::toString) |
|
711 |
.results(); |
|
712 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
713 |
QCOMPARE(list4, QList<QString>() << "1" << "2" << "3"); |
|
714 |
} |
|
715 |
{ |
|
716 |
QList<QString> list2 = QtConcurrent::mapped(numberLinkedList, &Number::toString).results(); |
|
717 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
718 |
QCOMPARE(list2, QList<QString>() << "1" << "2" << "3"); |
|
719 |
||
720 |
QList<QString> list3 = QtConcurrent::mapped(numberLinkedList.constBegin(), |
|
721 |
numberLinkedList.constEnd(), |
|
722 |
&Number::toString) |
|
723 |
.results(); |
|
724 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
725 |
QCOMPARE(list3, QList<QString>() << "1" << "2" << "3"); |
|
726 |
||
727 |
QList<QString> list4 = QtConcurrent::mapped(QLinkedList<Number>(numberLinkedList), |
|
728 |
&Number::toString) |
|
729 |
.results(); |
|
730 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
731 |
QCOMPARE(list4, QList<QString>() << "1" << "2" << "3"); |
|
732 |
} |
|
733 |
||
734 |
// change the value_type |
|
735 |
{ |
|
736 |
QList<QString> strings = QStringList() << "1" << "2" << "3"; |
|
737 |
QList<int> list = QtConcurrent::mapped(strings, StringToInt()).results(); |
|
738 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
739 |
||
740 |
QList<int> list2 = QtConcurrent::mapped(strings.constBegin(), |
|
741 |
strings.constEnd(), |
|
742 |
StringToInt()) |
|
743 |
.results(); |
|
744 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
745 |
} |
|
746 |
{ |
|
747 |
QList<QString> strings = QStringList() << "1" << "2" << "3"; |
|
748 |
QList<int> list = QtConcurrent::mapped(strings, stringToInt).results(); |
|
749 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
750 |
||
751 |
QList<int> list2 = QtConcurrent::mapped(strings.constBegin(), |
|
752 |
strings.constEnd(), |
|
753 |
stringToInt).results(); |
|
754 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
755 |
} |
|
756 |
||
757 |
{ |
|
758 |
QList<int> numberList2 = QtConcurrent::mapped(numberList, &Number::toInt).results(); |
|
759 |
QCOMPARE(numberList2, QList<int>() << 1 << 2 << 3); |
|
760 |
||
761 |
QList<int> numberList3 = QtConcurrent::mapped(numberList.constBegin(), |
|
762 |
numberList.constEnd(), |
|
763 |
&Number::toInt) |
|
764 |
.results(); |
|
765 |
QCOMPARE(numberList3, QList<int>() << 1 << 2 << 3); |
|
766 |
} |
|
767 |
||
768 |
// change the value_type from QStringList |
|
769 |
{ |
|
770 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
771 |
QList<int> list = QtConcurrent::mapped(strings, StringToInt()).results(); |
|
772 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
773 |
||
774 |
QList<int> list2 = QtConcurrent::mapped(strings.constBegin(), |
|
775 |
strings.constEnd(), |
|
776 |
StringToInt()) |
|
777 |
.results(); |
|
778 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
779 |
} |
|
780 |
{ |
|
781 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
782 |
QList<int> list = QtConcurrent::mapped(strings, stringToInt).results(); |
|
783 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
784 |
||
785 |
QList<int> list2 = QtConcurrent::mapped(strings.constBegin(), |
|
786 |
strings.constEnd(), |
|
787 |
stringToInt) |
|
788 |
.results(); |
|
789 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
790 |
} |
|
791 |
} |
|
792 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
793 |
void tst_QtConcurrentMap::blocking_mapped() |
0 | 794 |
{ |
795 |
QList<int> list; |
|
796 |
list << 1 << 2 << 3; |
|
797 |
QLinkedList<int> linkedList; |
|
798 |
linkedList << 1 << 2 << 3; |
|
799 |
QList<Number> numberList; |
|
800 |
numberList << 1 << 2 << 3; |
|
801 |
QLinkedList<Number> numberLinkedList; |
|
802 |
numberLinkedList << 1 << 2 << 3; |
|
803 |
||
804 |
// functor |
|
805 |
{ |
|
806 |
QList<int> list2 = QtConcurrent::blockingMapped(list, MultiplyBy2()); |
|
807 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
808 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
809 |
||
810 |
QList<int> list3 = QtConcurrent::blockingMapped<QList<int> >(list.constBegin(), |
|
811 |
list.constEnd(), |
|
812 |
MultiplyBy2()); |
|
813 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
814 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
815 |
||
816 |
QList<int> list4 = QtConcurrent::blockingMapped(QList<int>(list), MultiplyBy2()); |
|
817 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
818 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
819 |
} |
|
820 |
{ |
|
821 |
QLinkedList<int> linkedList2 = QtConcurrent::blockingMapped(linkedList, MultiplyBy2()); |
|
822 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
823 |
QCOMPARE(linkedList2, QLinkedList<int>() << 2 << 4 << 6); |
|
824 |
||
825 |
QLinkedList<int> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<int> >(linkedList.constBegin(), |
|
826 |
linkedList.constEnd(), |
|
827 |
MultiplyBy2()); |
|
828 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
829 |
QCOMPARE(linkedList3, QLinkedList<int>() << 2 << 4 << 6); |
|
830 |
||
831 |
QLinkedList<int> linkedList4 = QtConcurrent::blockingMapped(QLinkedList<int>(linkedList), MultiplyBy2()); |
|
832 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
833 |
QCOMPARE(linkedList4, QLinkedList<int>() << 2 << 4 << 6); |
|
834 |
} |
|
835 |
||
836 |
// function |
|
837 |
{ |
|
838 |
QList<int> list2 = QtConcurrent::blockingMapped(list, multiplyBy2); |
|
839 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
840 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
841 |
||
842 |
QList<int> list3 = QtConcurrent::blockingMapped<QList<int> >(list.constBegin(), |
|
843 |
list.constEnd(), |
|
844 |
multiplyBy2); |
|
845 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
846 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
847 |
||
848 |
QList<int> list4 = QtConcurrent::blockingMapped(QList<int>(list), multiplyBy2); |
|
849 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
850 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
851 |
} |
|
852 |
{ |
|
853 |
QLinkedList<int> linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2); |
|
854 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
855 |
QCOMPARE(linkedList2, QLinkedList<int>() << 2 << 4 << 6); |
|
856 |
||
857 |
QLinkedList<int> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<int> >(linkedList.constBegin(), |
|
858 |
linkedList.constEnd(), |
|
859 |
multiplyBy2); |
|
860 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
861 |
QCOMPARE(linkedList3, QLinkedList<int>() << 2 << 4 << 6); |
|
862 |
||
863 |
QLinkedList<int> linkedList4 = QtConcurrent::blockingMapped(QLinkedList<int>(linkedList), multiplyBy2); |
|
864 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
865 |
QCOMPARE(linkedList4, QLinkedList<int>() << 2 << 4 << 6); |
|
866 |
} |
|
867 |
||
868 |
// bound function |
|
869 |
{ |
|
870 |
QList<int> list2 = QtConcurrent::blockingMapped(list, multiplyBy2); |
|
871 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
872 |
QCOMPARE(list2, QList<int>() << 2 << 4 << 6); |
|
873 |
||
874 |
QList<int> list3 = QtConcurrent::blockingMapped<QList<int> >(list.constBegin(), |
|
875 |
list.constEnd(), |
|
876 |
multiplyBy2); |
|
877 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
878 |
QCOMPARE(list3, QList<int>() << 2 << 4 << 6); |
|
879 |
||
880 |
QList<int> list4 = QtConcurrent::blockingMapped(QList<int>(list), multiplyBy2); |
|
881 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
882 |
QCOMPARE(list4, QList<int>() << 2 << 4 << 6); |
|
883 |
} |
|
884 |
{ |
|
885 |
QLinkedList<int> linkedList2 = QtConcurrent::blockingMapped(linkedList, multiplyBy2); |
|
886 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
887 |
QCOMPARE(linkedList2, QLinkedList<int>() << 2 << 4 << 6); |
|
888 |
||
889 |
QLinkedList<int> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<int> >(linkedList.constBegin(), |
|
890 |
linkedList.constEnd(), |
|
891 |
multiplyBy2); |
|
892 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
893 |
QCOMPARE(linkedList3, QLinkedList<int>() << 2 << 4 << 6); |
|
894 |
||
895 |
QLinkedList<int> linkedList4 = QtConcurrent::blockingMapped(QLinkedList<int>(linkedList), multiplyBy2); |
|
896 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
897 |
QCOMPARE(linkedList4, QLinkedList<int>() << 2 << 4 << 6); |
|
898 |
} |
|
899 |
||
900 |
// const member function |
|
901 |
{ |
|
902 |
QList<Number> numberList2 = QtConcurrent::blockingMapped(numberList, &Number::multipliedBy2); |
|
903 |
QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3); |
|
904 |
QCOMPARE(numberList2, QList<Number>() << 2 << 4 << 6); |
|
905 |
||
906 |
QList<Number> numberList3 = QtConcurrent::blockingMapped<QList<Number> >(numberList.constBegin(), |
|
907 |
numberList.constEnd(), |
|
908 |
&Number::multipliedBy2); |
|
909 |
QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3); |
|
910 |
QCOMPARE(numberList3, QList<Number>() << 2 << 4 << 6); |
|
911 |
||
912 |
QList<Number> numberList4 = QtConcurrent::blockingMapped(QList<Number>(numberList), |
|
913 |
&Number::multipliedBy2); |
|
914 |
QCOMPARE(numberList, QList<Number>() << 1 << 2 << 3); |
|
915 |
QCOMPARE(numberList4, QList<Number>() << 2 << 4 << 6); |
|
916 |
} |
|
917 |
{ |
|
918 |
QLinkedList<Number> numberLinkedList2 = QtConcurrent::blockingMapped(numberLinkedList, &Number::multipliedBy2); |
|
919 |
QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3); |
|
920 |
QCOMPARE(numberLinkedList2, QLinkedList<Number>() << 2 << 4 << 6); |
|
921 |
||
922 |
QLinkedList<Number> numberLinkedList3 = QtConcurrent::blockingMapped<QLinkedList<Number> >(numberLinkedList.constBegin(), |
|
923 |
numberLinkedList.constEnd(), |
|
924 |
&Number::multipliedBy2); |
|
925 |
QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3); |
|
926 |
QCOMPARE(numberLinkedList3, QLinkedList<Number>() << 2 << 4 << 6); |
|
927 |
||
928 |
QLinkedList<Number> numberLinkedList4 = QtConcurrent::blockingMapped(QLinkedList<Number>(numberLinkedList), |
|
929 |
&Number::multipliedBy2); |
|
930 |
QCOMPARE(numberLinkedList, QLinkedList<Number>() << 1 << 2 << 3); |
|
931 |
QCOMPARE(numberLinkedList4, QLinkedList<Number>() << 2 << 4 << 6); |
|
932 |
} |
|
933 |
||
934 |
// change the value_type, same container |
|
935 |
||
936 |
// functor |
|
937 |
{ |
|
938 |
QList<double> list2 = QtConcurrent::blockingMapped<QList<double> >(list, IntToDouble()); |
|
939 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
940 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
941 |
||
942 |
QList<double> list3 = QtConcurrent::blockingMapped<QList<double> >(list.constBegin(), |
|
943 |
list.constEnd(), |
|
944 |
IntToDouble()); |
|
945 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
946 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
947 |
||
948 |
QList<double> list4 = QtConcurrent::blockingMapped<QList<double> >(QList<int>(list), |
|
949 |
IntToDouble()); |
|
950 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
951 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
952 |
} |
|
953 |
{ |
|
954 |
QLinkedList<double> linkedList2 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList, IntToDouble()); |
|
955 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
956 |
QCOMPARE(linkedList2, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
957 |
||
958 |
QLinkedList<double> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList.constBegin(), |
|
959 |
linkedList.constEnd(), |
|
960 |
IntToDouble()); |
|
961 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
962 |
QCOMPARE(linkedList3, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
963 |
||
964 |
QLinkedList<double> linkedList4 = QtConcurrent::blockingMapped<QLinkedList<double> >(QLinkedList<int>(linkedList), |
|
965 |
IntToDouble()); |
|
966 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
967 |
QCOMPARE(linkedList4, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
968 |
} |
|
969 |
||
970 |
// function |
|
971 |
{ |
|
972 |
QList<double> list2 = QtConcurrent::blockingMapped<QList<double> >(list, intToDouble); |
|
973 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
974 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
975 |
||
976 |
QList<double> list3 = QtConcurrent::blockingMapped<QList<double> >(list.constBegin(), |
|
977 |
list.constEnd(), |
|
978 |
intToDouble); |
|
979 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
980 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
981 |
||
982 |
QList<double> list4 = QtConcurrent::blockingMapped<QList<double> >(QList<int>(list), intToDouble); |
|
983 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
984 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
985 |
} |
|
986 |
{ |
|
987 |
QLinkedList<double> linkedList2 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList, intToDouble); |
|
988 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
989 |
QCOMPARE(linkedList2, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
990 |
||
991 |
QLinkedList<double> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList.constBegin(), |
|
992 |
linkedList.constEnd(), |
|
993 |
intToDouble); |
|
994 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
995 |
QCOMPARE(linkedList3, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
996 |
||
997 |
QLinkedList<double> linkedList4 = QtConcurrent::blockingMapped<QLinkedList<double> >(QLinkedList<int>(linkedList), intToDouble); |
|
998 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
999 |
QCOMPARE(linkedList4, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
1000 |
} |
|
1001 |
||
1002 |
// bound function |
|
1003 |
{ |
|
1004 |
QList<double> list2 = QtConcurrent::blockingMapped<QList<double> >(list, intToDouble); |
|
1005 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1006 |
QCOMPARE(list2, QList<double>() << 1.0 << 2.0 << 3.0); |
|
1007 |
||
1008 |
QList<double> list3 = QtConcurrent::blockingMapped<QList<double> >(list.constBegin(), |
|
1009 |
list.constEnd(), |
|
1010 |
intToDouble); |
|
1011 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1012 |
QCOMPARE(list3, QList<double>() << 1.0 << 2.0 << 3.0); |
|
1013 |
||
1014 |
||
1015 |
QList<double> list4 = QtConcurrent::blockingMapped<QList<double> >(QList<int>(list), |
|
1016 |
intToDouble); |
|
1017 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1018 |
QCOMPARE(list4, QList<double>() << 1.0 << 2.0 << 3.0); |
|
1019 |
} |
|
1020 |
{ |
|
1021 |
QLinkedList<double> linkedList2 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList, intToDouble); |
|
1022 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1023 |
QCOMPARE(linkedList2, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
1024 |
||
1025 |
QLinkedList<double> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<double> >(linkedList.constBegin(), |
|
1026 |
linkedList.constEnd(), |
|
1027 |
intToDouble); |
|
1028 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1029 |
QCOMPARE(linkedList3, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
1030 |
||
1031 |
||
1032 |
QLinkedList<double> linkedList4 = QtConcurrent::blockingMapped<QLinkedList<double> >(QLinkedList<int>(linkedList), |
|
1033 |
intToDouble); |
|
1034 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1035 |
QCOMPARE(linkedList4, QLinkedList<double>() << 1.0 << 2.0 << 3.0); |
|
1036 |
} |
|
1037 |
||
1038 |
// const member function |
|
1039 |
{ |
|
1040 |
QList<QString> list2 = |
|
1041 |
QtConcurrent::blockingMapped<QList<QString> >(numberList, &Number::toString); |
|
1042 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1043 |
QCOMPARE(list2, QList<QString>() << "1" << "2" << "3"); |
|
1044 |
||
1045 |
QList<QString> list3 = QtConcurrent::blockingMapped<QList<QString> >(numberList.constBegin(), |
|
1046 |
numberList.constEnd() |
|
1047 |
, &Number::toString); |
|
1048 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1049 |
QCOMPARE(list3, QList<QString>() << "1" << "2" << "3"); |
|
1050 |
||
1051 |
QList<QString> list4 = |
|
1052 |
QtConcurrent::blockingMapped<QList<QString> >(QList<Number>(numberList), &Number::toString); |
|
1053 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1054 |
QCOMPARE(list4, QList<QString>() << "1" << "2" << "3"); |
|
1055 |
} |
|
1056 |
{ |
|
1057 |
QLinkedList<QString> linkedList2 = |
|
1058 |
QtConcurrent::blockingMapped<QLinkedList<QString> >(numberLinkedList, &Number::toString); |
|
1059 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1060 |
QCOMPARE(linkedList2, QLinkedList<QString>() << "1" << "2" << "3"); |
|
1061 |
||
1062 |
QLinkedList<QString> linkedList3 = QtConcurrent::blockingMapped<QLinkedList<QString> >(numberLinkedList.constBegin(), |
|
1063 |
numberLinkedList.constEnd() |
|
1064 |
, &Number::toString); |
|
1065 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1066 |
QCOMPARE(linkedList3, QLinkedList<QString>() << "1" << "2" << "3"); |
|
1067 |
||
1068 |
QLinkedList<QString> linkedList4 = |
|
1069 |
QtConcurrent::blockingMapped<QLinkedList<QString> >(QLinkedList<Number>(numberLinkedList), &Number::toString); |
|
1070 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1071 |
QCOMPARE(linkedList4, QLinkedList<QString>() << "1" << "2" << "3"); |
|
1072 |
} |
|
1073 |
||
1074 |
// change the value_type |
|
1075 |
{ |
|
1076 |
QList<QString> strings = QStringList() << "1" << "2" << "3"; |
|
1077 |
QList<int> list = QtConcurrent::blockingMapped(strings, StringToInt()); |
|
1078 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1079 |
||
1080 |
QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(), |
|
1081 |
strings.constEnd(), |
|
1082 |
StringToInt()); |
|
1083 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
1084 |
} |
|
1085 |
{ |
|
1086 |
QList<QString> strings = QStringList() << "1" << "2" << "3"; |
|
1087 |
QList<int> list = QtConcurrent::blockingMapped(strings, stringToInt); |
|
1088 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1089 |
||
1090 |
QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(), |
|
1091 |
strings.constEnd(), |
|
1092 |
stringToInt); |
|
1093 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
1094 |
} |
|
1095 |
||
1096 |
{ |
|
1097 |
QList<int> numberList2 = QtConcurrent::blockingMapped(numberList, &Number::toInt); |
|
1098 |
QCOMPARE(numberList2, QList<int>() << 1 << 2 << 3); |
|
1099 |
||
1100 |
QList<int> numberList3 = QtConcurrent::blockingMapped<QList<int> >(numberList.constBegin(), |
|
1101 |
numberList.constEnd(), |
|
1102 |
&Number::toInt); |
|
1103 |
QCOMPARE(numberList3, QList<int>() << 1 << 2 << 3); |
|
1104 |
} |
|
1105 |
||
1106 |
// change the value_type from QStringList |
|
1107 |
{ |
|
1108 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
1109 |
QList<int> list = QtConcurrent::blockingMapped(strings, StringToInt()); |
|
1110 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1111 |
||
1112 |
QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(), |
|
1113 |
strings.constEnd(), |
|
1114 |
StringToInt()); |
|
1115 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
1116 |
} |
|
1117 |
{ |
|
1118 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
1119 |
QList<int> list = QtConcurrent::blockingMapped(strings, stringToInt); |
|
1120 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1121 |
||
1122 |
QList<int> list2 = QtConcurrent::blockingMapped<QList<int> >(strings.constBegin(), |
|
1123 |
strings.constEnd(), |
|
1124 |
stringToInt); |
|
1125 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
1126 |
} |
|
1127 |
||
1128 |
// functor |
|
1129 |
{ |
|
1130 |
QVector<double> list2 = QtConcurrent::blockingMapped<QVector<double> >(list, IntToDouble()); |
|
1131 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1132 |
QCOMPARE(list2, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1133 |
||
1134 |
QVector<double> list3 = QtConcurrent::blockingMapped<QVector<double> >(list.constBegin(), |
|
1135 |
list.constEnd(), |
|
1136 |
IntToDouble()); |
|
1137 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1138 |
QCOMPARE(list3, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1139 |
||
1140 |
QVector<double> list4 = QtConcurrent::blockingMapped<QVector<double> >(QList<int>(list), |
|
1141 |
IntToDouble()); |
|
1142 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1143 |
QCOMPARE(list4, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1144 |
||
1145 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
1146 |
QVector<int> list5 = QtConcurrent::blockingMapped<QVector<int> >(strings, StringToInt()); |
|
1147 |
QCOMPARE(list5, QVector<int>() << 1 << 2 << 3); |
|
1148 |
||
1149 |
QVector<int> list6 = QtConcurrent::blockingMapped<QVector<int> >(strings.constBegin(), |
|
1150 |
strings.constEnd(), |
|
1151 |
StringToInt()); |
|
1152 |
QCOMPARE(list6, QVector<int>() << 1 << 2 << 3); |
|
1153 |
||
1154 |
QVector<int> list7 = QtConcurrent::blockingMapped<QVector<int> >(QStringList(strings), |
|
1155 |
StringToInt()); |
|
1156 |
QCOMPARE(list7, QVector<int>() << 1 << 2 << 3); |
|
1157 |
} |
|
1158 |
||
1159 |
// function |
|
1160 |
{ |
|
1161 |
QVector<double> list2 = QtConcurrent::blockingMapped<QVector<double> >(list, intToDouble); |
|
1162 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1163 |
QCOMPARE(list2, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1164 |
||
1165 |
QVector<double> list3 = QtConcurrent::blockingMapped<QVector<double> >(list.constBegin(), |
|
1166 |
list.constEnd(), |
|
1167 |
intToDouble); |
|
1168 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1169 |
QCOMPARE(list3, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1170 |
||
1171 |
QVector<double> list4 = QtConcurrent::blockingMapped<QVector<double> >(QList<int>(list), |
|
1172 |
intToDouble); |
|
1173 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1174 |
QCOMPARE(list4, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1175 |
||
1176 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
1177 |
QVector<int> list5 = QtConcurrent::blockingMapped<QVector<int> >(strings, stringToInt); |
|
1178 |
QCOMPARE(list5, QVector<int>() << 1 << 2 << 3); |
|
1179 |
||
1180 |
QVector<int> list6 = QtConcurrent::blockingMapped<QVector<int> >(strings.constBegin(), |
|
1181 |
strings.constEnd(), |
|
1182 |
stringToInt); |
|
1183 |
QCOMPARE(list6, QVector<int>() << 1 << 2 << 3); |
|
1184 |
||
1185 |
QVector<int> list7 = QtConcurrent::blockingMapped<QVector<int> >(QStringList(strings), |
|
1186 |
stringToInt); |
|
1187 |
QCOMPARE(list7, QVector<int>() << 1 << 2 << 3); |
|
1188 |
} |
|
1189 |
||
1190 |
// bound function |
|
1191 |
{ |
|
1192 |
QVector<double> list2 = QtConcurrent::blockingMapped<QVector<double> >(list, intToDouble); |
|
1193 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1194 |
QCOMPARE(list2, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1195 |
||
1196 |
QVector<double> list3 = QtConcurrent::blockingMapped<QVector<double> >(QList<int>(list), intToDouble); |
|
1197 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1198 |
QCOMPARE(list3, QVector<double>() << 1.0 << 2.0 << 3.0); |
|
1199 |
||
1200 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
1201 |
QVector<int> list4 = QtConcurrent::blockingMapped<QVector<int> >(strings, stringToInt); |
|
1202 |
QCOMPARE(list4, QVector<int>() << 1 << 2 << 3); |
|
1203 |
||
1204 |
QVector<int> list5 = QtConcurrent::blockingMapped<QVector<int> >(QStringList(strings), stringToInt); |
|
1205 |
QCOMPARE(list5, QVector<int>() << 1 << 2 << 3); |
|
1206 |
} |
|
1207 |
||
1208 |
// const member function |
|
1209 |
{ |
|
1210 |
QVector<QString> list2 = QtConcurrent::blockingMapped<QVector<QString> >(numberList, &Number::toString); |
|
1211 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1212 |
QCOMPARE(list2, QVector<QString>() << "1" << "2" << "3"); |
|
1213 |
||
1214 |
QVector<QString> list3 = |
|
1215 |
QtConcurrent::blockingMapped<QVector<QString> >(QList<Number>(numberList), &Number::toString); |
|
1216 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1217 |
QCOMPARE(list3, QVector<QString>() << "1" << "2" << "3"); |
|
1218 |
||
1219 |
// not allowed: const member function where all arguments have default values |
|
1220 |
#if 0 |
|
1221 |
QStringList strings = QStringList() << "1" << "2" << "3"; |
|
1222 |
QVector<int> list4 = QtConcurrent::blockingMapped<QVector<int> >(strings, &QString::toInt); |
|
1223 |
QCOMPARE(list4, QVector<int>() << 1 << 2 << 3); |
|
1224 |
||
1225 |
QVector<int> list5 = QtConcurrent::blockingMapped<QVector<int> >(QStringList(strings), &QString::toInt); |
|
1226 |
QCOMPARE(list5, QVector<int>() << 1 << 2 << 3); |
|
1227 |
#endif |
|
1228 |
} |
|
1229 |
} |
|
1230 |
||
1231 |
int intSquare(int x) |
|
1232 |
{ |
|
1233 |
return x * x; |
|
1234 |
} |
|
1235 |
||
1236 |
class IntSquare |
|
1237 |
{ |
|
1238 |
public: |
|
1239 |
typedef int result_type; |
|
1240 |
||
1241 |
int operator()(int x) |
|
1242 |
{ |
|
1243 |
return x * x; |
|
1244 |
} |
|
1245 |
}; |
|
1246 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1247 |
void tst_QtConcurrentMap::mappedReduced() |
0 | 1248 |
{ |
1249 |
QList<int> list; |
|
1250 |
list << 1 << 2 << 3; |
|
1251 |
QLinkedList<int> linkedList; |
|
1252 |
linkedList << 1 << 2 << 3; |
|
1253 |
QList<Number> numberList; |
|
1254 |
numberList << 1 << 2 << 3; |
|
1255 |
QLinkedList<Number> numberLinkedList; |
|
1256 |
numberLinkedList << 1 << 2 << 3; |
|
1257 |
||
1258 |
// test Q_DECLARE_OPERATORS_FOR_FLAGS |
|
1259 |
QtConcurrent::ReduceOptions opt = (QtConcurrent::UnorderedReduce | QtConcurrent::SequentialReduce); |
|
1260 |
||
1261 |
// functor-functor |
|
1262 |
{ |
|
1263 |
int sum = QtConcurrent::mappedReduced<int>(list, IntSquare(), IntSumReduce()); |
|
1264 |
QCOMPARE(sum, 14); |
|
1265 |
int sum2 = QtConcurrent::mappedReduced<int>(list.constBegin(), |
|
1266 |
list.constEnd(), |
|
1267 |
IntSquare(), |
|
1268 |
IntSumReduce()); |
|
1269 |
QCOMPARE(sum2, 14); |
|
1270 |
||
1271 |
int sum3 = QtConcurrent::mappedReduced<int>(QList<int>(list), IntSquare(), IntSumReduce()); |
|
1272 |
QCOMPARE(sum3, 14); |
|
1273 |
||
1274 |
int sum4 = QtConcurrent::mappedReduced<int>(list, intSquare, intSumReduce); |
|
1275 |
QCOMPARE(sum4, 14); |
|
1276 |
int sum5 = QtConcurrent::mappedReduced<int>(list.constBegin(), |
|
1277 |
list.constEnd(), |
|
1278 |
intSquare, |
|
1279 |
intSumReduce); |
|
1280 |
QCOMPARE(sum5, 14); |
|
1281 |
||
1282 |
int sum6 = QtConcurrent::mappedReduced<int>(QList<int>(list), |
|
1283 |
intSquare, |
|
1284 |
intSumReduce); |
|
1285 |
QCOMPARE(sum6, 14); |
|
1286 |
} |
|
1287 |
{ |
|
1288 |
int sum = QtConcurrent::mappedReduced<int>(linkedList, IntSquare(), IntSumReduce()); |
|
1289 |
QCOMPARE(sum, 14); |
|
1290 |
int sum2 = QtConcurrent::mappedReduced<int>(linkedList.constBegin(), |
|
1291 |
linkedList.constEnd(), |
|
1292 |
IntSquare(), |
|
1293 |
IntSumReduce()); |
|
1294 |
QCOMPARE(sum2, 14); |
|
1295 |
||
1296 |
int sum3 = QtConcurrent::mappedReduced<int>(QLinkedList<int>(linkedList), IntSquare(), IntSumReduce()); |
|
1297 |
QCOMPARE(sum3, 14); |
|
1298 |
||
1299 |
int sum4 = QtConcurrent::mappedReduced<int>(linkedList, intSquare, intSumReduce); |
|
1300 |
QCOMPARE(sum4, 14); |
|
1301 |
int sum5 = QtConcurrent::mappedReduced<int>(linkedList.constBegin(), |
|
1302 |
linkedList.constEnd(), |
|
1303 |
intSquare, |
|
1304 |
intSumReduce); |
|
1305 |
QCOMPARE(sum5, 14); |
|
1306 |
||
1307 |
int sum6 = QtConcurrent::mappedReduced<int>(QLinkedList<int>(linkedList), |
|
1308 |
intSquare, |
|
1309 |
intSumReduce); |
|
1310 |
QCOMPARE(sum6, 14); |
|
1311 |
} |
|
1312 |
||
1313 |
// function-functor |
|
1314 |
{ |
|
1315 |
int sum = QtConcurrent::mappedReduced<int>(list, intSquare, IntSumReduce()); |
|
1316 |
QCOMPARE(sum, 14); |
|
1317 |
int sum2 = QtConcurrent::mappedReduced<int>(list.constBegin(), |
|
1318 |
list.constEnd(), |
|
1319 |
intSquare, |
|
1320 |
IntSumReduce()); |
|
1321 |
QCOMPARE(sum2, 14); |
|
1322 |
||
1323 |
int sum3 = QtConcurrent::mappedReduced<int>(QList<int>(list), intSquare, IntSumReduce()); |
|
1324 |
QCOMPARE(sum3, 14); |
|
1325 |
} |
|
1326 |
{ |
|
1327 |
int sum = QtConcurrent::mappedReduced<int>(linkedList, intSquare, IntSumReduce()); |
|
1328 |
QCOMPARE(sum, 14); |
|
1329 |
int sum2 = QtConcurrent::mappedReduced<int>(linkedList.constBegin(), |
|
1330 |
linkedList.constEnd(), |
|
1331 |
intSquare, |
|
1332 |
IntSumReduce()); |
|
1333 |
QCOMPARE(sum2, 14); |
|
1334 |
||
1335 |
int sum3 = QtConcurrent::mappedReduced<int>(QLinkedList<int>(linkedList), intSquare, IntSumReduce()); |
|
1336 |
QCOMPARE(sum3, 14); |
|
1337 |
} |
|
1338 |
||
1339 |
// functor-function |
|
1340 |
{ |
|
1341 |
int sum = QtConcurrent::mappedReduced(list, IntSquare(), intSumReduce); |
|
1342 |
QCOMPARE(sum, 14); |
|
1343 |
int sum2 = QtConcurrent::mappedReduced(list.constBegin(), |
|
1344 |
list.constEnd(), |
|
1345 |
IntSquare(), |
|
1346 |
intSumReduce); |
|
1347 |
QCOMPARE(sum2, 14); |
|
1348 |
||
1349 |
int sum3 = QtConcurrent::mappedReduced(QList<int>(list), IntSquare(), intSumReduce); |
|
1350 |
QCOMPARE(sum3, 14); |
|
1351 |
} |
|
1352 |
{ |
|
1353 |
int sum = QtConcurrent::mappedReduced(linkedList, IntSquare(), intSumReduce); |
|
1354 |
QCOMPARE(sum, 14); |
|
1355 |
int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), |
|
1356 |
linkedList.constEnd(), |
|
1357 |
IntSquare(), |
|
1358 |
intSumReduce); |
|
1359 |
QCOMPARE(sum2, 14); |
|
1360 |
||
1361 |
int sum3 = QtConcurrent::mappedReduced(QLinkedList<int>(linkedList), IntSquare(), intSumReduce); |
|
1362 |
QCOMPARE(sum3, 14); |
|
1363 |
} |
|
1364 |
||
1365 |
// function-function |
|
1366 |
{ |
|
1367 |
int sum = QtConcurrent::mappedReduced(list, intSquare, intSumReduce); |
|
1368 |
QCOMPARE(sum, 14); |
|
1369 |
int sum2 = QtConcurrent::mappedReduced(list.constBegin(), |
|
1370 |
list.constEnd(), |
|
1371 |
intSquare, |
|
1372 |
intSumReduce); |
|
1373 |
QCOMPARE(sum2, 14); |
|
1374 |
||
1375 |
int sum3 = QtConcurrent::mappedReduced(QList<int>(list), intSquare, intSumReduce); |
|
1376 |
QCOMPARE(sum3, 14); |
|
1377 |
} |
|
1378 |
{ |
|
1379 |
int sum = QtConcurrent::mappedReduced(linkedList, intSquare, intSumReduce); |
|
1380 |
QCOMPARE(sum, 14); |
|
1381 |
int sum2 = QtConcurrent::mappedReduced(linkedList.constBegin(), |
|
1382 |
linkedList.constEnd(), |
|
1383 |
intSquare, |
|
1384 |
intSumReduce); |
|
1385 |
QCOMPARE(sum2, 14); |
|
1386 |
||
1387 |
int sum3 = QtConcurrent::mappedReduced(QLinkedList<int>(linkedList), intSquare, intSumReduce); |
|
1388 |
QCOMPARE(sum3, 14); |
|
1389 |
} |
|
1390 |
||
1391 |
// functor-member |
|
1392 |
{ |
|
1393 |
QList<int> list2 = QtConcurrent::mappedReduced(list, |
|
1394 |
IntSquare(), |
|
1395 |
&QList<int>::push_back, |
|
1396 |
OrderedReduce); |
|
1397 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1398 |
QCOMPARE(list2, QList<int>() << 1 << 4 << 9); |
|
1399 |
||
1400 |
QList<int> list3 = QtConcurrent::mappedReduced(list.constBegin(), |
|
1401 |
list.constEnd(), |
|
1402 |
IntSquare(), |
|
1403 |
&QList<int>::push_back, |
|
1404 |
OrderedReduce); |
|
1405 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1406 |
QCOMPARE(list3, QList<int>() << 1 << 4 << 9); |
|
1407 |
||
1408 |
QList<int> list4 = QtConcurrent::mappedReduced(QList<int>(list), |
|
1409 |
IntSquare(), |
|
1410 |
&QList<int>::push_back, |
|
1411 |
OrderedReduce); |
|
1412 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1413 |
QCOMPARE(list4, QList<int>() << 1 << 4 << 9); |
|
1414 |
} |
|
1415 |
{ |
|
1416 |
QLinkedList<int> linkedList2 = QtConcurrent::mappedReduced(linkedList, |
|
1417 |
IntSquare(), |
|
1418 |
&QLinkedList<int>::push_back, |
|
1419 |
OrderedReduce); |
|
1420 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1421 |
QCOMPARE(linkedList2, QLinkedList<int>() << 1 << 4 << 9); |
|
1422 |
||
1423 |
QLinkedList<int> linkedList3 = QtConcurrent::mappedReduced(linkedList.constBegin(), |
|
1424 |
linkedList.constEnd(), |
|
1425 |
IntSquare(), |
|
1426 |
&QLinkedList<int>::push_back, |
|
1427 |
OrderedReduce); |
|
1428 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1429 |
QCOMPARE(linkedList3, QLinkedList<int>() << 1 << 4 << 9); |
|
1430 |
||
1431 |
QLinkedList<int> linkedList4 = QtConcurrent::mappedReduced(QLinkedList<int>(linkedList), |
|
1432 |
IntSquare(), |
|
1433 |
&QLinkedList<int>::push_back, |
|
1434 |
OrderedReduce); |
|
1435 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1436 |
QCOMPARE(linkedList4, QLinkedList<int>() << 1 << 4 << 9); |
|
1437 |
} |
|
1438 |
||
1439 |
// member-functor |
|
1440 |
{ |
|
1441 |
int sum = QtConcurrent::mappedReduced<int>(numberList, &Number::toInt, IntSumReduce()); |
|
1442 |
QCOMPARE(sum, 6); |
|
1443 |
int sum2 = QtConcurrent::mappedReduced<int>(numberList.constBegin(), |
|
1444 |
numberList.constEnd(), |
|
1445 |
&Number::toInt, |
|
1446 |
IntSumReduce()); |
|
1447 |
QCOMPARE(sum2, 6); |
|
1448 |
||
1449 |
int sum3 = QtConcurrent::mappedReduced<int>(QList<Number>(numberList), |
|
1450 |
&Number::toInt, |
|
1451 |
IntSumReduce()); |
|
1452 |
QCOMPARE(sum3, 6); |
|
1453 |
} |
|
1454 |
{ |
|
1455 |
int sum = QtConcurrent::mappedReduced<int>(numberLinkedList, &Number::toInt, IntSumReduce()); |
|
1456 |
QCOMPARE(sum, 6); |
|
1457 |
int sum2 = QtConcurrent::mappedReduced<int>(numberLinkedList.constBegin(), |
|
1458 |
numberLinkedList.constEnd(), |
|
1459 |
&Number::toInt, |
|
1460 |
IntSumReduce()); |
|
1461 |
QCOMPARE(sum2, 6); |
|
1462 |
||
1463 |
int sum3 = QtConcurrent::mappedReduced<int>(QLinkedList<Number>(numberLinkedList), |
|
1464 |
&Number::toInt, |
|
1465 |
IntSumReduce()); |
|
1466 |
QCOMPARE(sum3, 6); |
|
1467 |
} |
|
1468 |
||
1469 |
// member-member |
|
1470 |
{ |
|
1471 |
QList<int> list2 = QtConcurrent::mappedReduced(numberList, |
|
1472 |
&Number::toInt, |
|
1473 |
&QList<int>::push_back, |
|
1474 |
OrderedReduce); |
|
1475 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
1476 |
||
1477 |
QList<int> list3 = QtConcurrent::mappedReduced(numberList.constBegin(), |
|
1478 |
numberList.constEnd(), |
|
1479 |
&Number::toInt, |
|
1480 |
&QList<int>::push_back, |
|
1481 |
OrderedReduce); |
|
1482 |
QCOMPARE(list3, QList<int>() << 1 << 2 << 3); |
|
1483 |
||
1484 |
QList<int> list4 = QtConcurrent::mappedReduced(QList<Number>(numberList), |
|
1485 |
&Number::toInt, |
|
1486 |
&QList<int>::push_back, OrderedReduce); |
|
1487 |
QCOMPARE(list4, QList<int>() << 1 << 2 << 3); |
|
1488 |
} |
|
1489 |
{ |
|
1490 |
QLinkedList<int> linkedList2 = QtConcurrent::mappedReduced(numberLinkedList, |
|
1491 |
&Number::toInt, |
|
1492 |
&QLinkedList<int>::push_back, |
|
1493 |
OrderedReduce); |
|
1494 |
QCOMPARE(linkedList2, QLinkedList<int>() << 1 << 2 << 3); |
|
1495 |
||
1496 |
QLinkedList<int> linkedList3 = QtConcurrent::mappedReduced(numberLinkedList.constBegin(), |
|
1497 |
numberLinkedList.constEnd(), |
|
1498 |
&Number::toInt, |
|
1499 |
&QLinkedList<int>::push_back, |
|
1500 |
OrderedReduce); |
|
1501 |
QCOMPARE(linkedList3, QLinkedList<int>() << 1 << 2 << 3); |
|
1502 |
||
1503 |
QLinkedList<int> linkedList4 = QtConcurrent::mappedReduced(QLinkedList<Number>(numberLinkedList), |
|
1504 |
&Number::toInt, |
|
1505 |
&QLinkedList<int>::push_back, OrderedReduce); |
|
1506 |
QCOMPARE(linkedList4, QLinkedList<int>() << 1 << 2 << 3); |
|
1507 |
} |
|
1508 |
||
1509 |
// function-member |
|
1510 |
{ |
|
1511 |
QList<int> list2 = QtConcurrent::mappedReduced(list, |
|
1512 |
intSquare, |
|
1513 |
&QList<int>::push_back, |
|
1514 |
OrderedReduce); |
|
1515 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1516 |
QCOMPARE(list2, QList<int>() << 1 << 4 << 9); |
|
1517 |
||
1518 |
QList<int> list3 = QtConcurrent::mappedReduced(list.constBegin(), |
|
1519 |
list.constEnd(), |
|
1520 |
intSquare, |
|
1521 |
&QList<int>::push_back, |
|
1522 |
OrderedReduce); |
|
1523 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1524 |
QCOMPARE(list3, QList<int>() << 1 << 4 << 9); |
|
1525 |
||
1526 |
QList<int> list4 = QtConcurrent::mappedReduced(QList<int>(list), |
|
1527 |
intSquare, |
|
1528 |
&QList<int>::push_back, |
|
1529 |
OrderedReduce); |
|
1530 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1531 |
QCOMPARE(list4, QList<int>() << 1 << 4 << 9); |
|
1532 |
} |
|
1533 |
{ |
|
1534 |
QLinkedList<int> linkedList2 = QtConcurrent::mappedReduced(linkedList, |
|
1535 |
intSquare, |
|
1536 |
&QLinkedList<int>::append, |
|
1537 |
OrderedReduce); |
|
1538 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1539 |
QCOMPARE(linkedList2, QLinkedList<int>() << 1 << 4 << 9); |
|
1540 |
||
1541 |
QLinkedList<int> linkedList3 = QtConcurrent::mappedReduced(linkedList.constBegin(), |
|
1542 |
linkedList.constEnd(), |
|
1543 |
intSquare, |
|
1544 |
&QLinkedList<int>::append, |
|
1545 |
OrderedReduce); |
|
1546 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1547 |
QCOMPARE(linkedList3, QLinkedList<int>() << 1 << 4 << 9); |
|
1548 |
||
1549 |
QLinkedList<int> linkedList4 = QtConcurrent::mappedReduced(QLinkedList<int>(linkedList), |
|
1550 |
intSquare, |
|
1551 |
&QLinkedList<int>::append, |
|
1552 |
OrderedReduce); |
|
1553 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1554 |
QCOMPARE(linkedList4, QLinkedList<int>() << 1 << 4 << 9); |
|
1555 |
} |
|
1556 |
||
1557 |
// member-function |
|
1558 |
{ |
|
1559 |
int sum = QtConcurrent::mappedReduced(numberList, |
|
1560 |
&Number::toInt, |
|
1561 |
intSumReduce); |
|
1562 |
QCOMPARE(sum, 6); |
|
1563 |
int sum2 = QtConcurrent::mappedReduced(numberList.constBegin(), |
|
1564 |
numberList.constEnd(), |
|
1565 |
&Number::toInt, |
|
1566 |
intSumReduce); |
|
1567 |
QCOMPARE(sum2, 6); |
|
1568 |
||
1569 |
int sum3 = QtConcurrent::mappedReduced(QList<Number>(numberList), |
|
1570 |
&Number::toInt, |
|
1571 |
intSumReduce); |
|
1572 |
QCOMPARE(sum3, 6); |
|
1573 |
} |
|
1574 |
{ |
|
1575 |
int sum = QtConcurrent::mappedReduced(numberLinkedList, |
|
1576 |
&Number::toInt, |
|
1577 |
intSumReduce); |
|
1578 |
QCOMPARE(sum, 6); |
|
1579 |
int sum2 = QtConcurrent::mappedReduced(numberLinkedList.constBegin(), |
|
1580 |
numberLinkedList.constEnd(), |
|
1581 |
&Number::toInt, |
|
1582 |
intSumReduce); |
|
1583 |
QCOMPARE(sum2, 6); |
|
1584 |
||
1585 |
int sum3 = QtConcurrent::mappedReduced(QLinkedList<Number>(numberLinkedList), |
|
1586 |
&Number::toInt, |
|
1587 |
intSumReduce); |
|
1588 |
QCOMPARE(sum3, 6); |
|
1589 |
} |
|
1590 |
||
1591 |
// linked lists |
|
1592 |
{ |
|
1593 |
||
1594 |
QLinkedList<int> list; |
|
1595 |
list << 1 << 2 << 3; |
|
1596 |
||
1597 |
QLinkedList<Number> numberList; |
|
1598 |
numberList << 1 << 2 << 3; |
|
1599 |
||
1600 |
int sum = QtConcurrent::mappedReduced<int>(list, IntSquare(), IntSumReduce()); |
|
1601 |
QCOMPARE(sum, 14); |
|
1602 |
int sum2 = QtConcurrent::mappedReduced<int>(list.constBegin(), |
|
1603 |
list.constEnd(), |
|
1604 |
IntSquare(), |
|
1605 |
IntSumReduce()); |
|
1606 |
QCOMPARE(sum2, 14); |
|
1607 |
||
1608 |
int sum3 = QtConcurrent::mappedReduced<int>(QLinkedList<int>(list), IntSquare(), IntSumReduce()); |
|
1609 |
QCOMPARE(sum3, 14); |
|
1610 |
||
1611 |
int sum4 = QtConcurrent::mappedReduced<int>(list, intSquare, intSumReduce); |
|
1612 |
QCOMPARE(sum4, 14); |
|
1613 |
int sum5 = QtConcurrent::mappedReduced<int>(list.constBegin(), |
|
1614 |
list.constEnd(), |
|
1615 |
intSquare, |
|
1616 |
intSumReduce); |
|
1617 |
QCOMPARE(sum5, 14); |
|
1618 |
||
1619 |
int sum6 = QtConcurrent::mappedReduced<int>(QLinkedList<int>(list), |
|
1620 |
intSquare, |
|
1621 |
intSumReduce); |
|
1622 |
QCOMPARE(sum6, 14); |
|
1623 |
} |
|
1624 |
||
1625 |
// ### the same as above, with an initial result value |
|
1626 |
} |
|
1627 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
1628 |
void tst_QtConcurrentMap::blocking_mappedReduced() |
0 | 1629 |
{ |
1630 |
QList<int> list; |
|
1631 |
list << 1 << 2 << 3; |
|
1632 |
QLinkedList<int> linkedList; |
|
1633 |
linkedList << 1 << 2 << 3; |
|
1634 |
QList<Number> numberList; |
|
1635 |
numberList << 1 << 2 << 3; |
|
1636 |
QLinkedList<Number> numberLinkedList; |
|
1637 |
numberLinkedList << 1 << 2 << 3; |
|
1638 |
||
1639 |
// functor-functor |
|
1640 |
{ |
|
1641 |
int sum = QtConcurrent::blockingMappedReduced<int>(list, IntSquare(), IntSumReduce()); |
|
1642 |
QCOMPARE(sum, 14); |
|
1643 |
int sum2 = QtConcurrent::blockingMappedReduced<int>(list.constBegin(), |
|
1644 |
list.constEnd(), |
|
1645 |
IntSquare(), |
|
1646 |
IntSumReduce()); |
|
1647 |
QCOMPARE(sum2, 14); |
|
1648 |
||
1649 |
int sum3 = QtConcurrent::blockingMappedReduced<int>(QList<int>(list), IntSquare(), IntSumReduce()); |
|
1650 |
QCOMPARE(sum3, 14); |
|
1651 |
||
1652 |
int sum4 = QtConcurrent::blockingMappedReduced<int>(list, intSquare, intSumReduce); |
|
1653 |
QCOMPARE(sum4, 14); |
|
1654 |
int sum5 = QtConcurrent::blockingMappedReduced<int>(list.constBegin(), |
|
1655 |
list.constEnd(), |
|
1656 |
intSquare, |
|
1657 |
intSumReduce); |
|
1658 |
QCOMPARE(sum5, 14); |
|
1659 |
||
1660 |
int sum6 = QtConcurrent::blockingMappedReduced<int>(QList<int>(list), |
|
1661 |
intSquare, |
|
1662 |
intSumReduce); |
|
1663 |
QCOMPARE(sum6, 14); |
|
1664 |
} |
|
1665 |
{ |
|
1666 |
int sum = QtConcurrent::blockingMappedReduced<int>(linkedList, IntSquare(), IntSumReduce()); |
|
1667 |
QCOMPARE(sum, 14); |
|
1668 |
int sum2 = QtConcurrent::blockingMappedReduced<int>(linkedList.constBegin(), |
|
1669 |
linkedList.constEnd(), |
|
1670 |
IntSquare(), |
|
1671 |
IntSumReduce()); |
|
1672 |
QCOMPARE(sum2, 14); |
|
1673 |
||
1674 |
int sum3 = QtConcurrent::blockingMappedReduced<int>(QLinkedList<int>(linkedList), IntSquare(), IntSumReduce()); |
|
1675 |
QCOMPARE(sum3, 14); |
|
1676 |
||
1677 |
int sum4 = QtConcurrent::blockingMappedReduced<int>(linkedList, intSquare, intSumReduce); |
|
1678 |
QCOMPARE(sum4, 14); |
|
1679 |
int sum5 = QtConcurrent::blockingMappedReduced<int>(linkedList.constBegin(), |
|
1680 |
linkedList.constEnd(), |
|
1681 |
intSquare, |
|
1682 |
intSumReduce); |
|
1683 |
QCOMPARE(sum5, 14); |
|
1684 |
||
1685 |
int sum6 = QtConcurrent::blockingMappedReduced<int>(QLinkedList<int>(linkedList), |
|
1686 |
intSquare, |
|
1687 |
intSumReduce); |
|
1688 |
QCOMPARE(sum6, 14); |
|
1689 |
} |
|
1690 |
||
1691 |
// function-functor |
|
1692 |
{ |
|
1693 |
int sum = QtConcurrent::blockingMappedReduced<int>(list, intSquare, IntSumReduce()); |
|
1694 |
QCOMPARE(sum, 14); |
|
1695 |
int sum2 = QtConcurrent::blockingMappedReduced<int>(list.constBegin(), |
|
1696 |
list.constEnd(), |
|
1697 |
intSquare, |
|
1698 |
IntSumReduce()); |
|
1699 |
QCOMPARE(sum2, 14); |
|
1700 |
||
1701 |
int sum3 = QtConcurrent::blockingMappedReduced<int>(QList<int>(list), intSquare, IntSumReduce()); |
|
1702 |
QCOMPARE(sum3, 14); |
|
1703 |
} |
|
1704 |
{ |
|
1705 |
int sum = QtConcurrent::blockingMappedReduced<int>(linkedList, intSquare, IntSumReduce()); |
|
1706 |
QCOMPARE(sum, 14); |
|
1707 |
int sum2 = QtConcurrent::blockingMappedReduced<int>(linkedList.constBegin(), |
|
1708 |
linkedList.constEnd(), |
|
1709 |
intSquare, |
|
1710 |
IntSumReduce()); |
|
1711 |
QCOMPARE(sum2, 14); |
|
1712 |
||
1713 |
int sum3 = QtConcurrent::blockingMappedReduced<int>(QLinkedList<int>(linkedList), intSquare, IntSumReduce()); |
|
1714 |
QCOMPARE(sum3, 14); |
|
1715 |
} |
|
1716 |
||
1717 |
// functor-function |
|
1718 |
{ |
|
1719 |
int sum = QtConcurrent::blockingMappedReduced(list, IntSquare(), intSumReduce); |
|
1720 |
QCOMPARE(sum, 14); |
|
1721 |
int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), |
|
1722 |
list.constEnd(), |
|
1723 |
IntSquare(), |
|
1724 |
intSumReduce); |
|
1725 |
QCOMPARE(sum2, 14); |
|
1726 |
||
1727 |
int sum3 = QtConcurrent::blockingMappedReduced(QList<int>(list), IntSquare(), intSumReduce); |
|
1728 |
QCOMPARE(sum3, 14); |
|
1729 |
} |
|
1730 |
{ |
|
1731 |
int sum = QtConcurrent::blockingMappedReduced(linkedList, IntSquare(), intSumReduce); |
|
1732 |
QCOMPARE(sum, 14); |
|
1733 |
int sum2 = QtConcurrent::blockingMappedReduced(linkedList.constBegin(), |
|
1734 |
linkedList.constEnd(), |
|
1735 |
IntSquare(), |
|
1736 |
intSumReduce); |
|
1737 |
QCOMPARE(sum2, 14); |
|
1738 |
||
1739 |
int sum3 = QtConcurrent::blockingMappedReduced(QLinkedList<int>(linkedList), IntSquare(), intSumReduce); |
|
1740 |
QCOMPARE(sum3, 14); |
|
1741 |
} |
|
1742 |
||
1743 |
// function-function |
|
1744 |
{ |
|
1745 |
int sum = QtConcurrent::blockingMappedReduced(list, intSquare, intSumReduce); |
|
1746 |
QCOMPARE(sum, 14); |
|
1747 |
int sum2 = QtConcurrent::blockingMappedReduced(list.constBegin(), |
|
1748 |
list.constEnd(), |
|
1749 |
intSquare, |
|
1750 |
intSumReduce); |
|
1751 |
QCOMPARE(sum2, 14); |
|
1752 |
||
1753 |
int sum3 = QtConcurrent::blockingMappedReduced(QList<int>(list), intSquare, intSumReduce); |
|
1754 |
QCOMPARE(sum3, 14); |
|
1755 |
} |
|
1756 |
{ |
|
1757 |
int sum = QtConcurrent::blockingMappedReduced(linkedList, intSquare, intSumReduce); |
|
1758 |
QCOMPARE(sum, 14); |
|
1759 |
int sum2 = QtConcurrent::blockingMappedReduced(linkedList.constBegin(), |
|
1760 |
linkedList.constEnd(), |
|
1761 |
intSquare, |
|
1762 |
intSumReduce); |
|
1763 |
QCOMPARE(sum2, 14); |
|
1764 |
||
1765 |
int sum3 = QtConcurrent::blockingMappedReduced(QLinkedList<int>(linkedList), intSquare, intSumReduce); |
|
1766 |
QCOMPARE(sum3, 14); |
|
1767 |
} |
|
1768 |
||
1769 |
// functor-member |
|
1770 |
{ |
|
1771 |
QList<int> list2 = QtConcurrent::blockingMappedReduced(list, |
|
1772 |
IntSquare(), |
|
1773 |
&QList<int>::push_back, |
|
1774 |
OrderedReduce); |
|
1775 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1776 |
QCOMPARE(list2, QList<int>() << 1 << 4 << 9); |
|
1777 |
||
1778 |
QList<int> list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), |
|
1779 |
list.constEnd(), |
|
1780 |
IntSquare(), |
|
1781 |
&QList<int>::push_back, |
|
1782 |
OrderedReduce); |
|
1783 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1784 |
QCOMPARE(list3, QList<int>() << 1 << 4 << 9); |
|
1785 |
||
1786 |
QList<int> list4 = QtConcurrent::blockingMappedReduced(QList<int>(list), |
|
1787 |
IntSquare(), |
|
1788 |
&QList<int>::push_back, |
|
1789 |
OrderedReduce); |
|
1790 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1791 |
QCOMPARE(list4, QList<int>() << 1 << 4 << 9); |
|
1792 |
} |
|
1793 |
{ |
|
1794 |
QLinkedList<int> linkedList2 = QtConcurrent::blockingMappedReduced(linkedList, |
|
1795 |
IntSquare(), |
|
1796 |
&QLinkedList<int>::append, |
|
1797 |
OrderedReduce); |
|
1798 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1799 |
QCOMPARE(linkedList2, QLinkedList<int>() << 1 << 4 << 9); |
|
1800 |
||
1801 |
QLinkedList<int> linkedList3 = QtConcurrent::blockingMappedReduced(linkedList.constBegin(), |
|
1802 |
linkedList.constEnd(), |
|
1803 |
IntSquare(), |
|
1804 |
&QLinkedList<int>::append, |
|
1805 |
OrderedReduce); |
|
1806 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1807 |
QCOMPARE(linkedList3, QLinkedList<int>() << 1 << 4 << 9); |
|
1808 |
||
1809 |
QLinkedList<int> linkedList4 = QtConcurrent::blockingMappedReduced(QLinkedList<int>(linkedList), |
|
1810 |
IntSquare(), |
|
1811 |
&QLinkedList<int>::append, |
|
1812 |
OrderedReduce); |
|
1813 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1814 |
QCOMPARE(linkedList4, QLinkedList<int>() << 1 << 4 << 9); |
|
1815 |
} |
|
1816 |
||
1817 |
// member-functor |
|
1818 |
{ |
|
1819 |
int sum = QtConcurrent::blockingMappedReduced<int>(numberList, &Number::toInt, |
|
1820 |
IntSumReduce()); |
|
1821 |
QCOMPARE(sum, 6); |
|
1822 |
int sum2 = QtConcurrent::blockingMappedReduced<int>(numberList.constBegin(), |
|
1823 |
numberList.constEnd(), |
|
1824 |
&Number::toInt, |
|
1825 |
IntSumReduce()); |
|
1826 |
QCOMPARE(sum2, 6); |
|
1827 |
||
1828 |
int sum3 = QtConcurrent::blockingMappedReduced<int>(QList<Number>(numberList), |
|
1829 |
&Number::toInt, |
|
1830 |
IntSumReduce()); |
|
1831 |
QCOMPARE(sum3, 6); |
|
1832 |
} |
|
1833 |
{ |
|
1834 |
int sum = QtConcurrent::blockingMappedReduced<int>(numberLinkedList, &Number::toInt, IntSumReduce()); |
|
1835 |
QCOMPARE(sum, 6); |
|
1836 |
int sum2 = QtConcurrent::blockingMappedReduced<int>(numberLinkedList.constBegin(), |
|
1837 |
numberLinkedList.constEnd(), |
|
1838 |
&Number::toInt, |
|
1839 |
IntSumReduce()); |
|
1840 |
QCOMPARE(sum2, 6); |
|
1841 |
||
1842 |
int sum3 = QtConcurrent::blockingMappedReduced<int>(QLinkedList<Number>(numberLinkedList), |
|
1843 |
&Number::toInt, |
|
1844 |
IntSumReduce()); |
|
1845 |
QCOMPARE(sum3, 6); |
|
1846 |
} |
|
1847 |
||
1848 |
// member-member |
|
1849 |
{ |
|
1850 |
QList<int> list2 = QtConcurrent::blockingMappedReduced(numberList, |
|
1851 |
&Number::toInt, |
|
1852 |
&QList<int>::push_back, |
|
1853 |
OrderedReduce); |
|
1854 |
QCOMPARE(list2, QList<int>() << 1 << 2 << 3); |
|
1855 |
||
1856 |
QList<int> list3 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), |
|
1857 |
numberList.constEnd(), |
|
1858 |
&Number::toInt, |
|
1859 |
&QList<int>::push_back, |
|
1860 |
OrderedReduce); |
|
1861 |
QCOMPARE(list3, QList<int>() << 1 << 2 << 3); |
|
1862 |
||
1863 |
QList<int> list4 = QtConcurrent::blockingMappedReduced(QList<Number>(numberList), |
|
1864 |
&Number::toInt, |
|
1865 |
&QList<int>::push_back, OrderedReduce); |
|
1866 |
QCOMPARE(list4, QList<int>() << 1 << 2 << 3); |
|
1867 |
} |
|
1868 |
{ |
|
1869 |
QLinkedList<int> linkedList2 = QtConcurrent::blockingMappedReduced(numberLinkedList, |
|
1870 |
&Number::toInt, |
|
1871 |
&QLinkedList<int>::append, |
|
1872 |
OrderedReduce); |
|
1873 |
QCOMPARE(linkedList2, QLinkedList<int>() << 1 << 2 << 3); |
|
1874 |
||
1875 |
QLinkedList<int> linkedList3 = QtConcurrent::blockingMappedReduced(numberLinkedList.constBegin(), |
|
1876 |
numberLinkedList.constEnd(), |
|
1877 |
&Number::toInt, |
|
1878 |
&QLinkedList<int>::append, |
|
1879 |
OrderedReduce); |
|
1880 |
QCOMPARE(linkedList3, QLinkedList<int>() << 1 << 2 << 3); |
|
1881 |
||
1882 |
QLinkedList<int> linkedList4 = QtConcurrent::blockingMappedReduced(QLinkedList<Number>(numberLinkedList), |
|
1883 |
&Number::toInt, |
|
1884 |
&QLinkedList<int>::append, OrderedReduce); |
|
1885 |
QCOMPARE(linkedList4, QLinkedList<int>() << 1 << 2 << 3); |
|
1886 |
} |
|
1887 |
||
1888 |
// function-member |
|
1889 |
{ |
|
1890 |
QList<int> list2 = QtConcurrent::blockingMappedReduced(list, |
|
1891 |
intSquare, |
|
1892 |
&QList<int>::push_back, |
|
1893 |
OrderedReduce); |
|
1894 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1895 |
QCOMPARE(list2, QList<int>() << 1 << 4 << 9); |
|
1896 |
||
1897 |
QList<int> list3 = QtConcurrent::blockingMappedReduced(list.constBegin(), |
|
1898 |
list.constEnd(), |
|
1899 |
intSquare, |
|
1900 |
&QList<int>::push_back, |
|
1901 |
OrderedReduce); |
|
1902 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1903 |
QCOMPARE(list3, QList<int>() << 1 << 4 << 9); |
|
1904 |
||
1905 |
QList<int> list4 = QtConcurrent::blockingMappedReduced(QList<int>(list), |
|
1906 |
intSquare, |
|
1907 |
&QList<int>::push_back, |
|
1908 |
OrderedReduce); |
|
1909 |
QCOMPARE(list, QList<int>() << 1 << 2 << 3); |
|
1910 |
QCOMPARE(list4, QList<int>() << 1 << 4 << 9); |
|
1911 |
} |
|
1912 |
{ |
|
1913 |
QLinkedList<int> linkedList2 = QtConcurrent::blockingMappedReduced(linkedList, |
|
1914 |
intSquare, |
|
1915 |
&QLinkedList<int>::append, |
|
1916 |
OrderedReduce); |
|
1917 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1918 |
QCOMPARE(linkedList2, QLinkedList<int>() << 1 << 4 << 9); |
|
1919 |
||
1920 |
QLinkedList<int> linkedList3 = QtConcurrent::blockingMappedReduced(linkedList.constBegin(), |
|
1921 |
linkedList.constEnd(), |
|
1922 |
intSquare, |
|
1923 |
&QLinkedList<int>::append, |
|
1924 |
OrderedReduce); |
|
1925 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1926 |
QCOMPARE(linkedList3, QLinkedList<int>() << 1 << 4 << 9); |
|
1927 |
||
1928 |
QLinkedList<int> linkedList4 = QtConcurrent::blockingMappedReduced(QLinkedList<int>(linkedList), |
|
1929 |
intSquare, |
|
1930 |
&QLinkedList<int>::append, |
|
1931 |
OrderedReduce); |
|
1932 |
QCOMPARE(linkedList, QLinkedList<int>() << 1 << 2 << 3); |
|
1933 |
QCOMPARE(linkedList4, QLinkedList<int>() << 1 << 4 << 9); |
|
1934 |
} |
|
1935 |
||
1936 |
// member-function |
|
1937 |
{ |
|
1938 |
int sum = QtConcurrent::blockingMappedReduced(numberList, |
|
1939 |
&Number::toInt, |
|
1940 |
intSumReduce); |
|
1941 |
QCOMPARE(sum, 6); |
|
1942 |
int sum2 = QtConcurrent::blockingMappedReduced(numberList.constBegin(), |
|
1943 |
numberList.constEnd(), |
|
1944 |
&Number::toInt, |
|
1945 |
intSumReduce); |
|
1946 |
QCOMPARE(sum2, 6); |
|
1947 |
||
1948 |
int sum3 = QtConcurrent::blockingMappedReduced(QList<Number>(numberList), |
|
1949 |
&Number::toInt, |
|
1950 |
intSumReduce); |
|
1951 |
QCOMPARE(sum3, 6); |
|
1952 |
} |
|
1953 |
{ |
|
1954 |
int sum = QtConcurrent::blockingMappedReduced(numberLinkedList, |
|
1955 |
&Number::toInt, |
|
1956 |
intSumReduce); |
|
1957 |
QCOMPARE(sum, 6); |
|
1958 |
int sum2 = QtConcurrent::blockingMappedReduced(numberLinkedList.constBegin(), |
|
1959 |
numberLinkedList.constEnd(), |
|
1960 |
&Number::toInt, |
|
1961 |
intSumReduce); |
|
1962 |
QCOMPARE(sum2, 6); |
|
1963 |
||
1964 |
int sum3 = QtConcurrent::blockingMappedReduced(QLinkedList<Number>(numberLinkedList), |
|
1965 |
&Number::toInt, |
|
1966 |
intSumReduce); |
|
1967 |
QCOMPARE(sum3, 6); |
|
1968 |
} |
|
1969 |
||
1970 |
// linked lists |
|
1971 |
{ |
|
1972 |
||
1973 |
QLinkedList<int> list; |
|
1974 |
list << 1 << 2 << 3; |
|
1975 |
||
1976 |
QLinkedList<Number> numberList; |
|
1977 |
numberList << 1 << 2 << 3; |
|
1978 |
||
1979 |
int sum = QtConcurrent::blockingMappedReduced<int>(list, IntSquare(), IntSumReduce()); |
|
1980 |
QCOMPARE(sum, 14); |
|
1981 |
int sum2 = QtConcurrent::blockingMappedReduced<int>(list.constBegin(), |
|
1982 |
list.constEnd(), |
|
1983 |
IntSquare(), |
|
1984 |
IntSumReduce()); |
|
1985 |
QCOMPARE(sum2, 14); |
|
1986 |
||
1987 |
int sum3 = QtConcurrent::blockingMappedReduced<int>(QLinkedList<int>(list), IntSquare(), IntSumReduce()); |
|
1988 |
QCOMPARE(sum3, 14); |
|
1989 |
||
1990 |
int sum4 = QtConcurrent::blockingMappedReduced<int>(list, intSquare, intSumReduce); |
|
1991 |
QCOMPARE(sum4, 14); |
|
1992 |
int sum5 = QtConcurrent::blockingMappedReduced<int>(list.constBegin(), |
|
1993 |
list.constEnd(), |
|
1994 |
intSquare, |
|
1995 |
intSumReduce); |
|
1996 |
QCOMPARE(sum5, 14); |
|
1997 |
||
1998 |
int sum6 = QtConcurrent::blockingMappedReduced<int>(QLinkedList<int>(list), |
|
1999 |
intSquare, |
|
2000 |
intSumReduce); |
|
2001 |
QCOMPARE(sum6, 14); |
|
2002 |
} |
|
2003 |
||
2004 |
// ### the same as above, with an initial result value |
|
2005 |
} |
|
2006 |
||
2007 |
int sleeper(int val) |
|
2008 |
{ |
|
2009 |
QTest::qSleep(100); |
|
2010 |
return val; |
|
2011 |
} |
|
2012 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2013 |
void tst_QtConcurrentMap::assignResult() |
0 | 2014 |
{ |
2015 |
const QList<int> startList = QList<int>() << 0 << 1 << 2; |
|
2016 |
QList<int> list = QtConcurrent::blockingMapped(startList, sleeper); |
|
2017 |
QCOMPARE(list.at(0), 0); |
|
2018 |
QCOMPARE(list.at(1), 1); |
|
2019 |
} |
|
2020 |
||
2021 |
int fnConst(const int &i) |
|
2022 |
{ |
|
2023 |
return i; |
|
2024 |
} |
|
2025 |
||
2026 |
int fn(int &i) |
|
2027 |
{ |
|
2028 |
return i; |
|
2029 |
} |
|
2030 |
||
2031 |
QString changeTypeConst(const int &) |
|
2032 |
{ |
|
2033 |
return QString(); |
|
2034 |
} |
|
2035 |
||
2036 |
QString changeType(int &) |
|
2037 |
{ |
|
2038 |
return QString(); |
|
2039 |
} |
|
2040 |
||
2041 |
int changeTypeQStringListConst(const QStringList &) |
|
2042 |
{ |
|
2043 |
return 0; |
|
2044 |
} |
|
2045 |
||
2046 |
int changeTypeQStringList(QStringList &) |
|
2047 |
{ |
|
2048 |
return 0; |
|
2049 |
} |
|
2050 |
||
2051 |
class MemFnTester |
|
2052 |
{ |
|
2053 |
public: |
|
2054 |
MemFnTester() {} |
|
2055 |
||
2056 |
MemFnTester fn() |
|
2057 |
{ |
|
2058 |
return MemFnTester(); |
|
2059 |
} |
|
2060 |
||
2061 |
MemFnTester fnConst() const |
|
2062 |
{ |
|
2063 |
return MemFnTester(); |
|
2064 |
} |
|
2065 |
||
2066 |
QString changeType() |
|
2067 |
{ |
|
2068 |
return QString(); |
|
2069 |
} |
|
2070 |
||
2071 |
QString changeTypeConst() const |
|
2072 |
{ |
|
2073 |
return QString(); |
|
2074 |
} |
|
2075 |
}; |
|
2076 |
||
2077 |
Q_DECLARE_METATYPE(QVector<MemFnTester>); |
|
2078 |
Q_DECLARE_METATYPE(QList<MemFnTester>); |
|
2079 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2080 |
void tst_QtConcurrentMap::functionOverloads() |
0 | 2081 |
{ |
2082 |
QList<int> intList; |
|
2083 |
const QList<int> constIntList; |
|
2084 |
QList<MemFnTester> classList; |
|
2085 |
const QList<MemFnTester> constMemFnTesterList; |
|
2086 |
||
2087 |
QtConcurrent::mapped(intList, fnConst); |
|
2088 |
QtConcurrent::mapped(constIntList, fnConst); |
|
2089 |
QtConcurrent::mapped(classList, &MemFnTester::fnConst); |
|
2090 |
QtConcurrent::mapped(constMemFnTesterList, &MemFnTester::fnConst); |
|
2091 |
||
2092 |
QtConcurrent::blockingMapped<QVector<int> >(intList, fnConst); |
|
2093 |
QtConcurrent::blockingMapped<QVector<int> >(constIntList, fnConst); |
|
2094 |
QtConcurrent::blockingMapped<QVector<MemFnTester> >(classList, &MemFnTester::fnConst); |
|
2095 |
QtConcurrent::blockingMapped<QVector<MemFnTester> >(constMemFnTesterList, &MemFnTester::fnConst); |
|
2096 |
||
2097 |
QtConcurrent::blockingMapped<QList<QString> >(intList, changeTypeConst); |
|
2098 |
QtConcurrent::blockingMapped<QList<QString> >(constIntList, changeTypeConst); |
|
2099 |
QtConcurrent::blockingMapped<QList<QString> >(classList, &MemFnTester::changeTypeConst); |
|
2100 |
QtConcurrent::blockingMapped<QList<QString> >(constMemFnTesterList, &MemFnTester::changeTypeConst); |
|
2101 |
||
2102 |
QStringList stringList; |
|
2103 |
const QStringList constStringList; |
|
2104 |
// QtConcurrent::map(stringList, changeTypeQStringListConst); |
|
2105 |
// QtConcurrent::map(intList, changeTypeNonConst); |
|
2106 |
// QList<QString>(QtConcurrent::map(constStringList, changeTypeQStringList)); |
|
2107 |
// QtConcurrent::map(classList, &MemFnTester::changeType); |
|
2108 |
// QtConcurrent::map(classList, &MemFnTester::changeTypeConst); |
|
2109 |
// QtConcurrent::map(constMemFnTesterList, &MemFnTester::changeTypeConst); |
|
2110 |
} |
|
2111 |
||
2112 |
QAtomicInt currentInstanceCount; |
|
2113 |
QAtomicInt peakInstanceCount; |
|
2114 |
class InstanceCounter |
|
2115 |
{ |
|
2116 |
public: |
|
2117 |
inline InstanceCounter() |
|
2118 |
{ currentInstanceCount.fetchAndAddRelaxed(1); updatePeak(); } |
|
2119 |
inline ~InstanceCounter() |
|
2120 |
{ currentInstanceCount.fetchAndAddRelaxed(-1);} |
|
2121 |
inline InstanceCounter(const InstanceCounter &) |
|
2122 |
{ currentInstanceCount.fetchAndAddRelaxed(1); updatePeak(); } |
|
2123 |
||
2124 |
void updatePeak() |
|
2125 |
{ |
|
2126 |
forever { |
|
2127 |
const int localPeak = peakInstanceCount; |
|
2128 |
const int localCurrent = currentInstanceCount; |
|
2129 |
if (localCurrent <= localPeak) |
|
2130 |
break; |
|
2131 |
if (peakInstanceCount.testAndSetOrdered(localPeak, localCurrent)) |
|
2132 |
break; |
|
2133 |
} |
|
2134 |
} |
|
2135 |
}; |
|
2136 |
||
2137 |
InstanceCounter slowMap(const InstanceCounter &in) |
|
2138 |
{ |
|
2139 |
QTest::qSleep(2); |
|
2140 |
return in; |
|
2141 |
} |
|
2142 |
||
2143 |
InstanceCounter fastMap(const InstanceCounter &in) |
|
2144 |
{ |
|
2145 |
QTest::qSleep(rand() % 2 + 1); |
|
2146 |
// qDebug() << "map " << QThread::currentThread(); |
|
2147 |
return in; |
|
2148 |
} |
|
2149 |
||
2150 |
void slowReduce(int &result, const InstanceCounter&) |
|
2151 |
{ |
|
2152 |
QTest::qSleep(rand() % 4 + 1); |
|
2153 |
// qDebug() << "reduce" << QThread::currentThread(); |
|
2154 |
++result; |
|
2155 |
} |
|
2156 |
||
2157 |
void fastReduce(int &result, const InstanceCounter&) |
|
2158 |
{ |
|
2159 |
++result; |
|
2160 |
} |
|
2161 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2162 |
void tst_QtConcurrentMap::throttling() |
0 | 2163 |
{ |
2164 |
const int itemcount = 100; |
|
2165 |
const int allowedTemporaries = QThread::idealThreadCount() * 40; |
|
2166 |
||
2167 |
{ |
|
2168 |
currentInstanceCount = 0; |
|
2169 |
peakInstanceCount = 0; |
|
2170 |
||
2171 |
QList<InstanceCounter> instances; |
|
2172 |
for (int i = 0; i < itemcount; ++i) |
|
2173 |
instances.append(InstanceCounter()); |
|
2174 |
||
2175 |
QCOMPARE((int)currentInstanceCount, itemcount); |
|
2176 |
||
2177 |
int results = QtConcurrent::blockingMappedReduced(instances, slowMap, fastReduce); |
|
2178 |
QCOMPARE(results, itemcount); |
|
2179 |
qDebug() << (int)currentInstanceCount; |
|
2180 |
qDebug() << (int)peakInstanceCount; |
|
2181 |
QCOMPARE(int(currentInstanceCount), itemcount); |
|
2182 |
QVERIFY(int(peakInstanceCount) < itemcount + allowedTemporaries); |
|
2183 |
} |
|
2184 |
||
2185 |
{ |
|
2186 |
QCOMPARE(int(currentInstanceCount), 0); |
|
2187 |
peakInstanceCount = 0; |
|
2188 |
||
2189 |
QList<InstanceCounter> instances; |
|
2190 |
for (int i = 0; i < itemcount; ++i) |
|
2191 |
instances.append(InstanceCounter()); |
|
2192 |
||
2193 |
QCOMPARE(int(currentInstanceCount), itemcount); |
|
2194 |
int results = QtConcurrent::blockingMappedReduced(instances, fastMap, slowReduce); |
|
2195 |
||
2196 |
QCOMPARE(results, itemcount); |
|
2197 |
qDebug() << (int)currentInstanceCount; |
|
2198 |
qDebug() << (int)peakInstanceCount; |
|
2199 |
QCOMPARE((int)currentInstanceCount, itemcount); |
|
2200 |
QVERIFY(int(peakInstanceCount) < itemcount + allowedTemporaries); |
|
2201 |
} |
|
2202 |
} |
|
2203 |
||
2204 |
#ifndef QT_NO_EXCEPTIONS |
|
2205 |
void throwMapper(int &e) |
|
2206 |
{ |
|
2207 |
Q_UNUSED(e); |
|
2208 |
throw QtConcurrent::Exception(); |
|
2209 |
} |
|
2210 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2211 |
void tst_QtConcurrentMap::exceptions() |
0 | 2212 |
{ |
2213 |
bool caught = false; |
|
2214 |
try { |
|
2215 |
QList<int> list = QList<int>() << 1 << 2 << 3; |
|
2216 |
QtConcurrent::map(list, throwMapper).waitForFinished(); |
|
2217 |
} catch (Exception &e) { |
|
2218 |
caught = true; |
|
2219 |
} |
|
2220 |
if (!caught) |
|
2221 |
QFAIL("did not get exception"); |
|
2222 |
} |
|
2223 |
#endif |
|
2224 |
||
2225 |
int mapper(const int &i) |
|
2226 |
{ |
|
2227 |
QTest::qWait(1); |
|
2228 |
return i; |
|
2229 |
} |
|
2230 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2231 |
void tst_QtConcurrentMap::incrementalResults() |
0 | 2232 |
{ |
2233 |
const int count = 200; |
|
2234 |
QList<int> ints; |
|
2235 |
for (int i=0; i < count; ++i) |
|
2236 |
ints << i; |
|
2237 |
||
2238 |
QFuture<int> future = QtConcurrent::mapped(ints, mapper); |
|
2239 |
||
2240 |
QList<int> results; |
|
2241 |
||
2242 |
while (future.isFinished() == false) { |
|
2243 |
for (int i = 0; i < future.resultCount(); ++i) { |
|
2244 |
results += future.resultAt(i); |
|
2245 |
} |
|
2246 |
||
2247 |
QTest::qWait(1); |
|
2248 |
} |
|
2249 |
||
2250 |
QCOMPARE(future.isFinished(), true); |
|
2251 |
QCOMPARE(future.resultCount(), count); |
|
2252 |
QCOMPARE(future.results().count(), count); |
|
2253 |
} |
|
2254 |
||
2255 |
/* |
|
2256 |
Test that mapped does not cause deep copies when holding |
|
2257 |
references to Qt containers. |
|
2258 |
*/ |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2259 |
void tst_QtConcurrentMap::noDetatch() |
0 | 2260 |
{ |
2261 |
{ |
|
2262 |
QList<int> l = QList<int>() << 1; |
|
2263 |
QVERIFY(l.isDetached()); |
|
2264 |
||
2265 |
QList<int> ll = l; |
|
2266 |
QVERIFY(l.isDetached() == false); |
|
2267 |
||
2268 |
QtConcurrent::mapped(l, mapper).waitForFinished(); |
|
2269 |
||
2270 |
QVERIFY(l.isDetached() == false); |
|
2271 |
QVERIFY(ll.isDetached() == false); |
|
2272 |
||
2273 |
QtConcurrent::mappedReduced(l, mapper, intSumReduce).waitForFinished(); |
|
2274 |
||
2275 |
QVERIFY(l.isDetached() == false); |
|
2276 |
QVERIFY(ll.isDetached() == false); |
|
2277 |
||
2278 |
QtConcurrent::map(l, multiplyBy2Immutable).waitForFinished(); |
|
2279 |
QVERIFY(l.isDetached() == true); |
|
2280 |
QVERIFY(ll.isDetached() == true); |
|
2281 |
} |
|
2282 |
{ |
|
2283 |
const QList<int> l = QList<int>() << 1; |
|
2284 |
QVERIFY(l.isDetached()); |
|
2285 |
||
2286 |
const QList<int> ll = l; |
|
2287 |
QVERIFY(l.isDetached() == false); |
|
2288 |
||
2289 |
QtConcurrent::mapped(l, mapper).waitForFinished(); |
|
2290 |
||
2291 |
QVERIFY(l.isDetached() == false); |
|
2292 |
QVERIFY(ll.isDetached() == false); |
|
2293 |
||
2294 |
QtConcurrent::mappedReduced(l, mapper, intSumReduce).waitForFinished(); |
|
2295 |
||
2296 |
QVERIFY(l.isDetached() == false); |
|
2297 |
QVERIFY(ll.isDetached() == false); |
|
2298 |
} |
|
2299 |
||
2300 |
} |
|
2301 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2302 |
void tst_QtConcurrentMap::stlContainers() |
0 | 2303 |
{ |
2304 |
#ifdef QT_NO_STL |
|
2305 |
QSKIP("Qt compiled without STL support", SkipAll); |
|
2306 |
#else |
|
2307 |
std::vector<int> vector; |
|
2308 |
vector.push_back(1); |
|
2309 |
vector.push_back(2); |
|
2310 |
||
2311 |
std::vector<int> vector2 = QtConcurrent::blockingMapped<std::vector<int> >(vector, mapper); |
|
2312 |
QCOMPARE(vector2.size(), (std::vector<int>::size_type)(2)); |
|
2313 |
||
2314 |
std::list<int> list; |
|
2315 |
list.push_back(1); |
|
2316 |
list.push_back(2); |
|
2317 |
||
2318 |
std::list<int> list2 = QtConcurrent::blockingMapped<std::list<int> >(list, mapper); |
|
2319 |
QCOMPARE(list2.size(), (std::vector<int>::size_type)(2)); |
|
2320 |
||
2321 |
QtConcurrent::mapped(list, mapper).waitForFinished(); |
|
2322 |
||
2323 |
QtConcurrent::blockingMap(list, multiplyBy2Immutable); |
|
2324 |
#endif |
|
2325 |
} |
|
2326 |
||
2327 |
InstanceCounter ic_fn(const InstanceCounter & ic) |
|
2328 |
{ |
|
2329 |
return InstanceCounter(ic); |
|
2330 |
}; |
|
2331 |
||
2332 |
// Verify that held results are deleted when a future is |
|
2333 |
// assigned over with operator == |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2334 |
void tst_QtConcurrentMap::qFutureAssignmentLeak() |
0 | 2335 |
{ |
2336 |
currentInstanceCount = 0; |
|
2337 |
peakInstanceCount = 0; |
|
2338 |
QFuture<InstanceCounter> future; |
|
2339 |
{ |
|
2340 |
QList<InstanceCounter> list; |
|
2341 |
for (int i=0;i<1000;++i) |
|
2342 |
list += InstanceCounter(); |
|
2343 |
future = QtConcurrent::mapped(list, ic_fn); |
|
2344 |
future.waitForFinished(); |
|
2345 |
||
2346 |
future = QtConcurrent::mapped(list, ic_fn); |
|
2347 |
future.waitForFinished(); |
|
2348 |
||
2349 |
future = QtConcurrent::mapped(list, ic_fn); |
|
2350 |
future.waitForFinished(); |
|
2351 |
} |
|
2352 |
||
2353 |
QCOMPARE(int(currentInstanceCount), 1000); |
|
2354 |
future = QFuture<InstanceCounter>(); |
|
2355 |
QCOMPARE(int(currentInstanceCount), 0); |
|
2356 |
} |
|
2357 |
||
2358 |
inline void increment(int &num) |
|
2359 |
{ |
|
2360 |
++num; |
|
2361 |
} |
|
2362 |
||
2363 |
inline int echo(const int &num) |
|
2364 |
{ |
|
2365 |
return num; |
|
2366 |
} |
|
2367 |
||
2368 |
void add(int &result, const int &sum) |
|
2369 |
{ |
|
2370 |
result += sum; |
|
2371 |
} |
|
2372 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2373 |
void tst_QtConcurrentMap::stressTest() |
0 | 2374 |
{ |
2375 |
const int listSize = 1000; |
|
2376 |
const int sum = (listSize - 1) * (listSize / 2); |
|
2377 |
QList<int> list; |
|
2378 |
||
2379 |
||
2380 |
for (int i = 0; i < listSize; ++i) { |
|
2381 |
list.append(i); |
|
2382 |
} |
|
2383 |
||
2384 |
for (int i =0 ; i < 100; ++i) { |
|
2385 |
QList<int> result = QtConcurrent::blockingMapped(list, echo); |
|
2386 |
for (int j = 0; j < listSize; ++j) |
|
2387 |
QCOMPARE(result.at(j), j); |
|
2388 |
} |
|
2389 |
||
2390 |
for (int i = 0 ; i < 100; ++i) { |
|
2391 |
int result = QtConcurrent::blockingMappedReduced(list, echo, add); |
|
2392 |
QCOMPARE(result, sum); |
|
2393 |
} |
|
2394 |
||
2395 |
for (int i = 0 ; i < 100; ++i) { |
|
2396 |
QtConcurrent::map(list, increment).waitForFinished(); |
|
2397 |
for (int j = 0; j < listSize; ++j) |
|
2398 |
QCOMPARE(list.at(j), i + j + 1); |
|
2399 |
} |
|
2400 |
} |
|
2401 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2402 |
QTEST_MAIN(tst_QtConcurrentMap) |
0 | 2403 |
|
2404 |
#else |
|
2405 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2406 |
void tst_QtConcurrentMap::map() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2407 |
void tst_QtConcurrentMap::blocking_map() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2408 |
void tst_QtConcurrentMap::mapped() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2409 |
void tst_QtConcurrentMap::blocking_mapped() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2410 |
void tst_QtConcurrentMap::mappedReduced() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2411 |
void tst_QtConcurrentMap::blocking_mappedReduced() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2412 |
void tst_QtConcurrentMap::assignResult() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2413 |
void tst_QtConcurrentMap::functionOverloads() {} |
0 | 2414 |
#ifndef QT_NO_EXCEPTIONS |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2415 |
void tst_QtConcurrentMap::exceptions() {} |
0 | 2416 |
#endif |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2417 |
void tst_QtConcurrentMap::incrementalResults() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2418 |
void tst_QtConcurrentMap::stressTest() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2419 |
void tst_QtConcurrentMap::throttling() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2420 |
void tst_QtConcurrentMap::stlContainers() {} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
4
diff
changeset
|
2421 |
void tst_QtConcurrentMap::noDetatch() {} |
0 | 2422 |
|
2423 |
QTEST_NOOP_MAIN |
|
2424 |
||
2425 |
#endif |
|
2426 |
||
2427 |
#include "tst_qtconcurrentmap.moc" |