summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/kernel')
-rw-r--r--tests/auto/network/kernel/qhostinfo/BLACKLIST6
-rw-r--r--tests/auto/network/kernel/qhostinfo/qhostinfo.pro3
-rw-r--r--tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp42
-rw-r--r--tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp35
-rw-r--r--tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp114
5 files changed, 52 insertions, 148 deletions
diff --git a/tests/auto/network/kernel/qhostinfo/BLACKLIST b/tests/auto/network/kernel/qhostinfo/BLACKLIST
new file mode 100644
index 0000000000..87c5fe991f
--- /dev/null
+++ b/tests/auto/network/kernel/qhostinfo/BLACKLIST
@@ -0,0 +1,6 @@
+# These tests fail due to a DNS server issue
+# (this is not a Qt bug)
+[lookupIPv6:a-plus-aaaa]
+windows ci
+[blockingLookup:a-plus-aaaa]
+windows ci
diff --git a/tests/auto/network/kernel/qhostinfo/qhostinfo.pro b/tests/auto/network/kernel/qhostinfo/qhostinfo.pro
index 67a37faeb5..3d8457dd46 100644
--- a/tests/auto/network/kernel/qhostinfo/qhostinfo.pro
+++ b/tests/auto/network/kernel/qhostinfo/qhostinfo.pro
@@ -8,7 +8,4 @@ QT = core-private network-private testlib
win32:LIBS += -lws2_32
-# needed for getaddrinfo with official MinGW
-mingw:DEFINES += _WIN32_WINNT=0x0501
-
winrt: WINRT_MANIFEST.capabilities += internetClientServer
diff --git a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
index 14bffaf7ca..82825f608c 100644
--- a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
+++ b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
@@ -64,14 +64,10 @@
#include <qhostinfo.h>
#include "private/qhostinfo_p.h"
-#if !defined(QT_NO_GETADDRINFO)
-# include <sys/types.h>
-# if defined(Q_OS_UNIX)
+#include <sys/types.h>
+#if defined(Q_OS_UNIX)
# include <sys/socket.h>
-# endif
-# if !defined(Q_OS_WIN)
# include <netdb.h>
-# endif
#endif
#include "../../../network-settings.h"
@@ -86,6 +82,8 @@ class tst_QHostInfo : public QObject
private slots:
void init();
void initTestCase();
+ void swapFunction();
+ void moveOperator();
void getSetCheck();
void staticInformation();
void lookupIPv4_data();
@@ -129,6 +127,29 @@ private:
#endif
};
+void tst_QHostInfo::swapFunction()
+{
+ QHostInfo obj1, obj2;
+ obj1.setError(QHostInfo::HostInfoError(0));
+ obj2.setError(QHostInfo::HostInfoError(1));
+ obj1.swap(obj2);
+ QCOMPARE(QHostInfo::HostInfoError(0), obj2.error());
+ QCOMPARE(QHostInfo::HostInfoError(1), obj1.error());
+}
+
+void tst_QHostInfo::moveOperator()
+{
+ QHostInfo obj1, obj2, obj3(1);
+ obj1.setError(QHostInfo::HostInfoError(0));
+ obj2.setError(QHostInfo::HostInfoError(1));
+ obj1 = std::move(obj2);
+ obj2 = obj3;
+ QCOMPARE(QHostInfo::HostInfoError(1), obj1.error());
+ QCOMPARE(obj3.lookupId(), obj2.lookupId());
+}
+
+
+
// Testing get/set functions
void tst_QHostInfo::getSetCheck()
{
@@ -166,7 +187,7 @@ void tst_QHostInfo::initTestCase()
networkSession.reset(new QNetworkSession(networkConfiguration));
if (!networkSession->isOpen()) {
networkSession->open();
- QVERIFY(networkSession->waitForOpened(30000));
+ networkSession->waitForOpened(30000);
}
#endif
@@ -179,15 +200,13 @@ void tst_QHostInfo::initTestCase()
ipv6Available = true;
}
-// HP-UX 11i does not support IPv6 reverse lookups.
-#if !defined(QT_NO_GETADDRINFO) && !(defined(Q_OS_HPUX) && defined(__ia64))
// check if the system getaddrinfo can do IPv6 lookups
struct addrinfo hint, *result = 0;
memset(&hint, 0, sizeof hint);
hint.ai_family = AF_UNSPEC;
-# ifdef AI_ADDRCONFIG
+#ifdef AI_ADDRCONFIG
hint.ai_flags = AI_ADDRCONFIG;
-# endif
+#endif
int res = getaddrinfo("::1", "80", &hint, &result);
if (res == 0) {
@@ -199,7 +218,6 @@ void tst_QHostInfo::initTestCase()
ipv6LookupsAvailable = true;
}
}
-#endif
// run each testcase with and without test enabled
QTest::addColumn<bool>("cache");
diff --git a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
index 5695f90c53..36dcec0a82 100644
--- a/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
+++ b/tests/auto/network/kernel/qnetworkinterface/tst_qnetworkinterface.cpp
@@ -32,7 +32,7 @@
#include <qcoreapplication.h>
#include <qnetworkinterface.h>
-#include <qtcpsocket.h>
+#include <qudpsocket.h>
#ifndef QT_NO_BEARERMANAGEMENT
#include <QNetworkConfigurationManager>
#include <QNetworkSession>
@@ -48,6 +48,8 @@ public:
tst_QNetworkInterface();
virtual ~tst_QNetworkInterface();
+ bool isIPv6Working();
+
private slots:
void initTestCase();
void cleanupTestCase();
@@ -76,6 +78,13 @@ tst_QNetworkInterface::~tst_QNetworkInterface()
{
}
+bool tst_QNetworkInterface::isIPv6Working()
+{
+ QUdpSocket socket;
+ socket.connectToHost(QHostAddress::LocalHostIPv6, 1234);
+ return socket.state() == QAbstractSocket::ConnectedState || socket.waitForConnected(100);
+}
+
void tst_QNetworkInterface::initTestCase()
{
if (!QtNetworkSettings::verifyTestNetworkSettings())
@@ -172,35 +181,21 @@ void tst_QNetworkInterface::loopbackIPv4()
void tst_QNetworkInterface::loopbackIPv6()
{
+ if (!isIPv6Working())
+ QSKIP("IPv6 not active on this machine");
QList<QHostAddress> all = QNetworkInterface::allAddresses();
-
- bool loopbackfound = false;
- bool anyIPv6 = false;
- foreach (QHostAddress addr, all)
- if (addr == QHostAddress::LocalHostIPv6) {
- loopbackfound = true;
- anyIPv6 = true;
- break;
- } else if (addr.protocol() == QAbstractSocket::IPv6Protocol)
- anyIPv6 = true;
-
- QVERIFY(!anyIPv6 || loopbackfound);
+ QVERIFY(all.contains(QHostAddress(QHostAddress::LocalHostIPv6)));
}
void tst_QNetworkInterface::localAddress()
{
- QTcpSocket socket;
+ QUdpSocket socket;
socket.connectToHost(QtNetworkSettings::serverName(), 80);
QVERIFY(socket.waitForConnected(5000));
QHostAddress local = socket.localAddress();
- // make Apache happy on fluke
- socket.write("GET / HTTP/1.0\r\n\r\n");
- socket.waitForBytesWritten(1000);
- socket.close();
-
- // test that we can find the address that QTcpSocket reported
+ // test that we can find the address that QUdpSocket reported
QList<QHostAddress> all = QNetworkInterface::allAddresses();
QVERIFY(all.contains(local));
}
diff --git a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
index 7fef603003..90da0b64e2 100644
--- a/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
+++ b/tests/auto/network/kernel/qnetworkproxyfactory/tst_qnetworkproxyfactory.cpp
@@ -34,10 +34,8 @@
#include <qdebug.h>
#include <qnetworkproxy.h>
-#include <QNetworkConfiguration>
-#include <QNetworkConfigurationManager>
-#include <QNetworkSession>
#include <QNetworkAccessManager>
+#include <QNetworkInterface>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QList>
@@ -71,11 +69,6 @@ private slots:
void systemProxyForQuery_data();
void systemProxyForQuery() const;
void systemProxyForQuery_local();
-#ifndef QT_NO_BEARERMANAGEMENT
- void fromConfigurations();
- void inNetworkAccessManager_data();
- void inNetworkAccessManager();
-#endif
void genericSystemProxy();
void genericSystemProxy_data();
@@ -253,111 +246,6 @@ void tst_QNetworkProxyFactory::systemProxyForQuery_local()
QVERIFY(list.isEmpty() || (list[0].type() == QNetworkProxy::NoProxy));
}
-#ifndef QT_NO_BEARERMANAGEMENT
-
-//Purpose of this test is just to check systemProxyForQuery doesn't hang or crash
-//with any given configuration including no configuration.
-//We can't test it returns the right proxies without implementing the native proxy code
-//again here, which would be testing our implementation against itself.
-//Therefore it's just testing that something valid is returned (at least a NoProxy entry)
-void tst_QNetworkProxyFactory::fromConfigurations()
-{
- QNetworkConfigurationManager manager;
- QList<QNetworkProxy> proxies;
- QUrl url(QLatin1String("http://qt-project.org"));
- //get from known configurations
- foreach (QNetworkConfiguration config, manager.allConfigurations()) {
- QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest);
- proxies = QNetworkProxyFactory::systemProxyForQuery(query);
- QVERIFY(!proxies.isEmpty());
- foreach (QNetworkProxy proxy, proxies) {
- qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy);
- }
- }
-
- //get from default configuration
- QNetworkProxyQuery defaultquery(url, QNetworkProxyQuery::UrlRequest);
- proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery);
- QVERIFY(!proxies.isEmpty());
- foreach (QNetworkProxy proxy, proxies) {
- qDebug() << "default - " << formatProxyName(proxy);
- }
-
- //get from active configuration
- QNetworkSession session(manager.defaultConfiguration());
- session.open();
- QVERIFY(session.waitForOpened(30000));
- proxies = QNetworkProxyFactory::systemProxyForQuery(defaultquery);
- QVERIFY(!proxies.isEmpty());
- foreach (QNetworkProxy proxy, proxies) {
- qDebug() << "active - " << formatProxyName(proxy);
- }
-
- //get from known configurations while there is one active
- foreach (QNetworkConfiguration config, manager.allConfigurations()) {
- QNetworkProxyQuery query(config, url, QNetworkProxyQuery::UrlRequest);
- proxies = QNetworkProxyFactory::systemProxyForQuery(query);
- QVERIFY(!proxies.isEmpty());
- foreach (QNetworkProxy proxy, proxies) {
- qDebug() << config.name() << " - " << config.identifier() << " - " << formatProxyName(proxy);
- }
- }
-}
-
-void tst_QNetworkProxyFactory::inNetworkAccessManager_data()
-{
- QTest::addColumn<QNetworkConfiguration>("config");
- QTest::addColumn<QList<QNetworkProxy> >("proxies");
- QNetworkConfigurationManager manager;
- //get from known configurations
- foreach (QNetworkConfiguration config, manager.allConfigurations()) {
- QNetworkProxyQuery query(config, QUrl(QString("http://qt-project.org")), QNetworkProxyQuery::UrlRequest);
- QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery(query);
- QTest::newRow(config.name().toUtf8()) << config << proxies;
- }
-}
-
-//Purpose of this test is to check that QNetworkAccessManager uses the proxy from the configuration it
-//has been given. Needs two or more working configurations to be a good test.
-void tst_QNetworkProxyFactory::inNetworkAccessManager()
-{
- QFETCH(QNetworkConfiguration, config);
- QFETCH(QList<QNetworkProxy>, proxies);
-
- int count = QDebugProxyFactory::requestCounter;
-
- QNetworkAccessManager manager;
- manager.setConfiguration(config);
-
- //using an internet server, because cellular APs won't have a route to the test server.
- QNetworkRequest req(QUrl(QString("http://qt-project.org")));
- QNetworkReply *reply = manager.get(req);
- connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
- QTestEventLoop::instance().enterLoop(30);
- delete reply;
-
- if (count == QDebugProxyFactory::requestCounter) {
- //RND phones are preconfigured with several test access points which won't work without a matching SIM
- //If the network fails to start, QNAM won't ask the factory for proxies so we can't test.
- QSKIP("network configuration didn't start");
- }
- QVERIFY(factory);
-
- qDebug() << "testing network configuration for" << config.name();
- foreach (QNetworkProxy proxy, factory->returnedList) {
- qDebug() << formatProxyName(proxy);
- }
- qDebug() << " <vs> ";
- foreach (QNetworkProxy proxy, proxies) {
- qDebug() << formatProxyName(proxy);
- }
- if (config.type() != QNetworkConfiguration::InternetAccessPoint)
- QEXPECT_FAIL("","QNetworkProxyFactory::systemProxyForQuery doesn't work for service networks yet", Continue);
- QCOMPARE(factory->returnedList, proxies);
-}
-
-#endif //QT_NO_BEARERMANAGEMENT
-
Q_DECLARE_METATYPE(QNetworkProxy::ProxyType)
void tst_QNetworkProxyFactory::genericSystemProxy()