author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 22 Apr 2010 16:15:11 +0300 | |
branch | RCL_3 |
changeset 14 | 8c4229025c0b |
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 |
#include <QtTest/QtTest> |
|
42 |
#include <QtGui> |
|
43 |
#include <QtCore> |
|
44 |
||
45 |
#if defined(Q_OS_SYMBIAN) |
|
46 |
# define STRINGIFY(x) #x |
|
47 |
# define TOSTRING(x) STRINGIFY(x) |
|
48 |
# define SRCDIR "C:/Private/" TOSTRING(SYMBIAN_SRCDIR_UID) "/" |
|
49 |
#endif |
|
50 |
||
51 |
class tst_QIcoImageFormat : public QObject |
|
52 |
{ |
|
53 |
Q_OBJECT |
|
54 |
||
55 |
public: |
|
56 |
tst_QIcoImageFormat(); |
|
57 |
virtual ~tst_QIcoImageFormat(); |
|
58 |
||
59 |
||
60 |
public slots: |
|
61 |
void initTestCase(); |
|
62 |
void cleanupTestCase(); |
|
63 |
void init(); |
|
64 |
void cleanup(); |
|
65 |
private slots: |
|
66 |
void format(); |
|
67 |
void canRead_data(); |
|
68 |
void canRead(); |
|
69 |
void SequentialFile_data(); |
|
70 |
void SequentialFile(); |
|
71 |
void imageCount_data(); |
|
72 |
void imageCount(); |
|
73 |
void jumpToNextImage_data(); |
|
74 |
void jumpToNextImage(); |
|
75 |
void loopCount_data(); |
|
76 |
void loopCount(); |
|
77 |
void nextImageDelay_data(); |
|
78 |
void nextImageDelay(); |
|
79 |
void pngCompression_data(); |
|
80 |
void pngCompression(); |
|
81 |
||
82 |
private: |
|
83 |
QString m_IconPath; |
|
84 |
}; |
|
85 |
||
86 |
||
87 |
tst_QIcoImageFormat::tst_QIcoImageFormat() |
|
88 |
{ |
|
89 |
m_IconPath = QLatin1String(SRCDIR) + "/icons"; |
|
90 |
qDebug() << m_IconPath; |
|
91 |
} |
|
92 |
||
93 |
tst_QIcoImageFormat::~tst_QIcoImageFormat() |
|
94 |
{ |
|
95 |
||
96 |
} |
|
97 |
||
98 |
void tst_QIcoImageFormat::init() |
|
99 |
{ |
|
100 |
||
101 |
} |
|
102 |
||
103 |
void tst_QIcoImageFormat::cleanup() |
|
104 |
{ |
|
105 |
||
106 |
} |
|
107 |
||
108 |
void tst_QIcoImageFormat::initTestCase() |
|
109 |
{ |
|
110 |
||
111 |
} |
|
112 |
||
113 |
void tst_QIcoImageFormat::cleanupTestCase() |
|
114 |
{ |
|
115 |
||
116 |
} |
|
117 |
||
118 |
void tst_QIcoImageFormat::format() |
|
119 |
{ |
|
120 |
QImageReader reader(m_IconPath + "/valid/35FLOPPY.ICO", "ico"); |
|
121 |
QByteArray fmt = reader.format(); |
|
122 |
QCOMPARE(const_cast<const char*>(fmt.data()), "ico" ); |
|
123 |
} |
|
124 |
||
125 |
void tst_QIcoImageFormat::canRead_data() |
|
126 |
{ |
|
127 |
QTest::addColumn<QString>("fileName"); |
|
128 |
QTest::addColumn<int>("isValid"); |
|
129 |
||
130 |
QTest::newRow("floppy (16px,32px - 16 colors)") << "valid/35FLOPPY.ICO" << 1; |
|
131 |
QTest::newRow("16px,32px,48px - 256,16M colors") << "valid/abcardWindow.ico" << 1; |
|
132 |
QTest::newRow("16px - 16 colors") << "valid/App.ico" << 1; |
|
133 |
QTest::newRow("16px,32px,48px - 16,256,16M colors") << "valid/Obj_N2_Internal_Mem.ico" << 1; |
|
134 |
QTest::newRow("16px - 16,256,16M colors") << "valid/Status_Play.ico" << 1; |
|
135 |
QTest::newRow("16px,32px - 16 colors") << "valid/TIMER01.ICO" << 1; |
|
136 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLD.ico" << 1; |
|
137 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLDH.ico" << 1; |
|
138 |
QTest::newRow("invalid floppy (first 8 bytes = 0xff)") << "invalid/35floppy.ico" << 0; |
|
139 |
QTest::newRow("103x16px, 24BPP") << "valid/trolltechlogo_tiny.ico" << 1; |
|
140 |
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 1; |
|
141 |
QTest::newRow("PNG compression") << "valid/Qt.ico" << 1; |
|
142 |
} |
|
143 |
||
144 |
void tst_QIcoImageFormat::canRead() |
|
145 |
{ |
|
146 |
QFETCH(QString, fileName); |
|
147 |
QFETCH(int, isValid); |
|
148 |
||
149 |
QImageReader reader(m_IconPath + "/" + fileName); |
|
150 |
QCOMPARE(reader.canRead(), (isValid == 0 ? false : true)); |
|
151 |
} |
|
152 |
||
153 |
class QSequentialFile : public QFile |
|
154 |
{ |
|
155 |
public: |
|
156 |
QSequentialFile(const QString &name) : QFile(name) {} |
|
157 |
||
158 |
virtual ~QSequentialFile() {} |
|
159 |
||
160 |
virtual bool isSequential() const { |
|
161 |
return true; |
|
162 |
} |
|
163 |
||
164 |
}; |
|
165 |
||
166 |
void tst_QIcoImageFormat::SequentialFile_data() |
|
167 |
{ |
|
168 |
QTest::addColumn<QString>("fileName"); |
|
169 |
QTest::addColumn<int>("isValid"); |
|
170 |
||
171 |
QTest::newRow("floppy (16,32 pixels - 16 colors)") << "valid/35FLOPPY.ICO" << 1; |
|
172 |
||
173 |
QTest::newRow("invalid floppy (first 8 bytes = 0xff)") << "invalid/35floppy.ico" << 0; |
|
174 |
||
175 |
||
176 |
} |
|
177 |
||
178 |
void tst_QIcoImageFormat::SequentialFile() |
|
179 |
{ |
|
180 |
QFETCH(QString, fileName); |
|
181 |
QFETCH(int, isValid); |
|
182 |
||
183 |
QSequentialFile *file = new QSequentialFile(m_IconPath + "/" + fileName); |
|
184 |
QVERIFY(file); |
|
185 |
QVERIFY(file->open(QFile::ReadOnly)); |
|
186 |
QImageReader reader(file); |
|
187 |
||
188 |
// Perform the check twice. If canRead() does not restore the sequential device back to its original state, |
|
189 |
// it will fail on the second try. |
|
190 |
QCOMPARE(reader.canRead(), (isValid == 0 ? false : true)); |
|
191 |
QCOMPARE(reader.canRead(), (isValid == 0 ? false : true)); |
|
192 |
file->close(); |
|
193 |
} |
|
194 |
||
195 |
||
196 |
void tst_QIcoImageFormat::imageCount_data() |
|
197 |
{ |
|
198 |
QTest::addColumn<QString>("fileName"); |
|
199 |
QTest::addColumn<int>("count"); |
|
200 |
||
201 |
QTest::newRow("floppy (16px,32px - 16 colors)") << "valid/35FLOPPY.ICO" << 2; |
|
202 |
QTest::newRow("16px,32px,48px - 256,16M colors") << "valid/abcardWindow.ico" << 6; |
|
203 |
QTest::newRow("16px - 16 colors") << "valid/App.ico" << 1; |
|
204 |
QTest::newRow("16px,32px,48px - 16,256,16M colors") << "valid/Obj_N2_Internal_Mem.ico" << 9; |
|
205 |
QTest::newRow("16px - 16,256,16M colors") << "valid/Status_Play.ico" << 3; |
|
206 |
QTest::newRow("16px,32px - 16 colors") << "valid/TIMER01.ICO" << 2; |
|
207 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLD.ico" << 3; |
|
208 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLDH.ico" << 3; |
|
209 |
QTest::newRow("invalid floppy (first 8 bytes = 0xff)") << "invalid/35floppy.ico" << 0; |
|
210 |
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 9; |
|
211 |
QTest::newRow("PNG compression") << "valid/Qt.ico" << 4; |
|
212 |
||
213 |
} |
|
214 |
||
215 |
void tst_QIcoImageFormat::imageCount() |
|
216 |
{ |
|
217 |
QFETCH(QString, fileName); |
|
218 |
QFETCH(int, count); |
|
219 |
||
220 |
QImageReader reader(m_IconPath + "/" + fileName); |
|
221 |
QCOMPARE(reader.imageCount(), count); |
|
222 |
||
223 |
} |
|
224 |
||
225 |
void tst_QIcoImageFormat::jumpToNextImage_data() |
|
226 |
{ |
|
227 |
QTest::addColumn<QString>("fileName"); |
|
228 |
QTest::addColumn<int>("count"); |
|
229 |
||
230 |
QTest::newRow("floppy (16px,32px - 16 colors)") << "valid/35FLOPPY.ICO" << 2; |
|
231 |
QTest::newRow("16px,32px,48px - 256,16M colors") << "valid/abcardWindow.ico" << 6; |
|
232 |
QTest::newRow("16px - 16 colors") << "valid/App.ico" << 1; |
|
233 |
QTest::newRow("16px,32px,48px - 16,256,16M colors") << "valid/Obj_N2_Internal_Mem.ico" << 9; |
|
234 |
QTest::newRow("16px - 16,256,16M colors") << "valid/Status_Play.ico" << 3; |
|
235 |
QTest::newRow("16px,32px - 16 colors") << "valid/TIMER01.ICO" << 2; |
|
236 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLD.ico" << 3; |
|
237 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLDH.ico" << 3; |
|
238 |
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 9; |
|
239 |
QTest::newRow("PNG compression") << "valid/Qt.ico" << 4; |
|
240 |
} |
|
241 |
||
242 |
void tst_QIcoImageFormat::jumpToNextImage() |
|
243 |
{ |
|
244 |
QFETCH(QString, fileName); |
|
245 |
QFETCH(int, count); |
|
246 |
||
247 |
QImageReader reader(m_IconPath + "/" + fileName); |
|
248 |
bool bJumped = reader.jumpToImage(0); |
|
249 |
while (bJumped) { |
|
250 |
count--; |
|
251 |
bJumped = reader.jumpToNextImage(); |
|
252 |
} |
|
253 |
QCOMPARE(count, 0); |
|
254 |
} |
|
255 |
||
256 |
void tst_QIcoImageFormat::loopCount_data() |
|
257 |
{ |
|
258 |
QTest::addColumn<QString>("fileName"); |
|
259 |
QTest::addColumn<int>("count"); |
|
260 |
||
261 |
QTest::newRow("floppy (16px,32px - 16 colors)") << "valid/35FLOPPY.ICO" << 0; |
|
262 |
QTest::newRow("invalid floppy (first 8 bytes = 0xff)") << "invalid/35floppy.ico" << 0; |
|
263 |
} |
|
264 |
||
265 |
void tst_QIcoImageFormat::loopCount() |
|
266 |
{ |
|
267 |
QFETCH(QString, fileName); |
|
268 |
QFETCH(int, count); |
|
269 |
||
270 |
QImageReader reader(m_IconPath + "/" + fileName); |
|
271 |
QCOMPARE(reader.loopCount(), count); |
|
272 |
} |
|
273 |
||
274 |
void tst_QIcoImageFormat::nextImageDelay_data() |
|
275 |
{ |
|
276 |
QTest::addColumn<QString>("fileName"); |
|
277 |
QTest::addColumn<int>("count"); |
|
278 |
||
279 |
QTest::newRow("floppy (16px,32px - 16 colors)") << "valid/35FLOPPY.ICO" << 2; |
|
280 |
QTest::newRow("16px,32px,48px - 256,16M colors") << "valid/abcardWindow.ico" << 6; |
|
281 |
QTest::newRow("16px - 16 colors") << "valid/App.ico" << 1; |
|
282 |
QTest::newRow("16px,32px,48px - 16,256,16M colors") << "valid/Obj_N2_Internal_Mem.ico" << 9; |
|
283 |
QTest::newRow("16px - 16,256,16M colors") << "valid/Status_Play.ico" << 3; |
|
284 |
QTest::newRow("16px,32px - 16 colors") << "valid/TIMER01.ICO" << 2; |
|
285 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLD.ico" << 3; |
|
286 |
QTest::newRow("16px16c, 32px32c, 32px256c") << "valid/WORLDH.ico" << 3; |
|
287 |
QTest::newRow("invalid floppy (first 8 bytes = 0xff)") << "invalid/35floppy.ico" << -1; |
|
288 |
QTest::newRow("includes 32BPP w/alpha") << "valid/semitransparent.ico" << 9; |
|
289 |
QTest::newRow("PNG compression") << "valid/Qt.ico" << 4; |
|
290 |
} |
|
291 |
||
292 |
void tst_QIcoImageFormat::nextImageDelay() |
|
293 |
{ |
|
294 |
QFETCH(QString, fileName); |
|
295 |
QFETCH(int, count); |
|
296 |
||
297 |
QImageReader reader(m_IconPath + "/" + fileName); |
|
298 |
if (count == -1) { |
|
299 |
QCOMPARE(reader.nextImageDelay(), 0); |
|
300 |
} else { |
|
301 |
int i; |
|
302 |
for (i = 0; i < count; i++) { |
|
303 |
QVERIFY(reader.jumpToImage(i)); |
|
304 |
QCOMPARE(reader.nextImageDelay(), 0); |
|
305 |
} |
|
306 |
} |
|
307 |
} |
|
308 |
||
309 |
void tst_QIcoImageFormat::pngCompression_data() |
|
310 |
{ |
|
311 |
QTest::addColumn<QString>("fileName"); |
|
312 |
QTest::addColumn<int>("index"); |
|
313 |
QTest::addColumn<int>("width"); |
|
314 |
QTest::addColumn<int>("height"); |
|
315 |
||
316 |
QTest::newRow("PNG compression") << "valid/Qt.ico" << 4 << 256 << 256; |
|
317 |
} |
|
318 |
||
319 |
void tst_QIcoImageFormat::pngCompression() |
|
320 |
{ |
|
321 |
QFETCH(QString, fileName); |
|
322 |
QFETCH(int, index); |
|
323 |
QFETCH(int, width); |
|
324 |
QFETCH(int, height); |
|
325 |
||
326 |
QImageReader reader(m_IconPath + "/" + fileName); |
|
327 |
||
328 |
QImage image; |
|
329 |
reader.jumpToImage(index); |
|
330 |
reader.read(&image); |
|
331 |
||
332 |
QCOMPARE(image.width(), width); |
|
333 |
QCOMPARE(image.height(), height); |
|
334 |
} |
|
335 |
||
336 |
QTEST_MAIN(tst_QIcoImageFormat) |
|
337 |
#include "tst_qicoimageformat.moc" |
|
338 |