summaryrefslogtreecommitdiffstats
path: root/tests/auto/qhostinfo
diff options
context:
space:
mode:
authorShane Kearns <shane.kearns@accenture.com>2011-04-05 15:17:52 +0100
committerShane Kearns <shane.kearns@accenture.com>2011-04-05 16:45:59 +0100
commitdc474b5d19f66dc3ede087ae6fa8ec6f9245477e (patch)
tree3285c2fab5f5074c7c985d5cef33352918edbe61 /tests/auto/qhostinfo
parent4aef1e1dd1ec5ccfdf56d91975185ff96a51701b (diff)
Add autotests for QHostInfo::abortHostLookup
Test calling the abort from the same thread or from a different thread. The different thread is to check thread safety of the API. Reviewed-by: Markus Goetz
Diffstat (limited to 'tests/auto/qhostinfo')
-rw-r--r--tests/auto/qhostinfo/tst_qhostinfo.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/auto/qhostinfo/tst_qhostinfo.cpp b/tests/auto/qhostinfo/tst_qhostinfo.cpp
index 7b2fc558db..0e9319fc95 100644
--- a/tests/auto/qhostinfo/tst_qhostinfo.cpp
+++ b/tests/auto/qhostinfo/tst_qhostinfo.cpp
@@ -134,6 +134,8 @@ private slots:
void cache();
+ void abortHostLookup();
+ void abortHostLookupInDifferentThread();
protected slots:
void resultsReady(const QHostInfo &);
@@ -583,5 +585,52 @@ void tst_QHostInfo::resultsReady(const QHostInfo &hi)
QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection);
}
+void tst_QHostInfo::abortHostLookup()
+{
+ //reset counter
+ lookupsDoneCounter = 0;
+ bool valid = false;
+ int id = -1;
+ QHostInfo result = qt_qhostinfo_lookup("qt.nokia.com", this, SLOT(resultsReady(QHostInfo)), &valid, &id);
+ QVERIFY(!valid);
+ //it is assumed that the DNS request/response in the backend is slower than it takes to call abort
+ QHostInfo::abortHostLookup(id);
+ QTestEventLoop::instance().enterLoop(5);
+ QCOMPARE(lookupsDoneCounter, 0);
+}
+
+class LookupAborter : public QObject
+{
+ Q_OBJECT
+public slots:
+ void abort()
+ {
+ QHostInfo::abortHostLookup(id);
+ QThread::currentThread()->quit();
+ }
+public:
+ int id;
+};
+
+void tst_QHostInfo::abortHostLookupInDifferentThread()
+{
+ //reset counter
+ lookupsDoneCounter = 0;
+ bool valid = false;
+ int id = -1;
+ QHostInfo result = qt_qhostinfo_lookup("qt.nokia.com", this, SLOT(resultsReady(QHostInfo)), &valid, &id);
+ QVERIFY(!valid);
+ QThread thread;
+ LookupAborter aborter;
+ aborter.id = id;
+ aborter.moveToThread(&thread);
+ connect(&thread, SIGNAL(started()), &aborter, SLOT(abort()));
+ //it is assumed that the DNS request/response in the backend is slower than it takes to schedule the thread and call abort
+ thread.start();
+ QVERIFY(thread.wait(5000));
+ QTestEventLoop::instance().enterLoop(5);
+ QCOMPARE(lookupsDoneCounter, 0);
+}
+
QTEST_MAIN(tst_QHostInfo)
#include "tst_qhostinfo.moc"