diff options
author | Martin Jones <martin.jones@nokia.com> | 2012-07-27 13:38:43 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-27 08:43:06 +0200 |
commit | d3224ad22a38264aaae81e96384182aee7c1053f (patch) | |
tree | bfe95c25c969ce90d17a42868f57a7893633d5d3 /tests/auto/quick/qquickpixmapcache | |
parent | 0408dcd6a9d45e110610c6ed14987189d4e16c90 (diff) |
Pixmap loader adds images to unreferenced list when cache: false
Don't add uncached images to the unreferenced list, since
they cannot be reused later as they are not in the cache.
Additionally, we currently search for images in the cache, even if we
set cache: false. Setting cache false should not put images in the cache
and should not use images that are in the cache.
Task-number: QTBUG-26676
Change-Id: Ib7eb42199ae6ae6154b696c83ad1dd959e0f208f
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickpixmapcache')
-rw-r--r-- | tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp index fb2405c27a..c238ed863f 100644 --- a/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp +++ b/tests/auto/quick/qquickpixmapcache/tst_qquickpixmapcache.cpp @@ -74,6 +74,7 @@ private slots: void networkCrash(); #endif void lockingCrash(); + void uncached(); #if PIXMAP_DATA_LEAK_TEST void dataLeak(); #endif @@ -352,11 +353,15 @@ public: virtual QPixmap requestPixmap(const QString &d, QSize *, const QSize &) { Q_UNUSED(d) QPixmap pix(800, 600); - pix.fill(Qt::red); + pix.fill(fillColor); return pix; } + + static QRgb fillColor; }; +QRgb MyPixmapProvider::fillColor = qRgb(255, 0, 0); + // QTBUG-13345 void tst_qquickpixmapcache::shrinkcache() { @@ -417,6 +422,56 @@ void tst_qquickpixmapcache::lockingCrash() } } +void tst_qquickpixmapcache::uncached() +{ + QQmlEngine engine; + engine.addImageProvider(QLatin1String("mypixmaps"), new MyPixmapProvider); + + QUrl url("image://mypixmaps/mypix"); + { + QQuickPixmap p; + p.load(&engine, url, 0); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(255, 0, 0)); + } + + // uncached, so we will get a different colored image + MyPixmapProvider::fillColor = qRgb(0, 255, 0); + { + QQuickPixmap p; + p.load(&engine, url, 0); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(0, 255, 0)); + } + + // Load the image with cache enabled + MyPixmapProvider::fillColor = qRgb(0, 0, 255); + { + QQuickPixmap p; + p.load(&engine, url, QQuickPixmap::Cache); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(0, 0, 255)); + } + + // We should not get the cached version if we request uncached + MyPixmapProvider::fillColor = qRgb(255, 0, 255); + { + QQuickPixmap p; + p.load(&engine, url, 0); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(255, 0, 255)); + } + + // If we again load the image with cache enabled, we should get the previously cached version + MyPixmapProvider::fillColor = qRgb(0, 255, 255); + { + QQuickPixmap p; + p.load(&engine, url, QQuickPixmap::Cache); + QImage img = p.image(); + QCOMPARE(img.pixel(0,0), qRgb(0, 0, 255)); + } +} + #if PIXMAP_DATA_LEAK_TEST // This test should not be enabled by default as it |