summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMÃ¥rten Nordheim <marten.nordheim@qt.io>2021-01-12 17:25:03 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-14 13:44:30 +0000
commitbaa035684998616ec47bd4812fa24d25d1f5da2b (patch)
tree446ffc37058118e708ea8530864b3182ca5305fa /tests
parent9e4d9fca8a5ed0a10033345bc88b4ae39d20b952 (diff)
QCache: when overwriting, store the new cost instead of the delta
The delta was clearly intended to be used on the total (and still is) but it also wound up getting stored in the cache, which wouldn't be a big problem unless the object was removed, in which case we could incidentally 'free up more space' than intended. Change-Id: Ib2b0f072d30da6d16a93dce60e4c5f6080c109fc Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit d2e2d0d3a6249ccbc17ec92acb32fec9a0d71807) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/tools/qcache/tst_qcache.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qcache/tst_qcache.cpp b/tests/auto/corelib/tools/qcache/tst_qcache.cpp
index 54cf00f9da..da6f1bb34b 100644
--- a/tests/auto/corelib/tools/qcache/tst_qcache.cpp
+++ b/tests/auto/corelib/tools/qcache/tst_qcache.cpp
@@ -49,6 +49,7 @@ private slots:
void axioms_on_key_type();
void largeCache();
void internalChainOrderAfterEntryUpdate();
+ void emplaceLowerCost();
};
@@ -431,5 +432,18 @@ void tst_QCache::internalChainOrderAfterEntryUpdate()
QCOMPARE(cache.size(), 0);
}
+void tst_QCache::emplaceLowerCost()
+{
+ QCache<QString, int> cache;
+ cache.setMaxCost(5);
+ cache.insert("a", new int, 3); // insert high cost
+ cache.insert("a", new int, 1); // and then exchange it with a lower-cost object
+ QCOMPARE(cache.totalCost(), 1);
+ cache.remove("a"); // then remove the object
+ // The cache should now have a cost == 0 and be empty.
+ QCOMPARE(cache.totalCost(), 0);
+ QVERIFY(cache.isEmpty());
+}
+
QTEST_APPLESS_MAIN(tst_QCache)
#include "tst_qcache.moc"