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>
This commit is contained in:
parent
6032845ca2
commit
e409d771d9
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user