diff options
-rw-r--r-- | src/corelib/tools/qcache.h | 3 | ||||
-rw-r--r-- | tests/auto/qpixmapcache/tst_qpixmapcache.cpp | 25 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h index 16861c9..2408cd3 100644 --- a/src/corelib/tools/qcache.h +++ b/src/corelib/tools/qcache.h @@ -205,8 +205,7 @@ void QCache<Key,T>::trim(int m) while (n && total > m) { Node *u = n; n = n->p; - if (qIsDetached(*u->t)) - unlink(*u); + unlink(*u); } } diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp index 9f7192d..b36cf98 100644 --- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp @@ -72,6 +72,7 @@ private slots: void clear(); void pixmapKey(); void noLeak(); + void strictCacheLimit(); }; static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key) @@ -517,5 +518,29 @@ void tst_QPixmapCache::noLeak() QCOMPARE(oldSize, newSize); } + +void tst_QPixmapCache::strictCacheLimit() +{ + const int limit = 1024; // 1024 KB + + QPixmapCache::clear(); + QPixmapCache::setCacheLimit(limit); + + // insert 200 64x64 pixmaps + // 3200 KB for 32-bit depths + // 1600 KB for 16-bit depths + // not counting the duplicate entries + for (int i = 0; i < 200; ++i) { + QPixmap pixmap(64, 64); + pixmap.fill(Qt::transparent); + + QString id = QString::number(i); + QPixmapCache::insert(id + "-a", pixmap); + QPixmapCache::insert(id + "-b", pixmap); + } + + QVERIFY(QPixmapCache::totalUsed() <= limit); +} + QTEST_MAIN(tst_QPixmapCache) #include "tst_qpixmapcache.moc" |