diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-07-29 15:31:44 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2014-07-30 23:39:24 +0200 |
commit | e2331c6f76bda6d19f3b4cb2b9e3cbbfe0bdc2f6 (patch) | |
tree | 585cd3051a70db5ab214a3637621848ee936c607 /tests | |
parent | 41dae1e33ae9f9eafc2c0dddef04d9c5cabe0e56 (diff) |
QProgressDialog: don't crash when setting the same {bar,button,label} again
The associated test has unearthed that setBar() fails to make the new bar a child
of the progress dialog. This will be fixed in a separate commit.
Task-number: QTBUG-40502
Change-Id: I2d09ebb07ae6395449a4efe38a638df831eebdd7
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp index aadc95e640..4ff158f632 100644 --- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp +++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp @@ -44,8 +44,11 @@ #include <qapplication.h> #include <qdebug.h> +#include <qprogressbar.h> #include <qprogressdialog.h> +#include <qpushbutton.h> #include <qlabel.h> +#include <qpointer.h> #include <qthread.h> class tst_QProgressDialog : public QObject @@ -59,6 +62,7 @@ private Q_SLOTS: void getSetCheck(); void task198202(); void QTBUG_31046(); + void settingCustomWidgets(); }; void tst_QProgressDialog::cleanup() @@ -184,5 +188,51 @@ void tst_QProgressDialog::QTBUG_31046() QCOMPARE(50, dlg.value()); } +void tst_QProgressDialog::settingCustomWidgets() +{ + QPointer<QLabel> l = new QLabel; + QPointer<QPushButton> btn = new QPushButton; + QPointer<QProgressBar> bar = new QProgressBar; + QVERIFY(!l->parent()); + QVERIFY(!btn->parent()); + QVERIFY(!bar->parent()); + + { + QProgressDialog dlg; + + QVERIFY(!dlg.isAncestorOf(l)); + dlg.setLabel(l); + QVERIFY(dlg.isAncestorOf(l)); + QTest::ignoreMessage(QtWarningMsg, "QProgressDialog::setLabel: Attempt to set the same label again"); + dlg.setLabel(l); // setting the same widget again should not crash + QVERIFY(l); // and not delete the (old == new) widget + + QVERIFY(!dlg.isAncestorOf(btn)); + dlg.setCancelButton(btn); + QVERIFY(dlg.isAncestorOf(btn)); + QTest::ignoreMessage(QtWarningMsg, "QProgressDialog::setCancelButton: Attempt to set the same button again"); + dlg.setCancelButton(btn); // setting the same widget again should not crash + QVERIFY(btn); // and not delete the (old == new) widget + + QVERIFY(!dlg.isAncestorOf(bar)); + dlg.setBar(bar); + QEXPECT_FAIL("", "QProgressBar doesn't adopt custom progress bar as children", Continue); + QVERIFY(dlg.isAncestorOf(bar)); + QTest::ignoreMessage(QtWarningMsg, "QProgressDialog::setBar: Attempt to set the same progress bar again"); + dlg.setBar(bar); // setting the same widget again should not crash + QVERIFY(bar); // and not delete the (old == new) widget + } + + QVERIFY(!l); + QVERIFY(!btn); +#if 0 + QEXPECT_FAIL("", "QProgressBar doesn't clean up custom progress bars", Continue); + QVERIFY(!bar); +#else + // make cleanup() pass + delete bar; +#endif +} + QTEST_MAIN(tst_QProgressDialog) #include "tst_qprogressdialog.moc" |