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/kernel.pro3
-rw-r--r--tests/auto/network/kernel/qauthenticator/qauthenticator.pro2
-rw-r--r--tests/auto/network/kernel/qhostaddress/qhostaddress.pro8
-rw-r--r--tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp50
-rw-r--r--tests/auto/network/kernel/qhostinfo/qhostinfo.pro8
-rw-r--r--tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp8
-rw-r--r--tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro5
-rw-r--r--tests/auto/network/kernel/qnetworkdatagram/tst_qnetworkdatagram.cpp146
8 files changed, 207 insertions, 23 deletions
diff --git a/tests/auto/network/kernel/kernel.pro b/tests/auto/network/kernel/kernel.pro
index bb13c7dd7d..42df80dfa1 100644
--- a/tests/auto/network/kernel/kernel.pro
+++ b/tests/auto/network/kernel/kernel.pro
@@ -7,6 +7,7 @@ SUBDIRS=\
qauthenticator \
qnetworkproxy \
qnetworkinterface \
+ qnetworkdatagram \
qnetworkaddressentry \
qhostaddress \
@@ -17,7 +18,7 @@ winrt: SUBDIRS -= \
osx: SUBDIRS -= \ # QTBUG-41847
qhostinfo \
-!contains(QT_CONFIG, private_tests): SUBDIRS -= \
+!qtConfig(private_tests): SUBDIRS -= \
qauthenticator \
qhostinfo \
diff --git a/tests/auto/network/kernel/qauthenticator/qauthenticator.pro b/tests/auto/network/kernel/qauthenticator/qauthenticator.pro
index 5e4759b690..5038eea9af 100644
--- a/tests/auto/network/kernel/qauthenticator/qauthenticator.pro
+++ b/tests/auto/network/kernel/qauthenticator/qauthenticator.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qauthenticator
-requires(contains(QT_CONFIG,private_tests))
+requires(qtConfig(private_tests))
QT = core network-private testlib
SOURCES += tst_qauthenticator.cpp
DEFINES += SRCDIR=\\\"$$PWD/\\\"
diff --git a/tests/auto/network/kernel/qhostaddress/qhostaddress.pro b/tests/auto/network/kernel/qhostaddress/qhostaddress.pro
index 19d74dfd9b..a79fa2f59d 100644
--- a/tests/auto/network/kernel/qhostaddress/qhostaddress.pro
+++ b/tests/auto/network/kernel/qhostaddress/qhostaddress.pro
@@ -5,10 +5,4 @@ SOURCES += tst_qhostaddress.cpp
QT = core network testlib
-win32: {
-wince {
- LIBS += -lws2
-} else {
- LIBS += -lws2_32
-}
-}
+win32:LIBS += -lws2_32
diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
index 4fb97fe1f2..419c781aab 100644
--- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
+++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
@@ -62,6 +62,8 @@ private slots:
void specialAddresses();
void compare_data();
void compare();
+ void isEqual_data();
+ void isEqual();
void assignment();
void scopeId();
void hashKey();
@@ -291,6 +293,7 @@ void tst_QHostAddress::compare_data()
QTest::newRow("5") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::Broadcast) << false;
QTest::newRow("6") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::LocalHostIPv6) << false;
QTest::newRow("7") << QHostAddress() << QHostAddress(QHostAddress::LocalHostIPv6) << false;
+ QTest::newRow("any4-any6") << QHostAddress(QHostAddress::AnyIPv4) << QHostAddress(QHostAddress::AnyIPv6) << false;
Q_IPV6ADDR localhostv4mapped = { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1 } };
QTest::newRow("v4-v4mapped") << QHostAddress(QHostAddress::LocalHost) << QHostAddress("::ffff:127.0.0.1") << false;
@@ -309,6 +312,53 @@ void tst_QHostAddress::compare()
QCOMPARE(qHash(first), qHash(second));
}
+void tst_QHostAddress::isEqual_data()
+{
+ QTest::addColumn<QHostAddress>("first");
+ QTest::addColumn<QHostAddress>("second");
+ QTest::addColumn<int>("flags");
+ QTest::addColumn<bool>("result");
+
+ // QHostAddress::StrictConversion is already tested in compare()
+ QTest::newRow("localhost4to6-local") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertLocalHost << true;
+ QTest::newRow("localhost4to6-compat") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertV4CompatToIPv4 << false;
+ QTest::newRow("localhost4to6-mapped") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertV4MappedToIPv4 << false;
+ QTest::newRow("localhost4to6-unspec") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertUnspecifiedAddress << false;
+ QTest::newRow("0.0.0.1-::1-local") << QHostAddress("0.0.0.1") << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertLocalHost << false;
+ QTest::newRow("v4-v4compat-local") << QHostAddress("192.168.1.1") << QHostAddress("::192.168.1.1") << (int)QHostAddress::ConvertLocalHost << false;
+ QTest::newRow("v4-v4mapped-local") << QHostAddress("192.168.1.1") << QHostAddress("::ffff:192.168.1.1") << (int)QHostAddress::ConvertLocalHost << false;
+ QTest::newRow("0.0.0.1-::1-unspec") << QHostAddress("0.0.0.1") << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertUnspecifiedAddress << false;
+ QTest::newRow("v4-v4compat-unspec") << QHostAddress("192.168.1.1") << QHostAddress("::192.168.1.1") << (int)QHostAddress::ConvertUnspecifiedAddress << false;
+ QTest::newRow("v4-v4mapped-unspec") << QHostAddress("192.168.1.1") << QHostAddress("::ffff:192.168.1.1") << (int)QHostAddress::ConvertUnspecifiedAddress << false;
+ QTest::newRow("0.0.0.1-::1-compat") << QHostAddress("0.0.0.1") << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertV4CompatToIPv4 << false;
+ QTest::newRow("v4-v4compat-compat") << QHostAddress("192.168.1.1") << QHostAddress("::192.168.1.1") << (int)QHostAddress::ConvertV4CompatToIPv4 << true;
+ QTest::newRow("v4-v4mapped-compat") << QHostAddress("192.168.1.1") << QHostAddress("::ffff:192.168.1.1") << (int)QHostAddress::ConvertV4CompatToIPv4 << false;
+ QTest::newRow("0.0.0.1-::1-mapped") << QHostAddress("0.0.0.1") << QHostAddress(QHostAddress::LocalHostIPv6) << (int)QHostAddress::ConvertV4MappedToIPv4 << false;
+ QTest::newRow("v4-v4compat-mapped") << QHostAddress("192.168.1.1") << QHostAddress("::192.168.1.1") << (int)QHostAddress::ConvertV4MappedToIPv4 << false;
+ QTest::newRow("v4-v4mapped-mapped") << QHostAddress("192.168.1.1") << QHostAddress("::FFFF:192.168.1.1") << (int)QHostAddress::ConvertV4MappedToIPv4 << true;
+ QTest::newRow("undef-any-local") << QHostAddress() << QHostAddress(QHostAddress::Any) << (int)QHostAddress::ConvertLocalHost << false;
+ QTest::newRow("undef-any-unspec") << QHostAddress() << QHostAddress(QHostAddress::Any) << (int)QHostAddress::ConvertUnspecifiedAddress << false;
+ QTest::newRow("anyv6-anyv4-compat") << QHostAddress(QHostAddress::AnyIPv6) << QHostAddress(QHostAddress::AnyIPv4) << (int)QHostAddress::ConvertV4CompatToIPv4 << true;
+ QTest::newRow("anyv6-anyv4-mapped") << QHostAddress(QHostAddress::AnyIPv6) << QHostAddress(QHostAddress::AnyIPv4) << (int)QHostAddress::ConvertV4MappedToIPv4 << false;
+ QTest::newRow("anyv6-anyv4-unspec") << QHostAddress(QHostAddress::AnyIPv6) << QHostAddress(QHostAddress::AnyIPv4) << (int)QHostAddress::ConvertUnspecifiedAddress << true;
+ QTest::newRow("any-anyv4-unspec") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv4) << (int)QHostAddress::ConvertUnspecifiedAddress << true;
+ QTest::newRow("any-anyv6-unspec") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv6) << (int)QHostAddress::ConvertUnspecifiedAddress << true;
+ QTest::newRow("anyv6-anyv4-local") << QHostAddress(QHostAddress::AnyIPv6) << QHostAddress(QHostAddress::AnyIPv4) << (int)QHostAddress::ConvertLocalHost << false;
+ QTest::newRow("any-anyv4-local") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv4) << (int)QHostAddress::ConvertLocalHost << false;
+ QTest::newRow("any-anyv6-local") << QHostAddress(QHostAddress::Any) << QHostAddress(QHostAddress::AnyIPv6) << (int)QHostAddress::ConvertLocalHost << false;
+}
+
+void tst_QHostAddress::isEqual()
+{
+ QFETCH(QHostAddress, first);
+ QFETCH(QHostAddress, second);
+ QFETCH(int, flags);
+ QFETCH(bool, result);
+
+ QCOMPARE(first.isEqual(second, QHostAddress::ConversionModeFlag(flags)), result);
+ QCOMPARE(second.isEqual(first, QHostAddress::ConversionModeFlag(flags)), result);
+}
+
void tst_QHostAddress::assignment()
{
QHostAddress address;
diff --git a/tests/auto/network/kernel/qhostinfo/qhostinfo.pro b/tests/auto/network/kernel/qhostinfo/qhostinfo.pro
index 12858c97ee..67a37faeb5 100644
--- a/tests/auto/network/kernel/qhostinfo/qhostinfo.pro
+++ b/tests/auto/network/kernel/qhostinfo/qhostinfo.pro
@@ -3,14 +3,10 @@ TARGET = tst_qhostinfo
SOURCES += tst_qhostinfo.cpp
-requires(contains(QT_CONFIG,private_tests))
+requires(qtConfig(private_tests))
QT = core-private network-private testlib
-wince {
- LIBS += ws2.lib
-} else {
- win32:LIBS += -lws2_32
-}
+win32:LIBS += -lws2_32
# needed for getaddrinfo with official MinGW
mingw:DEFINES += _WIN32_WINNT=0x0501
diff --git a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
index 13d4442ada..f6d9b71aa2 100644
--- a/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
+++ b/tests/auto/network/kernel/qhostinfo/tst_qhostinfo.cpp
@@ -66,11 +66,7 @@
#include "private/qhostinfo_p.h"
#if !defined(QT_NO_GETADDRINFO)
-# if !defined(Q_OS_WINCE)
# include <sys/types.h>
-# else
-# include <types.h>
-# endif
# if defined(Q_OS_UNIX)
# include <sys/socket.h>
# endif
@@ -399,11 +395,7 @@ protected:
void tst_QHostInfo::threadSafety()
{
const int nattempts = 5;
-#if defined(Q_OS_WINCE)
- const int runs = 10;
-#else
const int runs = 100;
-#endif
LookupThread thr[nattempts];
for (int j = 0; j < runs; ++j) {
for (int i = 0; i < nattempts; ++i)
diff --git a/tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro b/tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro
new file mode 100644
index 0000000000..a2fe44060e
--- /dev/null
+++ b/tests/auto/network/kernel/qnetworkdatagram/qnetworkdatagram.pro
@@ -0,0 +1,5 @@
+CONFIG += testcase console
+CONFIG -= app_bundle
+TARGET = tst_qnetworkdatagram
+SOURCES += tst_qnetworkdatagram.cpp
+QT = core network testlib
diff --git a/tests/auto/network/kernel/qnetworkdatagram/tst_qnetworkdatagram.cpp b/tests/auto/network/kernel/qnetworkdatagram/tst_qnetworkdatagram.cpp
new file mode 100644
index 0000000000..3295580432
--- /dev/null
+++ b/tests/auto/network/kernel/qnetworkdatagram/tst_qnetworkdatagram.cpp
@@ -0,0 +1,146 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 Intel Corporation.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the QtNetwork module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QNetworkDatagram>
+#include <QtTest>
+#include <QCoreApplication>
+
+class tst_QNetworkDatagram : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QNetworkDatagram();
+
+private Q_SLOTS:
+ void getSetCheck();
+ void makeReply_data();
+ void makeReply();
+};
+
+tst_QNetworkDatagram::tst_QNetworkDatagram()
+{
+}
+
+void tst_QNetworkDatagram::getSetCheck()
+{
+ QNetworkDatagram dg;
+
+ QVERIFY(dg.isNull());
+ QVERIFY(!dg.isValid());
+ QCOMPARE(dg.senderAddress(), QHostAddress());
+ QCOMPARE(dg.destinationAddress(), QHostAddress());
+ QCOMPARE(dg.senderPort(), -1);
+ QCOMPARE(dg.destinationPort(), -1);
+ QCOMPARE(dg.hopLimit(), -1);
+ QCOMPARE(dg.interfaceIndex(), 0U);
+
+ dg.setHopLimit(1);
+ QCOMPARE(dg.hopLimit(), 1);
+ dg.setHopLimit(255);
+ QCOMPARE(dg.hopLimit(), 255);
+
+ dg.setInterfaceIndex(1);
+ QCOMPARE(dg.interfaceIndex(), 1U);
+ dg.setInterfaceIndex(1234567U);
+ QCOMPARE(dg.interfaceIndex(), 1234567U);
+
+ dg.setSender(QHostAddress::Any, 12345);
+ QCOMPARE(dg.senderAddress(), QHostAddress(QHostAddress::Any));
+ QCOMPARE(dg.senderPort(), 12345);
+ dg.setSender(QHostAddress::LocalHost);
+ QCOMPARE(dg.senderAddress(), QHostAddress(QHostAddress::LocalHost));
+ QCOMPARE(dg.senderPort(), 0);
+
+ dg.setDestination(QHostAddress::LocalHostIPv6, 12345);
+ QCOMPARE(dg.destinationAddress(), QHostAddress(QHostAddress::LocalHostIPv6));
+ QCOMPARE(dg.destinationPort(), 12345);
+ dg.setDestination(QHostAddress::Broadcast, 137);
+ QCOMPARE(dg.destinationAddress(), QHostAddress(QHostAddress::Broadcast));
+ QCOMPARE(dg.destinationPort(), 137);
+}
+
+void tst_QNetworkDatagram::makeReply_data()
+{
+ qRegisterMetaType<QNetworkDatagram>();
+ QTest::addColumn<QNetworkDatagram>("dgram");
+ QTest::addColumn<QString>("localAddress");
+
+ QNetworkDatagram dgram("some data", QHostAddress("192.0.2.1"), 10001);
+ dgram.setHopLimit(64);
+ dgram.setSender(QHostAddress::LocalHost, 12345);
+ QTest::newRow("ipv4") << dgram << "192.0.2.1";
+
+ dgram.setDestination(QHostAddress("224.0.0.1"), 10002);
+ QTest::newRow("ipv4-multicast") << dgram << QString();
+
+ dgram.setSender(QHostAddress::LocalHostIPv6, 12346);
+ dgram.setDestination(QHostAddress("2001:db8::1"), 12347);
+ QTest::newRow("ipv6") << dgram << "2001:db8::1";
+
+ dgram.setSender(QHostAddress("fe80::1%1"), 10003);
+ dgram.setDestination(QHostAddress("fe80::2%1"), 10004);
+ dgram.setInterfaceIndex(1);
+ QTest::newRow("ipv6-linklocal") << dgram << "fe80::2%1";
+
+ dgram.setDestination(QHostAddress("ff02::1%1"), 10005);
+ QTest::newRow("ipv6-multicast") << dgram << QString();
+}
+
+void tst_QNetworkDatagram::makeReply()
+{
+ QFETCH(QNetworkDatagram, dgram);
+ QFETCH(QString, localAddress);
+
+ {
+ QNetworkDatagram reply = dgram.makeReply("World");
+ QCOMPARE(reply.data(), QByteArray("World"));
+ QCOMPARE(reply.senderAddress(), QHostAddress(localAddress));
+ QCOMPARE(reply.senderPort(), localAddress.isEmpty() ? -1 : dgram.destinationPort());
+ QCOMPARE(reply.destinationAddress(), dgram.senderAddress());
+ QCOMPARE(reply.destinationPort(), dgram.senderPort());
+ QCOMPARE(reply.interfaceIndex(), dgram.interfaceIndex());
+ QCOMPARE(reply.hopLimit(), -1);
+ }
+
+ QNetworkDatagram copy = dgram;
+ copy.setData(copy.data());
+ {
+ QNetworkDatagram reply = qMove(copy).makeReply("World");
+ QCOMPARE(reply.data(), QByteArray("World"));
+ QCOMPARE(reply.senderAddress(), QHostAddress(localAddress));
+ QCOMPARE(reply.senderPort(), localAddress.isEmpty() ? -1 : dgram.destinationPort());
+ QCOMPARE(reply.destinationAddress(), dgram.senderAddress());
+ QCOMPARE(reply.destinationPort(), dgram.senderPort());
+ QCOMPARE(reply.interfaceIndex(), dgram.interfaceIndex());
+ QCOMPARE(reply.hopLimit(), -1);
+ }
+}
+
+QTEST_MAIN(tst_QNetworkDatagram)
+#include "tst_qnetworkdatagram.moc"