diff options
author | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-11-19 14:24:08 (GMT) |
---|---|---|
committer | Gunnar Sletta <gunnar.sletta@nokia.com> | 2010-11-19 14:24:08 (GMT) |
commit | e50e811461b54e07184af547f62aa44b3c5bb681 (patch) | |
tree | 45541bc05471d6c49305afeafa13f69031ccdecd /tests/auto/qimagereader/tst_qimagereader.cpp | |
parent | 05b65c2f9df1c2c56c72f313401a6adb422d381b (diff) | |
parent | b115770cc3bba68740a6848c7ccaed932399aca9 (diff) | |
download | Qt-e50e811461b54e07184af547f62aa44b3c5bb681.zip Qt-e50e811461b54e07184af547f62aa44b3c5bb681.tar.gz Qt-e50e811461b54e07184af547f62aa44b3c5bb681.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt
Conflicts:
src/gui/text/qfontengine_mac.mm
src/gui/text/qfontengine_p.h
Diffstat (limited to 'tests/auto/qimagereader/tst_qimagereader.cpp')
-rw-r--r-- | tests/auto/qimagereader/tst_qimagereader.cpp | 98 |
1 files changed, 83 insertions, 15 deletions
diff --git a/tests/auto/qimagereader/tst_qimagereader.cpp b/tests/auto/qimagereader/tst_qimagereader.cpp index 4b4bdd6..4aff8d5 100644 --- a/tests/auto/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/qimagereader/tst_qimagereader.cpp @@ -55,6 +55,8 @@ #include <QTcpServer> #include <QTimer> +#include "../platformquirks.h" + #if defined(Q_OS_SYMBIAN) # define SRCDIR "." #endif @@ -180,6 +182,9 @@ private slots: void saveFormat_data(); void saveFormat(); + + void preserveTexts_data(); + void preserveTexts(); }; static const QLatin1String prefix(SRCDIR "/images/"); @@ -315,23 +320,27 @@ void tst_QImageReader::jpegRgbCmyk() QImage image1(prefix + QLatin1String("YCbCr_cmyk.jpg")); QImage image2(prefix + QLatin1String("YCbCr_cmyk.png")); - // first, do some obvious tests - QCOMPARE(image1.height(), image2.height()); - QCOMPARE(image1.width(), image2.width()); - QCOMPARE(image1.format(), image2.format()); - QCOMPARE(image1.format(), QImage::Format_RGB32); - - // compare all the pixels with a slack of 3. This ignores rounding errors in libjpeg/libpng - for (int h = 0; h < image1.height(); ++h) { - const uchar *s1 = image1.constScanLine(h); - const uchar *s2 = image2.constScanLine(h); - for (int w = 0; w < image1.width() * 4; ++w) { - if (*s1 != *s2) { - QVERIFY2(qAbs(*s1 - *s2) <= 3, qPrintable(QString("images differ in line %1, col %2 (image1: %3, image2: %4)").arg(h).arg(w).arg(*s1, 0, 16).arg(*s2, 0, 16))); + if (PlatformQuirks::isImageLoaderImprecise()) { + // first, do some obvious tests + QCOMPARE(image1.height(), image2.height()); + QCOMPARE(image1.width(), image2.width()); + QCOMPARE(image1.format(), image2.format()); + QCOMPARE(image1.format(), QImage::Format_RGB32); + + // compare all the pixels with a slack of 3. This ignores rounding errors in libjpeg/libpng + for (int h = 0; h < image1.height(); ++h) { + const uchar *s1 = image1.constScanLine(h); + const uchar *s2 = image2.constScanLine(h); + for (int w = 0; w < image1.width() * 4; ++w) { + if (*s1 != *s2) { + QVERIFY2(qAbs(*s1 - *s2) <= 3, qPrintable(QString("images differ in line %1, col %2 (image1: %3, image2: %4)").arg(h).arg(w).arg(*s1, 0, 16).arg(*s2, 0, 16))); + } + s1++; + s2++; } - s1++; - s2++; } + } else { + QCOMPARE(image1, image2); } } @@ -1948,5 +1957,64 @@ void tst_QImageReader::saveFormat() } +void tst_QImageReader::preserveTexts_data() +{ + QTest::addColumn<QString>("text"); + + QTest::newRow("Simple") << "simpletext"; + QTest::newRow("Whitespace") << " A text with whitespace "; + QTest::newRow("Newline") << "A text\nwith newlines\n"; + QTest::newRow("Double newlines") << "A text\n\nwith double newlines\n\n"; + QTest::newRow("Long") << QString("A rather long text, at least after many repetitions. ").repeated(100); + QString latin1set; + int c; + for(c = 0x20; c <= 0x7e; c++) + latin1set.append(QLatin1Char(c)); + for(c = 0xa0; c <= 0xff; c++) + latin1set.append(QLatin1Char(c)); + QTest::newRow("All Latin1 chars") << latin1set; + +#if 0 + // Depends on iTXt support in libpng + QTest::newRow("Multibyte string") << QString::fromUtf8("\341\233\222\341\233\226\341\232\251\341\232\271\341\232\242\341\233\232\341\232\240"); +#endif +} + + +void tst_QImageReader::preserveTexts() +{ + QFETCH(QString, text); + QString key("testkey"); + QString key2("testkey2"); + QString text2("Some other text."); + QString key3("testkey3"); + QString text3("Some more other text."); + + QImage img(":/images/kollada.png"); + img.setText(key, text); + img.setText(key2, text2); + QBuffer buf; + buf.open(QIODevice::WriteOnly); + QVERIFY(img.save(&buf, "png")); + buf.close(); + QImage stored = QImage::fromData(buf.buffer(), "png"); + QCOMPARE(stored.text(key), text); + QCOMPARE(stored.text(key2), text2); + + QImage img2(":/images/kollada.png"); + img2.setText(key3, text3); + QBuffer buf2; + QImageWriter w(&buf2, "png"); + w.setText(key, text); + w.setText(key2, text2); + QVERIFY(w.write(img2)); + buf2.close(); + QImageReader r(&buf2, "png"); + QCOMPARE(r.text(key), text.simplified()); + QCOMPARE(r.text(key2), text2.simplified()); + QCOMPARE(r.text(key3), text3.simplified()); +} + + QTEST_MAIN(tst_QImageReader) #include "tst_qimagereader.moc" |