diff options
author | Gunnar Sletta <gunnar@trolltech.com> | 2009-09-15 07:48:43 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar@trolltech.com> | 2009-09-15 08:39:16 (GMT) |
commit | b94d6354cb0b24a92e674fc994919394c7549b5a (patch) | |
tree | 91c7b685b426accbc6e0657ab5e1e67f820ceaa4 /tests/auto/qimagereader | |
parent | 62fe4f11e49025156f9f5de2ffcbb9ad65198bc4 (diff) | |
download | Qt-b94d6354cb0b24a92e674fc994919394c7549b5a.zip Qt-b94d6354cb0b24a92e674fc994919394c7549b5a.tar.gz Qt-b94d6354cb0b24a92e674fc994919394c7549b5a.tar.bz2 |
Added support in qimagereader to base plugin selection on stream content
Reviewed-by: Trond
Diffstat (limited to 'tests/auto/qimagereader')
-rw-r--r-- | tests/auto/qimagereader/tst_qimagereader.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 8630021..cab8fda 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -167,6 +167,10 @@ private slots: void task255627_setNullScaledSize_data(); void task255627_setNullScaledSize(); + + void testIgnoresFormatAndExtension_data(); + void testIgnoresFormatAndExtension(); + }; static const QLatin1String prefix(SRCDIR "/images/"); @@ -225,6 +229,7 @@ void tst_QImageReader::readImage_data() QTest::newRow("PPM: runners") << QString("runners.ppm") << true << QByteArray("ppm"); QTest::newRow("PPM: test") << QString("test.ppm") << true << QByteArray("ppm"); QTest::newRow("XBM: gnus") << QString("gnus.xbm") << true << QByteArray("xbm"); + #if defined QTEST_HAVE_JPEG QTest::newRow("JPEG: beavis") << QString("beavis.jpg") << true << QByteArray("jpeg"); #endif @@ -1495,5 +1500,71 @@ void tst_QImageReader::pixelCompareWithBaseline() } } + +void tst_QImageReader::testIgnoresFormatAndExtension_data() +{ + QTest::addColumn<QString>("name"); + QTest::addColumn<QString>("extension"); + QTest::addColumn<QString>("expected"); + + QTest::newRow("black.png") << "black" << "png" << "png"; + QTest::newRow("black.xpm") << "black" << "xpm" << "xpm"; + QTest::newRow("colorful.bmp") << "colorful" << "bmp" << "bmp"; + QTest::newRow("image.ppm") << "image" << "ppm" << "ppm"; + QTest::newRow("image.pbm") << "image" << "pbm" << "pbm"; + QTest::newRow("image.pgm") << "image" << "pgm" << "pgm"; + +#if defined QTEST_HAVE_GIF + QTest::newRow("bat1.gif") << "bat1" << "gif" << "gif"; +#endif + +#if defined QTEST_HAVE_JPEG + QTest::newRow("beavis.jpg") << "beavis" << "jpg" << "jpeg"; +#endif + +#if defined QTEST_HAVE_MNG + QTest::newRow("fire.mng") << "fire" << "mng" << "mng"; +#endif + +#if defined QTEST_HAVE_TIFF + QTest::newRow("image_100dpi.tif") << "image_100dpi" << "tif" << "tiff"; +#endif +} + + +void tst_QImageReader::testIgnoresFormatAndExtension() +{ + QFETCH(QString, name); + QFETCH(QString, extension); + QFETCH(QString, expected); + + QList<QByteArray> formats = QImageReader::supportedImageFormats(); + QString fileNameBase = "images/" + name + "."; + + foreach (const QByteArray &f, formats) { + if (f == extension) + continue; + QFile tmp(QDir::tempPath() + "/" + name + "_" + expected + "." + f); + + QFile::copy(fileNameBase + extension, QFileInfo(tmp).absoluteFilePath()); + + QString format; + QImage image; + { + // image reader needs to be scoped for the remove() to work.. + QImageReader r; + r.setFileName(QFileInfo(tmp).absoluteFilePath()); + r.setDecideFormatFromContent(true); + format = r.format(); + r.read(&image); + } + + tmp.remove(); + + QVERIFY(!image.isNull()); + QCOMPARE(format, expected); + } +} + QTEST_MAIN(tst_QImageReader) #include "tst_qimagereader.moc" |