author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 15 Mar 2010 12:43:09 +0200 | |
branch | RCL_3 |
changeset 6 | dee5afe5301f |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
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 |
#include <qtest.h> |
|
43 |
#include <QPixmapCache> |
|
44 |
//TESTED_FILES= |
|
45 |
||
46 |
class tst_QPixmapCache : public QObject |
|
47 |
{ |
|
48 |
Q_OBJECT |
|
49 |
||
50 |
public: |
|
51 |
tst_QPixmapCache(); |
|
52 |
virtual ~tst_QPixmapCache(); |
|
53 |
||
54 |
public slots: |
|
55 |
void init(); |
|
56 |
void cleanup(); |
|
57 |
||
58 |
private slots: |
|
59 |
void insert_data(); |
|
60 |
void insert(); |
|
61 |
void find_data(); |
|
62 |
void find(); |
|
63 |
void styleUseCaseComplexKey(); |
|
64 |
void styleUseCaseComplexKey_data(); |
|
65 |
}; |
|
66 |
||
67 |
tst_QPixmapCache::tst_QPixmapCache() |
|
68 |
{ |
|
69 |
} |
|
70 |
||
71 |
tst_QPixmapCache::~tst_QPixmapCache() |
|
72 |
{ |
|
73 |
} |
|
74 |
||
75 |
void tst_QPixmapCache::init() |
|
76 |
{ |
|
77 |
} |
|
78 |
||
79 |
void tst_QPixmapCache::cleanup() |
|
80 |
{ |
|
81 |
} |
|
82 |
||
83 |
void tst_QPixmapCache::insert_data() |
|
84 |
{ |
|
85 |
QTest::addColumn<bool>("cacheType"); |
|
86 |
QTest::newRow("QPixmapCache") << true; |
|
87 |
QTest::newRow("QPixmapCache (int API)") << false; |
|
88 |
} |
|
89 |
||
90 |
QList<QPixmapCache::Key> keys; |
|
91 |
||
92 |
void tst_QPixmapCache::insert() |
|
93 |
{ |
|
94 |
QFETCH(bool, cacheType); |
|
95 |
QPixmap p; |
|
96 |
if (cacheType) { |
|
97 |
QBENCHMARK { |
|
98 |
for (int i = 0 ; i <= 10000 ; i++) |
|
99 |
{ |
|
100 |
QString tmp; |
|
101 |
tmp.sprintf("my-key-%d", i); |
|
102 |
QPixmapCache::insert(tmp, p); |
|
103 |
} |
|
104 |
} |
|
105 |
} else { |
|
106 |
QBENCHMARK { |
|
107 |
for (int i = 0 ; i <= 10000 ; i++) |
|
108 |
keys.append(QPixmapCache::insert(p)); |
|
109 |
} |
|
110 |
} |
|
111 |
} |
|
112 |
||
113 |
void tst_QPixmapCache::find_data() |
|
114 |
{ |
|
115 |
QTest::addColumn<bool>("cacheType"); |
|
116 |
QTest::newRow("QPixmapCache") << true; |
|
117 |
QTest::newRow("QPixmapCache (int API)") << false; |
|
118 |
} |
|
119 |
||
120 |
void tst_QPixmapCache::find() |
|
121 |
{ |
|
122 |
QFETCH(bool, cacheType); |
|
123 |
QPixmap p; |
|
124 |
if (cacheType) { |
|
125 |
QBENCHMARK { |
|
126 |
QString tmp; |
|
127 |
for (int i = 0 ; i <= 10000 ; i++) |
|
128 |
{ |
|
129 |
tmp.sprintf("my-key-%d", i); |
|
130 |
QPixmapCache::find(tmp, p); |
|
131 |
} |
|
132 |
} |
|
133 |
} else { |
|
134 |
QBENCHMARK { |
|
135 |
for (int i = 0 ; i <= 10000 ; i++) |
|
136 |
QPixmapCache::find(keys.at(i), &p); |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
} |
|
141 |
||
142 |
void tst_QPixmapCache::styleUseCaseComplexKey_data() |
|
143 |
{ |
|
144 |
QTest::addColumn<bool>("cacheType"); |
|
145 |
QTest::newRow("QPixmapCache") << true; |
|
146 |
QTest::newRow("QPixmapCache (int API)") << false; |
|
147 |
} |
|
148 |
||
149 |
struct styleStruct { |
|
150 |
QString key; |
|
151 |
uint state; |
|
152 |
uint direction; |
|
153 |
uint complex; |
|
154 |
uint palette; |
|
155 |
int width; |
|
156 |
int height; |
|
157 |
bool operator==(const styleStruct &str) const |
|
158 |
{ |
|
159 |
return str.state == state && str.direction == direction |
|
160 |
&& str.complex == complex && str.palette == palette && str.width == width |
|
161 |
&& str.height == height && str.key == key; |
|
162 |
} |
|
163 |
}; |
|
164 |
||
165 |
uint qHash(const styleStruct &myStruct) |
|
166 |
{ |
|
167 |
return qHash(myStruct.state); |
|
168 |
} |
|
169 |
||
170 |
void tst_QPixmapCache::styleUseCaseComplexKey() |
|
171 |
{ |
|
172 |
QFETCH(bool, cacheType); |
|
173 |
QPixmap p; |
|
174 |
if (cacheType) { |
|
175 |
QBENCHMARK { |
|
176 |
for (int i = 0 ; i <= 10000 ; i++) |
|
177 |
{ |
|
178 |
QString tmp; |
|
179 |
tmp.sprintf("%s-%d-%d-%d-%d-%d-%d", QString("my-progressbar-%1").arg(i).toLatin1().constData(), 5, 3, 0, 358, 100, 200); |
|
180 |
QPixmapCache::insert(tmp, p); |
|
181 |
} |
|
182 |
||
183 |
for (int i = 0 ; i <= 10000 ; i++) |
|
184 |
{ |
|
185 |
QString tmp; |
|
186 |
tmp.sprintf("%s-%d-%d-%d-%d-%d-%d", QString("my-progressbar-%1").arg(i).toLatin1().constData(), 5, 3, 0, 358, 100, 200); |
|
187 |
QPixmapCache::find(tmp, p); |
|
188 |
} |
|
189 |
} |
|
190 |
} else { |
|
191 |
QHash<styleStruct, QPixmapCache::Key> hash; |
|
192 |
QBENCHMARK { |
|
193 |
for (int i = 0 ; i <= 10000 ; i++) |
|
194 |
{ |
|
195 |
styleStruct myStruct; |
|
196 |
myStruct.key = QString("my-progressbar-%1").arg(i); |
|
197 |
myStruct.key = 5; |
|
198 |
myStruct.key = 4; |
|
199 |
myStruct.key = 3; |
|
200 |
myStruct.palette = 358; |
|
201 |
myStruct.width = 100; |
|
202 |
myStruct.key = 200; |
|
203 |
QPixmapCache::Key key = QPixmapCache::insert(p); |
|
204 |
hash.insert(myStruct, key); |
|
205 |
} |
|
206 |
for (int i = 0 ; i <= 10000 ; i++) |
|
207 |
{ |
|
208 |
styleStruct myStruct; |
|
209 |
myStruct.key = QString("my-progressbar-%1").arg(i); |
|
210 |
myStruct.key = 5; |
|
211 |
myStruct.key = 4; |
|
212 |
myStruct.key = 3; |
|
213 |
myStruct.palette = 358; |
|
214 |
myStruct.width = 100; |
|
215 |
myStruct.key = 200; |
|
216 |
QPixmapCache::Key key = hash.value(myStruct); |
|
217 |
QPixmapCache::find(key, &p); |
|
218 |
} |
|
219 |
} |
|
220 |
} |
|
221 |
||
222 |
} |
|
223 |
||
224 |
||
225 |
QTEST_MAIN(tst_QPixmapCache) |
|
226 |
#include "tst_qpixmapcache.moc" |