File indexing completed on 2025-01-26 04:04:55

0001 /*
0002  *  SPDX-FileCopyrightText: 2019 Anna Medonosova <anna.medonosova@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 
0008 #include <simpletest.h>
0009 #include <resources/KoGamutMask.h>
0010 
0011 #include <testutil.h>
0012 
0013 #include "KoGamutMaskTest.h"
0014 #include <KisGlobalResourcesInterface.h>
0015 
0016 KoGamutMaskTest::KoGamutMaskTest(QObject *parent) : QObject(parent)
0017 {
0018 
0019 }
0020 
0021 void KoGamutMaskTest::testCoordIsClear()
0022 {
0023     QFETCH(QString, maskFile);
0024     QFETCH(QPointF, coord);
0025     QFETCH(int, maskRotation);
0026     QFETCH(bool, expectedOutput);
0027 
0028     QScopedPointer<KoGamutMask> mask(new KoGamutMask(TestUtil::fetchDataFileLazy(maskFile)));
0029     mask->load(KisGlobalResourcesInterface::instance());
0030     Q_ASSERT(mask->valid());
0031     mask->setRotation(maskRotation);
0032 
0033     // for this test we have a hardcoded view size of 100
0034     QPointF translatedPoint = mask->viewToMaskTransform(100).map(coord);
0035 
0036     bool maskOutput = mask->coordIsClear(translatedPoint, false);
0037     QCOMPARE(maskOutput, expectedOutput);
0038 }
0039 
0040 void KoGamutMaskTest::testCoordIsClear_data()
0041 {
0042     QTest::addColumn<QString>("maskFile");
0043     QTest::addColumn<QPointF>("coord");
0044     QTest::addColumn<int>("maskRotation");
0045     QTest::addColumn<bool>("expectedOutput");
0046 
0047     // single shape mask
0048     QTest::addRow("Atmospheric_Triad.kgm: disallowed coordinate, no rotation") << "Atmospheric_Triad.kgm"
0049                                                                         << QPointF(0.0, 0.0) << 0
0050                                                                         << false;
0051 
0052     QTest::addRow("Atmospheric_Triad.kgm: allowed coordinate, no rotation") << "Atmospheric_Triad.kgm"
0053                                                                           << QPointF(33.0, 71.0) << 0
0054                                                                           << true;
0055 
0056     QTest::addRow("Atmospheric_Triad.kgm: disallowed coordinate, with rotation") << "Atmospheric_Triad.kgm"
0057                                                                             << QPointF(33.0, 71.0) << 180
0058                                                                             << false;
0059 
0060     QTest::addRow("Atmospheric_Triad.kgm: allowed coordinate, with rotation") << "Atmospheric_Triad.kgm"
0061                                                                              << QPointF(76.4,60.9) << 180
0062                                                                              << true;
0063 
0064 
0065     // multiple shapes mask
0066     QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 1, no rotation")
0067             << "Dominant_Hue_With_Accent.kgm"
0068             << QPointF(71.0, 49.0) << 0
0069             << true;
0070 
0071     QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 2, no rotation")
0072             << "Dominant_Hue_With_Accent.kgm"
0073             << QPointF(11.0, 51.0) << 0
0074             << true;
0075 
0076     QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 1, with rotation")
0077             << "Dominant_Hue_With_Accent.kgm"
0078             << QPointF(40.0, 21.0) << 256
0079             << true;
0080 
0081     QTest::addRow("Dominant_Hue_With_Accent.kgm: allowed coordinate, shape 2, with rotation")
0082             << "Dominant_Hue_With_Accent.kgm"
0083             << QPointF(57.0, 82.0) << 256
0084             << true;
0085 }
0086 
0087 void KoGamutMaskTest::testLoad()
0088 {
0089     QFETCH(QString, maskFile);
0090     QFETCH(QString, expectedTitle);
0091     QFETCH(QString, expectedDescription);
0092     QFETCH(int, expectedShapeCount);
0093 
0094     QScopedPointer<KoGamutMask> mask(new KoGamutMask(TestUtil::fetchDataFileLazy(maskFile)));
0095     mask->load(KisGlobalResourcesInterface::instance());
0096 
0097     Q_ASSERT(mask->valid());
0098 
0099     QCOMPARE(mask->title(), expectedTitle);
0100     QCOMPARE(mask->description(), expectedDescription);
0101     QCOMPARE(mask->koShapes().size(), expectedShapeCount);
0102 }
0103 
0104 void KoGamutMaskTest::testLoad_data()
0105 {
0106     QTest::addColumn<QString>("maskFile");
0107     QTest::addColumn<QString>("expectedTitle");
0108     QTest::addColumn<QString>("expectedDescription");
0109     QTest::addColumn<int>("expectedShapeCount");
0110 
0111     QTest::addRow("single shape mask")
0112             << "Atmospheric_Triad.kgm"
0113             << "Atmospheric Triad" << "test gamut mask description"
0114             << 1;
0115 
0116     QTest::addRow("multiple shape mask")
0117             << "Dominant_Hue_With_Accent.kgm"
0118             << "Dominant Hue With Accent" << ""
0119             << 2;
0120 }
0121 
0122 SIMPLE_TEST_MAIN(KoGamutMaskTest);