summaryrefslogtreecommitdiffstats
path: root/tests/manual
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2020-12-18 15:35:49 +0100
committerMårten Nordheim <marten.nordheim@qt.io>2021-02-02 11:10:06 +0100
commita3b58a7844f77bd416fad8307f8333ff7c0efacf (patch)
tree83cd728441d5404a0088d07aae8f8b719feadeae /tests/manual
parent1e3b0d92807323d9138478a66182dff4eaa86b20 (diff)
NetworkListManager based backend for QNetworkInformation
For Windows. Based on the code I wrote for QNetworkStatusMonitor. It also renames the netlistmgr feature, avoiding the abbreviation. Locally my MinGW fails the networklistmanager feature test so it may not be supported on MinGW, likely leaving it without a backend at all. Change-Id: I13bbe4127edc2a9c0bb91602c95f1cb206a85a69 Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'tests/manual')
-rw-r--r--tests/manual/CMakeLists.txt1
-rw-r--r--tests/manual/qnetworkinformation/CMakeLists.txt8
-rw-r--r--tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp63
3 files changed, 72 insertions, 0 deletions
diff --git a/tests/manual/CMakeLists.txt b/tests/manual/CMakeLists.txt
index 9f48f2832a..f9eb23cd5f 100644
--- a/tests/manual/CMakeLists.txt
+++ b/tests/manual/CMakeLists.txt
@@ -31,6 +31,7 @@ add_subdirectory(qlocale)
add_subdirectory(qmimedatabase)
add_subdirectory(qnetconmonitor)
add_subdirectory(qnetworkaccessmanager/qget)
+add_subdirectory(qnetworkinformation)
#special case begin
if (QT_FEATURE_openssl AND UNIX)
add_subdirectory(qnetworkreply)
diff --git a/tests/manual/qnetworkinformation/CMakeLists.txt b/tests/manual/qnetworkinformation/CMakeLists.txt
new file mode 100644
index 0000000000..964d48c93f
--- /dev/null
+++ b/tests/manual/qnetworkinformation/CMakeLists.txt
@@ -0,0 +1,8 @@
+
+qt_internal_add_manual_test(qnetworkinformation
+ SOURCES
+ tst_qnetworkinformation.cpp
+ PUBLIC_LIBRARIES
+ Qt::Network
+ Qt::Test
+)
diff --git a/tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp b/tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp
new file mode 100644
index 0000000000..6ef337fda9
--- /dev/null
+++ b/tests/manual/qnetworkinformation/tst_qnetworkinformation.cpp
@@ -0,0 +1,63 @@
+/****************************************************************************
+**
+** 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$
+**
+****************************************************************************/
+
+#include <QtCore/qcoreapplication.h>
+#include <QtCore/qmetaobject.h>
+#include <QtNetwork/qnetworkinformation.h>
+
+QByteArray nameOfEnumValue(QNetworkInformation::Reachability reachability)
+{
+ return QMetaEnum::fromType<QNetworkInformation::Reachability>().valueToKey(int(reachability));
+}
+
+int main(int argc, char **argv)
+{
+ QCoreApplication app(argc, argv);
+
+ QTextStream writer(stdout);
+
+ if (!QNetworkInformation::load(QNetworkInformation::Feature::Reachability)) {
+ qWarning("Failed to load any backend");
+ writer << "Backends available: " << QNetworkInformation::availableBackends().join(", ") << '\n';
+ return -1;
+ }
+ QNetworkInformation *info = QNetworkInformation::instance();
+ writer << "Backend loaded: " << info->backendName() << '\n';
+ writer << "Now you can make changes to the current network connection. Qt should see the "
+ "changes and notify about it.\n";
+ QObject::connect(info, &QNetworkInformation::reachabilityChanged,
+ [&writer](QNetworkInformation::Reachability newStatus) {
+ writer << "Updated: " << nameOfEnumValue(newStatus) << '\n';
+ writer.flush();
+ });
+
+ writer << "Initial: " << nameOfEnumValue(info->reachability()) << '\n';
+ writer.flush();
+
+ return app.exec();
+}