aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qmlnetwork/qqmlnetworkinformation
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qmlnetwork/qqmlnetworkinformation')
-rw-r--r--tests/auto/qmlnetwork/qqmlnetworkinformation/CMakeLists.txt39
-rw-r--r--tests/auto/qmlnetwork/qqmlnetworkinformation/data/tst_networkinformation.qml14
-rw-r--r--tests/auto/qmlnetwork/qqmlnetworkinformation/tst_qqmlnetworkinformation.cpp51
3 files changed, 104 insertions, 0 deletions
diff --git a/tests/auto/qmlnetwork/qqmlnetworkinformation/CMakeLists.txt b/tests/auto/qmlnetwork/qqmlnetworkinformation/CMakeLists.txt
new file mode 100644
index 0000000000..a9554a9295
--- /dev/null
+++ b/tests/auto/qmlnetwork/qqmlnetworkinformation/CMakeLists.txt
@@ -0,0 +1,39 @@
+# Copyright (C) 2023 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+if (NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT)
+ cmake_minimum_required(VERSION 3.16)
+ project(tst_qqmlnetworkinformation LANGUAGES C CXX ASM)
+ find_package(Qt6BuildInternals COMPONENTS STANDALONE_TEST)
+endif()
+
+# Collect test data
+file(GLOB_RECURSE test_data_glob
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/data/tst_*)
+list(APPEND test_data ${test_data_glob})
+
+qt_internal_add_test(tst_qqmlnetworkinformation
+ QMLTEST
+ SOURCES
+ tst_qqmlnetworkinformation.cpp
+ LIBRARIES
+ Qt::QmlPrivate
+ Qt::QuickTestUtilsPrivate
+ Qt::Network
+ TESTDATA ${test_data}
+)
+
+if(QT_BUILD_STANDALONE_TESTS)
+ qt_import_qml_plugins(tst_qqmlnetworkinformation)
+endif()
+
+qt_internal_extend_target(tst_qqmlnetworkinformation CONDITION ANDROID OR IOS
+ DEFINES
+ QT_QMLTEST_DATADIR=":/data"
+)
+
+qt_internal_extend_target(tst_qqmlnetworkinformation CONDITION NOT ANDROID AND NOT IOS
+ DEFINES
+ QT_QMLTEST_DATADIR="${CMAKE_CURRENT_SOURCE_DIR}/data"
+)
diff --git a/tests/auto/qmlnetwork/qqmlnetworkinformation/data/tst_networkinformation.qml b/tests/auto/qmlnetwork/qqmlnetworkinformation/data/tst_networkinformation.qml
new file mode 100644
index 0000000000..a429e05320
--- /dev/null
+++ b/tests/auto/qmlnetwork/qqmlnetworkinformation/data/tst_networkinformation.qml
@@ -0,0 +1,14 @@
+// Copyright (C) 2023 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+import QtQml
+import QtNetwork
+
+QtObject {
+ property int local: NetworkInformation.Reachability.Local
+ property int reachability: NetworkInformation.reachability
+ property bool isBehindCaptivePortal: NetworkInformation.isBehindCaptivePortal
+ property int ethernet: NetworkInformation.TransportMedium.Ethernet
+ property int transportMedium: NetworkInformation.transportMedium
+ property bool isMetered: NetworkInformation.isMetered
+}
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"