summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp')
-rw-r--r--tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp b/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp
index bbb6883238..0ea9e0259f 100644
--- a/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp
+++ b/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp
@@ -35,6 +35,7 @@
#include <QComboBox>
#include <QDialogButtonBox>
#include <qinputdialog.h>
+#include <QtWidgets/private/qdialog_p.h>
class tst_QInputDialog : public QObject
{
@@ -52,6 +53,7 @@ private slots:
void getInt();
void getDouble_data();
void getDouble();
+ void taskQTBUG_54693_crashWhenParentIsDeletedWhileDialogIsOpen();
void task255502getDouble();
void getText_data();
void getText();
@@ -311,6 +313,75 @@ void tst_QInputDialog::getDouble()
delete parent;
}
+namespace {
+class SelfDestructParent : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit SelfDestructParent(int delay = 100)
+ : QWidget(Q_NULLPTR)
+ {
+ QTimer::singleShot(delay, this, SLOT(deleteLater()));
+ }
+};
+}
+
+void tst_QInputDialog::taskQTBUG_54693_crashWhenParentIsDeletedWhileDialogIsOpen()
+{
+ // getText
+ {
+ QAutoPointer<SelfDestructParent> dialog(new SelfDestructParent);
+ bool ok = true;
+ const QString result = QInputDialog::getText(dialog.get(), "Title", "Label", QLineEdit::Normal, "Text", &ok);
+ QVERIFY(!dialog);
+ QVERIFY(!ok);
+ QVERIFY(result.isNull());
+ }
+
+ // getMultiLineText
+ {
+ QAutoPointer<SelfDestructParent> dialog(new SelfDestructParent);
+ bool ok = true;
+ const QString result = QInputDialog::getMultiLineText(dialog.get(), "Title", "Label", "Text", &ok);
+ QVERIFY(!dialog);
+ QVERIFY(!ok);
+ QVERIFY(result.isNull());
+ }
+
+ // getItem
+ for (int editable = false; editable <= true; ++editable) {
+ QAutoPointer<SelfDestructParent> dialog(new SelfDestructParent);
+ bool ok = true;
+ const QString result = QInputDialog::getItem(dialog.get(), "Title", "Label",
+ QStringList() << "1" << "2", 1, editable, &ok);
+ QVERIFY(!dialog);
+ QVERIFY(!ok);
+ QCOMPARE(result, QLatin1String("2"));
+ }
+
+ // getInt
+ {
+ const int initial = 7;
+ QAutoPointer<SelfDestructParent> dialog(new SelfDestructParent);
+ bool ok = true;
+ const int result = QInputDialog::getInt(dialog.get(), "Title", "Label", initial, -10, +10, 1, &ok);
+ QVERIFY(!dialog);
+ QVERIFY(!ok);
+ QCOMPARE(result, initial);
+ }
+
+ // getDouble
+ {
+ const double initial = 7;
+ QAutoPointer<SelfDestructParent> dialog(new SelfDestructParent);
+ bool ok = true;
+ const double result = QInputDialog::getDouble(dialog.get(), "Title", "Label", initial, -10, +10, 2, &ok);
+ QVERIFY(!dialog);
+ QVERIFY(!ok);
+ QCOMPARE(result, initial);
+ }
+}
+
void tst_QInputDialog::task255502getDouble()
{
parent = new QWidget;