439 lookupsDoneCounter = 0; |
440 lookupsDoneCounter = 0; |
440 |
441 |
441 for (int i = 0; i < COUNT; i++) |
442 for (int i = 0; i < COUNT; i++) |
442 QHostInfo::lookupHost("localhost", this, SLOT(resultsReady(const QHostInfo))); |
443 QHostInfo::lookupHost("localhost", this, SLOT(resultsReady(const QHostInfo))); |
443 |
444 |
444 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
445 QElapsedTimer timer; |
445 |
446 timer.start(); |
446 // spin two seconds more to see if it is not more :) |
447 while (timer.elapsed() < 10000 && lookupsDoneCounter < COUNT) { |
447 QTestEventLoop::instance().enterLoop(2); |
448 QTestEventLoop::instance().enterLoop(2); |
448 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
449 } |
|
450 QCOMPARE(lookupsDoneCounter, COUNT); |
449 } |
451 } |
450 |
452 |
451 // this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, |
453 // this test is for the multi-threaded QHostInfo rewrite. It is about getting results at all, |
452 // not about getting correct IPs |
454 // not about getting correct IPs |
|
455 void tst_QHostInfo::multipleDifferentLookups_data() |
|
456 { |
|
457 QTest::addColumn<int>("repeats"); |
|
458 QTest::newRow("1") << 1; |
|
459 QTest::newRow("2") << 2; |
|
460 QTest::newRow("5") << 5; |
|
461 QTest::newRow("10") << 10; |
|
462 } |
|
463 |
453 void tst_QHostInfo::multipleDifferentLookups() |
464 void tst_QHostInfo::multipleDifferentLookups() |
454 { |
465 { |
455 QStringList hostnameList; |
466 QStringList hostnameList; |
456 hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no" |
467 hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no" |
457 << "www.qtcentre.org" << "forum.nokia.com" << "www.forum.nokia.com" << "wiki.forum.nokia.com" |
468 << "www.qtcentre.org" << "forum.nokia.com" << "www.nokia.com" << "wiki.forum.nokia.com" |
458 << "www.nokia.no" << "nokia.de" << "127.0.0.1" << "----"; |
469 << "www.nokia.com" << "nokia.de" << "127.0.0.1" << "----"; |
459 |
470 |
|
471 QFETCH(int, repeats); |
460 const int COUNT = hostnameList.size(); |
472 const int COUNT = hostnameList.size(); |
461 lookupsDoneCounter = 0; |
473 lookupsDoneCounter = 0; |
462 |
474 |
463 for (int i = 0; i < hostnameList.size(); i++) |
475 for (int i = 0; i < hostnameList.size(); i++) |
464 QHostInfo::lookupHost(hostnameList.at(i), this, SLOT(resultsReady(const QHostInfo))); |
476 for (int j = 0; j < repeats; ++j) |
465 |
477 QHostInfo::lookupHost(hostnameList.at(i), this, SLOT(resultsReady(const QHostInfo))); |
466 // give some time |
478 |
467 QTestEventLoop::instance().enterLoop(5); |
479 QElapsedTimer timer; |
468 // try_verify gives some more time |
480 timer.start(); |
469 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
481 while (timer.elapsed() < 10000 && lookupsDoneCounter < repeats*COUNT) { |
470 |
482 QTestEventLoop::instance().enterLoop(2); |
471 // spin two seconds more to see if it is not more than expected |
483 } |
472 QTestEventLoop::instance().enterLoop(2); |
484 QCOMPARE(lookupsDoneCounter, repeats*COUNT); |
473 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
|
474 } |
485 } |
475 |
486 |
476 void tst_QHostInfo::cache() |
487 void tst_QHostInfo::cache() |
477 { |
488 { |
478 QFETCH_GLOBAL(bool, cache); |
489 QFETCH_GLOBAL(bool, cache); |