From 986c09f815ead14904fbef886d5e776b9627fee6 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 19 Dec 2019 15:07:15 +0100 Subject: [PATCH] Test QImage move semantics Tests the move semantics of QImage in Qt6. Change-Id: Ia4d95f0b88ca7dde0daf85a0f53049b42b5be1a5 Reviewed-by: Giuseppe D'Angelo --- tests/auto/gui/image/qimage/tst_qimage.cpp | 35 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 98de3dc5df..7ef700c01d 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -3369,7 +3369,7 @@ void tst_QImage::cleanupFunctions() { called = false; - QImage *copy = 0; + QImage *copy = nullptr; { QImage image(bufferImage.bits(), bufferImage.width(), bufferImage.height(), bufferImage.format(), cleanupFunction, &called); copy = new QImage(image); @@ -3378,7 +3378,38 @@ void tst_QImage::cleanupFunctions() delete copy; QVERIFY(called); } - + { + called = false; + QImage container; + { + QImage image(bufferImage.bits(), bufferImage.width(), bufferImage.height(), bufferImage.format(), cleanupFunction, &called); + container = std::move(image); + // Test methods don't crash after move: + Q_UNUSED(image.isNull()); + Q_UNUSED(image.width()); + Q_UNUSED(image.bytesPerLine()); + Q_UNUSED(image.sizeInBytes()); + Q_UNUSED(image.constBits()); + } + // 'image' was moved and should outlive its scope + QVERIFY(!called); + container = QImage(); + QVERIFY(called); + } + { + called = false; + QImage outer(bufferImage.bits(), bufferImage.width(), bufferImage.height(), bufferImage.format(), cleanupFunction, &called); + bool called2 = false; + { + uchar internalData[256]; + QImage internal(internalData, 16, 16, QImage::Format_Grayscale8, cleanupFunction, &called2); + internal = std::move(outer); + } + // 'internal' was _not_ moved and should not outlive its original scope + QVERIFY(called2); + // 'outer' was moved into the inner scope and should now be dead. + QVERIFY(called); + } } // test image devicePixelRatio setting and detaching