summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp131
-rw-r--r--tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp162
2 files changed, 275 insertions, 18 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 71aaa23da4..fe998c7d92 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -177,6 +177,12 @@ private slots:
void inplaceRgbConversion_data();
void inplaceRgbConversion();
+ void largeGenericRgbConversion_data();
+ void largeGenericRgbConversion();
+
+ void largeInplaceRgbConversion_data();
+ void largeInplaceRgbConversion();
+
void deepCopyWhenPaintingActive();
void scaled_QTBUG19157();
@@ -2896,16 +2902,15 @@ void tst_QImage::inplaceRgbConversion_data()
}
if (i == j)
continue;
- QTest::addRow("%s -> %s", formatToString(QImage::Format(i)).data(), formatToString(QImage::Format(j)).data())
- << QImage::Format(i) << QImage::Format(j);
+ if (qt_depthForFormat(QImage::Format(i)) >= qt_depthForFormat(QImage::Format(j)))
+ QTest::addRow("%s -> %s", formatToString(QImage::Format(i)).data(), formatToString(QImage::Format(j)).data())
+ << QImage::Format(i) << QImage::Format(j);
}
}
}
void tst_QImage::inplaceRgbConversion()
{
- // Test that conversions between RGB formats of the same bitwidth can be done inplace.
-#if defined(Q_COMPILER_REF_QUALIFIERS)
QFETCH(QImage::Format, format);
QFETCH(QImage::Format, dest_format);
@@ -2954,7 +2959,123 @@ void tst_QImage::inplaceRgbConversion()
QVERIFY(rwInplaceConverted.constBits() != (const uchar *)readWriteData);
QCOMPARE(normalConverted, rwInplaceConverted);
}
-#endif
+}
+
+void tst_QImage::largeGenericRgbConversion_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<QImage::Format>("dest_format");
+
+ QImage::Format formats[] = {
+ QImage::Format_RGB32,
+ QImage::Format_ARGB32,
+ QImage::Format_ARGB32_Premultiplied,
+ QImage::Format_RGB16,
+ QImage::Format_RGB888,
+ QImage::Format_RGBA8888,
+ QImage::Format_BGR30,
+ QImage::Format_A2RGB30_Premultiplied,
+ QImage::Format_RGBA64_Premultiplied,
+ };
+
+ for (QImage::Format src_format : formats) {
+ for (QImage::Format dst_format : formats) {
+ if (src_format == dst_format)
+ continue;
+
+ QTest::addRow("%s -> %s", formatToString(src_format).data(), formatToString(dst_format).data())
+ << src_format << dst_format;
+ }
+ }
+}
+
+void tst_QImage::largeGenericRgbConversion()
+{
+ // Also test a larger conversion for a few formats (here the tested precision is also higher)
+ QFETCH(QImage::Format, format);
+ QFETCH(QImage::Format, dest_format);
+
+ // Must have more than 64k pixels to trigger threaded codepath:
+ QImage image(512, 216, format);
+
+ for (int i = 0; i < image.height(); ++i)
+ for (int j = 0; j < image.width(); ++j)
+ image.setPixel(j, i, qRgb(j % 256, i, 0));
+
+ const bool precision_8bit = (format != QImage::Format_RGB16) && (dest_format != QImage::Format_RGB16);
+
+ QImage imageConverted = image.convertToFormat(dest_format);
+ QCOMPARE(imageConverted.format(), dest_format);
+ for (int i = 0; i < imageConverted.height(); ++i) {
+ for (int j = 0; j < imageConverted.width(); ++j) {
+ if (precision_8bit) {
+ QCOMPARE(imageConverted.pixel(j, i), image.pixel(j, i));
+ } else {
+ QRgb convertedColor = imageConverted.pixel(j,i);
+ QCOMPARE(qRed(convertedColor) & 0xF8, (j % 256) & 0xF8);
+ QCOMPARE(qGreen(convertedColor) & 0xFC, i & 0xFC);
+ }
+ }
+ }
+}
+
+void tst_QImage::largeInplaceRgbConversion_data()
+{
+ QTest::addColumn<QImage::Format>("format");
+ QTest::addColumn<QImage::Format>("dest_format");
+
+ QImage::Format formats[] = {
+ QImage::Format_RGB32,
+ QImage::Format_ARGB32,
+ QImage::Format_ARGB32_Premultiplied,
+ QImage::Format_RGB16,
+ QImage::Format_RGB888,
+ QImage::Format_RGBA8888,
+ QImage::Format_BGR30,
+ QImage::Format_A2RGB30_Premultiplied,
+ QImage::Format_RGBA64_Premultiplied,
+ };
+
+ for (QImage::Format src_format : formats) {
+ for (QImage::Format dst_format : formats) {
+ if (src_format == dst_format)
+ continue;
+ if (qt_depthForFormat(src_format) < qt_depthForFormat(dst_format))
+ continue;
+ QTest::addRow("%s -> %s", formatToString(src_format).data(), formatToString(dst_format).data())
+ << src_format << dst_format;
+ }
+ }
+}
+
+void tst_QImage::largeInplaceRgbConversion()
+{
+ // Also test a larger conversion for a few formats
+ QFETCH(QImage::Format, format);
+ QFETCH(QImage::Format, dest_format);
+
+ // Must have more than 64k pixels to trigger threaded codepath:
+ QImage image(512, 216, format);
+
+ for (int i = 0; i < image.height(); ++i)
+ for (int j = 0; j < image.width(); ++j)
+ image.setPixel(j, i, qRgb(j % 256, i, 0));
+
+ const bool precision_8bit = (format != QImage::Format_RGB16) && (dest_format != QImage::Format_RGB16);
+
+ image.convertTo(dest_format);
+ QCOMPARE(image.format(), dest_format);
+ for (int i = 0; i < image.height(); ++i) {
+ for (int j = 0; j < image.width(); ++j) {
+ if (precision_8bit) {
+ QCOMPARE(image.pixel(j,i), qRgb(j % 256, i, 0));
+ } else {
+ QRgb convertedColor = image.pixel(j,i);
+ QCOMPARE(qRed(convertedColor) & 0xF8, (j % 256) & 0xF8);
+ QCOMPARE(qGreen(convertedColor) & 0xFC, i & 0xFC);
+ }
+ }
+ }
}
void tst_QImage::deepCopyWhenPaintingActive()
diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
index 2dcca0209e..8466305832 100644
--- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
+++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp
@@ -62,6 +62,7 @@ private slots:
void lineBreaking();
#ifdef QT_BUILD_INTERNAL
void simpleBoundingRect();
+ void threeLineBoundingRect_data();
void threeLineBoundingRect();
void boundingRectWithLongLineAndNoWrap();
void forcedBreaks();
@@ -140,6 +141,7 @@ private slots:
void showLineAndParagraphSeparatorsCrash();
void koreanWordWrap();
void tooManyDirectionalCharctersCrash_qtbug77819();
+ void softHyphens();
private:
QFont testFont;
@@ -315,18 +317,49 @@ void tst_QTextLayout::simpleBoundingRect()
QCOMPARE(layout.boundingRect(), QRectF(0, 0, width, QFontMetrics(testFont).height()));
}
+void tst_QTextLayout::threeLineBoundingRect_data()
+{
+ QTest::addColumn<QChar>("wordBoundary1");
+ QTest::addColumn<QChar>("wordBoundary2");
+ QTest::newRow("2x' '") << QChar(' ') << QChar(' ');
+ QTest::newRow("2x'\\n'") << QChar('\n') << QChar('\n');
+ QTest::newRow("' ' + '\\n'") << QChar(' ') << QChar('\n');
+ QTest::newRow("'\\n' + ' '") << QChar('\n') << QChar(' ');
+ QTest::newRow("2x'\\t'") << QChar('\t') << QChar('\t');
+ QTest::newRow("2xsoft hyphen") << QChar(0xad) << QChar(0xad);
+ QTest::newRow("2x'-'") << QChar('-') << QChar('-');
+ QTest::newRow("2x'/'") << QChar('/') << QChar('/');
+ QTest::newRow("soft hyphen + ' '") << QChar(0xad) << QChar(' ');
+ QTest::newRow("soft hyphen + '\\n'") << QChar(0xad) << QChar('\n');
+ QTest::newRow("soft hyphen + '-'") << QChar(0xad) << QChar('-');
+ QTest::newRow("' ' + soft hyphen") << QChar(' ') << QChar(0xad);
+ QTest::newRow("'\\n' + soft hyphen") << QChar('\n') << QChar(0xad);
+ QTest::newRow("'-' + soft hyphen") << QChar('-') << QChar(0xad);
+}
+
void tst_QTextLayout::threeLineBoundingRect()
{
/* stricter check. break text into three lines */
+ QFETCH(QChar, wordBoundary1);
+ QFETCH(QChar, wordBoundary2);
QString firstWord("hello");
- QString secondWord("world");
- QString thirdWord("test");
- QString text(firstWord + ' ' + secondWord + ' ' + thirdWord);
-
- const int firstLineWidth = firstWord.length() * testFont.pixelSize();
- const int secondLineWidth = secondWord.length() * testFont.pixelSize();
- const int thirdLineWidth = thirdWord.length() * testFont.pixelSize();
+ QString secondWord("test");
+ QString thirdWord("world");
+ QString text(firstWord + wordBoundary1 + secondWord + wordBoundary2 + thirdWord);
+
+ int firstLineWidth = firstWord.length() * testFont.pixelSize();
+ int secondLineWidth = secondWord.length() * testFont.pixelSize();
+ int thirdLineWidth = thirdWord.length() * testFont.pixelSize();
+ // Trailing spaces do not count to line width:
+ if (!wordBoundary1.isSpace())
+ firstLineWidth += testFont.pixelSize();
+ if (!wordBoundary2.isSpace())
+ secondLineWidth += testFont.pixelSize();
+ // But trailing spaces do count to line length:
+ const int firstLineLength = firstWord.length() + 1;
+ const int secondLineLength = secondWord.length() + 1;
+ const int thirdLineLength = thirdWord.length();
const int longestLine = qMax(firstLineWidth, qMax(secondLineWidth, thirdLineWidth));
@@ -339,8 +372,7 @@ void tst_QTextLayout::threeLineBoundingRect()
line.setLineWidth(firstLineWidth);
line.setPosition(QPoint(0, y));
QCOMPARE(line.textStart(), pos);
- // + 1 for trailing space
- QCOMPARE(line.textLength(), firstWord.length() + 1);
+ QCOMPARE(line.textLength(), firstLineLength);
QCOMPARE(qRound(line.naturalTextWidth()), firstLineWidth);
pos += line.textLength();
@@ -349,9 +381,8 @@ void tst_QTextLayout::threeLineBoundingRect()
line = layout.createLine();
line.setLineWidth(secondLineWidth);
line.setPosition(QPoint(0, y));
- // + 1 for trailing space
QCOMPARE(line.textStart(), pos);
- QCOMPARE(line.textLength(), secondWord.length() + 1);
+ QCOMPARE(line.textLength(), secondLineLength);
QCOMPARE(qRound(line.naturalTextWidth()), secondLineWidth);
pos += line.textLength();
@@ -360,9 +391,8 @@ void tst_QTextLayout::threeLineBoundingRect()
line = layout.createLine();
line.setLineWidth(secondLineWidth);
line.setPosition(QPoint(0, y));
- // no trailing space here!
QCOMPARE(line.textStart(), pos);
- QCOMPARE(line.textLength(), thirdWord.length());
+ QCOMPARE(line.textLength(), thirdLineLength);
QCOMPARE(qRound(line.naturalTextWidth()), thirdLineWidth);
y += qRound(line.ascent() + line.descent());
@@ -2352,5 +2382,111 @@ void tst_QTextLayout::tooManyDirectionalCharctersCrash_qtbug77819()
tl.endLayout();
}
+void tst_QTextLayout::softHyphens()
+{
+ QString text = QStringLiteral("xxxx\u00ad") + QStringLiteral("xxxx\u00ad");
+
+ QFont font;
+ font.setPixelSize(14);
+ font.setHintingPreference(QFont::PreferNoHinting);
+ const float xAdvance = QFontMetricsF(font).horizontalAdvance(QChar('x'));
+ const float shyAdvance = QFontMetricsF(font).horizontalAdvance(QChar::SoftHyphen);
+ if (xAdvance < (shyAdvance + 1.0f))
+ QSKIP("Default font not suitable for this test.");
+ QTextLayout layout(text, font);
+ QTextOption option;
+ option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
+ layout.setTextOption(option);
+
+ // Loose fit
+ // xxxx- |
+ // xxxx- |
+ {
+ int pos = 0;
+ int y = 0;
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ line.setLineWidth(qCeil(5 * xAdvance) + 1);
+ line.setPosition(QPoint(0, y));
+ QCOMPARE(line.textStart(), pos);
+ QCOMPARE(line.textLength(), 5);
+ QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+
+ pos += line.textLength();
+ y += qRound(line.ascent() + line.descent());
+
+ line = layout.createLine();
+ line.setLineWidth(qCeil(5 * xAdvance) + 1);
+ line.setPosition(QPoint(0, y));
+ QCOMPARE(line.textStart(), pos);
+ QCOMPARE(line.textLength(), 5);
+ QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+ layout.endLayout();
+ }
+
+ // Tight fit
+ // xxxx-|
+ // xxxx-|
+ {
+ int pos = 0;
+ int y = 0;
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ line.setLineWidth(qCeil(4 * xAdvance + shyAdvance) + 1);
+ line.setPosition(QPoint(0, y));
+ QCOMPARE(line.textStart(), pos);
+ QCOMPARE(line.textLength(), 5);
+ QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+
+ pos += line.textLength();
+ y += qRound(line.ascent() + line.descent());
+
+ line = layout.createLine();
+ line.setLineWidth(qCeil(4 * xAdvance + shyAdvance) + 1);
+ line.setPosition(QPoint(0, y));
+ QCOMPARE(line.textStart(), pos);
+ QCOMPARE(line.textLength(), 5);
+ QVERIFY(qAbs(line.naturalTextWidth() - (4 * xAdvance + shyAdvance)) <= 1);
+ layout.endLayout();
+ }
+
+ // Very tight fit
+ // xxxx|
+ // xxxx|
+ // - |
+ {
+ int pos = 0;
+ int y = 0;
+ layout.beginLayout();
+ QTextLine line = layout.createLine();
+ line.setLineWidth(qCeil(4 * xAdvance) + 2);
+ line.setPosition(QPoint(0, y));
+ QCOMPARE(line.textStart(), pos);
+ QCOMPARE(line.textLength(), 4);
+ QVERIFY(qAbs(line.naturalTextWidth() - 4 * xAdvance) <= 1);
+
+ pos += line.textLength();
+ y += qRound(line.ascent() + line.descent());
+
+ line = layout.createLine();
+ line.setLineWidth(qCeil(4 * xAdvance) + 2);
+ line.setPosition(QPoint(0, y));
+ QCOMPARE(line.textStart(), pos);
+ QCOMPARE(line.textLength(), 5);
+ QVERIFY(qAbs(line.naturalTextWidth() - 4 * xAdvance) <= 1);
+
+ pos += line.textLength();
+ y += qRound(line.ascent() + line.descent());
+
+ line = layout.createLine();
+ line.setLineWidth(qCeil(4 * xAdvance) + 2);
+ line.setPosition(QPoint(0, y));
+ QCOMPARE(line.textStart(), pos);
+ QCOMPARE(line.textLength(), 1);
+ QVERIFY(qAbs(line.naturalTextWidth() - shyAdvance) <= 1);
+ layout.endLayout();
+ }
+}
+
QTEST_MAIN(tst_QTextLayout)
#include "tst_qtextlayout.moc"