summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp')
-rw-r--r--tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp113
1 files changed, 101 insertions, 12 deletions
diff --git a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
index 060fa51293..86b9d7eee2 100644
--- a/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
+++ b/tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp
@@ -42,34 +42,34 @@
#include <QtTest/QtTest>
-#include <qcoreapplication.h>
+#include <qapplication.h>
#include <qdebug.h>
+#include <qprogressbar.h>
#include <qprogressdialog.h>
+#include <qpushbutton.h>
#include <qlabel.h>
+#include <qpointer.h>
#include <qthread.h>
+#include <qtranslator.h>
class tst_QProgressDialog : public QObject
{
-Q_OBJECT
+ Q_OBJECT
-public:
- tst_QProgressDialog();
- virtual ~tst_QProgressDialog();
-
-private slots:
+private Q_SLOTS:
+ void cleanup();
void autoShow_data();
void autoShow();
void getSetCheck();
void task198202();
void QTBUG_31046();
+ void settingCustomWidgets();
+ void i18n();
};
-tst_QProgressDialog::tst_QProgressDialog()
-{
-}
-
-tst_QProgressDialog::~tst_QProgressDialog()
+void tst_QProgressDialog::cleanup()
{
+ QVERIFY(QApplication::topLevelWindows().empty());
}
void tst_QProgressDialog::autoShow_data()
@@ -190,5 +190,94 @@ 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
+}
+
+class QTestTranslator : public QTranslator
+{
+ const QString m_str;
+public:
+ explicit QTestTranslator(QString str) : m_str(qMove(str)) {}
+
+ QString translate(const char *, const char *sourceText, const char *, int) const Q_DECL_OVERRIDE
+ { return m_str + sourceText + m_str; }
+
+ bool isEmpty() const Q_DECL_OVERRIDE { return false; }
+};
+
+template <typename Translator>
+class QTranslatorGuard {
+ Translator t;
+public:
+ template <typename Arg>
+ explicit QTranslatorGuard(Arg a) : t(qMove(a))
+ { qApp->installTranslator(&t); }
+ ~QTranslatorGuard()
+ { qApp->removeTranslator(&t); }
+};
+
+void tst_QProgressDialog::i18n()
+{
+ QProgressDialog dlg;
+ QPushButton *btn = dlg.findChild<QPushButton*>();
+ QVERIFY(btn);
+ const QString xxx = QStringLiteral("xxx");
+ {
+ QTranslatorGuard<QTestTranslator> guard(xxx);
+ {
+ QPushButton *btn = dlg.findChild<QPushButton*>();
+ QVERIFY(btn);
+ QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
+ QVERIFY(btn->text().startsWith(xxx));
+ }
+ }
+ QVERIFY(btn);
+ QTRY_COMPARE(btn->text(), QProgressDialog::tr("Cancel"));
+ QVERIFY(!btn->text().startsWith(xxx));
+}
+
QTEST_MAIN(tst_QProgressDialog)
#include "tst_qprogressdialog.moc"