From e2c0d1ea2e0c35a3899283237ede02b4f49aa5b3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 17 Jan 2017 10:40:01 -0800 Subject: Read the .ini file back in text mode Because on Windows, the .ini files are saved with CRLF, but the files in the Qt resource are just LF (.gitattributes makes them so). Task-number: QTBUG-25446 Change-Id: I5eab0d9620bd1ba675b0a87c554f62cef0f98fcc Reviewed-by: Mitch Curtis Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index dadf4b612e..f94349fd02 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -2315,14 +2315,14 @@ void tst_QSettings::setIniCodec() { QFile inFile(settings4.fileName()); - inFile.open(QIODevice::ReadOnly); + inFile.open(QIODevice::ReadOnly | QIODevice::Text); actualContents4 = inFile.readAll(); inFile.close(); } { QFile inFile(settings5.fileName()); - inFile.open(QIODevice::ReadOnly); + inFile.open(QIODevice::ReadOnly | QIODevice::Text); actualContents5 = inFile.readAll(); inFile.close(); } @@ -2330,9 +2330,6 @@ void tst_QSettings::setIniCodec() QConfFile::clearCache(); -#ifdef Q_OS_WIN - QEXPECT_FAIL("", "QTBUG-25446", Abort); -#endif QCOMPARE(actualContents4, expeContents4); QCOMPARE(actualContents5, expeContents5); -- cgit v1.2.3 From 41e4b4de91227c12e50559ae74d3834e91eebc0b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Fri, 20 Jan 2017 14:55:41 +0100 Subject: QtGui/painting benchmark test: Fix Clang warning about uninitialized value benchmarktests.h:323:18: warning: field 'm_as_pixmap' is uninitialized when used here [-Wuninitialized] benchmarktests.h:371:18: warning: field 'm_as_pixmap' is uninitialized when used here [-Wuninitialized] benchmarktests.h:417:18: warning: field 'm_as_pixmap' is uninitialized when used here [-Wuninitialized] Change-Id: Ica496e3baa19e0701c64222ce8ab92ec94178db7 Reviewed-by: Eskil Abrahamsen Blomfeldt --- tests/benchmarks/gui/painting/qtbench/benchmarktests.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h index c69fca68bc..e4b98336c7 100644 --- a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h +++ b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h @@ -320,7 +320,7 @@ public: DrawScaledImage(const QImage &image, qreal scale, bool asPixmap) : Benchmark(QSize(image.width(), image.height())), m_image(image), - m_type(m_as_pixmap ? "Pixmap" : "Image"), + m_type(asPixmap ? "Pixmap" : "Image"), m_scale(scale), m_as_pixmap(asPixmap) { @@ -368,7 +368,7 @@ public: DrawTransformedImage(const QImage &image, bool asPixmap) : Benchmark(QSize(image.width(), image.height())), m_image(image), - m_type(m_as_pixmap ? "Pixmap" : "Image"), + m_type(asPixmap ? "Pixmap" : "Image"), m_as_pixmap(asPixmap) { m_pixmap = QPixmap::fromImage(m_image); @@ -414,7 +414,7 @@ public: DrawImage(const QImage &image, bool asPixmap) : Benchmark(QSize(image.width(), image.height())), m_image(image), - m_type(m_as_pixmap ? "Pixmap" : "Image"), + m_type(asPixmap ? "Pixmap" : "Image"), m_as_pixmap(asPixmap) { m_pixmap = QPixmap::fromImage(image); -- cgit v1.2.3 From 14f09643441cc2938dc2791e790f6309ab12cb1d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 19 Sep 2016 13:13:44 -0700 Subject: QVariant: don't do fuzzy comparisons with NaN and infinities There was a test that tested this, but was wrong. [ChangeLog][QtCore][QVariant] Fixed a bug that caused wrong results for comparisons of QVariants containing either NaN or infinite numbers. Task-number: QTBUG-56073 Change-Id: I33dc971f005a4848bb8ffffd1475d29d00dd1b7f Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 3a51e67768..442f7e80d1 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -1755,6 +1755,10 @@ void tst_QVariant::compareNumbers_data() const QTest::newRow("double5") << qVariantFromValue(0.) << qVariantFromValue(-qInf()) << +1; QTest::newRow("double6") << qVariantFromValue(-double(qInf())) << qVariantFromValue(-qInf()) << 0; QTest::newRow("double7") << qVariantFromValue(qInf()) << qVariantFromValue(qInf()) << 0; + QTest::newRow("double8") << qVariantFromValue(-qInf()) << qVariantFromValue(qInf()) << -1; + QTest::newRow("double9") << qVariantFromValue(qQNaN()) << qVariantFromValue(0.) << INT_MAX; + QTest::newRow("double10") << qVariantFromValue(0.) << qVariantFromValue(qQNaN()) << INT_MAX; + QTest::newRow("double11") << qVariantFromValue(qQNaN()) << qVariantFromValue(qQNaN()) << INT_MAX; // mixed comparisons // fp + fp @@ -1763,8 +1767,12 @@ void tst_QVariant::compareNumbers_data() const QTest::newRow("float+double3") << qVariantFromValue(0.f) << qVariantFromValue(-1.) << +1; QTest::newRow("float+double4") << qVariantFromValue(-float(qInf())) << qVariantFromValue(0.) << -1; QTest::newRow("float+double5") << qVariantFromValue(0.f) << qVariantFromValue(-qInf()) << +1; - QTest::newRow("float+double6") << qVariantFromValue(-float(qInf())) << qVariantFromValue(qInf()) << 0; + QTest::newRow("float+double6") << qVariantFromValue(-float(qInf())) << qVariantFromValue(-qInf()) << 0; QTest::newRow("float+double7") << qVariantFromValue(float(qInf())) << qVariantFromValue(qInf()) << 0; + QTest::newRow("float+double8") << qVariantFromValue(-float(qInf())) << qVariantFromValue(qInf()) << -1; + QTest::newRow("float+double9") << qVariantFromValue(qQNaN()) << qVariantFromValue(0.) << INT_MAX; + QTest::newRow("float+double10") << qVariantFromValue(0.) << qVariantFromValue(qQNaN()) << INT_MAX; + QTest::newRow("float+double11") << qVariantFromValue(qQNaN()) << qVariantFromValue(qQNaN()) << INT_MAX; // fp + int QTest::newRow("float+int1") << qVariantFromValue(0.f) << qVariantFromValue(0) << 0; @@ -1978,7 +1986,7 @@ void tst_QVariant::compareNumbers() const QCOMPARE(v2, v1); QVERIFY(v2 >= v1); QVERIFY(!(v2 > v1)); - } else { + } else if (expected == +1) { QVERIFY(!(v1 < v2)); QVERIFY(!(v1 <= v2)); QVERIFY(!(v1 == v2)); @@ -1990,6 +1998,9 @@ void tst_QVariant::compareNumbers() const QVERIFY(!(v2 == v1)); QVERIFY(!(v2 >= v1)); QVERIFY(!(v2 > v1)); + } else { + // unorderable (NaN) + QVERIFY(!(v1 == v2)); } } -- cgit v1.2.3 From 61371f0321e02b9835baecf4d635925aaf41e307 Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 16 Jan 2017 13:07:00 +0100 Subject: tst_qurl: add test for fromUserInput(3 args) using "." as working dir As used in recent qtdeclarative commits, so better make sure it keeps working. Change-Id: I6d0ceda76201e3e7f75661cb6449e1ff32329126 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qurl/tst_qurl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index a4461a12d3..994427ba12 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -3075,8 +3075,11 @@ void tst_QUrl::fromUserInputWithCwd_data() #endif ); // fromUserInput cleans the path } - QTest::newRow(("file-" + QByteArray::number(c++)).constData()) + QTest::newRow(("file-" + QByteArray::number(c)).constData()) << it.fileName() << QDir::currentPath() << url << url; + QTest::newRow(("file-" + QByteArray::number(c) + "-dot").constData()) + << it.fileName() << QStringLiteral(".") << url << url; + ++c; } #ifndef Q_OS_WINRT // WinRT cannot cd outside current / sandbox QDir parent = QDir::current(); -- cgit v1.2.3 From b8dbde10a065c3ba95b794b6d53ff62e8ca22ee7 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 30 Jan 2017 19:02:23 +0100 Subject: Fix data corruption when reading byte arrays from QSettings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On macOS, the code that read the plist is using QByteArray::fromRawCFData. When we return the data directly we need to detach the QByteArray so that it does not point CFData's data that will get deallocated just after the call. Task-number: QTBUG-58531 Change-Id: If829a304b986c99c8fc2aeeb992f2d539a4eef3a Reviewed-by: Thiago Macieira Reviewed-by: Tor Arne Vestbø --- tests/auto/corelib/io/qsettings/qsettings.qrc | 1 + tests/auto/corelib/io/qsettings/resourcefile6.plist | 10 ++++++++++ tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 11 +++++++++++ 3 files changed, 22 insertions(+) create mode 100644 tests/auto/corelib/io/qsettings/resourcefile6.plist (limited to 'tests') diff --git a/tests/auto/corelib/io/qsettings/qsettings.qrc b/tests/auto/corelib/io/qsettings/qsettings.qrc index c0be7e013f..c664a6f68c 100644 --- a/tests/auto/corelib/io/qsettings/qsettings.qrc +++ b/tests/auto/corelib/io/qsettings/qsettings.qrc @@ -5,6 +5,7 @@ resourcefile3.ini resourcefile4.ini resourcefile5.ini + resourcefile6.plist bom.ini diff --git a/tests/auto/corelib/io/qsettings/resourcefile6.plist b/tests/auto/corelib/io/qsettings/resourcefile6.plist new file mode 100644 index 0000000000..6f994accac --- /dev/null +++ b/tests/auto/corelib/io/qsettings/resourcefile6.plist @@ -0,0 +1,10 @@ + + + + + passwordData + + RBxVAAsDVsO/ + + + diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index f94349fd02..199ab442c4 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -178,6 +178,7 @@ private slots: void testByteArray_data(); void testByteArray(); + void testByteArrayNativeFormat(); void iniCodec(); void bom(); void embeddedZeroByte_data(); @@ -670,6 +671,16 @@ void tst_QSettings::testByteArray() } } +void tst_QSettings::testByteArrayNativeFormat() +{ +#ifndef Q_OS_MACOS + QSKIP("This test is specific to macOS plist reading."); +#else + QSettings settings(":/resourcefile6.plist", QSettings::NativeFormat); + QCOMPARE(settings.value("passwordData"), QVariant(QByteArray::fromBase64("RBxVAAsDVsO/"))); +#endif +} + void tst_QSettings::iniCodec() { { -- cgit v1.2.3 From 239418a947dc5230ce295b04edc5ee5b59009c7b Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sat, 4 Feb 2017 10:52:12 -0800 Subject: Use a precise timer in tst_QTimer::remainingTime At 200 ms, the error on first firing could be 10 ms. Task-number: QTBUG-58519 Change-Id: Ifaee7464122d402991b6fffd14a02a4ce782f11f Reviewed-by: Allan Sandfeld Jensen --- tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'tests') diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp index 29ff552f6a..3c2989831e 100644 --- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp +++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp @@ -158,6 +158,7 @@ void tst_QTimer::remainingTime() QTimer timer; connect(&timer, SIGNAL(timeout()), &helper, SLOT(timeout())); + timer.setTimerType(Qt::PreciseTimer); timer.start(200); QCOMPARE(helper.count, 0); -- cgit v1.2.3 From f53ab9d7363e2fb3b63cec1a00851f84f901de18 Mon Sep 17 00:00:00 2001 From: Aleksey Lysenko Date: Mon, 30 Jan 2017 22:55:57 +0200 Subject: Reset QFileDevicePrivate::cachedSize on file close When a QFile object is reused, the atEnd() method may return incorrect values. The reason for this is that QFileDevicePrivate::cachedSize is not cleared. Setting cachedSize = 0 in the close() method fixes this issue. Task-number: QTBUG-57698 Change-Id: I828a2cf844e98d581098f2c781fa47d2cd3275ce Reviewed-by: Alex Trotsenko Reviewed-by: Oswald Buddenhagen Reviewed-by: Lars Knoll --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 62 +++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'tests') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 2ef4c2c6a1..34ad2813b0 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -243,6 +243,8 @@ private slots: void invalidFile_data(); void invalidFile(); + void reuseQFile(); + private: enum FileType { OpenQFile, @@ -3436,5 +3438,65 @@ void tst_QFile::autocloseHandle() } } +void tst_QFile::reuseQFile() +{ + // QTemporaryDir is current dir, no need to remove these files + const QString filename1("filegt16k"); + const QString filename2("file16k"); + + // create test files for reusing QFile object + QFile file; + file.setFileName(filename1); + QVERIFY(file.open(QIODevice::WriteOnly)); + QByteArray ba(17408, 'a'); + qint64 written = file.write(ba); + QCOMPARE(written, 17408); + file.close(); + + file.setFileName(filename2); + QVERIFY(file.open(QIODevice::WriteOnly)); + ba.resize(16384); + written = file.write(ba); + QCOMPARE(written, 16384); + file.close(); + + QVERIFY(file.open(QIODevice::ReadOnly)); + QCOMPARE(file.size(), 16384); + QCOMPARE(file.pos(), qint64(0)); + QVERIFY(file.seek(10)); + QCOMPARE(file.pos(), qint64(10)); + QVERIFY(file.seek(0)); + QCOMPARE(file.pos(), qint64(0)); + QCOMPARE(file.readAll(), ba); + file.close(); + + file.setFileName(filename1); + QVERIFY(file.open(QIODevice::ReadOnly)); + + // read first file + { + // get file size without touching QFile + QFileInfo fi(filename1); + const qint64 fileSize = fi.size(); + file.read(fileSize); + QVERIFY(file.atEnd()); + file.close(); + } + + // try again with the next file with the same QFile object + file.setFileName(filename2); + QVERIFY(file.open(QIODevice::ReadOnly)); + + // read second file + { + // get file size without touching QFile + QFileInfo fi(filename2); + const qint64 fileSize = fi.size(); + file.read(fileSize); + QVERIFY(file.atEnd()); + file.close(); + } +} + QTEST_MAIN(tst_QFile) #include "tst_qfile.moc" -- cgit v1.2.3 From c876bb1f1333e47722e202b0916415e771137071 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 11 Jul 2016 19:55:24 +0200 Subject: QInputDialog: prevent crash in static get*() functions when parent gets deleted As explained in https://blogs.kde.org/2009/03/26/how-crash-almost-every-qtkde-application-and-how-fix-it-0 creating dialogs on the stack is a bad idea if the application or the dialog's parent window can be closed by means other than user interaction (such as a timer or an IPC call). Since we cannot know whether Qt is used to build such an application, we must assume it is, create the dialog on the heap, and monitor its lifetime with a QPointer. Instead of using manual resource management, add a minimal implementation of QAutoPointer, and use that in all static get*() functions. Task-number: QTBUG-54693 Change-Id: I6157dca18608e02be1ea2c2defbc31641defc9d1 Reviewed-by: Giuseppe D'Angelo Reviewed-by: David Faure --- .../widgets/dialogs/qinputdialog/qinputdialog.pro | 2 +- .../dialogs/qinputdialog/tst_qinputdialog.cpp | 71 ++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/widgets/dialogs/qinputdialog/qinputdialog.pro b/tests/auto/widgets/dialogs/qinputdialog/qinputdialog.pro index cc479812a8..9cb14c5350 100644 --- a/tests/auto/widgets/dialogs/qinputdialog/qinputdialog.pro +++ b/tests/auto/widgets/dialogs/qinputdialog/qinputdialog.pro @@ -1,4 +1,4 @@ CONFIG += testcase TARGET = tst_qinputdialog -QT += widgets testlib +QT += widgets-private testlib SOURCES += tst_qinputdialog.cpp diff --git a/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp b/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp index bbb6883238..0ea9e0259f 100644 --- a/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp +++ b/tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp @@ -35,6 +35,7 @@ #include #include #include +#include class tst_QInputDialog : public QObject { @@ -52,6 +53,7 @@ private slots: void getInt(); void getDouble_data(); void getDouble(); + void taskQTBUG_54693_crashWhenParentIsDeletedWhileDialogIsOpen(); void task255502getDouble(); void getText_data(); void getText(); @@ -311,6 +313,75 @@ void tst_QInputDialog::getDouble() delete parent; } +namespace { +class SelfDestructParent : public QWidget +{ + Q_OBJECT +public: + explicit SelfDestructParent(int delay = 100) + : QWidget(Q_NULLPTR) + { + QTimer::singleShot(delay, this, SLOT(deleteLater())); + } +}; +} + +void tst_QInputDialog::taskQTBUG_54693_crashWhenParentIsDeletedWhileDialogIsOpen() +{ + // getText + { + QAutoPointer dialog(new SelfDestructParent); + bool ok = true; + const QString result = QInputDialog::getText(dialog.get(), "Title", "Label", QLineEdit::Normal, "Text", &ok); + QVERIFY(!dialog); + QVERIFY(!ok); + QVERIFY(result.isNull()); + } + + // getMultiLineText + { + QAutoPointer dialog(new SelfDestructParent); + bool ok = true; + const QString result = QInputDialog::getMultiLineText(dialog.get(), "Title", "Label", "Text", &ok); + QVERIFY(!dialog); + QVERIFY(!ok); + QVERIFY(result.isNull()); + } + + // getItem + for (int editable = false; editable <= true; ++editable) { + QAutoPointer dialog(new SelfDestructParent); + bool ok = true; + const QString result = QInputDialog::getItem(dialog.get(), "Title", "Label", + QStringList() << "1" << "2", 1, editable, &ok); + QVERIFY(!dialog); + QVERIFY(!ok); + QCOMPARE(result, QLatin1String("2")); + } + + // getInt + { + const int initial = 7; + QAutoPointer dialog(new SelfDestructParent); + bool ok = true; + const int result = QInputDialog::getInt(dialog.get(), "Title", "Label", initial, -10, +10, 1, &ok); + QVERIFY(!dialog); + QVERIFY(!ok); + QCOMPARE(result, initial); + } + + // getDouble + { + const double initial = 7; + QAutoPointer dialog(new SelfDestructParent); + bool ok = true; + const double result = QInputDialog::getDouble(dialog.get(), "Title", "Label", initial, -10, +10, 2, &ok); + QVERIFY(!dialog); + QVERIFY(!ok); + QCOMPARE(result, initial); + } +} + void tst_QInputDialog::task255502getDouble() { parent = new QWidget; -- cgit v1.2.3 From 8b1d9d308b1f31e1b9c817e0d91e14baa3b76d6b Mon Sep 17 00:00:00 2001 From: Samuel Gaist Date: Mon, 29 Aug 2016 09:59:46 +0200 Subject: Fix result handling in QDialog::done The setData method of an item view would get an incorrect value of a QDialog's result. This patch changes the order of functions called to fix that. [ChangeLog][QtWidgets][QDialog] Fixed a bug where accessing the result of QDialog's result could yield an incorrect value in some situation like using it as a delegate for item views. Task-number: QTBUG-6018 Task-number: QTBUG-12156 Task-number: QTBUG-14430 Change-Id: I6ee4b6e8cacf6a806631c05c6c5dbcff925df65e Reviewed-by: Shawn Rutledge Reviewed-by: Jesus Fernandez Reviewed-by: Timur Pocheptsov --- .../qabstractitemview/tst_qabstractitemview.cpp | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'tests') diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 426db265ae..d241296a6b 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -52,6 +52,7 @@ #include #include #include +#include static inline void setFrameless(QWidget *w) { @@ -149,6 +150,7 @@ private slots: void QTBUG50535_update_on_new_selection_model(); void testSelectionModelInSyncWithView(); void testClickToSelect(); + void testDialogAsEditor(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -173,6 +175,29 @@ public: QSize size; }; +class DialogItemDelegate : public QStyledItemDelegate +{ +public: + DialogItemDelegate() : QStyledItemDelegate() { } + QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const + { + openedEditor = new QDialog(parent); + return openedEditor; + } + + void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const + { + Q_UNUSED(model) + Q_UNUSED(index) + + QDialog *dialog = qobject_cast(editor); + result = static_cast(dialog->result()); + } + + mutable QDialog::DialogCode result; + mutable QDialog *openedEditor; +}; + // Testing get/set functions void tst_QAbstractItemView::getSetCheck() { @@ -2156,5 +2181,37 @@ void tst_QAbstractItemView::testClickToSelect() QCOMPARE(spy.back().front().value(), QRect(nearCenterA, QSize(1, 1))); } +void tst_QAbstractItemView::testDialogAsEditor() +{ + DialogItemDelegate delegate; + + QStandardItemModel model; + model.appendRow(new QStandardItem(QStringLiteral("editme"))); + + QListView view; + view.setItemDelegate(&delegate); + view.setModel(&model); + view.show(); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + + view.edit(model.index(0,0)); + + QVERIFY(QTest::qWaitForWindowExposed(delegate.openedEditor)); + + delegate.openedEditor->reject(); + QApplication::processEvents(); + + QCOMPARE(delegate.result, QDialog::Rejected); + + view.edit(model.index(0,0)); + + QVERIFY(QTest::qWaitForWindowExposed(delegate.openedEditor)); + + delegate.openedEditor->accept(); + QApplication::processEvents(); + + QCOMPARE(delegate.result, QDialog::Accepted); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" -- cgit v1.2.3 From 9e5e30fa130e43524d9ff26493023ac966a878cc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 5 Feb 2017 14:55:01 +0100 Subject: QStringMatcher: fix setCaseSensitivity() on a non-QString-backed matcher When a non-QString-backed mode (via the (QChar*, int) ctor) was added for Qt 4.5, the author forgot to adjust the setCaseSensitivity() function. It still uses q_pattern instead of (p.uc, p.len) as the pattern for which to create the skip-table. Since there is no setPattern() overload for this mode, the correctness of the matcher is not harmed by this, but its performance degrades to that of a linear scan: the skip-table, being filled from an empty pattern, will be all-zeros, sending bm_find() into the 'possible match' case at every character. Since matching is still correct, but slow, it's not possible to write a test for this. I did, however, leave my attempts in the auto-test, for when we add QStringView overloads of setPattern() which will then be able to expose the bug. Change-Id: I7b803e8624b0352a0a974900affbbfc0c260d93b Reviewed-by: Giuseppe D'Angelo Reviewed-by: Edward Welbourne --- .../corelib/tools/qstringmatcher/tst_qstringmatcher.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp b/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp index 0c098cb1c3..8a55f54449 100644 --- a/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp +++ b/tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp @@ -54,12 +54,21 @@ void tst_QStringMatcher::qstringmatcher() // public Qt::CaseSensitivity caseSensitivity() const void tst_QStringMatcher::caseSensitivity() { - QStringMatcher matcher; + const QString haystack = QStringLiteral("foobarFoo"); + const QStringRef needle = haystack.rightRef(3); // "Foo" + QStringMatcher matcher(needle.data(), needle.size()); - matcher.setCaseSensitivity(Qt::CaseSensitive); QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive); + QCOMPARE(matcher.indexIn(haystack), 6); + matcher.setCaseSensitivity(Qt::CaseInsensitive); + QCOMPARE(matcher.caseSensitivity(), Qt::CaseInsensitive); + QCOMPARE(matcher.indexIn(haystack), 0); + + matcher.setCaseSensitivity(Qt::CaseSensitive); + QCOMPARE(matcher.caseSensitivity(), Qt::CaseSensitive); + QCOMPARE(matcher.indexIn(haystack), 6); } void tst_QStringMatcher::indexIn_data() -- cgit v1.2.3