Warning, file /graphics/krita/plugins/paintops/colorsmudge/tests/KisColorsmudgeOpTest.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "KisColorsmudgeOpTest.h" 0008 0009 #include "kistest.h" 0010 0011 #include <qimage_based_test.h> 0012 #include <stroke_testing_utils.h> 0013 #include <brushengine/kis_paint_information.h> 0014 #include <kis_canvas_resource_provider.h> 0015 #include <brushengine/kis_paintop_preset.h> 0016 #include <brushengine/kis_paintop_settings.h> 0017 #include <KoCanvasResourcesIds.h> 0018 0019 class TestColorsmudgeOp : public TestUtil::QImageBasedTest 0020 { 0021 public: 0022 TestColorsmudgeOp(const QString &prefix = "simple") 0023 : QImageBasedTest("colorsmudgeop") { 0024 m_prefix = prefix; 0025 } 0026 0027 void test(const QString &testName, const QString &presetFileName, bool useOverlay) { 0028 KisSurrogateUndoStore *undoStore = new KisSurrogateUndoStore(); 0029 KisImageSP image = createTrivialImage(undoStore); 0030 image->initialRefreshGraph(); 0031 image->resizeImage(QRect(0,0,200,200)); 0032 image->waitForDone(); 0033 0034 KisNodeSP paint1 = findNode(image->root(), "paint1"); 0035 0036 QVERIFY(paint1->extent().isEmpty()); 0037 0038 paint1->paintDevice()->fill(QRect(80, 5, 50, 190), KoColor(Qt::red, image->colorSpace())); 0039 0040 KisNodeSP targetNode = paint1; 0041 0042 if (useOverlay) { 0043 KisPaintLayerSP paint2 = new KisPaintLayer(image, "paint2", OPACITY_OPAQUE_U8); 0044 image->addNode(paint2, paint1->parent(), paint1); 0045 targetNode = paint2; 0046 0047 KisPaintLayerSP paintBg = new KisPaintLayer(image, "paintBg", OPACITY_OPAQUE_U8); 0048 image->addNode(paintBg, paint1->parent(), 0); 0049 paintBg->paintDevice()->fill(QRect(0, 100, 200, 100), KoColor(Qt::white, image->colorSpace())); 0050 0051 image->initialRefreshGraph(); 0052 } 0053 0054 KisPainter gc(targetNode->paintDevice()); 0055 0056 QScopedPointer<KoCanvasResourceProvider> manager( 0057 utils::createResourceManager(image, 0, presetFileName)); 0058 0059 manager->setResource(KoCanvasResource::ForegroundColor, KoColor(Qt::green, image->colorSpace())); 0060 0061 KisPaintOpPresetSP preset = 0062 manager->resource(KoCanvasResource::CurrentPaintOpPreset).value<KisPaintOpPresetSP>(); 0063 0064 if (useOverlay) { 0065 preset->settings()->setProperty("MergedPaint", true); 0066 } 0067 0068 QString testPrefix = 0069 QString("%1_%2") 0070 .arg(m_prefix) 0071 .arg(testName); 0072 0073 KisResourcesSnapshotSP resources = 0074 new KisResourcesSnapshot(image, 0075 targetNode, 0076 manager.data()); 0077 0078 resources->setupPainter(&gc); 0079 0080 doPaint(gc); 0081 0082 checkOneLayer(image, targetNode, testPrefix); 0083 } 0084 0085 void doPaint(KisPainter &gc) { 0086 0087 const QVector<qreal> pressureLevels = {1.0, 0.8, 0.5}; 0088 0089 int yOffset = 20; 0090 Q_FOREACH (qreal pressure, pressureLevels) { 0091 { 0092 KisDistanceInformation dist; 0093 KisPaintInformation p1(QPointF(20, yOffset), pressure); 0094 KisPaintInformation p2(QPointF(180, yOffset), pressure); 0095 0096 gc.paintLine(p1, p2, &dist); 0097 } 0098 0099 { 0100 KisDistanceInformation dist; 0101 KisPaintInformation p1(QPointF(100, yOffset + 30), pressure); 0102 KisPaintInformation p2(QPointF(180, yOffset + 30), pressure); 0103 0104 gc.paintLine(p1, p2, &dist); 0105 } 0106 0107 yOffset += 60; 0108 } 0109 } 0110 0111 QString m_presetFileName; 0112 QString m_prefix; 0113 }; 0114 0115 void KisColorsmudgeOpTest::test_data() 0116 { 0117 QTest::addColumn<QString>("testName"); 0118 QTest::addColumn<QString>("preset"); 0119 QTest::addColumn<bool>("overlay"); 0120 0121 QStringList files = { 0122 "test_smudge_20px_dul_nsa_new.0001.kpp", 0123 "test_smudge_20px_dul_nsa_old.0001.kpp", 0124 "test_smudge_20px_dul_sa_new.0001.kpp", 0125 "test_smudge_20px_dul_sa_old.0001.kpp", 0126 "test_smudge_20px_sme_nsa_new.0001.kpp", 0127 "test_smudge_20px_sme_nsa_old.0001.kpp", 0128 "test_smudge_20px_sme_sa_new.0001.kpp", 0129 "test_smudge_20px_sme_sa_old.0001.kpp" 0130 }; 0131 0132 for (int i = 0; i < 2; i++) { 0133 const bool useOverlay = bool(i); 0134 Q_FOREACH (const QString &file, files) { 0135 QRegularExpression re("test_smudge_(.+).0001.kpp"); 0136 const QString name = QString("%1_%2").arg(useOverlay ? "over" : "norm").arg(re.match(file).captured(1)); 0137 const QByteArray nameLatin = name.toLatin1(); 0138 QTest::addRow("%s", nameLatin.data()) << name << file << useOverlay; 0139 } 0140 } 0141 } 0142 0143 void KisColorsmudgeOpTest::test() 0144 { 0145 QFETCH(QString, testName); 0146 QFETCH(QString, preset); 0147 QFETCH(bool, overlay); 0148 0149 TestColorsmudgeOp t; 0150 t.test(testName, preset, overlay); 0151 } 0152 0153 KISTEST_MAIN(KisColorsmudgeOpTest)