summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/qimagereader/tst_qimagereader.cpp71
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"