summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-11-29 15:30:52 +0100
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-07 13:21:20 +0000
commit4077fcc6153493284b5e2b0812ff215b49e8c8b7 (patch)
tree83f2643e479437b69388255a400c981dea74f8cc /tests
parent630f8e7ad6e94c703f85fa11a9926ba83c478e72 (diff)
QHostAddress: fix assignment operators
QHostAddress allowed assignment from a QString, but the respective constructor is explicit, and rightfully so. So it does not make sense that the assignment operator is provided, because of the asymmetry caused between QHostAddress addr = funcReturningQString(); // ERROR addr = funcReturningQString(); // OK (until now) By the same token, since SpecialAddress is implicitly convertible to QHostAddress, provide the missing assignment operator from that enum. Add tests, rewriting the _data() function to use the enum instead of an int to pass SpecialAddress values, and to test !=, too. Added setAddress(SpecialAddress), since a) it was missing and b) to share code between the ctor and the assignment operator. Change-Id: Ief64c493be13ada8c6968801d9ed083b267fa902 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp63
1 files changed, 38 insertions, 25 deletions
diff --git a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
index 419c781aab..364e435d3d 100644
--- a/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
+++ b/tests/auto/network/kernel/qhostaddress/tst_qhostaddress.cpp
@@ -46,6 +46,8 @@
# include <netinet/in.h>
#endif
+Q_DECLARE_METATYPE(QHostAddress::SpecialAddress)
+
class tst_QHostAddress : public QObject
{
Q_OBJECT
@@ -232,51 +234,55 @@ void tst_QHostAddress::setAddress_QString()
void tst_QHostAddress::specialAddresses_data()
{
QTest::addColumn<QString>("text");
- QTest::addColumn<int>("address");
+ QTest::addColumn<QHostAddress::SpecialAddress>("address");
QTest::addColumn<bool>("result");
- QTest::newRow("localhost_1") << QString("127.0.0.1") << (int)QHostAddress::LocalHost << true;
- QTest::newRow("localhost_2") << QString("127.0.0.2") << (int)QHostAddress::LocalHost << false;
- QTest::newRow("localhost_3") << QString("127.0.0.2") << (int)QHostAddress::LocalHostIPv6 << false;
+ QTest::newRow("localhost_1") << QString("127.0.0.1") << QHostAddress::LocalHost << true;
+ QTest::newRow("localhost_2") << QString("127.0.0.2") << QHostAddress::LocalHost << false;
+ QTest::newRow("localhost_3") << QString("127.0.0.2") << QHostAddress::LocalHostIPv6 << false;
- QTest::newRow("localhost_ipv6_4") << QString("::1") << (int)QHostAddress::LocalHostIPv6 << true;
- QTest::newRow("localhost_ipv6_5") << QString("::2") << (int)QHostAddress::LocalHostIPv6 << false;
- QTest::newRow("localhost_ipv6_6") << QString("::1") << (int)QHostAddress::LocalHost << false;
+ QTest::newRow("localhost_ipv6_4") << QString("::1") << QHostAddress::LocalHostIPv6 << true;
+ QTest::newRow("localhost_ipv6_5") << QString("::2") << QHostAddress::LocalHostIPv6 << false;
+ QTest::newRow("localhost_ipv6_6") << QString("::1") << QHostAddress::LocalHost << false;
- QTest::newRow("null_1") << QString("") << (int)QHostAddress::Null << true;
- QTest::newRow("null_2") << QString("bjarne") << (int)QHostAddress::Null << true;
+ QTest::newRow("null_1") << QString("") << QHostAddress::Null << true;
+ QTest::newRow("null_2") << QString("bjarne") << QHostAddress::Null << true;
- QTest::newRow("compare_from_null") << QString("") << (int)QHostAddress::Broadcast << false;
+ QTest::newRow("compare_from_null") << QString("") << QHostAddress::Broadcast << false;
- QTest::newRow("broadcast_1") << QString("255.255.255.255") << (int)QHostAddress::Any << false;
- QTest::newRow("broadcast_2") << QString("255.255.255.255") << (int)QHostAddress::Broadcast << true;
+ QTest::newRow("broadcast_1") << QString("255.255.255.255") << QHostAddress::Any << false;
+ QTest::newRow("broadcast_2") << QString("255.255.255.255") << QHostAddress::Broadcast << true;
- QTest::newRow("any_ipv6") << QString("::") << (int)QHostAddress::AnyIPv6 << true;
- QTest::newRow("any_ipv4") << QString("0.0.0.0") << (int)QHostAddress::AnyIPv4 << true;
+ QTest::newRow("any_ipv6") << QString("::") << QHostAddress::AnyIPv6 << true;
+ QTest::newRow("any_ipv4") << QString("0.0.0.0") << QHostAddress::AnyIPv4 << true;
- QTest::newRow("dual_not_ipv6") << QString("::") << (int)QHostAddress::Any << false;
- QTest::newRow("dual_not_ipv4") << QString("0.0.0.0") << (int)QHostAddress::Any << false;
+ QTest::newRow("dual_not_ipv6") << QString("::") << QHostAddress::Any << false;
+ QTest::newRow("dual_not_ipv4") << QString("0.0.0.0") << QHostAddress::Any << false;
}
void tst_QHostAddress::specialAddresses()
{
QFETCH(QString, text);
- QFETCH(int, address);
+ QFETCH(QHostAddress::SpecialAddress, address);
QFETCH(bool, result);
- QVERIFY((QHostAddress(text) == (QHostAddress::SpecialAddress)address) == result);
+ QCOMPARE(QHostAddress(text) == address, result);
//check special address equal to itself (QTBUG-22898), note two overloads of operator==
- QVERIFY(QHostAddress((QHostAddress::SpecialAddress)address) == QHostAddress((QHostAddress::SpecialAddress)address));
- QVERIFY(QHostAddress((QHostAddress::SpecialAddress)address) == (QHostAddress::SpecialAddress)address);
+ QVERIFY(QHostAddress(address) == QHostAddress(address));
+ QVERIFY(QHostAddress(address) == address);
+ QVERIFY(!(QHostAddress(address) != QHostAddress(address)));
+ QVERIFY(!(QHostAddress(address) != address));
+
+ {
+ QHostAddress ha;
+ ha.setAddress(address);
+ QVERIFY(ha == address);
+ }
QHostAddress setter;
setter.setAddress(text);
- if (result) {
- QVERIFY(setter == (QHostAddress::SpecialAddress) address);
- } else {
- QVERIFY(!((QHostAddress::SpecialAddress) address == setter));
- }
+ QCOMPARE(setter == address, result);
}
@@ -359,6 +365,11 @@ void tst_QHostAddress::isEqual()
QCOMPARE(second.isEqual(first, QHostAddress::ConversionModeFlag(flags)), result);
}
+QT_WARNING_PUSH
+#ifdef QT_WARNING_DISABLE_DEPRECATED
+QT_WARNING_DISABLE_DEPRECATED
+#endif
+
void tst_QHostAddress::assignment()
{
QHostAddress address;
@@ -379,6 +390,8 @@ void tst_QHostAddress::assignment()
#endif // !Q_OS_WINRT
}
+QT_WARNING_POP
+
void tst_QHostAddress::scopeId()
{
QHostAddress address("fe80::2e0:4cff:fefb:662a%eth0");