diff options
author | Janne Anttila <janne.anttila@digia.com> | 2009-10-05 13:07:30 (GMT) |
---|---|---|
committer | Janne Anttila <janne.anttila@digia.com> | 2009-10-05 13:09:23 (GMT) |
commit | bfe0e5c0d47780542b174dc96973920fba11c451 (patch) | |
tree | 3f475f2aa778ba50bfae5999544c01eb910e3de2 /tests | |
parent | b73f1b3d88927b0c51c0624f67695cfd80167d38 (diff) | |
download | Qt-bfe0e5c0d47780542b174dc96973920fba11c451.zip Qt-bfe0e5c0d47780542b174dc96973920fba11c451.tar.gz Qt-bfe0e5c0d47780542b174dc96973920fba11c451.tar.bz2 |
Fixes to qpixmapcache test cases, test case now adapts to cache_limit.
The default cache_limit in different platforms have different value.
For example in Symbian the default is currently 1024 KB where as for
desktop platforms the default is 10 MB.
The purpose of modified qpixmapcache test cases was to do operations
until cache_limit was reached. This was achieved by hard coded 40000
iterations. However this hard-coded value is fargile for cache limit
changes, and in addition it unnecessarily made the test exectuion to
take very long time on platforms which had smaller cache limit.
This patch changes the test so that number of expected items to fit
in cache is calculated and then 1000 extra items is tried to put
in cache to make sure limit is exceeded.
Reviewed-by: Alexis Menard
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qpixmapcache/tst_qpixmapcache.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp index b487d74..9775d36 100644 --- a/tests/auto/qpixmapcache/tst_qpixmapcache.cpp +++ b/tests/auto/qpixmapcache/tst_qpixmapcache.cpp @@ -244,16 +244,23 @@ void tst_QPixmapCache::insert() QPixmap p2(10, 10); p2.fill(Qt::yellow); + // Calcuate estimated num of items what fits to cache + int estimatedNum = (1024 * QPixmapCache::cacheLimit()) + / ((p1.width() * p1.height() * p1.depth()) / 8); + + // Mare sure we will put enough items to reach the cache limit + const int numberOfKeys = estimatedNum + 1000; + // make sure it doesn't explode - for (int i = 0; i < 20000; ++i) + for (int i = 0; i < numberOfKeys; ++i) QPixmapCache::insert("0", p1); // ditto - for (int j = 0; j < 40000; ++j) + for (int j = 0; j < numberOfKeys; ++j) QPixmapCache::insert(QString::number(j), p1); int num = 0; - for (int k = 0; k < 40000; ++k) { + for (int k = 0; k < numberOfKeys; ++k) { if (QPixmapCache::find(QString::number(k))) ++num; } @@ -261,9 +268,6 @@ void tst_QPixmapCache::insert() if (QPixmapCache::find("0")) ++num; - int estimatedNum = (1024 * QPixmapCache::cacheLimit()) - / ((p1.width() * p1.height() * p1.depth()) / 8); - QVERIFY(num <= estimatedNum); QPixmap p3; QPixmapCache::insert("null", p3); @@ -281,11 +285,11 @@ void tst_QPixmapCache::insert() //The int part of the API // make sure it doesn't explode QList<QPixmapCache::Key> keys; - for (int i = 0; i < 40000; ++i) + for (int i = 0; i < numberOfKeys; ++i) keys.append(QPixmapCache::insert(p1)); num = 0; - for (int k = 0; k < 40000; ++k) { + for (int k = 0; k < numberOfKeys; ++k) { if (QPixmapCache::find(keys.at(k), &p2)) ++num; } @@ -393,7 +397,12 @@ void tst_QPixmapCache::clear() QPixmap p1(10, 10); p1.fill(Qt::red); - const int numberOfKeys = 40000; + // Calcuate estimated num of items what fits to cache + int estimatedNum = (1024 * QPixmapCache::cacheLimit()) + / ((p1.width() * p1.height() * p1.depth()) / 8); + + // Mare sure we will put enough items to reach the cache limit + const int numberOfKeys = estimatedNum + 1000; for (int i = 0; i < numberOfKeys; ++i) QVERIFY(QPixmapCache::find("x" + QString::number(i)) == 0); |