diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-12-19 15:07:15 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-16 18:49:01 +0200 |
commit | 986c09f815ead14904fbef886d5e776b9627fee6 (patch) | |
tree | 447c23d21f8e27c73cd8f555890f4afde123c065 /tests | |
parent | 1f9ec097b2171f9773b8285c67a2f852d680a73a (diff) |
Test QImage move semantics
Tests the move semantics of QImage in Qt6.
Change-Id: Ia4d95f0b88ca7dde0daf85a0f53049b42b5be1a5
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/gui/image/qimage/tst_qimage.cpp | 35 |
1 files 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 |