From d915432c23177a5d7f9ffd0d6899aab13ddc4c2b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 6 May 2014 12:03:33 +0200 Subject: QFileDialog: Return empty QUrl from the static get..FileUrl() functions. Task-number: QTBUG-38672 Change-Id: Idf554cd93d1a79db7c82f3165bd128fb31ead3e5 Reviewed-by: David Faure --- .../dialogs/qfiledialog/tst_qfiledialog.cpp | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'tests/auto/widgets') diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index 047df0d3f2..096658ae02 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -171,6 +171,7 @@ private slots: void tildeExpansion(); #endif // QT_BUILD_INTERNAL #endif + void getFileUrl(); private: QByteArray userSettings; @@ -1429,5 +1430,49 @@ void tst_QFiledialog::tildeExpansion() #endif // QT_BUILD_INTERNAL #endif +class DialogRejecter : public QObject +{ + Q_OBJECT +public: + DialogRejecter() + { + QTimer *timer = new QTimer(this); + timer->setInterval(1000); + connect(timer, &QTimer::timeout, this, &DialogRejecter::rejectFileDialog); + timer->start(); + } + +public slots: + void rejectFileDialog() + { + if (QWidget *w = QApplication::activeModalWidget()) + if (QDialog *d = qobject_cast(w)) + d->reject(); + } +}; + +void tst_QFiledialog::getFileUrl() +{ + // QTBUG-38672 , static functions should return empty Urls + const QFileDialog::Options options = QFileDialog::DontUseNativeDialog; + DialogRejecter dr; + + QUrl url = QFileDialog::getOpenFileUrl(0, QStringLiteral("getOpenFileUrl"), + QUrl(), QString(), Q_NULLPTR, options); + QVERIFY(url.isEmpty()); + QVERIFY(!url.isValid()); + + url = QFileDialog::getExistingDirectoryUrl(0, QStringLiteral("getExistingDirectoryUrl"), + QUrl(), options | QFileDialog::ShowDirsOnly); + QVERIFY(url.isEmpty()); + QVERIFY(!url.isValid()); + + url = QFileDialog::getSaveFileUrl(0, QStringLiteral("getSaveFileUrl"), + QUrl(), QString(), Q_NULLPTR, options); + QVERIFY(url.isEmpty()); + QVERIFY(!url.isValid()); + +} + QTEST_MAIN(tst_QFiledialog) #include "tst_qfiledialog.moc" -- cgit v1.2.3