equal
deleted
inserted
replaced
47 |
47 |
48 #ifndef QT_NO_CONCURRENT_TEST |
48 #ifndef QT_NO_CONCURRENT_TEST |
49 |
49 |
50 using namespace QtConcurrent; |
50 using namespace QtConcurrent; |
51 |
51 |
52 class TestRunFunction: public QObject |
52 class tst_QtConcurrentRun: public QObject |
53 { |
53 { |
54 Q_OBJECT |
54 Q_OBJECT |
55 private slots: |
55 private slots: |
56 void runLightFunction(); |
56 void runLightFunction(); |
57 void runHeavyFunction(); |
57 void runHeavyFunction(); |
71 #else |
71 #else |
72 # define F(X) X |
72 # define F(X) X |
73 #endif |
73 #endif |
74 |
74 |
75 |
75 |
76 QTEST_MAIN(TestRunFunction) |
76 QTEST_MAIN(tst_QtConcurrentRun) |
77 |
77 |
78 void light() |
78 void light() |
79 { |
79 { |
80 qDebug("in function"); |
80 qDebug("in function"); |
81 qDebug("done function"); |
81 qDebug("done function"); |
89 str.append("a"); |
89 str.append("a"); |
90 qDebug("done function"); |
90 qDebug("done function"); |
91 } |
91 } |
92 |
92 |
93 |
93 |
94 void TestRunFunction::runLightFunction() |
94 void tst_QtConcurrentRun::runLightFunction() |
95 { |
95 { |
96 qDebug("starting function"); |
96 qDebug("starting function"); |
97 QFuture<void> future = run(F(light)); |
97 QFuture<void> future = run(F(light)); |
98 qDebug("waiting"); |
98 qDebug("waiting"); |
99 future.waitForFinished(); |
99 future.waitForFinished(); |
100 qDebug("done"); |
100 qDebug("done"); |
101 } |
101 } |
102 |
102 |
103 void TestRunFunction::runHeavyFunction() |
103 void tst_QtConcurrentRun::runHeavyFunction() |
104 { |
104 { |
105 qDebug("starting function"); |
105 qDebug("starting function"); |
106 QFuture<void> future = run(F(heavy)); |
106 QFuture<void> future = run(F(heavy)); |
107 qDebug("waiting"); |
107 qDebug("waiting"); |
108 future.waitForFinished(); |
108 future.waitForFinished(); |
139 typedef int result_type; |
139 typedef int result_type; |
140 int operator()() const { return 10; } |
140 int operator()() const { return 10; } |
141 int operator()(int in) const { return in; } |
141 int operator()(int in) const { return in; } |
142 }; |
142 }; |
143 |
143 |
144 void TestRunFunction::returnValue() |
144 void tst_QtConcurrentRun::returnValue() |
145 { |
145 { |
146 QFuture<int> f; |
146 QFuture<int> f; |
147 |
147 |
148 f = run(F(returnInt0)); |
148 f = run(F(returnInt0)); |
149 QCOMPARE(f.result(), 10); |
149 QCOMPARE(f.result(), 10); |
215 void operator()() const { } |
215 void operator()() const { } |
216 void operator()(int) const { } |
216 void operator()(int) const { } |
217 void fooInt(int) const { }; |
217 void fooInt(int) const { }; |
218 }; |
218 }; |
219 |
219 |
220 void TestRunFunction::functionObject() |
220 void tst_QtConcurrentRun::functionObject() |
221 { |
221 { |
222 QFuture<void> f; |
222 QFuture<void> f; |
223 TestClass c; |
223 TestClass c; |
224 |
224 |
225 f = run(c); |
225 f = run(c); |
233 f = run(cc, 10); |
233 f = run(cc, 10); |
234 f = run(F(&cc), 10); |
234 f = run(F(&cc), 10); |
235 } |
235 } |
236 |
236 |
237 |
237 |
238 void TestRunFunction::memberFunctions() |
238 void tst_QtConcurrentRun::memberFunctions() |
239 { |
239 { |
240 TestClass c; |
240 TestClass c; |
241 |
241 |
242 run(c, F(&TestClass::foo)).waitForFinished(); |
242 run(c, F(&TestClass::foo)).waitForFinished(); |
243 run(&c, F(&TestClass::foo)).waitForFinished(); |
243 run(&c, F(&TestClass::foo)).waitForFinished(); |
276 { |
276 { |
277 |
277 |
278 } |
278 } |
279 |
279 |
280 |
280 |
281 void TestRunFunction::implicitConvertibleTypes() |
281 void tst_QtConcurrentRun::implicitConvertibleTypes() |
282 { |
282 { |
283 double d; |
283 double d; |
284 run(F(doubleFunction), d).waitForFinished(); |
284 run(F(doubleFunction), d).waitForFinished(); |
285 int i; |
285 int i; |
286 run(F(doubleFunction), d).waitForFinished(); |
286 run(F(doubleFunction), d).waitForFinished(); |
292 run(F(stringRefFunction), string).waitForFinished(); |
292 run(F(stringRefFunction), string).waitForFinished(); |
293 } |
293 } |
294 |
294 |
295 void fn() { } |
295 void fn() { } |
296 |
296 |
297 void TestRunFunction::runWaitLoop() |
297 void tst_QtConcurrentRun::runWaitLoop() |
298 { |
298 { |
299 for (int i = 0; i < 1000; ++i) |
299 for (int i = 0; i < 1000; ++i) |
300 run(fn).waitForFinished(); |
300 run(fn).waitForFinished(); |
301 } |
301 } |
302 |
302 |
322 return f1.result() + f2.result(); |
322 return f1.result() + f2.result(); |
323 } |
323 } |
324 return 1; |
324 return 1; |
325 } |
325 } |
326 |
326 |
327 void TestRunFunction::recursive() |
327 void tst_QtConcurrentRun::recursive() |
328 { |
328 { |
329 int levels = 15; |
329 int levels = 15; |
330 |
330 |
331 for (int i = 0; i < QThread::idealThreadCount(); ++i) { |
331 for (int i = 0; i < QThread::idealThreadCount(); ++i) { |
332 count = 0; |
332 count = 0; |
373 { |
373 { |
374 return 1; |
374 return 1; |
375 } |
375 } |
376 |
376 |
377 #if 0 |
377 #if 0 |
378 void TestRunFunction::createFunctor() |
378 void tst_QtConcurrentRun::createFunctor() |
379 { |
379 { |
380 e = 0; |
380 e = 0; |
381 ::QtConcurrent::createFunctor(vfn0)(); |
381 ::QtConcurrent::createFunctor(vfn0)(); |
382 e += QtConcurrent::createFunctor(fn0)(); |
382 e += QtConcurrent::createFunctor(fn0)(); |
383 ::QtConcurrent::createFunctor(vfn1)(1); // implicit conversions should work |
383 ::QtConcurrent::createFunctor(vfn1)(1); // implicit conversions should work |