summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-06-07 07:15:30 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-06-09 14:32:48 +0200
commite409d771d922b9772a0ecb4da575c6fd6f95676f (patch)
tree22255719c199ba974e3f579e13997a7488b7f46a
parent6032845ca2fc69fb67971ea9f7e06588ffcbe9f3 (diff)
tst_QPixmapCache: check insert() reports failure
None of the existing tests failed when I started to return a valid key from a failed insert(QPixmap), so add a test that would fail. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: I74f23d2ec4c04151f8f1266c0c503713d4642f3a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
index 407117c75b..84b4831768 100644
--- a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
+++ b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
@@ -31,6 +31,7 @@ private slots:
void setCacheLimit();
void find();
void insert();
+ void failedInsertReturnsInvalidKey();
void replace();
void remove();
void clear();
@@ -269,6 +270,7 @@ void tst_QPixmapCache::insert()
for (int i = 0; i < numberOfKeys; ++i) {
QPixmap p3(10,10);
keys.append(QPixmapCache::insert(p3));
+ QVERIFY(keys.back().isValid());
}
num = 0;
@@ -282,6 +284,32 @@ void tst_QPixmapCache::insert()
QVERIFY(num <= estimatedNum);
}
+void tst_QPixmapCache::failedInsertReturnsInvalidKey()
+{
+ //
+ // GIVEN: a pixmap whose memory footprint exceeds the cache's limit:
+ //
+ QPixmapCache::setCacheLimit(20);
+
+ QPixmap pm(256, 256);
+ pm.fill(Qt::transparent);
+ QCOMPARE_GT(pm.width() * pm.height() * pm.depth() / 8,
+ QPixmapCache::cacheLimit() * 1024);
+
+ //
+ // WHEN: trying to add this pixmap to the cache
+ //
+ const auto success = QPixmapCache::insert(u"foo"_s, pm); // QString API
+ { QPixmap r; QVERIFY(!QPixmapCache::find(u"foo"_s, &r)); }
+ const auto key = QPixmapCache::insert(pm); // "int" API
+
+ //
+ // THEN: failure is reported to the user
+ //
+ QVERIFY(!key.isValid()); // "int" API
+ QVERIFY(!success); // QString API
+}
+
void tst_QPixmapCache::replace()
{
//The int part of the API