QNI: Add supportedFeatures getter
Which just returns all the supported features Change-Id: I8c3996b00a6ebb114bdbc9db3085a0e27fc8fa79 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
a43dd9a6b1
commit
5f8e9c194e
@ -593,6 +593,16 @@ bool QNetworkInformation::supports(Features features) const
|
|||||||
return (d_func()->backend->featuresSupported() & features) == features;
|
return (d_func()->backend->featuresSupported() & features) == features;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\since 6.3
|
||||||
|
|
||||||
|
Returns all the supported features of the current backend.
|
||||||
|
*/
|
||||||
|
QNetworkInformation::Features QNetworkInformation::supportedFeatures() const
|
||||||
|
{
|
||||||
|
return d_func()->backend->featuresSupported();
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Attempts to load a backend whose name matches \a backend
|
Attempts to load a backend whose name matches \a backend
|
||||||
(case insensitively).
|
(case insensitively).
|
||||||
|
@ -94,6 +94,7 @@ public:
|
|||||||
QString backendName() const;
|
QString backendName() const;
|
||||||
|
|
||||||
bool supports(Features features) const;
|
bool supports(Features features) const;
|
||||||
|
Features supportedFeatures() const;
|
||||||
|
|
||||||
static bool load(QStringView backend);
|
static bool load(QStringView backend);
|
||||||
static bool load(Features features);
|
static bool load(Features features);
|
||||||
|
@ -39,6 +39,7 @@ class tst_QNetworkInformation : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
void initTestCase();
|
void initTestCase();
|
||||||
|
void supportedFeatures();
|
||||||
void reachability();
|
void reachability();
|
||||||
void behindCaptivePortal();
|
void behindCaptivePortal();
|
||||||
void transportMedium();
|
void transportMedium();
|
||||||
@ -89,8 +90,9 @@ public:
|
|||||||
|
|
||||||
static QNetworkInformation::Features featuresSupportedStatic()
|
static QNetworkInformation::Features featuresSupportedStatic()
|
||||||
{
|
{
|
||||||
return { QNetworkInformation::Feature::Reachability,
|
return { QNetworkInformation::Feature::Reachability
|
||||||
QNetworkInformation::Feature::CaptivePortal };
|
| QNetworkInformation::Feature::CaptivePortal
|
||||||
|
| QNetworkInformation::Feature::TransportMedium };
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -138,6 +140,22 @@ void tst_QNetworkInformation::cleanupTestCase()
|
|||||||
QVERIFY(!backends.contains(u"mock"));
|
QVERIFY(!backends.contains(u"mock"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QNetworkInformation::supportedFeatures()
|
||||||
|
{
|
||||||
|
auto info = QNetworkInformation::instance();
|
||||||
|
|
||||||
|
auto allFeatures = QNetworkInformation::Features(
|
||||||
|
QNetworkInformation::Feature::CaptivePortal | QNetworkInformation::Feature::Reachability
|
||||||
|
| QNetworkInformation::Feature::TransportMedium);
|
||||||
|
|
||||||
|
QCOMPARE(info->supportedFeatures(), allFeatures);
|
||||||
|
|
||||||
|
QVERIFY(info->supports(allFeatures));
|
||||||
|
QVERIFY(info->supports(QNetworkInformation::Feature::CaptivePortal));
|
||||||
|
QVERIFY(info->supports(QNetworkInformation::Feature::Reachability));
|
||||||
|
QVERIFY(info->supports(QNetworkInformation::Feature::TransportMedium));
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QNetworkInformation::reachability()
|
void tst_QNetworkInformation::reachability()
|
||||||
{
|
{
|
||||||
auto info = QNetworkInformation::instance();
|
auto info = QNetworkInformation::instance();
|
||||||
|
@ -55,6 +55,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
QNetworkInformation *info = QNetworkInformation::instance();
|
QNetworkInformation *info = QNetworkInformation::instance();
|
||||||
qDebug() << "Backend loaded:" << info->backendName();
|
qDebug() << "Backend loaded:" << info->backendName();
|
||||||
|
qDebug() << "Supports:" << info->supportedFeatures();
|
||||||
qDebug() << "Now you can make changes to the current network connection. Qt should see the "
|
qDebug() << "Now you can make changes to the current network connection. Qt should see the "
|
||||||
"changes and notify about it.";
|
"changes and notify about it.";
|
||||||
QObject::connect(info, &QNetworkInformation::reachabilityChanged,
|
QObject::connect(info, &QNetworkInformation::reachabilityChanged,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user