diff options
author | Liang Qi <liang.qi@qt.io> | 2017-02-10 21:10:21 +0100 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-02-10 22:35:04 +0100 |
commit | 364b161122b567e3a6f7343d438fb540b9fb7e5c (patch) | |
tree | 3d49953be9a58295a8c956cf5fdb00f581020605 /tests | |
parent | e58401a75b29beb38d37a40072106d5ef7cb0336 (diff) | |
parent | 8a410f60ae39b06555d807581caf7cb8bfab4fac (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/widgets/widgets/qmainwindowlayout_p.h
Change-Id: Id406a67606b885052ed405b0fbc8eea7d9d03224
Diffstat (limited to 'tests')
21 files changed, 334 insertions, 121 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 d69e0997d5..71a0c943d2 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -3058,8 +3058,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/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 72609d4095..e3bda6c2df 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -119,6 +119,7 @@ private slots: void refUnref(); void copy(); + void deepCopyPreservesDpr(); void depthOfNullObjects(); void transformed(); @@ -1133,6 +1134,19 @@ void tst_QPixmap::copy() QCOMPARE(trans, transCopy); } +// QTBUG-58653: Force a deep copy of a pixmap by +// having a QPainter and check whether DevicePixelRatio is preserved +void tst_QPixmap::deepCopyPreservesDpr() +{ + const qreal dpr = 2; + QPixmap src(32, 32); + src.setDevicePixelRatio(dpr); + src.fill(Qt::red); + QPainter painter(&src); + const QPixmap dest = src.copy(); + QCOMPARE(dest.devicePixelRatio(), dpr); +} + void tst_QPixmap::depthOfNullObjects() { QBitmap b1; diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index 6192e3cd8d..8667caa1ef 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -202,36 +202,36 @@ void tst_QFontMetrics::bypassShaping() QCOMPARE(textWidth, charsWidth); } -template<class FontMetrics> void elidedMultiLength_helper() +template<class FontMetrics, typename PrimitiveType> void elidedMultiLength_helper() { QString text1 = QLatin1String("Long Text 1\x9cShorter\x9csmall"); QString text1_long = "Long Text 1"; QString text1_short = "Shorter"; QString text1_small = "small"; FontMetrics fm = FontMetrics(QFont()); - int width_long = fm.size(0, text1_long).width(); + PrimitiveType width_long = fm.size(0, text1_long).width(); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, 8000), text1_long); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_long + 1), text1_long); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_long - 1), text1_short); - int width_short = fm.size(0, text1_short).width(); + PrimitiveType width_short = fm.size(0, text1_short).width(); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_short + 1), text1_short); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_short - 1), text1_small); // Not even wide enough for "small" - should use ellipsis QChar ellipsisChar(0x2026); QString text1_el = QString::fromLatin1("s") + ellipsisChar; - int width_small = fm.width(text1_el); + PrimitiveType width_small = fm.width(text1_el); QCOMPARE(fm.elidedText(text1,Qt::ElideRight, width_small + 1), text1_el); } void tst_QFontMetrics::elidedMultiLength() { - elidedMultiLength_helper<QFontMetrics>(); + elidedMultiLength_helper<QFontMetrics, int>(); } void tst_QFontMetrics::elidedMultiLengthF() { - elidedMultiLength_helper<QFontMetricsF>(); + elidedMultiLength_helper<QFontMetricsF, qreal>(); } void tst_QFontMetrics::inFontUcs4() diff --git a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp index 7c60c8c9f8..21b2697b90 100644 --- a/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp +++ b/tests/auto/gui/text/qglyphrun/tst_qglyphrun.cpp @@ -527,6 +527,7 @@ void tst_QGlyphRun::drawStruckOutText() QFont font; font.setStrikeOut(true); + font.setStyleStrategy(QFont::ForceIntegerMetrics); QTextLayout layout(s); layout.setFont(font); @@ -569,6 +570,7 @@ void tst_QGlyphRun::drawOverlinedText() QFont font; font.setOverline(true); + font.setStyleStrategy(QFont::ForceIntegerMetrics); QTextLayout layout(s); layout.setFont(font); @@ -611,6 +613,7 @@ void tst_QGlyphRun::drawUnderlinedText() QFont font; font.setUnderline(true); + font.setStyleStrategy(QFont::ForceIntegerMetrics); QTextLayout layout(s); layout.setFont(font); diff --git a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp index 9f84f64ee9..f4e3356ad0 100644 --- a/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/gui/text/qstatictext/tst_qstatictext.cpp @@ -716,6 +716,7 @@ void tst_QStaticText::drawStruckOutText() QFont font; font.setStrikeOut(true); + font.setStyleStrategy(QFont::ForceIntegerMetrics); { QPainter p(&imageDrawText); @@ -751,6 +752,7 @@ void tst_QStaticText::drawOverlinedText() QFont font; font.setOverline(true); + font.setStyleStrategy(QFont::ForceIntegerMetrics); { QPainter p(&imageDrawText); @@ -786,6 +788,7 @@ void tst_QStaticText::drawUnderlinedText() QFont font; font.setUnderline(true); + font.setStyleStrategy(QFont::ForceIntegerMetrics); { QPainter p(&imageDrawText); diff --git a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp index 36907b9258..ee50b98733 100644 --- a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp +++ b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp @@ -1104,7 +1104,7 @@ void tst_QTextScriptEngine::controlInSyllable_qtbug14204() const ushort *log_clusters = e->logClusters(&e->layoutData->items[0]); QCOMPARE(log_clusters[0], ushort(0)); QCOMPARE(log_clusters[1], ushort(0)); - QCOMPARE(log_clusters[2], ushort(1)); + QCOMPARE(log_clusters[2], ushort(0)); QCOMPARE(log_clusters[3], ushort(2)); } @@ -1214,6 +1214,9 @@ void tst_QTextScriptEngine::thaiWithZWJ() QFont font(QStringLiteral("Waree")); font.setStyleStrategy(QFont::NoFontMerging); + if (QFontInfo(font).styleName() != QStringLiteral("Book")) + QSKIP("couldn't find 'Waree Book' font"); + QString s(QString::fromUtf8("\xe0\xb8\xa3\xe2\x80\x8d\xe0\xb8\xa3\xe2\x80" "\x8c\x2e\xe0\xb8\xa3\x2e\xe2\x80\x9c\xe0\xb8" "\xa3\xe2\x80\xa6\xe0\xb8\xa3\xe2\x80\x9d\xe0" @@ -1233,20 +1236,22 @@ void tst_QTextScriptEngine::thaiWithZWJ() QCOMPARE(e->layoutData->items[2].num_glyphs, ushort(2)); // Thai: Thai character followed by superscript "a" which is of inherited type //A quick sanity check - check all the characters are individual clusters + // A thai implementation could either remove the ZWJ and ZWNJ characters, or hide them. + // The current implementation hides them, so we test for that. unsigned short *logClusters = e->layoutData->logClustersPtr; - for (int i = 0; i < 15; i++) + QCOMPARE(logClusters[0], ushort(0)); + QCOMPARE(logClusters[1], ushort(0)); + QCOMPARE(logClusters[2], ushort(2)); + QCOMPARE(logClusters[3], ushort(2)); + for (int i = 4; i < 15; i++) QCOMPARE(logClusters[i], ushort(i)); for (int i = 0; i < 3; i++) QCOMPARE(logClusters[i+15], ushort(0)); - // A thai implementation could either remove the ZWJ and ZWNJ characters, or hide them. - // The current implementation hides them, so we test for that. // The only characters that we should be hiding are the ZWJ and ZWNJ characters in position 1 and 3. const QGlyphLayout glyphLayout = e->layoutData->glyphLayout; for (int i = 0; i < 18; i++) { - if (i == 17) - QCOMPARE(glyphLayout.advances[i].toInt(), 0); - else if (i == 1 || i == 3) + if (i == 1 || i == 3) QCOMPARE(glyphLayout.advances[i].toInt(), 0); else QVERIFY(glyphLayout.advances[i].toInt() != 0); 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); diff --git a/tests/manual/diaglib/diaglib.pri b/tests/manual/diaglib/diaglib.pri index e3e7c3757c..f240a73167 100644 --- a/tests/manual/diaglib/diaglib.pri +++ b/tests/manual/diaglib/diaglib.pri @@ -10,7 +10,7 @@ HEADERS += \ $$PWD/qwindowdump.h \ $$PWD/nativewindowdump.h -win32 { +win32!winrt: { SOURCES += $$PWD/nativewindowdump_win.cpp LIBS *= -luser32 } else { diff --git a/tests/manual/windowflags/controllerwindow.cpp b/tests/manual/windowflags/controllerwindow.cpp index d02f64c27b..3654bfbad0 100644 --- a/tests/manual/windowflags/controllerwindow.cpp +++ b/tests/manual/windowflags/controllerwindow.cpp @@ -70,7 +70,7 @@ ControllerWidget::ControllerWidget(QWidget *parent) hintsControl->setHints(previewWindow->windowFlags()); connect(hintsControl, SIGNAL(changed(Qt::WindowFlags)), this, SLOT(updatePreview())); - statesControl = new WindowStatesControl(WindowStatesControl::WantVisibleCheckBox|WindowStatesControl::WantActiveCheckBox); + statesControl = new WindowStatesControl; statesControl->setStates(previewWindow->windowState()); statesControl->setVisibleValue(true); connect(statesControl, SIGNAL(changed()), this, SLOT(updatePreview())); @@ -106,13 +106,13 @@ void ControllerWidget::updatePreview() { const Qt::WindowFlags flags = typeControl->type() | hintsControl->hints(); - previewWindow->hide(); - previewDialog->hide(); - - if (previewWidgetButton->isChecked()) + if (previewWidgetButton->isChecked()) { previewWidget = previewWindow; - else + previewDialog->hide(); + } else { previewWidget = previewDialog; + previewWindow->hide(); + } if (modalWindowCheckBox->isChecked()) { parentWindow->show(); diff --git a/tests/manual/windowflags/controls.cpp b/tests/manual/windowflags/controls.cpp index 319f6aac8e..c167e5f8bf 100644 --- a/tests/manual/windowflags/controls.cpp +++ b/tests/manual/windowflags/controls.cpp @@ -161,97 +161,71 @@ void HintControl::slotCheckBoxChanged() emit changed(hints()); } -WindowStateControl::WindowStateControl(unsigned flags, QWidget *parent) +WindowStateControl::WindowStateControl(QWidget *parent) : QWidget(parent) , group(new QButtonGroup) - , visibleCheckBox(0) - , restoreButton(new QRadioButton(tr("Normal"))) - , minimizeButton(0) - , maximizeButton(new QRadioButton(tr("Maximized"))) - , fullscreenButton(new QRadioButton(tr("Fullscreen"))) + , restoreButton(new QCheckBox(tr("Normal"))) + , minimizeButton(new QCheckBox(tr("Minimized"))) + , maximizeButton(new QCheckBox(tr("Maximized"))) + , fullscreenButton(new QCheckBox(tr("Fullscreen"))) { QHBoxLayout *layout = new QHBoxLayout(this); - layout->setSpacing(0); + group->setExclusive(false); layout->setMargin(ControlLayoutMargin); - if (flags & WantVisibleCheckBox) { - visibleCheckBox = new QCheckBox(tr("Visible")); - connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - layout->addWidget(visibleCheckBox); - } - - group->setExclusive(true); - if (flags & WantMinimizeRadioButton) { - minimizeButton = new QRadioButton(tr("Minimized")); - group->addButton(minimizeButton, Qt::WindowMinimized); - layout->addWidget(minimizeButton); - } group->addButton(restoreButton, Qt::WindowNoState); + restoreButton->setEnabled(false); layout->addWidget(restoreButton); + group->addButton(minimizeButton, Qt::WindowMinimized); + layout->addWidget(minimizeButton); group->addButton(maximizeButton, Qt::WindowMaximized); layout->addWidget(maximizeButton); group->addButton(fullscreenButton, Qt::WindowFullScreen); layout->addWidget(fullscreenButton); - connect(group, SIGNAL(buttonReleased(int)), this, SIGNAL(changed())); + connect(group, SIGNAL(buttonReleased(int)), this, SIGNAL(stateChanged(int))); } -Qt::WindowState WindowStateControl::state() const +Qt::WindowStates WindowStateControl::state() const { - return Qt::WindowState(group->checkedId()); + Qt::WindowStates states; + foreach (QAbstractButton *button, group->buttons()) { + if (button->isChecked()) + states |= Qt::WindowState(group->id(button)); + } + return states; } -void WindowStateControl::setState(Qt::WindowState s) +void WindowStateControl::setState(Qt::WindowStates s) { group->blockSignals(true); - if (QAbstractButton *b = group->button(s)) - b->setChecked(true); - group->blockSignals(false); -} + foreach (QAbstractButton *button, group->buttons()) + button->setChecked(s & Qt::WindowState(group->id(button))); -bool WindowStateControl::visibleValue() const -{ - return visibleCheckBox && visibleCheckBox->isChecked(); -} + if (!(s & (Qt::WindowMaximized | Qt::WindowFullScreen))) + restoreButton->setChecked(true); -void WindowStateControl::setVisibleValue(bool v) -{ - if (visibleCheckBox) { - visibleCheckBox->blockSignals(true); - visibleCheckBox->setChecked(v); - visibleCheckBox->blockSignals(false); - } + group->blockSignals(false); } -WindowStatesControl::WindowStatesControl(unsigned flags, QWidget *parent) +WindowStatesControl::WindowStatesControl(QWidget *parent) : QGroupBox(tr("States"), parent) - , visibleCheckBox(0) - , activeCheckBox(0) - , minimizeCheckBox(new QCheckBox(tr("Minimized"))) - , stateControl(new WindowStateControl(0)) + , visibleCheckBox(new QCheckBox(tr("Visible"))) + , activeCheckBox(new QCheckBox(tr("Active"))) + , stateControl(new WindowStateControl) { QHBoxLayout *layout = new QHBoxLayout(this); layout->setSpacing(0); layout->setMargin(ControlLayoutMargin); - if (flags & WantVisibleCheckBox) { - visibleCheckBox = new QCheckBox(tr("Visible")); - connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - layout->addWidget(visibleCheckBox); - } - if (flags & WantActiveCheckBox) { - activeCheckBox = new QCheckBox(tr("Active")); - connect(activeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); - layout->addWidget(activeCheckBox); - } - layout->addWidget(minimizeCheckBox); + connect(visibleCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + layout->addWidget(visibleCheckBox); + connect(activeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(changed())); + layout->addWidget(activeCheckBox); layout->addWidget(stateControl); - connect(stateControl, SIGNAL(changed()), this, SIGNAL(changed())); - connect(minimizeCheckBox, SIGNAL(clicked()), this, SIGNAL(changed())); + connect(stateControl, SIGNAL(stateChanged(int)), this, SIGNAL(changed())); } Qt::WindowStates WindowStatesControl::states() const { Qt::WindowStates s = stateControl->state(); - if (minimizeCheckBox->isChecked()) - s |= Qt::WindowMinimized; if (activeValue()) s |= Qt::WindowActive; return s; @@ -259,11 +233,7 @@ Qt::WindowStates WindowStatesControl::states() const void WindowStatesControl::setStates(Qt::WindowStates s) { - minimizeCheckBox->blockSignals(true); - minimizeCheckBox->setChecked(s & Qt::WindowMinimized); - minimizeCheckBox->blockSignals(false); - s &= ~Qt::WindowMinimized; - stateControl->setState(Qt::WindowState(int(s))); + stateControl->setState(s); setActiveValue(s & Qt::WindowActive); } diff --git a/tests/manual/windowflags/controls.h b/tests/manual/windowflags/controls.h index 79faaaa9c3..e140d813cc 100644 --- a/tests/manual/windowflags/controls.h +++ b/tests/manual/windowflags/controls.h @@ -77,29 +77,20 @@ private: class WindowStateControl : public QWidget { Q_OBJECT public: - enum Flags { - WantVisibleCheckBox = 0x1, - WantMinimizeRadioButton = 0x2 - }; + explicit WindowStateControl(QWidget *parent= 0); - explicit WindowStateControl(unsigned flags, QWidget *parent= 0); - - Qt::WindowState state() const; - void setState(Qt::WindowState s); - - bool visibleValue() const; - void setVisibleValue(bool); + Qt::WindowStates state() const; + void setState(Qt::WindowStates s); signals: - void changed(); + void stateChanged(int); private: QButtonGroup *group; - QCheckBox *visibleCheckBox; - QRadioButton *restoreButton; - QRadioButton *minimizeButton; - QRadioButton *maximizeButton; - QRadioButton *fullscreenButton; + QCheckBox *restoreButton; + QCheckBox *minimizeButton; + QCheckBox *maximizeButton; + QCheckBox *fullscreenButton; }; // Control for the Qt::WindowStates flags (normal, maximized, fullscreen exclusively @@ -108,12 +99,7 @@ class WindowStatesControl : public QGroupBox { Q_OBJECT public: - enum Flags { - WantVisibleCheckBox = 0x1, - WantActiveCheckBox = 0x2 - }; - - explicit WindowStatesControl(unsigned flags, QWidget *parent= 0); + explicit WindowStatesControl(QWidget *parent= 0); Qt::WindowStates states() const; void setStates(Qt::WindowStates s); @@ -129,7 +115,6 @@ signals: private: QCheckBox *visibleCheckBox; QCheckBox *activeCheckBox; - QCheckBox *minimizeCheckBox; WindowStateControl *stateControl; }; |