summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/kernel/qnetworkinformation/tst_qnetworkinformation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/network/kernel/qnetworkinformation/tst_qnetworkinformation.cpp')
-rw-r--r--tests/auto/network/kernel/qnetworkinformation/tst_qnetworkinformation.cpp73
1 files changed, 38 insertions, 35 deletions
diff --git a/tests/auto/network/kernel/qnetworkinformation/tst_qnetworkinformation.cpp b/tests/auto/network/kernel/qnetworkinformation/tst_qnetworkinformation.cpp
index b78983ae40..daf81823e8 100644
--- a/tests/auto/network/kernel/qnetworkinformation/tst_qnetworkinformation.cpp
+++ b/tests/auto/network/kernel/qnetworkinformation/tst_qnetworkinformation.cpp
@@ -1,34 +1,10 @@
-/****************************************************************************
-**
-** Copyright (C) 2021 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the test suite 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$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtNetwork/private/qnetworkinformation_p.h>
#include <QtNetwork/qnetworkinformation.h>
#include <QtTest/qtest.h>
+#include <QtTest/qsignalspy.h>
#include <limits>
#include <memory>
@@ -43,6 +19,7 @@ private slots:
void reachability();
void behindCaptivePortal();
void transportMedium();
+ void isMetered();
void cleanupTestCase();
private:
@@ -88,11 +65,18 @@ public:
instance->setTransportMedium(medium);
}
+ static void setNewMetered(bool metered)
+ {
+ Q_ASSERT(instance);
+ instance->setMetered(metered);
+ }
+
static QNetworkInformation::Features featuresSupportedStatic()
{
return { QNetworkInformation::Feature::Reachability
| QNetworkInformation::Feature::CaptivePortal
- | QNetworkInformation::Feature::TransportMedium };
+ | QNetworkInformation::Feature::TransportMedium
+ | QNetworkInformation::Feature::Metered };
}
private:
@@ -126,10 +110,10 @@ void tst_QNetworkInformation::initTestCase()
auto backends = QNetworkInformation::availableBackends();
QVERIFY(backends.size() > prevBackends.size());
QVERIFY(backends.contains(u"mock"));
- QVERIFY(QNetworkInformation::load(u"mock"));
- QVERIFY(QNetworkInformation::load(u"mock"));
- QVERIFY(QNetworkInformation::load(u"mOcK"));
- QVERIFY(!QNetworkInformation::load(u"mocks"));
+ QVERIFY(QNetworkInformation::loadBackendByName(u"mock"));
+ QVERIFY(QNetworkInformation::loadBackendByName(u"mock"));
+ QVERIFY(QNetworkInformation::loadBackendByName(u"mOcK"));
+ QVERIFY(!QNetworkInformation::loadBackendByName(u"mocks"));
}
void tst_QNetworkInformation::cleanupTestCase()
@@ -144,9 +128,10 @@ void tst_QNetworkInformation::supportedFeatures()
{
auto info = QNetworkInformation::instance();
- auto allFeatures = QNetworkInformation::Features(
- QNetworkInformation::Feature::CaptivePortal | QNetworkInformation::Feature::Reachability
- | QNetworkInformation::Feature::TransportMedium);
+ auto allFeatures = QNetworkInformation::Features(QNetworkInformation::Feature::CaptivePortal
+ | QNetworkInformation::Feature::Reachability
+ | QNetworkInformation::Feature::TransportMedium
+ | QNetworkInformation::Feature::Metered);
QCOMPARE(info->supportedFeatures(), allFeatures);
@@ -154,6 +139,7 @@ void tst_QNetworkInformation::supportedFeatures()
QVERIFY(info->supports(QNetworkInformation::Feature::CaptivePortal));
QVERIFY(info->supports(QNetworkInformation::Feature::Reachability));
QVERIFY(info->supports(QNetworkInformation::Feature::TransportMedium));
+ QVERIFY(info->supports(QNetworkInformation::Feature::Metered));
}
void tst_QNetworkInformation::reachability()
@@ -248,5 +234,22 @@ void tst_QNetworkInformation::transportMedium()
QVERIFY(!signalEmitted);
}
+void tst_QNetworkInformation::isMetered()
+{
+ auto info = QNetworkInformation::instance();
+
+ QSignalSpy spy(info, &QNetworkInformation::isMeteredChanged);
+ QVERIFY(!info->isMetered());
+ MockBackend::setNewMetered(true);
+ QCOMPARE(spy.size(), 1);
+ QVERIFY(info->isMetered());
+ QVERIFY(spy[0][0].toBool());
+ spy.clear();
+
+ // Set the same value again, signal should not be emitted again
+ MockBackend::setNewMetered(true);
+ QCOMPARE(spy.size(), 0);
+}
+
QTEST_MAIN(tst_QNetworkInformation);
#include "tst_qnetworkinformation.moc"