diff options
Diffstat (limited to 'tests/auto/qimagewriter')
-rw-r--r-- | tests/auto/qimagewriter/tst_qimagewriter.cpp | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/tests/auto/qimagewriter/tst_qimagewriter.cpp b/tests/auto/qimagewriter/tst_qimagewriter.cpp index 17f1bc7dc0..0ebf06b459 100644 --- a/tests/auto/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/qimagewriter/tst_qimagewriter.cpp @@ -59,6 +59,7 @@ Q_DECLARE_METATYPE(QStringMap) Q_DECLARE_METATYPE(QIntList) Q_DECLARE_METATYPE(QImageWriter::ImageWriterError) Q_DECLARE_METATYPE(QIODevice *) +Q_DECLARE_METATYPE(QImage::Format) //TESTED_FILES= @@ -82,6 +83,9 @@ private slots: void writeImage2(); void supportedFormats(); + void readWriteNonDestructive_data(); + void readWriteNonDestructive(); + #if defined QTEST_HAVE_TIFF void largeTiff(); #endif @@ -97,6 +101,9 @@ private slots: void saveWithNoFormat_data(); void saveWithNoFormat(); + void resolution_data(); + void resolution(); + void saveToTemporaryFile(); }; @@ -162,7 +169,7 @@ tst_QImageWriter::tst_QImageWriter() tst_QImageWriter::~tst_QImageWriter() { - QDir dir("images"); + QDir dir(prefix); QStringList filesToDelete = dir.entryList(QStringList() << "gen-*" , QDir::NoDotAndDotDot | QDir::Files); foreach( QString file, filesToDelete) { QFile::remove(dir.absoluteFilePath(file)); @@ -373,6 +380,28 @@ void tst_QImageWriter::supportedFormats() QCOMPARE(formatSet.size(), formats.size()); } +void tst_QImageWriter::readWriteNonDestructive_data() +{ + QTest::addColumn<QImage::Format>("format"); + QTest::addColumn<QImage::Format>("expectedFormat"); + QTest::newRow("tiff mono") << QImage::Format_Mono << QImage::Format_Mono; + QTest::newRow("tiff indexed") << QImage::Format_Indexed8 << QImage::Format_Indexed8; + QTest::newRow("tiff rgb32") << QImage::Format_ARGB32 << QImage::Format_ARGB32; +} + +void tst_QImageWriter::readWriteNonDestructive() +{ + QFETCH(QImage::Format, format); + QFETCH(QImage::Format, expectedFormat); + QImage image = QImage(prefix + "colorful.bmp").convertToFormat(format); + QVERIFY(image.save(prefix + "gen-readWriteNonDestructive.tiff")); + + QImage image2 = QImage(prefix + "gen-readWriteNonDestructive.tiff"); + QImage::Format readFormat = image2.format(); + QCOMPARE(readFormat, expectedFormat); + QCOMPARE(image, image2); +} + void tst_QImageWriter::setDescription_data() { QTest::addColumn<QString>("fileName"); @@ -442,13 +471,13 @@ void tst_QImageWriter::supportsOption_data() QTest::addColumn<QString>("fileName"); QTest::addColumn<QIntList>("options"); - QTest::newRow("png") << QString(prefix + "gen-black.png") + QTest::newRow("png") << QString("gen-black.png") << (QIntList() << QImageIOHandler::Gamma << QImageIOHandler::Description << QImageIOHandler::Quality << QImageIOHandler::Size); #if defined QTEST_HAVE_TIFF - QTest::newRow("tiff") << QString("images/gen-black.tiff") + QTest::newRow("tiff") << QString("gen-black.tiff") << (QIntList() << QImageIOHandler::Size << QImageIOHandler::CompressionRatio); #endif @@ -475,7 +504,7 @@ void tst_QImageWriter::supportsOption() << QImageIOHandler::Animation << QImageIOHandler::BackgroundColor; - QImageWriter writer(fileName); + QImageWriter writer(prefix + fileName); for (int i = 0; i < options.size(); ++i) { QVERIFY(writer.supportsOption(QImageIOHandler::ImageOption(options.at(i)))); allOptions.remove(QImageIOHandler::ImageOption(options.at(i))); @@ -530,6 +559,39 @@ void tst_QImageWriter::saveWithNoFormat() QVERIFY2(!outImage.isNull(), qPrintable(reader.errorString())); } +void tst_QImageWriter::resolution_data() +{ + QTest::addColumn<QString>("filename"); + QTest::addColumn<int>("expectedDotsPerMeterX"); + QTest::addColumn<int>("expectedDotsPerMeterY"); +#if defined QTEST_HAVE_TIFF + QTest::newRow("TIFF: 100 dpi") << ("image_100dpi.tif") << qRound(100 * (100 / 2.54)) << qRound(100 * (100 / 2.54)); + QTest::newRow("TIFF: 50 dpi") << ("image_50dpi.tif") << qRound(50 * (100 / 2.54)) << qRound(50 * (100 / 2.54)); + QTest::newRow("TIFF: 300 dot per meter") << ("image_300dpm.tif") << 300 << 300; +#endif +} + +void tst_QImageWriter::resolution() +{ + QFETCH(QString, filename); + QFETCH(int, expectedDotsPerMeterX); + QFETCH(int, expectedDotsPerMeterY); + + QImage image(prefix + QLatin1String("colorful.bmp")); + image.setDotsPerMeterX(expectedDotsPerMeterX); + image.setDotsPerMeterY(expectedDotsPerMeterY); + const QString generatedFilepath = prefix + "gen-" + filename; + { + QImageWriter writer(generatedFilepath); + QVERIFY(writer.write(image)); + } + QImageReader reader(generatedFilepath); + const QImage generatedImage = reader.read(); + + QCOMPARE(expectedDotsPerMeterX, generatedImage.dotsPerMeterX()); + QCOMPARE(expectedDotsPerMeterY, generatedImage.dotsPerMeterY()); +} + void tst_QImageWriter::saveToTemporaryFile() { QImage image(prefix + "kollada.png"); |