QDnsLookup - port to the new property system
Read/write/notify properties, 3 out of 5 defined in this class. Task-number: QTBUG-85520 Change-Id: Ic6c74f90a2fa3c71d71cf9a5d557f1b6fc489d35 Reviewed-by: Andreas Buhr <andreas.buhr@qt.io> Reviewed-by: Sona Kurazyan <sona.kurazyan@qt.io>
This commit is contained in:
parent
9b239b7fac
commit
061254ed12
@ -356,10 +356,13 @@ QString QDnsLookup::name() const
|
||||
void QDnsLookup::setName(const QString &name)
|
||||
{
|
||||
Q_D(QDnsLookup);
|
||||
if (name != d->name) {
|
||||
d->name = name;
|
||||
emit nameChanged(name);
|
||||
}
|
||||
d->name = name;
|
||||
}
|
||||
|
||||
QBindable<QString> QDnsLookup::bindableName()
|
||||
{
|
||||
Q_D(QDnsLookup);
|
||||
return &d->name;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -375,10 +378,13 @@ QDnsLookup::Type QDnsLookup::type() const
|
||||
void QDnsLookup::setType(Type type)
|
||||
{
|
||||
Q_D(QDnsLookup);
|
||||
if (type != d->type) {
|
||||
d->type = type;
|
||||
emit typeChanged(type);
|
||||
}
|
||||
d->type = type;
|
||||
}
|
||||
|
||||
QBindable<QDnsLookup::Type> QDnsLookup::bindableType()
|
||||
{
|
||||
Q_D(QDnsLookup);
|
||||
return &d->type;
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -394,10 +400,13 @@ QHostAddress QDnsLookup::nameserver() const
|
||||
void QDnsLookup::setNameserver(const QHostAddress &nameserver)
|
||||
{
|
||||
Q_D(QDnsLookup);
|
||||
if (nameserver != d->nameserver) {
|
||||
d->nameserver = nameserver;
|
||||
emit nameserverChanged(nameserver);
|
||||
}
|
||||
d->nameserver = nameserver;
|
||||
}
|
||||
|
||||
QBindable<QHostAddress> QDnsLookup::bindableNameserver()
|
||||
{
|
||||
Q_D(QDnsLookup);
|
||||
return &d->nameserver;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include <QtCore/qshareddata.h>
|
||||
#include <QtCore/qsharedpointer.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qproperty.h>
|
||||
|
||||
QT_REQUIRE_CONFIG(dnslookup);
|
||||
|
||||
@ -178,9 +179,10 @@ class Q_NETWORK_EXPORT QDnsLookup : public QObject
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(Error error READ error NOTIFY finished)
|
||||
Q_PROPERTY(QString errorString READ errorString NOTIFY finished)
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged)
|
||||
Q_PROPERTY(QHostAddress nameserver READ nameserver WRITE setNameserver NOTIFY nameserverChanged)
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged BINDABLE bindableName)
|
||||
Q_PROPERTY(Type type READ type WRITE setType NOTIFY typeChanged BINDABLE bindableType)
|
||||
Q_PROPERTY(QHostAddress nameserver READ nameserver WRITE setNameserver NOTIFY nameserverChanged
|
||||
BINDABLE bindableNameserver)
|
||||
|
||||
public:
|
||||
enum Error
|
||||
@ -221,12 +223,15 @@ public:
|
||||
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
QBindable<QString> bindableName();
|
||||
|
||||
Type type() const;
|
||||
void setType(QDnsLookup::Type);
|
||||
QBindable<Type> bindableType();
|
||||
|
||||
QHostAddress nameserver() const;
|
||||
void setNameserver(const QHostAddress &nameserver);
|
||||
QBindable<QHostAddress> bindableNameserver();
|
||||
|
||||
QList<QDnsDomainNameRecord> canonicalNameRecords() const;
|
||||
QList<QDnsHostAddressRecord> hostAddressRecords() const;
|
||||
|
@ -103,9 +103,29 @@ public:
|
||||
static const char *msgNoIpV6NameServerAdresses;
|
||||
|
||||
bool isFinished;
|
||||
QString name;
|
||||
QDnsLookup::Type type;
|
||||
QHostAddress nameserver;
|
||||
|
||||
void nameChanged()
|
||||
{
|
||||
emit q_func()->nameChanged(name);
|
||||
}
|
||||
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QString, name,
|
||||
&QDnsLookupPrivate::nameChanged);
|
||||
|
||||
void typeChanged()
|
||||
{
|
||||
emit q_func()->typeChanged(type);
|
||||
}
|
||||
|
||||
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QDnsLookup::Type,
|
||||
type, &QDnsLookupPrivate::typeChanged);
|
||||
|
||||
void nameserverChanged()
|
||||
{
|
||||
emit q_func()->nameserverChanged(nameserver);
|
||||
}
|
||||
Q_OBJECT_BINDABLE_PROPERTY(QDnsLookupPrivate, QHostAddress, nameserver,
|
||||
&QDnsLookupPrivate::nameserverChanged);
|
||||
|
||||
QDnsLookupReply reply;
|
||||
QDnsLookupRunnable *runnable;
|
||||
|
||||
|
@ -29,6 +29,8 @@
|
||||
|
||||
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
|
||||
#include <QtNetwork/QDnsLookup>
|
||||
#include <QtNetwork/QHostAddress>
|
||||
|
||||
@ -49,6 +51,7 @@ private slots:
|
||||
void lookup();
|
||||
void lookupReuse();
|
||||
void lookupAbortRetry();
|
||||
void bindingsAndProperties();
|
||||
};
|
||||
|
||||
void tst_QDnsLookup::initTestCase()
|
||||
@ -375,5 +378,51 @@ void tst_QDnsLookup::lookupAbortRetry()
|
||||
QCOMPARE(lookup.hostAddressRecords().first().value(), QHostAddress("2001:db8::1"));
|
||||
}
|
||||
|
||||
void tst_QDnsLookup::bindingsAndProperties()
|
||||
{
|
||||
QFETCH_GLOBAL(const QString, tld);
|
||||
if (tld == QStringLiteral("idn"))
|
||||
return;
|
||||
|
||||
QDnsLookup lookup;
|
||||
|
||||
lookup.setType(QDnsLookup::A);
|
||||
QProperty<QDnsLookup::Type> dnsTypeProp;
|
||||
lookup.bindableType().setBinding(Qt::makePropertyBinding(dnsTypeProp));
|
||||
const QSignalSpy typeChangeSpy(&lookup, &QDnsLookup::typeChanged);
|
||||
|
||||
dnsTypeProp = QDnsLookup::AAAA;
|
||||
QCOMPARE(typeChangeSpy.count(), 1);
|
||||
QCOMPARE(lookup.type(), QDnsLookup::AAAA);
|
||||
|
||||
dnsTypeProp.setBinding(lookup.bindableType().makeBinding());
|
||||
lookup.setType(QDnsLookup::A);
|
||||
QCOMPARE(dnsTypeProp.value(), QDnsLookup::A);
|
||||
|
||||
QProperty<QString> nameProp;
|
||||
lookup.bindableName().setBinding(Qt::makePropertyBinding(nameProp));
|
||||
const QSignalSpy nameChangeSpy(&lookup, &QDnsLookup::nameChanged);
|
||||
|
||||
nameProp = QStringLiteral("a-plus-aaaa");
|
||||
QCOMPARE(nameChangeSpy.count(), 1);
|
||||
QCOMPARE(lookup.name(), QStringLiteral("a-plus-aaaa"));
|
||||
|
||||
nameProp.setBinding(lookup.bindableName().makeBinding());
|
||||
lookup.setName(QStringLiteral("a-single"));
|
||||
QCOMPARE(nameProp.value(), QStringLiteral("a-single"));
|
||||
|
||||
QProperty<QHostAddress> nameserverProp;
|
||||
lookup.bindableNameserver().setBinding(Qt::makePropertyBinding(nameserverProp));
|
||||
const QSignalSpy nameserverChangeSpy(&lookup, &QDnsLookup::nameserverChanged);
|
||||
|
||||
nameserverProp = QHostAddress::LocalHost;
|
||||
QCOMPARE(nameserverChangeSpy.count(), 1);
|
||||
QCOMPARE(lookup.nameserver(), QHostAddress::LocalHost);
|
||||
|
||||
nameserverProp.setBinding(lookup.bindableNameserver().makeBinding());
|
||||
lookup.setNameserver(QHostAddress::Any);
|
||||
QCOMPARE(nameserverProp.value(), QHostAddress::Any);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDnsLookup)
|
||||
#include "tst_qdnslookup.moc"
|
||||
|
Loading…
Reference in New Issue
Block a user