summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-12-13 01:00:10 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-12-13 01:00:11 +0100
commitad4f359f805cdb1f1ed4745165090cccfcf11441 (patch)
treeb6526cb215f2d15fd312a48f70798459dd6051b3 /tests
parentd20c9805763ab3dc504ebf2cefd33499d89ef22c (diff)
parent69f6d3bd44e4e2d36ef741a1914227f804504141 (diff)
Merge remote-tracking branch 'origin/5.12' into dev
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qcollator/tst_qcollator.cpp18
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp14
-rw-r--r--tests/auto/gui/painting/qpainter/tst_qpainter.cpp16
-rw-r--r--tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp73
-rw-r--r--tests/manual/textrendering/nativetext/main.cpp27
5 files changed, 98 insertions, 50 deletions
diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
index 2d65d3433f..72f88a235d 100644
--- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
+++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp
@@ -93,7 +93,7 @@ void tst_QCollator::compare_data()
QTest::addColumn<int>("caseInsensitiveResult");
QTest::addColumn<bool>("numericMode");
QTest::addColumn<bool>("ignorePunctuation");
- QTest::addColumn<int>("punctuationResult");
+ QTest::addColumn<int>("punctuationResult"); // Test ignores punctuation *and case*
/*
It's hard to test English, because it's treated differently
@@ -169,8 +169,12 @@ void tst_QCollator::compare_data()
QTest::newRow("french6") << QString("fr_FR") << QString("Test 9") << QString("Test_19") << -1 << -1 << true << true << -1;
QTest::newRow("french7") << QString("fr_FR") << QString("test_19") << QString("test 19") << 1 << 1 << true << false << 1;
QTest::newRow("french8") << QString("fr_FR") << QString("test.19") << QString("test,19") << 1 << 1 << true << true << 0;
-}
+ // C locale: case sensitive [A-Z] < [a-z] but case insensitive [Aa] < [Bb] <...< [Zz]
+ const QString C = QStringLiteral("C");
+ QTest::newRow("C:ABBA:AaaA") << C << QStringLiteral("ABBA") << QStringLiteral("AaaA") << -1 << 1 << false << false << 1;
+ QTest::newRow("C:AZa:aAZ") << C << QStringLiteral("AZa") << QStringLiteral("aAZ") << -1 << 1 << false << false << 1;
+}
void tst_QCollator::compare()
{
@@ -184,6 +188,10 @@ void tst_QCollator::compare()
QFETCH(int, punctuationResult);
QCollator collator(locale);
+ // Need to canonicalize sign to -1, 0 or 1, as .compare() can produce any -ve for <, any +ve for >.
+ auto asSign = [](int compared) {
+ return compared < 0 ? -1 : compared > 0 ? 1 : 0;
+ };
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_EMBEDDED)
if (collator.locale() != QLocale())
@@ -193,12 +201,12 @@ void tst_QCollator::compare()
if (numericMode)
collator.setNumericMode(true);
- QCOMPARE(collator.compare(s1, s2), result);
+ QCOMPARE(asSign(collator.compare(s1, s2)), result);
collator.setCaseSensitivity(Qt::CaseInsensitive);
- QCOMPARE(collator.compare(s1, s2), caseInsensitiveResult);
+ QCOMPARE(asSign(collator.compare(s1, s2)), caseInsensitiveResult);
#if !QT_CONFIG(iconv)
collator.setIgnorePunctuation(ignorePunctuation);
- QCOMPARE(collator.compare(s1, s2), punctuationResult);
+ QCOMPARE(asSign(collator.compare(s1, s2)), punctuationResult);
#endif
}
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 5ffd75f931..eded206d37 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -233,6 +233,7 @@ private slots:
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
void toWinHBITMAP_data();
void toWinHBITMAP();
+ void fromMonoHBITMAP();
#endif // Q_OS_WIN && !Q_OS_WINRT
private:
@@ -3635,6 +3636,19 @@ void tst_QImage::toWinHBITMAP()
DeleteDC(bitmapDc);
ReleaseDC(0, displayDc);
}
+
+void tst_QImage::fromMonoHBITMAP() // QTBUG-72343, corruption for mono bitmaps
+{
+ enum : int { width = 32, height = 32, size = width * height / 8 }; // 32x32 mono bitmap
+ char bitmapData[size];
+ memset(bitmapData, 0, size);
+ const HBITMAP hbitmap = CreateBitmap(width, height, /* planes */ 1, /* bitcount */ 1, bitmapData);
+ const QImage image = qt_imageFromWinHBITMAP(hbitmap);
+ QCOMPARE(image.size(), QSize(width, height));
+ QCOMPARE(image.scanLine(0)[0], 0u);
+ DeleteObject(hbitmap);
+}
+
#endif // Q_OS_WIN && !Q_OS_WINRT
QTEST_GUILESS_MAIN(tst_QImage)
diff --git a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
index 9bf9e99bf9..bc0baed15c 100644
--- a/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
+++ b/tests/auto/gui/painting/qpainter/tst_qpainter.cpp
@@ -299,6 +299,8 @@ private slots:
void fillPolygon();
+ void drawImageAtPointF();
+
private:
void fillData();
void setPenColor(QPainter& p);
@@ -5292,6 +5294,20 @@ void tst_QPainter::fillPolygon()
}
}
+void tst_QPainter::drawImageAtPointF()
+{
+ // Just test we do not crash
+ QImage image1(10, 10, QImage::Format_RGB32);
+ QImage image2(200, 200, QImage::Format_RGB32);
+
+ QPainter paint(&image2);
+ paint.setClipRect(97, 46, 14, 14);
+ paint.setCompositionMode(QPainter::CompositionMode_Source);
+ paint.drawImage(QPointF(96, std::numeric_limits<int>::max()), image1);
+ paint.drawImage(QPointF(std::numeric_limits<int>::min(), 48), image1);
+ paint.end();
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"
diff --git a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
index 049468fd7c..3b31a74adf 100644
--- a/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
+++ b/tests/auto/widgets/dialogs/qmessagebox/tst_qmessagebox.cpp
@@ -210,9 +210,9 @@ void tst_QMessageBox::button()
{
QMessageBox msgBox;
msgBox.addButton("retry", QMessageBox::DestructiveRole);
- QVERIFY(msgBox.button(QMessageBox::Ok) == 0); // not added yet
+ QVERIFY(msgBox.button(QMessageBox::Ok) == nullptr); // not added yet
QPushButton *b1 = msgBox.addButton(QMessageBox::Ok);
- QCOMPARE(msgBox.button(QMessageBox::Ok), (QAbstractButton *)b1); // just added
+ QCOMPARE(msgBox.button(QMessageBox::Ok), static_cast<QAbstractButton *>(b1)); // just added
QCOMPARE(msgBox.standardButton(b1), QMessageBox::Ok);
msgBox.addButton(QMessageBox::Cancel);
QCOMPARE(msgBox.standardButtons(), QMessageBox::Ok | QMessageBox::Cancel);
@@ -220,12 +220,12 @@ void tst_QMessageBox::button()
// remove the cancel, should not exist anymore
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
QVERIFY(!msgBox.button(QMessageBox::Cancel));
- QVERIFY(msgBox.button(QMessageBox::Yes) != 0);
+ QVERIFY(msgBox.button(QMessageBox::Yes) != nullptr);
// should not crash
QPushButton *b4 = new QPushButton;
msgBox.addButton(b4, QMessageBox::DestructiveRole);
- msgBox.addButton(0, QMessageBox::ActionRole);
+ msgBox.addButton(nullptr, QMessageBox::ActionRole);
}
void tst_QMessageBox::defaultButton()
@@ -237,7 +237,7 @@ void tst_QMessageBox::defaultButton()
QVERIFY(!msgBox.defaultButton());
QPushButton pushButton;
msgBox.setDefaultButton(&pushButton);
- QVERIFY(msgBox.defaultButton() == 0); // we have not added it yet
+ QVERIFY(msgBox.defaultButton() == nullptr); // we have not added it yet
QPushButton *retryButton = msgBox.addButton(QMessageBox::Retry);
msgBox.setDefaultButton(retryButton);
QCOMPARE(msgBox.defaultButton(), retryButton);
@@ -248,11 +248,11 @@ void tst_QMessageBox::defaultButton()
closeHelper.start(Qt::Key_Enter, &msgBox);
msgBox.exec();
- QCOMPARE(msgBox.clickedButton(), (QAbstractButton *)retryButton);
+ QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton));
QAbstractButton *okButton = msgBox.button(QMessageBox::Ok);
msgBox.setDefaultButton(QMessageBox::Ok);
- QCOMPARE(msgBox.defaultButton(), (QPushButton *)okButton);
+ QCOMPARE(msgBox.defaultButton(), static_cast<QPushButton *>(okButton));
closeHelper.start(Qt::Key_Enter, &msgBox);
msgBox.exec();
QCOMPARE(msgBox.clickedButton(), okButton);
@@ -260,7 +260,7 @@ void tst_QMessageBox::defaultButton()
QCOMPARE(msgBox.defaultButton(), okButton);
msgBox.removeButton(okButton);
delete okButton;
- okButton = 0;
+ okButton = nullptr;
QVERIFY(!msgBox.defaultButton());
msgBox.setDefaultButton(QMessageBox::Ok);
QVERIFY(!msgBox.defaultButton());
@@ -287,7 +287,7 @@ void tst_QMessageBox::escapeButton()
QVERIFY(msgBox.clickedButton() == msgBox.button(QMessageBox::Cancel)); // auto detected (cancel)
msgBox.setEscapeButton(retryButton);
- QCOMPARE(msgBox.escapeButton(), (QAbstractButton *)retryButton);
+ QCOMPARE(msgBox.escapeButton(), static_cast<QAbstractButton *>(retryButton));
// with escape
closeHelper.start(Qt::Key_Escape, &msgBox);
@@ -297,7 +297,7 @@ void tst_QMessageBox::escapeButton()
// with close
closeHelper.start(ExecCloseHelper::CloseWindow, &msgBox);
msgBox.exec();
- QCOMPARE(msgBox.clickedButton(), (QAbstractButton *)retryButton);
+ QCOMPARE(msgBox.clickedButton(), static_cast<QAbstractButton *>(retryButton));
QAbstractButton *okButton = msgBox.button(QMessageBox::Ok);
msgBox.setEscapeButton(QMessageBox::Ok);
@@ -309,7 +309,7 @@ void tst_QMessageBox::escapeButton()
QCOMPARE(msgBox.escapeButton(), okButton);
msgBox.removeButton(okButton);
delete okButton;
- okButton = 0;
+ okButton = nullptr;
QVERIFY(!msgBox.escapeButton());
msgBox.setEscapeButton(QMessageBox::Ok);
QVERIFY(!msgBox.escapeButton());
@@ -353,28 +353,28 @@ void tst_QMessageBox::statics()
ExecCloseHelper closeHelper;
for (int i = 0; i < 4; i++) {
closeHelper.start(Qt::Key_Escape);
- QMessageBox::StandardButton sb = (*statics[i])(0, "caption",
+ QMessageBox::StandardButton sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel,
QMessageBox::NoButton);
QCOMPARE(sb, QMessageBox::Cancel);
QVERIFY(closeHelper.done());
closeHelper.start(ExecCloseHelper::CloseWindow);
- sb = (*statics[i])(0, "caption",
+ sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help | QMessageBox::Cancel,
QMessageBox::NoButton);
QCOMPARE(sb, QMessageBox::Cancel);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- sb = (*statics[i])(0, "caption",
+ sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
QMessageBox::Yes);
QCOMPARE(sb, QMessageBox::Yes);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- sb = (*statics[i])(0, "caption",
+ sb = (*statics[i])(nullptr, "caption",
"text", QMessageBox::Yes | QMessageBox::No | QMessageBox::Help,
QMessageBox::No);
QCOMPARE(sb, QMessageBox::No);
@@ -400,7 +400,7 @@ void tst_QMessageBox::about()
{
ExecCloseHelper closeHelper;
closeHelper.start(Qt::Key_Escape);
- QMessageBox::about(0, "Caption", "This is an auto test");
+ QMessageBox::about(nullptr, "Caption", "This is an auto test");
// On Mac, about and aboutQt are not modal, so we need to
// explicitly run the event loop
#ifdef Q_OS_MAC
@@ -412,7 +412,7 @@ void tst_QMessageBox::about()
const int keyToSend = Qt::Key_Enter;
closeHelper.start(keyToSend);
- QMessageBox::aboutQt(0, "Caption");
+ QMessageBox::aboutQt(nullptr, "Caption");
#ifdef Q_OS_MAC
QTRY_VERIFY(closeHelper.done());
#else
@@ -427,7 +427,7 @@ void tst_QMessageBox::staticSourceCompat()
// source compat tests for < 4.2
ExecCloseHelper closeHelper;
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No);
int expectedButton = int(QMessageBox::Yes);
if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
const int dialogButtonBoxLayout = theme->themeHint(QPlatformTheme::DialogButtonBoxLayout).toInt();
@@ -439,39 +439,39 @@ void tst_QMessageBox::staticSourceCompat()
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No);
QCOMPARE(ret, int(QMessageBox::Yes));
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
QCOMPARE(ret, int(QMessageBox::No));
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Default, QMessageBox::No | QMessageBox::Escape);
QCOMPARE(ret, int(QMessageBox::Yes));
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default);
+ ret = QMessageBox::information(nullptr, "title", "text", QMessageBox::Yes | QMessageBox::Escape, QMessageBox::No | QMessageBox::Default);
QCOMPARE(ret, int(QMessageBox::No));
QVERIFY(closeHelper.done());
// the button text versions
closeHelper.start(Qt::Key_Enter);
- ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1);
+ ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
QCOMPARE(ret, 1);
QVERIFY(closeHelper.done());
if (0) { // don't run these tests since the dialog won't close!
closeHelper.start(Qt::Key_Escape);
- ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 1);
+ ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 1);
QCOMPARE(ret, -1);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Escape);
- ret = QMessageBox::information(0, "title", "text", "Yes", "No", QString(), 0, 1);
+ ret = QMessageBox::information(nullptr, "title", "text", "Yes", "No", QString(), 0, 1);
QCOMPARE(ret, 1);
QVERIFY(closeHelper.done());
}
@@ -618,9 +618,8 @@ void tst_QMessageBox::detailsButtonText()
QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox");
QVERIFY(bb); //get the detail button
- QList<QAbstractButton *> list = bb->buttons();
- QAbstractButton* btn = NULL;
- foreach(btn, list) {
+ auto list = bb->buttons();
+ for (auto btn : list) {
if (btn && (btn->inherits("QPushButton"))) {
if (btn->text().remove(QLatin1Char('&')) != QMessageBox::tr("OK")
&& btn->text() != QMessageBox::tr("Show Details...")) {
@@ -640,12 +639,12 @@ void tst_QMessageBox::expandDetails_QTBUG_32473()
QDialogButtonBox* bb = box.findChild<QDialogButtonBox*>("qt_msgbox_buttonbox");
QVERIFY(bb);
- QList<QAbstractButton *> list = bb->buttons();
- QAbstractButton* moreButton = NULL;
- foreach (QAbstractButton* btn, list)
- if (btn && bb->buttonRole(btn) == QDialogButtonBox::ActionRole)
- moreButton = btn;
- QVERIFY(moreButton);
+ auto list = bb->buttons();
+ auto it = std::find_if(list.rbegin(), list.rend(), [&](QAbstractButton *btn) {
+ return btn && bb->buttonRole(btn) == QDialogButtonBox::ActionRole; });
+ QVERIFY(it != list.rend());
+ auto moreButton = *it;
+
QVERIFY(QTest::qWaitForWindowExposed(&box));
QRect geom = box.geometry();
box.resized = false;
@@ -667,19 +666,19 @@ void tst_QMessageBox::incorrectDefaultButton()
closeHelper.start(Qt::Key_Escape);
//Do not crash here
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
- QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save );
+ QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Escape);
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
- QMessageBox::question( 0, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save );
+ QMessageBox::question(nullptr, "", "I've been hit!",QFlag(QMessageBox::Ok | QMessageBox::Cancel),QMessageBox::Save);
QVERIFY(closeHelper.done());
closeHelper.start(Qt::Key_Escape);
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
QTest::ignoreMessage(QtWarningMsg, "QDialogButtonBox::createButton: Invalid ButtonRole, button not added");
//do not crash here -> call old function of QMessageBox in this case
- QMessageBox::question( 0, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok);
+ QMessageBox::question(nullptr, "", "I've been hit!",QMessageBox::Ok | QMessageBox::Cancel,QMessageBox::Save | QMessageBox::Cancel,QMessageBox::Ok);
QVERIFY(closeHelper.done());
}
diff --git a/tests/manual/textrendering/nativetext/main.cpp b/tests/manual/textrendering/nativetext/main.cpp
index 5c7621e61f..3fb78858f0 100644
--- a/tests/manual/textrendering/nativetext/main.cpp
+++ b/tests/manual/textrendering/nativetext/main.cpp
@@ -101,7 +101,9 @@ public:
const int ascent = fontMetrics().ascent();
- p.setPen(Qt::magenta);
+ QPen metricsPen(Qt::magenta, 1.0);
+ metricsPen.setCosmetic(true);
+ p.setPen(metricsPen);
p.drawLine(QPoint(0, ascent), QPoint(width(), ascent));
p.end();
@@ -152,13 +154,22 @@ public:
if (font().styleStrategy() & QFont::NoAntialias)
CGContextSetShouldAntialias(ctx, false);
- // Retain count already tracked by QMacCGContext above
- NSGraphicsContext.currentContext = [NSGraphicsContext graphicsContextWithCGContext:ctx flipped:YES];
- [text().toNSString() drawAtPoint:CGPointZero withAttributes:@{
- NSFontAttributeName : (NSFont *)fontEngine->handle(),
- NSForegroundColorAttributeName : nsColor
- }];
- NSGraphicsContext.currentContext = nil;
+ // Flip to what CT expects
+ CGContextScaleCTM(ctx, 1, -1);
+ CGContextTranslateCTM(ctx, 0, -height());
+
+ // Set up baseline
+ CGContextSetTextPosition(ctx, 0, height() - fontMetrics().ascent());
+
+ auto *attributedString = [[NSAttributedString alloc] initWithString:text().toNSString()
+ attributes:@{
+ NSFontAttributeName : (NSFont *)fontEngine->handle(),
+ NSForegroundColorAttributeName : nsColor
+ }
+ ];
+
+ QCFType<CTLineRef> line = CTLineCreateWithAttributedString(CFAttributedStringRef([attributedString autorelease]));
+ CTLineDraw(line, ctx);
#endif
}