diff options
Diffstat (limited to 'tests/auto/printsupport/dialogs')
3 files changed, 45 insertions, 4 deletions
diff --git a/tests/auto/printsupport/dialogs/CMakeLists.txt b/tests/auto/printsupport/dialogs/CMakeLists.txt index 548ddc8577..b9baf14e39 100644 --- a/tests/auto/printsupport/dialogs/CMakeLists.txt +++ b/tests/auto/printsupport/dialogs/CMakeLists.txt @@ -1,3 +1,4 @@ -# Generated from dialogs.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause add_subdirectory(qabstractprintdialog) diff --git a/tests/auto/printsupport/dialogs/qabstractprintdialog/CMakeLists.txt b/tests/auto/printsupport/dialogs/qabstractprintdialog/CMakeLists.txt index 9bc1b3f6b0..64a7792d77 100644 --- a/tests/auto/printsupport/dialogs/qabstractprintdialog/CMakeLists.txt +++ b/tests/auto/printsupport/dialogs/qabstractprintdialog/CMakeLists.txt @@ -1,13 +1,20 @@ -# Generated from qabstractprintdialog.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_qabstractprintdialog Test: ##################################################################### +if(NOT QT_BUILD_STANDALONE_TESTS AND NOT QT_BUILDING_QT) + cmake_minimum_required(VERSION 3.16) + project(tst_qabstractprintdialog LANGUAGES CXX) + find_package(Qt6BuildInternals REQUIRED COMPONENTS STANDALONE_TEST) +endif() + qt_internal_add_test(tst_qabstractprintdialog SOURCES tst_qabstractprintdialog.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Gui Qt::PrintSupport Qt::Widgets diff --git a/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp b/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp index 8dcfab8e64..c3785efe18 100644 --- a/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp +++ b/tests/auto/printsupport/dialogs/qabstractprintdialog/tst_qabstractprintdialog.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QTest> @@ -24,6 +24,8 @@ private slots: void getSetCheck(); void setMinMax(); void setFromTo(); + + void hideNativeByDestruction(); #endif }; @@ -135,6 +137,37 @@ void tst_QAbstractPrintDialog::setFromTo() QCOMPARE(obj1.maxPage(), 50); } +void tst_QAbstractPrintDialog::hideNativeByDestruction() +{ +#ifdef Q_OS_WINDOWS + QSKIP("This test fails on windows, the QPrintDialog::setVisible implementation blocks"); +#endif + + QWidget window; + QWidget *child = new QWidget(&window); + QPointer<QPrintDialog> dialog = new QPrintDialog(child); + // Make it application modal so that we don't end up with a sheet on macOS + dialog->setWindowModality(Qt::ApplicationModal); + window.show(); + QVERIFY(QTest::qWaitForWindowActive(&window)); + dialog->open(); + + // We test that the dialog opens and closes by watching the activation of the + // transient parent window. If it doesn't deactivate, then we have to skip. + const auto windowActive = [&window]{ return window.isActiveWindow(); }; + const auto windowInactive = [&window]{ return !window.isActiveWindow(); }; + if (!QTest::qWaitFor(windowInactive, 2000)) + QSKIP("Dialog didn't activate"); + + // This should destroy the dialog and close the native window + child->deleteLater(); + QTRY_VERIFY(!dialog); + // If the native window is still open, then the transient parent can't become + // active + window.activateWindow(); + QVERIFY(QTest::qWaitFor(windowActive)); +} + #endif QTEST_MAIN(tst_QAbstractPrintDialog) |