aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlqt
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-02-11 14:26:23 +0100
committerMarc Mutz <marc.mutz@qt.io>2022-02-12 11:11:59 +0100
commit94c63a7f1236e764fcc8514ab17c993ee1e9aec7 (patch)
treea76309074db21c78fdc61e0681b6ab80bd633d88 /tests/auto/qml/qqmlqt
parent0a28ee11e398ac8947cf6e5699bddc65769e91de (diff)
tst_qqmlqt: reliably call QDesktopServices::unsetUrlHandler()
Use QScopeGuard instead of manual calls, so even a failed test will properly clean up after itself. Pick-to: 6.3 Change-Id: I321f3560557e58b16cd177c623cb78b5b25111a7 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlqt')
-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()