summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/image/qimage
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-01-31 13:32:22 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-31 16:21:17 +0100
commit298330bd436ca9437aa8023363f916b12811c7bf (patch)
treebbcfc14412984c75a183eca9ddc4244bbcc55edb /tests/auto/gui/image/qimage
parent2bf186a2e598a4bccdc4979085e8e4d963a3819d (diff)
Add support for cleanup functions for data-constructed QImages
A QImage can be constructed with a provided buffer, that has to be kept alive for the live-time of the QImage and all its copies. Frameworks like CoreGraphics or Cairo offer a similar method of creating image objects and also offer the ability to provide a callback function that is called when the image is destroyed. This patch adds this functionality to QImage by extending the QImage constructors that take a raw image buffer pointer. Change-Id: Ia6342408c560ef49b498c9e4664b4602febb0fcd Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com> Reviewed-by: Michalina Ziemba <michalina.ziemba@nokia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
Diffstat (limited to 'tests/auto/gui/image/qimage')
-rw-r--r--tests/auto/gui/image/qimage/tst_qimage.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp
index 173c299b69..cda887d8e1 100644
--- a/tests/auto/gui/image/qimage/tst_qimage.cpp
+++ b/tests/auto/gui/image/qimage/tst_qimage.cpp
@@ -144,6 +144,8 @@ private slots:
void deepCopyWhenPaintingActive();
void scaled_QTBUG19157();
+
+ void cleanupFunctions();
};
tst_QImage::tst_QImage()
@@ -1997,5 +1999,40 @@ void tst_QImage::scaled_QTBUG19157()
QVERIFY(!foo.isNull());
}
+static void cleanupFunction(void* info)
+{
+ bool *called = static_cast<bool*>(info);
+ *called = true;
+}
+
+void tst_QImage::cleanupFunctions()
+{
+ QImage bufferImage(64, 64, QImage::Format_ARGB32);
+ bufferImage.fill(0);
+
+ bool called;
+
+ {
+ called = false;
+ {
+ QImage image(bufferImage.bits(), bufferImage.width(), bufferImage.height(), bufferImage.format(), cleanupFunction, &called);
+ }
+ QVERIFY(called);
+ }
+
+ {
+ called = false;
+ QImage *copy = 0;
+ {
+ QImage image(bufferImage.bits(), bufferImage.width(), bufferImage.height(), bufferImage.format(), cleanupFunction, &called);
+ copy = new QImage(image);
+ }
+ QVERIFY(!called);
+ delete copy;
+ QVERIFY(called);
+ }
+
+}
+
QTEST_MAIN(tst_QImage)
#include "tst_qimage.moc"