Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / inc / test / outputdevice.hxx
blob8412dbaf8a7b19b3a97295bb93dbf3b9b454ac8a
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/.
9 */
11 #ifndef INCLUDED_VCL_OUTDEVTESTS_HXX
12 #define INCLUDED_VCL_OUTDEVTESTS_HXX
14 #include <vcl/virdev.hxx>
15 #include <vcl/test/TestResult.hxx>
17 namespace vcl::test {
19 /** Common subclass for output device rendering tests.
21 class VCL_DLLPUBLIC OutputDeviceTestCommon
23 protected:
25 ScopedVclPtr<VirtualDevice> mpVirtualDevice;
26 tools::Rectangle maVDRectangle;
28 static const Color constBackgroundColor;
29 static const Color constLineColor;
30 static const Color constFillColor;
32 public:
33 OutputDeviceTestCommon();
35 OUString getRenderBackendName() const;
37 void initialSetup(tools::Long nWidth, tools::Long nHeight, Color aColor, bool bEnableAA = false, bool bAlphaVirtualDevice = false);
39 static TestResult checkRectangle(Bitmap& rBitmap);
40 static TestResult checkRectangleAA(Bitmap& rBitmap);
41 static TestResult checkFilledRectangle(Bitmap& rBitmap, bool useLineColor);
42 static TestResult checkLines(Bitmap& rBitmap);
43 static TestResult checkAALines(Bitmap& rBitmap);
44 static TestResult checkDiamond(Bitmap& rBitmap);
46 static TestResult checkInvertRectangle(Bitmap& rBitmap);
47 static TestResult checkInvertN50Rectangle(Bitmap& aBitmap);
48 static TestResult checkInvertTrackFrameRectangle(Bitmap& aBitmap);
50 static TestResult checkRectangles(Bitmap& rBitmap, std::vector<Color>& aExpectedColors);
51 static TestResult checkRectangle(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor);
52 static TestResult checkRectangles(Bitmap& rBitmap, bool aEnableAA = false);
54 static TestResult checkFilled(Bitmap& rBitmap, tools::Rectangle aRectangle, Color aExpectedColor);
55 static TestResult checkChecker(Bitmap& rBitmap, sal_Int32 nStartX, sal_Int32 nEndX,
56 sal_Int32 nStartY, sal_Int32 nEndY, std::vector<Color> const & rExpected);
58 static TestResult checkLinearGradient(Bitmap& bitmap);
59 static TestResult checkLinearGradientAngled(Bitmap& bitmap);
60 static TestResult checkLinearGradientBorder(Bitmap& bitmap);
61 static TestResult checkLinearGradientIntensity(Bitmap& bitmap);
62 static TestResult checkLinearGradientSteps(Bitmap& bitmap);
63 static TestResult checkAxialGradient(Bitmap& bitmap);
64 static TestResult checkRadialGradient(Bitmap& bitmap);
65 static TestResult checkRadialGradientOfs(Bitmap& bitmap);
67 static void createDiamondPoints(tools::Rectangle rRect, int nOffset,
68 Point& rPoint1, Point& rPoint2,
69 Point& rPoint3, Point& rPoint4);
71 static tools::Polygon createDropShapePolygon();
72 static basegfx::B2DPolygon createHalfEllipsePolygon();
73 static tools::Polygon createClosedBezierLoop(const tools::Rectangle& rRect);
74 static basegfx::B2DPolygon createOpenPolygon(const tools::Rectangle& rRect, int nOffset = 4);
75 static basegfx::B2DPolygon createOpenBezier();
77 static void createHorizontalVerticalDiagonalLinePoints(tools::Rectangle rRect,
78 Point& rHorizontalLinePoint1, Point& rHorizontalLinePoint2,
79 Point& rVerticalLinePoint1, Point& rVerticalLinePoint2,
80 Point& rDiagonalLinePoint1, Point& rDiagonalLinePoint2);
81 // tools
82 static tools::Rectangle alignToCenter(tools::Rectangle aRect1, tools::Rectangle aRect2);
84 static TestResult checkBezier(Bitmap& rBitmap);
86 static TestResult checkLineCapRound(Bitmap& rBitmap) { return checkLineCap(rBitmap, css::drawing::LineCap_ROUND); }
87 static TestResult checkLineCapSquare(Bitmap& rBitmap) { return checkLineCap(rBitmap, css::drawing::LineCap_SQUARE); }
88 static TestResult checkLineCapButt(Bitmap& rBitmap) { return checkLineCap(rBitmap, css::drawing::LineCap_BUTT); }
90 static TestResult checkLineJoinBevel(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::Bevel); }
91 static TestResult checkLineJoinRound(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::Round); }
92 static TestResult checkLineJoinMiter(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::Miter); }
93 static TestResult checkLineJoinNone(Bitmap& rBitmap) { return checkLineJoin(rBitmap, basegfx::B2DLineJoin::NONE); }
94 static TestResult checkDropShape(Bitmap& rBitmap, bool aEnableAA = false);
95 static TestResult checkHalfEllipse(Bitmap& rBitmap, bool aEnableAA = false);
96 static TestResult checkClosedBezier(Bitmap& rBitmap);
97 static TestResult checkFilledAsymmetricalDropShape(Bitmap& rBitmap);
98 static TestResult checkTextLocation(Bitmap& rBitmap);
99 static TestResult checkEvenOddRuleInIntersectingRecs(Bitmap &rBitmap);
100 static TestResult checkIntersectingRecs(Bitmap& rBitmap,int aLayerNumber, Color aExpectedColor);
101 static TestResult checkOpenPolygon(Bitmap& rBitmap, bool aEnableAA = false);
102 static TestResult checkOpenBezier(Bitmap& rBitmap);
103 private:
104 static TestResult checkLineCap(Bitmap& rBitmap, css::drawing::LineCap lineCap);
105 static TestResult checkLineJoin(Bitmap& rBitmap, basegfx::B2DLineJoin lineJoin);
108 class VCL_DLLPUBLIC OutputDeviceTestBitmap : public OutputDeviceTestCommon
110 public:
111 OutputDeviceTestBitmap() = default;
113 Bitmap setupDrawTransformedBitmap(vcl::PixelFormat aBitmapFormat,
114 bool isBitmapGreyScale = false);
115 Bitmap setupComplexDrawTransformedBitmap(vcl::PixelFormat aBitmapFormat,
116 bool isBitmapGreyScale = false);
117 Bitmap setupDrawBitmap(vcl::PixelFormat aBitmapFormat, bool isBitmapGreyScale = false);
118 Bitmap setupDrawBitmapExWithAlpha(vcl::PixelFormat aBitmapFormat);
119 Bitmap setupDrawMask(vcl::PixelFormat aBitmapFormat);
120 BitmapEx setupDrawBlend(vcl::PixelFormat aBitmapFormat);
122 static TestResult checkTransformedBitmap(Bitmap& rBitmap);
123 static TestResult checkComplexTransformedBitmap(Bitmap& rBitmap);
124 static TestResult checkBitmapExWithAlpha(Bitmap& rBitmap);
125 static TestResult checkMask(Bitmap& rBitmap);
126 static TestResult checkBlend(const BitmapEx& rBitmap);
128 static TestResult checkTransformedBitmap8bppGreyScale(Bitmap& rBitmap);
131 class VCL_DLLPUBLIC OutputDeviceTestAnotherOutDev : public OutputDeviceTestCommon
133 public:
134 OutputDeviceTestAnotherOutDev() = default;
136 Bitmap setupDrawOutDev();
137 Bitmap setupDrawOutDevScaledClipped();
138 Bitmap setupDrawOutDevSelf();
139 Bitmap setupXOR();
141 static TestResult checkDrawOutDev(Bitmap& rBitmap);
142 static TestResult checkDrawOutDevScaledClipped(Bitmap& rBitmap);
143 static TestResult checkDrawOutDevSelf(Bitmap& rBitmap);
144 static TestResult checkXOR(Bitmap& rBitmap);
147 class VCL_DLLPUBLIC OutputDeviceTestPixel : public OutputDeviceTestCommon
149 public:
150 OutputDeviceTestPixel() = default;
152 Bitmap setupRectangle(bool bEnableAA);
153 Bitmap setupRectangleOnSize1028();
154 Bitmap setupRectangleOnSize4096();
157 class VCL_DLLPUBLIC OutputDeviceTestLine : public OutputDeviceTestCommon
159 public:
160 OutputDeviceTestLine() = default;
162 Bitmap setupRectangle(bool bEnableAA);
163 Bitmap setupRectangleOnSize1028();
164 Bitmap setupRectangleOnSize4096();
165 Bitmap setupDiamond();
166 Bitmap setupLines();
167 Bitmap setupAALines();
169 Bitmap setupDashedLine();
170 static TestResult checkDashedLine(Bitmap& rBitmap);
172 Bitmap setupLineCapRound() { return setupLineCap(css::drawing::LineCap_ROUND); }
173 Bitmap setupLineCapSquare() { return setupLineCap(css::drawing::LineCap_SQUARE); }
174 Bitmap setupLineCapButt() { return setupLineCap(css::drawing::LineCap_BUTT); }
176 Bitmap setupLineJoinBevel() { return setupLineJoin(basegfx::B2DLineJoin::Bevel); }
177 Bitmap setupLineJoinRound() { return setupLineJoin(basegfx::B2DLineJoin::Round); }
178 Bitmap setupLineJoinMiter() { return setupLineJoin(basegfx::B2DLineJoin::Miter); }
179 Bitmap setupLineJoinNone() { return setupLineJoin(basegfx::B2DLineJoin::NONE); }
180 private:
181 Bitmap setupLineCap( css::drawing::LineCap lineCap );
182 Bitmap setupLineJoin( basegfx::B2DLineJoin lineJoin );
185 class VCL_DLLPUBLIC OutputDeviceTestPolyLine : public OutputDeviceTestCommon
187 public:
188 OutputDeviceTestPolyLine() = default;
190 Bitmap setupRectangle(bool bEnableAA);
191 Bitmap setupDiamond();
192 Bitmap setupLines();
193 Bitmap setupAALines();
194 Bitmap setupDropShape();
195 Bitmap setupAADropShape();
196 Bitmap setupHalfEllipse(bool aEnableAA = false);
197 Bitmap setupClosedBezier();
198 Bitmap setupRectangleOnSize1028();
199 Bitmap setupRectangleOnSize4096();
200 Bitmap setupOpenPolygon();
201 Bitmap setupOpenBezier();
204 class VCL_DLLPUBLIC OutputDeviceTestPolyLineB2D : public OutputDeviceTestCommon
206 public:
207 OutputDeviceTestPolyLineB2D() = default;
209 Bitmap setupRectangle(bool bEnableAA);
210 Bitmap setupDiamond();
211 Bitmap setupBezier();
212 Bitmap setupAABezier();
213 Bitmap setupHalfEllipse(bool aEnableAA = false);
214 Bitmap setupRectangleOnSize1028();
215 Bitmap setupRectangleOnSize4096();
216 Bitmap setupOpenPolygon();
217 Bitmap setupOpenBezier();
220 class VCL_DLLPUBLIC OutputDeviceTestRect : public OutputDeviceTestCommon
222 public:
223 OutputDeviceTestRect() = default;
225 Bitmap setupRectangle(bool bEnableAA);
226 Bitmap setupFilledRectangle(bool useLineColor);
227 Bitmap setupRectangleOnSize1028();
228 Bitmap setupRectangleOnSize4096();
229 Bitmap setupInvert_NONE();
230 Bitmap setupInvert_N50();
231 Bitmap setupInvert_TrackFrame();
234 class VCL_DLLPUBLIC OutputDeviceTestPolygon : public OutputDeviceTestCommon
236 public:
237 OutputDeviceTestPolygon() = default;
239 Bitmap setupRectangle(bool bEnableAA);
240 Bitmap setupFilledRectangle(bool useLineColor);
241 Bitmap setupDiamond();
242 Bitmap setupLines();
243 Bitmap setupAALines();
244 Bitmap setupDropShape();
245 Bitmap setupAADropShape();
246 Bitmap setupHalfEllipse(bool aEnableAA = false);
247 Bitmap setupClosedBezier();
248 Bitmap setupFilledAsymmetricalDropShape();
249 Bitmap setupRectangleOnSize1028();
250 Bitmap setupRectangleOnSize4096();
251 Bitmap setupOpenPolygon();
254 class VCL_DLLPUBLIC OutputDeviceTestPolyPolygon : public OutputDeviceTestCommon
256 public:
257 OutputDeviceTestPolyPolygon() = default;
259 Bitmap setupRectangle(bool bEnableAA);
260 Bitmap setupFilledRectangle(bool useLineColor);
261 Bitmap setupIntersectingRectangles();
262 Bitmap setupRectangleOnSize1028();
263 Bitmap setupRectangleOnSize4096();
264 Bitmap setupOpenPolygon();
267 class VCL_DLLPUBLIC OutputDeviceTestPolyPolygonB2D : public OutputDeviceTestCommon
269 public:
270 OutputDeviceTestPolyPolygonB2D() = default;
272 Bitmap setupRectangle(bool bEnableAA);
273 Bitmap setupFilledRectangle(bool useLineColor);
274 Bitmap setupIntersectingRectangles();
275 Bitmap setupRectangleOnSize1028();
276 Bitmap setupRectangleOnSize4096();
277 Bitmap setupOpenPolygon();
280 class VCL_DLLPUBLIC OutputDeviceTestGradient : public OutputDeviceTestCommon
282 public:
283 OutputDeviceTestGradient() = default;
285 Bitmap setupLinearGradient();
286 Bitmap setupLinearGradientAngled();
287 Bitmap setupLinearGradientBorder();
288 Bitmap setupLinearGradientIntensity();
289 Bitmap setupLinearGradientSteps();
290 Bitmap setupAxialGradient();
291 Bitmap setupRadialGradient();
292 Bitmap setupRadialGradientOfs();
295 class VCL_DLLPUBLIC OutputDeviceTestClip : public OutputDeviceTestCommon
297 public:
298 Bitmap setupClipRectangle();
299 Bitmap setupClipPolygon();
300 Bitmap setupClipPolyPolygon();
301 Bitmap setupClipB2DPolyPolygon();
303 static TestResult checkClip(Bitmap& rBitmap);
306 class VCL_DLLPUBLIC OutputDeviceTestText : public OutputDeviceTestCommon
308 public:
309 Bitmap setupTextBitmap();
312 } // end namespace vcl::test
314 #endif
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */