aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qmlnetwork/qqmlnetworkinformation/tst_qqmlnetworkinformation.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qmlnetwork/qqmlnetworkinformation/tst_qqmlnetworkinformation.cpp')
-rw-r--r--tests/auto/qmlnetwork/qqmlnetworkinformation/tst_qqmlnetworkinformation.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qmlnetwork/qqmlnetworkinformation/tst_qqmlnetworkinformation.cpp b/tests/auto/qmlnetwork/qqmlnetworkinformation/tst_qqmlnetworkinformation.cpp
new file mode 100644
index 0000000000..768d751c53
--- /dev/null
+++ b/tests/auto/qmlnetwork/qqmlnetworkinformation/tst_qqmlnetworkinformation.cpp
@@ -0,0 +1,51 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QQmlEngine>
+#include <QQmlComponent>
+#include <QtNetwork/qnetworkinformation.h>
+#include <QtQuickTestUtils/private/qmlutils_p.h>
+
+class tst_qqmlnetworkinformation : public QQmlDataTest
+{
+ Q_OBJECT
+
+public:
+ explicit tst_qqmlnetworkinformation() : QQmlDataTest(QT_QMLTEST_DATADIR) { }
+
+private Q_SLOTS:
+ void networkInformation();
+};
+
+void tst_qqmlnetworkinformation::networkInformation()
+{
+ QNetworkInformation::loadDefaultBackend();
+ QNetworkInformation *networkinfo = QNetworkInformation::instance();
+#if defined(Q_OS_LINUX) || defined(Q_OS_WIN) || defined(Q_OS_ANDROID) || defined(Q_OS_DARWIN)
+ QVERIFY(networkinfo);
+#else
+ QSKIP("Platform does not provide network information");
+#endif
+
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("tst_networkinformation.qml"));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+
+ QCOMPARE(object->property("local").toInt(),
+ static_cast<int>(QNetworkInformation::Reachability::Local));
+ QCOMPARE(object->property("reachability").toInt(),
+ static_cast<int>(networkinfo->reachability()));
+ QCOMPARE(object->property("isBehindCaptivePortal").toBool(),
+ networkinfo->isBehindCaptivePortal());
+ QCOMPARE(object->property("ethernet").toInt(),
+ static_cast<int>(QNetworkInformation::TransportMedium::Ethernet));
+ QCOMPARE(object->property("transportMedium").toInt(),
+ static_cast<int>(networkinfo->transportMedium()));
+ QCOMPARE(object->property("isMetered").toBool(), networkinfo->isMetered());
+}
+
+QTEST_MAIN(tst_qqmlnetworkinformation)
+
+#include "tst_qqmlnetworkinformation.moc"