diff options
Diffstat (limited to 'tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp')
-rw-r--r-- | tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp | 89 |
1 files changed, 56 insertions, 33 deletions
diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp index 6f527e7b6b..baf727d766 100644 --- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp +++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp @@ -1,33 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 <QtTest/QtTest> +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + + +#include <QTest> #include <qapplication.h> #include <qdebug.h> @@ -51,8 +26,10 @@ private Q_SLOTS: void getSetCheck(); void task198202(); void QTBUG_31046(); + void QTBUG_19983(); void settingCustomWidgets(); void i18n(); + void setValueReentrancyGuard(); }; void tst_QProgressDialog::cleanup() @@ -107,7 +84,7 @@ void tst_QProgressDialog::autoShow() // in order to test for the setValue() behavior instead // See autoShowCtor() for the ctor timer check dlg.setValue(value); - QThread::msleep(delay); + QThread::sleep(std::chrono::milliseconds{delay}); dlg.setValue(min+1); QCOMPARE(dlg.isVisible(), expectedAutoShow); } @@ -116,7 +93,7 @@ void tst_QProgressDialog::autoShowCtor() { QProgressDialog dlg; QVERIFY(!dlg.isVisible()); - QThread::msleep(dlg.minimumDuration()); + QThread::sleep(std::chrono::milliseconds{dlg.minimumDuration()}); QTRY_VERIFY(dlg.isVisible()); } @@ -204,11 +181,34 @@ void tst_QProgressDialog::QTBUG_31046() { QProgressDialog dlg("", "", 50, 60); dlg.setValue(0); - QThread::msleep(200); + QThread::sleep(std::chrono::milliseconds{200}); dlg.setValue(50); QCOMPARE(50, dlg.value()); } +void tst_QProgressDialog::QTBUG_19983() +{ + QProgressDialog tempDlg; + tempDlg.setRange(0, 0); + tempDlg.setLabelText("This is a test."); + + QPushButton *btnOne = new QPushButton("Cancel", &tempDlg); + tempDlg.setCancelButton(btnOne); + tempDlg.show(); + QVERIFY(QTest::qWaitForWindowExposed(&tempDlg)); + const auto btnOneGeometry = btnOne->geometry(); + QVERIFY(QPoint(0,0) != btnOneGeometry.topLeft()); + + tempDlg.cancel(); + QVERIFY(!tempDlg.isVisible()); + + QPushButton *btnTwo = new QPushButton("Cancel", &tempDlg); + tempDlg.setCancelButton(btnTwo); + tempDlg.show(); + QVERIFY(QTest::qWaitForWindowExposed(&tempDlg)); + QCOMPARE(btnOneGeometry, btnTwo->geometry()); +} + void tst_QProgressDialog::settingCustomWidgets() { QPointer<QLabel> l = new QLabel; @@ -291,5 +291,28 @@ void tst_QProgressDialog::i18n() QVERIFY(!btn->text().startsWith(xxx)); } +void tst_QProgressDialog::setValueReentrancyGuard() +{ + // Tests setValue() of window modal QProgressBar with + // Qt::QueuedConnection: + // This test crashes with a stack overflow if the boolean + // guard "processingEvents" that prevents reentranct calls + // to QCoreApplication::processEvents() within setValue() + // has not been implemented + + constexpr int steps = 100; // Should be at least 50 to test for crash + + QProgressDialog dlg("Testing setValue reentrancy guard...", QString(), 0, steps); + dlg.setWindowModality(Qt::WindowModal); + dlg.setMinimumDuration(0); + dlg.setAutoReset(false); + + // Simulate a quick work loop + for (int i = 0; i <= steps; ++i) + QMetaObject::invokeMethod(&dlg, "setValue", Qt::QueuedConnection, Q_ARG(int, i)); + + QTRY_COMPARE(dlg.value(), steps); +} + QTEST_MAIN(tst_QProgressDialog) #include "tst_qprogressdialog.moc" |