summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2009-12-21 16:03:13 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-03-02 10:15:48 (GMT)
commit5a028f794fe48dc7141acedbf0e896b488bb8cd5 (patch)
tree842a59a33a9e57693f7b537434fb9a04020bc675 /tests/auto
parentb08f42e5cc0d94a3b54494f6fe0af90be858f1eb (diff)
downloadQt-5a028f794fe48dc7141acedbf0e896b488bb8cd5.zip
Qt-5a028f794fe48dc7141acedbf0e896b488bb8cd5.tar.gz
Qt-5a028f794fe48dc7141acedbf0e896b488bb8cd5.tar.bz2
Add DNS caching to QHostInfo
By default enabled, but it can be disabled via a compile flag. Reviewed-by: Thiago
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qhostinfo/tst_qhostinfo.cpp55
1 files changed, 54 insertions, 1 deletions
diff --git a/tests/auto/qhostinfo/tst_qhostinfo.cpp b/tests/auto/qhostinfo/tst_qhostinfo.cpp
index d5411d0..cbadcf5 100644
--- a/tests/auto/qhostinfo/tst_qhostinfo.cpp
+++ b/tests/auto/qhostinfo/tst_qhostinfo.cpp
@@ -72,6 +72,7 @@
#endif
#include <qhostinfo.h>
+#include "private/qhostinfo_p.h"
#if !defined(QT_NO_GETADDRINFO)
# if !defined(Q_OS_WINCE)
@@ -108,10 +109,11 @@ public:
public slots:
void init();
void cleanup();
+ void initTestCase();
+
private slots:
void getSetCheck();
void staticInformation();
- void initTestCase();
void lookupIPv4_data();
void lookupIPv4();
void lookupIPv6_data();
@@ -128,6 +130,8 @@ private slots:
void multipleSameLookups();
void multipleDifferentLookups();
+ void cache();
+
protected slots:
void resultsReady(const QHostInfo &);
@@ -205,10 +209,21 @@ void tst_QHostInfo::initTestCase()
// We have IPv6 support
ipv6Available = true;
}
+
+
+ // run each testcase with and without test enabled
+ QTest::addColumn<bool>("cache");
+ QTest::newRow("WithCache") << false;
+ QTest::newRow("WithoutCache") << true;
}
void tst_QHostInfo::init()
{
+ // delete the cache so inidividual testcase results are independant from each other
+ qt_qhostinfo_clear_cache();
+
+ QFETCH_GLOBAL(bool, cache);
+ qt_qhostinfo_enable_cache(cache);
}
void tst_QHostInfo::cleanup()
@@ -458,6 +473,44 @@ void tst_QHostInfo::multipleDifferentLookups()
QTRY_VERIFY(lookupsDoneCounter == COUNT);
}
+void tst_QHostInfo::cache()
+{
+ QFETCH_GLOBAL(bool, cache);
+ if (!cache)
+ return; // test makes only sense when cache enabled
+
+ // reset slot counter
+ lookupsDoneCounter = 0;
+
+ // lookup once, wait in event loop, result should not come directly.
+ bool valid = true;
+ QHostInfo result = qt_qhostinfo_lookup("localhost", this, SLOT(resultsReady(QHostInfo)), &valid);
+ QTestEventLoop::instance().enterLoop(5);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(valid == false);
+ QVERIFY(result.addresses().isEmpty());
+
+ // loopkup second time, result should come directly
+ valid = false;
+ result = qt_qhostinfo_lookup("localhost", this, SLOT(resultsReady(QHostInfo)), &valid);
+ QVERIFY(valid == true);
+ QVERIFY(!result.addresses().isEmpty());
+
+ // clear the cache
+ qt_qhostinfo_clear_cache();
+
+ // lookup third time, result should not come directly.
+ valid = true;
+ result = qt_qhostinfo_lookup("localhost", this, SLOT(resultsReady(QHostInfo)), &valid);
+ QTestEventLoop::instance().enterLoop(5);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(valid == false);
+ QVERIFY(result.addresses().isEmpty());
+
+ // the slot should have been called 2 times.
+ QVERIFY(lookupsDoneCounter == 2);
+}
+
void tst_QHostInfo::resultsReady(const QHostInfo &hi)
{
lookupDone = true;