1 /*
2  *  Copyright (c) 2007 Boudewijn Rempt boud@valdyas.org
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include "kis_adjustment_layer_test.h"
20 
21 #include <QTest>
22 
23 
24 #include <KoColorSpace.h>
25 #include <KoColorSpaceRegistry.h>
26 
27 #include "kis_adjustment_layer.h"
28 #include "filter/kis_filter_configuration.h"
29 #include "filter/kis_filter.h"
30 #include "filter/kis_filter_registry.h"
31 #include "kis_image.h"
32 #include "kis_selection.h"
33 #include "kis_types.h"
34 #include "kis_datamanager.h"
35 #include "kis_pixel_selection.h"
36 #include "testutil.h"
37 
testCreation()38 void KisAdjustmentLayerTest::testCreation()
39 {
40     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
41     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
42     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
43     Q_ASSERT(f);
44     KisFilterConfigurationSP  kfc = f->defaultConfiguration();
45     Q_ASSERT(kfc);
46 
47     KisAdjustmentLayerSP test = new KisAdjustmentLayer(image, "test", kfc, 0);
48 }
49 
testSetSelection()50 void KisAdjustmentLayerTest::testSetSelection()
51 {
52     KisSelectionSP sel = new KisSelection();
53     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
54     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
55     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
56     Q_ASSERT(f);
57     KisFilterConfigurationSP  kfc = f->defaultConfiguration();
58     Q_ASSERT(kfc);
59     sel->pixelSelection()->select(QRect(10, 10, 200, 200), 128);
60     KisAdjustmentLayerSP l1 = new KisAdjustmentLayer(image, "bla", kfc, sel);
61     QCOMPARE(sel->selectedExactRect(), l1->internalSelection()->selectedExactRect());
62 }
63 
testInverted()64 void KisAdjustmentLayerTest::testInverted()
65 {
66     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
67     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
68     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
69     Q_ASSERT(f);
70     KisFilterConfigurationSP  kfc = f->defaultConfiguration();
71     Q_ASSERT(kfc);
72 
73     KisSelectionSP sel2 = new KisSelection();
74     sel2->pixelSelection()->invert();
75     KisAdjustmentLayerSP l2 = new KisAdjustmentLayer(image, "bla", kfc, sel2);
76     QCOMPARE(l2->internalSelection()->selectedExactRect(), image->bounds());
77 
78     KisSelectionSP sel3 = new KisSelection();
79     sel3->pixelSelection()->select(QRect(50, -10, 800, 30), 128);
80     l2->setInternalSelection(sel3);
81 
82 }
83 
testSelectionParent()84 void KisAdjustmentLayerTest::testSelectionParent()
85 {
86     const KoColorSpace * colorSpace = KoColorSpaceRegistry::instance()->rgb8();
87     KisImageSP image = new KisImage(0, 512, 512, colorSpace, "adj layer test");
88     KisFilterSP f = KisFilterRegistry::instance()->value("invert");
89     Q_ASSERT(f);
90 
91     {
92         KisAdjustmentLayerSP adjLayer =
93             new KisAdjustmentLayer(image, "bla", f->defaultConfiguration(), 0);
94 
95         QCOMPARE(adjLayer->internalSelection()->parentNode(), KisNodeWSP(adjLayer));
96     }
97 
98     {
99         KisSelectionSP selection = new KisSelection();
100         KisAdjustmentLayerSP adjLayer =
101             new KisAdjustmentLayer(image, "bla", f->defaultConfiguration(), selection);
102 
103         QCOMPARE(adjLayer->internalSelection()->parentNode(), KisNodeWSP(adjLayer));
104     }
105 
106     {
107         KisAdjustmentLayerSP adjLayer =
108             new KisAdjustmentLayer(image, "bla", f->defaultConfiguration(), 0);
109 
110         KisSelectionSP selection = new KisSelection();
111         adjLayer->setInternalSelection(selection);
112 
113         QCOMPARE(adjLayer->internalSelection()->parentNode(), KisNodeWSP(adjLayer));
114     }
115 }
116 
117 QTEST_MAIN(KisAdjustmentLayerTest)
118