File indexing completed on 2024-12-22 04:10:12

0001 /*
0002  *  SPDX-FileCopyrightText: 2007 Boudewijn Rempt boud @valdyas.org
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_adjustment_layer_test.h"
0008 
0009 #include <simpletest.h>
0010 
0011 
0012 #include <KoColorSpace.h>
0013 #include <KoColorSpaceRegistry.h>
0014 
0015 #include "kis_adjustment_layer.h"
0016 #include "filter/kis_filter_configuration.h"
0017 #include "filter/kis_filter.h"
0018 #include "filter/kis_filter_registry.h"
0019 #include "kis_image.h"
0020 #include "kis_selection.h"
0021 #include "kis_types.h"
0022 #include "kis_datamanager.h"
0023 #include "kis_pixel_selection.h"
0024 #include <testutil.h>
0025 #include <KisGlobalResourcesInterface.h>
0026 
0027 void KisAdjustmentLayerTest::testCreation()
0028 {
0029     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
0030     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
0031     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
0032     Q_ASSERT(f);
0033     KisFilterConfigurationSP  kfc = f->defaultConfiguration(KisGlobalResourcesInterface::instance());
0034     Q_ASSERT(kfc);
0035 
0036     KisAdjustmentLayerSP test = new KisAdjustmentLayer(image, "test", kfc->cloneWithResourcesSnapshot(), 0);
0037 }
0038 
0039 void KisAdjustmentLayerTest::testSetSelection()
0040 {
0041     KisSelectionSP sel = new KisSelection();
0042     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
0043     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
0044     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
0045     Q_ASSERT(f);
0046     KisFilterConfigurationSP  kfc = f->defaultConfiguration(KisGlobalResourcesInterface::instance());
0047     Q_ASSERT(kfc);
0048     sel->pixelSelection()->select(QRect(10, 10, 200, 200), 128);
0049     KisAdjustmentLayerSP l1 = new KisAdjustmentLayer(image, "bla", kfc->cloneWithResourcesSnapshot(), sel);
0050     QCOMPARE(sel->selectedExactRect(), l1->internalSelection()->selectedExactRect());
0051 }
0052 
0053 void KisAdjustmentLayerTest::testInverted()
0054 {
0055     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
0056     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
0057     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
0058     Q_ASSERT(f);
0059     KisFilterConfigurationSP  kfc = f->defaultConfiguration(KisGlobalResourcesInterface::instance());
0060     Q_ASSERT(kfc);
0061 
0062     KisSelectionSP sel2 = new KisSelection();
0063     sel2->pixelSelection()->invert();
0064     KisAdjustmentLayerSP l2 = new KisAdjustmentLayer(image, "bla", kfc->cloneWithResourcesSnapshot(), sel2);
0065     QCOMPARE(l2->internalSelection()->selectedExactRect(), image->bounds());
0066 
0067     KisSelectionSP sel3 = new KisSelection();
0068     sel3->pixelSelection()->select(QRect(50, -10, 800, 30), 128);
0069     l2->setInternalSelection(sel3);
0070 
0071 }
0072 
0073 void KisAdjustmentLayerTest::testSelectionParent()
0074 {
0075     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
0076     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
0077     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
0078     Q_ASSERT(f);
0079 
0080     {
0081         KisAdjustmentLayerSP adjLayer =
0082             new KisAdjustmentLayer(image, "bla", f->defaultConfiguration(KisGlobalResourcesInterface::instance())->cloneWithResourcesSnapshot(), 0);
0083 
0084         QCOMPARE(adjLayer->internalSelection()->parentNode(), KisNodeWSP(adjLayer));
0085     }
0086 
0087     {
0088         KisSelectionSP selection = new KisSelection();
0089         KisAdjustmentLayerSP adjLayer =
0090             new KisAdjustmentLayer(image, "bla", f->defaultConfiguration(KisGlobalResourcesInterface::instance())->cloneWithResourcesSnapshot(), selection);
0091 
0092         QCOMPARE(adjLayer->internalSelection()->parentNode(), KisNodeWSP(adjLayer));
0093     }
0094 
0095     {
0096         KisAdjustmentLayerSP adjLayer =
0097             new KisAdjustmentLayer(image, "bla", f->defaultConfiguration(KisGlobalResourcesInterface::instance())->cloneWithResourcesSnapshot(), 0);
0098 
0099         KisSelectionSP selection = new KisSelection();
0100         adjLayer->setInternalSelection(selection);
0101 
0102         QCOMPARE(adjLayer->internalSelection()->parentNode(), KisNodeWSP(adjLayer));
0103     }
0104 }
0105 
0106 SIMPLE_TEST_MAIN(KisAdjustmentLayerTest)