122 void blockingLookup(); |
123 void blockingLookup(); |
123 |
124 |
124 void raceCondition(); |
125 void raceCondition(); |
125 void threadSafety(); |
126 void threadSafety(); |
126 |
127 |
|
128 void multipleSameLookups(); |
|
129 void multipleDifferentLookups(); |
|
130 |
127 protected slots: |
131 protected slots: |
128 void resultsReady(const QHostInfo &); |
132 void resultsReady(const QHostInfo &); |
129 |
133 |
130 private: |
134 private: |
131 bool ipv6LookupsAvailable; |
135 bool ipv6LookupsAvailable; |
132 bool ipv6Available; |
136 bool ipv6Available; |
133 bool lookupDone; |
137 bool lookupDone; |
|
138 int lookupsDoneCounter; |
134 QHostInfo lookupResults; |
139 QHostInfo lookupResults; |
135 }; |
140 }; |
136 |
141 |
137 // Testing get/set functions |
142 // Testing get/set functions |
138 void tst_QHostInfo::getSetCheck() |
143 void tst_QHostInfo::getSetCheck() |
409 for (int k = nattempts - 1; k >= 0; --k) |
414 for (int k = nattempts - 1; k >= 0; --k) |
410 thr[k].wait(); |
415 thr[k].wait(); |
411 } |
416 } |
412 } |
417 } |
413 |
418 |
|
419 // this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, |
|
420 // not about getting correct IPs |
|
421 void tst_QHostInfo::multipleSameLookups() |
|
422 { |
|
423 const int COUNT = 10; |
|
424 lookupsDoneCounter = 0; |
|
425 |
|
426 for (int i = 0; i < COUNT; i++) |
|
427 QHostInfo::lookupHost("localhost", this, SLOT(resultsReady(const QHostInfo))); |
|
428 |
|
429 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
|
430 |
|
431 // spin two seconds more to see if it is not more :) |
|
432 QTestEventLoop::instance().enterLoop(2); |
|
433 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
|
434 } |
|
435 |
|
436 // this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, |
|
437 // not about getting correct IPs |
|
438 void tst_QHostInfo::multipleDifferentLookups() |
|
439 { |
|
440 QStringList hostnameList; |
|
441 hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no" |
|
442 << "www.qtcentre.org" << "forum.nokia.com" << "www.forum.nokia.com" << "wiki.forum.nokia.com" |
|
443 << "www.nokia.no" << "nokia.de" << "127.0.0.1" << "----"; |
|
444 |
|
445 const int COUNT = hostnameList.size(); |
|
446 lookupsDoneCounter = 0; |
|
447 |
|
448 for (int i = 0; i < hostnameList.size(); i++) |
|
449 QHostInfo::lookupHost(hostnameList.at(i), this, SLOT(resultsReady(const QHostInfo))); |
|
450 |
|
451 // give some time |
|
452 QTestEventLoop::instance().enterLoop(5); |
|
453 // try_verify gives some more time |
|
454 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
|
455 |
|
456 // spin two seconds more to see if it is not more than expected |
|
457 QTestEventLoop::instance().enterLoop(2); |
|
458 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
|
459 } |
|
460 |
414 void tst_QHostInfo::resultsReady(const QHostInfo &hi) |
461 void tst_QHostInfo::resultsReady(const QHostInfo &hi) |
415 { |
462 { |
416 lookupDone = true; |
463 lookupDone = true; |
417 lookupResults = hi; |
464 lookupResults = hi; |
418 |
465 lookupsDoneCounter++; |
419 QTestEventLoop::instance().exitLoop(); |
466 QTestEventLoop::instance().exitLoop(); |
420 } |
467 } |
421 |
468 |
422 QTEST_MAIN(tst_QHostInfo) |
469 QTEST_MAIN(tst_QHostInfo) |
423 #include "tst_qhostinfo.moc" |
470 #include "tst_qhostinfo.moc" |