summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel/qhostinfo
diff options
context:
space:
mode:
authorJesus Fernandez <jesus.fernandez@qt.io>2016-10-24 21:01:09 +0200
committerJesus Fernandez <jesus.fernandez@qt.io>2017-01-24 20:54:07 +0000
commitad5eb297e179a164e297a7c2eb3b9674a1196605 (patch)
tree925a52ab653dfb0f63c422959f209ea89aae1e48 /tests/auto/network/kernel/qhostinfo
parent21f27c9a4d0f2ab0976c144f631c9171c899014b (diff)
Add QHostInfo::lookupHost overload with modern connect syntax
Task-number: QTBUG-56424 Change-Id: I49053ac2859e6c6c07e4a704b8b5f0d6a2d0b8a4 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/network/kernel/qhostinfo')
-rw-r--r--tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
index f6d9b71aa2..41ed7d2b93 100644
--- a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
+++ b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
@@ -93,6 +93,10 @@ private slots:
void lookupIPv4();
void lookupIPv6_data();
void lookupIPv6();
+ void lookupConnectToFunctionPointer_data();
+ void lookupConnectToFunctionPointer();
+ void lookupConnectToLambda_data();
+ void lookupConnectToLambda();
void reverseLookup_data();
void reverseLookup();
@@ -307,6 +311,74 @@ void tst_QHostInfo::lookupIPv6()
QCOMPARE(tmp.join(' ').toLower(), expected.join(' ').toLower());
}
+void tst_QHostInfo::lookupConnectToFunctionPointer_data()
+{
+ lookupIPv4_data();
+}
+
+void tst_QHostInfo::lookupConnectToFunctionPointer()
+{
+ QFETCH(QString, hostname);
+ QFETCH(int, err);
+ QFETCH(QString, addresses);
+
+ lookupDone = false;
+ QHostInfo::lookupHost(hostname, this, &tst_QHostInfo::resultsReady);
+
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(lookupDone);
+
+ if (int(lookupResults.error()) != int(err))
+ qWarning() << hostname << "=>" << lookupResults.errorString();
+ QCOMPARE(int(lookupResults.error()), int(err));
+
+ QStringList tmp;
+ for (const auto &result : lookupResults.addresses())
+ tmp.append(result.toString());
+ tmp.sort();
+
+ QStringList expected = addresses.split(' ');
+ expected.sort();
+
+ QCOMPARE(tmp.join(' '), expected.join(' '));
+}
+
+void tst_QHostInfo::lookupConnectToLambda_data()
+{
+ lookupIPv4_data();
+}
+
+void tst_QHostInfo::lookupConnectToLambda()
+{
+ QFETCH(QString, hostname);
+ QFETCH(int, err);
+ QFETCH(QString, addresses);
+
+ lookupDone = false;
+ QHostInfo::lookupHost(hostname, [=](const QHostInfo &hostInfo) {
+ resultsReady(hostInfo);
+ });
+
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(lookupDone);
+
+ if (int(lookupResults.error()) != int(err))
+ qWarning() << hostname << "=>" << lookupResults.errorString();
+ QCOMPARE(int(lookupResults.error()), int(err));
+
+ QStringList tmp;
+ for (int i = 0; i < lookupResults.addresses().count(); ++i)
+ tmp.append(lookupResults.addresses().at(i).toString());
+ tmp.sort();
+
+ QStringList expected = addresses.split(' ');
+ expected.sort();
+
+ QCOMPARE(tmp.join(' '), expected.join(' '));
+}
+
void tst_QHostInfo::reverseLookup_data()
{
QTest::addColumn<QString>("address");