summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/widgets/dialogs')
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp98
-rw-r--r--tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp39
2 files changed, 73 insertions, 64 deletions
diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
index b4f2a8d009..92200618d6 100644
--- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp
@@ -429,26 +429,18 @@ void tst_QFiledialog::completer_data()
QTest::addColumn<QString>("input");
QTest::addColumn<int>("expected");
- QTest::newRow("r, 10") << "" << "r" << 10;
- QTest::newRow("x, 0") << "" << "x" << 0;
- QTest::newRow("../, -1") << "" << "../" << -1;
+ const QString rootPath = QDir::rootPath();
- QTest::newRow("goto root") << QString() << QDir::rootPath() << -1;
- QTest::newRow("start at root") << QDir::rootPath() << QString() << -1;
+ QTest::newRow("r, 10") << QString() << "r" << 10;
+ QTest::newRow("x, 0") << QString() << "x" << 0;
+ QTest::newRow("../, -1") << QString() << "../" << -1;
- QDir root = QDir::root();
- QStringList list = root.entryList();
- QString folder;
- for (int i = 0; i < list.count(); ++i) {
- if (list[i].at(0) == QChar('.'))
- continue;
- QFileInfo info(QDir::rootPath() + list[i]);
- if (info.isDir()) {
- folder = QDir::rootPath() + list[i];
- break;
- }
- }
+ QTest::newRow("goto root") << QString() << rootPath << -1;
+ QTest::newRow("start at root") << rootPath << QString() << -1;
+ QFileInfoList list = QDir::root().entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
+ QVERIFY(!list.isEmpty());
+ const QString folder = list.first().absoluteFilePath();
QTest::newRow("start at one below root r") << folder << "r" << -1;
QTest::newRow("start at one below root ../") << folder << "../" << -1;
}
@@ -457,27 +449,35 @@ void tst_QFiledialog::completer()
{
typedef QSharedPointer<QTemporaryFile> TemporaryFilePtr;
+#ifdef Q_OS_WIN
+ static const Qt::CaseSensitivity caseSensitivity = Qt::CaseInsensitive;
+#else
+ static const Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive;
+#endif
+
QFETCH(QString, input);
QFETCH(QString, startPath);
QFETCH(int, expected);
- QTemporaryDir tempDir;
- QVERIFY(tempDir.isValid());
-
- const QString tempPath = tempDir.path();
- startPath = startPath.isEmpty() ? tempPath : QDir::cleanPath(startPath);
-
// make temp dir and files
+ QScopedPointer<QTemporaryDir> tempDir;
QList<TemporaryFilePtr> files;
- QT_TRY {
- for (int i = 0; i < 10; ++i) {
- TemporaryFilePtr file(new QTemporaryFile(tempPath + QStringLiteral("/rXXXXXX")));
- QVERIFY(file->open());
- files.append(file);
+
+ if (startPath.isEmpty()) {
+ tempDir.reset(new QTemporaryDir);
+ QVERIFY(tempDir->isValid());
+ startPath = tempDir->path();
+ for (int i = 0; i < 10; ++i) {
+ TemporaryFilePtr file(new QTemporaryFile(startPath + QStringLiteral("/rXXXXXX")));
+ QVERIFY(file->open());
+ files.append(file);
+ }
}
// ### flesh this out more
- QNonNativeFileDialog fd(0,QString("Test it"),startPath);
+ QNonNativeFileDialog fd(0, QLatin1String(QTest::currentTestFunction())
+ + QStringLiteral(" \"") + QLatin1String(QTest::currentDataTag())
+ + QLatin1Char('"'), startPath);
fd.setOptions(QFileDialog::DontUseNativeDialog);
fd.show();
QVERIFY(QTest::qWaitForWindowExposed(&fd));
@@ -509,10 +509,20 @@ void tst_QFiledialog::completer()
QCOMPARE(model->index(fd.directory().path()), model->index(startPath));
if (input.isEmpty()) {
- QModelIndex r = model->index(model->rootPath());
- QVERIFY(model->rowCount(r) > 0);
- QModelIndex idx = model->index(0, 0, r);
- input = idx.data().toString().at(0);
+ // Try to find a suitable directory under root that does not
+ // start with 'C' to avoid issues with completing to "C:" drives on Windows.
+ const QString rootPath = model->rootPath();
+ const QChar rootPathFirstChar = rootPath.at(0).toLower();
+ QModelIndex rootIndex = model->index(rootPath);
+ const int rowCount = model->rowCount(rootIndex);
+ QVERIFY(rowCount > 0);
+ for (int row = 0; row < rowCount && input.isEmpty(); ++row) {
+ const QString name = model->index(row, 0, rootIndex).data().toString();
+ const QChar firstChar = name.at(0);
+ if (firstChar.isLetter() && firstChar.toLower() != rootPathFirstChar)
+ input = firstChar;
+ }
+ QVERIFY2(!input.isEmpty(), "Unable to find a suitable input directory");
}
// press 'keys' for the input
@@ -525,7 +535,7 @@ void tst_QFiledialog::completer()
if (!fullPath.endsWith(QLatin1Char('/')))
fullPath.append(QLatin1Char('/'));
fullPath.append(input);
- if (input.startsWith(QDir::rootPath())) {
+ if (input.startsWith(QDir::rootPath(), caseSensitivity)) {
fullPath = input;
input.clear();
}
@@ -536,29 +546,13 @@ void tst_QFiledialog::completer()
expected = 0;
if (input.startsWith(".."))
input.clear();
- for (int ii = 0; ii < expectedFiles.count(); ++ii) {
-#if defined(Q_OS_WIN)
- if (expectedFiles.at(ii).startsWith(input,Qt::CaseInsensitive))
-#else
- if (expectedFiles.at(ii).startsWith(input))
-#endif
+ foreach (const QString &expectedFile, expectedFiles) {
+ if (expectedFile.startsWith(input, caseSensitivity))
++expected;
}
}
- QTest::qWait(1000);
- if (cModel->rowCount() != expected) {
- for (int i = 0; i < cModel->rowCount(); ++i) {
- QString file = cModel->index(i, 0).data().toString();
- expectedFiles.removeAll(file);
- }
- //qDebug() << expectedFiles;
- }
-
QTRY_COMPARE(cModel->rowCount(), expected);
- } QT_CATCH(...) {
- QT_RETHROW;
- }
}
void tst_QFiledialog::completer_up()
diff --git a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
index d8ca50fac6..92c9ff3375 100644
--- a/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
+++ b/tests/auto/widgets/dialogs/qwizard/tst_qwizard.cpp
@@ -43,6 +43,7 @@
#include <QVBoxLayout>
#include <QWizard>
#include <QTreeWidget>
+#include <QScreen>
Q_DECLARE_METATYPE(QWizard::WizardButton);
@@ -148,6 +149,7 @@ void tst_QWizard::init()
void tst_QWizard::cleanup()
{
+ QVERIFY(QApplication::topLevelWidgets().isEmpty());
}
void tst_QWizard::buttonText()
@@ -975,9 +977,17 @@ void tst_QWizard::setOption_IgnoreSubTitles()
#if defined(Q_OS_WINCE)
QSKIP("Skipped because of limited resources and potential crash. (Task: 166824)");
#endif
+ const QRect availableGeometry = QGuiApplication::primaryScreen()->availableGeometry();
+ const int kPixels = (availableGeometry.width() + 500) / 1000;
+ const int frame = 50 * kPixels;
+ const int size = 400 * kPixels;
QWizard wizard1;
+#ifdef Q_OS_WIN
+ wizard1.setWizardStyle(QWizard::ClassicStyle); // Avoid Vista style focus animations, etc.
+#endif
wizard1.setButtonLayout(QList<QWizard::WizardButton>() << QWizard::CancelButton);
- wizard1.resize(500, 500);
+ wizard1.resize(size, size);
+ wizard1.move(availableGeometry.left() + frame, availableGeometry.top() + frame);
QVERIFY(!wizard1.testOption(QWizard::IgnoreSubTitles));
QWizardPage *page11 = new QWizardPage;
page11->setTitle("Page X");
@@ -990,8 +1000,12 @@ void tst_QWizard::setOption_IgnoreSubTitles()
wizard1.addPage(page12);
QWizard wizard2;
+#ifdef Q_OS_WIN
+ wizard2.setWizardStyle(QWizard::ClassicStyle); // Avoid Vista style focus animations, etc.
+#endif
wizard2.setButtonLayout(QList<QWizard::WizardButton>() << QWizard::CancelButton);
- wizard2.resize(500, 500);
+ wizard2.resize(size, size);
+ wizard2.move(availableGeometry.left() + 2 * frame + size, availableGeometry.top() + frame);
wizard2.setOption(QWizard::IgnoreSubTitles, true);
QWizardPage *page21 = new QWizardPage;
page21->setTitle("Page X");
@@ -1005,6 +1019,7 @@ void tst_QWizard::setOption_IgnoreSubTitles()
wizard1.show();
wizard2.show();
+ QVERIFY(QTest::qWaitForWindowExposed(&wizard2));
// Check that subtitles are shown when they should (i.e.,
// they're set and IgnoreSubTitles is off).
@@ -1019,24 +1034,24 @@ void tst_QWizard::setOption_IgnoreSubTitles()
QImage i12 = grabWidget(&wizard1);
QImage i22 = grabWidget(&wizard2);
- QVERIFY(i12 == i22);
- QVERIFY(i21 == i22);
+ QCOMPARE(i12, i22);
+ QCOMPARE(i21, i22);
wizard1.back();
wizard2.back();
QImage i13 = grabWidget(&wizard1);
QImage i23 = grabWidget(&wizard2);
- QVERIFY(i13 == i11);
- QVERIFY(i23 == i21);
+ QCOMPARE(i13, i11);
+ QCOMPARE(i23, i21);
wizard1.setOption(QWizard::IgnoreSubTitles, true);
wizard2.setOption(QWizard::IgnoreSubTitles, false);
QImage i14 = grabWidget(&wizard1);
QImage i24 = grabWidget(&wizard2);
- QVERIFY(i14 == i21);
- QVERIFY(i24 == i11);
+ QCOMPARE(i14, i21);
+ QCOMPARE(i24, i11);
// Check the impact of subtitles on the rest of the layout, by
// using a subtitle that looks empty (but that isn't). In
@@ -1060,7 +1075,7 @@ void tst_QWizard::setOption_IgnoreSubTitles()
QImage i2 = grabWidget(&wizard1);
if (j == 0 || wizard1.wizardStyle() == QWizard::MacStyle) {
- QVERIFY(i1 == i2);
+ QCOMPARE(i1, i2);
} else {
QVERIFY(i1 != i2);
}
@@ -2411,9 +2426,9 @@ void tst_QWizard::sideWidget()
wizard.setSideWidget(0);
QVERIFY(wizard.sideWidget() == 0);
- QWidget *w1 = new QWidget(&wizard);
- wizard.setSideWidget(w1);
- QVERIFY(wizard.sideWidget() == w1);
+ QScopedPointer<QWidget> w1(new QWidget(&wizard));
+ wizard.setSideWidget(w1.data());
+ QCOMPARE(wizard.sideWidget(), w1.data());
QWidget *w2 = new QWidget(&wizard);
wizard.setSideWidget(w2);
QVERIFY(wizard.sideWidget() == w2);