calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / vcl / qa / cppunit / gradient.cxx
blob2f33f4b1a6d04a5c757ac0e15a65f9ce57e6ce3a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <test/bootstrapfixture.hxx>
11 #include <test/outputdevice.hxx>
13 #include <sal/log.hxx>
14 #include <basegfx/matrix/b2dhommatrix.hxx>
15 #include <basegfx/numeric/ftools.hxx>
16 #include <basegfx/polygon/b2dpolygon.hxx>
17 #include <basegfx/polygon/b2dpolypolygon.hxx>
18 #include <basegfx/vector/b2enums.hxx>
20 #include <vcl/gradient.hxx>
21 #include <vcl/lineinfo.hxx>
22 #include <vcl/print.hxx>
23 #include <vcl/rendercontext/RasterOp.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/gdimtf.hxx>
27 #include <vcl/metaact.hxx>
29 #include <bitmap/BitmapWriteAccess.hxx>
30 #include <bufferdevice.hxx>
31 #include <window.h>
33 class VclGradientTest : public test::BootstrapFixture
35 public:
36 VclGradientTest()
37 : BootstrapFixture(true, false)
41 void testAddGradientActions_rect_linear();
42 void testAddGradientActions_rect_axial();
43 void testAddGradientActions_rect_complex();
45 CPPUNIT_TEST_SUITE(VclGradientTest);
46 CPPUNIT_TEST(testAddGradientActions_rect_linear);
47 CPPUNIT_TEST(testAddGradientActions_rect_axial);
48 CPPUNIT_TEST(testAddGradientActions_rect_complex);
49 CPPUNIT_TEST_SUITE_END();
52 static size_t TestLinearStripes(GDIMetaFile& rMtf, size_t nTimes, size_t nIndex)
54 nIndex++;
55 MetaAction* pAction = rMtf.GetAction(nIndex);
56 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action (start)", MetaActionType::FILLCOLOR,
57 pAction->GetType());
59 nIndex++;
60 pAction = rMtf.GetAction(nIndex);
61 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action (start)", MetaActionType::POLYGON,
62 pAction->GetType());
64 for (size_t i = 0; i < nTimes - 1; i++)
66 nIndex++;
67 pAction = rMtf.GetAction(nIndex);
68 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR,
69 pAction->GetType());
71 nIndex++;
72 pAction = rMtf.GetAction(nIndex);
73 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON,
74 pAction->GetType());
77 nIndex++;
78 pAction = rMtf.GetAction(nIndex);
79 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action (end)", MetaActionType::FILLCOLOR,
80 pAction->GetType());
82 nIndex++;
83 pAction = rMtf.GetAction(nIndex);
84 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action (end)", MetaActionType::POLYGON,
85 pAction->GetType());
87 return nIndex;
90 void VclGradientTest::testAddGradientActions_rect_linear()
92 GDIMetaFile aMtf;
93 tools::Rectangle aRect(Point(10, 10), Size(40, 40));
94 Gradient aGradient(css::awt::GradientStyle_LINEAR, COL_RED, COL_WHITE);
95 aGradient.SetBorder(100);
97 aGradient.AddGradientActions(aRect, aMtf);
99 size_t nIndex = 0;
101 MetaAction* pAction = aMtf.GetAction(nIndex);
102 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH, pAction->GetType());
104 nIndex++;
105 pAction = aMtf.GetAction(nIndex);
106 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rectangular intersect clip action",
107 MetaActionType::ISECTRECTCLIPREGION, pAction->GetType());
109 nIndex++;
110 pAction = aMtf.GetAction(nIndex);
111 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a line color action", MetaActionType::LINECOLOR,
112 pAction->GetType());
114 TestLinearStripes(aMtf, 3, nIndex);
117 static size_t TestAxialStripes(GDIMetaFile& rMtf, size_t nTimes, size_t nIndex)
119 nIndex++;
120 MetaAction* pAction = rMtf.GetAction(nIndex);
121 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR,
122 pAction->GetType());
124 nIndex++;
125 pAction = rMtf.GetAction(nIndex);
126 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON,
127 pAction->GetType());
129 nIndex++;
130 pAction = rMtf.GetAction(nIndex);
131 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON,
132 pAction->GetType());
134 for (size_t i = 0; i < nTimes - 1; i++)
136 nIndex++;
137 pAction = rMtf.GetAction(nIndex);
138 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR,
139 pAction->GetType());
141 nIndex++;
142 pAction = rMtf.GetAction(nIndex);
143 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON,
144 pAction->GetType());
146 nIndex++;
147 pAction = rMtf.GetAction(nIndex);
148 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON,
149 pAction->GetType());
152 nIndex++;
153 pAction = rMtf.GetAction(nIndex);
154 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR,
155 pAction->GetType());
157 nIndex++;
158 pAction = rMtf.GetAction(nIndex);
159 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polygon action", MetaActionType::POLYGON,
160 pAction->GetType());
162 return nIndex;
165 void VclGradientTest::testAddGradientActions_rect_axial()
167 GDIMetaFile aMtf;
168 tools::Rectangle aRect(Point(10, 10), Size(40, 40));
169 Gradient aGradient(css::awt::GradientStyle_AXIAL, COL_RED, COL_WHITE);
170 aGradient.SetBorder(100);
172 aGradient.AddGradientActions(aRect, aMtf);
174 size_t nIndex = 0;
176 MetaAction* pAction = aMtf.GetAction(nIndex);
177 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH, pAction->GetType());
179 nIndex++;
180 pAction = aMtf.GetAction(nIndex);
181 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rectangular intersect clip action",
182 MetaActionType::ISECTRECTCLIPREGION, pAction->GetType());
184 nIndex++;
185 pAction = aMtf.GetAction(nIndex);
186 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a line color action", MetaActionType::LINECOLOR,
187 pAction->GetType());
189 TestAxialStripes(aMtf, 3, nIndex);
192 static size_t TestComplexStripes(GDIMetaFile& rMtf, size_t nTimes, size_t nIndex)
194 nIndex++;
195 MetaAction* pAction = rMtf.GetAction(nIndex);
196 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR,
197 pAction->GetType());
199 for (size_t i = 1; i < nTimes; i++)
201 nIndex++;
202 pAction = rMtf.GetAction(nIndex);
203 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", MetaActionType::POLYPOLYGON,
204 pAction->GetType());
206 nIndex++;
207 pAction = rMtf.GetAction(nIndex);
208 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR,
209 pAction->GetType());
212 nIndex++;
213 pAction = rMtf.GetAction(nIndex);
214 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a fill color action", MetaActionType::FILLCOLOR,
215 pAction->GetType());
217 nIndex++;
218 pAction = rMtf.GetAction(nIndex);
219 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a polypolygon action", MetaActionType::POLYGON,
220 pAction->GetType());
222 return nIndex;
225 void VclGradientTest::testAddGradientActions_rect_complex()
227 GDIMetaFile aMtf;
228 tools::Rectangle aRect(Point(10, 10), Size(40, 40));
229 Gradient aGradient(css::awt::GradientStyle_SQUARE, COL_RED, COL_WHITE);
230 aGradient.SetBorder(10);
232 aGradient.AddGradientActions(aRect, aMtf);
234 size_t nIndex = 0;
236 MetaAction* pAction = aMtf.GetAction(nIndex);
237 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a push action", MetaActionType::PUSH, pAction->GetType());
239 nIndex++;
240 pAction = aMtf.GetAction(nIndex);
241 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a rectangular intersect clip action",
242 MetaActionType::ISECTRECTCLIPREGION, pAction->GetType());
244 nIndex++;
245 pAction = aMtf.GetAction(nIndex);
246 CPPUNIT_ASSERT_EQUAL_MESSAGE("Not a line color action", MetaActionType::LINECOLOR,
247 pAction->GetType());
249 TestComplexStripes(aMtf, 40, nIndex);
252 CPPUNIT_TEST_SUITE_REGISTRATION(VclGradientTest);
254 CPPUNIT_PLUGIN_IMPLEMENT();
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */