diff options
Diffstat (limited to 'tests/auto/widgets/dialogs')
-rw-r--r-- | tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp | 40 | ||||
-rw-r--r-- | tests/auto/widgets/dialogs/qprogressdialog/tst_qprogressdialog.cpp | 113 |
2 files changed, 127 insertions, 26 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index 096658ae02..b9ca831e0c 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -114,8 +114,8 @@ public: virtual ~tst_QFiledialog(); public slots: + void initTestCase(); void init(); - void cleanup(); private slots: void currentChangedSignal(); @@ -171,7 +171,7 @@ private slots: void tildeExpansion(); #endif // QT_BUILD_INTERNAL #endif - void getFileUrl(); + void rejectModalDialogs(); private: QByteArray userSettings; @@ -185,28 +185,25 @@ tst_QFiledialog::~tst_QFiledialog() { } +void tst_QFiledialog::initTestCase() +{ + QStandardPaths::setTestModeEnabled(true); +} + void tst_QFiledialog::init() { - // Save the developers settings so they don't get mad when their sidebar folders are gone. + // clean up the sidebar between each test QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); settings.beginGroup(QLatin1String("Qt")); - userSettings = settings.value(QLatin1String("filedialog")).toByteArray(); settings.remove(QLatin1String("filedialog")); - // populate it with some default settings + // populate the sidebar with some default settings QNonNativeFileDialog fd; #if defined(Q_OS_WINCE) QTest::qWait(1000); #endif } -void tst_QFiledialog::cleanup() -{ - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("Qt")); - settings.setValue(QLatin1String("filedialog"), userSettings); -} - class MyAbstractItemDelegate : public QAbstractItemDelegate { public: @@ -252,7 +249,10 @@ void tst_QFiledialog::directoryEnteredSignal() // sidebar QSidebar *sidebar = fd.findChild<QSidebar*>("sidebar"); - sidebar->setCurrentIndex(sidebar->model()->index(1, 0)); + QVERIFY(sidebar->model()->rowCount() >= 2); + QModelIndex secondItem = sidebar->model()->index(1, 0); + QVERIFY(secondItem.isValid()); + sidebar->setCurrentIndex(secondItem); QTest::keyPress(sidebar->viewport(), Qt::Key_Return); QCOMPARE(spyDirectoryEntered.count(), 1); spyDirectoryEntered.clear(); @@ -1451,7 +1451,7 @@ public slots: } }; -void tst_QFiledialog::getFileUrl() +void tst_QFiledialog::rejectModalDialogs() { // QTBUG-38672 , static functions should return empty Urls const QFileDialog::Options options = QFileDialog::DontUseNativeDialog; @@ -1472,6 +1472,18 @@ void tst_QFiledialog::getFileUrl() QVERIFY(url.isEmpty()); QVERIFY(!url.isValid()); + // Same test with local files + QString file = QFileDialog::getOpenFileName(0, QStringLiteral("getOpenFileName"), + QString(), QString(), Q_NULLPTR, options); + QVERIFY(file.isEmpty()); + + file = QFileDialog::getExistingDirectory(0, QStringLiteral("getExistingDirectory"), + QString(), options | QFileDialog::ShowDirsOnly); + QVERIFY(file.isEmpty()); + + file = QFileDialog::getSaveFileName(0, QStringLiteral("getSaveFileName"), + QString(), QString(), Q_NULLPTR, options); + QVERIFY(file.isEmpty()); } QTEST_MAIN(tst_QFiledialog) 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" |