Test QImage move semantics

Tests the move semantics of QImage in Qt6.

Change-Id: Ia4d95f0b88ca7dde0daf85a0f53049b42b5be1a5
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
bb10
Allan Sandfeld Jensen 2019-12-19 15:07:15 +01:00
parent 1f9ec097b2
commit 986c09f815
1 changed files with 33 additions and 2 deletions

View File

@ -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