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