diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2009-10-16 16:26:06 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2009-10-16 16:26:06 (GMT) |
commit | af1fa7fe766980210d7363c1559197f34b10d834 (patch) | |
tree | e2964649ca8469269950a265060b3d1e7e6026f6 /tests | |
parent | c5bfbe27f5bbdb1f3e76af8ca5e0f4df27875a06 (diff) | |
parent | 1433a2c8682cb1c8f89ceaf97ad7a509ac686879 (diff) | |
download | Qt-af1fa7fe766980210d7363c1559197f34b10d834.zip Qt-af1fa7fe766980210d7363c1559197f34b10d834.tar.gz Qt-af1fa7fe766980210d7363c1559197f34b10d834.tar.bz2 |
Merge branch '4.6'
Conflicts:
translations/assistant_adp_pl.ts
translations/assistant_adp_ru.ts
Diffstat (limited to 'tests')
52 files changed, 2559 insertions, 998 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 9bc1d5c..8e3ce81 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -234,6 +234,7 @@ SUBDIRS += \ qpainterpath \ qpalette \ qparallelanimationgroup \ + qpauseanimation \ qpathclipper \ qpen \ qpicture \ diff --git a/tests/auto/bic/tst_bic.cpp b/tests/auto/bic/tst_bic.cpp index 82c8dc0..8c6056e 100644 --- a/tests/auto/bic/tst_bic.cpp +++ b/tests/auto/bic/tst_bic.cpp @@ -252,6 +252,7 @@ QBic::Info tst_Bic::getCurrentInfo(const QString &libName) } if (proc.exitCode() != 0) { qWarning() << "gcc returned with" << proc.exitCode(); + qDebug() << proc.readAllStandardError(); return QBic::Info(); } @@ -268,6 +269,7 @@ QBic::Info tst_Bic::getCurrentInfo(const QString &libName) qFatal("Could not locate the GCC output file, update this test"); return QBic::Info(); } else if (files.size() > 1) { + qDebug() << files; qFatal("Located more than one output file, please clean up before running this test"); return QBic::Info(); } 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/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp index d6911d2..db840f4 100644 --- a/tests/auto/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/qabstractitemview/tst_qabstractitemview.cpp @@ -223,6 +223,7 @@ private slots: void task257481_emptyEditor(); void shiftArrowSelectionAfterScrolling(); void shiftSelectionAfterRubberbandSelection(); + void ctrlRubberbandSelection(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1388,5 +1389,49 @@ void tst_QAbstractItemView::shiftSelectionAfterRubberbandSelection() QVERIFY(selected.contains(index2)); } +void tst_QAbstractItemView::ctrlRubberbandSelection() +{ + QStandardItemModel model; + for (int i=0; i<3; ++i) { + QStandardItem *item = new QStandardItem(QString("%1").arg(i)); + model.setItem(i, 0, item); + } + + QListView view; + view.setFixedSize(150, 450); + view.setFlow(QListView::LeftToRight); + view.setGridSize(QSize(100, 100)); + view.setSelectionMode(QListView::ExtendedSelection); + view.setViewMode(QListView::IconMode); + view.setModel(&model); + view.show(); + QTest::qWait(30); + + QModelIndex index1 = model.index(1, 0); + QModelIndex index2 = model.index(2, 0); + + // Select item 1 + view.setCurrentIndex(index1); + QModelIndexList selected = view.selectionModel()->selectedIndexes(); + QCOMPARE(selected.count(), 1); + QVERIFY(selected.contains(index1)); + + // Now press control and draw a rubberband around items 1 and 2. + // The mouse move event has to be created manually because the QTest framework does not + // contain a function for mouse moves with buttons pressed. + QPoint pressPos = view.visualRect(index1).topLeft() - QPoint(1, 1); + QPoint releasePos = view.visualRect(index2).bottomRight() + QPoint(1, 1); + QTest::mousePress(view.viewport(), Qt::LeftButton, Qt::ControlModifier, pressPos); + QMouseEvent moveEvent(QEvent::MouseMove, releasePos, Qt::NoButton, Qt::LeftButton, Qt::ControlModifier); + bool moveEventReceived = qApp->notify(view.viewport(), &moveEvent); + QVERIFY(moveEventReceived); + QTest::mouseRelease(view.viewport(), Qt::LeftButton, Qt::ControlModifier, releasePos); + + // Verify that item 2 is selected now + selected = view.selectionModel()->selectedIndexes(); + QCOMPARE(selected.count(), 1); + QVERIFY(selected.contains(index2)); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" 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/qcombobox/tst_qcombobox.cpp b/tests/auto/qcombobox/tst_qcombobox.cpp index e76f0f7..0d3469d 100644 --- a/tests/auto/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/qcombobox/tst_qcombobox.cpp @@ -151,6 +151,7 @@ private slots: void subControlRectsWithOffset_data(); void subControlRectsWithOffset(); void task260974_menuItemRectangleForComboBoxPopup(); + void removeItem(); protected slots: void onEditTextChanged( const QString &newString ); @@ -2398,5 +2399,22 @@ void tst_QComboBox::task260974_menuItemRectangleForComboBoxPopup() #endif } +void tst_QComboBox::removeItem() +{ + QComboBox cb; + cb.removeItem(-1); + cb.removeItem(1); + cb.removeItem(0); + QCOMPARE(cb.count(), 0); + + cb.addItem("foo"); + cb.removeItem(-1); + QCOMPARE(cb.count(), 1); + cb.removeItem(1); + QCOMPARE(cb.count(), 1); + cb.removeItem(0); + QCOMPARE(cb.count(), 0); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" 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 29e4fe6..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()); @@ -874,7 +866,7 @@ void tst_QFileSystemModel::sort() } else { for(int i = 0; i < myModel->rowCount(parent); ++i) { - QVERIFY(dirPath + QChar('/') + myModel->index(i, 1, parent).data(QFileSystemModel::FileNameRole).toString() == expectedOrder.at(i)); + QTRY_COMPARE(dirPath + QChar('/') + myModel->index(i, 1, parent).data(QFileSystemModel::FileNameRole).toString(), expectedOrder.at(i)); } } @@ -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/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index e4eaf4e..0a6f60e 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -82,6 +82,14 @@ Q_DECLARE_METATYPE(QRectF) #define Q_CHECK_PAINTEVENTS #endif +#if defined(Q_WS_MAC) && defined(QT_MAC_USE_COCOA) +// On mac (cocoa) we always get full update. +// So check that the expected region is contained inside the actual +#define COMPARE_REGIONS(ACTUAL, EXPECTED) QVERIFY((EXPECTED).subtracted(ACTUAL).isEmpty()) +#else +#define COMPARE_REGIONS QTRY_COMPARE +#endif + static void sendMousePress(QGraphicsScene *scene, const QPointF &point, Qt::MouseButton button = Qt::LeftButton) { QGraphicsSceneMouseEvent event(QEvent::GraphicsSceneMousePress); @@ -6183,7 +6191,7 @@ void tst_QGraphicsItem::opacity2() MyGraphicsView view(&scene); view.show(); QTest::qWaitForWindowShown(&view); - QTRY_COMPARE(view.repaints, 1); + QTRY_VERIFY(view.repaints >= 1); #define RESET_REPAINT_COUNTERS \ parent->repaints = 0; \ @@ -6290,7 +6298,7 @@ void tst_QGraphicsItem::opacityZeroUpdates() QRegion expectedRegion = parentDeviceBoundingRect.adjusted(-2, -2, 2, 2); expectedRegion += childDeviceBoundingRect.adjusted(-2, -2, 2, 2); - QTRY_COMPARE(view.paintedRegion, expectedRegion); + COMPARE_REGIONS(view.paintedRegion, expectedRegion); } class StacksBehindParentHelper : public QGraphicsRectItem @@ -7117,7 +7125,7 @@ void tst_QGraphicsItem::update() qApp->processEvents(); QCOMPARE(item->repaints, 1); QCOMPARE(view.repaints, 1); - QCOMPARE(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); + COMPARE_REGIONS(view.paintedRegion, expectedRegion + expectedRegion.translated(50, 50)); // Make sure moving a parent item triggers an update on the children // (even though the parent itself is outside the viewport). @@ -7392,7 +7400,7 @@ void tst_QGraphicsItem::moveItem() QRegion expectedParentRegion = parentDeviceBoundingRect; // old position parentDeviceBoundingRect.translate(20, 20); expectedParentRegion += parentDeviceBoundingRect; // new position - QCOMPARE(view.paintedRegion, expectedParentRegion); + COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); RESET_COUNTERS @@ -7402,7 +7410,7 @@ void tst_QGraphicsItem::moveItem() QCOMPARE(child->repaints, 1); QCOMPARE(view.repaints, 1); const QRegion expectedChildRegion = expectedParentRegion.translated(20, 20); - QCOMPARE(view.paintedRegion, expectedChildRegion); + COMPARE_REGIONS(view.paintedRegion, expectedChildRegion); RESET_COUNTERS @@ -7413,7 +7421,7 @@ void tst_QGraphicsItem::moveItem() QCOMPARE(grandChild->repaints, 1); QCOMPARE(view.repaints, 1); const QRegion expectedGrandChildRegion = expectedParentRegion.translated(40, 40); - QCOMPARE(view.paintedRegion, expectedGrandChildRegion); + COMPARE_REGIONS(view.paintedRegion, expectedGrandChildRegion); RESET_COUNTERS @@ -7426,7 +7434,7 @@ void tst_QGraphicsItem::moveItem() expectedParentRegion.translate(20, 20); expectedParentRegion += expectedChildRegion.translated(20, 20); expectedParentRegion += expectedGrandChildRegion.translated(20, 20); - QCOMPARE(view.paintedRegion, expectedParentRegion); + COMPARE_REGIONS(view.paintedRegion, expectedParentRegion); } void tst_QGraphicsItem::sorting_data() diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index 76e7202..013a028 100644 --- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -170,6 +170,7 @@ private slots: void dontCrashWhenDie(); void createProxyForChildWidget(); void actionsContextMenu(); + void actionsContextMenu_data(); void deleteProxyForChildWidget(); void bypassGraphicsProxyWidget_data(); void bypassGraphicsProxyWidget(); @@ -1531,7 +1532,7 @@ void tst_QGraphicsProxyWidget::setWidget_simple() // Properties // QCOMPARE(proxy.focusPolicy(), lineEdit->focusPolicy()); - QCOMPARE(proxy.palette(), lineEdit->palette()); + // QCOMPARE(proxy.palette(), lineEdit->palette()); #ifndef QT_NO_CURSOR QCOMPARE(proxy.cursor().shape(), lineEdit->cursor().shape()); #endif @@ -1756,6 +1757,8 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleWidget() QTRY_VERIFY(leftDial->hasFocus()); QCOMPARE(eventSpy.counts[QEvent::FocusIn], 2); QCOMPARE(eventSpy.counts[QEvent::FocusOut], 2); + + delete view; } void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets() @@ -1878,6 +1881,8 @@ void tst_QGraphicsProxyWidget::tabFocus_simpleTwoWidgets() QVERIFY(leftDial->hasFocus()); QCOMPARE(eventSpy.counts[QEvent::FocusIn], 2); QCOMPARE(eventSpy.counts[QEvent::FocusOut], 2); + + delete view; } void tst_QGraphicsProxyWidget::tabFocus_complexWidget() @@ -1988,6 +1993,8 @@ void tst_QGraphicsProxyWidget::tabFocus_complexWidget() QApplication::processEvents(); QVERIFY(!box->hasFocus()); leftDial->hasFocus(); + + delete view; } void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets() @@ -2156,6 +2163,8 @@ void tst_QGraphicsProxyWidget::tabFocus_complexTwoWidgets() QApplication::processEvents(); QVERIFY(!box->hasFocus()); leftDial->hasFocus(); + + delete view; } void tst_QGraphicsProxyWidget::setFocus_simpleWidget() @@ -2222,6 +2231,8 @@ void tst_QGraphicsProxyWidget::setFocus_simpleWidget() // Symmetry editProxy->clearFocus(); QVERIFY(!edit->hasFocus()); + + delete view; } void tst_QGraphicsProxyWidget::setFocus_simpleTwoWidgets() @@ -2272,6 +2283,8 @@ void tst_QGraphicsProxyWidget::setFocus_simpleTwoWidgets() QVERIFY(!editProxy->hasFocus()); QVERIFY(edit2->hasFocus()); QVERIFY(edit2Proxy->hasFocus()); + + delete view; } void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets() @@ -2391,6 +2404,8 @@ void tst_QGraphicsProxyWidget::setFocus_complexTwoWidgets() QCOMPARE(eventSpyBox.counts[QEvent::FocusOut], 1); QCOMPARE(eventSpyBox_2.counts[QEvent::FocusIn], 0); QCOMPARE(eventSpyBox_2.counts[QEvent::FocusOut], 0); + + delete view; } void tst_QGraphicsProxyWidget::popup_basic() @@ -2780,13 +2795,13 @@ void tst_QGraphicsProxyWidget::palettePropagation() QCOMPARE(proxySpy.counts[QEvent::PaletteChange], 0); QVERIFY(edit->testAttribute(Qt::WA_SetPalette)); QVERIFY(!proxy.testAttribute(Qt::WA_SetPalette)); - QCOMPARE(proxy.palette(), lineEditPalette); + QCOMPARE(proxy.palette(), QPalette()); edit->setPalette(QPalette()); QCOMPARE(editSpy.counts[QEvent::PaletteChange], 2); QCOMPARE(proxySpy.counts[QEvent::PaletteChange], 0); QVERIFY(!edit->testAttribute(Qt::WA_SetPalette)); QVERIFY(!proxy.testAttribute(Qt::WA_SetPalette)); - QCOMPARE(proxy.palette(), lineEditPalette); + QCOMPARE(proxy.palette(), QPalette()); // Proxy to widget proxy.setPalette(palette); @@ -2896,6 +2911,9 @@ void tst_QGraphicsProxyWidget::dontCrashWhenDie() QTest::qWait(100); QTest::mouseMove(w->view->viewport(), w->view->mapFromScene(w->widget->mapToScene(w->widget->boundingRect().center()))); delete w->item; + + QApplication::processEvents(); + delete w; } void tst_QGraphicsProxyWidget::createProxyForChildWidget() @@ -3014,30 +3032,67 @@ private slots: } }; +void tst_QGraphicsProxyWidget::actionsContextMenu_data() +{ + QTest::addColumn<bool>("actionsContextMenu"); + QTest::addColumn<bool>("hasFocus"); + + QTest::newRow("without actionsContextMenu and with focus") << false << true; + QTest::newRow("without actionsContextMenu and without focus") << false << false; + QTest::newRow("with actionsContextMenu and focus") << true << true; + QTest::newRow("with actionsContextMenu without focus") << true << false; +} + void tst_QGraphicsProxyWidget::actionsContextMenu() { - ContextMenuWidget *widget = new ContextMenuWidget; - widget->addAction(new QAction("item 1", widget)); - widget->addAction(new QAction("item 2", widget)); - widget->addAction(new QAction("item 3", widget)); - widget->setContextMenuPolicy(Qt::ActionsContextMenu); + QFETCH(bool, hasFocus); + QFETCH(bool, actionsContextMenu); + ContextMenuWidget *widget = new ContextMenuWidget; + if (actionsContextMenu) { + widget->addAction(new QAction("item 1", widget)); + widget->addAction(new QAction("item 2", widget)); + widget->addAction(new QAction("item 3", widget)); + widget->setContextMenuPolicy(Qt::ActionsContextMenu); + } QGraphicsScene scene; - scene.addWidget(widget); QGraphicsView view(&scene); view.show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif + QApplication::setActiveWindow(&view); + QTest::qWaitForWindowShown(&view); + view.setFocus(); + QTRY_VERIFY(view.hasFocus()); + + if (hasFocus) + scene.addWidget(widget)->setFocus(); + else + scene.addWidget(widget)->clearFocus(); + + QApplication::processEvents(); + QContextMenuEvent contextMenuEvent(QContextMenuEvent::Mouse, view.viewport()->rect().center(), view.viewport()->mapToGlobal(view.viewport()->rect().center())); contextMenuEvent.accept(); qApp->sendEvent(view.viewport(), &contextMenuEvent); - QVERIFY(widget->embeddedPopup); - QVERIFY(!widget->gotContextMenuEvent); + if (hasFocus) { + if (actionsContextMenu) { + //actionsContextMenu embedded popup but no contextMenuEvent (widget has focus) + QVERIFY(widget->embeddedPopup); + QVERIFY(!widget->gotContextMenuEvent); + } else { + //no embedded popup but contextMenuEvent (widget has focus) + QVERIFY(!widget->embeddedPopup); + QVERIFY(widget->gotContextMenuEvent); + } + } else { + //qgraphicsproxywidget doesn't have the focus, the widget must not receive any contextMenuEvent and must not create any QMenu + QVERIFY(!widget->embeddedPopup); + QVERIFY(!widget->gotContextMenuEvent); + } + } diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index f5e9acb..0589994 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -266,6 +266,7 @@ private slots: void dispatchHoverOnPress(); void initialFocus_data(); void initialFocus(); + void polishItems(); // task specific tests below me void task139710_bspTreeCrash(); @@ -3882,5 +3883,32 @@ void tst_QGraphicsScene::initialFocus() QCOMPARE(rect->hasFocus(), shouldHaveFocus); } +class PolishItem : public QGraphicsTextItem +{ +public: + PolishItem(QGraphicsItem *parent = 0) : QGraphicsTextItem(parent) { } + +protected: + QVariant itemChange(GraphicsItemChange change, const QVariant& value) + { + if (change == ItemVisibleChange) { + if (value.toBool()) + qDeleteAll(childItems()); + } + return QGraphicsItem::itemChange(change, value); + } +}; + +void tst_QGraphicsScene::polishItems() +{ + QGraphicsScene scene; + PolishItem *parent = new PolishItem; + scene.addItem(parent); + PolishItem *child = new PolishItem(parent); + Q_UNUSED(child) + // test that QGraphicsScenePrivate::_q_polishItems() doesn't crash + QMetaObject::invokeMethod(&scene,"_q_polishItems"); +} + QTEST_MAIN(tst_QGraphicsScene) #include "tst_qgraphicsscene.moc" diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index df3ebef..389200b 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -84,6 +84,12 @@ Q_DECLARE_METATYPE(QPolygonF) Q_DECLARE_METATYPE(QRectF) Q_DECLARE_METATYPE(Qt::ScrollBarPolicy) +#ifdef Q_WS_MAC +//On mac we get full update. So check that the expected region is contained inside the actual +#define COMPARE_REGIONS(ACTUAL, EXPECTED) QVERIFY((EXPECTED).subtracted(ACTUAL).isEmpty()) +#else +#define COMPARE_REGIONS QCOMPARE +#endif static void sendMousePress(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::LeftButton) { @@ -115,6 +121,7 @@ public: } int count() const { return _count; } + void reset() { _count = 0; } protected: bool eventFilter(QObject *watched, QEvent *event) @@ -2203,9 +2210,11 @@ void tst_QGraphicsView::viewportUpdateMode() // The view gets two updates for the update scene updates. QTRY_VERIFY(!view.lastUpdateRegions.isEmpty()); +#ifndef QT_MAC_USE_COCOA //cocoa doesn't support drawing regions QCOMPARE(view.lastUpdateRegions.last().rects().size(), 2); QCOMPARE(view.lastUpdateRegions.last().rects().at(0).size(), QSize(15, 15)); QCOMPARE(view.lastUpdateRegions.last().rects().at(1).size(), QSize(15, 15)); +#endif // Set full update mode. view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); @@ -2938,10 +2947,11 @@ void tst_QGraphicsView::task239729_noViewUpdate() view->show(); QTest::qWaitForWindowShown(view); - QTRY_COMPARE(spy.count(), 1); + QTRY_VERIFY(spy.count() >= 1); + spy.reset(); scene.update(); QApplication::processEvents(); - QTRY_COMPARE(spy.count(), 2); + QTRY_COMPARE(spy.count(), 1); delete view; } @@ -3177,7 +3187,7 @@ void tst_QGraphicsView::moveItemWhileScrolling() int a = adjustForAntialiasing ? 2 : 1; expectedRegion += QRect(40, 50, 10, 10).adjusted(-a, -a, a, a); expectedRegion += QRect(40, 60, 10, 10).adjusted(-a, -a, a, a); - QCOMPARE(view.lastPaintedRegion, expectedRegion); + COMPARE_REGIONS(view.lastPaintedRegion, expectedRegion); } void tst_QGraphicsView::centerOnDirtyItem() @@ -3423,10 +3433,12 @@ void tst_QGraphicsView::exposeRegion() // Make sure it triggers correct repaint on the view. QTRY_COMPARE(view.lastUpdateRegions.size(), 1); - QTRY_COMPARE(view.lastUpdateRegions.at(0), expectedExposeRegion); + COMPARE_REGIONS(view.lastUpdateRegions.at(0), expectedExposeRegion); // Make sure the item didn't get any repaints. +#ifndef QT_MAC_USE_COCOA QCOMPARE(item->paints, 0); +#endif } void tst_QGraphicsView::update_data() diff --git a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp index 26021e0..6b5ad09 100644 --- a/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp @@ -159,6 +159,7 @@ private slots: void ensureClipping(); void widgetSendsGeometryChanges(); void respectHFW(); + void addChildInpolishEvent(); // Task fixes void task236127_bspTreeIndexFails(); @@ -2716,6 +2717,58 @@ void tst_QGraphicsWidget::respectHFW() #endif } +class PolishWidget : public QGraphicsWidget +{ +public: + + PolishWidget(Qt::GlobalColor color, QGraphicsItem *parent=0) : + QGraphicsWidget(parent), mColor(color) + { + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) + { + painter->setBrush(QBrush(mColor)); + painter->drawRect(boundingRect()); + } + + void polishEvent() + { + if (!parentWidget()) { + //We add a child in the polish event for the parent + PolishWidget *childWidget = new PolishWidget(Qt::black, this); + childWidget->setGeometry(QRectF(10,10,30,30)); + } + + QGraphicsWidget::polishEvent(); + mColor = Qt::red; + update(); + numberOfPolish++; + } + + static int numberOfPolish; + +private: + Qt::GlobalColor mColor; +}; + +int PolishWidget::numberOfPolish = 0; + +void tst_QGraphicsWidget::addChildInpolishEvent() +{ + QGraphicsScene scene; + + PolishWidget *parentWidget = new PolishWidget(Qt::white); + scene.addItem(parentWidget); + + QGraphicsView view(&scene); + view.resize(200, 200); + view.show(); + QTest::qWaitForWindowShown(&view); + QCOMPARE(PolishWidget::numberOfPolish, 2); +} + + QTEST_MAIN(tst_QGraphicsWidget) #include "tst_qgraphicswidget.moc" diff --git a/tests/auto/qheaderview/tst_qheaderview.cpp b/tests/auto/qheaderview/tst_qheaderview.cpp index 920231d..3286768 100644 --- a/tests/auto/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/qheaderview/tst_qheaderview.cpp @@ -1836,7 +1836,7 @@ void tst_QHeaderView::preserveHiddenSectionWidth() model.insertRow(1); view.showSection(2); QCOMPARE(view.sectionSize(0), 100); - QCOMPARE(view.sectionSize(1), 30); + QCOMPARE(view.sectionSize(1), view.defaultSectionSize()); QCOMPARE(view.sectionSize(2), 50); } diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index 4eb149f..f12fa92 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -675,7 +675,13 @@ void tst_QMenu::activeSubMenuPosition() #ifdef Q_OS_WINCE_WM QSKIP("Not true for Windows Mobile Soft Keys", SkipSingle); #endif + +#ifdef Q_OS_SYMBIAN + // On Symbian, QS60Style::pixelMetric(QStyle::PM_SubMenuOverlap) is different with other styles. + QVERIFY(sub->pos().x() < main->pos().x()); +#else QVERIFY(sub->pos().x() > main->pos().x()); +#endif QCOMPARE(sub->activeAction(), subAction); } @@ -778,6 +784,11 @@ void tst_QMenu::menuSizeHint() int maxWidth =0; QRect result; foreach(QAction *action, menu.actions()) { +#ifdef QT_SOFTKEYS_ENABLED + // Softkey actions are not widgets and have no geometry. + if (menu.actionGeometry(action).topLeft() == QPoint(0,0)) + continue; +#endif maxWidth = qMax(maxWidth, menu.actionGeometry(action).width()); result |= menu.actionGeometry(action); QCOMPARE(result.x(), left + hmargin + panelWidth); @@ -816,6 +827,9 @@ void tst_QMenu::task258920_mouseBorder() QSKIP("Mouse move related signals for Windows Mobile unavailable", SkipAll); #endif Menu258920 menu; + // On Symbian, styleHint(QStyle::SH_Menu_MouseTracking) in QS60Style is false. + // For other styles which inherit from QWindowsStyle, the value is true. + menu.setMouseTracking(true); QAction *action = menu.addAction("test"); menu.popup(QApplication::desktop()->availableGeometry().center()); 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/qpauseanimation/qpauseanimation.pro b/tests/auto/qpauseanimation/qpauseanimation.pro new file mode 100644 index 0000000..4599cf0 --- /dev/null +++ b/tests/auto/qpauseanimation/qpauseanimation.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +QT = core gui +SOURCES += tst_qpauseanimation.cpp + + diff --git a/tests/auto/qpauseanimation/tst_qpauseanimation.cpp b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp new file mode 100644 index 0000000..62b43c4 --- /dev/null +++ b/tests/auto/qpauseanimation/tst_qpauseanimation.cpp @@ -0,0 +1,409 @@ +/**************************************************************************** +** +** 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 <QtCore/qpauseanimation.h> +#include <QtCore/qpropertyanimation.h> +#include <QtCore/qsequentialanimationgroup.h> + +#include <private/qabstractanimation_p.h> + +//TESTED_CLASS=QPauseAnimation +//TESTED_FILES= + +class TestablePauseAnimation : public QPauseAnimation +{ + Q_OBJECT +public: + TestablePauseAnimation(QObject *parent = 0) + : QPauseAnimation(parent), + m_updateCurrentTimeCount(0) + { + } + + int m_updateCurrentTimeCount; +protected: + void updateCurrentTime(int currentTime) + { + //qDebug() << this << "update current time: " << currentTime; + QPauseAnimation::updateCurrentTime(currentTime); + ++m_updateCurrentTimeCount; + } +}; + +class EnableConsistentTiming +{ +public: + EnableConsistentTiming() + { + QUnifiedTimer *timer = QUnifiedTimer::instance(); + timer->setConsistentTiming(true); + } + ~EnableConsistentTiming() + { + QUnifiedTimer *timer = QUnifiedTimer::instance(); + timer->setConsistentTiming(false); + } +}; + +class tst_QPauseAnimation : public QObject +{ + Q_OBJECT +public: + tst_QPauseAnimation(); + virtual ~tst_QPauseAnimation(); + +public Q_SLOTS: + void init(); + void cleanup(); + +private slots: + void changeDirectionWhileRunning(); + void noTimerUpdates_data(); + void noTimerUpdates(); + void mulitplePauseAnimations(); + void pauseAndPropertyAnimations(); + void pauseResume(); + void sequentialPauseGroup(); + void sequentialGroupWithPause(); + void multipleSequentialGroups(); + void zeroDuration(); +}; + +tst_QPauseAnimation::tst_QPauseAnimation() +{ +} + +tst_QPauseAnimation::~tst_QPauseAnimation() +{ +} + +void tst_QPauseAnimation::init() +{ + qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State"); + qRegisterMetaType<QAbstractAnimation::DeletionPolicy>("QAbstractAnimation::DeletionPolicy"); +} + +void tst_QPauseAnimation::cleanup() +{ +} + +void tst_QPauseAnimation::changeDirectionWhileRunning() +{ + QUnifiedTimer *timer = QUnifiedTimer::instance(); + timer->setConsistentTiming(true); + + TestablePauseAnimation animation; + animation.setDuration(400); + animation.start(); + QTest::qWait(100); + QVERIFY(animation.state() == QAbstractAnimation::Running); + animation.setDirection(QAbstractAnimation::Backward); + QTest::qWait(animation.totalDuration() + 50); + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + + timer->setConsistentTiming(false); +} + +void tst_QPauseAnimation::noTimerUpdates_data() +{ + QTest::addColumn<int>("duration"); + QTest::addColumn<int>("loopCount"); + + QTest::newRow("0") << 200 << 1; + QTest::newRow("1") << 160 << 1; + QTest::newRow("2") << 160 << 2; + QTest::newRow("3") << 200 << 3; +} + +void tst_QPauseAnimation::noTimerUpdates() +{ + QUnifiedTimer *timer = QUnifiedTimer::instance(); + timer->setConsistentTiming(true); + + QFETCH(int, duration); + QFETCH(int, loopCount); + + TestablePauseAnimation animation; + animation.setDuration(duration); + animation.setLoopCount(loopCount); + animation.start(); + QTest::qWait(animation.totalDuration() + 100); + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + QCOMPARE(animation.m_updateCurrentTimeCount, 2); + + timer->setConsistentTiming(false); +} + +void tst_QPauseAnimation::mulitplePauseAnimations() +{ + QUnifiedTimer *timer = QUnifiedTimer::instance(); + timer->setConsistentTiming(true); + + TestablePauseAnimation animation; + animation.setDuration(200); + + TestablePauseAnimation animation2; + animation2.setDuration(800); + + animation.start(); + animation2.start(); + QTest::qWait(animation.totalDuration() + 100); + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + QVERIFY(animation2.state() == QAbstractAnimation::Running); + QCOMPARE(animation.m_updateCurrentTimeCount, 2); + QCOMPARE(animation2.m_updateCurrentTimeCount, 2); + + QTest::qWait(550); + QVERIFY(animation2.state() == QAbstractAnimation::Stopped); + QCOMPARE(animation2.m_updateCurrentTimeCount, 3); + + timer->setConsistentTiming(false); +} + +void tst_QPauseAnimation::pauseAndPropertyAnimations() +{ + EnableConsistentTiming enabled; + + TestablePauseAnimation pause; + pause.setDuration(200); + + QObject o; + o.setProperty("ole", 42); + + QPropertyAnimation animation(&o, "ole"); + animation.setEndValue(43); + + pause.start(); + + QTest::qWait(100); + animation.start(); + + QVERIFY(animation.state() == QAbstractAnimation::Running); + QVERIFY(pause.state() == QAbstractAnimation::Running); + QCOMPARE(pause.m_updateCurrentTimeCount, 2); + + QTest::qWait(animation.totalDuration() + 100); + +#ifdef Q_OS_WIN + if (animation.state() != QAbstractAnimation::Stopped) + QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort); +#endif + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + QVERIFY(pause.state() == QAbstractAnimation::Stopped); + QVERIFY(pause.m_updateCurrentTimeCount > 3); +} + +void tst_QPauseAnimation::pauseResume() +{ + TestablePauseAnimation animation; + animation.setDuration(400); + animation.start(); + QVERIFY(animation.state() == QAbstractAnimation::Running); + QTest::qWait(200); + animation.pause(); + QVERIFY(animation.state() == QAbstractAnimation::Paused); + animation.start(); + QTest::qWait(250); + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + QCOMPARE(animation.m_updateCurrentTimeCount, 3); +} + +void tst_QPauseAnimation::sequentialPauseGroup() +{ + QSequentialAnimationGroup group; + + TestablePauseAnimation animation1(&group); + animation1.setDuration(200); + TestablePauseAnimation animation2(&group); + animation2.setDuration(200); + TestablePauseAnimation animation3(&group); + animation3.setDuration(200); + + group.start(); + + QVERIFY(group.state() == QAbstractAnimation::Running); + QVERIFY(animation1.state() == QAbstractAnimation::Running); + QVERIFY(animation2.state() == QAbstractAnimation::Stopped); + QVERIFY(animation3.state() == QAbstractAnimation::Stopped); + + group.setCurrentTime(250); + + QVERIFY(group.state() == QAbstractAnimation::Running); + QVERIFY(animation1.state() == QAbstractAnimation::Stopped); + QCOMPARE(&animation2, group.currentAnimation()); + QVERIFY(animation2.state() == QAbstractAnimation::Running); + QVERIFY(animation3.state() == QAbstractAnimation::Stopped); + + group.setCurrentTime(500); + + QVERIFY(group.state() == QAbstractAnimation::Running); + QVERIFY(animation1.state() == QAbstractAnimation::Stopped); + QVERIFY(animation2.state() == QAbstractAnimation::Stopped); + QCOMPARE(&animation3, group.currentAnimation()); + QVERIFY(animation3.state() == QAbstractAnimation::Running); + + group.setCurrentTime(750); + + QVERIFY(group.state() == QAbstractAnimation::Stopped); + QVERIFY(animation1.state() == QAbstractAnimation::Stopped); + QVERIFY(animation2.state() == QAbstractAnimation::Stopped); + QVERIFY(animation3.state() == QAbstractAnimation::Stopped); + + QCOMPARE(animation1.m_updateCurrentTimeCount, 2); + QCOMPARE(animation2.m_updateCurrentTimeCount, 2); + QCOMPARE(animation3.m_updateCurrentTimeCount, 2); +} + +void tst_QPauseAnimation::sequentialGroupWithPause() +{ + QSequentialAnimationGroup group; + + QObject o; + o.setProperty("ole", 42); + + QPropertyAnimation animation(&o, "ole", &group); + animation.setEndValue(43); + TestablePauseAnimation pause(&group); + pause.setDuration(250); + + group.start(); + + QVERIFY(group.state() == QAbstractAnimation::Running); + QVERIFY(animation.state() == QAbstractAnimation::Running); + QVERIFY(pause.state() == QAbstractAnimation::Stopped); + + group.setCurrentTime(300); + + QVERIFY(group.state() == QAbstractAnimation::Running); + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + QCOMPARE(&pause, group.currentAnimation()); + QVERIFY(pause.state() == QAbstractAnimation::Running); + + group.setCurrentTime(600); + + QVERIFY(group.state() == QAbstractAnimation::Stopped); + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + QVERIFY(pause.state() == QAbstractAnimation::Stopped); + + QCOMPARE(pause.m_updateCurrentTimeCount, 2); +} + +void tst_QPauseAnimation::multipleSequentialGroups() +{ + EnableConsistentTiming enabled; + + QParallelAnimationGroup group; + group.setLoopCount(2); + + QSequentialAnimationGroup subgroup1(&group); + + QObject o; + o.setProperty("ole", 42); + + QPropertyAnimation animation(&o, "ole", &subgroup1); + animation.setEndValue(43); + animation.setDuration(300); + TestablePauseAnimation pause(&subgroup1); + pause.setDuration(200); + + QSequentialAnimationGroup subgroup2(&group); + + o.setProperty("ole2", 42); + QPropertyAnimation animation2(&o, "ole2", &subgroup2); + animation2.setEndValue(43); + animation2.setDuration(200); + TestablePauseAnimation pause2(&subgroup2); + pause2.setDuration(250); + + QSequentialAnimationGroup subgroup3(&group); + + TestablePauseAnimation pause3(&subgroup3); + pause3.setDuration(400); + + o.setProperty("ole3", 42); + QPropertyAnimation animation3(&o, "ole3", &subgroup3); + animation3.setEndValue(43); + animation3.setDuration(200); + + QSequentialAnimationGroup subgroup4(&group); + + TestablePauseAnimation pause4(&subgroup4); + pause4.setDuration(310); + + TestablePauseAnimation pause5(&subgroup4); + pause5.setDuration(60); + + group.start(); + + QVERIFY(group.state() == QAbstractAnimation::Running); + QVERIFY(subgroup1.state() == QAbstractAnimation::Running); + QVERIFY(subgroup2.state() == QAbstractAnimation::Running); + QVERIFY(subgroup3.state() == QAbstractAnimation::Running); + QVERIFY(subgroup4.state() == QAbstractAnimation::Running); + + QTest::qWait(group.totalDuration() + 100); + +#ifdef Q_OS_WIN + if (group.state() != QAbstractAnimation::Stopped) + QEXPECT_FAIL("", "On windows, consistent timing is not working properly due to bad timer resolution", Abort); +#endif + QVERIFY(group.state() == QAbstractAnimation::Stopped); + QVERIFY(subgroup1.state() == QAbstractAnimation::Stopped); + QVERIFY(subgroup2.state() == QAbstractAnimation::Stopped); + QVERIFY(subgroup3.state() == QAbstractAnimation::Stopped); + QVERIFY(subgroup4.state() == QAbstractAnimation::Stopped); + + QCOMPARE(pause5.m_updateCurrentTimeCount, 4); +} + +void tst_QPauseAnimation::zeroDuration() +{ + TestablePauseAnimation animation; + animation.start(); + QTest::qWait(animation.totalDuration() + 100); + QVERIFY(animation.state() == QAbstractAnimation::Stopped); + QCOMPARE(animation.m_updateCurrentTimeCount, 1); +} + +QTEST_MAIN(tst_QPauseAnimation) +#include "tst_qpauseanimation.moc" 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 55da180..d75cfa7 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -100,6 +100,9 @@ private slots: void moveCursor_data(); void moveCursor(); + void moveCursorStrikesBack_data(); + void moveCursorStrikesBack(); + void hideRows_data(); void hideRows(); @@ -190,6 +193,7 @@ private slots: void mouseWheel(); void addColumnWhileEditing(); + void task234926_setHeaderSorting(); }; // Testing get/set functions @@ -252,12 +256,43 @@ public: row_count(rows), column_count(columns), can_fetch_more(false), - fetch_more_count(0) {} + fetch_more_count(0), + disabled_rows(), + disabled_columns() {} int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } bool isEditable(const QModelIndex &) const { return true; } + Qt::ItemFlags flags(const QModelIndex &index) const + { + Qt::ItemFlags index_flags = QAbstractTableModel::flags(index); + if (disabled_rows.contains(index.row()) + || disabled_columns.contains(index.column())) + index_flags &= ~Qt::ItemIsEnabled; + return index_flags; + } + + void disableRow(int row) + { + disabled_rows.insert(row); + } + + void enableRow(int row) + { + disabled_rows.remove(row); + } + + void disableColumn(int column) + { + disabled_columns.insert(column); + } + + void enableColumn(int column) + { + disabled_columns.remove(column); + } + QVariant data(const QModelIndex &idx, int role) const { if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { @@ -363,6 +398,8 @@ public: int column_count; bool can_fetch_more; int fetch_more_count; + QSet<int> disabled_rows; + QSet<int> disabled_columns; }; class QtTestTableView : public QTableView @@ -834,7 +871,7 @@ void tst_QTableView::moveCursor_data() << 4 << 4 << -1 << 2 << 0 << 2 << int(QtTestTableView::MoveNext) << int(Qt::NoModifier) - << 1 << 0 << IntPair(0,0) << IntPair(3,0); + << 1 << 3 << IntPair(0,0) << IntPair(3,0); // MoveLeft QTest::newRow("MoveLeft (0,0)") @@ -1137,6 +1174,132 @@ void tst_QTableView::moveCursor() QCOMPARE(newIndex.column(), expectedColumn); } +void tst_QTableView::moveCursorStrikesBack_data() +{ + QTest::addColumn<int>("hideRow"); + QTest::addColumn<int>("hideColumn"); + QTest::addColumn<IntList>("disableRows"); + QTest::addColumn<IntList>("disableColumns"); + QTest::addColumn<QRect>("span"); + + QTest::addColumn<int>("startRow"); + QTest::addColumn<int>("startColumn"); + QTest::addColumn<IntList>("cursorMoveActions"); + QTest::addColumn<int>("expectedRow"); + QTest::addColumn<int>("expectedColumn"); + + QTest::newRow("Last column disabled. Task QTBUG-3878") << -1 << -1 + << IntList() + << (IntList() << 6) + << QRect() + << 0 << 5 << (IntList() << int(QtTestTableView::MoveNext)) + << 1 << 0; + + QTest::newRow("Span, anchor column hidden") << -1 << 1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 2; + + QTest::newRow("Span, anchor column disabled") << -1 << -1 + << IntList() + << (IntList() << 1) + << QRect(1, 2, 2, 3) + << 2 << 0 << (IntList() << int(QtTestTableView::MoveNext)) + << 2 << 2; + + QTest::newRow("Span, anchor row hidden") << 2 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 3 << 2; + + QTest::newRow("Span, anchor row disabled") << -1 << -1 + << (IntList() << 2) + << IntList() + << QRect(1, 2, 2, 3) + << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown)) + << 3 << 2; + + QTest::newRow("Move through span right") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 3 << 0 << (IntList() << int(QtTestTableView::MoveRight) << int(QtTestTableView::MoveRight)) + << 3 << 3; + + QTest::newRow("Move through span left") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 3 << 3 << (IntList() << int(QtTestTableView::MoveLeft) << int(QtTestTableView::MoveLeft)) + << 3 << 0; + + QTest::newRow("Move through span down") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 1 << 2 << (IntList() << int(QtTestTableView::MoveDown) << int(QtTestTableView::MoveDown)) + << 5 << 2; + + QTest::newRow("Move through span up") << -1 << -1 + << IntList() + << IntList() + << QRect(1, 2, 2, 3) + << 5 << 2 << (IntList() << int(QtTestTableView::MoveUp) << int(QtTestTableView::MoveUp)) + << 1 << 2; +} + +void tst_QTableView::moveCursorStrikesBack() +{ + QFETCH(int, hideRow); + QFETCH(int, hideColumn); + QFETCH(IntList, disableRows); + QFETCH(IntList, disableColumns); + QFETCH(QRect, span); + + QFETCH(int, startRow); + QFETCH(int, startColumn); + QFETCH(IntList, cursorMoveActions); + QFETCH(int, expectedRow); + QFETCH(int, expectedColumn); + + QtTestTableModel model(7, 7); + QtTestTableView view; + view.setModel(&model); + view.hideRow(hideRow); + view.hideColumn(hideColumn); + + foreach (int row, disableRows) + model.disableRow(row); + foreach (int column, disableColumns) + model.disableColumn(column); + + if (span.height() && span.width()) + view.setSpan(span.top(), span.left(), span.height(), span.width()); + view.show(); + + QModelIndex index = model.index(startRow, startColumn); + view.setCurrentIndex(index); + + int newRow = -1; + int newColumn = -1; + foreach (int cursorMoveAction, cursorMoveActions) { + QModelIndex newIndex = view.moveCursor((QtTestTableView::CursorAction)cursorMoveAction, 0); + view.setCurrentIndex(newIndex); + newRow = newIndex.row(); + newColumn = newIndex.column(); + } + + // expected fails, task 119433 + if(newRow == -1) + return; + QCOMPARE(newRow, expectedRow); + QCOMPARE(newColumn, expectedColumn); +} + void tst_QTableView::hideRows_data() { QTest::addColumn<int>("rowCount"); @@ -2540,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); @@ -2555,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); @@ -3087,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. @@ -3612,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/qtreewidget/tst_qtreewidget.cpp b/tests/auto/qtreewidget/tst_qtreewidget.cpp index 11c4543..6defd7b 100644 --- a/tests/auto/qtreewidget/tst_qtreewidget.cpp +++ b/tests/auto/qtreewidget/tst_qtreewidget.cpp @@ -49,6 +49,9 @@ #include <qheaderview.h> #include <qlineedit.h> #include <QScrollBar> +#include <QStyledItemDelegate> + +#include "../../shared/util.h" //TESTED_CLASS= @@ -163,6 +166,7 @@ private slots: void task217309(); void setCurrentItemExpandsParent(); void task239150_editorWidth(); + void setTextUpdate(); public slots: void itemSelectionChanged(); @@ -3233,6 +3237,41 @@ void tst_QTreeWidget::task239150_editorWidth() +void tst_QTreeWidget::setTextUpdate() +{ + QTreeWidget treeWidget; + treeWidget.setColumnCount(2); + + class MyItemDelegate : public QStyledItemDelegate + { + public: + MyItemDelegate() : numPaints(0) { } + void paint(QPainter *painter, + const QStyleOptionViewItem &option, const QModelIndex &index) const + { + numPaints++; + QStyledItemDelegate::paint(painter, option, index); + } + + mutable int numPaints; + } delegate; + + treeWidget.setItemDelegate(&delegate); + treeWidget.show(); + QStringList strList; + strList << "variable1" << "0"; + QTreeWidgetItem *item = new QTreeWidgetItem(strList); + treeWidget.insertTopLevelItem(0, item); + QTest::qWait(50); + QTRY_VERIFY(delegate.numPaints > 0); + delegate.numPaints = 0; + + item->setText(1, "42"); + QApplication::processEvents(); + QTRY_VERIFY(delegate.numPaints > 0); +} + + QTEST_MAIN(tst_QTreeWidget) #include "tst_qtreewidget.moc" diff --git a/tests/auto/qurl/tst_qurl.cpp b/tests/auto/qurl/tst_qurl.cpp index 026c30e..72c13bf 100644 --- a/tests/auto/qurl/tst_qurl.cpp +++ b/tests/auto/qurl/tst_qurl.cpp @@ -137,6 +137,7 @@ private slots: void ipv6(); void ipv6_2_data(); void ipv6_2(); + void moreIpv6(); void toPercentEncoding_data(); void toPercentEncoding(); void isRelative_data(); @@ -2276,6 +2277,13 @@ void tst_QUrl::ipv6_2() QCOMPARE(url.toString(), output); } +void tst_QUrl::moreIpv6() +{ + QUrl waba1("http://www.kde.org/cgi/test.cgi"); + waba1.setHost("::ffff:129.144.52.38"); + QCOMPARE(QString::fromLatin1(waba1.toEncoded()), QString::fromLatin1("http://[::ffff:129.144.52.38]/cgi/test.cgi")); +} + void tst_QUrl::punycode_data() { QTest::addColumn<QString>("original"); diff --git a/tests/auto/quuid/tst_quuid.cpp b/tests/auto/quuid/tst_quuid.cpp index e262be7..d78fda5 100644 --- a/tests/auto/quuid/tst_quuid.cpp +++ b/tests/auto/quuid/tst_quuid.cpp @@ -72,6 +72,8 @@ private slots: void variants(); void versions(); + void threadUniqueness(); + public: // Variables QUuid uuidA; @@ -169,6 +171,30 @@ void tst_QUuid::versions() QVERIFY( NCS.version() == QUuid::VerUnknown ); } +class UuidThread : public QThread +{ +public: + QUuid uuid; + + void run() + { + uuid = QUuid::createUuid(); + } +}; + +void tst_QUuid::threadUniqueness() +{ + QVector<UuidThread *> threads(qMax(2, QThread::idealThreadCount())); + for (int i = 0; i < threads.count(); ++i) + threads[i] = new UuidThread; + for (int i = 0; i < threads.count(); ++i) + threads[i]->start(); + for (int i = 0; i < threads.count(); ++i) + QVERIFY(threads[i]->wait(1000)); + for (int i = 1; i < threads.count(); ++i) + QVERIFY(threads[0]->uuid != threads[i]->uuid); + qDeleteAll(threads); +} QTEST_MAIN(tst_QUuid) #include "tst_quuid.moc" diff --git a/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp b/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp index bc6fe68..9623e80 100644 --- a/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp +++ b/tests/auto/qvideosurfaceformat/tst_qvideosurfaceformat.cpp @@ -120,7 +120,7 @@ void tst_QVideoSurfaceFormat::constructNull() QCOMPARE(format.frameHeight(), -1); QCOMPARE(format.viewport(), QRect()); QCOMPARE(format.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); - QCOMPARE(format.frameRate(), QVideoSurfaceFormat::FrameRate()); + QCOMPARE(format.frameRate(), 0.0); QCOMPARE(format.pixelAspectRatio(), QSize(1, 1)); QCOMPARE(format.yuvColorSpace(), QVideoSurfaceFormat::YCbCr_Undefined); } @@ -159,7 +159,7 @@ void tst_QVideoSurfaceFormat::construct() QCOMPARE(format.frameHeight(), frameSize.height()); QCOMPARE(format.viewport(), viewport); QCOMPARE(format.scanLineDirection(), QVideoSurfaceFormat::TopToBottom); - QCOMPARE(format.frameRate(), QVideoSurfaceFormat::FrameRate()); + QCOMPARE(format.frameRate(), 0.0); QCOMPARE(format.pixelAspectRatio(), QSize(1, 1)); QCOMPARE(format.yuvColorSpace(), QVideoSurfaceFormat::YCbCr_Undefined); } @@ -315,21 +315,21 @@ void tst_QVideoSurfaceFormat::scanLineDirection() void tst_QVideoSurfaceFormat::frameRate_data() { - QTest::addColumn<QVideoSurfaceFormat::FrameRate>("frameRate"); + QTest::addColumn<qreal>("frameRate"); QTest::newRow("null") - << QVideoSurfaceFormat::FrameRate(0, 0); + << 0.0; QTest::newRow("1/1") - << QVideoSurfaceFormat::FrameRate(1, 1); + << 1.0; QTest::newRow("24/1") - << QVideoSurfaceFormat::FrameRate(24, 1); + << 24.0; QTest::newRow("15/2") - << QVideoSurfaceFormat::FrameRate(15, 2); + << 7.5; } void tst_QVideoSurfaceFormat::frameRate() { - QFETCH(QVideoSurfaceFormat::FrameRate, frameRate); + QFETCH(qreal, frameRate); { QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); @@ -337,29 +337,16 @@ void tst_QVideoSurfaceFormat::frameRate() format.setFrameRate(frameRate); QCOMPARE(format.frameRate(), frameRate); - QCOMPARE(qvariant_cast<QVideoSurfaceFormat::FrameRate>(format.property("frameRate")), - frameRate); - } - { - QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); - - format.setFrameRate(frameRate.first, frameRate.second); - - QCOMPARE(format.frameRate(), frameRate); - QCOMPARE( - qvariant_cast<QVideoSurfaceFormat::FrameRate>(format.property("frameRate")), - frameRate); + QCOMPARE(qvariant_cast<qreal>(format.property("frameRate")), frameRate); } { QVideoSurfaceFormat format(QSize(64, 64), QVideoFrame::Format_RGB32); format.setFrameRate(frameRate); - format.setProperty( - "frameRate", qVariantFromValue<QVideoSurfaceFormat::FrameRate>(frameRate)); + format.setProperty("frameRate", frameRate); QCOMPARE(format.frameRate(), frameRate); - QCOMPARE(qvariant_cast<QVideoSurfaceFormat::FrameRate>(format.property("frameRate")), - frameRate); + QCOMPARE(qvariant_cast<qreal>(format.property("frameRate")), frameRate); } } @@ -609,13 +596,13 @@ void tst_QVideoSurfaceFormat::compare() QCOMPARE(format1 == format2, true); QCOMPARE(format1 != format2, false); - format1.setFrameRate(QVideoSurfaceFormat::FrameRate(15, 2)); + format1.setFrameRate(7.5); // Not equal frame rate differs. QCOMPARE(format1 == format2, false); QCOMPARE(format1 != format2, true); - format2.setFrameRate(15, 2); + format2.setFrameRate(7.50001); // Equal. QCOMPARE(format1 == format2, true); diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index f8341c3..758821b 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -239,7 +239,12 @@ private slots: void setFixedSize(); void ensureCreated(); + void winIdChangeEvent(); +#ifdef Q_OS_SYMBIAN + void reparentCausesChildWinIdChange(); +#else void persistentWinId(); +#endif void qobject_castInDestroyedSlot(); void showHideEvent_data(); @@ -4348,6 +4353,144 @@ void tst_QWidget::ensureCreated() } } +class WinIdChangeWidget : public QWidget { +public: + WinIdChangeWidget(QWidget *p = 0) + : QWidget(p) + , m_winIdChangeEventCount(0) + { + + } +protected: + bool event(QEvent *e){ + if(e->type() == QEvent::WinIdChange) + ++m_winIdChangeEventCount; + else + return QWidget::event(e); + } +public: + int m_winIdChangeEventCount; +}; + +void tst_QWidget::winIdChangeEvent() +{ + { + // Transforming an alien widget into a native widget + WinIdChangeWidget widget; + const WId winIdBefore = widget.internalWinId(); + const WId winIdAfter = widget.winId(); + QVERIFY(winIdBefore != winIdAfter); + QCOMPARE(widget.m_winIdChangeEventCount, 1); + } + + { + // Changing parent of a native widget + QWidget parent1, parent2; + WinIdChangeWidget child(&parent1); + const WId winIdBefore = child.winId(); + QCOMPARE(child.m_winIdChangeEventCount, 1); + child.setParent(&parent2); + const WId winIdAfter = child.internalWinId(); +#ifdef Q_OS_SYMBIAN + QVERIFY(winIdBefore != winIdAfter); + QCOMPARE(child.m_winIdChangeEventCount, 2); +#else + QCOMPARE(winIdBefore, winIdAfter); + QCOMPARE(child.m_winIdChangeEventCount, 1); +#endif + } + + { + // Changing parent of an alien widget + QWidget parent1, parent2; + WinIdChangeWidget child(&parent1); + const WId winIdBefore = child.internalWinId(); + child.setParent(&parent2); + const WId winIdAfter = child.internalWinId(); + QCOMPARE(winIdBefore, winIdAfter); + QCOMPARE(child.m_winIdChangeEventCount, 0); + } + + { + // Making native child widget into a top-level window + QWidget parent; + WinIdChangeWidget child(&parent); + child.winId(); + const WId winIdBefore = child.internalWinId(); + QCOMPARE(child.m_winIdChangeEventCount, 1); + const Qt::WindowFlags flags = child.windowFlags(); + child.setWindowFlags(flags | Qt::Window); + const WId winIdAfter = child.internalWinId(); + QVERIFY(winIdBefore != winIdAfter); + QCOMPARE(child.m_winIdChangeEventCount, 2); + } +} + +#ifdef Q_OS_SYMBIAN +void tst_QWidget::reparentCausesChildWinIdChange() +{ + QWidget *parent = new QWidget; + QWidget *w1 = new QWidget; + QWidget *w2 = new QWidget; + QWidget *w3 = new QWidget; + w1->setParent(parent); + w2->setParent(w1); + w3->setParent(w2); + + WId winId1 = w1->winId(); + WId winId2 = w2->winId(); + WId winId3 = w3->winId(); + + // reparenting causes winIds of the widget being reparented, and all of its children, to change + w1->setParent(0); + QVERIFY(w1->winId() != winId1); + winId1 = w1->winId(); + QVERIFY(w2->winId() != winId2); + winId2 = w2->winId(); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + w1->setParent(parent); + QVERIFY(w1->winId() != winId1); + winId1 = w1->winId(); + QVERIFY(w2->winId() != winId2); + winId2 = w2->winId(); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + w2->setParent(0); + QVERIFY(w2->winId() != winId2); + winId2 = w2->winId(); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + w2->setParent(parent); + QVERIFY(w2->winId() != winId2); + winId2 = w2->winId(); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + w2->setParent(w1); + QVERIFY(w2->winId() != winId2); + winId2 = w2->winId(); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + w3->setParent(0); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + w3->setParent(w1); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + w3->setParent(w2); + QVERIFY(w3->winId() != winId3); + winId3 = w3->winId(); + + delete parent; +} +#else void tst_QWidget::persistentWinId() { QWidget *parent = new QWidget; @@ -4404,6 +4547,7 @@ void tst_QWidget::persistentWinId() delete parent; } +#endif // Q_OS_SYMBIAN class ShowHideEventWidget : public QWidget { @@ -4524,9 +4668,6 @@ void tst_QWidget::update() QCOMPARE(child.paintedRegion, child.visibleRegion()); QCOMPARE(w.numPaintEvents, 1); QCOMPARE(w.visibleRegion(), QRegion(w.rect())); -#ifdef QT_MAC_USE_COCOA - QEXPECT_FAIL(0, "Cocoa compositor paints the content view", Continue); -#endif QCOMPARE(w.paintedRegion, child.visibleRegion().translated(childOffset)); w.reset(); @@ -5136,15 +5277,6 @@ void tst_QWidget::windowMoveResize() // now hide widget.hide(); QTest::qWait(10); -#if defined (Q_WS_MAC) && defined(QT_MAC_USE_COCOA) - QEXPECT_FAIL("130,100 0x200, flags 800", - "Cocoa's Delegate sends a spurios move event when the window has a width of zero and non-zero height", - Abort); - - QEXPECT_FAIL("130,100 0x200, flags 0", - "Cocoa's Delegate sends a spurios move event when the window has a width of zero and non-zero height", - Abort); -#endif QTRY_COMPARE(widget.pos(), rect.topLeft()); QTRY_COMPARE(widget.size(), rect.size()); @@ -7466,8 +7598,8 @@ void tst_QWidget::updateWhileMinimized() UpdateWidget widget; // Filter out activation change and focus events to avoid update() calls in QWidget. widget.updateOnActivationChangeAndFocusIn = false; - widget.show(); widget.reset(); + widget.show(); QTest::qWaitForWindowShown(&widget); QApplication::processEvents(); QTRY_VERIFY(widget.numPaintEvents > 0); @@ -9267,7 +9399,8 @@ void tst_QWidget::rectOutsideCoordinatesLimit_task144779() QPixmap correct(main.size()); correct.fill(Qt::green); - QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage(), correct.toImage()); + QTRY_COMPARE(QPixmap::grabWindow(main.winId()).toImage().convertToFormat(QImage::Format_RGB32), + correct.toImage().convertToFormat(QImage::Format_RGB32)); QApplication::restoreOverrideCursor(); } diff --git a/tests/auto/qwidgetaction/tst_qwidgetaction.cpp b/tests/auto/qwidgetaction/tst_qwidgetaction.cpp index 586a707..50b3337 100644 --- a/tests/auto/qwidgetaction/tst_qwidgetaction.cpp +++ b/tests/auto/qwidgetaction/tst_qwidgetaction.cpp @@ -125,6 +125,7 @@ void tst_QWidgetAction::defaultWidget() tb1.addAction(action); QVERIFY(combo->parent() == &tb1); qApp->processEvents(); + qApp->processEvents(); QVERIFY(combo->isVisible()); // not supported, not supposed to work, hence the parent() check @@ -139,6 +140,7 @@ void tst_QWidgetAction::defaultWidget() tb2.addAction(action); qApp->processEvents(); //the call to hide is delayd by the toolbar layout + qApp->processEvents(); QVERIFY(combo->parent() == &tb2); QVERIFY(combo->isVisible()); diff --git a/tests/manual/gestures/graphicsview/gestures.cpp b/tests/manual/gestures/graphicsview/gestures.cpp index c888aa1..5416457 100644 --- a/tests/manual/gestures/graphicsview/gestures.cpp +++ b/tests/manual/gestures/graphicsview/gestures.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** 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 "gestures.h" #include <QTouchEvent> diff --git a/tests/manual/gestures/graphicsview/gestures.h b/tests/manual/gestures/graphicsview/gestures.h index 630a7ef..6140b12 100644 --- a/tests/manual/gestures/graphicsview/gestures.h +++ b/tests/manual/gestures/graphicsview/gestures.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + #ifndef GESTURE_H #define GESTURE_H diff --git a/tests/manual/gestures/graphicsview/imageitem.cpp b/tests/manual/gestures/graphicsview/imageitem.cpp index d6f406c..307d7e4 100644 --- a/tests/manual/gestures/graphicsview/imageitem.cpp +++ b/tests/manual/gestures/graphicsview/imageitem.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** 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 "imageitem.h" #include "gestures.h" diff --git a/tests/manual/gestures/graphicsview/imageitem.h b/tests/manual/gestures/graphicsview/imageitem.h index ad0e397..776c8d1 100644 --- a/tests/manual/gestures/graphicsview/imageitem.h +++ b/tests/manual/gestures/graphicsview/imageitem.h @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + #ifndef IMAGEITEM_H #define IMAGEITEM_H diff --git a/tests/manual/gestures/graphicsview/main.cpp b/tests/manual/gestures/graphicsview/main.cpp index 1db5614..263a963 100644 --- a/tests/manual/gestures/graphicsview/main.cpp +++ b/tests/manual/gestures/graphicsview/main.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** 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 <QtGui> #include "imageitem.h" diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp index f89f247..0e7f538 100644 --- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the examples of the Qt Toolkit. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h index e31799e..b062fd0 100644 --- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h +++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the examples of the Qt Toolkit. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/gestures/scrollarea/main.cpp b/tests/manual/gestures/scrollarea/main.cpp index e2fa4d3..2796637 100644 --- a/tests/manual/gestures/scrollarea/main.cpp +++ b/tests/manual/gestures/scrollarea/main.cpp @@ -1,3 +1,44 @@ +/**************************************************************************** +** +** 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 <QtGui> #include "mousepangesturerecognizer.h" diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp index 6e2171c..79b633e 100644 --- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp +++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the examples of the Qt Toolkit. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h index f6df289..c92d477 100644 --- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h +++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h @@ -4,7 +4,7 @@ ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** -** This file is part of the examples of the Qt Toolkit. +** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** No Commercial Usage |