author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 5 | d3bac044e0f0 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
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 |
#include <QBuffer> |
|
46 |
#include <QDebug> |
|
47 |
#include <QFile> |
|
48 |
#include <QImage> |
|
49 |
#include <QImageReader> |
|
50 |
#include <QImageWriter> |
|
51 |
#include <QLabel> |
|
52 |
#include <QPixmap> |
|
53 |
#include <QSet> |
|
54 |
#include <QTcpSocket> |
|
55 |
#include <QTcpServer> |
|
56 |
#include <QTimer> |
|
57 |
||
58 |
#if defined(Q_OS_SYMBIAN) |
|
59 |
# define SRCDIR "." |
|
60 |
#endif |
|
61 |
||
62 |
typedef QMap<QString, QString> QStringMap; |
|
63 |
typedef QList<int> QIntList; |
|
64 |
Q_DECLARE_METATYPE(QImage) |
|
65 |
Q_DECLARE_METATYPE(QRect) |
|
66 |
Q_DECLARE_METATYPE(QSize) |
|
67 |
Q_DECLARE_METATYPE(QColor) |
|
68 |
Q_DECLARE_METATYPE(QStringMap) |
|
69 |
Q_DECLARE_METATYPE(QIntList) |
|
70 |
Q_DECLARE_METATYPE(QIODevice *) |
|
71 |
Q_DECLARE_METATYPE(QImage::Format) |
|
72 |
||
73 |
//TESTED_FILES= |
|
74 |
||
75 |
class tst_QImageReader : public QObject |
|
76 |
{ |
|
77 |
Q_OBJECT |
|
78 |
||
79 |
public: |
|
80 |
tst_QImageReader(); |
|
81 |
virtual ~tst_QImageReader(); |
|
82 |
||
83 |
public slots: |
|
84 |
void init(); |
|
85 |
void cleanup(); |
|
86 |
||
87 |
private slots: |
|
88 |
void getSetCheck(); |
|
89 |
void readImage_data(); |
|
90 |
void readImage(); |
|
91 |
void jpegRgbCmyk(); |
|
92 |
||
93 |
void setScaledSize_data(); |
|
94 |
void setScaledSize(); |
|
95 |
||
96 |
void setClipRect_data(); |
|
97 |
void setClipRect(); |
|
98 |
||
99 |
void setScaledClipRect_data(); |
|
100 |
void setScaledClipRect(); |
|
101 |
||
102 |
void imageFormat_data(); |
|
103 |
void imageFormat(); |
|
104 |
||
105 |
void blackXPM(); |
|
106 |
void transparentXPM(); |
|
107 |
void multiWordNamedColorXPM(); |
|
108 |
||
109 |
void supportedFormats(); |
|
110 |
||
111 |
void readFromDevice_data(); |
|
112 |
void readFromDevice(); |
|
113 |
||
114 |
void readFromFileAfterJunk_data(); |
|
115 |
void readFromFileAfterJunk(); |
|
116 |
||
117 |
void setBackgroundColor_data(); |
|
118 |
void setBackgroundColor(); |
|
119 |
||
120 |
void supportsAnimation_data(); |
|
121 |
void supportsAnimation(); |
|
122 |
||
123 |
void description_data(); |
|
124 |
void description(); |
|
125 |
||
126 |
void readFromResources_data(); |
|
127 |
void readFromResources(); |
|
128 |
||
129 |
void dotsPerMeter_data(); |
|
130 |
void dotsPerMeter(); |
|
131 |
||
132 |
void physicalDpi_data(); |
|
133 |
void physicalDpi(); |
|
134 |
||
135 |
void sizeBeforeRead_data(); |
|
136 |
void sizeBeforeRead(); |
|
137 |
||
138 |
void imageFormatBeforeRead_data(); |
|
139 |
void imageFormatBeforeRead(); |
|
140 |
||
141 |
#if defined QTEST_HAVE_GIF |
|
142 |
void gifHandlerBugs(); |
|
143 |
void animatedGif(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
144 |
void gifImageCount(); |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
145 |
void gifLoopCount(); |
0 | 146 |
#endif |
147 |
||
148 |
void readCorruptImage_data(); |
|
149 |
void readCorruptImage(); |
|
150 |
void readCorruptBmp(); |
|
151 |
||
152 |
void supportsOption_data(); |
|
153 |
void supportsOption(); |
|
154 |
||
155 |
#if defined QTEST_HAVE_TIFF |
|
156 |
void tiffCompression_data(); |
|
157 |
void tiffCompression(); |
|
158 |
void tiffEndianness(); |
|
159 |
||
160 |
void tiffOrientation_data(); |
|
161 |
void tiffOrientation(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
162 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
void tiffGrayscale(); |
0 | 164 |
#endif |
165 |
||
166 |
void autoDetectImageFormat(); |
|
167 |
void fileNameProbing(); |
|
168 |
||
169 |
void pixelCompareWithBaseline_data(); |
|
170 |
void pixelCompareWithBaseline(); |
|
171 |
||
172 |
void task255627_setNullScaledSize_data(); |
|
173 |
void task255627_setNullScaledSize(); |
|
174 |
||
175 |
void testIgnoresFormatAndExtension_data(); |
|
176 |
void testIgnoresFormatAndExtension(); |
|
177 |
||
178 |
}; |
|
179 |
||
180 |
static const QLatin1String prefix(SRCDIR "/images/"); |
|
181 |
||
182 |
// Testing get/set functions |
|
183 |
void tst_QImageReader::getSetCheck() |
|
184 |
{ |
|
185 |
QImageReader obj1; |
|
186 |
// QIODevice * QImageReader::device() |
|
187 |
// void QImageReader::setDevice(QIODevice *) |
|
188 |
QFile *var1 = new QFile; |
|
189 |
obj1.setDevice(var1); |
|
190 |
||
191 |
//A bit strange but that's the only way to compile under windows. |
|
192 |
QCOMPARE((QIODevice *) var1, obj1.device()); |
|
193 |
obj1.setDevice((QIODevice *)0); |
|
194 |
QCOMPARE((QIODevice *) 0, |
|
195 |
obj1.device()); |
|
196 |
delete var1; |
|
197 |
} |
|
198 |
||
199 |
tst_QImageReader::tst_QImageReader() |
|
200 |
{ |
|
201 |
} |
|
202 |
||
203 |
tst_QImageReader::~tst_QImageReader() |
|
204 |
{ |
|
205 |
||
206 |
} |
|
207 |
||
208 |
void tst_QImageReader::init() |
|
209 |
{ |
|
210 |
} |
|
211 |
||
212 |
void tst_QImageReader::cleanup() |
|
213 |
{ |
|
214 |
} |
|
215 |
||
216 |
void tst_QImageReader::readImage_data() |
|
217 |
{ |
|
218 |
QTest::addColumn<QString>("fileName"); |
|
219 |
QTest::addColumn<bool>("success"); |
|
220 |
QTest::addColumn<QByteArray>("format"); |
|
221 |
||
222 |
QTest::newRow("empty") << QString() << false << QByteArray(); |
|
223 |
QTest::newRow("BMP: colorful") << QString("colorful.bmp") << true << QByteArray("bmp"); |
|
224 |
QTest::newRow("BMP: font") << QString("font.bmp") << true << QByteArray("bmp"); |
|
225 |
QTest::newRow("BMP: signed char") << QString("crash-signed-char.bmp") << true << QByteArray("bmp"); |
|
226 |
QTest::newRow("BMP: 4bpp RLE") << QString("4bpp-rle.bmp") << true << QByteArray("bmp"); |
|
227 |
QTest::newRow("BMP: 4bpp uncompressed") << QString("tst7.bmp") << true << QByteArray("bmp"); |
|
228 |
QTest::newRow("BMP: 16bpp") << QString("16bpp.bmp") << true << QByteArray("bmp"); |
|
229 |
QTest::newRow("BMP: negative height") << QString("negativeheight.bmp") << true << QByteArray("bmp"); |
|
230 |
QTest::newRow("XPM: marble") << QString("marble.xpm") << true << QByteArray("xpm"); |
|
231 |
QTest::newRow("PNG: kollada") << QString("kollada.png") << true << QByteArray("png"); |
|
232 |
QTest::newRow("PPM: teapot") << QString("teapot.ppm") << true << QByteArray("ppm"); |
|
233 |
QTest::newRow("PPM: runners") << QString("runners.ppm") << true << QByteArray("ppm"); |
|
234 |
QTest::newRow("PPM: test") << QString("test.ppm") << true << QByteArray("ppm"); |
|
235 |
QTest::newRow("XBM: gnus") << QString("gnus.xbm") << true << QByteArray("xbm"); |
|
236 |
||
237 |
#if defined QTEST_HAVE_JPEG |
|
238 |
QTest::newRow("JPEG: beavis") << QString("beavis.jpg") << true << QByteArray("jpeg"); |
|
239 |
#endif |
|
240 |
#if defined QTEST_HAVE_GIF |
|
241 |
QTest::newRow("GIF: earth") << QString("earth.gif") << true << QByteArray("gif"); |
|
242 |
QTest::newRow("GIF: trolltech") << QString("trolltech.gif") << true << QByteArray("gif"); |
|
243 |
#endif |
|
244 |
#if defined QTEST_HAVE_MNG |
|
245 |
QTest::newRow("MNG: ball") << QString("ball.mng") << true << QByteArray("mng"); |
|
246 |
QTest::newRow("MNG: fire") << QString("fire.mng") << true << QByteArray("mng"); |
|
247 |
#endif |
|
248 |
} |
|
249 |
||
250 |
void tst_QImageReader::readImage() |
|
251 |
{ |
|
252 |
QFETCH(QString, fileName); |
|
253 |
QFETCH(bool, success); |
|
254 |
QFETCH(QByteArray, format); |
|
255 |
||
256 |
for (int i = 0; i < 2; ++i) { |
|
257 |
QImageReader io(prefix + fileName, i ? QByteArray() : format); |
|
258 |
if (success) { |
|
259 |
if (!io.supportsAnimation()) |
|
260 |
QVERIFY(io.imageCount() > 0); |
|
261 |
} else { |
|
262 |
QCOMPARE(io.imageCount(), -1); |
|
263 |
} |
|
264 |
QImage image = io.read(); |
|
265 |
if (!success) { |
|
266 |
QVERIFY(image.isNull()); |
|
267 |
return; |
|
268 |
} |
|
269 |
||
270 |
QVERIFY2(!image.isNull(), io.errorString().toLatin1().constData()); |
|
271 |
||
272 |
// No format |
|
273 |
QImageReader io2(prefix + fileName); |
|
274 |
QVERIFY2(!io2.read().isNull(), io.errorString().toLatin1().constData()); |
|
275 |
||
276 |
// No extension, no format |
|
277 |
QImageReader io3(prefix + fileName.left(fileName.lastIndexOf(QLatin1Char('.')))); |
|
278 |
QVERIFY2(!io3.read().isNull(), io.errorString().toLatin1().constData()); |
|
279 |
||
280 |
// Read into \a image2 |
|
281 |
QImage image2; |
|
282 |
QImageReader image2Reader(prefix + fileName, i ? QByteArray() : format); |
|
283 |
QCOMPARE(image2Reader.format(), format); |
|
284 |
QVERIFY(image2Reader.read(&image2)); |
|
285 |
if (image2Reader.canRead()) { |
|
286 |
if (i) |
|
287 |
QVERIFY(!image2Reader.format().isEmpty()); |
|
288 |
else |
|
289 |
QCOMPARE(image2Reader.format(), format); |
|
290 |
} else { |
|
291 |
if (i) |
|
292 |
QVERIFY(image2Reader.format().isEmpty()); |
|
293 |
else |
|
294 |
QVERIFY(!image2Reader.format().isEmpty()); |
|
295 |
} |
|
296 |
QCOMPARE(image, image2); |
|
297 |
||
298 |
do { |
|
299 |
QVERIFY2(!image.isNull(), io.errorString().toLatin1().constData()); |
|
300 |
} while (!(image = io.read()).isNull()); |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
void tst_QImageReader::jpegRgbCmyk() |
|
305 |
{ |
|
306 |
QImage image1(prefix + QLatin1String("YCbCr_cmyk.jpg")); |
|
307 |
QImage image2(prefix + QLatin1String("YCbCr_cmyk.png")); |
|
308 |
||
309 |
QCOMPARE(image1, image2); |
|
310 |
} |
|
311 |
||
312 |
void tst_QImageReader::setScaledSize_data() |
|
313 |
{ |
|
314 |
QTest::addColumn<QString>("fileName"); |
|
315 |
QTest::addColumn<QSize>("newSize"); |
|
316 |
QTest::addColumn<QByteArray>("format"); |
|
317 |
||
318 |
QTest::newRow("BMP: colorful") << "colorful" << QSize(200, 200) << QByteArray("bmp"); |
|
319 |
QTest::newRow("BMP: font") << "font" << QSize(200, 200) << QByteArray("bmp"); |
|
320 |
QTest::newRow("XPM: marble") << "marble" << QSize(200, 200) << QByteArray("xpm"); |
|
321 |
QTest::newRow("PNG: kollada") << "kollada" << QSize(200, 200) << QByteArray("png"); |
|
322 |
QTest::newRow("PPM: teapot") << "teapot" << QSize(200, 200) << QByteArray("ppm"); |
|
323 |
QTest::newRow("PPM: runners") << "runners.ppm" << QSize(400, 400) << QByteArray("ppm"); |
|
324 |
QTest::newRow("PPM: test") << "test.ppm" << QSize(10, 10) << QByteArray("ppm"); |
|
325 |
QTest::newRow("XBM: gnus") << "gnus" << QSize(200, 200) << QByteArray("xbm"); |
|
326 |
#ifdef QTEST_HAVE_JPEG |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
327 |
QTest::newRow("JPEG: beavis A") << "beavis" << QSize(200, 200) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
328 |
QTest::newRow("JPEG: beavis B") << "beavis" << QSize(175, 175) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
329 |
QTest::newRow("JPEG: beavis C") << "beavis" << QSize(100, 100) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
330 |
QTest::newRow("JPEG: beavis D") << "beavis" << QSize(100, 200) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
331 |
QTest::newRow("JPEG: beavis E") << "beavis" << QSize(200, 100) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
332 |
QTest::newRow("JPEG: beavis F") << "beavis" << QSize(87, 87) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
333 |
QTest::newRow("JPEG: beavis G") << "beavis" << QSize(50, 45) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
334 |
QTest::newRow("JPEG: beavis H") << "beavis" << QSize(43, 43) << QByteArray("jpeg"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
335 |
QTest::newRow("JPEG: beavis I") << "beavis" << QSize(25, 25) << QByteArray("jpeg"); |
0 | 336 |
#endif // QTEST_HAVE_JPEG |
337 |
#ifdef QTEST_HAVE_GIF |
|
338 |
QTest::newRow("GIF: earth") << "earth" << QSize(200, 200) << QByteArray("gif"); |
|
339 |
QTest::newRow("GIF: trolltech") << "trolltech" << QSize(200, 200) << QByteArray("gif"); |
|
340 |
#endif // QTEST_HAVE_GIF |
|
341 |
#ifdef QTEST_HAVE_MNG |
|
342 |
QTest::newRow("MNG: ball") << "ball" << QSize(200, 200) << QByteArray("mng"); |
|
343 |
QTest::newRow("MNG: fire") << "fire" << QSize(200, 200) << QByteArray("mng"); |
|
344 |
#endif // QTEST_HAVE_MNG |
|
345 |
} |
|
346 |
||
347 |
void tst_QImageReader::setScaledSize() |
|
348 |
{ |
|
349 |
QFETCH(QString, fileName); |
|
350 |
QFETCH(QSize, newSize); |
|
351 |
QFETCH(QByteArray, format); |
|
352 |
||
353 |
if (!format.isEmpty() && !QImageReader::supportedImageFormats().contains(format)) |
|
354 |
QSKIP("Qt does not support reading the \"" + format + "\" format", SkipSingle); |
|
355 |
||
356 |
QImageReader reader(prefix + fileName); |
|
357 |
reader.setScaledSize(newSize); |
|
358 |
QImage image = reader.read(); |
|
359 |
QVERIFY(!image.isNull()); |
|
360 |
||
361 |
QCOMPARE(image.size(), newSize); |
|
362 |
} |
|
363 |
||
364 |
void tst_QImageReader::task255627_setNullScaledSize_data() |
|
365 |
{ |
|
366 |
setScaledSize_data(); |
|
367 |
} |
|
368 |
||
369 |
void tst_QImageReader::task255627_setNullScaledSize() |
|
370 |
{ |
|
371 |
QFETCH(QString, fileName); |
|
372 |
QFETCH(QByteArray, format); |
|
373 |
||
374 |
if (!format.isEmpty() && !QImageReader::supportedImageFormats().contains(format)) |
|
375 |
QSKIP("Qt does not support reading the \"" + format + "\" format", SkipSingle); |
|
376 |
||
377 |
QImageReader reader(prefix + fileName); |
|
378 |
||
379 |
// set a null size |
|
380 |
reader.setScaledSize(QSize(0, 0)); |
|
381 |
reader.setQuality(0); |
|
382 |
QImage image = reader.read(); |
|
383 |
QVERIFY(image.isNull()); |
|
384 |
QCOMPARE(image.size(), QSize(0, 0)); |
|
385 |
} |
|
386 |
||
387 |
void tst_QImageReader::setClipRect_data() |
|
388 |
{ |
|
389 |
QTest::addColumn<QString>("fileName"); |
|
390 |
QTest::addColumn<QRect>("newRect"); |
|
391 |
QTest::addColumn<QByteArray>("format"); |
|
392 |
QTest::newRow("BMP: colorful") << "colorful" << QRect(0, 0, 50, 50) << QByteArray("bmp"); |
|
393 |
QTest::newRow("BMP: font") << "font" << QRect(0, 0, 50, 50) << QByteArray("bmp"); |
|
394 |
QTest::newRow("BMP: 4bpp uncompressed") << "tst7.bmp" << QRect(0, 0, 31, 31) << QByteArray("bmp"); |
|
395 |
QTest::newRow("XPM: marble") << "marble" << QRect(0, 0, 50, 50) << QByteArray("xpm"); |
|
396 |
QTest::newRow("PNG: kollada") << "kollada" << QRect(0, 0, 50, 50) << QByteArray("png"); |
|
397 |
QTest::newRow("PPM: teapot") << "teapot" << QRect(0, 0, 50, 50) << QByteArray("ppm"); |
|
398 |
QTest::newRow("PPM: runners") << "runners.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm"); |
|
399 |
QTest::newRow("PPM: test") << "test.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm"); |
|
400 |
QTest::newRow("XBM: gnus") << "gnus" << QRect(0, 0, 50, 50) << QByteArray("xbm"); |
|
401 |
#ifdef QTEST_HAVE_JPEG |
|
402 |
QTest::newRow("JPEG: beavis") << "beavis" << QRect(0, 0, 50, 50) << QByteArray("jpeg"); |
|
403 |
#endif // QTEST_HAVE_JPEG |
|
404 |
#ifdef QTEST_HAVE_GIF |
|
405 |
QTest::newRow("GIF: earth") << "earth" << QRect(0, 0, 50, 50) << QByteArray("gif"); |
|
406 |
QTest::newRow("GIF: trolltech") << "trolltech" << QRect(0, 0, 50, 50) << QByteArray("gif"); |
|
407 |
#endif // QTEST_HAVE_GIF |
|
408 |
#ifdef QTEST_HAVE_MNG |
|
409 |
QTest::newRow("MNG: ball") << "ball" << QRect(0, 0, 50, 50) << QByteArray("mng"); |
|
410 |
QTest::newRow("MNG: fire") << "fire" << QRect(0, 0, 50, 50) << QByteArray("mng"); |
|
411 |
#endif // QTEST_HAVE_MNG |
|
412 |
} |
|
413 |
||
414 |
void tst_QImageReader::setClipRect() |
|
415 |
{ |
|
416 |
QFETCH(QString, fileName); |
|
417 |
QFETCH(QRect, newRect); |
|
418 |
QFETCH(QByteArray, format); |
|
419 |
||
420 |
if (!format.isEmpty() && !QImageReader::supportedImageFormats().contains(format)) |
|
421 |
QSKIP("Qt does not support reading the \"" + format + "\" format", SkipSingle); |
|
422 |
||
423 |
QImageReader reader(prefix + fileName); |
|
424 |
reader.setClipRect(newRect); |
|
425 |
QImage image = reader.read(); |
|
426 |
QVERIFY(!image.isNull()); |
|
427 |
QCOMPARE(image.rect(), newRect); |
|
428 |
||
429 |
QImageReader originalReader(prefix + fileName); |
|
430 |
QImage originalImage = originalReader.read(); |
|
431 |
QCOMPARE(originalImage.copy(newRect), image); |
|
432 |
} |
|
433 |
||
434 |
void tst_QImageReader::setScaledClipRect_data() |
|
435 |
{ |
|
436 |
QTest::addColumn<QString>("fileName"); |
|
437 |
QTest::addColumn<QRect>("newRect"); |
|
438 |
QTest::addColumn<QByteArray>("format"); |
|
439 |
||
440 |
QTest::newRow("BMP: colorful") << "colorful" << QRect(0, 0, 50, 50) << QByteArray("bmp"); |
|
441 |
QTest::newRow("BMP: font") << "font" << QRect(0, 0, 50, 50) << QByteArray("bmp"); |
|
442 |
QTest::newRow("XPM: marble") << "marble" << QRect(0, 0, 50, 50) << QByteArray("xpm"); |
|
443 |
QTest::newRow("PNG: kollada") << "kollada" << QRect(0, 0, 50, 50) << QByteArray("png"); |
|
444 |
QTest::newRow("PPM: teapot") << "teapot" << QRect(0, 0, 50, 50) << QByteArray("ppm"); |
|
445 |
QTest::newRow("PPM: runners") << "runners.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm"); |
|
446 |
QTest::newRow("PPM: test") << "test.ppm" << QRect(0, 0, 50, 50) << QByteArray("ppm"); |
|
447 |
QTest::newRow("XBM: gnus") << "gnus" << QRect(0, 0, 50, 50) << QByteArray("xbm"); |
|
448 |
#ifdef QTEST_HAVE_JPEG |
|
449 |
QTest::newRow("JPEG: beavis") << "beavis" << QRect(0, 0, 50, 50) << QByteArray("jpeg"); |
|
450 |
#endif // QTEST_HAVE_JPEG |
|
451 |
#ifdef QTEST_HAVE_GIF |
|
452 |
QTest::newRow("GIF: earth") << "earth" << QRect(0, 0, 50, 50) << QByteArray("gif"); |
|
453 |
QTest::newRow("GIF: trolltech") << "trolltech" << QRect(0, 0, 50, 50) << QByteArray("gif"); |
|
454 |
#endif // QTEST_HAVE_GIF |
|
455 |
#ifdef QTEST_HAVE_MNG |
|
456 |
QTest::newRow("MNG: ball") << "ball" << QRect(0, 0, 50, 50) << QByteArray("mng"); |
|
457 |
QTest::newRow("MNG: fire") << "fire" << QRect(0, 0, 50, 50) << QByteArray("mng"); |
|
458 |
#endif // QTEST_HAVE_MNG |
|
459 |
} |
|
460 |
||
461 |
void tst_QImageReader::setScaledClipRect() |
|
462 |
{ |
|
463 |
QFETCH(QString, fileName); |
|
464 |
QFETCH(QRect, newRect); |
|
465 |
QFETCH(QByteArray, format); |
|
466 |
||
467 |
if (!format.isEmpty() && !QImageReader::supportedImageFormats().contains(format)) |
|
468 |
QSKIP("Qt does not support reading the \"" + format + "\" format", SkipSingle); |
|
469 |
||
470 |
QImageReader reader(prefix + fileName); |
|
471 |
reader.setScaledSize(QSize(300, 300)); |
|
472 |
reader.setScaledClipRect(newRect); |
|
473 |
QImage image = reader.read(); |
|
474 |
QVERIFY(!image.isNull()); |
|
475 |
QCOMPARE(image.rect(), newRect); |
|
476 |
||
477 |
QImageReader originalReader(prefix + fileName); |
|
478 |
originalReader.setScaledSize(QSize(300, 300)); |
|
479 |
QImage originalImage = originalReader.read(); |
|
480 |
QCOMPARE(originalImage.copy(newRect), image); |
|
481 |
} |
|
482 |
||
483 |
void tst_QImageReader::imageFormat_data() |
|
484 |
{ |
|
485 |
QTest::addColumn<QString>("fileName"); |
|
486 |
QTest::addColumn<QByteArray>("format"); |
|
487 |
QTest::addColumn<QImage::Format>("imageFormat"); |
|
488 |
||
489 |
QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm") << QImage::Format_Mono; |
|
490 |
QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm") << QImage::Format_Indexed8; |
|
491 |
QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm") << QImage::Format_RGB32; |
|
492 |
QTest::newRow("ppm-2") << QString("teapot.ppm") << QByteArray("ppm") << QImage::Format_RGB32; |
|
493 |
QTest::newRow("ppm-3") << QString("runners.ppm") << QByteArray("ppm") << QImage::Format_RGB32; |
|
494 |
QTest::newRow("ppm-4") << QString("test.ppm") << QByteArray("ppm") << QImage::Format_RGB32; |
|
495 |
#ifdef QTEST_HAVE_JPEG |
|
496 |
QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg") << QImage::Format_Indexed8; |
|
497 |
QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg") << QImage::Format_RGB32; |
|
498 |
QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg") << QImage::Format_RGB32; |
|
499 |
#endif |
|
500 |
#if defined QTEST_HAVE_GIF |
|
501 |
QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif") << QImage::Format_Invalid; |
|
502 |
QTest::newRow("gif-2") << QString("trolltech.gif") << QByteArray("gif") << QImage::Format_Invalid; |
|
503 |
#endif |
|
504 |
QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm") << QImage::Format_MonoLSB; |
|
505 |
QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm") << QImage::Format_Indexed8; |
|
506 |
QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp") << QImage::Format_Indexed8; |
|
507 |
QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp") << QImage::Format_Indexed8; |
|
508 |
QTest::newRow("png") << QString("kollada.png") << QByteArray("png") << QImage::Format_ARGB32; |
|
509 |
QTest::newRow("png-2") << QString("YCbCr_cmyk.png") << QByteArray("png") << QImage::Format_RGB32; |
|
510 |
QTest::newRow("mng-1") << QString("ball.mng") << QByteArray("mng") << QImage::Format_Invalid; |
|
511 |
QTest::newRow("mng-2") << QString("fire.mng") << QByteArray("mng") << QImage::Format_Invalid; |
|
512 |
} |
|
513 |
||
514 |
void tst_QImageReader::imageFormat() |
|
515 |
{ |
|
516 |
QFETCH(QString, fileName); |
|
517 |
QFETCH(QByteArray, format); |
|
518 |
QFETCH(QImage::Format, imageFormat); |
|
519 |
||
520 |
if (QImageReader::imageFormat(prefix + fileName).isEmpty()) { |
|
521 |
if (QByteArray("jpeg") == format) |
|
522 |
#ifndef QTEST_HAVE_JPEG |
|
523 |
return; |
|
524 |
#endif // !QTEST_HAVE_JPEG |
|
525 |
if (QByteArray("gif") == format) |
|
526 |
#ifndef QTEST_HAVE_GIF |
|
527 |
return; |
|
528 |
#endif // !QTEST_HAVE_GIF |
|
529 |
if (QByteArray("mng") == format) |
|
530 |
#ifndef QTEST_HAVE_MNG |
|
531 |
return; |
|
532 |
#endif // !QTEST_HAVE_MNG |
|
533 |
QSKIP(("Qt does not support the " + format + " format.").constData(), SkipSingle); |
|
534 |
} else { |
|
535 |
QCOMPARE(QImageReader::imageFormat(prefix + fileName), format); |
|
536 |
} |
|
537 |
QImageReader reader(prefix + fileName); |
|
538 |
QCOMPARE(reader.imageFormat(), imageFormat); |
|
539 |
} |
|
540 |
||
541 |
void tst_QImageReader::blackXPM() |
|
542 |
{ |
|
543 |
QImage image(prefix + QLatin1String("black.xpm")); |
|
544 |
QImage image2(prefix + QLatin1String("black.png")); |
|
545 |
QCOMPARE(image.pixel(25, 25), qRgb(190, 190, 190)); |
|
546 |
QCOMPARE(image.pixel(25, 25), image2.pixel(25, 25)); |
|
547 |
} |
|
548 |
||
549 |
void tst_QImageReader::transparentXPM() |
|
550 |
{ |
|
551 |
QImage image(prefix + QLatin1String("nontransparent.xpm")); |
|
552 |
QImage image2(prefix + QLatin1String("transparent.xpm")); |
|
553 |
QCOMPARE(image.format(), QImage::Format_RGB32); |
|
554 |
QCOMPARE(image2.format(), QImage::Format_ARGB32); |
|
555 |
} |
|
556 |
||
557 |
void tst_QImageReader::multiWordNamedColorXPM() |
|
558 |
{ |
|
559 |
QImage image(prefix + QLatin1String("namedcolors.xpm")); |
|
560 |
QCOMPARE(image.pixel(0, 0), qRgb(102, 139, 139)); // pale turquoise 4 |
|
561 |
QCOMPARE(image.pixel(0, 1), qRgb(250, 250, 210)); // light golden rod yellow |
|
562 |
QCOMPARE(image.pixel(0, 2), qRgb(255, 250, 205)); // lemon chiffon |
|
563 |
} |
|
564 |
||
565 |
void tst_QImageReader::supportedFormats() |
|
566 |
{ |
|
567 |
QList<QByteArray> formats = QImageReader::supportedImageFormats(); |
|
568 |
QList<QByteArray> sortedFormats = formats; |
|
569 |
qSort(sortedFormats); |
|
570 |
||
571 |
// check that the list is sorted |
|
572 |
QCOMPARE(formats, sortedFormats); |
|
573 |
||
574 |
QSet<QByteArray> formatSet; |
|
575 |
foreach (QByteArray format, formats) |
|
576 |
formatSet << format; |
|
577 |
||
578 |
// check that the list does not contain duplicates |
|
579 |
QCOMPARE(formatSet.size(), formats.size()); |
|
580 |
} |
|
581 |
||
582 |
void tst_QImageReader::setBackgroundColor_data() |
|
583 |
{ |
|
584 |
QTest::addColumn<QString>("fileName"); |
|
585 |
QTest::addColumn<QColor>("color"); |
|
586 |
||
587 |
QTest::newRow("BMP: colorful") << QString("colorful.bmp") << QColor(Qt::white); |
|
588 |
QTest::newRow("BMP: font") << QString("font.bmp") << QColor(Qt::black); |
|
589 |
QTest::newRow("BMP: signed char") << QString("crash-signed-char.bmp") << QColor(Qt::red); |
|
590 |
QTest::newRow("XPM: marble") << QString("marble.xpm") << QColor(Qt::darkRed); |
|
591 |
QTest::newRow("PNG: kollada") << QString("kollada.png") << QColor(Qt::green); |
|
592 |
QTest::newRow("PPM: teapot") << QString("teapot.ppm") << QColor(Qt::darkGreen); |
|
593 |
QTest::newRow("PPM: runners") << QString("runners.ppm") << QColor(Qt::red); |
|
594 |
QTest::newRow("PPM: test") << QString("test.ppm") << QColor(Qt::white); |
|
595 |
QTest::newRow("XBM: gnus") << QString("gnus.xbm") << QColor(Qt::blue); |
|
596 |
#if defined QTEST_HAVE_JPEG |
|
597 |
QTest::newRow("JPEG: beavis") << QString("beavis.jpg") << QColor(Qt::darkBlue); |
|
598 |
#endif |
|
599 |
#if defined QTEST_HAVE_GIF |
|
600 |
QTest::newRow("GIF: earth") << QString("earth.gif") << QColor(Qt::cyan); |
|
601 |
QTest::newRow("GIF: trolltech") << QString("trolltech.gif") << QColor(Qt::magenta); |
|
602 |
#endif |
|
603 |
#if defined QTEST_HAVE_MNG |
|
604 |
QTest::newRow("MNG: ball") << QString("ball.mng") << QColor(Qt::yellow); |
|
605 |
QTest::newRow("MNG: fire") << QString("fire.mng") << QColor(Qt::gray); |
|
606 |
#endif |
|
607 |
} |
|
608 |
||
609 |
void tst_QImageReader::setBackgroundColor() |
|
610 |
{ |
|
611 |
QFETCH(QString, fileName); |
|
612 |
QFETCH(QColor, color); |
|
613 |
QImageReader io("images/" + fileName); |
|
614 |
io.setBackgroundColor(color); |
|
615 |
if (io.backgroundColor().isValid()) |
|
616 |
QCOMPARE(io.backgroundColor(), color); |
|
617 |
} |
|
618 |
||
619 |
void tst_QImageReader::supportsAnimation_data() |
|
620 |
{ |
|
621 |
QTest::addColumn<QString>("fileName"); |
|
622 |
QTest::addColumn<bool>("success"); |
|
623 |
||
624 |
QTest::newRow("BMP: colorful") << QString("colorful.bmp") << false; |
|
625 |
QTest::newRow("BMP: font") << QString("font.bmp") << false; |
|
626 |
QTest::newRow("BMP: signed char") << QString("crash-signed-char.bmp") << false; |
|
627 |
QTest::newRow("XPM: marble") << QString("marble.xpm") << false; |
|
628 |
QTest::newRow("PNG: kollada") << QString("kollada.png") << false; |
|
629 |
QTest::newRow("PPM: teapot") << QString("teapot.ppm") << false; |
|
630 |
QTest::newRow("PPM: teapot") << QString("teapot.ppm") << false; |
|
631 |
QTest::newRow("PPM: runners") << QString("runners.ppm") << false; |
|
632 |
QTest::newRow("XBM: gnus") << QString("gnus.xbm") << false; |
|
633 |
#if defined QTEST_HAVE_JPEG |
|
634 |
QTest::newRow("JPEG: beavis") << QString("beavis.jpg") << false; |
|
635 |
#endif |
|
636 |
#if defined QTEST_HAVE_GIF |
|
637 |
QTest::newRow("GIF: earth") << QString("earth.gif") << true; |
|
638 |
QTest::newRow("GIF: trolltech") << QString("trolltech.gif") << true; |
|
639 |
#endif |
|
640 |
#if defined QTEST_HAVE_MNG |
|
641 |
QTest::newRow("MNG: ball") << QString("ball.mng") << true; |
|
642 |
QTest::newRow("MNG: fire") << QString("fire.mng") << true; |
|
643 |
#endif |
|
644 |
} |
|
645 |
||
646 |
void tst_QImageReader::supportsAnimation() |
|
647 |
{ |
|
648 |
QFETCH(QString, fileName); |
|
649 |
QFETCH(bool, success); |
|
650 |
QImageReader io(prefix + fileName); |
|
651 |
QCOMPARE(io.supportsAnimation(), success); |
|
652 |
} |
|
653 |
||
654 |
void tst_QImageReader::sizeBeforeRead_data() |
|
655 |
{ |
|
656 |
imageFormat_data(); |
|
657 |
} |
|
658 |
||
659 |
void tst_QImageReader::sizeBeforeRead() |
|
660 |
{ |
|
661 |
QFETCH(QString, fileName); |
|
662 |
QFETCH(QByteArray, format); |
|
663 |
QImageReader reader(prefix + fileName); |
|
664 |
QVERIFY(reader.canRead()); |
|
665 |
if (format == "mng") { |
|
666 |
QCOMPARE(reader.size(), QSize()); |
|
667 |
return; |
|
668 |
} |
|
669 |
||
670 |
QSize size = reader.size(); |
|
671 |
QVERIFY(reader.canRead()); |
|
672 |
QImage image = reader.read(); |
|
673 |
QVERIFY(!image.isNull()); |
|
674 |
QCOMPARE(size, image.size()); |
|
675 |
} |
|
676 |
||
677 |
void tst_QImageReader::imageFormatBeforeRead_data() |
|
678 |
{ |
|
679 |
imageFormat_data(); |
|
680 |
} |
|
681 |
||
682 |
void tst_QImageReader::imageFormatBeforeRead() |
|
683 |
{ |
|
684 |
QFETCH(QString, fileName); |
|
685 |
QFETCH(QImage::Format, imageFormat); |
|
686 |
QImageReader reader(fileName); |
|
687 |
if (reader.supportsOption(QImageIOHandler::ImageFormat)) { |
|
688 |
QImage::Format fileFormat = reader.imageFormat(); |
|
689 |
QCOMPARE(fileFormat, imageFormat); |
|
690 |
QSize size = reader.size(); |
|
691 |
QImage image(size, fileFormat); |
|
692 |
QVERIFY(reader.read(&image)); |
|
693 |
QCOMPARE(image.format(), fileFormat); |
|
694 |
} |
|
695 |
} |
|
696 |
||
697 |
#if defined QTEST_HAVE_GIF |
|
698 |
void tst_QImageReader::gifHandlerBugs() |
|
699 |
{ |
|
700 |
{ |
|
701 |
QImageReader io(prefix + "trolltech.gif"); |
|
702 |
QVERIFY(io.loopCount() != 1); |
|
703 |
int count=0; |
|
704 |
for (; io.canRead(); io.read(), ++count) ; |
|
705 |
QVERIFY(count == 34); |
|
706 |
} |
|
707 |
||
708 |
// Task 95166 |
|
709 |
{ |
|
710 |
QImageReader io1(prefix + "bat1.gif"); |
|
711 |
QImageReader io2(prefix + "bat2.gif"); |
|
712 |
QVERIFY(io1.canRead()); |
|
713 |
QVERIFY(io2.canRead()); |
|
714 |
QImage im1 = io1.read(); |
|
715 |
QImage im2 = io2.read(); |
|
716 |
QVERIFY(!im1.isNull()); |
|
717 |
QVERIFY(!im2.isNull()); |
|
718 |
QCOMPARE(im1, im2); |
|
719 |
} |
|
720 |
||
721 |
// Task 9994 |
|
722 |
{ |
|
723 |
QImageReader io1(prefix + "noclearcode.gif"); |
|
724 |
QImageReader io2(prefix + "noclearcode.bmp"); |
|
725 |
QVERIFY(io1.canRead()); QVERIFY(io2.canRead()); |
|
726 |
QImage im1 = io1.read(); QImage im2 = io2.read(); |
|
727 |
QVERIFY(!im1.isNull()); QVERIFY(!im2.isNull()); |
|
728 |
QCOMPARE(im1.convertToFormat(QImage::Format_ARGB32), im2.convertToFormat(QImage::Format_ARGB32)); |
|
729 |
} |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
730 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
731 |
// Check the undocumented feature. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
732 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
733 |
QImageReader io(prefix + "endless-anim.gif"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
734 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
735 |
QCOMPARE(io.loopCount(), -1); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
736 |
} |
0 | 737 |
} |
738 |
||
739 |
void tst_QImageReader::animatedGif() |
|
740 |
{ |
|
741 |
QImageReader io(":images/qt.gif"); |
|
742 |
QImage image = io.read(); |
|
743 |
QVERIFY(!image.isNull()); |
|
744 |
int i = 0; |
|
745 |
while(!image.isNull()){ |
|
746 |
QString frameName = QString(":images/qt%1.gif").arg(++i); |
|
747 |
QCOMPARE(image, QImage(frameName)); |
|
748 |
image = io.read(); |
|
749 |
} |
|
750 |
} |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
751 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
752 |
// http://bugreports.qt.nokia.com/browse/QTBUG-6696 |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
753 |
// Check the count of images in various call orders... |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
754 |
void tst_QImageReader::gifImageCount() |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
755 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
756 |
// just read every frame... and see how much we got.. |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
757 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
758 |
QImageReader io(":images/four-frames.gif"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
759 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
760 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
761 |
QImage blackFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
762 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
763 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
764 |
QImage whiteFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
765 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
766 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
767 |
QImage greenFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
768 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
769 |
QVERIFY(io.imageCount() == 4); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
770 |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
771 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
772 |
QImage blueFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
773 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
774 |
QVERIFY(!io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
775 |
QImage emptyFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
776 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
777 |
QVERIFY(!io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
778 |
QCOMPARE(blackFrame.pixel(0,0), qRgb(0, 0, 0)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
779 |
QCOMPARE(blackFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
780 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
781 |
QCOMPARE(whiteFrame.pixel(0,0), qRgb(0xff, 0xff, 0xff)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
782 |
QCOMPARE(whiteFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
783 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
784 |
QCOMPARE(greenFrame.pixel(0,0), qRgb(0x0, 0xff, 0x0)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
785 |
QCOMPARE(greenFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
786 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
787 |
QCOMPARE(blueFrame.pixel(0,0), qRgb(0x0, 0x0, 0xff)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
788 |
QCOMPARE(blueFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
789 |
QVERIFY(emptyFrame.isNull()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
790 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
791 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
792 |
// Read and get the size |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
793 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
794 |
QImageReader io(":images/four-frames.gif"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
795 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
796 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
797 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
798 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
799 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
800 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
801 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
802 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
803 |
QImage blackFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
804 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
805 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
806 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
807 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
808 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
809 |
QImage whiteFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
810 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
811 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
812 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
813 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
814 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
815 |
QImage greenFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
816 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
817 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
818 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
819 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
820 |
QVERIFY(io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
821 |
QImage blueFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
822 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
823 |
QVERIFY(!io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
824 |
QCOMPARE(io.size(), QSize()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
825 |
QCOMPARE(io.size(), QSize()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
826 |
QVERIFY(!io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
827 |
QImage emptyFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
828 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
829 |
QVERIFY(!io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
830 |
QCOMPARE(blackFrame.pixel(0,0), qRgb(0, 0, 0)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
831 |
QCOMPARE(blackFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
832 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
833 |
QCOMPARE(whiteFrame.pixel(0,0), qRgb(0xff, 0xff, 0xff)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
834 |
QCOMPARE(whiteFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
835 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
836 |
QCOMPARE(greenFrame.pixel(0,0), qRgb(0x0, 0xff, 0x0)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
837 |
QCOMPARE(greenFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
838 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
839 |
QCOMPARE(blueFrame.pixel(0,0), qRgb(0x0, 0x0, 0xff)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
840 |
QCOMPARE(blueFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
841 |
QVERIFY(emptyFrame.isNull()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
842 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
843 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
844 |
// Do a Size query as substitute for canRead |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
845 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
846 |
QImageReader io(":images/four-frames.gif"); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
847 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
848 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
849 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
850 |
QImage blackFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
851 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
852 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
853 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
854 |
QImage whiteFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
855 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
856 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
857 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
858 |
QImage greenFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
859 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
860 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
861 |
QCOMPARE(io.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
862 |
QImage blueFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
863 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
864 |
QCOMPARE(io.size(), QSize()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
865 |
QVERIFY(!io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
866 |
QImage emptyFrame = io.read(); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
867 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
868 |
QVERIFY(!io.canRead()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
869 |
QCOMPARE(blackFrame.pixel(0,0), qRgb(0, 0, 0)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
870 |
QCOMPARE(blackFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
871 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
872 |
QCOMPARE(whiteFrame.pixel(0,0), qRgb(0xff, 0xff, 0xff)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
873 |
QCOMPARE(whiteFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
874 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
875 |
QCOMPARE(greenFrame.pixel(0,0), qRgb(0x0, 0xff, 0x0)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
876 |
QCOMPARE(greenFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
877 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
878 |
QCOMPARE(blueFrame.pixel(0,0), qRgb(0x0, 0x0, 0xff)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
879 |
QCOMPARE(blueFrame.size(), QSize(64,64)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
880 |
QVERIFY(emptyFrame.isNull()); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
881 |
} |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
882 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
883 |
QImageReader io(":images/trolltech.gif"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
884 |
QVERIFY(io.imageCount() == 34); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
885 |
QVERIFY(io.size() == QSize(128,64)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
886 |
} |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
887 |
} |
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
888 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
889 |
void tst_QImageReader::gifLoopCount() |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
890 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
891 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
892 |
QImageReader io(":images/qt-gif-anim.gif"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
893 |
QCOMPARE(io.loopCount(), -1); // infinite loop |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
894 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
895 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
896 |
QImageReader io(":images/qt-gif-noanim.gif"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
897 |
QCOMPARE(io.loopCount(), 0); // no loop |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
898 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
899 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
900 |
|
0 | 901 |
#endif |
902 |
||
903 |
class Server : public QObject |
|
904 |
{ |
|
905 |
Q_OBJECT |
|
906 |
public: |
|
907 |
Server(const QByteArray &data) :serverSocket(0) |
|
908 |
{ |
|
909 |
connect(&server, SIGNAL(newConnection()), this, SLOT(acceptNewConnection())); |
|
910 |
server.listen(); |
|
911 |
this->data = data; |
|
912 |
} |
|
913 |
||
914 |
public slots: |
|
915 |
void runTest() |
|
916 |
{ |
|
917 |
connect(&clientSocket, SIGNAL(connected()), this, SLOT(connected())); |
|
918 |
clientSocket.connectToHost(QHostAddress::LocalHost, server.serverPort()); |
|
919 |
} |
|
920 |
||
921 |
public: |
|
922 |
inline QTcpSocket *socket() const { return serverSocket; } |
|
923 |
||
924 |
signals: |
|
925 |
void ready(); |
|
926 |
||
927 |
private slots: |
|
928 |
void acceptNewConnection() |
|
929 |
{ |
|
930 |
serverSocket = server.nextPendingConnection(); |
|
931 |
connect(serverSocket, SIGNAL(error(QAbstractSocket::SocketError)), |
|
932 |
this, SLOT(remoteHostClosed())); |
|
933 |
} |
|
934 |
||
935 |
void connected() |
|
936 |
{ |
|
937 |
clientSocket.write(data); |
|
938 |
clientSocket.disconnectFromHost(); |
|
939 |
} |
|
940 |
||
941 |
void remoteHostClosed() |
|
942 |
{ |
|
943 |
emit ready(); |
|
944 |
} |
|
945 |
||
946 |
private: |
|
947 |
QTcpServer server; |
|
948 |
QTcpSocket clientSocket; |
|
949 |
QTcpSocket *serverSocket; |
|
950 |
QByteArray data; |
|
951 |
}; |
|
952 |
||
953 |
void tst_QImageReader::readFromDevice_data() |
|
954 |
{ |
|
955 |
QTest::addColumn<QString>("fileName"); |
|
956 |
QTest::addColumn<QByteArray>("format"); |
|
957 |
||
958 |
QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm"); |
|
959 |
QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm"); |
|
960 |
QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm"); |
|
961 |
QTest::newRow("ppm-2") << QString("teapot.ppm") << QByteArray("ppm"); |
|
962 |
QTest::newRow("ppm-3") << QString("teapot.ppm") << QByteArray("ppm"); |
|
963 |
QTest::newRow("ppm-4") << QString("runners.ppm") << QByteArray("ppm"); |
|
964 |
#ifdef QTEST_HAVE_JPEG |
|
965 |
QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg"); |
|
966 |
QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg"); |
|
967 |
QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg"); |
|
968 |
#endif // QTEST_HAVE_JPEG |
|
969 |
#ifdef QTEST_HAVE_GIF |
|
970 |
QTest::newRow("gif-1") << QString("earth.gif") << QByteArray("gif"); |
|
971 |
QTest::newRow("gif-2") << QString("trolltech.gif") << QByteArray("gif"); |
|
972 |
#endif // QTEST_HAVE_GIF |
|
973 |
QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm"); |
|
974 |
QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm"); |
|
975 |
QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp"); |
|
976 |
QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp"); |
|
977 |
QTest::newRow("png") << QString("kollada.png") << QByteArray("png"); |
|
978 |
#ifdef QTEST_HAVE_MNG |
|
979 |
QTest::newRow("mng-1") << QString("ball.mng") << QByteArray("mng"); |
|
980 |
QTest::newRow("mng-2") << QString("fire.mng") << QByteArray("mng"); |
|
981 |
#endif // QTEST_HAVE_MNG |
|
982 |
} |
|
983 |
||
984 |
void tst_QImageReader::readFromDevice() |
|
985 |
{ |
|
986 |
QFETCH(QString, fileName); |
|
987 |
QFETCH(QByteArray, format); |
|
988 |
||
989 |
QImage expectedImage(prefix + fileName, format); |
|
990 |
||
991 |
QFile file(prefix + fileName); |
|
992 |
QVERIFY(file.open(QFile::ReadOnly)); |
|
993 |
QByteArray imageData = file.readAll(); |
|
994 |
QVERIFY(!imageData.isEmpty()); |
|
995 |
{ |
|
996 |
QBuffer buffer; |
|
997 |
buffer.setData(imageData); |
|
998 |
QVERIFY(buffer.open(QBuffer::ReadOnly)); |
|
999 |
||
1000 |
QImageReader reader(&buffer); |
|
1001 |
QVERIFY(reader.canRead()); |
|
1002 |
QImage imageReaderImage = reader.read(); |
|
1003 |
||
1004 |
QCOMPARE(imageReaderImage, expectedImage); |
|
1005 |
||
1006 |
buffer.seek(0); |
|
1007 |
||
1008 |
QImage image1; |
|
1009 |
QVERIFY(image1.loadFromData((const uchar *)buffer.data().data(), |
|
1010 |
buffer.data().size(), format.data())); |
|
1011 |
QCOMPARE(image1, expectedImage); |
|
1012 |
||
1013 |
QByteArray throughBase64 = QByteArray::fromBase64(imageData.toBase64()); |
|
1014 |
QVERIFY(image1.loadFromData((const uchar *)throughBase64.data(), |
|
1015 |
throughBase64.size(), format.data())); |
|
1016 |
QCOMPARE(image1, expectedImage); |
|
1017 |
} |
|
1018 |
||
1019 |
Server server(imageData); |
|
1020 |
QEventLoop loop; |
|
1021 |
connect(&server, SIGNAL(ready()), &loop, SLOT(quit())); |
|
1022 |
QTimer::singleShot(0, &server, SLOT(runTest())); |
|
1023 |
QTimer::singleShot(5000, &loop, SLOT(quit())); |
|
1024 |
loop.exec(); |
|
1025 |
||
1026 |
QImageReader reader(server.socket(), format == "xbm" ? "xbm" : ""); |
|
1027 |
if (format == "xbm") |
|
1028 |
QVERIFY(!reader.canRead()); |
|
1029 |
else |
|
1030 |
QVERIFY(reader.canRead()); |
|
1031 |
QImage imageReaderImage = reader.read(); |
|
1032 |
QCOMPARE(imageReaderImage, expectedImage); |
|
1033 |
} |
|
1034 |
||
1035 |
void tst_QImageReader::readFromFileAfterJunk_data() |
|
1036 |
{ |
|
1037 |
QTest::addColumn<QString>("fileName"); |
|
1038 |
QTest::addColumn<QByteArray>("format"); |
|
1039 |
||
1040 |
QTest::newRow("pbm") << QString("image.pbm") << QByteArray("pbm"); |
|
1041 |
QTest::newRow("pgm") << QString("image.pgm") << QByteArray("pgm"); |
|
1042 |
QTest::newRow("ppm-1") << QString("image.ppm") << QByteArray("ppm"); |
|
1043 |
QTest::newRow("ppm-2") << QString("teapot.ppm") << QByteArray("ppm"); |
|
1044 |
QTest::newRow("ppm-3") << QString("teapot.ppm") << QByteArray("ppm"); |
|
1045 |
QTest::newRow("ppm-4") << QString("runners.ppm") << QByteArray("ppm"); |
|
1046 |
#ifdef QTEST_HAVE_JPEG |
|
1047 |
QTest::newRow("jpeg-1") << QString("beavis.jpg") << QByteArray("jpeg"); |
|
1048 |
QTest::newRow("jpeg-2") << QString("YCbCr_cmyk.jpg") << QByteArray("jpeg"); |
|
1049 |
QTest::newRow("jpeg-3") << QString("YCbCr_rgb.jpg") << QByteArray("jpeg"); |
|
1050 |
#endif |
|
1051 |
#if defined QTEST_HAVE_GIF |
|
1052 |
// QTest::newRow("gif-1") << QString("images/earth.gif") << QByteArray("gif"); |
|
1053 |
// QTest::newRow("gif-2") << QString("images/trolltech.gif") << QByteArray("gif"); |
|
1054 |
#endif |
|
1055 |
QTest::newRow("xbm") << QString("gnus.xbm") << QByteArray("xbm"); |
|
1056 |
QTest::newRow("xpm") << QString("marble.xpm") << QByteArray("xpm"); |
|
1057 |
QTest::newRow("bmp-1") << QString("colorful.bmp") << QByteArray("bmp"); |
|
1058 |
QTest::newRow("bmp-2") << QString("font.bmp") << QByteArray("bmp"); |
|
1059 |
QTest::newRow("png") << QString("kollada.png") << QByteArray("png"); |
|
1060 |
// QTest::newRow("mng-1") << QString("images/ball.mng") << QByteArray("mng"); |
|
1061 |
// QTest::newRow("mng-2") << QString("images/fire.mng") << QByteArray("mng"); |
|
1062 |
} |
|
1063 |
||
1064 |
void tst_QImageReader::readFromFileAfterJunk() |
|
1065 |
{ |
|
1066 |
QFETCH(QString, fileName); |
|
1067 |
QFETCH(QByteArray, format); |
|
1068 |
||
1069 |
if (!QImageReader::supportedImageFormats().contains(format)) { |
|
1070 |
QString cause = QString("Skipping %1; no %2 support").arg(fileName).arg(QString(format)); |
|
1071 |
QSKIP(qPrintable(cause), SkipSingle); |
|
1072 |
} |
|
1073 |
||
1074 |
QFile::remove("junk"); |
|
1075 |
QFile junkFile("junk"); |
|
1076 |
QVERIFY(junkFile.open(QFile::WriteOnly)); |
|
1077 |
||
1078 |
QFile imageFile(prefix + fileName); |
|
1079 |
QVERIFY(imageFile.open(QFile::ReadOnly)); |
|
1080 |
QByteArray imageData = imageFile.readAll(); |
|
1081 |
QVERIFY(!imageData.isNull()); |
|
1082 |
||
1083 |
int iterations = 10; |
|
1084 |
if (format == "ppm" || format == "pbm" || format == "pgm") |
|
1085 |
iterations = 1; |
|
1086 |
||
1087 |
if (format == "mng" || !QImageWriter::supportedImageFormats().contains(format)) { |
|
1088 |
for (int i = 0; i < iterations; ++i) { |
|
1089 |
junkFile.write("deadbeef", 9); |
|
1090 |
QCOMPARE(junkFile.write(imageData), qint64(imageData.size())); |
|
1091 |
} |
|
1092 |
} else { |
|
1093 |
for (int i = 0; i < iterations; ++i) { |
|
1094 |
QImageWriter writer(&junkFile, format); |
|
1095 |
junkFile.write("deadbeef", 9); |
|
1096 |
QVERIFY(writer.write(QImage(prefix + fileName))); |
|
1097 |
} |
|
1098 |
} |
|
1099 |
junkFile.close(); |
|
1100 |
junkFile.open(QFile::ReadOnly); |
|
1101 |
||
1102 |
for (int i = 0; i < iterations; ++i) { |
|
1103 |
QByteArray ole = junkFile.read(9); |
|
1104 |
junkFile.ungetChar(ole[ole.size() - 1]); |
|
1105 |
char c; |
|
1106 |
junkFile.getChar(&c); |
|
1107 |
QImageReader reader(&junkFile); |
|
1108 |
QVERIFY(reader.canRead()); |
|
1109 |
QVERIFY(!reader.read().isNull()); |
|
1110 |
} |
|
1111 |
} |
|
1112 |
||
1113 |
void tst_QImageReader::description_data() |
|
1114 |
{ |
|
1115 |
QTest::addColumn<QString>("fileName"); |
|
1116 |
QTest::addColumn<QStringMap>("description"); |
|
1117 |
||
1118 |
QMap<QString, QString> willem; |
|
1119 |
willem["Title"] = "PngSuite"; |
|
1120 |
willem["Author"] = "Willem A.J. van Schaik (gwillem@ntuvax.ntu.ac.sg)"; |
|
1121 |
willem["Copyright"] = "Copyright Willem van Schaik, Singapore 1995"; |
|
1122 |
willem["Description"] = "A compilation of a set of images created to test the " |
|
1123 |
"various color-types of the PNG format. Included are " |
|
1124 |
"black&white, color, paletted, with alpha channel, with " |
|
1125 |
"transparency formats. All bit-depths allowed according " |
|
1126 |
"to the spec are present."; |
|
1127 |
willem["Software"] = "Created on a NeXTstation color using \"pnmtopng\"."; |
|
1128 |
willem["Disclaimer"] = "Freeware."; |
|
1129 |
||
1130 |
QTest::newRow("PNG") << QString("pngwithtext.png") << willem; |
|
1131 |
QTest::newRow("PNG Compressed") << QString("pngwithcompressedtext.png") << willem; |
|
1132 |
} |
|
1133 |
||
1134 |
void tst_QImageReader::description() |
|
1135 |
{ |
|
1136 |
QFETCH(QString, fileName); |
|
1137 |
QFETCH(QStringMap, description); |
|
1138 |
||
1139 |
// Sanity check |
|
1140 |
QVERIFY(!QImage(prefix + fileName).isNull()); |
|
1141 |
||
1142 |
QImageReader reader(prefix + fileName); |
|
1143 |
||
1144 |
foreach (QString key, description.keys()) |
|
1145 |
QCOMPARE(reader.text(key), description.value(key)); |
|
1146 |
QCOMPARE(reader.textKeys(), QStringList(description.keys())); |
|
1147 |
||
1148 |
QImage image = reader.read(); |
|
1149 |
QVERIFY(!image.isNull()); |
|
1150 |
||
1151 |
foreach (QString key, description.keys()) |
|
1152 |
QCOMPARE(image.text(key), description.value(key)); |
|
1153 |
QCOMPARE(image.textKeys(), QStringList(description.keys())); |
|
1154 |
||
1155 |
foreach (QString key, description.keys()) |
|
1156 |
QCOMPARE(reader.text(key), description.value(key)); |
|
1157 |
QCOMPARE(reader.textKeys(), QStringList(description.keys())); |
|
1158 |
} |
|
1159 |
||
1160 |
void tst_QImageReader::readFromResources_data() |
|
1161 |
{ |
|
1162 |
QTest::addColumn<QString>("fileName"); |
|
1163 |
QTest::addColumn<QByteArray>("format"); |
|
1164 |
QTest::addColumn<QSize>("size"); |
|
1165 |
QTest::addColumn<QString>("message"); |
|
1166 |
||
1167 |
QTest::newRow("corrupt.bmp") << QString("corrupt.bmp") |
|
1168 |
<< QByteArray("bmp") << QSize(0, 0) |
|
1169 |
<< QString(""); |
|
1170 |
QTest::newRow("negativeheight.bmp") << QString("negativeheight.bmp") |
|
1171 |
<< QByteArray("bmp") << QSize(127, 64) |
|
1172 |
<< QString(""); |
|
1173 |
QTest::newRow("font.bmp") << QString("font.bmp") |
|
1174 |
<< QByteArray("bmp") << QSize(240, 8) |
|
1175 |
<< QString(""); |
|
1176 |
QTest::newRow("noclearcode.bmp") << QString("noclearcode.bmp") |
|
1177 |
<< QByteArray("bmp") << QSize(29, 18) |
|
1178 |
<< QString(""); |
|
1179 |
QTest::newRow("colorful.bmp") << QString("colorful.bmp") |
|
1180 |
<< QByteArray("bmp") << QSize(320, 200) |
|
1181 |
<< QString(""); |
|
1182 |
QTest::newRow("16bpp.bmp") << QString("16bpp.bmp") |
|
1183 |
<< QByteArray("bmp") << QSize(320, 240) |
|
1184 |
<< QString(""); |
|
1185 |
QTest::newRow("crash-signed-char.bmp") << QString("crash-signed-char.bmp") |
|
1186 |
<< QByteArray("bmp") << QSize(360, 280) |
|
1187 |
<< QString(""); |
|
1188 |
QTest::newRow("4bpp-rle.bmp") << QString("4bpp-rle.bmp") |
|
1189 |
<< QByteArray("bmp") << QSize(640, 480) |
|
1190 |
<< QString(""); |
|
1191 |
#ifdef QTEST_HAVE_GIF |
|
1192 |
QTest::newRow("corrupt.gif") << QString("corrupt.gif") |
|
1193 |
<< QByteArray("gif") << QSize(0, 0) |
|
1194 |
<< QString(""); |
|
1195 |
QTest::newRow("trolltech.gif") << QString("trolltech.gif") |
|
1196 |
<< QByteArray("gif") << QSize(128, 64) |
|
1197 |
<< QString(""); |
|
1198 |
QTest::newRow("noclearcode.gif") << QString("noclearcode.gif") |
|
1199 |
<< QByteArray("gif") << QSize(29, 18) |
|
1200 |
<< QString(""); |
|
1201 |
QTest::newRow("earth.gif") << QString("earth.gif") |
|
1202 |
<< QByteArray("gif") << QSize(320, 200) |
|
1203 |
<< QString(""); |
|
1204 |
QTest::newRow("bat1.gif") << QString("bat1.gif") |
|
1205 |
<< QByteArray("gif") << QSize(32, 32) |
|
1206 |
<< QString(""); |
|
1207 |
QTest::newRow("bat2.gif") << QString("bat2.gif") |
|
1208 |
<< QByteArray("gif") << QSize(32, 32) |
|
1209 |
<< QString(""); |
|
1210 |
#endif |
|
1211 |
#ifdef QTEST_HAVE_JPEG |
|
1212 |
QTest::newRow("corrupt.jpg") << QString("corrupt.jpg") |
|
1213 |
<< QByteArray("jpg") << QSize(0, 0) |
|
1214 |
<< QString("JPEG datastream contains no image"); |
|
1215 |
QTest::newRow("beavis.jpg") << QString("beavis.jpg") |
|
1216 |
<< QByteArray("jpg") << QSize(350, 350) |
|
1217 |
<< QString(""); |
|
1218 |
QTest::newRow("YCbCr_cmyk.jpg") << QString("YCbCr_cmyk.jpg") |
|
1219 |
<< QByteArray("jpg") << QSize(75, 50) |
|
1220 |
<< QString(""); |
|
1221 |
QTest::newRow("YCbCr_rgb.jpg") << QString("YCbCr_rgb.jpg") |
|
1222 |
<< QByteArray("jpg") << QSize(75, 50) |
|
1223 |
<< QString(""); |
|
1224 |
#endif |
|
1225 |
#ifdef QTEST_HAVE_MNG |
|
1226 |
QTest::newRow("corrupt.mng") << QString("corrupt.mng") |
|
1227 |
<< QByteArray("mng") << QSize(0, 0) |
|
1228 |
<< QString("MNG error 901: Application signalled I/O error; chunk IHDR; subcode 0:0"); |
|
1229 |
QTest::newRow("fire.mng") << QString("fire.mng") |
|
1230 |
<< QByteArray("mng") << QSize(30, 60) |
|
1231 |
<< QString(""); |
|
1232 |
QTest::newRow("ball.mng") << QString("ball.mng") |
|
1233 |
<< QByteArray("mng") << QSize(32, 32) |
|
1234 |
<< QString(""); |
|
1235 |
#endif |
|
1236 |
QTest::newRow("image.pbm") << QString("image.pbm") |
|
1237 |
<< QByteArray("pbm") << QSize(16, 6) |
|
1238 |
<< QString(""); |
|
1239 |
QTest::newRow("image.pgm") << QString("image.pgm") |
|
1240 |
<< QByteArray("pgm") << QSize(24, 7) |
|
1241 |
<< QString(""); |
|
1242 |
QTest::newRow("corrupt.png") << QString("corrupt.png") |
|
1243 |
<< QByteArray("png") << QSize(0, 0) |
|
1244 |
<< QString(""); |
|
1245 |
QTest::newRow("away.png") << QString("away.png") |
|
1246 |
<< QByteArray("png") << QSize(16, 16) |
|
1247 |
<< QString(""); |
|
1248 |
QTest::newRow("image.png") << QString("image.png") |
|
1249 |
<< QByteArray("png") << QSize(22, 22) |
|
1250 |
<< QString(""); |
|
1251 |
QTest::newRow("pngwithcompressedtext.png") << QString("pngwithcompressedtext.png") |
|
1252 |
<< QByteArray("png") << QSize(32, 32) |
|
1253 |
<< QString(""); |
|
1254 |
QTest::newRow("pngwithtext.png") << QString("pngwithtext.png") |
|
1255 |
<< QByteArray("png") << QSize(32, 32) |
|
1256 |
<< QString(""); |
|
1257 |
QTest::newRow("kollada.png") << QString("kollada.png") |
|
1258 |
<< QByteArray("png") << QSize(436, 160) |
|
1259 |
<< QString(""); |
|
1260 |
QTest::newRow("black.png") << QString("black.png") |
|
1261 |
<< QByteArray("png") << QSize(48, 48) |
|
1262 |
<< QString(""); |
|
1263 |
QTest::newRow("YCbCr_cmyk.png") << QString("YCbCr_cmyk.png") |
|
1264 |
<< QByteArray("png") << QSize(75, 50) |
|
1265 |
<< QString(""); |
|
1266 |
QTest::newRow("teapot.ppm") << QString("teapot.ppm") |
|
1267 |
<< QByteArray("ppm") << QSize(256, 256) |
|
1268 |
<< QString(""); |
|
1269 |
QTest::newRow("image.ppm") << QString("image.ppm") |
|
1270 |
<< QByteArray("ppm") << QSize(4, 4) |
|
1271 |
<< QString(""); |
|
1272 |
QTest::newRow("runners.ppm") << QString("runners.ppm") |
|
1273 |
<< QByteArray("ppm") << QSize(400, 400) |
|
1274 |
<< QString(""); |
|
1275 |
QTest::newRow("test.ppm") << QString("test.ppm") |
|
1276 |
<< QByteArray("ppm") << QSize(10, 10) |
|
1277 |
<< QString(""); |
|
1278 |
// QTest::newRow("corrupt.xbm") << QString("corrupt.xbm") << QByteArray("xbm") << QSize(0, 0); |
|
1279 |
QTest::newRow("gnus.xbm") << QString("gnus.xbm") |
|
1280 |
<< QByteArray("xbm") << QSize(271, 273) |
|
1281 |
<< QString(""); |
|
1282 |
QTest::newRow("corrupt-colors.xpm") << QString("corrupt-colors.xpm") |
|
1283 |
<< QByteArray("xpm") << QSize(0, 0) |
|
1284 |
<< QString("QImage: XPM color specification is missing: bla9an.n#x"); |
|
1285 |
QTest::newRow("corrupt-pixels.xpm") << QString("corrupt-pixels.xpm") |
|
1286 |
<< QByteArray("xpm") << QSize(0, 0) |
|
1287 |
<< QString("QImage: XPM pixels missing on image line 3"); |
|
1288 |
QTest::newRow("marble.xpm") << QString("marble.xpm") |
|
1289 |
<< QByteArray("xpm") << QSize(240, 240) |
|
1290 |
<< QString(""); |
|
1291 |
QTest::newRow("test.xpm") << QString("test.xpm") |
|
1292 |
<< QByteArray("xpm") << QSize(256, 256) |
|
1293 |
<< QString(""); |
|
1294 |
QTest::newRow("black.xpm") << QString("black.xpm") |
|
1295 |
<< QByteArray("xpm") << QSize(48, 48) |
|
1296 |
<< QString(""); |
|
1297 |
QTest::newRow("namedcolors.xpm") << QString("namedcolors.xpm") |
|
1298 |
<< QByteArray("xpm") << QSize(8, 8) |
|
1299 |
<< QString(""); |
|
1300 |
QTest::newRow("nontransparent.xpm") << QString("nontransparent.xpm") |
|
1301 |
<< QByteArray("xpm") << QSize(8, 8) |
|
1302 |
<< QString(""); |
|
1303 |
QTest::newRow("transparent.xpm") << QString("transparent.xpm") |
|
1304 |
<< QByteArray("xpm") << QSize(8, 8) |
|
1305 |
<< QString(""); |
|
1306 |
} |
|
1307 |
||
1308 |
void tst_QImageReader::readFromResources() |
|
1309 |
{ |
|
1310 |
QFETCH(QString, fileName); |
|
1311 |
QFETCH(QByteArray, format); |
|
1312 |
QFETCH(QSize, size); |
|
1313 |
QFETCH(QString, message); |
|
1314 |
for (int i = 0; i < 2; ++i) { |
|
1315 |
QString file = i ? (":/images/" + fileName) : (prefix + fileName); |
|
1316 |
{ |
|
1317 |
// suppress warnings if we expect them |
|
1318 |
if (!message.isEmpty()) { |
|
1319 |
for (int j = 0; j < 5; ++j) |
|
1320 |
QTest::ignoreMessage(QtWarningMsg, message.toLatin1()); |
|
1321 |
} |
|
1322 |
||
1323 |
// 1) full filename, no format |
|
1324 |
QImageReader reader(file); |
|
1325 |
QImage image = reader.read(); |
|
1326 |
if (size.isNull()) |
|
1327 |
QVERIFY(image.isNull()); |
|
1328 |
else |
|
1329 |
QVERIFY(!image.isNull()); |
|
1330 |
QCOMPARE(image.size(), size); |
|
1331 |
} |
|
1332 |
{ |
|
1333 |
// 2) full filename, with format |
|
1334 |
QImageReader reader(file, format); |
|
1335 |
QImage image = reader.read(); |
|
1336 |
if (size.isNull()) |
|
1337 |
QVERIFY(image.isNull()); |
|
1338 |
else |
|
1339 |
QVERIFY(!image.isNull()); |
|
1340 |
QCOMPARE(image.size(), size); |
|
1341 |
} |
|
1342 |
{ |
|
1343 |
// 3) full filename, with uppercase format |
|
1344 |
QImageReader reader(file, format.toUpper()); |
|
1345 |
QImage image = reader.read(); |
|
1346 |
if (size.isNull()) |
|
1347 |
QVERIFY(image.isNull()); |
|
1348 |
else |
|
1349 |
QVERIFY(!image.isNull()); |
|
1350 |
QCOMPARE(image.size(), size); |
|
1351 |
} |
|
1352 |
{ |
|
1353 |
// 4) chopped filename, with format |
|
1354 |
QImageReader reader(file.left(file.lastIndexOf(QLatin1Char('.'))), format); |
|
1355 |
QImage image = reader.read(); |
|
1356 |
if (size.isNull()) |
|
1357 |
QVERIFY(image.isNull()); |
|
1358 |
else |
|
1359 |
QVERIFY(!image.isNull()); |
|
1360 |
QCOMPARE(image.size(), size); |
|
1361 |
} |
|
1362 |
{ |
|
1363 |
// 5) chopped filename, with uppercase format |
|
1364 |
QImageReader reader(file.left(file.lastIndexOf(QLatin1Char('.'))), format.toUpper()); |
|
1365 |
QImage image = reader.read(); |
|
1366 |
if (size.isNull()) |
|
1367 |
QVERIFY(image.isNull()); |
|
1368 |
else |
|
1369 |
QVERIFY(!image.isNull()); |
|
1370 |
QCOMPARE(image.size(), size); |
|
1371 |
} |
|
1372 |
} |
|
1373 |
||
1374 |
// Check that the results are identical |
|
1375 |
if (!message.isEmpty()) { |
|
1376 |
QTest::ignoreMessage(QtWarningMsg, message.toLatin1()); |
|
1377 |
QTest::ignoreMessage(QtWarningMsg, message.toLatin1()); |
|
1378 |
} |
|
1379 |
QCOMPARE(QImageReader(prefix + fileName).read(), QImageReader(":/images/" + fileName).read()); |
|
1380 |
} |
|
1381 |
||
1382 |
void tst_QImageReader::readCorruptImage_data() |
|
1383 |
{ |
|
1384 |
QTest::addColumn<QString>("fileName"); |
|
1385 |
QTest::addColumn<bool>("shouldFail"); |
|
1386 |
QTest::addColumn<QString>("message"); |
|
1387 |
#if defined QTEST_HAVE_JPEG |
|
1388 |
QTest::newRow("corrupt jpeg") << QString("corrupt.jpg") << true |
|
1389 |
<< QString("JPEG datastream contains no image"); |
|
1390 |
#endif |
|
1391 |
#if defined QTEST_HAVE_GIF |
|
1392 |
QTest::newRow("corrupt gif") << QString("corrupt.gif") << true << QString(""); |
|
1393 |
#endif |
|
1394 |
#ifdef QTEST_HAVE_MNG |
|
1395 |
QTest::newRow("corrupt mng") << QString("corrupt.mng") << true |
|
1396 |
<< QString("MNG error 901: Application signalled I/O error; chunk IHDR; subcode 0:0"); |
|
1397 |
#endif |
|
1398 |
QTest::newRow("corrupt png") << QString("corrupt.png") << true << QString(""); |
|
1399 |
QTest::newRow("corrupt bmp") << QString("corrupt.bmp") << true << QString(""); |
|
1400 |
QTest::newRow("corrupt xpm (colors)") << QString("corrupt-colors.xpm") << true |
|
1401 |
<< QString("QImage: XPM color specification is missing: bla9an.n#x"); |
|
1402 |
QTest::newRow("corrupt xpm (pixels)") << QString("corrupt-pixels.xpm") << true |
|
1403 |
<< QString("QImage: XPM pixels missing on image line 3"); |
|
1404 |
QTest::newRow("corrupt xbm") << QString("corrupt.xbm") << false << QString(""); |
|
1405 |
#if defined QTEST_HAVE_TIFF |
|
1406 |
QTest::newRow("corrupt tiff") << QString("corrupt-data.tif") << true << QString(""); |
|
1407 |
#endif |
|
1408 |
} |
|
1409 |
||
1410 |
void tst_QImageReader::readCorruptImage() |
|
1411 |
{ |
|
1412 |
QFETCH(QString, fileName); |
|
1413 |
QFETCH(bool, shouldFail); |
|
1414 |
QFETCH(QString, message); |
|
1415 |
||
1416 |
if (!message.isEmpty()) |
|
1417 |
QTest::ignoreMessage(QtWarningMsg, message.toLatin1()); |
|
1418 |
QImageReader reader(prefix + fileName); |
|
1419 |
QVERIFY(reader.canRead()); |
|
1420 |
QCOMPARE(reader.read().isNull(), shouldFail); |
|
1421 |
} |
|
1422 |
||
1423 |
void tst_QImageReader::readCorruptBmp() |
|
1424 |
{ |
|
1425 |
QCOMPARE(QImage(prefix + "tst7.bmp").convertToFormat(QImage::Format_ARGB32_Premultiplied), QImage(prefix + "tst7.png").convertToFormat(QImage::Format_ARGB32_Premultiplied)); |
|
1426 |
} |
|
1427 |
||
1428 |
void tst_QImageReader::supportsOption_data() |
|
1429 |
{ |
|
1430 |
QTest::addColumn<QString>("fileName"); |
|
1431 |
QTest::addColumn<QIntList>("options"); |
|
1432 |
||
1433 |
QTest::newRow("png") << QString("black.png") |
|
1434 |
<< (QIntList() << QImageIOHandler::Gamma |
|
1435 |
<< QImageIOHandler::Description |
|
1436 |
<< QImageIOHandler::Quality |
|
1437 |
<< QImageIOHandler::Size); |
|
1438 |
} |
|
1439 |
||
1440 |
void tst_QImageReader::supportsOption() |
|
1441 |
{ |
|
1442 |
QFETCH(QString, fileName); |
|
1443 |
QFETCH(QIntList, options); |
|
1444 |
||
1445 |
QSet<QImageIOHandler::ImageOption> allOptions; |
|
1446 |
allOptions << QImageIOHandler::Size |
|
1447 |
<< QImageIOHandler::ClipRect |
|
1448 |
<< QImageIOHandler::Description |
|
1449 |
<< QImageIOHandler::ScaledClipRect |
|
1450 |
<< QImageIOHandler::ScaledSize |
|
1451 |
<< QImageIOHandler::CompressionRatio |
|
1452 |
<< QImageIOHandler::Gamma |
|
1453 |
<< QImageIOHandler::Quality |
|
1454 |
<< QImageIOHandler::Name |
|
1455 |
<< QImageIOHandler::SubType |
|
1456 |
<< QImageIOHandler::IncrementalReading |
|
1457 |
<< QImageIOHandler::Endianness |
|
1458 |
<< QImageIOHandler::Animation |
|
1459 |
<< QImageIOHandler::BackgroundColor; |
|
1460 |
||
1461 |
QImageReader reader(prefix + fileName); |
|
1462 |
for (int i = 0; i < options.size(); ++i) { |
|
1463 |
QVERIFY(reader.supportsOption(QImageIOHandler::ImageOption(options.at(i)))); |
|
1464 |
allOptions.remove(QImageIOHandler::ImageOption(options.at(i))); |
|
1465 |
} |
|
1466 |
||
1467 |
foreach (QImageIOHandler::ImageOption option, allOptions) |
|
1468 |
QVERIFY(!reader.supportsOption(option)); |
|
1469 |
} |
|
1470 |
||
1471 |
#if defined QTEST_HAVE_TIFF |
|
1472 |
void tst_QImageReader::tiffCompression_data() |
|
1473 |
{ |
|
1474 |
QTest::addColumn<QString>("uncompressedFile"); |
|
1475 |
QTest::addColumn<QString>("compressedFile"); |
|
1476 |
||
1477 |
QTest::newRow("TIFF: adobedeflate") << "rgba_nocompression_littleendian.tif" |
|
1478 |
<< "rgba_adobedeflate_littleendian.tif"; |
|
1479 |
QTest::newRow("TIFF: lzw") << "rgba_nocompression_littleendian.tif" |
|
1480 |
<< "rgba_lzw_littleendian.tif"; |
|
1481 |
QTest::newRow("TIFF: packbits") << "rgba_nocompression_littleendian.tif" |
|
1482 |
<< "rgba_packbits_littleendian.tif"; |
|
1483 |
QTest::newRow("TIFF: zipdeflate") << "rgba_nocompression_littleendian.tif" |
|
1484 |
<< "rgba_zipdeflate_littleendian.tif"; |
|
1485 |
} |
|
1486 |
||
1487 |
void tst_QImageReader::tiffCompression() |
|
1488 |
{ |
|
1489 |
QFETCH(QString, uncompressedFile); |
|
1490 |
QFETCH(QString, compressedFile); |
|
1491 |
||
1492 |
QImage uncompressedImage(prefix + uncompressedFile); |
|
1493 |
QImage compressedImage(prefix + compressedFile); |
|
1494 |
||
1495 |
QCOMPARE(uncompressedImage, compressedImage); |
|
1496 |
} |
|
1497 |
||
1498 |
void tst_QImageReader::tiffEndianness() |
|
1499 |
{ |
|
1500 |
QImage littleEndian(prefix + "rgba_nocompression_littleendian.tif"); |
|
1501 |
QImage bigEndian(prefix + "rgba_nocompression_bigendian.tif"); |
|
1502 |
||
1503 |
QCOMPARE(littleEndian, bigEndian); |
|
1504 |
} |
|
1505 |
||
1506 |
void tst_QImageReader::tiffOrientation_data() |
|
1507 |
{ |
|
1508 |
QTest::addColumn<QString>("expected"); |
|
1509 |
QTest::addColumn<QString>("oriented"); |
|
1510 |
QTest::newRow("Indexed TIFF, orientation1") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_1.tiff"; |
|
1511 |
QTest::newRow("Indexed TIFF, orientation2") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_2.tiff"; |
|
1512 |
QTest::newRow("Indexed TIFF, orientation3") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_3.tiff"; |
|
1513 |
QTest::newRow("Indexed TIFF, orientation4") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_4.tiff"; |
|
1514 |
QTest::newRow("Indexed TIFF, orientation5") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_5.tiff"; |
|
1515 |
QTest::newRow("Indexed TIFF, orientation6") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_6.tiff"; |
|
1516 |
QTest::newRow("Indexed TIFF, orientation7") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_7.tiff"; |
|
1517 |
QTest::newRow("Indexed TIFF, orientation8") << "tiff_oriented/original_indexed.tiff" << "tiff_oriented/indexed_orientation_8.tiff"; |
|
1518 |
||
1519 |
QTest::newRow("Mono TIFF, orientation1") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_1.tiff"; |
|
1520 |
QTest::newRow("Mono TIFF, orientation2") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_2.tiff"; |
|
1521 |
QTest::newRow("Mono TIFF, orientation3") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_3.tiff"; |
|
1522 |
QTest::newRow("Mono TIFF, orientation4") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_4.tiff"; |
|
1523 |
QTest::newRow("Mono TIFF, orientation5") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_5.tiff"; |
|
1524 |
QTest::newRow("Mono TIFF, orientation6") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_6.tiff"; |
|
1525 |
QTest::newRow("Mono TIFF, orientation7") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_7.tiff"; |
|
1526 |
QTest::newRow("Mono TIFF, orientation8") << "tiff_oriented/original_mono.tiff" << "tiff_oriented/mono_orientation_8.tiff"; |
|
1527 |
||
1528 |
QTest::newRow("RGB TIFF, orientation1") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_1.tiff"; |
|
1529 |
QTest::newRow("RGB TIFF, orientation2") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_2.tiff"; |
|
1530 |
QTest::newRow("RGB TIFF, orientation3") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_3.tiff"; |
|
1531 |
QTest::newRow("RGB TIFF, orientation4") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_4.tiff"; |
|
1532 |
QTest::newRow("RGB TIFF, orientation5") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_5.tiff"; |
|
1533 |
QTest::newRow("RGB TIFF, orientation6") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_6.tiff"; |
|
1534 |
QTest::newRow("RGB TIFF, orientation7") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_7.tiff"; |
|
1535 |
QTest::newRow("RGB TIFF, orientation8") << "tiff_oriented/original_rgb.tiff" << "tiff_oriented/rgb_orientation_8.tiff"; |
|
1536 |
} |
|
1537 |
||
1538 |
void tst_QImageReader::tiffOrientation() |
|
1539 |
{ |
|
1540 |
QFETCH(QString, expected); |
|
1541 |
QFETCH(QString, oriented); |
|
1542 |
||
1543 |
QImage expectedImage(prefix + expected); |
|
1544 |
QImage orientedImage(prefix + oriented); |
|
1545 |
QCOMPARE(expectedImage, orientedImage); |
|
1546 |
} |
|
1547 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1548 |
void tst_QImageReader::tiffGrayscale() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1549 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1550 |
QImage actualImage(prefix + "grayscale.tif"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1551 |
QImage expectedImage(prefix + "grayscale-ref.tif"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1552 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1553 |
QCOMPARE(expectedImage, actualImage.convertToFormat(expectedImage.format())); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1554 |
} |
0 | 1555 |
#endif |
1556 |
||
1557 |
void tst_QImageReader::dotsPerMeter_data() |
|
1558 |
{ |
|
1559 |
QTest::addColumn<QString>("fileName"); |
|
1560 |
QTest::addColumn<int>("expectedDotsPerMeterX"); |
|
1561 |
QTest::addColumn<int>("expectedDotsPerMeterY"); |
|
1562 |
#if defined QTEST_HAVE_TIFF |
|
1563 |
QTest::newRow("TIFF: 72 dpi") << ("rgba_nocompression_littleendian.tif") << qRound(72 * (100 / 2.54)) << qRound(72 * (100 / 2.54)); |
|
1564 |
QTest::newRow("TIFF: 100 dpi") << ("image_100dpi.tif") << qRound(100 * (100 / 2.54)) << qRound(100 * (100 / 2.54)); |
|
1565 |
#endif |
|
1566 |
} |
|
1567 |
||
1568 |
void tst_QImageReader::dotsPerMeter() |
|
1569 |
{ |
|
1570 |
QFETCH(QString, fileName); |
|
1571 |
QFETCH(int, expectedDotsPerMeterX); |
|
1572 |
QFETCH(int, expectedDotsPerMeterY); |
|
1573 |
||
1574 |
QImage image(prefix + fileName); |
|
1575 |
||
1576 |
QCOMPARE(image.dotsPerMeterX(), expectedDotsPerMeterX); |
|
1577 |
QCOMPARE(image.dotsPerMeterY(), expectedDotsPerMeterY); |
|
1578 |
} |
|
1579 |
||
1580 |
void tst_QImageReader::physicalDpi_data() |
|
1581 |
{ |
|
1582 |
QTest::addColumn<QString>("fileName"); |
|
1583 |
QTest::addColumn<int>("expectedPhysicalDpiX"); |
|
1584 |
QTest::addColumn<int>("expectedPhysicalDpiY"); |
|
1585 |
#if defined QTEST_HAVE_TIFF |
|
1586 |
QTest::newRow("TIFF: 72 dpi") << "rgba_nocompression_littleendian.tif" << 72 << 72; |
|
1587 |
QTest::newRow("TIFF: 100 dpi") << "image_100dpi.tif" << 100 << 100; |
|
1588 |
#endif |
|
1589 |
} |
|
1590 |
||
1591 |
void tst_QImageReader::physicalDpi() |
|
1592 |
{ |
|
1593 |
QFETCH(QString, fileName); |
|
1594 |
QFETCH(int, expectedPhysicalDpiX); |
|
1595 |
QFETCH(int, expectedPhysicalDpiY); |
|
1596 |
||
1597 |
QImage image(prefix + fileName); |
|
1598 |
||
1599 |
QCOMPARE(image.physicalDpiX(), expectedPhysicalDpiX); |
|
1600 |
QCOMPARE(image.physicalDpiY(), expectedPhysicalDpiY); |
|
1601 |
} |
|
1602 |
||
1603 |
void tst_QImageReader::autoDetectImageFormat() |
|
1604 |
{ |
|
1605 |
// Assume PNG is supported :-) |
|
1606 |
{ |
|
1607 |
// Disables file name extension probing |
|
1608 |
QImageReader reader(prefix + "kollada"); |
|
1609 |
reader.setAutoDetectImageFormat(false); |
|
1610 |
QVERIFY(!reader.canRead()); |
|
1611 |
QVERIFY(reader.read().isNull()); |
|
1612 |
reader.setAutoDetectImageFormat(true); |
|
1613 |
QVERIFY(reader.canRead()); |
|
1614 |
QVERIFY(!reader.read().isNull()); |
|
1615 |
} |
|
1616 |
{ |
|
1617 |
// Disables detection based on suffix |
|
1618 |
QImageReader reader(prefix + "kollada.png"); |
|
1619 |
reader.setAutoDetectImageFormat(false); |
|
1620 |
QVERIFY(!reader.canRead()); |
|
1621 |
QVERIFY(reader.read().isNull()); |
|
1622 |
reader.setAutoDetectImageFormat(true); |
|
1623 |
QVERIFY(reader.canRead()); |
|
1624 |
QVERIFY(!reader.read().isNull()); |
|
1625 |
} |
|
1626 |
{ |
|
1627 |
// Disables detection based on content |
|
1628 |
QImageReader reader(prefix + "kollada-noext"); |
|
1629 |
reader.setAutoDetectImageFormat(false); |
|
1630 |
QVERIFY(!reader.canRead()); |
|
1631 |
QVERIFY(reader.read().isNull()); |
|
1632 |
reader.setAutoDetectImageFormat(true); |
|
1633 |
QVERIFY(reader.canRead()); |
|
1634 |
QVERIFY(!reader.read().isNull()); |
|
1635 |
} |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1636 |
|
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1637 |
#ifdef QTEST_HAVE_JPEG |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1638 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1639 |
QImageReader io(prefix + "YCbCr_rgb.jpg"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1640 |
io.setAutoDetectImageFormat(false); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1641 |
// This should fail since no format string is given |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1642 |
QImage image; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1643 |
QVERIFY(!io.read(&image)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1644 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1645 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1646 |
QImageReader io(prefix + "YCbCr_rgb.jpg", "jpg"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1647 |
io.setAutoDetectImageFormat(false); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1648 |
QImage image; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1649 |
QVERIFY(io.read(&image)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1650 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1651 |
#endif |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1652 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1653 |
QImageReader io(prefix + "tst7.png"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1654 |
io.setAutoDetectImageFormat(false); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1655 |
// This should fail since no format string is given |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1656 |
QImage image; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1657 |
QVERIFY(!io.read(&image)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1658 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1659 |
{ |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1660 |
QImageReader io(prefix + "tst7.png", "png"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1661 |
io.setAutoDetectImageFormat(false); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1662 |
QImage image; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1663 |
QVERIFY(io.read(&image)); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1664 |
} |
0 | 1665 |
} |
1666 |
||
1667 |
void tst_QImageReader::fileNameProbing() |
|
1668 |
{ |
|
1669 |
QString name("doesnotexist.png"); |
|
1670 |
QImageReader r; |
|
1671 |
r.setFileName(name); // non-existing / non-readable file |
|
1672 |
QCOMPARE(r.fileName(), name); |
|
1673 |
||
1674 |
r.size(); |
|
1675 |
QCOMPARE(r.fileName(), name); |
|
1676 |
r.read(); |
|
1677 |
QCOMPARE(r.fileName(), name); |
|
1678 |
} |
|
1679 |
||
1680 |
void tst_QImageReader::pixelCompareWithBaseline_data() |
|
1681 |
{ |
|
1682 |
QTest::addColumn<QString>("fileName"); |
|
1683 |
||
1684 |
QTest::newRow("floppy (16px,32px - 16 colors)") << "35floppy.ico"; |
|
1685 |
QTest::newRow("semitransparent") << "semitransparent.ico"; |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1686 |
QTest::newRow("slightlybrokenBMPHeader") << "kde_favicon.ico"; |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1687 |
QTest::newRow("sightlybrokenIconHeader") << "connect.ico"; |
0 | 1688 |
} |
1689 |
||
1690 |
void tst_QImageReader::pixelCompareWithBaseline() |
|
1691 |
{ |
|
1692 |
QFETCH(QString, fileName); |
|
1693 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1694 |
static int enteredCount = 0; // Used for better error diagnostics if something fails. We |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1695 |
static int loadFailCount = 0; // don't know if the reason load() fails is that the plugin |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1696 |
// does not exist or because of a bug in the plugin. But if at |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1697 |
// least one file succeeded we know that the plugin was built. |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1698 |
// The other failures are then real failures. |
0 | 1699 |
QImage icoImg; |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1700 |
const QString inputFileName(QString::fromAscii("images/%1").arg(fileName)); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1701 |
QFileInfo fi(inputFileName); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1702 |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1703 |
++enteredCount; |
0 | 1704 |
// might fail if the plugin does not exist, which is ok. |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1705 |
if (icoImg.load(inputFileName)) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1706 |
icoImg = icoImg.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1707 |
const QString baselineFileName(QString::fromAscii("baseline/%1.png").arg(fi.baseName())); |
0 | 1708 |
#if 0 |
1709 |
icoImg.save(baselineFileName); |
|
1710 |
#else |
|
1711 |
QImage baseImg; |
|
1712 |
QVERIFY(baseImg.load(baselineFileName)); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1713 |
baseImg = baseImg.convertToFormat(QImage::Format_ARGB32_Premultiplied); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1714 |
QCOMPARE(int(baseImg.format()), int(icoImg.format())); |
0 | 1715 |
QCOMPARE(baseImg, icoImg); |
1716 |
#endif |
|
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1717 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1718 |
++loadFailCount; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1719 |
if (enteredCount != loadFailCount) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1720 |
QFAIL("Plugin is built, but some did not load properly"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1721 |
} else { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1722 |
qWarning("loading failed, check if ico plugin is built"); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1723 |
} |
0 | 1724 |
} |
1725 |
} |
|
1726 |
||
1727 |
||
1728 |
void tst_QImageReader::testIgnoresFormatAndExtension_data() |
|
1729 |
{ |
|
1730 |
QTest::addColumn<QString>("name"); |
|
1731 |
QTest::addColumn<QString>("extension"); |
|
1732 |
QTest::addColumn<QString>("expected"); |
|
1733 |
||
1734 |
QTest::newRow("black.png") << "black" << "png" << "png"; |
|
1735 |
QTest::newRow("black.xpm") << "black" << "xpm" << "xpm"; |
|
1736 |
QTest::newRow("colorful.bmp") << "colorful" << "bmp" << "bmp"; |
|
1737 |
QTest::newRow("image.ppm") << "image" << "ppm" << "ppm"; |
|
1738 |
QTest::newRow("image.pbm") << "image" << "pbm" << "pbm"; |
|
1739 |
QTest::newRow("image.pgm") << "image" << "pgm" << "pgm"; |
|
1740 |
||
1741 |
#if defined QTEST_HAVE_GIF |
|
1742 |
QTest::newRow("bat1.gif") << "bat1" << "gif" << "gif"; |
|
1743 |
#endif |
|
1744 |
||
1745 |
#if defined QTEST_HAVE_JPEG |
|
1746 |
QTest::newRow("beavis.jpg") << "beavis" << "jpg" << "jpeg"; |
|
1747 |
#endif |
|
1748 |
||
1749 |
#if defined QTEST_HAVE_MNG |
|
1750 |
QTest::newRow("fire.mng") << "fire" << "mng" << "mng"; |
|
1751 |
#endif |
|
1752 |
||
1753 |
#if defined QTEST_HAVE_TIFF |
|
1754 |
QTest::newRow("image_100dpi.tif") << "image_100dpi" << "tif" << "tiff"; |
|
1755 |
#endif |
|
1756 |
} |
|
1757 |
||
1758 |
||
1759 |
void tst_QImageReader::testIgnoresFormatAndExtension() |
|
1760 |
{ |
|
1761 |
QFETCH(QString, name); |
|
1762 |
QFETCH(QString, extension); |
|
1763 |
QFETCH(QString, expected); |
|
1764 |
||
1765 |
QList<QByteArray> formats = QImageReader::supportedImageFormats(); |
|
1766 |
QString fileNameBase = "images/" + name + "."; |
|
1767 |
||
1768 |
foreach (const QByteArray &f, formats) { |
|
1769 |
if (f == extension) |
|
1770 |
continue; |
|
1771 |
QFile tmp(QDir::tempPath() + "/" + name + "_" + expected + "." + f); |
|
1772 |
||
1773 |
QFile::copy(fileNameBase + extension, QFileInfo(tmp).absoluteFilePath()); |
|
1774 |
||
1775 |
QString format; |
|
1776 |
QImage image; |
|
1777 |
{ |
|
1778 |
// image reader needs to be scoped for the remove() to work.. |
|
1779 |
QImageReader r; |
|
1780 |
r.setFileName(QFileInfo(tmp).absoluteFilePath()); |
|
1781 |
r.setDecideFormatFromContent(true); |
|
1782 |
format = r.format(); |
|
1783 |
r.read(&image); |
|
1784 |
} |
|
1785 |
||
1786 |
tmp.remove(); |
|
1787 |
||
1788 |
QVERIFY(!image.isNull()); |
|
1789 |
QCOMPARE(format, expected); |
|
1790 |
} |
|
1791 |
} |
|
1792 |
||
1793 |
QTEST_MAIN(tst_QImageReader) |
|
1794 |
#include "tst_qimagereader.moc" |