tests/auto/qimagewriter/tst_qimagewriter.cpp
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
   389 
   389 
   390 void tst_QImageWriter::readWriteNonDestructive_data()
   390 void tst_QImageWriter::readWriteNonDestructive_data()
   391 {
   391 {
   392     QTest::addColumn<QImage::Format>("format");
   392     QTest::addColumn<QImage::Format>("format");
   393     QTest::addColumn<QImage::Format>("expectedFormat");
   393     QTest::addColumn<QImage::Format>("expectedFormat");
   394     QTest::newRow("tiff mono") << QImage::Format_Mono << QImage::Format_Mono;
   394     QTest::addColumn<bool>("grayscale");
   395     QTest::newRow("tiff indexed") << QImage::Format_Indexed8 << QImage::Format_Indexed8;
   395     QTest::newRow("tiff mono") << QImage::Format_Mono << QImage::Format_Mono << false;
   396     QTest::newRow("tiff rgb32") << QImage::Format_ARGB32 << QImage::Format_ARGB32;
   396     QTest::newRow("tiff indexed") << QImage::Format_Indexed8 << QImage::Format_Indexed8 << false;
       
   397     QTest::newRow("tiff rgb32") << QImage::Format_ARGB32 << QImage::Format_ARGB32 << false;
       
   398     QTest::newRow("tiff grayscale") << QImage::Format_Indexed8 << QImage::Format_Indexed8 << true;
   397 }
   399 }
   398 
   400 
   399 void tst_QImageWriter::readWriteNonDestructive()
   401 void tst_QImageWriter::readWriteNonDestructive()
   400 {
   402 {
   401     QFETCH(QImage::Format, format);
   403     QFETCH(QImage::Format, format);
   402     QFETCH(QImage::Format, expectedFormat);
   404     QFETCH(QImage::Format, expectedFormat);
       
   405     QFETCH(bool, grayscale);
   403     QImage image = QImage(prefix + "colorful.bmp").convertToFormat(format);
   406     QImage image = QImage(prefix + "colorful.bmp").convertToFormat(format);
       
   407 
       
   408     if (grayscale) {
       
   409         QVector<QRgb> colors;
       
   410         for (int i = 0; i < 256; ++i)
       
   411             colors << qRgb(i, i, i);
       
   412         image.setColorTable(colors);
       
   413     }
       
   414 
   404     QVERIFY(image.save(prefix + "gen-readWriteNonDestructive.tiff"));
   415     QVERIFY(image.save(prefix + "gen-readWriteNonDestructive.tiff"));
   405 
   416 
   406     QImage image2 = QImage(prefix + "gen-readWriteNonDestructive.tiff");
   417     QImage image2 = QImage(prefix + "gen-readWriteNonDestructive.tiff");
   407     QImage::Format readFormat = image2.format();
   418     QImage::Format readFormat = image2.format();
   408     QCOMPARE(readFormat, expectedFormat);
   419     QCOMPARE(readFormat, expectedFormat);
   544     QFETCH(QString, fileName);
   555     QFETCH(QString, fileName);
   545     QFETCH(QByteArray, format);
   556     QFETCH(QByteArray, format);
   546     QFETCH(QImageWriter::ImageWriterError, error);
   557     QFETCH(QImageWriter::ImageWriterError, error);
   547 
   558 
   548     QImage niceImage(64, 64, QImage::Format_ARGB32);
   559     QImage niceImage(64, 64, QImage::Format_ARGB32);
   549     qMemSet(niceImage.bits(), 0, niceImage.numBytes());
   560     qMemSet(niceImage.bits(), 0, niceImage.byteCount());
   550 
   561 
   551     QImageWriter writer(fileName /* , 0 - no format! */);
   562     QImageWriter writer(fileName /* , 0 - no format! */);
   552     if (error != 0) {
   563     if (error != 0) {
   553         QVERIFY(!writer.write(niceImage));
   564         QVERIFY(!writer.write(niceImage));
   554         QCOMPARE(writer.error(), error);
   565         QCOMPARE(writer.error(), error);