tst_QPixmapCache: check we leak QString keys of evicted pixmaps
Task-number: QTBUG-112200 Change-Id: Icf0a40b68a4ef3ec930a74b47e6ca88d9d0060ca Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit b74ef9ee48127c8cb65a87d7cf943134b8ef6886) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
9d6543ea40
commit
55fbb4c372
@ -7,6 +7,8 @@
|
|||||||
#include <qpixmapcache.h>
|
#include <qpixmapcache.h>
|
||||||
#include "private/qpixmapcache_p.h"
|
#include "private/qpixmapcache_p.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE // The test requires QT_BUILD_INTERNAL
|
QT_BEGIN_NAMESPACE // The test requires QT_BUILD_INTERNAL
|
||||||
Q_AUTOTEST_EXPORT void qt_qpixmapcache_flush_detached_pixmaps();
|
Q_AUTOTEST_EXPORT void qt_qpixmapcache_flush_detached_pixmaps();
|
||||||
Q_AUTOTEST_EXPORT int qt_qpixmapcache_qpixmapcache_total_used();
|
Q_AUTOTEST_EXPORT int qt_qpixmapcache_qpixmapcache_total_used();
|
||||||
@ -40,8 +42,13 @@ private slots:
|
|||||||
void pixmapKey();
|
void pixmapKey();
|
||||||
void noLeak();
|
void noLeak();
|
||||||
void clearDoesNotLeakStringKeys();
|
void clearDoesNotLeakStringKeys();
|
||||||
|
void evictionDoesNotLeakStringKeys();
|
||||||
|
void reducingCacheLimitDoesNotLeakStringKeys();
|
||||||
void strictCacheLimit();
|
void strictCacheLimit();
|
||||||
void noCrashOnLargeInsert();
|
void noCrashOnLargeInsert();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void stringLeak_impl(std::function<void()> whenOp);
|
||||||
};
|
};
|
||||||
|
|
||||||
static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key)
|
static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key)
|
||||||
@ -522,6 +529,35 @@ void tst_QPixmapCache::noLeak()
|
|||||||
|
|
||||||
void tst_QPixmapCache::clearDoesNotLeakStringKeys()
|
void tst_QPixmapCache::clearDoesNotLeakStringKeys()
|
||||||
{
|
{
|
||||||
|
stringLeak_impl([] { QPixmapCache::clear(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QPixmapCache::evictionDoesNotLeakStringKeys()
|
||||||
|
{
|
||||||
|
stringLeak_impl([] {
|
||||||
|
// fill the cache with other pixmaps to force eviction of "our" pixmap:
|
||||||
|
constexpr int Iterations = 10;
|
||||||
|
for (int i = 0; i < Iterations; ++i) {
|
||||||
|
QPixmap pm(64, 64);
|
||||||
|
pm.fill(Qt::transparent);
|
||||||
|
[[maybe_unused]] auto r = QPixmapCache::insert(pm);
|
||||||
|
}
|
||||||
|
QEXPECT_FAIL("", "QTBUG-112200", Continue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QPixmapCache::reducingCacheLimitDoesNotLeakStringKeys()
|
||||||
|
{
|
||||||
|
stringLeak_impl([] {
|
||||||
|
QPixmapCache::setCacheLimit(0);
|
||||||
|
QEXPECT_FAIL("", "QTBUG-112200", Continue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void tst_QPixmapCache::stringLeak_impl(std::function<void()> whenOp)
|
||||||
|
{
|
||||||
|
QVERIFY(whenOp);
|
||||||
|
|
||||||
QPixmapCache::setCacheLimit(20); // 20KiB
|
QPixmapCache::setCacheLimit(20); // 20KiB
|
||||||
//
|
//
|
||||||
// GIVEN: a QPixmap with QString key `key` in QPixmapCache
|
// GIVEN: a QPixmap with QString key `key` in QPixmapCache
|
||||||
@ -539,9 +575,11 @@ void tst_QPixmapCache::clearDoesNotLeakStringKeys()
|
|||||||
QVERIFY(!key.isDetached()); // was saved inside QPixmapCache
|
QVERIFY(!key.isDetached()); // was saved inside QPixmapCache
|
||||||
|
|
||||||
//
|
//
|
||||||
// WHEN: clearing the cache:
|
// WHEN: performing the given operation
|
||||||
//
|
//
|
||||||
QPixmapCache::clear();
|
whenOp();
|
||||||
|
if (QTest::currentTestFailed())
|
||||||
|
return;
|
||||||
|
|
||||||
//
|
//
|
||||||
// THEN: `key` is no longer referenced by QPixmapCache:
|
// THEN: `key` is no longer referenced by QPixmapCache:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user