diff --git a/plugins/impex/exr/tests/kis_exr_test.cpp b/plugins/impex/exr/tests/kis_exr_test.cpp index f3e2f0fb55..3ad1e84221 100644 --- a/plugins/impex/exr/tests/kis_exr_test.cpp +++ b/plugins/impex/exr/tests/kis_exr_test.cpp @@ -1,94 +1,99 @@ /* * Copyright (C) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_exr_test.h" #include #include #include #include #include #include "filestest.h" #ifndef FILES_DATA_DIR #error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita" #endif void KisExrTest::testFiles() { TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", QStringList(), QString(), 5); } +void KisExrTest::testWriteonly() +{ + TestUtil::testWriteonly(QString(FILES_DATA_DIR)); +} + void KisExrTest::testRoundTrip() { QString inputFileName(TestUtil::fetchDataFileLazy("CandleGlass.exr")); KisDocument *doc1 = KisPart::instance()->createDocument(); doc1->setFileBatchMode(true); bool r = doc1->importDocument(QUrl::fromLocalFile(inputFileName)); QVERIFY(r); QVERIFY(doc1->errorMessage().isEmpty()); QVERIFY(doc1->image()); QTemporaryFile savedFile(QDir::tempPath() + QLatin1String("/krita_XXXXXX") + QLatin1String(".exr")); savedFile.setAutoRemove(true); savedFile.open(); QString savedFileName(savedFile.fileName()); QString typeName = KisMimeDatabase::mimeTypeForFile(savedFileName, false); QByteArray mimeType(typeName.toLatin1()); r = doc1->exportDocumentSync(QUrl::fromLocalFile(savedFileName), mimeType); QVERIFY(r); QVERIFY(QFileInfo(savedFileName).exists()); { KisDocument *doc2 = KisPart::instance()->createDocument(); doc2->setFileBatchMode(true); r = doc2->importDocument(QUrl::fromLocalFile(savedFileName)); QVERIFY(r); QVERIFY(doc2->errorMessage().isEmpty()); QVERIFY(doc2->image()); doc1->image()->root()->firstChild()->paintDevice()->convertToQImage(0).save("1.png"); doc2->image()->root()->firstChild()->paintDevice()->convertToQImage(0).save("2.png"); QVERIFY(TestUtil::comparePaintDevicesClever( doc1->image()->root()->firstChild()->paintDevice(), doc2->image()->root()->firstChild()->paintDevice(), 0.01 /* meaningless alpha */)); delete doc2; } savedFile.close(); delete doc1; } KISTEST_MAIN(KisExrTest) diff --git a/plugins/impex/exr/tests/kis_exr_test.h b/plugins/impex/exr/tests/kis_exr_test.h index 4dad62dfca..568b5fb61d 100644 --- a/plugins/impex/exr/tests/kis_exr_test.h +++ b/plugins/impex/exr/tests/kis_exr_test.h @@ -1,32 +1,33 @@ /* * Copyright (C) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_EXR_TEST_H_ #define _KIS_EXR_TEST_H_ #include class KisExrTest : public QObject { Q_OBJECT private Q_SLOTS: void testFiles(); + void testWriteonly(); void testRoundTrip(); }; #endif diff --git a/plugins/impex/jpeg/tests/data/writeonlyFile.txt b/plugins/impex/jpeg/tests/data/writeonlyFile.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/impex/jpeg/tests/kis_jpeg_test.cpp b/plugins/impex/jpeg/tests/kis_jpeg_test.cpp index 59da037645..d81631faa3 100644 --- a/plugins/impex/jpeg/tests/kis_jpeg_test.cpp +++ b/plugins/impex/jpeg/tests/kis_jpeg_test.cpp @@ -1,55 +1,64 @@ /* * Copyright (C) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_jpeg_test.h" #include #include #include "kisexiv2/kis_exiv2.h" #include "filestest.h" #include "jpeglib.h" #include #ifndef FILES_DATA_DIR #error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita" #endif #ifndef JPEG_LIB_VERSION #error "JPEG_LIB_VERSION not set. libjpeg should set it." #endif +const QString JpegMimetype = "image/jpeg"; + void KisJpegTest::testFiles() { KisExiv2::initialize(); /** * Different versions of JPEG library may produce a bit different * result, so just compare in a weak way, i.e, only the size for real */ const int fuzziness = 1; const int maxNumFailingPixels = 2592 * 1952; // All pixels can be different... + const bool showDebug = false; // No need to write down all pixels that are different since all of them can be. if (JPEG_LIB_VERSION == 80){ - TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", QStringList(), "_80", fuzziness, maxNumFailingPixels); + TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", QStringList(), "_80", fuzziness, maxNumFailingPixels, showDebug); }else { - TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", QStringList(), QString(), fuzziness, maxNumFailingPixels); + TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", QStringList(), QString(), fuzziness, maxNumFailingPixels, showDebug); } +} +void KisJpegTest::testWriteonly() +{ + TestUtil::testWriteonly(QString(FILES_DATA_DIR), JpegMimetype); } + + KISTEST_MAIN(KisJpegTest) diff --git a/plugins/impex/jpeg/tests/kis_jpeg_test.h b/plugins/impex/jpeg/tests/kis_jpeg_test.h index 5c19b0cda6..ef64b07c17 100644 --- a/plugins/impex/jpeg/tests/kis_jpeg_test.h +++ b/plugins/impex/jpeg/tests/kis_jpeg_test.h @@ -1,31 +1,32 @@ /* * Copyright (C) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_JPEG_TEST_H_ #define _KIS_JPEG_TEST_H_ #include class KisJpegTest : public QObject { Q_OBJECT private Q_SLOTS: void testFiles(); + void testWriteonly(); }; #endif diff --git a/plugins/impex/png/tests/data/writeonlyFile.txt b/plugins/impex/png/tests/data/writeonlyFile.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/impex/png/tests/kis_png_test.cpp b/plugins/impex/png/tests/kis_png_test.cpp index 17a8fb9d9a..01d4842110 100644 --- a/plugins/impex/png/tests/kis_png_test.cpp +++ b/plugins/impex/png/tests/kis_png_test.cpp @@ -1,155 +1,162 @@ /* * Copyright (C) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "kis_png_test.h" #include #include #include "filestest.h" #include #ifndef FILES_DATA_DIR #error "FILES_DATA_DIR not set. A directory with the data used for testing the importing of files in krita" #endif +const QString PngMimetype = "image/png"; + void KisPngTest::testFiles() { TestUtil::testFiles(QString(FILES_DATA_DIR) + "/sources", QStringList(), QString(), 1); } +void KisPngTest::testWriteonly() +{ + TestUtil::testWriteonly(QString(FILES_DATA_DIR), PngMimetype); +} + void roudTripHdrImage(const KoColorSpace *savingColorSpace) { qDebug() << "Test saving" << savingColorSpace->id() << savingColorSpace->profile()->name(); const KoColorSpace * scRGBF32 = KoColorSpaceRegistry::instance()->colorSpace( RGBAColorModelID.id(), Float32BitsColorDepthID.id(), KoColorSpaceRegistry::instance()->p709G10Profile()); KoColor fillColor(scRGBF32); float *pixelPtr = reinterpret_cast(fillColor.data()); pixelPtr[0] = 2.7; pixelPtr[1] = 1.6; pixelPtr[2] = 0.8; pixelPtr[3] = 0.9; { QScopedPointer doc(KisPart::instance()->createDocument()); KisImageSP image = new KisImage(0, 3, 3, scRGBF32, "png test"); KisPaintLayerSP paintLayer0 = new KisPaintLayer(image, "paint0", OPACITY_OPAQUE_U8); paintLayer0->paintDevice()->fill(image->bounds(), fillColor); image->addNode(paintLayer0, image->root()); // convert image color space before saving image->convertImageColorSpace(savingColorSpace, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags()); image->waitForDone(); KisImportExportManager manager(doc.data()); doc->setFileBatchMode(true); doc->setCurrentImage(image); KisPropertiesConfigurationSP exportConfiguration = new KisPropertiesConfiguration(); exportConfiguration->setProperty("saveAsHDR", true); exportConfiguration->setProperty("saveSRGBProfile", false); exportConfiguration->setProperty("forceSRGB", false); doc->exportDocumentSync(QUrl::fromLocalFile("test.png"), "image/png", exportConfiguration); } { QScopedPointer doc(KisPart::instance()->createDocument()); KisImportExportManager manager(doc.data()); doc->setFileBatchMode(true); KisImportExportErrorCode loadingStatus = manager.importDocument("test.png", QString()); QVERIFY(loadingStatus.isOk()); KisImageSP image = doc->image(); image->initialRefreshGraph(); KoColor resultColor; // qDebug() << ppVar(image->colorSpace()) << image->colorSpace()->profile()->name(); // image->projection()->pixel(1, 1, &resultColor); // qDebug() << ppVar(resultColor); image->convertImageColorSpace(scRGBF32, KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::internalConversionFlags()); image->waitForDone(); image->projection()->pixel(1, 1, &resultColor); // qDebug() << ppVar(resultColor); const float tolerance = savingColorSpace->colorDepthId() == Integer8BitsColorDepthID ? 0.02 : 0.01; bool resultIsValid = true; float *resultPtr = reinterpret_cast(resultColor.data()); for (int i = 0; i < 4; i++) { resultIsValid &= qAbs(resultPtr[i] - pixelPtr[i]) < tolerance; } if (!resultIsValid) { qDebug() << ppVar(fillColor) << ppVar(resultColor); } QVERIFY(resultIsValid); } } void KisPngTest::testSaveHDR() { QVector colorDepthIds; colorDepthIds << Float16BitsColorDepthID; colorDepthIds << Float32BitsColorDepthID; QVector profiles; profiles << KoColorSpaceRegistry::instance()->p709G10Profile(); profiles << KoColorSpaceRegistry::instance()->p2020G10Profile(); profiles << KoColorSpaceRegistry::instance()->p2020PQProfile(); Q_FOREACH(const KoID &depth, colorDepthIds) { Q_FOREACH(const KoColorProfile *profile, profiles) { roudTripHdrImage( KoColorSpaceRegistry::instance()->colorSpace( RGBAColorModelID.id(), depth.id(), profile)); } } roudTripHdrImage( KoColorSpaceRegistry::instance()->colorSpace( RGBAColorModelID.id(), Integer16BitsColorDepthID.id(), KoColorSpaceRegistry::instance()->p2020PQProfile())); roudTripHdrImage( KoColorSpaceRegistry::instance()->colorSpace( RGBAColorModelID.id(), Integer8BitsColorDepthID.id(), KoColorSpaceRegistry::instance()->p2020PQProfile())); } KISTEST_MAIN(KisPngTest) diff --git a/plugins/impex/png/tests/kis_png_test.h b/plugins/impex/png/tests/kis_png_test.h index e312f85756..0c2374b4c6 100644 --- a/plugins/impex/png/tests/kis_png_test.h +++ b/plugins/impex/png/tests/kis_png_test.h @@ -1,32 +1,33 @@ /* * Copyright (C) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef _KIS_PNG_TEST_H_ #define _KIS_PNG_TEST_H_ #include class KisPngTest : public QObject { Q_OBJECT private Q_SLOTS: void testFiles(); + void testWriteonly(); void testSaveHDR(); }; #endif diff --git a/sdk/tests/filestest.h b/sdk/tests/filestest.h index d491aa7b1d..c15ff85496 100644 --- a/sdk/tests/filestest.h +++ b/sdk/tests/filestest.h @@ -1,118 +1,170 @@ /* * Copyright (C) 2007 Cyrille Berger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef FILESTEST #define FILESTEST #include "testutil.h" #include #include #include #include #include #include #include #include #include #include #include #include #include +#include +#include +#include namespace TestUtil { -void testFiles(const QString& _dirname, const QStringList& exclusions, const QString &resultSuffix = QString(), int fuzzy = 0, int maxNumFailingPixels = 0) +void testFiles(const QString& _dirname, const QStringList& exclusions, const QString &resultSuffix = QString(), int fuzzy = 0, int maxNumFailingPixels = 0, bool showDebug = true) { QDir dirSources(_dirname); QStringList failuresFileInfo; QStringList failuresDocImage; QStringList failuresCompare; Q_FOREACH (QFileInfo sourceFileInfo, dirSources.entryInfoList()) { qDebug() << sourceFileInfo.fileName(); if (exclusions.indexOf(sourceFileInfo.fileName()) > -1) { continue; } if (!sourceFileInfo.isHidden() && !sourceFileInfo.isDir()) { QFileInfo resultFileInfo(QString(FILES_DATA_DIR) + "/results/" + sourceFileInfo.fileName() + resultSuffix + ".png"); if (!resultFileInfo.exists()) { failuresFileInfo << resultFileInfo.fileName(); continue; } KisDocument *doc = qobject_cast(KisPart::instance()->createDocument()); KisImportExportManager manager(doc); doc->setFileBatchMode(true); KisImportExportErrorCode status = manager.importDocument(sourceFileInfo.absoluteFilePath(), QString()); Q_UNUSED(status); if (!doc->image()) { failuresDocImage << sourceFileInfo.fileName(); continue; } QString id = doc->image()->colorSpace()->id(); if (id != "GRAYA" && id != "GRAYAU16" && id != "RGBA" && id != "RGBA16") { dbgKrita << "Images need conversion"; doc->image()->convertImageColorSpace(KoColorSpaceRegistry::instance()->rgb8(), KoColorConversionTransformation::IntentAbsoluteColorimetric, KoColorConversionTransformation::NoOptimization); } qApp->processEvents(); doc->image()->waitForDone(); QImage sourceImage = doc->image()->projection()->convertToQImage(0, doc->image()->bounds()); QImage resultImage(resultFileInfo.absoluteFilePath()); resultImage = resultImage.convertToFormat(QImage::Format_ARGB32); sourceImage = sourceImage.convertToFormat(QImage::Format_ARGB32); QPoint pt; - if (!TestUtil::compareQImages(pt, resultImage, sourceImage, fuzzy, fuzzy, maxNumFailingPixels)) { + if (!TestUtil::compareQImages(pt, resultImage, sourceImage, fuzzy, fuzzy, maxNumFailingPixels, showDebug)) { failuresCompare << sourceFileInfo.fileName() + ": " + QString("Pixel (%1,%2) has different values").arg(pt.x()).arg(pt.y()).toLatin1(); sourceImage.save(sourceFileInfo.fileName() + ".png"); resultImage.save(resultFileInfo.fileName() + ".expected.png"); continue; } delete doc; } } if (failuresCompare.isEmpty() && failuresDocImage.isEmpty() && failuresFileInfo.isEmpty()) { return; } qWarning() << "Comparison failures: " << failuresCompare; qWarning() << "No image failures: " << failuresDocImage; qWarning() << "No comparison image: " << failuresFileInfo; QFAIL("Failed testing files"); } + +void testWriteonly(const QString& _dirname, QString mimetype = "") +{ + QString writeonlyFilename = _dirname + "writeonlyFile.txt"; + + QFileInfo sourceFileInfo(writeonlyFilename); + QFileDevice::Permissions permissionsBefore; + if (sourceFileInfo.exists()) { + permissionsBefore = QFile::permissions(sourceFileInfo.absoluteFilePath()); + ENTER_FUNCTION() << permissionsBefore; + } else { + QFile file(writeonlyFilename); + file.open(QIODevice::WriteOnly); + permissionsBefore = file.permissions(); + file.close(); + } + QFileDevice::Permissions permissionsNow = permissionsBefore & + (~QFileDevice::ReadUser & ~QFileDevice::ReadOwner + & ~QFileDevice::ReadGroup & ~QFileDevice::ReadOther); + QFile::setPermissions(sourceFileInfo.absoluteFilePath(), permissionsNow); + + + KisDocument *doc = qobject_cast(KisPart::instance()->createDocument()); + + KisImportExportManager manager(doc); + doc->setFileBatchMode(true); + + KisImportExportErrorCode status = manager.importDocument(sourceFileInfo.absoluteFilePath(), mimetype); + qDebug() << "import result = " << status; + + QVERIFY(!status.isOk()); + + + qApp->processEvents(); + + if (doc->image()) { + doc->image()->waitForDone(); + } + + delete doc; + + QFileDevice::Permissions permissionsAfter = permissionsNow | + (QFileDevice::ReadUser | QFileDevice::ReadOwner + | QFileDevice::ReadGroup | QFileDevice::ReadOther); + QFile::setPermissions(sourceFileInfo.absoluteFilePath(), permissionsAfter); +} + + + } #endif diff --git a/sdk/tests/qimage_test_util.h b/sdk/tests/qimage_test_util.h index e1d0a294ce..fffbb596fc 100644 --- a/sdk/tests/qimage_test_util.h +++ b/sdk/tests/qimage_test_util.h @@ -1,245 +1,246 @@ /* * Copyright (c) 2016 Dmitry Kazakov * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef QIMAGE_TEST_UTIL_H #define QIMAGE_TEST_UTIL_H #ifdef FILES_OUTPUT_DIR #include #include namespace TestUtil { inline QString fetchExternalDataFileName(const QString relativeFileName) { static QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); static QString unittestsDataDirPath = "KRITA_UNITTESTS_DATA_DIR"; QString path; if (!env.contains(unittestsDataDirPath)) { warnKrita << "Environment variable" << unittestsDataDirPath << "is not set"; return QString(); } else { path = env.value(unittestsDataDirPath, ""); } QString filename = path + QDir::separator() + relativeFileName; return filename; } inline QString fetchDataFileLazy(const QString relativeFileName, bool externalTest = false) { if (externalTest) { return fetchExternalDataFileName(relativeFileName); } else { QString filename = QString(FILES_DATA_DIR) + QDir::separator() + relativeFileName; if (QFileInfo(filename).exists()) { return filename; } filename = QString(FILES_DEFAULT_DATA_DIR) + QDir::separator() + relativeFileName; if (QFileInfo(filename).exists()) { return filename; } } return QString(); } // quint8 arguments are automatically converted into int inline bool compareChannels(int ch1, int ch2, int fuzzy) { return qAbs(ch1 - ch2) <= fuzzy; } -inline bool compareQImages(QPoint & pt, const QImage & image1, const QImage & image2, int fuzzy = 0, int fuzzyAlpha = 0, int maxNumFailingPixels = 0) +inline bool compareQImages(QPoint & pt, const QImage & image1, const QImage & image2, int fuzzy = 0, int fuzzyAlpha = 0, int maxNumFailingPixels = 0, bool showDebug = true) { // QTime t; // t.start(); const int w1 = image1.width(); const int h1 = image1.height(); const int w2 = image2.width(); const int h2 = image2.height(); const int bytesPerLine = image1.bytesPerLine(); if (w1 != w2 || h1 != h2) { pt.setX(-1); pt.setY(-1); qDebug() << "Images have different sizes" << image1.size() << image2.size(); return false; } int numFailingPixels = 0; for (int y = 0; y < h1; ++y) { const QRgb * const firstLine = reinterpret_cast(image2.scanLine(y)); const QRgb * const secondLine = reinterpret_cast(image1.scanLine(y)); if (memcmp(firstLine, secondLine, bytesPerLine) != 0) { for (int x = 0; x < w1; ++x) { const QRgb a = firstLine[x]; const QRgb b = secondLine[x]; const bool same = compareChannels(qRed(a), qRed(b), fuzzy) && compareChannels(qGreen(a), qGreen(b), fuzzy) && compareChannels(qBlue(a), qBlue(b), fuzzy); const bool sameAlpha = compareChannels(qAlpha(a), qAlpha(b), fuzzyAlpha); const bool bothTransparent = sameAlpha && qAlpha(a)==0; if (!bothTransparent && (!same || !sameAlpha)) { pt.setX(x); pt.setY(y); numFailingPixels++; - qDebug() << " Different at" << pt - << "source" << qRed(a) << qGreen(a) << qBlue(a) << qAlpha(a) - << "dest" << qRed(b) << qGreen(b) << qBlue(b) << qAlpha(b) - << "fuzzy" << fuzzy - << "fuzzyAlpha" << fuzzyAlpha - << "(" << numFailingPixels << "of" << maxNumFailingPixels << "allowed )"; - + if (showDebug) { + qDebug() << " Different at" << pt + << "source" << qRed(a) << qGreen(a) << qBlue(a) << qAlpha(a) + << "dest" << qRed(b) << qGreen(b) << qBlue(b) << qAlpha(b) + << "fuzzy" << fuzzy + << "fuzzyAlpha" << fuzzyAlpha + << "(" << numFailingPixels << "of" << maxNumFailingPixels << "allowed )"; + } if (numFailingPixels > maxNumFailingPixels) { return false; } } } } } // qDebug() << "compareQImages time elapsed:" << t.elapsed(); // qDebug() << "Images are identical"; return true; } inline bool checkQImageImpl(bool externalTest, const QImage &srcImage, const QString &testName, const QString &prefix, const QString &name, int fuzzy, int fuzzyAlpha, int maxNumFailingPixels) { QImage image = srcImage.convertToFormat(QImage::Format_ARGB32); if (fuzzyAlpha == -1) { fuzzyAlpha = fuzzy; } QString filename(prefix + "_" + name + ".png"); QString dumpName(prefix + "_" + name + "_expected.png"); const QString standardPath = testName + QDir::separator() + prefix + QDir::separator() + filename; QString fullPath = fetchDataFileLazy(standardPath, externalTest); if (fullPath.isEmpty() || !QFileInfo(fullPath).exists()) { // Try without the testname subdirectory fullPath = fetchDataFileLazy(prefix + QDir::separator() + filename, externalTest); } if (fullPath.isEmpty() || !QFileInfo(fullPath).exists()) { // Try without the prefix subdirectory fullPath = fetchDataFileLazy(testName + QDir::separator() + filename, externalTest); } if (!QFileInfo(fullPath).exists()) { fullPath = ""; } bool canSkipExternalTest = fullPath.isEmpty() && externalTest; QImage ref(fullPath); bool valid = true; QPoint t; if(!compareQImages(t, image, ref, fuzzy, fuzzyAlpha, maxNumFailingPixels)) { bool saveStandardResults = true; if (canSkipExternalTest) { static QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); static QString writeUnittestsVar = "KRITA_WRITE_UNITTESTS"; int writeUnittests = env.value(writeUnittestsVar, "0").toInt(); if (writeUnittests) { QString path = fetchExternalDataFileName(standardPath); QFileInfo pathInfo(path); QDir directory; directory.mkpath(pathInfo.path()); qDebug() << "--- Saving reference image:" << name << path; image.save(path); saveStandardResults = false; } else { qDebug() << "--- External image not found. Skipping..." << name; } } else { qDebug() << "--- Wrong image:" << name; valid = false; } if (saveStandardResults) { image.save(QString(FILES_OUTPUT_DIR) + QDir::separator() + filename); ref.save(QString(FILES_OUTPUT_DIR) + QDir::separator() + dumpName); } } return valid; } inline bool checkQImage(const QImage &image, const QString &testName, const QString &prefix, const QString &name, int fuzzy = 0, int fuzzyAlpha = -1, int maxNumFailingPixels = 0) { return checkQImageImpl(false, image, testName, prefix, name, fuzzy, fuzzyAlpha, maxNumFailingPixels); } inline bool checkQImageExternal(const QImage &image, const QString &testName, const QString &prefix, const QString &name, int fuzzy = 0, int fuzzyAlpha = -1, int maxNumFailingPixels = 0) { return checkQImageImpl(true, image, testName, prefix, name, fuzzy, fuzzyAlpha, maxNumFailingPixels); } } #endif // FILES_OUTPUT_DIR #endif // QIMAGE_TEST_UTIL_H