aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-02-11 14:26:23 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-02-12 13:03:51 +0000
commit670720fca26ddc1a799bb970d3bfea42f38f10bb (patch)
treeb18c1f1dc7e81bd8ec00a3167174377e2c600a9a
parent900f6b14f6585224cc4dc87b5855d68e2727aa1b (diff)
tst_qqmlqt: reliably call QDesktopServices::unsetUrlHandler()
Use QScopeGuard instead of manual calls, so even a failed test will properly clean up after itself. Change-Id: I321f3560557e58b16cd177c623cb78b5b25111a7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 94c63a7f1236e764fcc8514ab17c993ee1e9aec7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/qqmlqt/tst_qqmlqt.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
index 8e4849e2d6..e97ab543d1 100644
--- a/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
+++ b/tests/auto/qml/qqmlqt/tst_qqmlqt.cpp
@@ -637,7 +637,10 @@ void tst_qqmlqt::openUrlExternally()
const QUrl htmlTestFile = testFileUrl("test.html");
QDesktopServices::setUrlHandler("test", &handler, "noteCall");
QDesktopServices::setUrlHandler(htmlTestFile.scheme(), &handler, "noteCall");
-
+ const auto unset = qScopeGuard([&] {
+ QDesktopServices::unsetUrlHandler(htmlTestFile.scheme());
+ QDesktopServices::unsetUrlHandler("test");
+ });
QQmlComponent component(&engine, testFileUrl("openUrlExternally.qml"));
QScopedPointer<QObject> object(component.create());
QVERIFY(object != nullptr);
@@ -648,9 +651,6 @@ void tst_qqmlqt::openUrlExternally()
QCOMPARE(handler.called,2);
QCOMPARE(handler.last, htmlTestFile);
-
- QDesktopServices::unsetUrlHandler("test");
- QDesktopServices::unsetUrlHandler(htmlTestFile.scheme());
}
void tst_qqmlqt::openUrlExternally_pragmaLibrary()
@@ -660,6 +660,10 @@ void tst_qqmlqt::openUrlExternally_pragmaLibrary()
const QUrl htmlTestFile = testFileUrl("test.html");
QDesktopServices::setUrlHandler("test", &handler, "noteCall");
QDesktopServices::setUrlHandler(htmlTestFile.scheme(), &handler, "noteCall");
+ const auto unset = qScopeGuard([&] {
+ QDesktopServices::unsetUrlHandler(htmlTestFile.scheme());
+ QDesktopServices::unsetUrlHandler("test");
+ });
QQmlComponent component(&engine, testFileUrl("openUrlExternally_lib.qml"));
QScopedPointer<QObject> object(component.create());
@@ -671,9 +675,6 @@ void tst_qqmlqt::openUrlExternally_pragmaLibrary()
QCOMPARE(handler.called,2);
QCOMPARE(handler.last, htmlTestFile);
-
- QDesktopServices::unsetUrlHandler("test");
- QDesktopServices::unsetUrlHandler(htmlTestFile.scheme());
}
void tst_qqmlqt::md5()