1 /*
2 * Copyright (c) 2013 Dmitry Kazakov <dimula73@gmail.com>
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 "fill_processing_visitor_test.h"
20
21 #include <QTest>
22
23 #include "kis_undo_stores.h"
24 #include "kis_processing_applicator.h"
25
26 #include "testutil.h"
27 #include "qimage_based_test.h"
28 #include "stroke_testing_utils.h"
29 #include <resources/KoPattern.h>
30 #include "kis_canvas_resource_provider.h"
31
32 #include <processing/fill_processing_visitor.h>
33
34 class FillProcessingVisitorTester : public TestUtil::QImageBasedTest
35 {
36 public:
FillProcessingVisitorTester()37 FillProcessingVisitorTester()
38 : QImageBasedTest("fill_processing")
39 {
40 }
41
test(const QString & testname,bool haveSelection,bool usePattern,bool selectionOnly)42 void test(const QString &testname, bool haveSelection, bool usePattern, bool selectionOnly) {
43 KisSurrogateUndoStore *undoStore = new KisSurrogateUndoStore();
44 KisImageSP image = createImage(undoStore);
45
46 if (haveSelection) {
47 addGlobalSelection(image);
48 }
49
50 image->initialRefreshGraph();
51
52 QVERIFY(checkLayersInitial(image));
53
54 KisNodeSP fillNode = findNode(image->root(), "paint1");
55
56 KoCanvasResourceProvider *manager = utils::createResourceManager(image, fillNode);
57
58 KoPattern *newPattern = new KoPattern(TestUtil::fetchDataFileLazy("HR_SketchPaper_01.pat"));
59 newPattern->load();
60 Q_ASSERT(newPattern->valid());
61
62 QVariant v;
63 v.setValue(static_cast<void*>(newPattern));
64 manager->setResource(KisCanvasResourceProvider::CurrentPattern, v);
65
66 KisResourcesSnapshotSP resources =
67 new KisResourcesSnapshot(image,
68 fillNode,
69 manager);
70
71 KisProcessingVisitorSP visitor =
72 new FillProcessingVisitor(0,
73 QPoint(100,100),
74 image->globalSelection(),
75 resources,
76 false, // useFastMode
77 usePattern,
78 selectionOnly,
79 false,
80 10, 10, 10,
81 true /* use the current device (unmerged) */,
82 false);
83
84
85 KisProcessingApplicator applicator(image, fillNode,
86 KisProcessingApplicator::NONE);
87
88 applicator.applyVisitor(visitor);
89 applicator.end();
90 image->waitForDone();
91
92 QVERIFY(checkOneLayer(image, fillNode, testname, 500));
93
94 undoStore->undo();
95 image->waitForDone();
96
97 QVERIFY(checkLayersInitial(image));
98 }
99 };
100
testFillColorNoSelection()101 void FillProcessingVisitorTest::testFillColorNoSelection()
102 {
103 FillProcessingVisitorTester tester;
104 tester.test("fill_color_no_selection", false, false, false);
105 }
106
testFillPatternNoSelection()107 void FillProcessingVisitorTest::testFillPatternNoSelection()
108 {
109 FillProcessingVisitorTester tester;
110 tester.test("fill_pattern_no_selection", false, true, false);
111 }
112
testFillColorHaveSelection()113 void FillProcessingVisitorTest::testFillColorHaveSelection()
114 {
115 FillProcessingVisitorTester tester;
116 tester.test("fill_color_have_selection", true, false, false);
117 }
118
testFillPatternHaveSelection()119 void FillProcessingVisitorTest::testFillPatternHaveSelection()
120 {
121 FillProcessingVisitorTester tester;
122 tester.test("fill_pattern_have_selection", true, true, false);
123 }
124
testFillColorNoSelectionSelectionOnly()125 void FillProcessingVisitorTest::testFillColorNoSelectionSelectionOnly()
126 {
127 FillProcessingVisitorTester tester;
128 tester.test("fill_color_no_selection_selection_only", false, false, true);
129 }
130
testFillPatternNoSelectionSelectionOnly()131 void FillProcessingVisitorTest::testFillPatternNoSelectionSelectionOnly()
132 {
133 FillProcessingVisitorTester tester;
134 tester.test("fill_pattern_no_selection_selection_only", false, true, true);
135 }
136
testFillColorHaveSelectionSelectionOnly()137 void FillProcessingVisitorTest::testFillColorHaveSelectionSelectionOnly()
138 {
139 FillProcessingVisitorTester tester;
140 tester.test("fill_color_have_selection_selection_only", true, false, true);
141 }
142
testFillPatternHaveSelectionSelectionOnly()143 void FillProcessingVisitorTest::testFillPatternHaveSelectionSelectionOnly()
144 {
145 FillProcessingVisitorTester tester;
146 tester.test("fill_pattern_have_selection_selection_only", true, true, true);
147 }
148
149 QTEST_MAIN(FillProcessingVisitorTest)
150