Add swap and move operator to QHostInfo

Also mark as shared-come-qt6,

[ChangeLog][QtNetwork][QHostInfo] Added swap() and move operator.

Change-Id: I8f422868f0487a37aeba3bc74685dc4912e9b3a4
Coverity-Id: 168204
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Jesus Fernandez 2017-04-27 19:08:56 +02:00 committed by Jesus Fernandez
parent cafefd1d33
commit 904788e3c6
3 changed files with 51 additions and 0 deletions

View File

@ -278,6 +278,27 @@ int QHostInfo::lookupHost(const QString &name, QObject *receiver,
return id; return id;
} }
/*!
\fn QHostInfo &QHostInfo::operator=(QHostInfo &&other)
Move-assigns \a other to this QHostInfo instance.
\note The moved-from object \a other is placed in a
partially-formed state, in which the only valid operations are
destruction and assignment of a new value.
\since 5.10
*/
/*!
\fn void QHostInfo::swap(QHostInfo &other)
Swaps host-info \other with this host-info. This operation is
very fast and never fails.
\since 5.10
*/
/*! /*!
\fn int QHostInfo::lookupHost(const QString &name, const QObject *receiver, PointerToMemberFunction function) \fn int QHostInfo::lookupHost(const QString &name, const QObject *receiver, PointerToMemberFunction function)

View File

@ -63,8 +63,11 @@ public:
explicit QHostInfo(int lookupId = -1); explicit QHostInfo(int lookupId = -1);
QHostInfo(const QHostInfo &d); QHostInfo(const QHostInfo &d);
QHostInfo &operator=(const QHostInfo &d); QHostInfo &operator=(const QHostInfo &d);
QHostInfo &operator=(QHostInfo &&other) Q_DECL_NOTHROW { swap(other); return *this; }
~QHostInfo(); ~QHostInfo();
void swap(QHostInfo &other) Q_DECL_NOTHROW { qSwap(d, other.d); }
QString hostName() const; QString hostName() const;
void setHostName(const QString &name); void setHostName(const QString &name);
@ -154,6 +157,8 @@ private:
QtPrivate::QSlotObjectBase *slotObj); QtPrivate::QSlotObjectBase *slotObj);
}; };
Q_DECLARE_SHARED_NOT_MOVABLE_UNTIL_QT6(QHostInfo)
QT_END_NAMESPACE QT_END_NAMESPACE
Q_DECLARE_METATYPE(QHostInfo) Q_DECLARE_METATYPE(QHostInfo)

View File

@ -86,6 +86,8 @@ class tst_QHostInfo : public QObject
private slots: private slots:
void init(); void init();
void initTestCase(); void initTestCase();
void swapFunction();
void moveOperator();
void getSetCheck(); void getSetCheck();
void staticInformation(); void staticInformation();
void lookupIPv4_data(); void lookupIPv4_data();
@ -129,6 +131,29 @@ private:
#endif #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 // Testing get/set functions
void tst_QHostInfo::getSetCheck() void tst_QHostInfo::getSetCheck()
{ {