0
|
1 |
/****************************************************************************
|
|
2 |
**
|
4
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
|
|
45 |
|
|
46 |
#include <qpixmapcache.h>
|
|
47 |
#include "../../../src/gui/image/qpixmapcache_p.h"
|
|
48 |
|
|
49 |
|
|
50 |
//TESTED_CLASS=
|
|
51 |
//TESTED_FILES=
|
|
52 |
|
|
53 |
class tst_QPixmapCache : public QObject
|
|
54 |
{
|
|
55 |
Q_OBJECT
|
|
56 |
|
|
57 |
public:
|
|
58 |
tst_QPixmapCache();
|
|
59 |
virtual ~tst_QPixmapCache();
|
|
60 |
|
|
61 |
|
|
62 |
public slots:
|
|
63 |
void init();
|
|
64 |
private slots:
|
|
65 |
void cacheLimit();
|
|
66 |
void setCacheLimit();
|
|
67 |
void find();
|
|
68 |
void insert();
|
|
69 |
void replace();
|
|
70 |
void remove();
|
|
71 |
void clear();
|
|
72 |
void pixmapKey();
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
73 |
void noLeak();
|
0
|
74 |
};
|
|
75 |
|
|
76 |
static QPixmapCache::KeyData* getPrivate(QPixmapCache::Key &key)
|
|
77 |
{
|
|
78 |
return (*reinterpret_cast<QPixmapCache::KeyData**>(&key));
|
|
79 |
}
|
|
80 |
|
|
81 |
static QPixmapCache::KeyData** getPrivateRef(QPixmapCache::Key &key)
|
|
82 |
{
|
|
83 |
return (reinterpret_cast<QPixmapCache::KeyData**>(&key));
|
|
84 |
}
|
|
85 |
|
|
86 |
static int originalCacheLimit;
|
|
87 |
|
|
88 |
tst_QPixmapCache::tst_QPixmapCache()
|
|
89 |
{
|
|
90 |
originalCacheLimit = QPixmapCache::cacheLimit();
|
|
91 |
}
|
|
92 |
|
|
93 |
tst_QPixmapCache::~tst_QPixmapCache()
|
|
94 |
{
|
|
95 |
}
|
|
96 |
|
|
97 |
void tst_QPixmapCache::init()
|
|
98 |
{
|
|
99 |
QPixmapCache::setCacheLimit(originalCacheLimit);
|
|
100 |
QPixmapCache::clear();
|
|
101 |
}
|
|
102 |
|
|
103 |
void tst_QPixmapCache::cacheLimit()
|
|
104 |
{
|
|
105 |
// make sure the default is reasonable;
|
|
106 |
// it was between 2048 and 10240 last time I looked at it
|
|
107 |
QVERIFY(originalCacheLimit >= 1024 && originalCacheLimit <= 20480);
|
|
108 |
|
|
109 |
QPixmapCache::setCacheLimit(100);
|
|
110 |
QCOMPARE(QPixmapCache::cacheLimit(), 100);
|
|
111 |
|
|
112 |
QPixmapCache::setCacheLimit(-50);
|
|
113 |
QCOMPARE(QPixmapCache::cacheLimit(), -50);
|
|
114 |
}
|
|
115 |
|
|
116 |
void tst_QPixmapCache::setCacheLimit()
|
|
117 |
{
|
|
118 |
QPixmap *p1 = new QPixmap(2, 3);
|
|
119 |
QPixmapCache::insert("P1", *p1);
|
|
120 |
QVERIFY(QPixmapCache::find("P1") != 0);
|
|
121 |
delete p1;
|
|
122 |
|
|
123 |
QPixmapCache::setCacheLimit(0);
|
|
124 |
QVERIFY(QPixmapCache::find("P1") == 0);
|
|
125 |
|
|
126 |
p1 = new QPixmap(2, 3);
|
|
127 |
QPixmapCache::setCacheLimit(1000);
|
|
128 |
QPixmapCache::insert("P1", *p1);
|
|
129 |
QVERIFY(QPixmapCache::find("P1") != 0);
|
|
130 |
|
|
131 |
delete p1;
|
|
132 |
|
|
133 |
//The int part of the API
|
|
134 |
p1 = new QPixmap(2, 3);
|
|
135 |
QPixmapCache::Key key = QPixmapCache::insert(*p1);
|
|
136 |
QVERIFY(QPixmapCache::find(key, p1) != 0);
|
|
137 |
delete p1;
|
|
138 |
|
|
139 |
QPixmapCache::setCacheLimit(0);
|
|
140 |
QVERIFY(QPixmapCache::find(key, p1) == 0);
|
|
141 |
|
|
142 |
p1 = new QPixmap(2, 3);
|
|
143 |
QPixmapCache::setCacheLimit(1000);
|
|
144 |
QPixmapCache::replace(key, *p1);
|
|
145 |
QVERIFY(QPixmapCache::find(key, p1) == 0);
|
|
146 |
|
|
147 |
delete p1;
|
|
148 |
|
|
149 |
//Let check if keys are released when the pixmap cache is
|
|
150 |
//full or has been flushed.
|
|
151 |
QPixmapCache::clear();
|
|
152 |
p1 = new QPixmap(2, 3);
|
|
153 |
key = QPixmapCache::insert(*p1);
|
|
154 |
QVERIFY(QPixmapCache::find(key, p1) != 0);
|
|
155 |
QPixmapCache::setCacheLimit(0);
|
|
156 |
QVERIFY(QPixmapCache::find(key, p1) == 0);
|
|
157 |
QPixmapCache::setCacheLimit(1000);
|
|
158 |
key = QPixmapCache::insert(*p1);
|
|
159 |
QCOMPARE(getPrivate(key)->isValid, true);
|
|
160 |
QCOMPARE(getPrivate(key)->key, 1);
|
|
161 |
|
|
162 |
delete p1;
|
|
163 |
|
|
164 |
//Let check if removing old entries doesn't let you get
|
|
165 |
// wrong pixmaps
|
|
166 |
QPixmapCache::clear();
|
|
167 |
QPixmap p2;
|
|
168 |
p1 = new QPixmap(2, 3);
|
|
169 |
key = QPixmapCache::insert(*p1);
|
|
170 |
QVERIFY(QPixmapCache::find(key, &p2) != 0);
|
|
171 |
//we flush the cache
|
|
172 |
QPixmapCache::setCacheLimit(0);
|
|
173 |
QPixmapCache::setCacheLimit(1000);
|
|
174 |
QPixmapCache::Key key2 = QPixmapCache::insert(*p1);
|
|
175 |
QCOMPARE(getPrivate(key2)->key, 1);
|
|
176 |
QVERIFY(QPixmapCache::find(key, &p2) == 0);
|
|
177 |
QVERIFY(QPixmapCache::find(key2, &p2) != 0);
|
|
178 |
QCOMPARE(p2, *p1);
|
|
179 |
|
|
180 |
delete p1;
|
|
181 |
|
|
182 |
//Here we simulate the flushing when the app is idle
|
|
183 |
/*QPixmapCache::clear();
|
|
184 |
QPixmapCache::setCacheLimit(originalCacheLimit);
|
|
185 |
p1 = new QPixmap(300, 300);
|
|
186 |
key = QPixmapCache::insert(*p1);
|
|
187 |
QCOMPARE(getPrivate(key)->key, 1);
|
|
188 |
key2 = QPixmapCache::insert(*p1);
|
|
189 |
key2 = QPixmapCache::insert(*p1);
|
|
190 |
QPixmapCache::Key key3 = QPixmapCache::insert(*p1);
|
|
191 |
QTest::qWait(32000);
|
|
192 |
key2 = QPixmapCache::insert(*p1);
|
|
193 |
QCOMPARE(getPrivate(key2)->key, 1);
|
|
194 |
//This old key is not valid anymore after the flush
|
|
195 |
QCOMPARE(getPrivate(key)->isValid, false);
|
|
196 |
QVERIFY(QPixmapCache::find(key, &p2) == 0);
|
|
197 |
delete p1;*/
|
|
198 |
}
|
|
199 |
|
|
200 |
void tst_QPixmapCache::find()
|
|
201 |
{
|
|
202 |
QPixmap p1(10, 10);
|
|
203 |
p1.fill(Qt::red);
|
|
204 |
QVERIFY(QPixmapCache::insert("P1", p1));
|
|
205 |
|
|
206 |
QPixmap p2;
|
|
207 |
QVERIFY(QPixmapCache::find("P1", p2));
|
|
208 |
QCOMPARE(p2.width(), 10);
|
|
209 |
QCOMPARE(p2.height(), 10);
|
|
210 |
QCOMPARE(p1, p2);
|
|
211 |
|
|
212 |
// obsolete
|
|
213 |
QPixmap *p3 = QPixmapCache::find("P1");
|
|
214 |
QVERIFY(p3);
|
|
215 |
QCOMPARE(p1, *p3);
|
|
216 |
|
|
217 |
//The int part of the API
|
|
218 |
QPixmapCache::Key key = QPixmapCache::insert(p1);
|
|
219 |
|
|
220 |
QVERIFY(QPixmapCache::find(key, &p2));
|
|
221 |
QCOMPARE(p2.width(), 10);
|
|
222 |
QCOMPARE(p2.height(), 10);
|
|
223 |
QCOMPARE(p1, p2);
|
|
224 |
|
|
225 |
QPixmapCache::clear();
|
|
226 |
QPixmapCache::setCacheLimit(128);
|
|
227 |
|
|
228 |
key = QPixmapCache::insert(p1);
|
|
229 |
|
|
230 |
//The int part of the API
|
|
231 |
QList<QPixmapCache::Key> keys;
|
|
232 |
for (int i = 0; i < 4000; ++i)
|
|
233 |
QPixmapCache::insert(p1);
|
|
234 |
|
|
235 |
//at that time the first key has been erase because no more place in the cache
|
|
236 |
QVERIFY(QPixmapCache::find(key, &p1) == 0);
|
|
237 |
QCOMPARE(getPrivate(key)->isValid, false);
|
|
238 |
}
|
|
239 |
|
|
240 |
void tst_QPixmapCache::insert()
|
|
241 |
{
|
|
242 |
QPixmap p1(10, 10);
|
|
243 |
p1.fill(Qt::red);
|
|
244 |
|
|
245 |
QPixmap p2(10, 10);
|
|
246 |
p2.fill(Qt::yellow);
|
|
247 |
|
|
248 |
// Calcuate estimated num of items what fits to cache
|
|
249 |
int estimatedNum = (1024 * QPixmapCache::cacheLimit())
|
|
250 |
/ ((p1.width() * p1.height() * p1.depth()) / 8);
|
|
251 |
|
|
252 |
// Mare sure we will put enough items to reach the cache limit
|
|
253 |
const int numberOfKeys = estimatedNum + 1000;
|
|
254 |
|
|
255 |
// make sure it doesn't explode
|
|
256 |
for (int i = 0; i < numberOfKeys; ++i)
|
|
257 |
QPixmapCache::insert("0", p1);
|
|
258 |
|
|
259 |
// ditto
|
|
260 |
for (int j = 0; j < numberOfKeys; ++j)
|
|
261 |
QPixmapCache::insert(QString::number(j), p1);
|
|
262 |
|
|
263 |
int num = 0;
|
|
264 |
for (int k = 0; k < numberOfKeys; ++k) {
|
|
265 |
if (QPixmapCache::find(QString::number(k)))
|
|
266 |
++num;
|
|
267 |
}
|
|
268 |
|
|
269 |
if (QPixmapCache::find("0"))
|
|
270 |
++num;
|
|
271 |
|
|
272 |
QVERIFY(num <= estimatedNum);
|
|
273 |
QPixmap p3;
|
|
274 |
QPixmapCache::insert("null", p3);
|
|
275 |
|
|
276 |
QPixmap c1(10, 10);
|
|
277 |
c1.fill(Qt::yellow);
|
|
278 |
QPixmapCache::insert("custom", c1);
|
|
279 |
QVERIFY(!c1.isDetached());
|
|
280 |
QPixmap c2(10, 10);
|
|
281 |
c2.fill(Qt::red);
|
|
282 |
QPixmapCache::insert("custom", c2);
|
|
283 |
//We have deleted the old pixmap in the cache for the same key
|
|
284 |
QVERIFY(c1.isDetached());
|
|
285 |
|
|
286 |
//The int part of the API
|
|
287 |
// make sure it doesn't explode
|
|
288 |
QList<QPixmapCache::Key> keys;
|
|
289 |
for (int i = 0; i < numberOfKeys; ++i)
|
|
290 |
keys.append(QPixmapCache::insert(p1));
|
|
291 |
|
|
292 |
num = 0;
|
|
293 |
for (int k = 0; k < numberOfKeys; ++k) {
|
|
294 |
if (QPixmapCache::find(keys.at(k), &p2))
|
|
295 |
++num;
|
|
296 |
}
|
|
297 |
|
|
298 |
estimatedNum = (1024 * QPixmapCache::cacheLimit())
|
|
299 |
/ ((p1.width() * p1.height() * p1.depth()) / 8);
|
|
300 |
QVERIFY(num <= estimatedNum);
|
|
301 |
}
|
|
302 |
|
|
303 |
void tst_QPixmapCache::replace()
|
|
304 |
{
|
|
305 |
//The int part of the API
|
|
306 |
QPixmap p1(10, 10);
|
|
307 |
p1.fill(Qt::red);
|
|
308 |
|
|
309 |
QPixmap p2(10, 10);
|
|
310 |
p2.fill(Qt::yellow);
|
|
311 |
|
|
312 |
QPixmapCache::Key key = QPixmapCache::insert(p1);
|
|
313 |
QCOMPARE(getPrivate(key)->isValid, true);
|
|
314 |
|
|
315 |
QPixmap p3;
|
|
316 |
QVERIFY(QPixmapCache::find(key, &p3) == 1);
|
|
317 |
|
|
318 |
QPixmapCache::replace(key, p2);
|
|
319 |
|
|
320 |
QVERIFY(QPixmapCache::find(key, &p3) == 1);
|
|
321 |
QCOMPARE(getPrivate(key)->isValid, true);
|
|
322 |
QCOMPARE(getPrivate(key)->key, 1);
|
|
323 |
|
|
324 |
QCOMPARE(p3.width(), 10);
|
|
325 |
QCOMPARE(p3.height(), 10);
|
|
326 |
QCOMPARE(p3, p2);
|
|
327 |
|
|
328 |
//Broken keys
|
|
329 |
QCOMPARE(QPixmapCache::replace(QPixmapCache::Key(), p2), false);
|
|
330 |
}
|
|
331 |
|
|
332 |
void tst_QPixmapCache::remove()
|
|
333 |
{
|
|
334 |
QPixmap p1(10, 10);
|
|
335 |
p1.fill(Qt::red);
|
|
336 |
|
|
337 |
QPixmapCache::insert("red", p1);
|
|
338 |
p1.fill(Qt::yellow);
|
|
339 |
|
|
340 |
QPixmap p2;
|
|
341 |
QVERIFY(QPixmapCache::find("red", p2));
|
|
342 |
QVERIFY(p1.toImage() != p2.toImage());
|
|
343 |
QVERIFY(p1.toImage() == p1.toImage()); // sanity check
|
|
344 |
|
|
345 |
QPixmapCache::remove("red");
|
|
346 |
QVERIFY(QPixmapCache::find("red") == 0);
|
|
347 |
QPixmapCache::remove("red");
|
|
348 |
QVERIFY(QPixmapCache::find("red") == 0);
|
|
349 |
|
|
350 |
QPixmapCache::remove("green");
|
|
351 |
QVERIFY(QPixmapCache::find("green") == 0);
|
|
352 |
|
|
353 |
//The int part of the API
|
|
354 |
QPixmapCache::clear();
|
|
355 |
p1.fill(Qt::red);
|
|
356 |
QPixmapCache::Key key = QPixmapCache::insert(p1);
|
|
357 |
p1.fill(Qt::yellow);
|
|
358 |
|
|
359 |
QVERIFY(QPixmapCache::find(key, &p2));
|
|
360 |
QVERIFY(p1.toImage() != p2.toImage());
|
|
361 |
QVERIFY(p1.toImage() == p1.toImage()); // sanity check
|
|
362 |
|
|
363 |
QPixmapCache::remove(key);
|
|
364 |
QVERIFY(QPixmapCache::find(key, &p1) == 0);
|
|
365 |
|
|
366 |
//Broken key
|
|
367 |
QPixmapCache::remove(QPixmapCache::Key());
|
|
368 |
QVERIFY(QPixmapCache::find(QPixmapCache::Key(), &p1) == 0);
|
|
369 |
|
|
370 |
//Test if keys are release
|
|
371 |
QPixmapCache::clear();
|
|
372 |
key = QPixmapCache::insert(p1);
|
|
373 |
QCOMPARE(getPrivate(key)->key, 1);
|
|
374 |
QPixmapCache::remove(key);
|
|
375 |
key = QPixmapCache::insert(p1);
|
|
376 |
QCOMPARE(getPrivate(key)->key, 1);
|
|
377 |
|
|
378 |
//Test if pixmaps are correctly deleted
|
|
379 |
QPixmapCache::clear();
|
|
380 |
key = QPixmapCache::insert(p1);
|
|
381 |
QCOMPARE(getPrivate(key)->key, 1);
|
|
382 |
QVERIFY(QPixmapCache::find(key, &p1) != 0);
|
|
383 |
QPixmapCache::remove(key);
|
|
384 |
QCOMPARE(p1.isDetached(), true);
|
|
385 |
|
|
386 |
//We mix both part of the API
|
|
387 |
QPixmapCache::clear();
|
|
388 |
p1.fill(Qt::red);
|
|
389 |
QPixmapCache::insert("red", p1);
|
|
390 |
key = QPixmapCache::insert(p1);
|
|
391 |
QPixmapCache::remove(key);
|
|
392 |
QVERIFY(QPixmapCache::find(key, &p1) == 0);
|
|
393 |
QVERIFY(QPixmapCache::find("red") != 0);
|
|
394 |
}
|
|
395 |
|
|
396 |
void tst_QPixmapCache::clear()
|
|
397 |
{
|
|
398 |
QPixmap p1(10, 10);
|
|
399 |
p1.fill(Qt::red);
|
|
400 |
|
|
401 |
// Calcuate estimated num of items what fits to cache
|
|
402 |
int estimatedNum = (1024 * QPixmapCache::cacheLimit())
|
|
403 |
/ ((p1.width() * p1.height() * p1.depth()) / 8);
|
|
404 |
|
|
405 |
// Mare sure we will put enough items to reach the cache limit
|
|
406 |
const int numberOfKeys = estimatedNum + 1000;
|
|
407 |
|
|
408 |
for (int i = 0; i < numberOfKeys; ++i)
|
|
409 |
QVERIFY(QPixmapCache::find("x" + QString::number(i)) == 0);
|
|
410 |
|
|
411 |
for (int j = 0; j < numberOfKeys; ++j)
|
|
412 |
QPixmapCache::insert(QString::number(j), p1);
|
|
413 |
|
|
414 |
int num = 0;
|
|
415 |
for (int k = 0; k < numberOfKeys; ++k) {
|
|
416 |
if (QPixmapCache::find(QString::number(k), p1))
|
|
417 |
++num;
|
|
418 |
}
|
|
419 |
QVERIFY(num > 0);
|
|
420 |
|
|
421 |
QPixmapCache::clear();
|
|
422 |
|
|
423 |
for (int k = 0; k < numberOfKeys; ++k)
|
|
424 |
QVERIFY(QPixmapCache::find(QString::number(k)) == 0);
|
|
425 |
|
|
426 |
//The int part of the API
|
|
427 |
QPixmap p2(10, 10);
|
|
428 |
p2.fill(Qt::red);
|
|
429 |
|
|
430 |
QList<QPixmapCache::Key> keys;
|
|
431 |
for (int k = 0; k < numberOfKeys; ++k)
|
|
432 |
keys.append(QPixmapCache::insert(p2));
|
|
433 |
|
|
434 |
QPixmapCache::clear();
|
|
435 |
|
|
436 |
for (int k = 0; k < numberOfKeys; ++k) {
|
|
437 |
QVERIFY(QPixmapCache::find(keys.at(k), &p1) == 0);
|
|
438 |
QCOMPARE(getPrivate(keys[k])->isValid, false);
|
|
439 |
}
|
|
440 |
}
|
|
441 |
|
|
442 |
void tst_QPixmapCache::pixmapKey()
|
|
443 |
{
|
|
444 |
QPixmapCache::Key key;
|
|
445 |
//Default constructed keys have no d pointer unless
|
|
446 |
//we use them
|
|
447 |
QVERIFY(!getPrivate(key));
|
|
448 |
//Let's put a d pointer
|
|
449 |
QPixmapCache::KeyData** keyd = getPrivateRef(key);
|
|
450 |
*keyd = new QPixmapCache::KeyData;
|
|
451 |
QCOMPARE(getPrivate(key)->ref, 1);
|
|
452 |
QPixmapCache::Key key2;
|
|
453 |
//Let's put a d pointer
|
|
454 |
QPixmapCache::KeyData** key2d = getPrivateRef(key2);
|
|
455 |
*key2d = new QPixmapCache::KeyData;
|
|
456 |
QCOMPARE(getPrivate(key2)->ref, 1);
|
|
457 |
key = key2;
|
|
458 |
QCOMPARE(getPrivate(key2)->ref, 2);
|
|
459 |
QCOMPARE(getPrivate(key)->ref, 2);
|
|
460 |
QPixmapCache::Key key3;
|
|
461 |
//Let's put a d pointer
|
|
462 |
QPixmapCache::KeyData** key3d = getPrivateRef(key3);
|
|
463 |
*key3d = new QPixmapCache::KeyData;
|
|
464 |
QPixmapCache::Key key4 = key3;
|
|
465 |
QCOMPARE(getPrivate(key3)->ref, 2);
|
|
466 |
QCOMPARE(getPrivate(key4)->ref, 2);
|
|
467 |
key4 = key;
|
|
468 |
QCOMPARE(getPrivate(key4)->ref, 3);
|
|
469 |
QCOMPARE(getPrivate(key3)->ref, 1);
|
|
470 |
QPixmapCache::Key key5(key3);
|
|
471 |
QCOMPARE(getPrivate(key3)->ref, 2);
|
|
472 |
QCOMPARE(getPrivate(key5)->ref, 2);
|
|
473 |
|
|
474 |
//let test default constructed keys
|
|
475 |
QPixmapCache::Key key6;
|
|
476 |
QVERIFY(!getPrivate(key6));
|
|
477 |
QPixmapCache::Key key7;
|
|
478 |
QVERIFY(!getPrivate(key7));
|
|
479 |
key6 = key7;
|
|
480 |
QVERIFY(!getPrivate(key6));
|
|
481 |
QVERIFY(!getPrivate(key7));
|
|
482 |
QPixmapCache::Key key8(key7);
|
|
483 |
QVERIFY(!getPrivate(key8));
|
|
484 |
}
|
|
485 |
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
486 |
//QTP: remove temporarily to get the code compiled.
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
487 |
// The following function is implemented in qpixmapcache.cpp in GUI but export for
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
488 |
// auto test only with marco Q_AUTOTEST_EXPORT
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
489 |
|
8
|
490 |
//QT_BEGIN_NAMESPACE
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
491 |
//extern int q_QPixmapCache_keyHashSize();
|
8
|
492 |
//QT_END_NAMESPACE
|
3
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
493 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
494 |
void tst_QPixmapCache::noLeak()
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
495 |
{
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
496 |
QPixmapCache::Key key;
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
497 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
498 |
int oldSize = 0;//q_QPixmapCache_keyHashSize();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
499 |
for (int i = 0; i < 100; ++i) {
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
500 |
QPixmap pm(128, 128);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
501 |
pm.fill(Qt::transparent);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
502 |
key = QPixmapCache::insert(pm);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
503 |
QPixmapCache::remove(key);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
504 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
505 |
int newSize = 0;//q_QPixmapCache_keyHashSize();
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
506 |
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
507 |
QCOMPARE(oldSize, newSize);
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
508 |
}
|
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
diff
changeset
|
509 |
|
0
|
510 |
QTEST_MAIN(tst_QPixmapCache)
|
|
511 |
#include "tst_qpixmapcache.moc"
|