summaryrefslogtreecommitdiffstats
path: root/tests/auto/qpixmapcache
diff options
context:
space:
mode:
authorSamuel Rødal <sroedal@trolltech.com>2009-12-10 16:22:53 (GMT)
committerSamuel Rødal <sroedal@trolltech.com>2009-12-10 17:43:30 (GMT)
commit3a8a1f83d60ec16e4c61e2b0a327a5af02917a5a (patch)
treef73f7623cb2eb3fc76e4c1333364216d884ae4bd /tests/auto/qpixmapcache
parentbf9456c5a2d8dfe9a35a2175186630cb426858ad (diff)
downloadQt-3a8a1f83d60ec16e4c61e2b0a327a5af02917a5a.zip
Qt-3a8a1f83d60ec16e4c61e2b0a327a5af02917a5a.tar.gz
Qt-3a8a1f83d60ec16e4c61e2b0a327a5af02917a5a.tar.bz2
Prevented leak of keys in QPixmapCache.
Removing a pixmap from the pixmap cache using the new QPixmapCache::Key API left the keys dangling in the QCache's internal QHash. The problem is that the Key is invalidated as soon as the QPixmapCacheEntry is destroyed, thus removing it from the hash failed. Reordering the destruction of the object and the removal of the key in QHash fixes the problem. Reviewed-by: Alexis Reviewed-by: Thiago
Diffstat (limited to 'tests/auto/qpixmapcache')
-rw-r--r--tests/auto/qpixmapcache/tst_qpixmapcache.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp
index 9775d36..c89a182 100644
--- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp
+++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp
@@ -70,6 +70,7 @@ private slots:
void remove();
void clear();
void pixmapKey();
+ void noLeak();
};
static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key)
@@ -482,5 +483,23 @@ void tst_QPixmapCache::pixmapKey()
QVERIFY(!getPrivate(key8));
}
+extern int q_QPixmapCache_keyHashSize();
+
+void tst_QPixmapCache::noLeak()
+{
+ QPixmapCache::Key key;
+
+ int oldSize = q_QPixmapCache_keyHashSize();
+ for (int i = 0; i < 100; ++i) {
+ QPixmap pm(128, 128);
+ pm.fill(Qt::transparent);
+ key = QPixmapCache::insert(pm);
+ QPixmapCache::remove(key);
+ }
+ int newSize = q_QPixmapCache_keyHashSize();
+
+ QCOMPARE(oldSize, newSize);
+}
+
QTEST_MAIN(tst_QPixmapCache)
#include "tst_qpixmapcache.moc"