diff --git a/plugins/impex/sai/CMakeLists.txt b/plugins/impex/sai/CMakeLists.txt index 6e23dadce4..2ab5504445 100644 --- a/plugins/impex/sai/CMakeLists.txt +++ b/plugins/impex/sai/CMakeLists.txt @@ -1,34 +1,34 @@ -#add_subdirectory(tests) +add_subdirectory(tests) set( CMAKE_CXX_STANDARD 14 ) set( CMAKE_CXX_STANDARD_REQUIRED ON ) set( CMAKE_CXX_EXTENSIONS OFF ) set( CMAKE_COLOR_MAKEFILE ON ) set( CMAKE_VERBOSE_MAKEFILE ON ) set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) if( MSVC ) add_compile_options( /W3 ) elseif( CMAKE_COMPILER_IS_GNUCXX ) add_compile_options( -march=native ) add_compile_options( -Wall ) add_compile_options( -Wextra ) endif() include_directories(3rdparty/libsai/include) set(kritasaiimport_SOURCES kis_sai_import.cpp kis_sai_converter.cpp 3rdparty/libsai/source/sai.cpp ) add_library(kritasaiimport MODULE ${kritasaiimport_SOURCES}) target_link_libraries(kritasaiimport kritaui) install(TARGETS kritasaiimport DESTINATION ${KRITA_PLUGIN_INSTALL_DIR}) install( PROGRAMS krita_sai.desktop DESTINATION ${XDG_APPS_INSTALL_DIR}) diff --git a/plugins/impex/sai/tests/CMakeLists.txt b/plugins/impex/sai/tests/CMakeLists.txt new file mode 100644 index 0000000000..4fd5fe31b3 --- /dev/null +++ b/plugins/impex/sai/tests/CMakeLists.txt @@ -0,0 +1,11 @@ +set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) +include_directories( ${CMAKE_SOURCE_DIR}/sdk/tests ) + +include(KritaAddBrokenUnitTest) + +macro_add_unittest_definitions() + +ecm_add_test(kis_sai_test.cpp + TEST_NAME KisSaiTest + LINK_LIBRARIES kritaui Qt5::Test + NAME_PREFIX "plugins-impex-") diff --git a/plugins/impex/sai/tests/data/incorrectFormatFile.txt b/plugins/impex/sai/tests/data/incorrectFormatFile.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/impex/sai/tests/data/sai_rgb_test.png b/plugins/impex/sai/tests/data/sai_rgb_test.png new file mode 100644 index 0000000000..8d861c3a69 Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_rgb_test.png differ diff --git a/plugins/impex/sai/tests/data/sai_rgba_test.png b/plugins/impex/sai/tests/data/sai_rgba_test.png new file mode 100644 index 0000000000..8763e524db Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_rgba_test.png differ diff --git a/plugins/impex/sai/tests/data/sai_rgba_test.sai b/plugins/impex/sai/tests/data/sai_rgba_test.sai new file mode 100644 index 0000000000..67d52ca1a2 Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_rgba_test.sai differ diff --git a/plugins/impex/sai/tests/data/sai_test_blending_modes.png b/plugins/impex/sai/tests/data/sai_test_blending_modes.png new file mode 100644 index 0000000000..6b1897345f Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_blending_modes.png differ diff --git a/plugins/impex/sai/tests/data/sai_test_blending_modes.sai b/plugins/impex/sai/tests/data/sai_test_blending_modes.sai new file mode 100644 index 0000000000..38f97645ef Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_blending_modes.sai differ diff --git a/plugins/impex/sai/tests/data/sai_test_clipping_groups.png b/plugins/impex/sai/tests/data/sai_test_clipping_groups.png new file mode 100644 index 0000000000..f783cfa1dc Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_clipping_groups.png differ diff --git a/plugins/impex/sai/tests/data/sai_test_clipping_groups.sai b/plugins/impex/sai/tests/data/sai_test_clipping_groups.sai new file mode 100644 index 0000000000..d7c8ec681a Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_clipping_groups.sai differ diff --git a/plugins/impex/sai/tests/data/sai_test_layer_configurations.png b/plugins/impex/sai/tests/data/sai_test_layer_configurations.png new file mode 100644 index 0000000000..bbb54c92dd Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_layer_configurations.png differ diff --git a/plugins/impex/sai/tests/data/sai_test_layer_configurations.sai b/plugins/impex/sai/tests/data/sai_test_layer_configurations.sai new file mode 100644 index 0000000000..7c1047fb65 Binary files /dev/null and b/plugins/impex/sai/tests/data/sai_test_layer_configurations.sai differ diff --git a/plugins/impex/sai/tests/data/writeonlyFile.txt b/plugins/impex/sai/tests/data/writeonlyFile.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/plugins/impex/sai/tests/kis_sai_test.cpp b/plugins/impex/sai/tests/kis_sai_test.cpp new file mode 100644 index 0000000000..38aaa79dbe --- /dev/null +++ b/plugins/impex/sai/tests/kis_sai_test.cpp @@ -0,0 +1,155 @@ +/* + * 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::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 new file mode 100644 index 0000000000..f53ce2d125 --- /dev/null +++ b/plugins/impex/sai/tests/kis_sai_test.h @@ -0,0 +1,40 @@ +/* + * 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 testImportFromWriteonly(); + void testImportIncorrectFormat(); + +}; + +#endif // KIS_SAI_TEST_H