diff options
author | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-10-15 14:23:50 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-10-15 14:23:50 (GMT) |
commit | bdc951eb87e0b1aa752d3ec750cfd837714bd8b7 (patch) | |
tree | 65f9abe4c72b112118fac79cc6c46bcd379aebf2 /tests | |
parent | 6b08c50f93236fec9ed24eaf36f839315e8dc08e (diff) | |
parent | 2eee73e843ba7b4c6e83bd6bfaa08994520c417d (diff) | |
download | Qt-bdc951eb87e0b1aa752d3ec750cfd837714bd8b7.zip Qt-bdc951eb87e0b1aa752d3ec750cfd837714bd8b7.tar.gz Qt-bdc951eb87e0b1aa752d3ec750cfd837714bd8b7.tar.bz2 |
Merge branch '4.6' of scm.dev.nokia.troll.no:qt/qt-widget-team into 4.6
Diffstat (limited to 'tests')
28 files changed, 1258 insertions, 944 deletions
diff --git a/tests/auto/gestures/tst_gestures.cpp b/tests/auto/gestures/tst_gestures.cpp index 0a6caff..46ed45e 100644 --- a/tests/auto/gestures/tst_gestures.cpp +++ b/tests/auto/gestures/tst_gestures.cpp @@ -474,17 +474,20 @@ void tst_Gestures::finishedWithoutStarted() { GestureWidget widget; widget.grabGesture(CustomGesture::GestureType, Qt::WidgetGesture); + // the gesture will claim it finished, but it was never started. CustomEvent ev; - QTest::ignoreMessage(QtWarningMsg, "QGestureManager::filterEvent: some gestures were finished even though they've never started"); - for (int i = CustomGesture::SerialFinishedThreshold; - i < CustomGesture::SerialFinishedThreshold+1; ++i) { - ev.serial = i; - QApplication::sendEvent(&widget, &ev); - } + ev.serial = CustomGesture::SerialFinishedThreshold; + QApplication::sendEvent(&widget, &ev); - QCOMPARE(widget.gestureEventsReceived, 0); + QCOMPARE(widget.customEventsReceived, 1); + QCOMPARE(widget.gestureEventsReceived, 2); QCOMPARE(widget.gestureOverrideEventsReceived, 0); + QCOMPARE(widget.events.all.size(), 2); + QCOMPARE(widget.events.started.size(), 1); + QCOMPARE(widget.events.updated.size(), 0); + QCOMPARE(widget.events.finished.size(), 1); + QCOMPARE(widget.events.canceled.size(), 0); } void tst_Gestures::unknownGesture() diff --git a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp index 6b580df..ecc0594 100644 --- a/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp +++ b/tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp @@ -137,6 +137,8 @@ void tst_Q3SqlCursor::createTestTables( QSqlDatabase db ) QVERIFY_SQL(q, exec("SET ANSI_DEFAULTS ON")); QVERIFY_SQL(q, exec("SET IMPLICIT_TRANSACTIONS OFF")); } + else if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); // please never ever change this table; otherwise fix all tests ;) if ( tst_Databases::isMSAccess( db ) ) { diff --git a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp index 5893687..68e8ce8 100644 --- a/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp +++ b/tests/auto/q3sqlselectcursor/tst_q3sqlselectcursor.cpp @@ -107,9 +107,15 @@ void tst_Q3SqlSelectCursor::createTestTables( QSqlDatabase db ) if ( !db.isValid() ) return; QSqlQuery q( db ); + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); // please never ever change this table; otherwise fix all tests ;) - QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null," - "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" )); + if (tst_Databases::isMSAccess(db)) + QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null," + "t_char char(40), t_numeric number, primary key (id, t_varchar) )" )); + else + QVERIFY_SQL(q, exec( "create table " + qTableName( "qtest" ) + " ( id int not null, t_varchar varchar(40) not null," + "t_char char(40), t_numeric numeric(6, 3), primary key (id, t_varchar) )" )); } void tst_Q3SqlSelectCursor::dropTestTables( QSqlDatabase db ) diff --git a/tests/auto/qapplication/tst_qapplication.cpp b/tests/auto/qapplication/tst_qapplication.cpp index abcacef..97aa092 100644 --- a/tests/auto/qapplication/tst_qapplication.cpp +++ b/tests/auto/qapplication/tst_qapplication.cpp @@ -1242,6 +1242,10 @@ public slots: } void deleteLaterAndExitLoop() { + // Check that 'p' is not deleted before exec returns, since the call + // to QEventLoop::quit() should stop 'eventLoop' from processing + // any more events (that is, delete later) until we return to the + // _current_ event loop: QEventLoop eventLoop; QPointer<QObject> p(this); QMetaObject::invokeMethod(this, "deleteLater", Qt::QueuedConnection); diff --git a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp index b90873e..b46f88d 100644 --- a/tests/auto/qaudiooutput/tst_qaudiooutput.cpp +++ b/tests/auto/qaudiooutput/tst_qaudiooutput.cpp @@ -156,9 +156,14 @@ void tst_QAudioOutput::pullFile() // Wait until finished... QTestEventLoop::instance().enterLoop(1); QCOMPARE(audio->totalTime(), qint64(692250)); + +#ifdef Q_OS_WINCE + // 4.wav is a little less than 700ms, so notify should fire 4 times on Wince! + QVERIFY(readSignal.count() >= 4); +#else // 4.wav is a little less than 700ms, so notify should fire 6 times! QVERIFY(readSignal.count() >= 6); - +#endif audio->stop(); QTest::qWait(20); // wait 20ms QVERIFY(audio->state() == QAudio::StopState); diff --git a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp index a19f865..8b0335c 100644 --- a/tests/auto/qbuttongroup/tst_qbuttongroup.cpp +++ b/tests/auto/qbuttongroup/tst_qbuttongroup.cpp @@ -128,14 +128,15 @@ void tst_QButtonGroup::cleanup() { } +QT_BEGIN_NAMESPACE +extern bool Q_GUI_EXPORT qt_tab_all_widgets; +QT_END_NAMESPACE + + void tst_QButtonGroup::arrowKeyNavigation() { -#ifdef Q_WS_MAC - QSettings appleSettings(QLatin1String("apple.com")); - QVariant appleValue = appleSettings.value(QLatin1String("AppleKeyboardUIMode"), 0); - if (!(appleValue.toInt() & 0x2)) + if (!qt_tab_all_widgets) QSKIP("This test requires full keyboard control to be enabled.", SkipAll); -#endif QDialog dlg(0); QHBoxLayout layout(&dlg); diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp index dc2ca61..2f9410b 100644 --- a/tests/auto/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp @@ -140,36 +140,6 @@ private slots: void clearLineEdit(); void enableChooseButton(); void hooks(); - void listRoot(); - void heapCorruption(); - void deleteDirAndFiles(); - void filter(); - void showNameFilterDetails(); - void unc(); - void emptyUncPath(); - - void task178897_minimumSize(); - void task180459_lastDirectory_data(); - void task180459_lastDirectory(); - void task227304_proxyOnFileDialog(); - void task227930_correctNavigationKeyboardBehavior(); -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - void task226366_lowerCaseHardDriveWindows(); -#endif - void task233037_selectingDirectory(); - void task235069_hideOnEscape(); - void task236402_dontWatchDeletedDir(); - void task203703_returnProperSeparator(); - void task228844_ensurePreviousSorting(); - void task239706_editableFilterCombo(); - void task218353_relativePaths(); - void task251321_sideBarHiddenEntries(); - void task251341_sideBarRemoveEntries(); - void task254490_selectFileMultipleTimes(); - void task257579_sideBarWithNonCleanUrls(); - void task259105_filtersCornerCases(); - - void QTBUG4419_lineEditSelectAll(); private: QByteArray userSettings; @@ -1345,842 +1315,5 @@ void tst_QFiledialog::hooks() QCOMPARE(QFileDialog::getSaveFileName(), QString("saveName")); } -void tst_QFiledialog::listRoot() -{ -#if defined QT_BUILD_INTERNAL - QFileInfoGatherer::fetchedRoot = false; - QString dir(QDir::currentPath()); - QNonNativeFileDialog fd(0, QString(), dir); - fd.show(); - QCOMPARE(QFileInfoGatherer::fetchedRoot,false); - fd.setDirectory(""); - QTest::qWait(500); - QCOMPARE(QFileInfoGatherer::fetchedRoot,true); -#endif -} - -void tst_QFiledialog::heapCorruption() -{ - QVector<QNonNativeFileDialog*> dialogs; - for (int i=0; i < 10; i++) { - QNonNativeFileDialog *f = new QNonNativeFileDialog(NULL); - dialogs << f; - } - qDeleteAll(dialogs); -} - -struct FriendlyQFileDialog : public QFileDialog -{ - friend class tst_QFileDialog; - Q_DECLARE_PRIVATE(QFileDialog) -}; - - -void tst_QFiledialog::deleteDirAndFiles() -{ -#if defined QT_BUILD_INTERNAL - QString tempPath = QDir::tempPath() + '/' + "QFileDialogTestDir4FullDelete"; - QDir dir; - QVERIFY(dir.mkpath(tempPath + "/foo")); - QVERIFY(dir.mkpath(tempPath + "/foo/B")); - QVERIFY(dir.mkpath(tempPath + "/foo/B")); - QVERIFY(dir.mkpath(tempPath + "/foo/c")); - QVERIFY(dir.mkpath(tempPath + "/bar")); - QFile(tempPath + "/foo/a"); - QTemporaryFile *t; - t = new QTemporaryFile(tempPath + "/foo/aXXXXXX"); - t->setAutoRemove(false); - t->open(); - t->close(); - delete t; - - t = new QTemporaryFile(tempPath + "/foo/B/yXXXXXX"); - t->setAutoRemove(false); - t->open(); - t->close(); - delete t; - FriendlyQFileDialog fd; - fd.setOption(QFileDialog::DontUseNativeDialog); - fd.d_func()->removeDirectory(tempPath); - QFileInfo info(tempPath); - QTest::qWait(2000); - QVERIFY(!info.exists()); -#endif -} - -void tst_QFiledialog::filter() -{ - QNonNativeFileDialog fd; - QAction *hiddenAction = qFindChild<QAction*>(&fd, "qt_show_hidden_action"); - QVERIFY(hiddenAction); - QVERIFY(hiddenAction->isEnabled()); - QVERIFY(!hiddenAction->isChecked()); - QDir::Filters filter = fd.filter(); - filter |= QDir::Hidden; - fd.setFilter(filter); - QVERIFY(hiddenAction->isChecked()); -} - -void tst_QFiledialog::showNameFilterDetails() -{ - QNonNativeFileDialog fd; - QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo"); - QVERIFY(filters); - QVERIFY(fd.isNameFilterDetailsVisible()); - - - QStringList filterChoices; - filterChoices << "Image files (*.png *.xpm *.jpg)" - << "Text files (*.txt)" - << "Any files (*.*)"; - fd.setFilters(filterChoices); - - fd.setNameFilterDetailsVisible(false); - QCOMPARE(filters->itemText(0), QString("Image files")); - QCOMPARE(filters->itemText(1), QString("Text files")); - QCOMPARE(filters->itemText(2), QString("Any files")); - - fd.setNameFilterDetailsVisible(true); - QCOMPARE(filters->itemText(0), filterChoices.at(0)); - QCOMPARE(filters->itemText(1), filterChoices.at(1)); - QCOMPARE(filters->itemText(2), filterChoices.at(2)); -} - -void tst_QFiledialog::unc() -{ -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - // Only test UNC on Windows./ - QString dir("\\\\" + QtNetworkSettings::winServerName() + "\\testsharewritable"); -#else - QString dir(QDir::currentPath()); -#endif - QVERIFY(QFile::exists(dir)); - QNonNativeFileDialog fd(0, QString(), dir); - QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); - QVERIFY(model); - QCOMPARE(model->index(fd.directory().absolutePath()), model->index(dir)); -} - -void tst_QFiledialog::emptyUncPath() -{ - QNonNativeFileDialog fd; - fd.show(); - QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); - QVERIFY(lineEdit); - // press 'keys' for the input - for (int i = 0; i < 3 ; ++i) - QTest::keyPress(lineEdit, Qt::Key_Backslash); - QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); - QVERIFY(model); -} - -void tst_QFiledialog::task178897_minimumSize() -{ - QNonNativeFileDialog fd; - QStringList history = fd.history(); - history << QDir::toNativeSeparators("/verylongdirectory/" - "aaaaaaaaaabbbbbbbbcccccccccccddddddddddddddeeeeeeeeeeeeffffffffffgggtggggggggghhhhhhhhiiiiiijjjk"); - fd.setHistory(history); - fd.show(); - - QSize ms = fd.layout()->minimumSize(); - QVERIFY(ms.width() < 400); -} - -void tst_QFiledialog::task180459_lastDirectory_data() -{ - QTest::addColumn<QString>("path"); - QTest::addColumn<QString>("directory"); - QTest::addColumn<bool>("isEnabled"); - QTest::addColumn<QString>("result"); - - QTest::newRow("path+file") << QDir::homePath() + QDir::separator() + "foo" - << QDir::homePath() << true - << QDir::homePath() + QDir::separator() + "foo" ; - QTest::newRow("no path") << "" - << QDir::tempPath() << false << QString(); - QTest::newRow("file") << "foo" - << QDir::currentPath() << true - << QDir::currentPath() + QDir::separator() + "foo" ; - QTest::newRow("path") << QDir::homePath() - << QDir::homePath() << false << QString(); - QTest::newRow("path not existing") << "/usr/bin/foo/bar/foo/foo.txt" - << QDir::tempPath() << true - << QDir::tempPath() + QDir::separator() + "foo.txt"; - -} - -void tst_QFiledialog::task180459_lastDirectory() -{ - //first visit the temp directory and close the dialog - QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", QDir::tempPath()); - QFileSystemModel *model = qFindChild<QFileSystemModel*>(dlg, "qt_filesystem_model"); - QVERIFY(model); - QCOMPARE(model->index(QDir::tempPath()), model->index(dlg->directory().absolutePath())); - delete dlg; - - QFETCH(QString, path); - QFETCH(QString, directory); - QFETCH(bool, isEnabled); - QFETCH(QString, result); - - dlg = new QNonNativeFileDialog(0, "", path); - model = qFindChild<QFileSystemModel*>(dlg, "qt_filesystem_model"); - QVERIFY(model); - dlg->setAcceptMode(QFileDialog::AcceptSave); - QCOMPARE(model->index(dlg->directory().absolutePath()), model->index(directory)); - - QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(dlg, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Save); - QVERIFY(button); - QCOMPARE(button->isEnabled(), isEnabled); - if (isEnabled) - QCOMPARE(model->index(result), model->index(dlg->selectedFiles().first())); - - delete dlg; -} - - - -class FilterDirModel : public QSortFilterProxyModel -{ - -public: - FilterDirModel(QString root, QObject* parent=0):QSortFilterProxyModel(parent), m_root(root) - {} - ~FilterDirModel() - {}; - -protected: - bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const - { - QModelIndex parentIndex; - parentIndex = source_parent; - - QString path; - path = parentIndex.child(source_row,0).data(Qt::DisplayRole).toString(); - - do { - path = parentIndex.data(Qt::DisplayRole).toString() + "/" + path; - parentIndex = parentIndex.parent(); - } while(parentIndex.isValid()); - - QFileInfo info(path); - if (info.isDir() && (QDir(path) != m_root)) - return false; - return true; - } - - -private: - QDir m_root; - - -}; - -class sortProxy : public QSortFilterProxyModel -{ -public: - sortProxy(QObject *parent) : QSortFilterProxyModel(parent) - { - } -protected: - virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const - { - QFileSystemModel * const model = qobject_cast<QFileSystemModel *>(sourceModel()); - const QFileInfo leftInfo(model->fileInfo(left)); - const QFileInfo rightInfo(model->fileInfo(right)); - - if (leftInfo.isDir() == rightInfo.isDir()) - return(leftInfo.filePath().compare(rightInfo.filePath(),Qt::CaseInsensitive) < 0); - else if (leftInfo.isDir()) - return(false); - else - return(true); - } -}; - -class CrashDialog : public QNonNativeFileDialog -{ - Q_OBJECT - -public: - CrashDialog(QWidget *parent, const QString &caption, const -QString &dir, const QString &filter) - : QNonNativeFileDialog(parent, caption, dir, filter) - { - sortProxy *proxyModel = new sortProxy(this); - setProxyModel(proxyModel); - } -}; - -void tst_QFiledialog::task227304_proxyOnFileDialog() -{ -#if defined QT_BUILD_INTERNAL - QNonNativeFileDialog fd(0, "", QDir::currentPath(), 0); - fd.setProxyModel(new FilterDirModel(QDir::currentPath())); - fd.show(); - QLineEdit *edit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); - QTest::qWait(200); - QTest::keyClick(edit, Qt::Key_T); - QTest::keyClick(edit, Qt::Key_S); - QTest::qWait(200); - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - - CrashDialog *dialog = new CrashDialog(0, QString("crash dialog test"), QDir::homePath(), QString("*") ); - dialog->setFileMode(QFileDialog::ExistingFile); - dialog->show(); - - QListView *list = qFindChild<QListView*>(dialog, "listView"); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - - dialog->close(); - fd.close(); - - QNonNativeFileDialog fd2(0, "I should not crash with a proxy", QDir::tempPath(), 0); - QSortFilterProxyModel *pm = new QSortFilterProxyModel; - fd2.setProxyModel(pm); - fd2.show(); - QSidebar *sidebar = qFindChild<QSidebar*>(&fd2, "sidebar"); - sidebar->setFocus(); - sidebar->selectUrl(QUrl::fromLocalFile(QDir::homePath())); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); - QTest::qWait(250); - //We shouldn't crash -#endif -} - -void tst_QFiledialog::task227930_correctNavigationKeyboardBehavior() -{ - QDir current = QDir::currentPath(); - current.mkdir("test"); - current.cd("test"); - QFile file("test/out.txt"); - QFile file2("test/out2.txt"); - QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); - QVERIFY(file2.open(QIODevice::WriteOnly | QIODevice::Text)); - current.cdUp(); - current.mkdir("test2"); - QNonNativeFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.show(); - QListView *list = qFindChild<QListView*>(&fd, "listView"); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - QTest::mouseClick(list->viewport(), Qt::LeftButton,0); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Backspace); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Down); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - QCOMPARE(fd.isVisible(), true); - QTest::qWait(200); - file.close(); - file2.close(); - file.remove(); - file2.remove(); - current.rmdir("test"); - current.rmdir("test2"); -} - -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) -void tst_QFiledialog::task226366_lowerCaseHardDriveWindows() -{ - QNonNativeFileDialog fd; - fd.setDirectory(QDir::root().path()); - fd.show(); - QLineEdit *edit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); - QToolButton *buttonParent = qFindChild<QToolButton*>(&fd, "toParentButton"); - QTest::qWait(200); - QTest::mouseClick(buttonParent, Qt::LeftButton,0,QPoint(0,0)); - QTest::qWait(2000); - QTest::keyClick(edit, Qt::Key_C); - QTest::qWait(200); - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - QTest::qWait(200); - QCOMPARE(edit->text(), QString("C:")); - QTest::qWait(2000); - //i clear my previous selection in the completer - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - edit->clear(); - QTest::keyClick(edit, (char)(Qt::Key_C | Qt::SHIFT)); - QTest::qWait(200); - QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); - QCOMPARE(edit->text(), QString("C:")); -} -#endif - -void tst_QFiledialog::task233037_selectingDirectory() -{ - QDir current = QDir::currentPath(); - current.mkdir("test"); - QNonNativeFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.setAcceptMode( QFileDialog::AcceptSave); - fd.show(); - QListView *list = qFindChild<QListView*>(&fd, "listView"); - QTest::qWait(3000); // Wait for sort to settle (I need a signal). -#ifdef QT_KEYPAD_NAVIGATION - list->setEditFocus(true); -#endif - QTest::keyClick(list, Qt::Key_Down); - QTest::qWait(100); - QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Save); - QVERIFY(button); - QCOMPARE(button->isEnabled(), true); - current.rmdir("test"); -} - -void tst_QFiledialog::task235069_hideOnEscape() -{ - QDir current = QDir::currentPath(); - QNonNativeFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.setAcceptMode( QFileDialog::AcceptSave); - fd.show(); - QListView *list = qFindChild<QListView*>(&fd, "listView"); - list->setFocus(); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Escape); - QCOMPARE(fd.isVisible(), false); - QNonNativeFileDialog fd2; - fd2.setDirectory(current.absolutePath()); - fd2.setAcceptMode( QFileDialog::AcceptSave); - fd2.show(); - QLineEdit *edit = qFindChild<QLineEdit*>(&fd2, "fileNameEdit"); - QTest::keyClick(edit, Qt::Key_Escape); - QCOMPARE(fd2.isVisible(), false); -} - -void tst_QFiledialog::task236402_dontWatchDeletedDir() -{ -#if defined QT_BUILD_INTERNAL - //THIS TEST SHOULD NOT DISPLAY WARNINGS - QDir current = QDir::currentPath(); - //make sure it is the first on the list - current.mkdir("aaaaaaaaaa"); - FriendlyQFileDialog fd; - fd.setViewMode(QFileDialog::List); - fd.setDirectory(current.absolutePath()); - fd.setAcceptMode( QFileDialog::AcceptSave); - fd.show(); - QListView *list = qFindChild<QListView*>(&fd, "listView"); - list->setFocus(); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Backspace); - QTest::keyClick(list, Qt::Key_Down); - QTest::qWait(200); - fd.d_func()->removeDirectory(current.absolutePath() + "/aaaaaaaaaa/"); - QTest::qWait(1000); -#endif -} - -void tst_QFiledialog::task203703_returnProperSeparator() -{ - QDir current = QDir::currentPath(); - current.mkdir("aaaaaaaaaaaaaaaaaa"); - QNonNativeFileDialog fd; - fd.setDirectory(current.absolutePath()); - fd.setViewMode(QFileDialog::List); - fd.setFileMode(QFileDialog::Directory); - fd.show(); - QTest::qWait(500); - QListView *list = qFindChild<QListView*>(&fd, "listView"); - list->setFocus(); - QTest::qWait(200); - QTest::keyClick(list, Qt::Key_Return); - QTest::qWait(1000); - QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Cancel); - QTest::keyClick(button, Qt::Key_Return); - QTest::qWait(500); - QString result = fd.selectedFiles().first(); - QVERIFY(result.at(result.count() - 1) != '/'); - QVERIFY(!result.contains('\\')); - current.rmdir("aaaaaaaaaaaaaaaaaa"); -} - -void tst_QFiledialog::task228844_ensurePreviousSorting() -{ - QDir current = QDir::currentPath(); - current.mkdir("aaaaaaaaaaaaaaaaaa"); - current.cd("aaaaaaaaaaaaaaaaaa"); - current.mkdir("a"); - current.mkdir("b"); - current.mkdir("c"); - current.mkdir("d"); - current.mkdir("e"); - current.mkdir("f"); - current.mkdir("g"); - QTemporaryFile *tempFile = new QTemporaryFile(current.absolutePath() + "/rXXXXXX"); - tempFile->open(); - current.cdUp(); - - QNonNativeFileDialog fd; - fd.setDirectory(current.absolutePath()); - fd.setViewMode(QFileDialog::Detail); - fd.show(); - QTest::qWait(500); - QTreeView *tree = qFindChild<QTreeView*>(&fd, "treeView"); - tree->header()->setSortIndicator(3,Qt::DescendingOrder); - QTest::qWait(200); - QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); - QPushButton *button = buttonBox->button(QDialogButtonBox::Open); - QTest::mouseClick(button, Qt::LeftButton); - QTest::qWait(500); - - QNonNativeFileDialog fd2; - fd2.setFileMode(QFileDialog::Directory); - fd2.restoreState(fd.saveState()); - current.cd("aaaaaaaaaaaaaaaaaa"); - fd2.setDirectory(current.absolutePath()); - fd2.show(); - QTest::qWait(500); - QTreeView *tree2 = qFindChild<QTreeView*>(&fd2, "treeView"); - tree2->setFocus(); - - QCOMPARE(tree2->rootIndex().data(QFileSystemModel::FilePathRole).toString(),current.absolutePath()); - - QDialogButtonBox *buttonBox2 = qFindChild<QDialogButtonBox*>(&fd2, "buttonBox"); - QPushButton *button2 = buttonBox2->button(QDialogButtonBox::Open); - fd2.selectFile("g"); - QTest::mouseClick(button2, Qt::LeftButton); - QTest::qWait(500); - - QCOMPARE(fd2.selectedFiles().first(), current.absolutePath() + QChar('/') + QLatin1String("g")); - - QNonNativeFileDialog fd3(0, "This is a third file dialog", tempFile->fileName()); - fd3.restoreState(fd.saveState()); - fd3.setFileMode(QFileDialog::Directory); - fd3.show(); - QTest::qWait(500); - QTreeView *tree3 = qFindChild<QTreeView*>(&fd3, "treeView"); - tree3->setFocus(); - - QCOMPARE(tree3->rootIndex().data(QFileSystemModel::FilePathRole).toString(), current.absolutePath()); - - QDialogButtonBox *buttonBox3 = qFindChild<QDialogButtonBox*>(&fd3, "buttonBox"); - QPushButton *button3 = buttonBox3->button(QDialogButtonBox::Open); - QTest::mouseClick(button3, Qt::LeftButton); - QTest::qWait(500); - - QCOMPARE(fd3.selectedFiles().first(), tempFile->fileName()); - - current.cd("aaaaaaaaaaaaaaaaaa"); - current.rmdir("a"); - current.rmdir("b"); - current.rmdir("c"); - current.rmdir("d"); - current.rmdir("e"); - current.rmdir("f"); - current.rmdir("g"); - tempFile->close(); - delete tempFile; - current.cdUp(); - current.rmdir("aaaaaaaaaaaaaaaaaa"); -} - - -void tst_QFiledialog::task239706_editableFilterCombo() -{ - QNonNativeFileDialog d; - d.setNameFilter("*.cpp *.h"); - - d.show(); - QTest::qWait(500); - - QList<QComboBox *> comboList = d.findChildren<QComboBox *>(); - QComboBox *filterCombo = 0; - foreach (QComboBox *combo, comboList) { - if (combo->objectName() == QString("fileTypeCombo")) { - filterCombo = combo; - break; - } - } - Q_ASSERT(filterCombo); - filterCombo->setEditable(true); - QTest::mouseClick(filterCombo, Qt::LeftButton); - QTest::keyPress(filterCombo, Qt::Key_X); - QTest::keyPress(filterCombo, Qt::Key_Enter); // should not trigger assertion failure -} - -void tst_QFiledialog::task218353_relativePaths() -{ - QDir appDir = QDir::current(); - QVERIFY(appDir.cdUp() != false); - QNonNativeFileDialog d(0, "TestDialog", ".."); - QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); - - d.setDirectory(appDir.absolutePath() + QLatin1String("/non-existing-directory/../another-non-existing-dir/../")); - QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); - - QDir::current().mkdir("test"); - appDir = QDir::current(); - d.setDirectory(appDir.absolutePath() + QLatin1String("/test/../test/../")); - QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); - appDir.rmdir("test"); -} - -void tst_QFiledialog::task251321_sideBarHiddenEntries() -{ -#if defined QT_BUILD_INTERNAL - QNonNativeFileDialog fd; - - QDir current = QDir::currentPath(); - current.mkdir(".hidden"); - QDir hiddenDir = QDir(".hidden"); - hiddenDir.mkdir("subdir"); - QDir hiddenSubDir = QDir(".hidden/subdir"); - hiddenSubDir.mkdir("happy"); - hiddenSubDir.mkdir("happy2"); - - QList<QUrl> urls; - urls << QUrl::fromLocalFile(hiddenSubDir.absolutePath()); - fd.setSidebarUrls(urls); - fd.show(); - QTest::qWait(250); - - QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); - sidebar->setFocus(); - sidebar->selectUrl(QUrl::fromLocalFile(hiddenSubDir.absolutePath())); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); - QTest::qWait(250); - - QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); - QCOMPARE(model->rowCount(model->index(hiddenSubDir.absolutePath())), 2); - - hiddenSubDir.rmdir("happy2"); - hiddenSubDir.rmdir("happy"); - hiddenDir.rmdir("subdir"); - current.rmdir(".hidden"); -#endif -} - -#if defined QT_BUILD_INTERNAL -class MyQSideBar : public QSidebar -{ -public : - MyQSideBar(QWidget *parent = 0) : QSidebar(parent) - {} - - void removeSelection() { - QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); - QList<QPersistentModelIndex> indexes; - for (int i = 0; i < idxs.count(); i++) - indexes.append(idxs.at(i)); - - for (int i = 0; i < indexes.count(); ++i) - if (!indexes.at(i).data(Qt::UserRole + 1).toUrl().path().isEmpty()) - model()->removeRow(indexes.at(i).row()); - } -}; -#endif - -void tst_QFiledialog::task251341_sideBarRemoveEntries() -{ -#if defined QT_BUILD_INTERNAL - QNonNativeFileDialog fd; - - QDir current = QDir::currentPath(); - current.mkdir("testDir"); - QDir testSubDir = QDir("testDir"); - - QList<QUrl> urls; - urls << QUrl::fromLocalFile(testSubDir.absolutePath()); - urls << QUrl::fromLocalFile("NotFound"); - fd.setSidebarUrls(urls); - fd.show(); - QTest::qWait(250); - - QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); - sidebar->setFocus(); - //We enter in the first bookmark - sidebar->selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); - QTest::qWait(250); - - QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); - //There is no file - QCOMPARE(model->rowCount(model->index(testSubDir.absolutePath())), 0); - //Icon is not enabled QUrlModel::EnabledRole - QVariant value = sidebar->model()->index(0, 0).data(Qt::UserRole + 2); - QCOMPARE(qvariant_cast<bool>(value), true); - - sidebar->setFocus(); - //We enter in the second bookmark which is invalid - sidebar->selectUrl(QUrl::fromLocalFile("NotFound")); - QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); - QTest::qWait(250); - - //We fallback to root because the entry in the bookmark is invalid - QCOMPARE(model->rowCount(model->index("NotFound")), model->rowCount(model->index(model->rootPath()))); - //Icon is not enabled QUrlModel::EnabledRole - value = sidebar->model()->index(1, 0).data(Qt::UserRole + 2); - QCOMPARE(qvariant_cast<bool>(value), false); - - MyQSideBar mySideBar; - mySideBar.init(model, urls); - mySideBar.show(); - mySideBar.selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); - QTest::qWait(1000); - mySideBar.removeSelection(); - - //We remove the first entry - QList<QUrl> expected; - expected << QUrl::fromLocalFile("NotFound"); - QCOMPARE(mySideBar.urls(), expected); - - mySideBar.selectUrl(QUrl::fromLocalFile("NotFound")); - mySideBar.removeSelection(); - - //We remove the second entry - expected.clear(); - QCOMPARE(mySideBar.urls(), expected); - - current.rmdir("testDir"); -#endif -} - -void tst_QFiledialog::task254490_selectFileMultipleTimes() -{ - QString tempPath = QDir::tempPath(); - QTemporaryFile *t; - t = new QTemporaryFile; - t->open(); - QNonNativeFileDialog fd(0, "TestFileDialog"); - - fd.setDirectory(tempPath); - fd.setViewMode(QFileDialog::List); - fd.setAcceptMode(QFileDialog::AcceptSave); - fd.setFileMode(QFileDialog::AnyFile); - - //This should select the file in the QFileDialog - fd.selectFile(t->fileName()); - - //This should clear the selection and write it into the filename line edit - fd.selectFile("new_file.txt"); - - fd.show(); - QTest::qWait(250); - - QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); - QVERIFY(lineEdit); - QCOMPARE(lineEdit->text(),QLatin1String("new_file.txt")); - QListView *list = qFindChild<QListView*>(&fd, "listView"); - QVERIFY(list); - QCOMPARE(list->selectionModel()->selectedRows(0).count(), 0); - - t->deleteLater(); -} - -void tst_QFiledialog::task257579_sideBarWithNonCleanUrls() -{ -#if defined QT_BUILD_INTERNAL - QDir tempDir = QDir::temp(); - QLatin1String dirname("autotest_task257579"); - tempDir.rmdir(dirname); //makes sure it doesn't exist any more - QVERIFY(tempDir.mkdir(dirname)); - QString url = QString::fromLatin1("%1/%2/..").arg(tempDir.absolutePath()).arg(dirname); - QNonNativeFileDialog fd; - fd.setSidebarUrls(QList<QUrl>() << QUrl::fromLocalFile(url)); - QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); - QCOMPARE(sidebar->urls().count(), 1); - QVERIFY(sidebar->urls().first().toLocalFile() != url); - QCOMPARE(sidebar->urls().first().toLocalFile(), QDir::cleanPath(url)); - -#ifdef Q_OS_WIN - QCOMPARE(sidebar->model()->index(0,0).data().toString().toLower(), tempDir.dirName().toLower()); -#else - QCOMPARE(sidebar->model()->index(0,0).data().toString(), tempDir.dirName()); -#endif - - //all tests are finished, we can remove the temporary dir - QVERIFY(tempDir.rmdir(dirname)); -#endif -} - -void tst_QFiledialog::task259105_filtersCornerCases() -{ - QNonNativeFileDialog fd(0, "TestFileDialog"); - fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)")); - fd.setOption(QFileDialog::HideNameFilterDetails, true); - fd.show(); - QTest::qWait(250); - - //Extensions are hidden - QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo"); - QVERIFY(filters); - QCOMPARE(filters->currentText(), QLatin1String("All Files!")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files")); - - //We should have the full names - fd.setOption(QFileDialog::HideNameFilterDetails, false); - QTest::qWait(250); - filters->setCurrentIndex(0); - QCOMPARE(filters->currentText(), QLatin1String("All Files! (*)")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); - - //Corner case undocumented of the task - fd.setNameFilter(QLatin1String("\352 (I like cheese) All Files! (*);;Text Files (*.txt)")); - QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files! (*)")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); - - fd.setOption(QFileDialog::HideNameFilterDetails, true); - filters->setCurrentIndex(0); - QTest::qWait(500); - QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files")); - - fd.setOption(QFileDialog::HideNameFilterDetails, true); - filters->setCurrentIndex(0); - QTest::qWait(500); - QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); - filters->setCurrentIndex(1); - QCOMPARE(filters->currentText(), QLatin1String("Text Files")); -} - -void tst_QFiledialog::QTBUG4419_lineEditSelectAll() -{ - QString tempPath = QDir::tempPath(); - QTemporaryFile *t; - t = new QTemporaryFile; - t->open(); - QNonNativeFileDialog fd(0, "TestFileDialog", t->fileName()); - - fd.setDirectory(tempPath); - fd.setViewMode(QFileDialog::List); - fd.setAcceptMode(QFileDialog::AcceptSave); - fd.setFileMode(QFileDialog::AnyFile); - - fd.show(); - QApplication::setActiveWindow(&fd); - QTest::qWaitForWindowShown(&fd); - QTRY_COMPARE(fd.isVisible(), true); - QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&fd)); - - QTest::qWait(250); - QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); - - QCOMPARE(tempPath + QChar('/') + lineEdit->text(), t->fileName()); - QCOMPARE(tempPath + QChar('/') + lineEdit->selectedText(), t->fileName()); -} - QTEST_MAIN(tst_QFiledialog) #include "tst_qfiledialog.moc" diff --git a/tests/auto/qfiledialog2/qfiledialog2.pro b/tests/auto/qfiledialog2/qfiledialog2.pro new file mode 100644 index 0000000..4ebf977 --- /dev/null +++ b/tests/auto/qfiledialog2/qfiledialog2.pro @@ -0,0 +1,27 @@ +############################################################ +# Project file for autotest for file qfiledialog.h +############################################################ + +load(qttest_p4) + +SOURCES += tst_qfiledialog2.cpp + +wince*|symbian { + addFiles.sources = *.cpp + addFiles.path = . + filesInDir.sources = *.pro + filesInDir.path = someDir + DEPLOYMENT += addFiles filesInDir +} + +symbian:TARGET.EPOCHEAPSIZE="0x100 0x1000000" +symbian:HEADERS += ../../../include/qtgui/private/qfileinfogatherer_p.h + +wince* { + DEFINES += SRCDIR=\\\"./\\\" +} else:symbian { + TARGET.UID3 = 0xE0340003 + DEFINES += SYMBIAN_SRCDIR_UID=$$lower($$replace(TARGET.UID3,"0x","")) +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} diff --git a/tests/auto/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp new file mode 100644 index 0000000..18f94a9 --- /dev/null +++ b/tests/auto/qfiledialog2/tst_qfiledialog2.cpp @@ -0,0 +1,1006 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> + +#include <qcoreapplication.h> +#include <qdebug.h> +#include <qfiledialog.h> +#include <qabstractitemdelegate.h> +#include <qdirmodel.h> +#include <qitemdelegate.h> +#include <qlistview.h> +#include <qcombobox.h> +#include <qpushbutton.h> +#include <qtoolbutton.h> +#include <qtreeview.h> +#include <qheaderview.h> +#include <qcompleter.h> +#include <qaction.h> +#include <qdialogbuttonbox.h> +#include <qsortfilterproxymodel.h> +#include <qlineedit.h> +#include <qlayout.h> +#include "../../shared/util.h" +#include "../../../src/gui/dialogs/qsidebar_p.h" +#include "../../../src/gui/dialogs/qfilesystemmodel_p.h" +#include "../../../src/gui/dialogs/qfiledialog_p.h" + +#include "../network-settings.h" + +//TESTED_CLASS= +//TESTED_FILES= + +#if defined(Q_OS_SYMBIAN) +# define STRINGIFY(x) #x +# define TOSTRING(x) STRINGIFY(x) +# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/" +#endif + +class QNonNativeFileDialog : public QFileDialog +{ + Q_OBJECT +public: + QNonNativeFileDialog(QWidget *parent = 0, const QString &caption = QString(), const QString &directory = QString(), const QString &filter = QString()) + : QFileDialog(parent, caption, directory, filter) + { + setOption(QFileDialog::DontUseNativeDialog, true); + } +}; + +class tst_QFiledialog : public QObject +{ +Q_OBJECT + +public: + tst_QFiledialog(); + virtual ~tst_QFiledialog(); + +public slots: + void init(); + void cleanup(); + +private slots: + void listRoot(); + void heapCorruption(); + void deleteDirAndFiles(); + void filter(); + void showNameFilterDetails(); + void unc(); + void emptyUncPath(); + + void task178897_minimumSize(); + void task180459_lastDirectory_data(); + void task180459_lastDirectory(); + void task227304_proxyOnFileDialog(); + void task227930_correctNavigationKeyboardBehavior(); +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + void task226366_lowerCaseHardDriveWindows(); +#endif + void task233037_selectingDirectory(); + void task235069_hideOnEscape(); + void task236402_dontWatchDeletedDir(); + void task203703_returnProperSeparator(); + void task228844_ensurePreviousSorting(); + void task239706_editableFilterCombo(); + void task218353_relativePaths(); + void task251321_sideBarHiddenEntries(); + void task251341_sideBarRemoveEntries(); + void task254490_selectFileMultipleTimes(); + void task257579_sideBarWithNonCleanUrls(); + void task259105_filtersCornerCases(); + + void QTBUG4419_lineEditSelectAll(); + +private: + QByteArray userSettings; +}; + +tst_QFiledialog::tst_QFiledialog() +{ +} + +tst_QFiledialog::~tst_QFiledialog() +{ +} + +void tst_QFiledialog::init() +{ + // Save the developers settings so they don't get mad when their sidebar folders are gone. + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("Qt")); + userSettings = settings.value(QLatin1String("filedialog")).toByteArray(); + settings.remove(QLatin1String("filedialog")); + + // populate it with some default settings + QNonNativeFileDialog fd; +#if defined(Q_OS_WINCE) + QTest::qWait(1000); +#endif +} + +void tst_QFiledialog::cleanup() +{ + QSettings settings(QSettings::UserScope, QLatin1String("Trolltech")); + settings.beginGroup(QLatin1String("Qt")); + settings.setValue(QLatin1String("filedialog"), userSettings); +} + +void tst_QFiledialog::listRoot() +{ +#if defined QT_BUILD_INTERNAL + QFileInfoGatherer::fetchedRoot = false; + QString dir(QDir::currentPath()); + QNonNativeFileDialog fd(0, QString(), dir); + fd.show(); + QCOMPARE(QFileInfoGatherer::fetchedRoot,false); + fd.setDirectory(""); + QTest::qWait(500); + QCOMPARE(QFileInfoGatherer::fetchedRoot,true); +#endif +} + +void tst_QFiledialog::heapCorruption() +{ + QVector<QNonNativeFileDialog*> dialogs; + for (int i=0; i < 10; i++) { + QNonNativeFileDialog *f = new QNonNativeFileDialog(NULL); + dialogs << f; + } + qDeleteAll(dialogs); +} + +struct FriendlyQFileDialog : public QFileDialog +{ + friend class tst_QFileDialog; + Q_DECLARE_PRIVATE(QFileDialog) +}; + + +void tst_QFiledialog::deleteDirAndFiles() +{ +#if defined QT_BUILD_INTERNAL + QString tempPath = QDir::tempPath() + '/' + "QFileDialogTestDir4FullDelete"; + QDir dir; + QVERIFY(dir.mkpath(tempPath + "/foo")); + QVERIFY(dir.mkpath(tempPath + "/foo/B")); + QVERIFY(dir.mkpath(tempPath + "/foo/B")); + QVERIFY(dir.mkpath(tempPath + "/foo/c")); + QVERIFY(dir.mkpath(tempPath + "/bar")); + QFile(tempPath + "/foo/a"); + QTemporaryFile *t; + t = new QTemporaryFile(tempPath + "/foo/aXXXXXX"); + t->setAutoRemove(false); + t->open(); + t->close(); + delete t; + + t = new QTemporaryFile(tempPath + "/foo/B/yXXXXXX"); + t->setAutoRemove(false); + t->open(); + t->close(); + delete t; + FriendlyQFileDialog fd; + fd.setOption(QFileDialog::DontUseNativeDialog); + fd.d_func()->removeDirectory(tempPath); + QFileInfo info(tempPath); + QTest::qWait(2000); + QVERIFY(!info.exists()); +#endif +} + +void tst_QFiledialog::filter() +{ + QNonNativeFileDialog fd; + QAction *hiddenAction = qFindChild<QAction*>(&fd, "qt_show_hidden_action"); + QVERIFY(hiddenAction); + QVERIFY(hiddenAction->isEnabled()); + QVERIFY(!hiddenAction->isChecked()); + QDir::Filters filter = fd.filter(); + filter |= QDir::Hidden; + fd.setFilter(filter); + QVERIFY(hiddenAction->isChecked()); +} + +void tst_QFiledialog::showNameFilterDetails() +{ + QNonNativeFileDialog fd; + QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo"); + QVERIFY(filters); + QVERIFY(fd.isNameFilterDetailsVisible()); + + + QStringList filterChoices; + filterChoices << "Image files (*.png *.xpm *.jpg)" + << "Text files (*.txt)" + << "Any files (*.*)"; + fd.setFilters(filterChoices); + + fd.setNameFilterDetailsVisible(false); + QCOMPARE(filters->itemText(0), QString("Image files")); + QCOMPARE(filters->itemText(1), QString("Text files")); + QCOMPARE(filters->itemText(2), QString("Any files")); + + fd.setNameFilterDetailsVisible(true); + QCOMPARE(filters->itemText(0), filterChoices.at(0)); + QCOMPARE(filters->itemText(1), filterChoices.at(1)); + QCOMPARE(filters->itemText(2), filterChoices.at(2)); +} + +void tst_QFiledialog::unc() +{ +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) + // Only test UNC on Windows./ + QString dir("\\\\" + QtNetworkSettings::winServerName() + "\\testsharewritable"); +#else + QString dir(QDir::currentPath()); +#endif + QVERIFY(QFile::exists(dir)); + QNonNativeFileDialog fd(0, QString(), dir); + QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); + QVERIFY(model); + QCOMPARE(model->index(fd.directory().absolutePath()), model->index(dir)); +} + +void tst_QFiledialog::emptyUncPath() +{ + QNonNativeFileDialog fd; + fd.show(); + QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); + QVERIFY(lineEdit); + // press 'keys' for the input + for (int i = 0; i < 3 ; ++i) + QTest::keyPress(lineEdit, Qt::Key_Backslash); + QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); + QVERIFY(model); +} + +void tst_QFiledialog::task178897_minimumSize() +{ + QNonNativeFileDialog fd; + QStringList history = fd.history(); + history << QDir::toNativeSeparators("/verylongdirectory/" + "aaaaaaaaaabbbbbbbbcccccccccccddddddddddddddeeeeeeeeeeeeffffffffffgggtggggggggghhhhhhhhiiiiiijjjk"); + fd.setHistory(history); + fd.show(); + + QSize ms = fd.layout()->minimumSize(); + QVERIFY(ms.width() < 400); +} + +void tst_QFiledialog::task180459_lastDirectory_data() +{ + QTest::addColumn<QString>("path"); + QTest::addColumn<QString>("directory"); + QTest::addColumn<bool>("isEnabled"); + QTest::addColumn<QString>("result"); + + QTest::newRow("path+file") << QDir::homePath() + QDir::separator() + "foo" + << QDir::homePath() << true + << QDir::homePath() + QDir::separator() + "foo" ; + QTest::newRow("no path") << "" + << QDir::tempPath() << false << QString(); + QTest::newRow("file") << "foo" + << QDir::currentPath() << true + << QDir::currentPath() + QDir::separator() + "foo" ; + QTest::newRow("path") << QDir::homePath() + << QDir::homePath() << false << QString(); + QTest::newRow("path not existing") << "/usr/bin/foo/bar/foo/foo.txt" + << QDir::tempPath() << true + << QDir::tempPath() + QDir::separator() + "foo.txt"; + +} + +void tst_QFiledialog::task180459_lastDirectory() +{ + //first visit the temp directory and close the dialog + QNonNativeFileDialog *dlg = new QNonNativeFileDialog(0, "", QDir::tempPath()); + QFileSystemModel *model = qFindChild<QFileSystemModel*>(dlg, "qt_filesystem_model"); + QVERIFY(model); + QCOMPARE(model->index(QDir::tempPath()), model->index(dlg->directory().absolutePath())); + delete dlg; + + QFETCH(QString, path); + QFETCH(QString, directory); + QFETCH(bool, isEnabled); + QFETCH(QString, result); + + dlg = new QNonNativeFileDialog(0, "", path); + model = qFindChild<QFileSystemModel*>(dlg, "qt_filesystem_model"); + QVERIFY(model); + dlg->setAcceptMode(QFileDialog::AcceptSave); + QCOMPARE(model->index(dlg->directory().absolutePath()), model->index(directory)); + + QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(dlg, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Save); + QVERIFY(button); + QCOMPARE(button->isEnabled(), isEnabled); + if (isEnabled) + QCOMPARE(model->index(result), model->index(dlg->selectedFiles().first())); + + delete dlg; +} + + + +class FilterDirModel : public QSortFilterProxyModel +{ + +public: + FilterDirModel(QString root, QObject* parent=0):QSortFilterProxyModel(parent), m_root(root) + {} + ~FilterDirModel() + {}; + +protected: + bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const + { + QModelIndex parentIndex; + parentIndex = source_parent; + + QString path; + path = parentIndex.child(source_row,0).data(Qt::DisplayRole).toString(); + + do { + path = parentIndex.data(Qt::DisplayRole).toString() + "/" + path; + parentIndex = parentIndex.parent(); + } while(parentIndex.isValid()); + + QFileInfo info(path); + if (info.isDir() && (QDir(path) != m_root)) + return false; + return true; + } + + +private: + QDir m_root; + + +}; + +class sortProxy : public QSortFilterProxyModel +{ +public: + sortProxy(QObject *parent) : QSortFilterProxyModel(parent) + { + } +protected: + virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const + { + QFileSystemModel * const model = qobject_cast<QFileSystemModel *>(sourceModel()); + const QFileInfo leftInfo(model->fileInfo(left)); + const QFileInfo rightInfo(model->fileInfo(right)); + + if (leftInfo.isDir() == rightInfo.isDir()) + return(leftInfo.filePath().compare(rightInfo.filePath(),Qt::CaseInsensitive) < 0); + else if (leftInfo.isDir()) + return(false); + else + return(true); + } +}; + +class CrashDialog : public QNonNativeFileDialog +{ + Q_OBJECT + +public: + CrashDialog(QWidget *parent, const QString &caption, const +QString &dir, const QString &filter) + : QNonNativeFileDialog(parent, caption, dir, filter) + { + sortProxy *proxyModel = new sortProxy(this); + setProxyModel(proxyModel); + } +}; + +void tst_QFiledialog::task227304_proxyOnFileDialog() +{ +#if defined QT_BUILD_INTERNAL + QNonNativeFileDialog fd(0, "", QDir::currentPath(), 0); + fd.setProxyModel(new FilterDirModel(QDir::currentPath())); + fd.show(); + QLineEdit *edit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); + QTest::qWait(200); + QTest::keyClick(edit, Qt::Key_T); + QTest::keyClick(edit, Qt::Key_S); + QTest::qWait(200); + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + + CrashDialog *dialog = new CrashDialog(0, QString("crash dialog test"), QDir::homePath(), QString("*") ); + dialog->setFileMode(QFileDialog::ExistingFile); + dialog->show(); + + QListView *list = qFindChild<QListView*>(dialog, "listView"); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + + dialog->close(); + fd.close(); + + QNonNativeFileDialog fd2(0, "I should not crash with a proxy", QDir::tempPath(), 0); + QSortFilterProxyModel *pm = new QSortFilterProxyModel; + fd2.setProxyModel(pm); + fd2.show(); + QSidebar *sidebar = qFindChild<QSidebar*>(&fd2, "sidebar"); + sidebar->setFocus(); + sidebar->selectUrl(QUrl::fromLocalFile(QDir::homePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); + QTest::qWait(250); + //We shouldn't crash +#endif +} + +void tst_QFiledialog::task227930_correctNavigationKeyboardBehavior() +{ + QDir current = QDir::currentPath(); + current.mkdir("test"); + current.cd("test"); + QFile file("test/out.txt"); + QFile file2("test/out2.txt"); + QVERIFY(file.open(QIODevice::WriteOnly | QIODevice::Text)); + QVERIFY(file2.open(QIODevice::WriteOnly | QIODevice::Text)); + current.cdUp(); + current.mkdir("test2"); + QNonNativeFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.show(); + QListView *list = qFindChild<QListView*>(&fd, "listView"); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + QTest::mouseClick(list->viewport(), Qt::LeftButton,0); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Backspace); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Down); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + QCOMPARE(fd.isVisible(), true); + QTest::qWait(200); + file.close(); + file2.close(); + file.remove(); + file2.remove(); + current.rmdir("test"); + current.rmdir("test2"); +} + +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +void tst_QFiledialog::task226366_lowerCaseHardDriveWindows() +{ + QNonNativeFileDialog fd; + fd.setDirectory(QDir::root().path()); + fd.show(); + QLineEdit *edit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); + QToolButton *buttonParent = qFindChild<QToolButton*>(&fd, "toParentButton"); + QTest::qWait(200); + QTest::mouseClick(buttonParent, Qt::LeftButton,0,QPoint(0,0)); + QTest::qWait(2000); + QTest::keyClick(edit, Qt::Key_C); + QTest::qWait(200); + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + QTest::qWait(200); + QCOMPARE(edit->text(), QString("C:")); + QTest::qWait(2000); + //i clear my previous selection in the completer + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + edit->clear(); + QTest::keyClick(edit, (char)(Qt::Key_C | Qt::SHIFT)); + QTest::qWait(200); + QTest::keyClick(edit->completer()->popup(), Qt::Key_Down); + QCOMPARE(edit->text(), QString("C:")); +} +#endif + +void tst_QFiledialog::task233037_selectingDirectory() +{ + QDir current = QDir::currentPath(); + current.mkdir("test"); + QNonNativeFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.setAcceptMode( QFileDialog::AcceptSave); + fd.show(); + QListView *list = qFindChild<QListView*>(&fd, "listView"); + QTest::qWait(3000); // Wait for sort to settle (I need a signal). +#ifdef QT_KEYPAD_NAVIGATION + list->setEditFocus(true); +#endif + QTest::keyClick(list, Qt::Key_Down); + QTest::qWait(100); + QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Save); + QVERIFY(button); + QCOMPARE(button->isEnabled(), true); + current.rmdir("test"); +} + +void tst_QFiledialog::task235069_hideOnEscape() +{ + QDir current = QDir::currentPath(); + QNonNativeFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.setAcceptMode( QFileDialog::AcceptSave); + fd.show(); + QListView *list = qFindChild<QListView*>(&fd, "listView"); + list->setFocus(); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Escape); + QCOMPARE(fd.isVisible(), false); + QNonNativeFileDialog fd2; + fd2.setDirectory(current.absolutePath()); + fd2.setAcceptMode( QFileDialog::AcceptSave); + fd2.show(); + QLineEdit *edit = qFindChild<QLineEdit*>(&fd2, "fileNameEdit"); + QTest::keyClick(edit, Qt::Key_Escape); + QCOMPARE(fd2.isVisible(), false); +} + +void tst_QFiledialog::task236402_dontWatchDeletedDir() +{ +#if defined QT_BUILD_INTERNAL + //THIS TEST SHOULD NOT DISPLAY WARNINGS + QDir current = QDir::currentPath(); + //make sure it is the first on the list + current.mkdir("aaaaaaaaaa"); + FriendlyQFileDialog fd; + fd.setViewMode(QFileDialog::List); + fd.setDirectory(current.absolutePath()); + fd.setAcceptMode( QFileDialog::AcceptSave); + fd.show(); + QListView *list = qFindChild<QListView*>(&fd, "listView"); + list->setFocus(); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Backspace); + QTest::keyClick(list, Qt::Key_Down); + QTest::qWait(200); + fd.d_func()->removeDirectory(current.absolutePath() + "/aaaaaaaaaa/"); + QTest::qWait(1000); +#endif +} + +void tst_QFiledialog::task203703_returnProperSeparator() +{ + QDir current = QDir::currentPath(); + current.mkdir("aaaaaaaaaaaaaaaaaa"); + QNonNativeFileDialog fd; + fd.setDirectory(current.absolutePath()); + fd.setViewMode(QFileDialog::List); + fd.setFileMode(QFileDialog::Directory); + fd.show(); + QTest::qWait(500); + QListView *list = qFindChild<QListView*>(&fd, "listView"); + list->setFocus(); + QTest::qWait(200); + QTest::keyClick(list, Qt::Key_Return); + QTest::qWait(1000); + QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Cancel); + QTest::keyClick(button, Qt::Key_Return); + QTest::qWait(500); + QString result = fd.selectedFiles().first(); + QVERIFY(result.at(result.count() - 1) != '/'); + QVERIFY(!result.contains('\\')); + current.rmdir("aaaaaaaaaaaaaaaaaa"); +} + +void tst_QFiledialog::task228844_ensurePreviousSorting() +{ + QDir current = QDir::currentPath(); + current.mkdir("aaaaaaaaaaaaaaaaaa"); + current.cd("aaaaaaaaaaaaaaaaaa"); + current.mkdir("a"); + current.mkdir("b"); + current.mkdir("c"); + current.mkdir("d"); + current.mkdir("e"); + current.mkdir("f"); + current.mkdir("g"); + QTemporaryFile *tempFile = new QTemporaryFile(current.absolutePath() + "/rXXXXXX"); + tempFile->open(); + current.cdUp(); + + QNonNativeFileDialog fd; + fd.setDirectory(current.absolutePath()); + fd.setViewMode(QFileDialog::Detail); + fd.show(); + QTest::qWait(500); + QTreeView *tree = qFindChild<QTreeView*>(&fd, "treeView"); + tree->header()->setSortIndicator(3,Qt::DescendingOrder); + QTest::qWait(200); + QDialogButtonBox *buttonBox = qFindChild<QDialogButtonBox*>(&fd, "buttonBox"); + QPushButton *button = buttonBox->button(QDialogButtonBox::Open); + QTest::mouseClick(button, Qt::LeftButton); + QTest::qWait(500); + + QNonNativeFileDialog fd2; + fd2.setFileMode(QFileDialog::Directory); + fd2.restoreState(fd.saveState()); + current.cd("aaaaaaaaaaaaaaaaaa"); + fd2.setDirectory(current.absolutePath()); + fd2.show(); + QTest::qWait(500); + QTreeView *tree2 = qFindChild<QTreeView*>(&fd2, "treeView"); + tree2->setFocus(); + + QCOMPARE(tree2->rootIndex().data(QFileSystemModel::FilePathRole).toString(),current.absolutePath()); + + QDialogButtonBox *buttonBox2 = qFindChild<QDialogButtonBox*>(&fd2, "buttonBox"); + QPushButton *button2 = buttonBox2->button(QDialogButtonBox::Open); + fd2.selectFile("g"); + QTest::mouseClick(button2, Qt::LeftButton); + QTest::qWait(500); + + QCOMPARE(fd2.selectedFiles().first(), current.absolutePath() + QChar('/') + QLatin1String("g")); + + QNonNativeFileDialog fd3(0, "This is a third file dialog", tempFile->fileName()); + fd3.restoreState(fd.saveState()); + fd3.setFileMode(QFileDialog::Directory); + fd3.show(); + QTest::qWait(500); + QTreeView *tree3 = qFindChild<QTreeView*>(&fd3, "treeView"); + tree3->setFocus(); + + QCOMPARE(tree3->rootIndex().data(QFileSystemModel::FilePathRole).toString(), current.absolutePath()); + + QDialogButtonBox *buttonBox3 = qFindChild<QDialogButtonBox*>(&fd3, "buttonBox"); + QPushButton *button3 = buttonBox3->button(QDialogButtonBox::Open); + QTest::mouseClick(button3, Qt::LeftButton); + QTest::qWait(500); + + QCOMPARE(fd3.selectedFiles().first(), tempFile->fileName()); + + current.cd("aaaaaaaaaaaaaaaaaa"); + current.rmdir("a"); + current.rmdir("b"); + current.rmdir("c"); + current.rmdir("d"); + current.rmdir("e"); + current.rmdir("f"); + current.rmdir("g"); + tempFile->close(); + delete tempFile; + current.cdUp(); + current.rmdir("aaaaaaaaaaaaaaaaaa"); +} + + +void tst_QFiledialog::task239706_editableFilterCombo() +{ + QNonNativeFileDialog d; + d.setNameFilter("*.cpp *.h"); + + d.show(); + QTest::qWait(500); + + QList<QComboBox *> comboList = d.findChildren<QComboBox *>(); + QComboBox *filterCombo = 0; + foreach (QComboBox *combo, comboList) { + if (combo->objectName() == QString("fileTypeCombo")) { + filterCombo = combo; + break; + } + } + Q_ASSERT(filterCombo); + filterCombo->setEditable(true); + QTest::mouseClick(filterCombo, Qt::LeftButton); + QTest::keyPress(filterCombo, Qt::Key_X); + QTest::keyPress(filterCombo, Qt::Key_Enter); // should not trigger assertion failure +} + +void tst_QFiledialog::task218353_relativePaths() +{ + QDir appDir = QDir::current(); + QVERIFY(appDir.cdUp() != false); + QNonNativeFileDialog d(0, "TestDialog", ".."); + QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); + + d.setDirectory(appDir.absolutePath() + QLatin1String("/non-existing-directory/../another-non-existing-dir/../")); + QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); + + QDir::current().mkdir("test"); + appDir = QDir::current(); + d.setDirectory(appDir.absolutePath() + QLatin1String("/test/../test/../")); + QCOMPARE(d.directory().absolutePath(), appDir.absolutePath()); + appDir.rmdir("test"); +} + +void tst_QFiledialog::task251321_sideBarHiddenEntries() +{ +#if defined QT_BUILD_INTERNAL + QNonNativeFileDialog fd; + + QDir current = QDir::currentPath(); + current.mkdir(".hidden"); + QDir hiddenDir = QDir(".hidden"); + hiddenDir.mkdir("subdir"); + QDir hiddenSubDir = QDir(".hidden/subdir"); + hiddenSubDir.mkdir("happy"); + hiddenSubDir.mkdir("happy2"); + + QList<QUrl> urls; + urls << QUrl::fromLocalFile(hiddenSubDir.absolutePath()); + fd.setSidebarUrls(urls); + fd.show(); + QTest::qWait(250); + + QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); + sidebar->setFocus(); + sidebar->selectUrl(QUrl::fromLocalFile(hiddenSubDir.absolutePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); + QTest::qWait(250); + + QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); + QCOMPARE(model->rowCount(model->index(hiddenSubDir.absolutePath())), 2); + + hiddenSubDir.rmdir("happy2"); + hiddenSubDir.rmdir("happy"); + hiddenDir.rmdir("subdir"); + current.rmdir(".hidden"); +#endif +} + +#if defined QT_BUILD_INTERNAL +class MyQSideBar : public QSidebar +{ +public : + MyQSideBar(QWidget *parent = 0) : QSidebar(parent) + {} + + void removeSelection() { + QList<QModelIndex> idxs = selectionModel()->selectedIndexes(); + QList<QPersistentModelIndex> indexes; + for (int i = 0; i < idxs.count(); i++) + indexes.append(idxs.at(i)); + + for (int i = 0; i < indexes.count(); ++i) + if (!indexes.at(i).data(Qt::UserRole + 1).toUrl().path().isEmpty()) + model()->removeRow(indexes.at(i).row()); + } +}; +#endif + +void tst_QFiledialog::task251341_sideBarRemoveEntries() +{ +#if defined QT_BUILD_INTERNAL + QNonNativeFileDialog fd; + + QDir current = QDir::currentPath(); + current.mkdir("testDir"); + QDir testSubDir = QDir("testDir"); + + QList<QUrl> urls; + urls << QUrl::fromLocalFile(testSubDir.absolutePath()); + urls << QUrl::fromLocalFile("NotFound"); + fd.setSidebarUrls(urls); + fd.show(); + QTest::qWait(250); + + QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); + sidebar->setFocus(); + //We enter in the first bookmark + sidebar->selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(0, 0)).center()); + QTest::qWait(250); + + QFileSystemModel *model = qFindChild<QFileSystemModel*>(&fd, "qt_filesystem_model"); + //There is no file + QCOMPARE(model->rowCount(model->index(testSubDir.absolutePath())), 0); + //Icon is not enabled QUrlModel::EnabledRole + QVariant value = sidebar->model()->index(0, 0).data(Qt::UserRole + 2); + QCOMPARE(qvariant_cast<bool>(value), true); + + sidebar->setFocus(); + //We enter in the second bookmark which is invalid + sidebar->selectUrl(QUrl::fromLocalFile("NotFound")); + QTest::mouseClick(sidebar->viewport(), Qt::LeftButton, 0, sidebar->visualRect(sidebar->model()->index(1, 0)).center()); + QTest::qWait(250); + + //We fallback to root because the entry in the bookmark is invalid + QCOMPARE(model->rowCount(model->index("NotFound")), model->rowCount(model->index(model->rootPath()))); + //Icon is not enabled QUrlModel::EnabledRole + value = sidebar->model()->index(1, 0).data(Qt::UserRole + 2); + QCOMPARE(qvariant_cast<bool>(value), false); + + MyQSideBar mySideBar; + mySideBar.init(model, urls); + mySideBar.show(); + mySideBar.selectUrl(QUrl::fromLocalFile(testSubDir.absolutePath())); + QTest::qWait(1000); + mySideBar.removeSelection(); + + //We remove the first entry + QList<QUrl> expected; + expected << QUrl::fromLocalFile("NotFound"); + QCOMPARE(mySideBar.urls(), expected); + + mySideBar.selectUrl(QUrl::fromLocalFile("NotFound")); + mySideBar.removeSelection(); + + //We remove the second entry + expected.clear(); + QCOMPARE(mySideBar.urls(), expected); + + current.rmdir("testDir"); +#endif +} + +void tst_QFiledialog::task254490_selectFileMultipleTimes() +{ + QString tempPath = QDir::tempPath(); + QTemporaryFile *t; + t = new QTemporaryFile; + t->open(); + QNonNativeFileDialog fd(0, "TestFileDialog"); + + fd.setDirectory(tempPath); + fd.setViewMode(QFileDialog::List); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setFileMode(QFileDialog::AnyFile); + + //This should select the file in the QFileDialog + fd.selectFile(t->fileName()); + + //This should clear the selection and write it into the filename line edit + fd.selectFile("new_file.txt"); + + fd.show(); + QTest::qWait(250); + + QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); + QVERIFY(lineEdit); + QCOMPARE(lineEdit->text(),QLatin1String("new_file.txt")); + QListView *list = qFindChild<QListView*>(&fd, "listView"); + QVERIFY(list); + QCOMPARE(list->selectionModel()->selectedRows(0).count(), 0); + + t->deleteLater(); +} + +void tst_QFiledialog::task257579_sideBarWithNonCleanUrls() +{ +#if defined QT_BUILD_INTERNAL + QDir tempDir = QDir::temp(); + QLatin1String dirname("autotest_task257579"); + tempDir.rmdir(dirname); //makes sure it doesn't exist any more + QVERIFY(tempDir.mkdir(dirname)); + QString url = QString::fromLatin1("%1/%2/..").arg(tempDir.absolutePath()).arg(dirname); + QNonNativeFileDialog fd; + fd.setSidebarUrls(QList<QUrl>() << QUrl::fromLocalFile(url)); + QSidebar *sidebar = qFindChild<QSidebar*>(&fd, "sidebar"); + QCOMPARE(sidebar->urls().count(), 1); + QVERIFY(sidebar->urls().first().toLocalFile() != url); + QCOMPARE(sidebar->urls().first().toLocalFile(), QDir::cleanPath(url)); + +#ifdef Q_OS_WIN + QCOMPARE(sidebar->model()->index(0,0).data().toString().toLower(), tempDir.dirName().toLower()); +#else + QCOMPARE(sidebar->model()->index(0,0).data().toString(), tempDir.dirName()); +#endif + + //all tests are finished, we can remove the temporary dir + QVERIFY(tempDir.rmdir(dirname)); +#endif +} + +void tst_QFiledialog::task259105_filtersCornerCases() +{ + QNonNativeFileDialog fd(0, "TestFileDialog"); + fd.setNameFilter(QLatin1String("All Files! (*);;Text Files (*.txt)")); + fd.setOption(QFileDialog::HideNameFilterDetails, true); + fd.show(); + QTest::qWait(250); + + //Extensions are hidden + QComboBox *filters = qFindChild<QComboBox*>(&fd, "fileTypeCombo"); + QVERIFY(filters); + QCOMPARE(filters->currentText(), QLatin1String("All Files!")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files")); + + //We should have the full names + fd.setOption(QFileDialog::HideNameFilterDetails, false); + QTest::qWait(250); + filters->setCurrentIndex(0); + QCOMPARE(filters->currentText(), QLatin1String("All Files! (*)")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); + + //Corner case undocumented of the task + fd.setNameFilter(QLatin1String("\352 (I like cheese) All Files! (*);;Text Files (*.txt)")); + QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files! (*)")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files (*.txt)")); + + fd.setOption(QFileDialog::HideNameFilterDetails, true); + filters->setCurrentIndex(0); + QTest::qWait(500); + QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files")); + + fd.setOption(QFileDialog::HideNameFilterDetails, true); + filters->setCurrentIndex(0); + QTest::qWait(500); + QCOMPARE(filters->currentText(), QLatin1String("\352 (I like cheese) All Files!")); + filters->setCurrentIndex(1); + QCOMPARE(filters->currentText(), QLatin1String("Text Files")); +} + +void tst_QFiledialog::QTBUG4419_lineEditSelectAll() +{ + QString tempPath = QDir::tempPath(); + QTemporaryFile *t; + t = new QTemporaryFile; + t->open(); + QNonNativeFileDialog fd(0, "TestFileDialog", t->fileName()); + + fd.setDirectory(tempPath); + fd.setViewMode(QFileDialog::List); + fd.setAcceptMode(QFileDialog::AcceptSave); + fd.setFileMode(QFileDialog::AnyFile); + + fd.show(); + QApplication::setActiveWindow(&fd); + QTest::qWaitForWindowShown(&fd); + QTRY_COMPARE(fd.isVisible(), true); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget*>(&fd)); + + QTest::qWait(250); + QLineEdit *lineEdit = qFindChild<QLineEdit*>(&fd, "fileNameEdit"); + + QCOMPARE(tempPath + QChar('/') + lineEdit->text(), t->fileName()); + QCOMPARE(tempPath + QChar('/') + lineEdit->selectedText(), t->fileName()); +} + +QTEST_MAIN(tst_QFiledialog) +#include "tst_qfiledialog2.moc" diff --git a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp index 3b24352..f2d9017 100644 --- a/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -806,21 +806,13 @@ void tst_QFileSystemModel::sort() myModel->d_func()->disableRecursiveSort = true; QDir dir(QDir::tempPath()); - dir.mkdir("sortTemp"); - dir.cd("sortTemp"); + //initialize the randomness + qsrand(QDateTime::currentDateTime().toTime_t()); + QString tempName = QLatin1String("sortTemp.") + QString::number(qrand()); + dir.mkdir(tempName); + dir.cd(tempName); QTRY_VERIFY(dir.exists()); - //To be sure we clean the dir if it was there before - QDirIterator it(dir.absolutePath(), QDir::NoDotAndDotDot); - while(it.hasNext()) - { - it.next(); - QFileInfo info = it.fileInfo(); - if (info.isDir()) - dir.rmdir(info.fileName()); - else - QFile::remove(info.absoluteFilePath()); - } const QString dirPath = dir.absolutePath(); QVERIFY(dir.exists()); @@ -882,11 +874,11 @@ void tst_QFileSystemModel::sort() delete myModel; dir.setPath(QDir::tempPath()); - dir.cd("sortTemp"); + dir.cd(tempName); tempFile.remove(); tempFile2.remove(); dir.cdUp(); - dir.rmdir("sortTemp"); + dir.rmdir(tempName); } diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index 755d866..1c7a159 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -435,7 +435,7 @@ void tst_QGraphicsAnchorLayout1::testAddAndRemoveAnchor() layout->removeAnchor(layout, Qt::AnchorLeft, widget1, Qt::AnchorLeft); QCOMPARE( layout->count(), 4 ); - QCOMPARE( (int)widget1->parentLayoutItem(), 0 ); + QVERIFY( !widget1->parentLayoutItem() ); // test that item is not removed from layout if other anchors remain set layout->setAnchor(widget2, Qt::AnchorLeft, widget3, Qt::AnchorRight, 10); diff --git a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp index 4f28df4..8e7bb45 100644 --- a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp @@ -146,7 +146,7 @@ void tst_QGraphicsLinearLayout::initTestCase() // since the style will influence the results, we have to ensure // that the tests are run using the same style on all platforms #ifdef Q_WS_S60 - QApplication::setStyle(new QWindowsStyle); + QApplication::setStyle(new QWindowsStyle); #else QApplication::setStyle(new QPlastiqueStyle); #endif @@ -332,6 +332,7 @@ void tst_QGraphicsLinearLayout::alignment() widget->resize(newSize); view.show(); widget->show(); + QTest::qWaitForWindowShown(&view); QApplication::processEvents(); int x = 0; diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 013a028..2426ce9 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -1287,6 +1287,7 @@ void tst_QGraphicsProxyWidget::paintEvent() QGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); + QTest::qWait(70); SubQGraphicsProxyWidget proxy; @@ -1297,14 +1298,14 @@ void tst_QGraphicsProxyWidget::paintEvent() w->show(); QTest::qWaitForWindowShown(w); QApplication::processEvents(); - QTest::qWait(50); + QTest::qWait(100); proxy.setWidget(w); scene.addItem(&proxy); //make sure we flush all the paint events QTest::qWait(70); QTRY_VERIFY(proxy.paintCount > 1); - QTest::qWait(70); + QTest::qWait(110); proxy.paintCount = 0; w->update(); @@ -2705,7 +2706,7 @@ void tst_QGraphicsProxyWidget::windowOpacity() view.show(); QTest::qWaitForWindowShown(&view); QApplication::sendPostedEvents(); - QTest::qWait(50); + QTest::qWait(150); qRegisterMetaType<QList<QRectF> >("QList<QRectF>"); QSignalSpy signalSpy(&scene, SIGNAL(changed(const QList<QRectF> &))); diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp index 8368114..c676959 100644 --- a/tests/auto/qlineedit/tst_qlineedit.cpp +++ b/tests/auto/qlineedit/tst_qlineedit.cpp @@ -3304,41 +3304,45 @@ void tst_QLineEdit::task174640_editingFinished() layout->addWidget(le2); mw.show(); - QTest::qWait(200); + QApplication::setActiveWindow(&mw); mw.activateWindow(); + QTest::qWaitForWindowShown(&mw); QSignalSpy editingFinishedSpy(le1, SIGNAL(editingFinished())); le1->setFocus(); - QTest::qWait(200); - QVERIFY(le1->hasFocus()); + QTest::qWait(20); + QTRY_VERIFY(le1->hasFocus()); QCOMPARE(editingFinishedSpy.count(), 0); le2->setFocus(); - QTest::qWait(200); - QVERIFY(le2->hasFocus()); + QTest::qWait(20); + QTRY_VERIFY(le2->hasFocus()); QCOMPARE(editingFinishedSpy.count(), 1); editingFinishedSpy.clear(); le1->setFocus(); - QTest::qWait(200); - QVERIFY(le1->hasFocus()); + QTest::qWait(20); + QTRY_VERIFY(le1->hasFocus()); QMenu *testMenu1 = new QMenu(le1); testMenu1->addAction("foo"); testMenu1->addAction("bar"); testMenu1->show(); - QTest::qWait(200); + QTest::qWaitForWindowShown(testMenu1); + QTest::qWait(20); mw.activateWindow(); + delete testMenu1; QCOMPARE(editingFinishedSpy.count(), 0); - QVERIFY(le1->hasFocus()); + QTRY_VERIFY(le1->hasFocus()); QMenu *testMenu2 = new QMenu(le2); testMenu2->addAction("foo2"); testMenu2->addAction("bar2"); testMenu2->show(); - QTest::qWait(200); + QTest::qWaitForWindowShown(testMenu2); + QTest::qWait(20); mw.activateWindow(); delete testMenu2; QCOMPARE(editingFinishedSpy.count(), 1); diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp index 9515d87..e4f267d 100644 --- a/tests/auto/qpainter/tst_qpainter.cpp +++ b/tests/auto/qpainter/tst_qpainter.cpp @@ -1554,7 +1554,7 @@ void tst_QPainter::drawClippedEllipse_data() void tst_QPainter::drawClippedEllipse() { QFETCH(QRect, rect); -#if defined(Q_OS_WINCE) +#if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN) if (sizeof(qreal) != sizeof(double)) QSKIP("Test only works for qreal==double", SkipAll); #endif diff --git a/tests/auto/qsidebar/tst_qsidebar.cpp b/tests/auto/qsidebar/tst_qsidebar.cpp index 7b157f6..b810305 100644 --- a/tests/auto/qsidebar/tst_qsidebar.cpp +++ b/tests/auto/qsidebar/tst_qsidebar.cpp @@ -122,6 +122,12 @@ void tst_QSidebar::addUrls() QSidebar qsidebar; qsidebar.init(&fsmodel, emptyUrls); QAbstractItemModel *model = qsidebar.model(); +#if defined(Q_OS_SYMBIAN) + // On Symbian, QDir::rootPath() and QDir::home() are same. + QDir testDir = QDir::currentPath(); +#else + QDir testDir = QDir::home(); +#endif // default QCOMPARE(model->rowCount(), 0); @@ -146,13 +152,13 @@ void tst_QSidebar::addUrls() // test inserting with already existing rows QList<QUrl> moreUrls; - moreUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); + moreUrls << QUrl::fromLocalFile(testDir.absolutePath()); qsidebar.addUrls(moreUrls, -1); QCOMPARE(model->rowCount(), 3); // make sure invalid urls are still added QList<QUrl> badUrls; - badUrls << QUrl::fromLocalFile(QDir::home().absolutePath() + "/I used to exist"); + badUrls << QUrl::fromLocalFile(testDir.absolutePath() + "/I used to exist"); qsidebar.addUrls(badUrls, 0); QCOMPARE(model->rowCount(), 4); @@ -179,30 +185,30 @@ void tst_QSidebar::addUrls() QList<QUrl> doubleUrls; //tow exact same paths, we have only one entry - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath()); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath()); qsidebar.setUrls(emptyUrls); qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 1); // Two paths that are effectively pointing to the same location - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath() + "/."); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath()); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath() + "/."); qsidebar.setUrls(emptyUrls); qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 1); #if defined(Q_OS_WIN) //Windows is case insensitive so no duplicate entries in that case - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath().toUpper()); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath()); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath().toUpper()); qsidebar.setUrls(emptyUrls); qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 1); #else //Two different paths we should have two entries - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath()); - doubleUrls << QUrl::fromLocalFile(QDir::home().absolutePath().toUpper()); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath()); + doubleUrls << QUrl::fromLocalFile(testDir.absolutePath().toUpper()); qsidebar.setUrls(emptyUrls); qsidebar.addUrls(doubleUrls, 1); QCOMPARE(qsidebar.urls().size(), 2); diff --git a/tests/auto/qsqldatabase/tst_databases.h b/tests/auto/qsqldatabase/tst_databases.h index c5c3663..25b1e2f 100644 --- a/tests/auto/qsqldatabase/tst_databases.h +++ b/tests/auto/qsqldatabase/tst_databases.h @@ -258,6 +258,7 @@ public: // addDb( "QTDS7", "testdb", "testuser", "Ee4Gabf6_", "bq-winserv2008" ); // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2003-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); // addDb( "QODBC3", "DRIVER={SQL SERVER};SERVER=bq-winserv2008-x86-01.apac.nokia.com;DATABASE=testdb;PORT=1433", "testuser", "Ee4Gabf6_", "" ); +// addDb( "QODBC", "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dbs\\access\\testdb.mdb", "", "", "" ); } void open() diff --git a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp index c9c8f5e..13d68ff 100644 --- a/tests/auto/qsqldatabase/tst_qsqldatabase.cpp +++ b/tests/auto/qsqldatabase/tst_qsqldatabase.cpp @@ -304,10 +304,11 @@ void tst_QSqlDatabase::createTestTables(QSqlDatabase db) // ### stupid workaround until we find a way to hardcode this // in the MySQL server startup script q.exec("set table_type=innodb"); - if (tst_Databases::isSqlServer(db)) { + else if (tst_Databases::isSqlServer(db)) { QVERIFY_SQL(q, exec("SET ANSI_DEFAULTS ON")); QVERIFY_SQL(q, exec("SET IMPLICIT_TRANSACTIONS OFF")); - } + } else if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); // please never ever change this table; otherwise fix all tests ;) if (tst_Databases::isMSAccess(db)) { @@ -334,6 +335,12 @@ void tst_QSqlDatabase::dropTestTables(QSqlDatabase db) { if (!db.isValid()) return; + + if(tst_Databases::isPostgreSQL(db)) { + QSqlQuery q(db); + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + } + // drop the view first, otherwise we'll get dependency problems tst_Databases::safeDropViews(db, QStringList() << qTableName("qtest_view") << qTableName("qtest_view2")); @@ -792,8 +799,8 @@ void tst_QSqlDatabase::checkValues(const FieldDef fieldDefs[], QSqlDatabase db) if (val1.type() == QVariant::DateTime || val1.type() == QVariant::Time) qDebug("Received Time: " + val1.toTime().toString("hh:mm:ss.zzz")); QFAIL(QString(" Expected: '%1' Received: '%2' for field %3 (etype %4 rtype %5) in checkValues").arg( - val2.toString()).arg( - val1.toString()).arg( + val2.type() == QVariant::ByteArray ? val2.toByteArray().toHex() : val2.toString()).arg( + val1.type() == QVariant::ByteArray ? val1.toByteArray().toHex() : val1.toString()).arg( fieldDefs[ i ].fieldName()).arg( val2.typeName()).arg( val1.typeName()) @@ -1019,6 +1026,10 @@ void tst_QSqlDatabase::recordPSQL() }; QSqlQuery q(db); + + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + q.exec("drop sequence " + qTableName("qtestfields") + "_t_bigserial_seq"); q.exec("drop sequence " + qTableName("qtestfields") + "_t_serial_seq"); // older psql cut off the table name @@ -1292,9 +1303,9 @@ void tst_QSqlDatabase::recordAccess() FieldDef("varchar(20)", QVariant::String, QString("Blah1")), FieldDef("single", QVariant::Double, 1.12345), FieldDef("double", QVariant::Double, 1.123456), - FieldDef("byte", QVariant::Int, 255), + FieldDef("byte", QVariant::UInt, 255), #ifdef QT3_SUPPORT - FieldDef("binary", QVariant::ByteArray, Q3CString("Blah2")), + FieldDef("binary(5)", QVariant::ByteArray, Q3CString("Blah2")), #endif FieldDef("long", QVariant::Int, 2147483647), FieldDef("memo", QVariant::String, memo), @@ -1494,6 +1505,11 @@ void tst_QSqlDatabase::psql_schemas() QSKIP("server does not support schemas", SkipSingle); QSqlQuery q(db); + + if(tst_Databases::isPostgreSQL(db)) { + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + } + QVERIFY_SQL(q, exec("CREATE SCHEMA " + qTableName("qtestschema"))); QString table = qTableName("qtestschema") + '.' + qTableName("qtesttable"); @@ -1529,6 +1545,9 @@ void tst_QSqlDatabase::psql_escapedIdentifiers() QSqlQuery q(db); + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + QString schemaName = qTableName("qtestScHeMa"); QString tableName = qTableName("qtest"); QString field1Name = QString("fIeLdNaMe"); @@ -1643,7 +1662,10 @@ void tst_QSqlDatabase::precisionPolicy() QSKIP("Driver or database doesn't support setting precision policy", SkipSingle); // Create a test table with some data - QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, num numeric(18,5))").arg(tableName))); + if(tst_Databases::isMSAccess(db)) + QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, num number)").arg(tableName))); + else + QVERIFY_SQL(q, exec(QString("CREATE TABLE %1 (id smallint, num numeric(18,5))").arg(tableName))); QVERIFY_SQL(q, prepare(QString("INSERT INTO %1 VALUES (?, ?)").arg(tableName))); q.bindValue(0, 1); q.bindValue(1, 123); @@ -2007,6 +2029,7 @@ void tst_QSqlDatabase::odbc_bindBoolean() QSKIP("MySql has inconsistent behaviour of bit field type across versions.", SkipSingle); return; } + QSqlQuery q(db); QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("qtestBindBool") + "(id int, boolvalue bit)")); @@ -2038,6 +2061,8 @@ void tst_QSqlDatabase::odbc_testqGetString() QSqlQuery q(db); if (tst_Databases::isSqlServer(db)) QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue varchar(MAX))")); + else if(tst_Databases::isMSAccess(db)) + QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue memo)")); else QVERIFY_SQL(q, exec("CREATE TABLE " + qTableName("testqGetString") + "(id int, vcvalue varchar(65538))")); @@ -2264,7 +2289,10 @@ void tst_QSqlDatabase::odbc_uintfield() unsigned int val = 4294967295U; QSqlQuery q(db); - q.exec(QString("CREATE TABLE %1(num numeric(10))").arg(tableName)); + if ( tst_Databases::isMSAccess( db ) ) + QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(num number)").arg(tableName))); + else + QVERIFY_SQL(q, exec(QString("CREATE TABLE %1(num numeric(10))").arg(tableName))); q.prepare(QString("INSERT INTO %1 VALUES(?)").arg(tableName)); q.addBindValue(val); QVERIFY_SQL(q, exec()); @@ -2440,8 +2468,8 @@ void tst_QSqlDatabase::mysql_savepointtest() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); - if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 ) - QSKIP( "Test requires MySQL >= 5.0", SkipSingle ); + if ( db.driverName().startsWith( "QMYSQL" ) && tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 1 ).toInt()<4.1 ) + QSKIP( "Test requires MySQL >= 4.1", SkipSingle ); QSqlQuery q(db); QVERIFY_SQL(q, exec("begin")); diff --git a/tests/auto/qsqldriver/tst_qsqldriver.cpp b/tests/auto/qsqldriver/tst_qsqldriver.cpp index f463c9e..5322b97 100644 --- a/tests/auto/qsqldriver/tst_qsqldriver.cpp +++ b/tests/auto/qsqldriver/tst_qsqldriver.cpp @@ -85,6 +85,9 @@ void tst_QSqlDriver::recreateTestTables(QSqlDatabase db) { QSqlQuery q(db); + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + tst_Databases::safeDropTable( db, qTableName( "relTEST1" ) ); QVERIFY_SQL( q, exec("create table " + qTableName("relTEST1") + @@ -160,7 +163,11 @@ void tst_QSqlDriver::record() //check that we can't get records using incorrect tablename casing that's been quoted rec = db.driver()->record(db.driver()->escapeIdentifier(tablename,QSqlDriver::TableName)); - if (tst_Databases::isMySQL(db) || db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QTDS") || tst_Databases::isSqlServer(db)) + if (tst_Databases::isMySQL(db) + || db.driverName().startsWith("QSQLITE") + || db.driverName().startsWith("QTDS") + || tst_Databases::isSqlServer(db) + || tst_Databases::isMSAccess(db)) QCOMPARE(rec.count(), 4); //mysql, sqlite and tds will match else QCOMPARE(rec.count(), 0); @@ -208,7 +215,11 @@ void tst_QSqlDriver::primaryIndex() tablename = tablename.toUpper(); index = db.driver()->primaryIndex(db.driver()->escapeIdentifier(tablename, QSqlDriver::TableName)); - if (tst_Databases::isMySQL(db) || db.driverName().startsWith("QSQLITE") || db.driverName().startsWith("QTDS") || tst_Databases::isSqlServer(db)) + if (tst_Databases::isMySQL(db) + || db.driverName().startsWith("QSQLITE") + || db.driverName().startsWith("QTDS") + || tst_Databases::isSqlServer(db) + || tst_Databases::isMSAccess(db)) QCOMPARE(index.count(), 1); //mysql will always find the table name regardless of casing else QCOMPARE(index.count(), 0); diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp index 5ed9cfa..546c105 100644 --- a/tests/auto/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp @@ -333,6 +333,8 @@ void tst_QSqlQuery::createTestTables( QSqlDatabase db ) // ### stupid workaround until we find a way to hardcode this // in the MySQL server startup script q.exec( "set table_type=innodb" ); + else if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); if(tst_Databases::isPostgreSQL(db)) QVERIFY_SQL( q, exec( "create table " + qTableName( "qtest" ) + " (id serial NOT NULL, t_varchar varchar(20), t_char char(20), primary key(id)) WITH OIDS" ) ); @@ -1645,6 +1647,9 @@ void tst_QSqlQuery::prepare_bind_exec() QString createQuery; + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + if ( tst_Databases::isSqlServer( db ) || db.driverName().startsWith( "QTDS" ) ) createQuery = "create table " + qTableName( "qtest_prepare" ) + " (id int primary key, name nvarchar(20) null)"; else if ( db.driverName().startsWith( "QMYSQL" ) && useUnicode ) diff --git a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp index 391219b..3131f35 100644 --- a/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp +++ b/tests/auto/qsqlquerymodel/tst_qsqlquerymodel.cpp @@ -158,6 +158,8 @@ void tst_QSqlQueryModel::createTestTables(QSqlDatabase db) { dropTestTables(db); QSqlQuery q(db); + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); QVERIFY_SQL( q, exec("create table " + qTableName("test") + "(id integer not null, name varchar(20), title integer, primary key (id))")); QVERIFY_SQL( q, exec("create table " + qTableName("test2") + "(id integer not null, title varchar(20), primary key (id))")); QVERIFY_SQL( q, exec("create table " + qTableName("test3") + "(id integer not null, primary key (id))")); diff --git a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp index 05d546e..cb24a9f 100644 --- a/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp +++ b/tests/auto/qsqlrelationaltablemodel/tst_qsqlrelationaltablemodel.cpp @@ -837,10 +837,10 @@ void tst_QSqlRelationalTableModel::insertRecordDuplicateFieldNames() QVERIFY_SQL(model, select()); if (db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) { - QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name")).toUpper()).toString(), + QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name_2")).toUpper()).toString(), QString("Trondheim")); } else { - QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name"))).toString(), + QCOMPARE(model.record(1).value(qTableName("reltest4").append(QLatin1String("_name_2"))).toString(), QString("Trondheim")); } @@ -859,9 +859,9 @@ void tst_QSqlRelationalTableModel::insertRecordDuplicateFieldNames() // The duplicate field names is aliased because it's comes from the relation's display column. if(db.driverName().startsWith("QIBASE") || db.driverName().startsWith("QOCI") || db.driverName().startsWith("QDB2")) - QCOMPARE(rec.fieldName(2), (qTableName("reltest4").append(QLatin1String("_name"))).toUpper()); + QCOMPARE(rec.fieldName(2), (qTableName("reltest4").append(QLatin1String("_name_2"))).toUpper()); else - QCOMPARE(rec.fieldName(2), qTableName("reltest4").append(QLatin1String("_name"))); + QCOMPARE(rec.fieldName(2), qTableName("reltest4").append(QLatin1String("_name_2"))); QVERIFY(model.insertRecord(-1, rec)); QCOMPARE(model.data(model.index(2, 2)).toString(), QString("Oslo")); diff --git a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp index 49e087f..653d944 100644 --- a/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp +++ b/tests/auto/qsqltablemodel/tst_qsqltablemodel.cpp @@ -143,6 +143,8 @@ void tst_QSqlTableModel::dropTestTables() for (int i = 0; i < dbs.dbNames.count(); ++i) { QSqlDatabase db = QSqlDatabase::database(dbs.dbNames.at(i)); QSqlQuery q(db); + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); QStringList tableNames; tableNames << qTableName("test") @@ -659,6 +661,9 @@ void tst_QSqlTableModel::primaryKeyOrder() QSqlQuery q(db); + if(tst_Databases::isPostgreSQL(db)) + QVERIFY_SQL( q, exec("set client_min_messages='warning'")); + QVERIFY_SQL( q, exec("create table "+qTableName("foo")+"(a varchar(20), id int not null primary key, b varchar(20))")); QSqlTableModel model(0, db); @@ -897,6 +902,8 @@ void tst_QSqlTableModel::sqlite_attachedDatabase() QFETCH(QString, dbName); QSqlDatabase db = QSqlDatabase::database(dbName); CHECK_DATABASE(db); + if(db.databaseName() == ":memory:") + QSKIP(":memory: database, skipping test", SkipSingle); QSqlDatabase attachedDb = QSqlDatabase::cloneDatabase(db, db.driverName() + QLatin1String("attached")); attachedDb.setDatabaseName(db.databaseName()+QLatin1String("attached.dat")); diff --git a/tests/auto/qsqlthread/tst_qsqlthread.cpp b/tests/auto/qsqlthread/tst_qsqlthread.cpp index c088a47..be66e9e 100644 --- a/tests/auto/qsqlthread/tst_qsqlthread.cpp +++ b/tests/auto/qsqlthread/tst_qsqlthread.cpp @@ -404,6 +404,8 @@ void tst_QSqlThread::readWriteThreading() if (db.databaseName() == ":memory:") QSKIP("does not work with in-memory databases", SkipSingle); + else if (tst_Databases::isMSAccess(db)) + QSKIP("does not work with MS Access databases", SkipSingle); SqlProducer producer(db); SqlConsumer consumer(db); diff --git a/tests/auto/qsslsocket/tst_qsslsocket.cpp b/tests/auto/qsslsocket/tst_qsslsocket.cpp index 77e3763..6efe440 100644 --- a/tests/auto/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/qsslsocket/tst_qsslsocket.cpp @@ -1377,6 +1377,7 @@ void tst_QSslSocket::waitForMinusOne() // connect to the server QSslSocket socket; + QTest::qSleep(100); socket.connectToHost("127.0.0.1", server.serverPort); QVERIFY(socket.waitForConnected(-1)); socket.ignoreSslErrors(); diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index eab5a35..d75cfa7 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -193,6 +193,7 @@ private slots: void mouseWheel(); void addColumnWhileEditing(); + void task234926_setHeaderSorting(); }; // Testing get/set functions @@ -2702,6 +2703,7 @@ void tst_QTableView::indexAt() QtTestTableView view; view.show(); + QTest::qWaitForWindowShown(&view); //some styles change the scroll mode in their polish view.setHorizontalScrollMode(QAbstractItemView::ScrollPerItem); @@ -2717,9 +2719,10 @@ void tst_QTableView::indexAt() for (int c = 0; c < columnCount; ++c) view.setColumnWidth(c, columnWidth); - QTest::qWait(0); // ### needed to pass the test + QTest::qWait(20); view.horizontalScrollBar()->setValue(horizontalScroll); view.verticalScrollBar()->setValue(verticalScroll); + QTest::qWait(20); QModelIndex index = view.indexAt(QPoint(x, y)); QCOMPARE(index.row(), expectedRow); @@ -3249,9 +3252,15 @@ void tst_QTableView::resizeToContents() } +QT_BEGIN_NAMESPACE +extern bool Q_GUI_EXPORT qt_tab_all_widgets; // qapplication.cpp +QT_END_NAMESPACE void tst_QTableView::tabFocus() { + if (!qt_tab_all_widgets) + QSKIP("This test requires full keyboard control to be enabled.", SkipAll); + // QTableView enables tabKeyNavigation by default, but you should be able // to change focus on an empty table view, or on a table view that doesn't // have this property set. @@ -3774,5 +3783,41 @@ void tst_QTableView::task191545_dragSelectRows() } } +void tst_QTableView::task234926_setHeaderSorting() +{ + QStringListModel model; + QStringList data; + data << "orange" << "apple" << "banana" << "lemon" << "pumpkin"; + QStringList sortedDataA = data; + QStringList sortedDataD = data; + qSort(sortedDataA); + qSort(sortedDataD.begin(), sortedDataD.end(), qGreater<QString>()); + model.setStringList(data); + QTableView view; + view.setModel(&model); +// view.show(); + QTest::qWait(20); + QCOMPARE(model.stringList(), data); + view.setSortingEnabled(true); + view.sortByColumn(0, Qt::AscendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataA); + + view.horizontalHeader()->setSortIndicator(0, Qt::DescendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataD); + + QHeaderView *h = new QHeaderView(Qt::Horizontal); + h->setModel(&model); + view.setHorizontalHeader(h); + h->setSortIndicator(0, Qt::AscendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataA); + + h->setSortIndicator(0, Qt::DescendingOrder); + QApplication::processEvents(); + QCOMPARE(model.stringList() , sortedDataD); +} + QTEST_MAIN(tst_QTableView) #include "tst_qtableview.moc" diff --git a/tests/auto/qtablewidget/tst_qtablewidget.cpp b/tests/auto/qtablewidget/tst_qtablewidget.cpp index 5aa2d1d..b85851f 100644 --- a/tests/auto/qtablewidget/tst_qtablewidget.cpp +++ b/tests/auto/qtablewidget/tst_qtablewidget.cpp @@ -102,6 +102,7 @@ private slots: void cellWidget(); void task231094(); void task219380_removeLastRow(); + void task262056_sortDuplicate(); private: QTableWidget *testWidget; @@ -1474,6 +1475,26 @@ void tst_QTableWidget::task219380_removeLastRow() QCOMPARE(testWidget->cellWidget(18, 0)->geometry(), testWidget->visualItemRect(&item)); } +void tst_QTableWidget::task262056_sortDuplicate() +{ + testWidget->setColumnCount(2); + testWidget->setRowCount(8); + testWidget->setSortingEnabled(true); + QStringList items = (QStringList() << "AAA" << "BBB" << "CCC" << "CCC" << "DDD"\ + << "EEE" << "FFF" << "GGG"); + for (int i = 0; i<8; i++ ) { + QTableWidgetItem *twi = new QTableWidgetItem(items.at(i)); + testWidget->setItem(i,0,twi); + testWidget->setItem(i,1,new QTableWidgetItem(QString("item %1").arg(i))); + } + testWidget->sortItems(0, Qt::AscendingOrder); + QSignalSpy layoutChangedSpy(testWidget->model(), SIGNAL(layoutChanged())); + testWidget->item(3,0)->setBackgroundColor(Qt::red); + + QCOMPARE(layoutChangedSpy.count(),0); + +} + QTEST_MAIN(tst_QTableWidget) #include "tst_qtablewidget.moc" diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index c000a12..daeee3d 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -7459,11 +7459,11 @@ void tst_QWidget::updateWhileMinimized() QTest::qWaitForWindowShown(&widget); QApplication::processEvents(); QTRY_VERIFY(widget.numPaintEvents > 0); - QTest::qWait(50); + QTest::qWait(150); // Minimize window. widget.showMinimized(); - QTest::qWait(70); + QTest::qWait(110); widget.reset(); @@ -8164,7 +8164,7 @@ public: static bool firstTime = true; if (firstTime) - QTimer::singleShot(150, this, SLOT(resizeMe())); + QTimer::singleShot(250, this, SLOT(resizeMe())); firstTime = false; } @@ -8181,7 +8181,7 @@ void tst_QWidget::moveInResizeEvent() testWidget.setGeometry(50, 50, 200, 200); testWidget.show(); QTest::qWaitForWindowShown(&testWidget); - QTest::qWait(160); + QTest::qWait(300); QRect expectedGeometry(100,100, 100, 100); QTRY_COMPARE(testWidget.geometry(), expectedGeometry); |