summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2010-12-06 13:06:56 (GMT)
committerSamuel Rødal <samuel.rodal@nokia.com>2010-12-06 14:14:28 (GMT)
commit9a63863d6f0c614c041c3d4b375bf88d93148ef7 (patch)
tree73397d058acc2051261f6550b46d97a31faa8195 /tests
parent6ae84f1183e91c910ca92a55e37f8254ace805c0 (diff)
downloadQt-9a63863d6f0c614c041c3d4b375bf88d93148ef7.zip
Qt-9a63863d6f0c614c041c3d4b375bf88d93148ef7.tar.gz
Qt-9a63863d6f0c614c041c3d4b375bf88d93148ef7.tar.bz2
Make sure to do a deep copy of a QImage when it's being painted on.
Not doing so can produce some hard-to-track-down bugs in the app. Task-number: QTBUG-15749 Reviewed-by: Gunnar Sletta
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qimage/tst_qimage.cpp16
-rw-r--r--tests/auto/qpixmap/tst_qpixmap.cpp17
2 files changed, 33 insertions, 0 deletions
diff --git a/tests/auto/qimage/tst_qimage.cpp b/tests/auto/qimage/tst_qimage.cpp
index b446941..b2c59fc 100644
--- a/tests/auto/qimage/tst_qimage.cpp
+++ b/tests/auto/qimage/tst_qimage.cpp
@@ -142,6 +142,8 @@ private slots:
void rgbSwapped_data();
void rgbSwapped();
+
+ void deepCopyWhenPaintingActive();
};
tst_QImage::tst_QImage()
@@ -1886,5 +1888,19 @@ void tst_QImage::rgbSwapped()
QCOMPARE(memcmp(image.constBits(), imageSwappedTwice.constBits(), image.numBytes()), 0);
}
+void tst_QImage::deepCopyWhenPaintingActive()
+{
+ QImage image(64, 64, QImage::Format_ARGB32_Premultiplied);
+ image.fill(0);
+
+ QPainter painter(&image);
+ QImage copy = image;
+
+ painter.setBrush(Qt::black);
+ painter.drawEllipse(image.rect());
+
+ QVERIFY(copy != image);
+}
+
QTEST_MAIN(tst_QImage)
#include "tst_qimage.moc"
diff --git a/tests/auto/qpixmap/tst_qpixmap.cpp b/tests/auto/qpixmap/tst_qpixmap.cpp
index 51e6cf5..d5267b5 100644
--- a/tests/auto/qpixmap/tst_qpixmap.cpp
+++ b/tests/auto/qpixmap/tst_qpixmap.cpp
@@ -185,6 +185,8 @@ private slots:
void preserveDepth();
void splash_crash();
+ void toImageDeepCopy();
+
void loadAsBitmapOrPixmap();
};
@@ -1751,6 +1753,21 @@ void tst_QPixmap::loadAsBitmapOrPixmap()
QVERIFY(bitmap.isQBitmap());
}
+void tst_QPixmap::toImageDeepCopy()
+{
+ QPixmap pixmap(64, 64);
+ pixmap.fill(Qt::white);
+
+ QPainter painter(&pixmap);
+ QImage first = pixmap.toImage();
+
+ painter.setBrush(Qt::black);
+ painter.drawEllipse(pixmap.rect());
+
+ QImage second = pixmap.toImage();
+
+ QVERIFY(first != second);
+}
QTEST_MAIN(tst_QPixmap)