From 72854081b2e3831ab6619a9c2e7f4ba0a6a1d316 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 20 Feb 2015 14:54:34 +0100 Subject: Add tests for detach on setDevicePixelRatio() Change-Id: I414ff0b794e0202a7f8c931b59b973cb1e7dc148 Reviewed-by: Paul Olav Tvete --- tests/auto/gui/image/qimage/tst_qimage.cpp | 29 ++++++++++++++++++++++++++++ tests/auto/gui/image/qpixmap/tst_qpixmap.cpp | 28 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index decd4ef931..0f9bdc7a1a 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -178,6 +178,8 @@ private slots: void cleanupFunctions(); + void devicePixelRatio(); + private: const QString m_prefix; }; @@ -2730,5 +2732,32 @@ void tst_QImage::cleanupFunctions() } +// test image devicePixelRatio setting and detaching +void tst_QImage::devicePixelRatio() +{ + // create image + QImage a(64, 64, QImage::Format_ARGB32); + a.fill(Qt::white); + QCOMPARE(a.devicePixelRatio(), qreal(1.0)); + QCOMPARE(a.isDetached(), true); + + // copy image + QImage b = a; + QCOMPARE(b.devicePixelRatio(), qreal(1.0)); + QCOMPARE(a.isDetached(), false); + QCOMPARE(b.isDetached(), false); + + // set devicePixelRatio to the current value: does not detach + a.setDevicePixelRatio(qreal(1.0)); + QCOMPARE(a.isDetached(), false); + QCOMPARE(b.isDetached(), false); + + // set devicePixelRatio to a new value: may detach (currently + // does, but we may want to avoid the data copy the future) + a.setDevicePixelRatio(qreal(2.0)); + QCOMPARE(a.devicePixelRatio(), qreal(2.0)); + QCOMPARE(b.devicePixelRatio(), qreal(1.0)); +} + QTEST_GUILESS_MAIN(tst_QImage) #include "tst_qimage.moc" diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 0fda8482ce..58cc5824bd 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -164,6 +164,7 @@ private slots: void detachOnLoad_QTBUG29639(); void copyOnNonAlignedBoundary(); + void devicePixelRatio(); private: const QString m_prefix; @@ -1543,5 +1544,32 @@ void tst_QPixmap::copyOnNonAlignedBoundary() QPixmap pm2 = pm1.copy(QRect(5, 0, 3, 2)); // When copying second line: 2 bytes too many are read which might cause an access violation. } +// test pixmap devicePixelRatio setting and detaching +void tst_QPixmap::devicePixelRatio() +{ + // create pixmap + QPixmap a(64, 64); + a.fill(Qt::white); + QCOMPARE(a.devicePixelRatio(), qreal(1.0)); + QCOMPARE(a.isDetached(), true); + + // copy pixmap + QPixmap b = a; + QCOMPARE(b.devicePixelRatio(), qreal(1.0)); + QCOMPARE(a.isDetached(), false); + QCOMPARE(b.isDetached(), false); + + // set devicePixelRatio to the current value: does not detach + a.setDevicePixelRatio(qreal(1.0)); + QCOMPARE(a.isDetached(), false); + QCOMPARE(b.isDetached(), false); + + // set devicePixelRatio to a new value: may detach (currently + // does, but we may want to avoid the data copy the future) + a.setDevicePixelRatio(qreal(2.0)); + QCOMPARE(a.devicePixelRatio(), qreal(2.0)); + QCOMPARE(b.devicePixelRatio(), qreal(1.0)); +} + QTEST_MAIN(tst_QPixmap) #include "tst_qpixmap.moc" -- cgit v1.2.3