summaryrefslogtreecommitdiffstats
path: root/tests/auto/qpainter/tst_qpainter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qpainter/tst_qpainter.cpp')
-rw-r--r--tests/auto/qpainter/tst_qpainter.cpp84
1 files changed, 79 insertions, 5 deletions
diff --git a/tests/auto/qpainter/tst_qpainter.cpp b/tests/auto/qpainter/tst_qpainter.cpp
index c21514b9c6..984443490f 100644
--- a/tests/auto/qpainter/tst_qpainter.cpp
+++ b/tests/auto/qpainter/tst_qpainter.cpp
@@ -72,11 +72,13 @@
#include <qgraphicsscene.h>
#include <qgraphicsproxywidget.h>
#include <qlayout.h>
+#include <qfontdatabase.h>
#if defined(Q_OS_SYMBIAN)
# define SRCDIR "."
#endif
+Q_DECLARE_METATYPE(QGradientStops)
Q_DECLARE_METATYPE(QLine)
Q_DECLARE_METATYPE(QRect)
Q_DECLARE_METATYPE(QSize)
@@ -189,6 +191,7 @@ private slots:
void fillRect_stretchToDeviceMode();
void monoImages();
+ void linearGradientSymmetry_data();
void linearGradientSymmetry();
void gradientInterpolation();
@@ -264,6 +267,8 @@ private slots:
void QTBUG17053_zeroDashPattern();
+ void drawTextOutsideGuiThread();
+
private:
void fillData();
void setPenColor(QPainter& p);
@@ -3983,8 +3988,42 @@ static QLinearGradient inverseGradient(QLinearGradient g)
return g2;
}
+void tst_QPainter::linearGradientSymmetry_data()
+{
+ QTest::addColumn<QGradientStops>("stops");
+
+ if (sizeof(qreal) != sizeof(float)) {
+ QGradientStops stops;
+ stops << qMakePair(qreal(0.0), QColor(Qt::blue));
+ stops << qMakePair(qreal(0.2), QColor(220, 220, 220, 0));
+ stops << qMakePair(qreal(0.6), QColor(Qt::red));
+ stops << qMakePair(qreal(0.9), QColor(220, 220, 220, 255));
+ stops << qMakePair(qreal(1.0), QColor(Qt::black));
+ QTest::newRow("multiple stops") << stops;
+ }
+
+ {
+ QGradientStops stops;
+ stops << qMakePair(qreal(0.0), QColor(Qt::blue));
+ stops << qMakePair(qreal(1.0), QColor(Qt::black));
+ QTest::newRow("two stops") << stops;
+ }
+
+ if (sizeof(qreal) != sizeof(float)) {
+ QGradientStops stops;
+ stops << qMakePair(qreal(0.3), QColor(Qt::blue));
+ stops << qMakePair(qreal(0.6), QColor(Qt::black));
+ QTest::newRow("two stops 2") << stops;
+ }
+}
+
void tst_QPainter::linearGradientSymmetry()
{
+#ifdef Q_WS_QWS
+ QSKIP("QWS has limited resolution in the gradient color table", SkipAll);
+#else
+ QFETCH(QGradientStops, stops);
+
QImage a(64, 8, QImage::Format_ARGB32_Premultiplied);
QImage b(64, 8, QImage::Format_ARGB32_Premultiplied);
@@ -3992,11 +4031,7 @@ void tst_QPainter::linearGradientSymmetry()
b.fill(0);
QLinearGradient gradient(QRectF(b.rect()).topLeft(), QRectF(b.rect()).topRight());
- gradient.setColorAt(0.0, Qt::blue);
- gradient.setColorAt(0.2, QColor(220, 220, 220, 0));
- gradient.setColorAt(0.6, Qt::red);
- gradient.setColorAt(0.9, QColor(220, 220, 220, 255));
- gradient.setColorAt(1.0, Qt::black);
+ gradient.setStops(stops);
QPainter pa(&a);
pa.fillRect(a.rect(), gradient);
@@ -4008,6 +4043,7 @@ void tst_QPainter::linearGradientSymmetry()
b = b.mirrored(true);
QCOMPARE(a, b);
+#endif
}
void tst_QPainter::gradientInterpolation()
@@ -4706,6 +4742,44 @@ void tst_QPainter::QTBUG17053_zeroDashPattern()
QCOMPARE(image, original);
}
+class TextDrawerThread : public QThread
+{
+public:
+ void run();
+ QImage rendering;
+};
+
+void TextDrawerThread::run()
+{
+ rendering = QImage(100, 100, QImage::Format_ARGB32_Premultiplied);
+ rendering.fill(0);
+ QPainter p(&rendering);
+ p.fillRect(10, 10, 100, 100, Qt::blue);
+ p.setPen(Qt::green);
+ p.drawText(20, 20, "some text");
+ p.end();
+}
+
+void tst_QPainter::drawTextOutsideGuiThread()
+{
+ if (!QFontDatabase::supportsThreadedFontRendering())
+ QSKIP("No threaded font rendering", SkipAll);
+
+ QImage referenceRendering(100, 100, QImage::Format_ARGB32_Premultiplied);
+ referenceRendering.fill(0);
+ QPainter p(&referenceRendering);
+ p.fillRect(10, 10, 100, 100, Qt::blue);
+ p.setPen(Qt::green);
+ p.drawText(20, 20, "some text");
+ p.end();
+
+ TextDrawerThread t;
+ t.start();
+ t.wait();
+
+ QCOMPARE(referenceRendering, t.rendering);
+}
+
QTEST_MAIN(tst_QPainter)
#include "tst_qpainter.moc"