diff --git a/plugins/impex/sai/tests/data/sai_test_layer_offset.png b/plugins/impex/sai/tests/data/sai_test_layer_offset.png new file mode 100644 index 0000000000..e620885eb5 Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_layer_offset.png differ diff --git a/plugins/impex/sai/tests/data/sai_test_layer_offset.sai b/plugins/impex/sai/tests/data/sai_test_layer_offset.sai new file mode 100644 index 0000000000..ddfadaca0d Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_layer_offset.sai differ diff --git a/plugins/impex/sai/tests/kis_sai_test.cpp b/plugins/impex/sai/tests/kis_sai_test.cpp index 38aaa79dbe..b81fa5916c 100644 --- a/plugins/impex/sai/tests/kis_sai_test.cpp +++ b/plugins/impex/sai/tests/kis_sai_test.cpp @@ -1,155 +1,174 @@ /* * Copyright (C) 2019 Wolthera van Hövell tot Westerflier * * 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 #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 #include "kis_sai_test.h" const QString SaiMimeType = "application/x-painttool-sai"; void KisSaiTest::testOpening() { QFileInfo sourceFileInfo(QString(FILES_DATA_DIR) + QDir::separator() + "sai_rgba_test.sai"); QScopedPointer doc(qobject_cast(KisPart::instance()->createDocument())); KisImportExportManager manager(doc.data()); doc->setFileBatchMode(true); KisImportExportErrorCode status = manager.importDocument(sourceFileInfo.absoluteFilePath(), QString()); QVERIFY(status.isOk()); Q_ASSERT(doc->image()); } QSharedPointer openSaiDocument(const QFileInfo &fileInfo) { QSharedPointer doc(qobject_cast(KisPart::instance()->createDocument())); KisImportExportManager manager(doc.data()); doc->setFileBatchMode(true); KisImportExportErrorCode status = manager.importDocument(fileInfo.absoluteFilePath(), QString()); Q_UNUSED(status); return doc; } void KisSaiTest::testColorData() { QFileInfo sourceFileInfo(QString(FILES_DATA_DIR) + QDir::separator() + "sai_rgba_test.sai"); //Because the projection color is set to white, this needs to be undone here. //QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "sai_rgba_test.png"); QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "sai_rgb_test.png"); Q_ASSERT(sourceFileInfo.exists()); QSharedPointer doc = openSaiDocument(sourceFileInfo); QVERIFY(doc->image()); QPoint errpoint; int fuzzy = 0; int fuzzyAlpha = 1; if(!TestUtil::compareQImages(errpoint, qimage, doc->image()->projection()->convertToQImage(0, 0, 0, qimage.width(), qimage.height()), fuzzy, fuzzyAlpha)) { QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); } } void KisSaiTest::testBlendingModes() { QFileInfo sourceFileInfo(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_blending_modes.sai"); QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_blending_modes.png"); Q_ASSERT(sourceFileInfo.exists()); QSharedPointer doc = openSaiDocument(sourceFileInfo); QVERIFY(doc->image()); QPoint errpoint; int fuzzy = 1; int fuzzyAlpha = 1; if(!TestUtil::compareQImages(errpoint, qimage, doc->image()->projection()->convertToQImage(0, 0, 0, qimage.width(), qimage.height()), fuzzy, fuzzyAlpha)) { QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); } } void KisSaiTest::testLayerConfiguration() { QFileInfo sourceFileInfo(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_layer_configurations.sai"); QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_layer_configurations.png"); Q_ASSERT(sourceFileInfo.exists()); QSharedPointer doc = openSaiDocument(sourceFileInfo); QVERIFY(doc->image()); QPoint errpoint; int fuzzy = 1; int fuzzyAlpha = 1; //Two for masks //Two for textures and layerstyles. int maximumFailures = 4; if(!TestUtil::compareQImages(errpoint, qimage, doc->image()->projection()->convertToQImage(0, 0, 0, qimage.width(), qimage.height()), fuzzy, fuzzyAlpha, maximumFailures)) { QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); } } void KisSaiTest::testClippingAndGroups() { QFileInfo sourceFileInfo(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_clipping_groups.sai"); QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_clipping_groups.png"); Q_ASSERT(sourceFileInfo.exists()); QSharedPointer doc = openSaiDocument(sourceFileInfo); QVERIFY(doc->image()); QPoint errpoint; int fuzzy = 1; int fuzzyAlpha = 1; if(!TestUtil::compareQImages(errpoint, qimage, doc->image()->projection()->convertToQImage(0, 0, 0, qimage.width(), qimage.height()), fuzzy, fuzzyAlpha)) { QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); } } +void KisSaiTest::testLayerOffset() +{ + QFileInfo sourceFileInfo(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_layer_offset.sai"); + QImage qimage(QString(FILES_DATA_DIR) + QDir::separator() + "sai_test_layer_offset.png"); + + Q_ASSERT(sourceFileInfo.exists()); + + QSharedPointer doc = openSaiDocument(sourceFileInfo); + QVERIFY(doc->image()); + + QPoint errpoint; + int fuzzy = 1; + int fuzzyAlpha = 1; + if(!TestUtil::compareQImages(errpoint, qimage, + doc->image()->projection()->convertToQImage(0, 0, 0, qimage.width(), qimage.height()), fuzzy, fuzzyAlpha)) { + QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1()); + } +} + void KisSaiTest::testImportFromWriteonly() { TestUtil::testImportFromWriteonly(QString(FILES_DATA_DIR), SaiMimeType); } void KisSaiTest::testImportIncorrectFormat() { TestUtil::testImportIncorrectFormat(QString(FILES_DATA_DIR), SaiMimeType); } KISTEST_MAIN(KisSaiTest) diff --git a/plugins/impex/sai/tests/kis_sai_test.h b/plugins/impex/sai/tests/kis_sai_test.h index f53ce2d125..8cca7f5705 100644 --- a/plugins/impex/sai/tests/kis_sai_test.h +++ b/plugins/impex/sai/tests/kis_sai_test.h @@ -1,40 +1,41 @@ /* * Copyright (C) 2019 Wolthera van Hövell tot Westerflier * * 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_SAI_TEST_H #define KIS_SAI_TEST_H #include class KisSaiTest : public QObject { Q_OBJECT private Q_SLOTS: void testOpening(); void testColorData(); void testBlendingModes(); void testLayerConfiguration(); void testClippingAndGroups(); + void testLayerOffset(); void testImportFromWriteonly(); void testImportIncorrectFormat(); }; #endif // KIS_SAI_TEST_H