summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-02-08 15:48:29 +0100
committerLiang Qi <liang.qi@qt.io>2017-02-08 15:49:18 +0100
commitdd756011da13b95fdb630a1bbb90234f1e60f415 (patch)
treea6259b1e9b6463108796ce912e3d1752e301505f /tests
parent0c50edbe84914469973a3b10e0170023ccdd66fe (diff)
parentb6bf2a33f4c33a212da7b58a049b3b5b20b3f327 (diff)
downloadqtbase-dd756011da13b95fdb630a1bbb90234f1e60f415.tar.gz
Merge remote-tracking branch 'origin/5.8' into 5.9
Conflicts: configure.json mkspecs/win32-icc/qmake.conf Change-Id: Ibf40546b024d644c7d9ed490bee15b82597f4d3f
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp62
-rw-r--r--tests/auto/corelib/io/qsettings/qsettings.qrc1
-rw-r--r--tests/auto/corelib/io/qsettings/resourcefile6.plist10
-rw-r--r--tests/auto/corelib/io/qsettings/tst_qsettings.cpp18
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp5
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp1
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp15
-rw-r--r--tests/auto/corelib/tools/qstringmatcher/tst_qstringmatcher.cpp13
-rw-r--r--tests/auto/widgets/dialogs/qinputdialog/qinputdialog.pro2
-rw-r--r--tests/auto/widgets/dialogs/qinputdialog/tst_qinputdialog.cpp71
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp57
-rw-r--r--tests/benchmarks/gui/painting/qtbench/benchmarktests.h6
12 files changed, 247 insertions, 14 deletions
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index e2a0c80396..57e197aa83 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,
@@ -3434,5 +3436,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"
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 @@
<file>resourcefile3.ini</file>
<file>resourcefile4.ini</file>
<file>resourcefile5.ini</file>
+ <file>resourcefile6.plist</file>
<file>bom.ini</file>
</qresource>
</RCC>
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 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>passwordData</key>
+ <data>
+ RBxVAAsDVsO/
+ </data>
+</dict>
+</plist>
diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp
index fcff13b416..332c2dcc01 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();
@@ -671,6 +672,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()
{
{
@@ -2316,14 +2327,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();
}
@@ -2331,9 +2342,6 @@ void tst_QSettings::setIniCodec()
QConfFile::clearCache();
-#ifdef Q_OS_WIN
- QEXPECT_FAIL("", "QTBUG-25446", Abort);
-#endif
QCOMPARE(actualContents4, expeContents4);
QCOMPARE(actualContents5, expeContents5);
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();
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);
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index 2a9b9c0a7f..6cb23023c7 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));
}
}
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()
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 <QComboBox>
#include <QDialogButtonBox>
#include <qinputdialog.h>
+#include <QtWidgets/private/qdialog_p.h>
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<SelfDestructParent> 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<SelfDestructParent> 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<SelfDestructParent> 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<SelfDestructParent> 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<SelfDestructParent> 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;
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 <qstringlistmodel.h>
#include <qsortfilterproxymodel.h>
#include <qproxystyle.h>
+#include <qdialog.h>
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<QDialog *>(editor);
+ result = static_cast<QDialog::DialogCode>(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>(), 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"
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);