203 QTcpServer server; |
207 QTcpServer server; |
204 if (server.listen(QHostAddress("::1"))) { |
208 if (server.listen(QHostAddress("::1"))) { |
205 // We have IPv6 support |
209 // We have IPv6 support |
206 ipv6Available = true; |
210 ipv6Available = true; |
207 } |
211 } |
|
212 |
|
213 |
|
214 // run each testcase with and without test enabled |
|
215 QTest::addColumn<bool>("cache"); |
|
216 QTest::newRow("WithCache") << true; |
|
217 QTest::newRow("WithoutCache") << false; |
208 } |
218 } |
209 |
219 |
210 void tst_QHostInfo::init() |
220 void tst_QHostInfo::init() |
211 { |
221 { |
|
222 // delete the cache so inidividual testcase results are independant from each other |
|
223 qt_qhostinfo_clear_cache(); |
|
224 |
|
225 QFETCH_GLOBAL(bool, cache); |
|
226 qt_qhostinfo_enable_cache(cache); |
212 } |
227 } |
213 |
228 |
214 void tst_QHostInfo::cleanup() |
229 void tst_QHostInfo::cleanup() |
215 { |
230 { |
216 } |
231 } |
456 // spin two seconds more to see if it is not more than expected |
471 // spin two seconds more to see if it is not more than expected |
457 QTestEventLoop::instance().enterLoop(2); |
472 QTestEventLoop::instance().enterLoop(2); |
458 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
473 QTRY_VERIFY(lookupsDoneCounter == COUNT); |
459 } |
474 } |
460 |
475 |
|
476 void tst_QHostInfo::cache() |
|
477 { |
|
478 QFETCH_GLOBAL(bool, cache); |
|
479 if (!cache) |
|
480 return; // test makes only sense when cache enabled |
|
481 |
|
482 // reset slot counter |
|
483 lookupsDoneCounter = 0; |
|
484 |
|
485 // lookup once, wait in event loop, result should not come directly. |
|
486 bool valid = true; |
|
487 int id = -1; |
|
488 QHostInfo result = qt_qhostinfo_lookup("localhost", this, SLOT(resultsReady(QHostInfo)), &valid, &id); |
|
489 QTestEventLoop::instance().enterLoop(5); |
|
490 QVERIFY(!QTestEventLoop::instance().timeout()); |
|
491 QVERIFY(valid == false); |
|
492 QVERIFY(result.addresses().isEmpty()); |
|
493 |
|
494 // loopkup second time, result should come directly |
|
495 valid = false; |
|
496 result = qt_qhostinfo_lookup("localhost", this, SLOT(resultsReady(QHostInfo)), &valid, &id); |
|
497 QVERIFY(valid == true); |
|
498 QVERIFY(!result.addresses().isEmpty()); |
|
499 |
|
500 // clear the cache |
|
501 qt_qhostinfo_clear_cache(); |
|
502 |
|
503 // lookup third time, result should not come directly. |
|
504 valid = true; |
|
505 result = qt_qhostinfo_lookup("localhost", this, SLOT(resultsReady(QHostInfo)), &valid, &id); |
|
506 QTestEventLoop::instance().enterLoop(5); |
|
507 QVERIFY(!QTestEventLoop::instance().timeout()); |
|
508 QVERIFY(valid == false); |
|
509 QVERIFY(result.addresses().isEmpty()); |
|
510 |
|
511 // the slot should have been called 2 times. |
|
512 QVERIFY(lookupsDoneCounter == 2); |
|
513 } |
|
514 |
461 void tst_QHostInfo::resultsReady(const QHostInfo &hi) |
515 void tst_QHostInfo::resultsReady(const QHostInfo &hi) |
462 { |
516 { |
463 lookupDone = true; |
517 lookupDone = true; |
464 lookupResults = hi; |
518 lookupResults = hi; |
465 lookupsDoneCounter++; |
519 lookupsDoneCounter++; |