summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/tools/qcache.h3
-rw-r--r--tests/auto/collections/tst_collections.cpp2
-rw-r--r--tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp25
3 files changed, 27 insertions, 3 deletions
diff --git a/src/corelib/tools/qcache.h b/src/corelib/tools/qcache.h
index c42a908f5c..2928140863 100644
--- a/src/corelib/tools/qcache.h
+++ b/src/corelib/tools/qcache.h
@@ -196,8 +196,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/collections/tst_collections.cpp b/tests/auto/collections/tst_collections.cpp
index e8ce83cb75..7c13ecf4b1 100644
--- a/tests/auto/collections/tst_collections.cpp
+++ b/tests/auto/collections/tst_collections.cpp
@@ -2413,7 +2413,7 @@ void tst_Collections::cache()
two = s;
}
QVERIFY(!cache.contains(3));
- QVERIFY(cache.contains(2));
+ QVERIFY(!cache.contains(2));
}
{
QCache<int, int> cache(100);
diff --git a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
index e8f749d946..25a43404c4 100644
--- a/tests/auto/gui/image/qpixmapcache/tst_qpixmapcache.cpp
+++ b/tests/auto/gui/image/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"