equal
deleted
inserted
replaced
88 |
88 |
89 #ifndef QT_NO_CONCURRENT_TEST |
89 #ifndef QT_NO_CONCURRENT_TEST |
90 |
90 |
91 using namespace QtConcurrent; |
91 using namespace QtConcurrent; |
92 |
92 |
93 class tst_iteratekernel: public QObject |
93 class tst_QtConcurrentIterateKernel: public QObject |
94 { |
94 { |
95 Q_OBJECT |
95 Q_OBJECT |
96 private slots: |
96 private slots: |
97 // "for" iteration tests: |
97 // "for" iteration tests: |
98 void instantiate(); |
98 void instantiate(); |
147 return runIterations(it, index, index + 1, result); |
147 return runIterations(it, index, index + 1, result); |
148 } |
148 } |
149 }; |
149 }; |
150 |
150 |
151 |
151 |
152 void tst_iteratekernel::instantiate() |
152 void tst_QtConcurrentIterateKernel::instantiate() |
153 { |
153 { |
154 startThreadEngine(new PrintFor(0, 40)).startBlocking(); |
154 startThreadEngine(new PrintFor(0, 40)).startBlocking(); |
155 QCOMPARE((int)iterations, 40); |
155 QCOMPARE((int)iterations, 40); |
156 } |
156 } |
157 |
157 |
158 void tst_iteratekernel::cancel() |
158 void tst_QtConcurrentIterateKernel::cancel() |
159 { |
159 { |
160 { |
160 { |
161 QFuture<void> f = startThreadEngine(new SleepPrintFor(0, 40)).startAsynchronously(); |
161 QFuture<void> f = startThreadEngine(new SleepPrintFor(0, 40)).startAsynchronously(); |
162 f.cancel(); |
162 f.cancel(); |
163 f.waitForFinished(); |
163 f.waitForFinished(); |
180 { |
180 { |
181 return runIterations(it, index, index + 1, result); |
181 return runIterations(it, index, index + 1, result); |
182 } |
182 } |
183 }; |
183 }; |
184 |
184 |
185 void tst_iteratekernel::stresstest() |
185 void tst_QtConcurrentIterateKernel::stresstest() |
186 { |
186 { |
187 const int iterations = 1000; |
187 const int iterations = 1000; |
188 const int times = 50; |
188 const int times = 50; |
189 for (int i = 0; i < times; ++i) { |
189 for (int i = 0; i < times; ++i) { |
190 counter = 0; |
190 counter = 0; |
192 f.startBlocking(); |
192 f.startBlocking(); |
193 QCOMPARE((int)counter, iterations); |
193 QCOMPARE((int)counter, iterations); |
194 } |
194 } |
195 } |
195 } |
196 |
196 |
197 void tst_iteratekernel::noIterations() |
197 void tst_QtConcurrentIterateKernel::noIterations() |
198 { |
198 { |
199 const int times = 20000; |
199 const int times = 20000; |
200 for (int i = 0; i < times; ++i) |
200 for (int i = 0; i < times; ++i) |
201 startThreadEngine(new IterateKernel<TestIterator, void>(0, 0)).startBlocking(); |
201 startThreadEngine(new IterateKernel<TestIterator, void>(0, 0)).startBlocking(); |
202 } |
202 } |
240 return (iterations > 100 && iterations < 200); |
240 return (iterations > 100 && iterations < 200); |
241 } |
241 } |
242 bool throttling; |
242 bool throttling; |
243 }; |
243 }; |
244 |
244 |
245 void tst_iteratekernel::throttling() |
245 void tst_QtConcurrentIterateKernel::throttling() |
246 { |
246 { |
247 const int totalIterations = 400; |
247 const int totalIterations = 400; |
248 iterations = 0; |
248 iterations = 0; |
249 |
249 |
250 threads.clear(); |
250 threads.clear(); |
269 peakBlockSize = qMax(peakBlockSize, end - begin); |
269 peakBlockSize = qMax(peakBlockSize, end - begin); |
270 return false; |
270 return false; |
271 } |
271 } |
272 }; |
272 }; |
273 |
273 |
274 void tst_iteratekernel::blockSize() |
274 void tst_QtConcurrentIterateKernel::blockSize() |
275 { |
275 { |
276 #ifdef QT_NO_STL |
276 #ifdef QT_NO_STL |
277 QSKIP("Missing stl iterators prevent correct block size calculation", SkipAll); |
277 QSKIP("Missing stl iterators prevent correct block size calculation", SkipAll); |
278 #endif |
278 #endif |
279 const int expectedMinimumBlockSize = 1024 / QThread::idealThreadCount(); |
279 const int expectedMinimumBlockSize = 1024 / QThread::idealThreadCount(); |
294 return true; |
294 return true; |
295 } |
295 } |
296 }; |
296 }; |
297 |
297 |
298 |
298 |
299 void tst_iteratekernel::multipleResults() |
299 void tst_QtConcurrentIterateKernel::multipleResults() |
300 { |
300 { |
301 #ifdef QT_NO_STL |
301 #ifdef QT_NO_STL |
302 QSKIP("Missing stl iterators prevent correct summation", SkipAll); |
302 QSKIP("Missing stl iterators prevent correct summation", SkipAll); |
303 #endif |
303 #endif |
304 QFuture<int> f = startThreadEngine(new MultipleResultsFor(0, 10)).startAsynchronously(); |
304 QFuture<int> f = startThreadEngine(new MultipleResultsFor(0, 10)).startAsynchronously(); |
318 { |
318 { |
319 return false; |
319 return false; |
320 } |
320 } |
321 }; |
321 }; |
322 |
322 |
323 void tst_iteratekernel::instantiateWhile() |
323 void tst_QtConcurrentIterateKernel::instantiateWhile() |
324 { |
324 { |
325 PrintWhile w; |
325 PrintWhile w; |
326 w.startBlocking(); |
326 w.startBlocking(); |
327 } |
327 } |
328 |
328 |
337 ::iterationCount.ref(); |
337 ::iterationCount.ref(); |
338 return false; |
338 return false; |
339 } |
339 } |
340 }; |
340 }; |
341 |
341 |
342 void tst_iteratekernel::stresstestWhile() |
342 void tst_QtConcurrentIterateKernel::stresstestWhile() |
343 { |
343 { |
344 int iterations = 100000; |
344 int iterations = 100000; |
345 StressWhile w(iterations); |
345 StressWhile w(iterations); |
346 w.startBlocking(); |
346 w.startBlocking(); |
347 QCOMPARE(int(iterationCount), iterations); |
347 QCOMPARE(int(iterationCount), iterations); |
348 } |
348 } |
349 #endif |
349 #endif |
350 |
350 |
351 QTEST_MAIN(tst_iteratekernel) |
351 QTEST_MAIN(tst_QtConcurrentIterateKernel) |
352 |
352 |
353 #include "tst_qtconcurrentiteratekernel.moc" |
353 #include "tst_qtconcurrentiteratekernel.moc" |
354 |
354 |
355 #else |
355 #else |
356 QTEST_NOOP_MAIN |
356 QTEST_NOOP_MAIN |