Avoid potential negative array index access to cached text.
[LibreOffice.git] / vcl / backendtest / outputdevice / common.cxx
blobbd8b905f647f190e498c055746a486e5231c9678
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 #include <test/outputdevice.hxx>
13 #include <vcl/BitmapWriteAccess.hxx>
14 #include <salgdi.hxx>
16 #include <map>
18 namespace vcl::test {
20 namespace
24 int deltaColor(BitmapColor aColor1, BitmapColor aColor2)
26 int deltaR = std::abs(aColor1.GetRed() - aColor2.GetRed());
27 int deltaG = std::abs(aColor1.GetGreen() - aColor2.GetGreen());
28 int deltaB = std::abs(aColor1.GetBlue() - aColor2.GetBlue());
30 return std::max(std::max(deltaR, deltaG), deltaB);
33 void checkValue(BitmapScopedWriteAccess& pAccess, int x, int y, Color aExpected,
34 int& nNumberOfQuirks, int& nNumberOfErrors, bool bQuirkMode, int nColorDeltaThresh = 0)
36 const bool bColorize = false;
37 Color aColor = pAccess->GetPixel(y, x);
38 int nColorDelta = deltaColor(aColor, aExpected);
40 if (nColorDelta <= nColorDeltaThresh)
42 if (bColorize)
43 pAccess->SetPixel(y, x, COL_LIGHTGREEN);
45 else if (bQuirkMode)
47 nNumberOfQuirks++;
48 if (bColorize)
49 pAccess->SetPixel(y, x, COL_YELLOW);
51 else
53 nNumberOfErrors++;
54 if (bColorize)
55 pAccess->SetPixel(y, x, COL_LIGHTRED);
59 void checkValue(BitmapScopedWriteAccess& pAccess, const Point& point, Color aExpected,
60 int& nNumberOfQuirks, int& nNumberOfErrors, bool bQuirkMode, int nColorDeltaThresh = 0)
62 checkValue(pAccess, point.getX(), point.getY(), aExpected, nNumberOfQuirks, nNumberOfErrors, bQuirkMode, nColorDeltaThresh);
65 void checkValue(BitmapScopedWriteAccess& pAccess, int x, int y, Color aExpected,
66 int& nNumberOfQuirks, int& nNumberOfErrors, int nColorDeltaThresh, int nColorDeltaThreshQuirk = 0)
68 const bool bColorize = false;
69 Color aColor = pAccess->GetPixel(y, x);
70 int nColorDelta = deltaColor(aColor, aExpected);
71 nColorDeltaThreshQuirk = std::max( nColorDeltaThresh, nColorDeltaThreshQuirk);
73 if (nColorDelta <= nColorDeltaThresh)
75 if (bColorize)
76 pAccess->SetPixel(y, x, COL_LIGHTGREEN);
78 else if (nColorDelta <= nColorDeltaThreshQuirk)
80 nNumberOfQuirks++;
81 if (bColorize)
82 pAccess->SetPixel(y, x, COL_YELLOW);
84 else
86 nNumberOfErrors++;
87 if (bColorize)
88 pAccess->SetPixel(y, x, COL_LIGHTRED);
92 char returnDominantColor(Color aColor)
94 int aRed = aColor.GetRed();
95 int aGreen = aColor.GetGreen();
96 int aBlue = aColor.GetBlue();
97 if (aRed > aGreen && aRed > aBlue)
98 return 'R';
100 if (aGreen > aRed && aGreen > aBlue)
101 return 'G';
103 if(aBlue > aRed && aBlue > aGreen)
104 return 'B';
106 return 'X'; //No Dominant Color.
109 void checkValueAA(BitmapScopedWriteAccess& pAccess, int x, int y, Color aExpected,
110 int& nNumberOfQuirks, int& nNumberOfErrors, int nColorDeltaThresh = 64)
112 const bool bColorize = false;
113 Color aColor = pAccess->GetPixel(y, x);
114 bool aColorResult = returnDominantColor(aExpected) == returnDominantColor(aColor);
115 int nColorDelta = deltaColor(aColor, aExpected);
117 if (nColorDelta <= nColorDeltaThresh && aColorResult)
119 if (bColorize)
120 pAccess->SetPixel(y, x, COL_LIGHTGREEN);
122 else if (aColorResult)
124 nNumberOfQuirks++;
125 if (bColorize)
126 pAccess->SetPixel(y, x, COL_YELLOW);
128 else
130 nNumberOfErrors++;
131 if (bColorize)
132 pAccess->SetPixel(y, x, COL_LIGHTRED);
136 // Return all colors in the rectangle and their count.
137 std::map<Color, int> collectColors(Bitmap& bitmap, const tools::Rectangle& rectangle)
139 std::map<Color, int> colors;
140 BitmapScopedWriteAccess pAccess(bitmap);
141 for (tools::Long y = rectangle.Top(); y < rectangle.Bottom(); ++y)
142 for (tools::Long x = rectangle.Left(); x < rectangle.Right(); ++x)
143 ++colors[pAccess->GetPixel(y, x)]; // operator[] initializes to 0 (default ctor) if creating
144 return colors;
147 bool checkConvexHullProperty(Bitmap& bitmap, Color constLineColor, int nWidthOffset,
148 int nHeightOffset)
150 BitmapScopedWriteAccess pAccess(bitmap);
151 tools::Long thresholdWidth = pAccess->Width() - nWidthOffset;
152 tools::Long thresholdHeight = pAccess->Height() - nHeightOffset;
153 for (tools::Long y = 0; y < pAccess->Height(); ++y)
155 for (tools::Long x = 0; x < pAccess->Width(); ++x)
158 If the shape exceeds the threshold limit of height or width or both,
159 this would indicate that the bezier curve is not within its convex polygon and
160 hence is faulty.
162 if (pAccess->GetPixel(y, x) == constLineColor
163 && (thresholdHeight < y || thresholdWidth < x))
165 return false;
169 return true;
172 TestResult checkRect(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor)
174 BitmapScopedWriteAccess pAccess(rBitmap);
175 tools::Long nHeight = pAccess->Height();
176 tools::Long nWidth = pAccess->Width();
178 tools::Long firstX = 0 + aLayerNumber;
179 tools::Long firstY = 0 + aLayerNumber;
181 tools::Long lastX = nWidth - aLayerNumber - 1;
182 tools::Long lastY = nHeight - aLayerNumber - 1;
184 TestResult aResult = TestResult::Passed;
185 int nNumberOfQuirks = 0;
186 int nNumberOfErrors = 0;
188 // check corner quirks
189 checkValue(pAccess, firstX, firstY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
190 checkValue(pAccess, lastX, firstY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
191 checkValue(pAccess, firstX, lastY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
192 checkValue(pAccess, lastX, lastY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
194 for (tools::Long y = firstY + 1; y <= lastY - 1; y++)
196 checkValue(pAccess, firstX, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
197 checkValue(pAccess, lastX, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
199 for (tools::Long x = firstX + 1; x <= lastX - 1; x++)
201 checkValue(pAccess, x, firstY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
202 checkValue(pAccess, x, lastY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
204 if (nNumberOfQuirks > 0)
205 aResult = TestResult::PassedWithQuirks;
206 if (nNumberOfErrors > 0)
207 aResult = TestResult::Failed;
208 return aResult;
211 TestResult checkHorizontalVerticalDiagonalLines(Bitmap& rBitmap, Color aExpectedColor, int nColorThresh)
213 BitmapScopedWriteAccess pAccess(rBitmap);
214 tools::Long nWidth = pAccess->Width();
215 tools::Long nHeight = pAccess->Height();
217 TestResult aResult = TestResult::Passed;
218 int nNumberOfQuirks = 0;
219 int nNumberOfErrors = 0;
221 // check horizontal line
223 tools::Long startX = 4;
224 tools::Long endX = nWidth - 2;
226 tools::Long y = 1;
228 checkValue(pAccess, startX, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true, nColorThresh);
229 checkValue(pAccess, endX, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true, nColorThresh);
231 for (tools::Long x = startX + 1; x <= endX - 1; x++)
233 checkValue(pAccess, x, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false, nColorThresh);
237 // check vertical line
239 tools::Long startY = 4;
240 tools::Long endY = nHeight - 2;
242 tools::Long x = 1;
244 checkValue(pAccess, x, startY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true, nColorThresh);
245 checkValue(pAccess, x, endY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true, nColorThresh);
247 for (tools::Long y = startY + 1; y <= endY - 1; y++)
249 checkValue(pAccess, x, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false, nColorThresh);
253 // check diagonal line
255 tools::Long startX = 1;
256 tools::Long endX = nWidth - 2;
258 tools::Long startY = 1;
259 tools::Long endY = nHeight - 2;
261 tools::Long x = startX;
262 tools::Long y = startY;
264 checkValue(pAccess, startX, startY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true, nColorThresh);
265 checkValue(pAccess, endX, endY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true, nColorThresh);
267 x++; y++;
269 while(y <= endY - 1 && x <= endX - 1)
271 checkValue(pAccess, x, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false, nColorThresh);
272 x++; y++;
276 if (nNumberOfQuirks > 0)
277 aResult = TestResult::PassedWithQuirks;
278 if (nNumberOfErrors > 0)
279 aResult = TestResult::Failed;
280 return aResult;
283 TestResult checkDiamondLine(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor)
285 BitmapScopedWriteAccess pAccess(rBitmap);
286 tools::Long nHeight = pAccess->Height();
287 tools::Long nWidth = pAccess->Width();
289 tools::Long midX = nWidth / 2;
290 tools::Long midY = nHeight / 2;
292 tools::Long firstX = aLayerNumber;
293 tools::Long lastX = nWidth - aLayerNumber - 1;
295 tools::Long firstY = aLayerNumber;
296 tools::Long lastY = nHeight - aLayerNumber - 1;
298 tools::Long offsetFromMid = 0;
300 TestResult aResult = TestResult::Passed;
301 int nNumberOfQuirks = 0;
302 int nNumberOfErrors = 0;
304 checkValue(pAccess, firstX, midY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
305 checkValue(pAccess, lastX, midY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
306 checkValue(pAccess, midX, firstY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
307 checkValue(pAccess, midX, lastY, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, true);
309 offsetFromMid = 1;
310 for (tools::Long x = firstX + 1; x <= midX - 1; x++)
312 checkValue(pAccess, x, midY - offsetFromMid, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
313 checkValue(pAccess, x, midY + offsetFromMid, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
315 offsetFromMid++;
318 offsetFromMid = midY - aLayerNumber - 1;
320 for (tools::Long x = midX + 1; x <= lastX - 1; x++)
322 checkValue(pAccess, x, midY - offsetFromMid, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
323 checkValue(pAccess, x, midY + offsetFromMid, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
325 offsetFromMid--;
328 if (nNumberOfQuirks > 0)
329 aResult = TestResult::PassedWithQuirks;
330 if (nNumberOfErrors > 0)
331 aResult = TestResult::Failed;
332 return aResult;
335 } // end anonymous namespace
337 const Color OutputDeviceTestCommon::constBackgroundColor(COL_LIGHTGRAY);
338 const Color OutputDeviceTestCommon::constLineColor(COL_LIGHTBLUE);
339 const Color OutputDeviceTestCommon::constFillColor(COL_BLUE);
341 OutputDeviceTestCommon::OutputDeviceTestCommon()
344 OUString OutputDeviceTestCommon::getRenderBackendName() const
346 if (mpVirtualDevice && mpVirtualDevice->GetGraphics())
348 SalGraphics const * pGraphics = mpVirtualDevice->GetGraphics();
349 return pGraphics->getRenderBackendName();
351 return OUString();
354 void OutputDeviceTestCommon::initialSetup(tools::Long nWidth, tools::Long nHeight, Color aColor, bool bEnableAA, bool bAlphaVirtualDevice)
356 if (bAlphaVirtualDevice)
357 mpVirtualDevice = VclPtr<VirtualDevice>::Create(DeviceFormat::WITH_ALPHA);
358 else
359 mpVirtualDevice = VclPtr<VirtualDevice>::Create(DeviceFormat::WITHOUT_ALPHA);
361 maVDRectangle = tools::Rectangle(Point(), Size (nWidth, nHeight));
362 mpVirtualDevice->SetOutputSizePixel(maVDRectangle.GetSize());
363 if (bEnableAA)
364 mpVirtualDevice->SetAntialiasing(AntialiasingFlags::Enable | AntialiasingFlags::PixelSnapHairline);
365 else
366 mpVirtualDevice->SetAntialiasing(AntialiasingFlags::NONE);
367 mpVirtualDevice->SetBackground(Wallpaper(aColor));
368 mpVirtualDevice->Erase();
371 TestResult OutputDeviceTestCommon::checkLines(Bitmap& rBitmap)
373 return checkHorizontalVerticalDiagonalLines(rBitmap, constLineColor, 0);
376 TestResult OutputDeviceTestCommon::checkAALines(Bitmap& rBitmap)
378 return checkHorizontalVerticalDiagonalLines(rBitmap, constLineColor, 30); // 30 color values threshold delta
381 static void checkResult(TestResult eResult, TestResult & eTotal)
383 if (eTotal == TestResult::Failed)
384 return;
386 if (eResult == TestResult::Failed)
387 eTotal = TestResult::Failed;
389 if (eResult == TestResult::PassedWithQuirks)
390 eTotal = TestResult::PassedWithQuirks;
393 TestResult OutputDeviceTestCommon::checkInvertRectangle(Bitmap& aBitmap)
395 TestResult aReturnValue = TestResult::Passed;
396 TestResult eResult;
398 std::vector<Color> aExpected{ COL_WHITE, COL_WHITE };
399 eResult = checkRectangles(aBitmap, aExpected);
400 checkResult(eResult, aReturnValue);
402 eResult = checkFilled(aBitmap, tools::Rectangle(Point(2, 2), Size(8, 8)), COL_LIGHTCYAN);
403 checkResult(eResult, aReturnValue);
405 eResult = checkFilled(aBitmap, tools::Rectangle(Point(10, 2), Size(8, 8)), COL_LIGHTMAGENTA);
406 checkResult(eResult, aReturnValue);
408 eResult = checkFilled(aBitmap, tools::Rectangle(Point(2, 10), Size(8, 8)), COL_YELLOW);
409 checkResult(eResult, aReturnValue);
411 eResult = checkFilled(aBitmap, tools::Rectangle(Point(10, 10), Size(8, 8)), COL_BLACK);
412 checkResult(eResult, aReturnValue);
414 return aReturnValue;
417 TestResult OutputDeviceTestCommon::checkChecker(Bitmap& rBitmap, sal_Int32 nStartX, sal_Int32 nEndX, sal_Int32 nStartY, sal_Int32 nEndY, std::vector<Color> const & rExpected)
419 TestResult aReturnValue = TestResult::Passed;
421 int choice = 0;
422 for (sal_Int32 y = nStartY; y <= nEndY; ++y)
424 for (sal_Int32 x = nStartX; x <= nEndX; ++x)
426 TestResult eResult = checkFilled(rBitmap, tools::Rectangle(Point(x, y), Size(1, 1)), rExpected[choice % 2]);
427 checkResult(eResult, aReturnValue);
428 choice++;
430 choice++;
432 return aReturnValue;
435 TestResult OutputDeviceTestCommon::checkInvertN50Rectangle(Bitmap& aBitmap)
437 TestResult aReturnValue = TestResult::Passed;
438 TestResult eResult;
440 std::vector<Color> aExpected{ COL_WHITE, COL_WHITE };
441 eResult = checkRectangles(aBitmap, aExpected);
442 checkResult(eResult, aReturnValue);
444 eResult = checkChecker(aBitmap, 2, 9, 2, 9, { COL_LIGHTCYAN, COL_LIGHTRED });
445 checkResult(eResult, aReturnValue);
446 eResult = checkChecker(aBitmap, 2, 9, 10, 17, { COL_YELLOW, COL_LIGHTBLUE });
447 checkResult(eResult, aReturnValue);
448 eResult = checkChecker(aBitmap, 10, 17, 2, 9, { COL_LIGHTMAGENTA, COL_LIGHTGREEN });
449 checkResult(eResult, aReturnValue);
450 eResult = checkChecker(aBitmap, 10, 17, 10, 17, { COL_BLACK, COL_WHITE });
451 checkResult(eResult, aReturnValue);
453 return aReturnValue;
456 TestResult OutputDeviceTestCommon::checkInvertTrackFrameRectangle(Bitmap& aBitmap)
458 std::vector<Color> aExpected
460 COL_WHITE, COL_WHITE
462 return checkRectangles(aBitmap, aExpected);
465 TestResult OutputDeviceTestCommon::checkRectangle(Bitmap& aBitmap)
467 std::vector<Color> aExpected
469 constBackgroundColor, constBackgroundColor, constLineColor,
470 constBackgroundColor, constBackgroundColor, constLineColor, constBackgroundColor
472 return checkRectangles(aBitmap, aExpected);
475 TestResult OutputDeviceTestCommon::checkRectangles(Bitmap& rBitmap, bool aEnableAA)
477 BitmapScopedWriteAccess pAccess(rBitmap);
479 TestResult aResult = TestResult::Passed;
480 int nNumberOfQuirks = 0;
481 int nNumberOfErrors = 0;
483 std::vector<Color> aExpected = { constBackgroundColor, constLineColor, constLineColor };
485 for (size_t aLayerNumber = 0; aLayerNumber < aExpected.size(); aLayerNumber++)
487 tools::Long startX = aLayerNumber, endX = pAccess->Width() / 2 - aLayerNumber + 1;
488 tools::Long startY = aLayerNumber, endY = pAccess->Height() - aLayerNumber - 1;
490 for (tools::Long ptX = startX; ptX <= endX; ++ptX)
492 if (aEnableAA)
494 checkValueAA(pAccess, ptX, startY + (aLayerNumber == 2 ? 2 : 0),
495 aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors);
496 checkValueAA(pAccess, ptX, endY - (aLayerNumber == 2 ? 2 : 0),
497 aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors);
499 else
501 checkValue(pAccess, ptX, startY + (aLayerNumber == 2 ? 2 : 0),
502 aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors, true);
503 checkValue(pAccess, ptX, endY - (aLayerNumber == 2 ? 2 : 0),
504 aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors, true);
507 for (tools::Long ptY = startY + (aLayerNumber == 2 ? 2 : 0);
508 ptY <= endY - (aLayerNumber == 2 ? 2 : 0); ++ptY)
510 if (aEnableAA)
512 checkValueAA(pAccess, startX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
513 nNumberOfErrors);
514 checkValueAA(pAccess, endX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
515 nNumberOfErrors);
517 else
519 checkValue(pAccess, startX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
520 nNumberOfErrors, true);
521 checkValue(pAccess, endX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
522 nNumberOfErrors, true);
526 if (nNumberOfQuirks > 0)
527 aResult = TestResult::PassedWithQuirks;
528 if (nNumberOfErrors > 0)
529 aResult = TestResult::Failed;
530 return aResult;
533 TestResult OutputDeviceTestCommon::checkRectangleAA(Bitmap& aBitmap)
535 return checkRectangles(aBitmap, true);
538 TestResult OutputDeviceTestCommon::checkFilledRectangle(Bitmap& aBitmap, bool useLineColor)
540 std::vector<Color> aExpected{ constBackgroundColor,
541 useLineColor ? constLineColor : constFillColor, constFillColor,
542 constFillColor, constFillColor };
544 BitmapScopedWriteAccess pAccess(aBitmap);
546 TestResult aResult = TestResult::Passed;
547 int nNumberOfQuirks = 0;
548 int nNumberOfErrors = 0;
550 for (size_t aLayerNumber = 0; aLayerNumber < aExpected.size(); aLayerNumber++)
552 tools::Long startX = aLayerNumber, endX = pAccess->Width() / 2 - aLayerNumber + 1;
553 tools::Long startY = aLayerNumber, endY = pAccess->Height() - aLayerNumber - 1;
555 for (tools::Long ptX = startX; ptX <= endX; ++ptX)
557 checkValue(pAccess, ptX, startY, aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors,
558 true);
559 checkValue(pAccess, ptX, endY, aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors, true);
561 for (tools::Long ptY = startY; ptY <= endY; ++ptY)
563 checkValue(pAccess, startX, ptY, aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors,
564 true);
565 checkValue(pAccess, endX, ptY, aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors, true);
568 if (nNumberOfQuirks > 0)
569 aResult = TestResult::PassedWithQuirks;
570 if (nNumberOfErrors > 0)
571 aResult = TestResult::Failed;
572 return aResult;
575 TestResult OutputDeviceTestCommon::checkFilled(Bitmap& rBitmap, tools::Rectangle aRectangle, Color aExpectedColor)
577 BitmapScopedWriteAccess pAccess(rBitmap);
579 TestResult aResult = TestResult::Passed;
580 int nNumberOfQuirks = 0;
581 int nNumberOfErrors = 0;
583 for (tools::Long y = aRectangle.Top(); y < aRectangle.Top() + aRectangle.GetHeight(); y++)
585 for (tools::Long x = aRectangle.Left(); x < aRectangle.Left() + aRectangle.GetWidth(); x++)
587 checkValue(pAccess, x, y, aExpectedColor, nNumberOfQuirks, nNumberOfErrors, false);
591 if (nNumberOfQuirks > 0)
592 aResult = TestResult::PassedWithQuirks;
594 if (nNumberOfErrors > 0)
595 aResult = TestResult::Failed;
597 return aResult;
600 TestResult OutputDeviceTestCommon::checkRectangles(Bitmap& aBitmap, std::vector<Color>& aExpectedColors)
602 TestResult aReturnValue = TestResult::Passed;
603 for (size_t i = 0; i < aExpectedColors.size(); i++)
605 TestResult eResult = checkRect(aBitmap, i, aExpectedColors[i]);
607 if (eResult == TestResult::Failed)
608 aReturnValue = TestResult::Failed;
609 if (eResult == TestResult::PassedWithQuirks && aReturnValue != TestResult::Failed)
610 aReturnValue = TestResult::PassedWithQuirks;
612 return aReturnValue;
615 TestResult OutputDeviceTestCommon::checkRectangle(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor)
617 return checkRect(rBitmap, aLayerNumber, aExpectedColor);
620 tools::Rectangle OutputDeviceTestCommon::alignToCenter(tools::Rectangle aRect1, tools::Rectangle aRect2)
622 Point aPoint((aRect1.GetWidth() / 2.0) - (aRect2.GetWidth() / 2.0),
623 (aRect1.GetHeight() / 2.0) - (aRect2.GetHeight() / 2.0));
625 return tools::Rectangle(aPoint, aRect2.GetSize());
628 TestResult OutputDeviceTestCommon::checkDiamond(Bitmap& rBitmap)
630 return checkDiamondLine(rBitmap, 1, constLineColor);
633 void OutputDeviceTestCommon::createDiamondPoints(tools::Rectangle rRect, int nOffset,
634 Point& rPoint1, Point& rPoint2,
635 Point& rPoint3, Point& rPoint4)
637 tools::Long midPointX = rRect.Left() + (rRect.Right() - rRect.Left()) / 2.0;
638 tools::Long midPointY = rRect.Top() + (rRect.Bottom() - rRect.Top()) / 2.0;
640 rPoint1 = Point(midPointX , midPointY - nOffset);
641 rPoint2 = Point(midPointX + nOffset, midPointY );
642 rPoint3 = Point(midPointX , midPointY + nOffset);
643 rPoint4 = Point(midPointX - nOffset, midPointY );
646 tools::Polygon OutputDeviceTestCommon::createDropShapePolygon()
648 tools::Polygon aPolygon(15);
650 aPolygon.SetPoint(Point(10, 2), 0);
651 aPolygon.SetFlags(0, PolyFlags::Normal);
652 aPolygon.SetPoint(Point(14, 2), 1);
653 aPolygon.SetFlags(1, PolyFlags::Control);
654 aPolygon.SetPoint(Point(18, 6), 2);
655 aPolygon.SetFlags(2, PolyFlags::Control);
656 aPolygon.SetPoint(Point(18, 10), 3);
658 aPolygon.SetFlags(3, PolyFlags::Normal);
659 aPolygon.SetPoint(Point(18, 10), 4);
660 aPolygon.SetFlags(4, PolyFlags::Normal);
661 aPolygon.SetPoint(Point(18, 14), 5);
662 aPolygon.SetFlags(5, PolyFlags::Control);
663 aPolygon.SetPoint(Point(14, 18), 6);
664 aPolygon.SetFlags(6, PolyFlags::Control);
665 aPolygon.SetPoint(Point(10, 18), 7);
666 aPolygon.SetFlags(7, PolyFlags::Normal);
668 aPolygon.SetPoint(Point(10, 18), 8);
669 aPolygon.SetFlags(8, PolyFlags::Normal);
670 aPolygon.SetPoint(Point(6, 18), 9);
671 aPolygon.SetFlags(9, PolyFlags::Control);
672 aPolygon.SetPoint(Point(2, 14), 10);
673 aPolygon.SetFlags(10, PolyFlags::Control);
674 aPolygon.SetPoint(Point(2, 10), 11);
675 aPolygon.SetFlags(11, PolyFlags::Normal);
677 aPolygon.SetPoint(Point(2, 10), 12);
678 aPolygon.SetFlags(12, PolyFlags::Normal);
679 aPolygon.SetPoint(Point(2, 2), 13);
680 aPolygon.SetFlags(13, PolyFlags::Normal);
681 aPolygon.SetPoint(Point(10, 2), 14);
682 aPolygon.SetFlags(14, PolyFlags::Normal);
684 aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
686 return aPolygon;
689 basegfx::B2DPolygon OutputDeviceTestCommon::createHalfEllipsePolygon()
691 basegfx::B2DPolygon aPolygon;
693 aPolygon.append({ 9.0, 1.0 });
694 aPolygon.append({ 17.0, 10.0 });
695 aPolygon.append({ 1.0, 10.0 });
696 aPolygon.setClosed(true);
698 aPolygon.setControlPoints(0, { 1.5, 1.5 }, { 16.5, 1.5 });
700 return aPolygon;
703 tools::Polygon OutputDeviceTestCommon::createClosedBezierLoop(const tools::Rectangle& rRect)
705 tools::Long minX = rRect.Left();
706 tools::Long maxX = rRect.Right() - 2;
707 tools::Long minY = rRect.Top();
708 tools::Long maxY = rRect.Bottom() - 2;
710 tools::Polygon aPolygon(4);
712 aPolygon.SetPoint(Point((maxX / 2.0), maxY), 0);
713 aPolygon.SetFlags(0, PolyFlags::Normal);
714 aPolygon.SetPoint(Point(maxX, minY), 1);
715 aPolygon.SetFlags(1, PolyFlags::Control);
716 aPolygon.SetPoint(Point(minX, minY), 2);
717 aPolygon.SetFlags(2, PolyFlags::Control);
718 aPolygon.SetPoint(Point((maxX / 2.0), maxY), 3);
719 aPolygon.SetFlags(3, PolyFlags::Normal);
721 aPolygon.Optimize(PolyOptimizeFlags::CLOSE);
723 return aPolygon;
726 basegfx::B2DPolygon OutputDeviceTestCommon::createOpenPolygon(const tools::Rectangle& rRect, int nOffset)
728 int nMidOffset = rRect.GetWidth() / 2;
729 basegfx::B2DPolygon aPolygon{
730 basegfx::B2DPoint(rRect.Left() + nOffset - (nOffset + 1) / 2, rRect.Top() + nOffset - 1),
731 basegfx::B2DPoint(rRect.Left() + nOffset - (nOffset + 1) / 2, rRect.Bottom() - nOffset + 1),
732 basegfx::B2DPoint(rRect.Right() - nMidOffset - nOffset / 3, rRect.Bottom() - nOffset + 1),
733 basegfx::B2DPoint(rRect.Right() - nMidOffset - nOffset / 3, rRect.Top() + nOffset - 1),
735 aPolygon.setClosed(false);
736 return aPolygon;
739 basegfx::B2DPolygon OutputDeviceTestCommon::createOpenBezier()
741 basegfx::B2DPolygon aPolygon;
743 aPolygon.append({ 5.0, 2.0 });
744 aPolygon.append({ 3.0, 14.0 });
745 aPolygon.setClosed(false);
747 aPolygon.setControlPoints(0, { 15.0, 2.0 }, { 15.0, 15.0 });
749 return aPolygon;
752 TestResult OutputDeviceTestCommon::checkDropShape(Bitmap& rBitmap, bool aEnableAA)
754 BitmapScopedWriteAccess pAccess(rBitmap);
756 TestResult aResult = TestResult::Passed;
757 int nNumberOfQuirks = 0;
758 int nNumberOfErrors = 0;
760 std::map<std::pair<int, int>, bool> SetPixels
761 = { { { 2, 2 }, true }, { { 3, 2 }, true }, { { 4, 2 }, true }, { { 5, 2 }, true },
762 { { 6, 2 }, true }, { { 7, 2 }, true }, { { 8, 2 }, true }, { { 9, 2 }, true },
763 { { 10, 2 }, true }, { { 11, 2 }, true }, { { 12, 2 }, true }, { { 2, 3 }, true },
764 { { 13, 3 }, true }, { { 14, 3 }, true }, { { 2, 4 }, true }, { { 15, 4 }, true },
765 { { 2, 5 }, true }, { { 16, 5 }, true }, { { 2, 6 }, true }, { { 17, 6 }, true },
766 { { 2, 7 }, true }, { { 17, 7 }, true }, { { 2, 8 }, true }, { { 18, 8 }, true },
767 { { 2, 9 }, true }, { { 18, 9 }, true }, { { 2, 10 }, true }, { { 18, 10 }, true },
768 { { 2, 11 }, true }, { { 18, 11 }, true }, { { 2, 12 }, true }, { { 18, 12 }, true },
769 { { 3, 13 }, true }, { { 17, 13 }, true }, { { 3, 14 }, true }, { { 17, 14 }, true },
770 { { 4, 15 }, true }, { { 16, 15 }, true }, { { 5, 16 }, true }, { { 15, 16 }, true },
771 { { 6, 17 }, true }, { { 7, 17 }, true }, { { 13, 17 }, true }, { { 14, 17 }, true },
772 { { 8, 18 }, true }, { { 9, 18 }, true }, { { 10, 18 }, true }, { { 11, 18 }, true },
773 { { 12, 18 }, true } };
775 for (tools::Long x = 0; x < pAccess->Width(); x++)
777 for (tools::Long y = 0; y < pAccess->Height(); y++)
779 if (SetPixels[{ x, y }])
781 if (aEnableAA)
783 // coverity[swapped_arguments : FALSE] - this is in the correct order
784 checkValueAA(pAccess, y, x, constLineColor, nNumberOfQuirks, nNumberOfErrors);
786 else
787 checkValue(pAccess, y, x, constLineColor, nNumberOfQuirks, nNumberOfErrors,
788 true);
790 else
792 if (!aEnableAA)
793 checkValue(pAccess, y, x, constBackgroundColor, nNumberOfQuirks, nNumberOfErrors,
794 true);
799 if (nNumberOfQuirks > 0)
800 aResult = TestResult::PassedWithQuirks;
801 if (nNumberOfErrors > 0)
802 aResult = TestResult::Failed;
803 return aResult;
806 void OutputDeviceTestCommon::createHorizontalVerticalDiagonalLinePoints(tools::Rectangle rRect,
807 Point& rHorizontalLinePoint1, Point& rHorizontalLinePoint2,
808 Point& rVerticalLinePoint1, Point& rVerticalLinePoint2,
809 Point& rDiagonalLinePoint1, Point& rDiagonalLinePoint2)
811 rHorizontalLinePoint1 = Point(4, 1);
812 rHorizontalLinePoint2 = Point(rRect.Right() - 1, 1);
814 rVerticalLinePoint1 = Point(1, 4);
815 rVerticalLinePoint2 = Point(1,rRect.Bottom() - 1);
817 rDiagonalLinePoint1 = Point(1, 1);
818 rDiagonalLinePoint2 = Point(rRect.Right() - 1, rRect.Bottom() - 1);
821 TestResult OutputDeviceTestCommon::checkBezier(Bitmap& rBitmap)
823 std::vector<Color> aExpected
825 constBackgroundColor, constBackgroundColor
827 // Check the bezier doesn't go over to the margins first
828 // TODO extend the check with more exact assert
829 return checkRectangles(rBitmap, aExpected);
832 TestResult OutputDeviceTestCommon::checkHalfEllipse(Bitmap& rBitmap, bool aEnableAA)
834 BitmapScopedWriteAccess pAccess(rBitmap);
836 TestResult aResult = TestResult::Passed;
837 int nNumberOfQuirks = 0;
838 int nNumberOfErrors = 0;
840 std::map<std::pair<tools::Long, tools::Long>, bool> SetPixels = {
841 { { 8, 1 }, true }, { { 9, 1 }, true }, { { 10, 1 }, true }, { { 6, 2 }, true },
842 { { 7, 2 }, true }, { { 10, 2 }, true }, { { 4, 3 }, true }, { { 5, 3 }, true },
843 { { 10, 3 }, true }, { { 3, 4 }, true }, { { 10, 4 }, true }, { { 2, 5 }, true },
844 { { 10, 5 }, true }, { { 2, 6 }, true }, { { 10, 6 }, true }, { { 1, 7 }, true },
845 { { 10, 7 }, true }, { { 1, 8 }, true }, { { 10, 8 }, true }, { { 1, 9 }, true },
846 { { 10, 9 }, true }, { { 1, 10 }, true }, { { 10, 10 }, true }, { { 1, 11 }, true },
847 { { 10, 11 }, true }, { { 2, 12 }, true }, { { 10, 12 }, true }, { { 2, 13 }, true },
848 { { 10, 13 }, true }, { { 3, 14 }, true }, { { 10, 14 }, true }, { { 4, 15 }, true },
849 { { 5, 15 }, true }, { { 10, 15 }, true }, { { 6, 16 }, true }, { { 7, 16 }, true },
850 { { 10, 16 }, true }, { { 8, 17 }, true }, { { 9, 17 }, true }, { { 10, 17 }, true }
853 for (tools::Long x = 0; x < pAccess->Width(); x++)
855 for (tools::Long y = 0; y < pAccess->Height(); ++y)
857 // coverity[swapped_arguments : FALSE] - this is in the correct order
858 if (SetPixels[{ y, x }])
860 if (aEnableAA)
861 checkValueAA(pAccess, x, y, constLineColor, nNumberOfQuirks, nNumberOfErrors);
862 else
863 checkValue(pAccess, x, y, constLineColor, nNumberOfQuirks, nNumberOfErrors,
864 true);
866 else
868 if (!aEnableAA)
869 checkValue(pAccess, x, y, constBackgroundColor, nNumberOfQuirks,
870 nNumberOfErrors, true);
875 if (nNumberOfQuirks > 0)
876 aResult = TestResult::PassedWithQuirks;
877 if (nNumberOfErrors > 0)
878 aResult = TestResult::Failed;
879 return aResult;
882 TestResult OutputDeviceTestCommon::checkClosedBezier(Bitmap& rBitmap)
884 BitmapScopedWriteAccess pAccess(rBitmap);
886 TestResult aResult = TestResult::Passed;
887 int nNumberOfQuirks = 0;
888 int nNumberOfErrors = 0;
890 std::map<std::pair<tools::Long, tools::Long>, bool> SetPixels
891 = { { { 3, 8 }, true }, { { 3, 9 }, true }, { { 3, 10 }, true }, { { 4, 7 }, true },
892 { { 4, 8 }, true }, { { 4, 9 }, true }, { { 4, 10 }, true }, { { 4, 11 }, true },
893 { { 5, 7 }, true }, { { 5, 11 }, true }, { { 6, 6 }, true }, { { 6, 12 }, true },
894 { { 7, 6 }, true }, { { 7, 12 }, true }, { { 8, 7 }, true }, { { 8, 11 }, true },
895 { { 9, 7 }, true }, { { 9, 11 }, true }, { { 10, 7 }, true }, { { 10, 11 }, true },
896 { { 11, 8 }, true }, { { 11, 9 }, true }, { { 11, 10 }, true }, { { 12, 8 }, true },
897 { { 12, 9 }, true }, { { 12, 10 }, true }, { { 13, 9 }, true } };
899 for (tools::Long x = 0; x < pAccess->Width(); x++)
901 for (tools::Long y = 0; y < pAccess->Height(); ++y)
903 // coverity[swapped_arguments : FALSE] - this is in the correct order
904 if (SetPixels[{ y, x }])
906 checkValue(pAccess, x, y, constLineColor, nNumberOfQuirks, nNumberOfErrors, true);
908 else
910 checkValue(pAccess, x, y, constBackgroundColor, nNumberOfQuirks, nNumberOfErrors,
911 true);
916 if (nNumberOfQuirks > 0)
917 aResult = TestResult::PassedWithQuirks;
918 if (nNumberOfErrors > 0 || !checkConvexHullProperty(rBitmap, constLineColor, 2, 2))
919 aResult = TestResult::Failed;
920 return aResult;
923 TestResult OutputDeviceTestCommon::checkOpenBezier(Bitmap& rBitmap)
925 BitmapScopedWriteAccess pAccess(rBitmap);
927 TestResult aResult = TestResult::Passed;
928 int nNumberOfQuirks = 0;
929 int nNumberOfErrors = 0;
931 std::map<std::pair<int, int>, bool> SetPixels
932 = { { { 14, 3 }, true }, { { 14, 4 }, true }, { { 14, 5 }, true }, { { 3, 6 }, true },
933 { { 4, 6 }, true }, { { 14, 6 }, true }, { { 4, 7 }, true }, { { 5, 7 }, true },
934 { { 13, 7 }, true }, { { 6, 8 }, true }, { { 7, 8 }, true }, { { 12, 8 }, true },
935 { { 13, 8 }, true }, { { 8, 9 }, true }, { { 9, 9 }, true }, { { 10, 9 }, true },
936 { { 11, 9 }, true }, { { 12, 9 }, true } };
938 for (tools::Long x = 0; x < pAccess->Width(); x++)
940 for (tools::Long y = 0; y < pAccess->Height(); ++y)
942 // coverity[swapped_arguments : FALSE] - this is in the correct order
943 if (SetPixels[{ y, x }])
945 checkValue(pAccess, x, y, constLineColor, nNumberOfQuirks, nNumberOfErrors, true);
947 else
949 checkValue(pAccess, x, y, constBackgroundColor, nNumberOfQuirks, nNumberOfErrors,
950 true);
954 if (nNumberOfQuirks > 0)
955 aResult = TestResult::PassedWithQuirks;
956 if (nNumberOfErrors > 0 || !checkConvexHullProperty(rBitmap, constLineColor, 2, 5))
957 aResult = TestResult::Failed;
958 return aResult;
961 TestResult OutputDeviceTestCommon::checkFilledAsymmetricalDropShape(Bitmap& rBitmap)
963 BitmapScopedWriteAccess pAccess(rBitmap);
965 TestResult aResult = TestResult::Passed;
966 int nNumberOfQuirks = 0;
967 int nNumberOfErrors = 0;
969 std::map<std::pair<tools::Long, tools::Long>, bool> SetPixels
970 = { { { 2, 2 }, true }, { { 3, 2 }, true }, { { 4, 2 }, true }, { { 5, 2 }, true },
971 { { 6, 2 }, true }, { { 7, 2 }, true }, { { 8, 2 }, true }, { { 9, 2 }, true },
972 { { 10, 2 }, true }, { { 11, 2 }, true }, { { 2, 3 }, true }, { { 3, 3 }, true },
973 { { 4, 3 }, true }, { { 5, 3 }, true }, { { 6, 3 }, true }, { { 7, 3 }, true },
974 { { 8, 3 }, true }, { { 9, 3 }, true }, { { 10, 3 }, true }, { { 11, 3 }, true },
975 { { 12, 3 }, true }, { { 13, 3 }, true }, { { 2, 4 }, true }, { { 3, 4 }, true },
976 { { 4, 4 }, true }, { { 5, 4 }, true }, { { 6, 4 }, true }, { { 7, 4 }, true },
977 { { 8, 4 }, true }, { { 9, 4 }, true }, { { 10, 4 }, true }, { { 11, 4 }, true },
978 { { 12, 4 }, true }, { { 13, 4 }, true }, { { 14, 4 }, true }, { { 15, 4 }, true },
979 { { 2, 5 }, true }, { { 3, 5 }, true }, { { 4, 5 }, true }, { { 5, 5 }, true },
980 { { 6, 5 }, true }, { { 7, 5 }, true }, { { 8, 5 }, true }, { { 9, 5 }, true },
981 { { 10, 5 }, true }, { { 11, 5 }, true }, { { 12, 5 }, true }, { { 13, 5 }, true },
982 { { 14, 5 }, true }, { { 15, 5 }, true }, { { 2, 6 }, true }, { { 3, 6 }, true },
983 { { 4, 6 }, true }, { { 5, 6 }, true }, { { 6, 6 }, true }, { { 7, 6 }, true },
984 { { 8, 6 }, true }, { { 9, 6 }, true }, { { 10, 6 }, true }, { { 11, 6 }, true },
985 { { 12, 6 }, true }, { { 13, 6 }, true }, { { 14, 6 }, true }, { { 15, 6 }, true },
986 { { 16, 6 }, true }, { { 2, 7 }, true }, { { 3, 7 }, true }, { { 4, 7 }, true },
987 { { 5, 7 }, true }, { { 6, 7 }, true }, { { 7, 7 }, true }, { { 8, 7 }, true },
988 { { 9, 7 }, true }, { { 10, 7 }, true }, { { 11, 7 }, true }, { { 12, 7 }, true },
989 { { 13, 7 }, true }, { { 14, 7 }, true }, { { 15, 7 }, true }, { { 16, 7 }, true },
990 { { 2, 8 }, true }, { { 3, 8 }, true }, { { 4, 8 }, true }, { { 5, 8 }, true },
991 { { 6, 8 }, true }, { { 7, 8 }, true }, { { 8, 8 }, true }, { { 9, 8 }, true },
992 { { 10, 8 }, true }, { { 11, 8 }, true }, { { 12, 8 }, true }, { { 13, 8 }, true },
993 { { 14, 8 }, true }, { { 15, 8 }, true }, { { 16, 8 }, true }, { { 17, 8 }, true },
994 { { 2, 9 }, true }, { { 3, 9 }, true }, { { 4, 9 }, true }, { { 5, 9 }, true },
995 { { 6, 9 }, true }, { { 7, 9 }, true }, { { 8, 9 }, true }, { { 9, 9 }, true },
996 { { 10, 9 }, true }, { { 11, 9 }, true }, { { 12, 9 }, true }, { { 13, 9 }, true },
997 { { 14, 9 }, true }, { { 15, 9 }, true }, { { 16, 9 }, true }, { { 17, 9 }, true },
998 { { 2, 10 }, true }, { { 3, 10 }, true }, { { 4, 10 }, true }, { { 5, 10 }, true },
999 { { 6, 10 }, true }, { { 7, 10 }, true }, { { 8, 10 }, true }, { { 9, 10 }, true },
1000 { { 10, 10 }, true }, { { 11, 10 }, true }, { { 12, 10 }, true }, { { 13, 10 }, true },
1001 { { 14, 10 }, true }, { { 15, 10 }, true }, { { 16, 10 }, true }, { { 17, 10 }, true },
1002 { { 2, 11 }, true }, { { 3, 11 }, true }, { { 4, 11 }, true }, { { 5, 11 }, true },
1003 { { 6, 11 }, true }, { { 7, 11 }, true }, { { 8, 11 }, true }, { { 9, 11 }, true },
1004 { { 10, 11 }, true }, { { 11, 11 }, true }, { { 12, 11 }, true }, { { 13, 11 }, true },
1005 { { 14, 11 }, true }, { { 15, 11 }, true }, { { 16, 11 }, true }, { { 17, 11 }, true },
1006 { { 3, 12 }, true }, { { 4, 12 }, true }, { { 5, 12 }, true }, { { 6, 12 }, true },
1007 { { 7, 12 }, true }, { { 8, 12 }, true }, { { 9, 12 }, true }, { { 10, 12 }, true },
1008 { { 11, 12 }, true }, { { 12, 12 }, true }, { { 13, 12 }, true }, { { 14, 12 }, true },
1009 { { 15, 12 }, true }, { { 16, 12 }, true }, { { 3, 13 }, true }, { { 4, 13 }, true },
1010 { { 5, 13 }, true }, { { 6, 13 }, true }, { { 7, 13 }, true }, { { 8, 13 }, true },
1011 { { 9, 13 }, true }, { { 10, 13 }, true }, { { 11, 13 }, true }, { { 12, 13 }, true },
1012 { { 13, 13 }, true }, { { 14, 13 }, true }, { { 15, 13 }, true }, { { 16, 13 }, true },
1013 { { 4, 14 }, true }, { { 5, 14 }, true }, { { 6, 14 }, true }, { { 7, 14 }, true },
1014 { { 8, 14 }, true }, { { 9, 14 }, true }, { { 10, 14 }, true }, { { 11, 14 }, true },
1015 { { 12, 14 }, true }, { { 13, 14 }, true }, { { 14, 14 }, true }, { { 15, 14 }, true },
1016 { { 5, 15 }, true }, { { 6, 15 }, true }, { { 7, 15 }, true }, { { 8, 15 }, true },
1017 { { 9, 15 }, true }, { { 10, 15 }, true }, { { 11, 15 }, true }, { { 12, 15 }, true },
1018 { { 13, 15 }, true }, { { 14, 15 }, true }, { { 15, 15 }, true }, { { 6, 16 }, true },
1019 { { 7, 16 }, true }, { { 8, 16 }, true }, { { 9, 16 }, true }, { { 10, 16 }, true },
1020 { { 11, 16 }, true }, { { 12, 16 }, true }, { { 13, 16 }, true }, { { 8, 17 }, true },
1021 { { 9, 17 }, true }, { { 10, 17 }, true }, { { 11, 17 }, true } };
1023 for (tools::Long x = 0; x < pAccess->Width(); x++)
1025 for (tools::Long y = 0; y < pAccess->Height(); ++y)
1027 if (SetPixels[{ x, y }])
1029 checkValue(pAccess, y, x, constFillColor, nNumberOfQuirks, nNumberOfErrors, true);
1031 else
1033 checkValue(pAccess, y, x, constBackgroundColor, nNumberOfQuirks, nNumberOfErrors, true);
1038 if (nNumberOfQuirks > 0)
1039 aResult = TestResult::PassedWithQuirks;
1040 if (nNumberOfErrors > 0)
1041 aResult = TestResult::Failed;
1042 return aResult;
1045 TestResult OutputDeviceTestCommon::checkTextLocation(Bitmap& rBitmap)
1047 BitmapScopedWriteAccess pAccess(rBitmap);
1049 TestResult aResult = TestResult::Passed;
1051 //The limit to which error would be tolerated.
1052 tools::Long textThreshold = 3;
1053 tools::Long textWidth = 3, textHeight = 8;
1054 tools::Long deviationX = 0, deviationY = 0;
1055 tools::Long verticalStart = 0, verticalEnd = 0;
1056 tools::Long horizontalStart = 0, horizontalEnd = 0;
1057 tools::Long midX = pAccess->Width() / 2.0;
1058 tools::Long midY = pAccess->Height() / 2.0;
1059 bool insideFlag = false;
1061 //Traversing horizontally
1062 for (tools::Long x = 0, y = pAccess->Height() / 2.0; x < pAccess->Width(); ++x)
1064 if (pAccess->GetPixel(y, x) != constBackgroundColor)
1066 if (!insideFlag)
1068 horizontalStart = x;
1069 insideFlag = true;
1071 else
1073 horizontalEnd = x;
1078 deviationX = abs(midX - horizontalStart);
1079 midY -= midY / 2.0;
1080 midY += 1;
1082 insideFlag = false;
1083 //Traversing vertically
1084 for (tools::Long x = 0, y = pAccess->Height() / 2.0; x < pAccess->Height(); ++x)
1086 if (pAccess->GetPixel(x, y) != constBackgroundColor)
1088 if (!insideFlag)
1090 verticalStart = x;
1091 insideFlag = true;
1093 else
1095 verticalEnd = x;
1100 deviationY = abs(midY - verticalStart);
1102 if (deviationX != 0 || deviationY != 0 || abs(horizontalStart - horizontalEnd) + 1 != textWidth
1103 || abs(verticalStart - verticalEnd) + 1 != textHeight)
1105 aResult = TestResult::PassedWithQuirks;
1108 if (deviationX > textThreshold || deviationY > textThreshold
1109 || abs((abs(horizontalStart - horizontalEnd) + 1) - textWidth) > textThreshold
1110 || abs((abs(verticalStart - verticalEnd) + 1) - textHeight) > textThreshold)
1112 aResult = TestResult::Failed;
1115 return aResult;
1118 TestResult OutputDeviceTestCommon::checkIntersectingRecs(Bitmap& rBitmap, int aLayerNumber,
1119 Color aExpected)
1121 BitmapScopedWriteAccess pAccess(rBitmap);
1123 TestResult aResult = TestResult::Passed;
1124 int nNumberOfQuirks = 0;
1125 int nNumberOfErrors = 0;
1127 for (int x = 4; x <= 19; ++x)
1129 checkValue(pAccess, x, aLayerNumber, aExpected, nNumberOfQuirks, nNumberOfErrors, true);
1132 if (nNumberOfQuirks > 0)
1133 aResult = TestResult::PassedWithQuirks;
1134 if (nNumberOfErrors > 0)
1135 aResult = TestResult::Failed;
1136 return aResult;
1139 TestResult OutputDeviceTestCommon::checkEvenOddRuleInIntersectingRecs(Bitmap& rBitmap)
1142 The even-odd rule would be tested via the below pattern as layers both of the
1143 constFillColor & constBackgroundColor appears in an even-odd fashion.
1145 std::vector<Color> aExpectedColors
1146 = { constBackgroundColor, constBackgroundColor, constLineColor, constFillColor,
1147 constFillColor, constLineColor, constBackgroundColor, constBackgroundColor,
1148 constLineColor, constFillColor, constFillColor, constLineColor,
1149 constBackgroundColor, constBackgroundColor, constLineColor, constFillColor,
1150 constFillColor, constLineColor, constBackgroundColor, constBackgroundColor,
1151 constLineColor, constFillColor, constLineColor };
1153 TestResult aReturnValue = TestResult::Passed;
1154 for (size_t i = 0; i < aExpectedColors.size(); i++)
1156 TestResult eResult = checkIntersectingRecs(rBitmap, i, aExpectedColors[i]);
1158 if (eResult == TestResult::Failed)
1159 aReturnValue = TestResult::Failed;
1160 if (eResult == TestResult::PassedWithQuirks && aReturnValue != TestResult::Failed)
1161 aReturnValue = TestResult::PassedWithQuirks;
1163 return aReturnValue;
1166 TestResult OutputDeviceTestCommon::checkOpenPolygon(Bitmap& rBitmap, bool aEnableAA)
1168 std::vector<Color> aExpected = { constBackgroundColor, constLineColor, constLineColor };
1170 BitmapScopedWriteAccess pAccess(rBitmap);
1172 TestResult aResult = TestResult::Passed;
1173 int nNumberOfQuirks = 0;
1174 int nNumberOfErrors = 0;
1176 for (size_t aLayerNumber = 0; aLayerNumber < aExpected.size(); aLayerNumber++)
1178 tools::Long startX = aLayerNumber + 1, endX = pAccess->Width() / 2 - aLayerNumber;
1179 tools::Long startY = aLayerNumber + 2, endY = pAccess->Height() - aLayerNumber - 3;
1181 for (tools::Long ptX = startX; ptX <= endX; ++ptX)
1183 if (aEnableAA)
1185 checkValueAA(pAccess, ptX, endY - (aLayerNumber == 2 ? 2 : 0),
1186 aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors);
1188 else
1190 checkValue(pAccess, ptX, endY - (aLayerNumber == 2 ? 2 : 0),
1191 aExpected[aLayerNumber], nNumberOfQuirks, nNumberOfErrors, true);
1194 for (tools::Long ptY = startY + (aLayerNumber == 2 ? 2 : 0);
1195 ptY <= endY - (aLayerNumber == 2 ? 2 : 0); ++ptY)
1197 if (aEnableAA)
1199 checkValueAA(pAccess, startX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
1200 nNumberOfErrors);
1201 checkValueAA(pAccess, endX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
1202 nNumberOfErrors);
1204 else
1206 checkValue(pAccess, startX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
1207 nNumberOfErrors, true);
1208 checkValue(pAccess, endX, ptY, aExpected[aLayerNumber], nNumberOfQuirks,
1209 nNumberOfErrors, true);
1214 if (nNumberOfQuirks > 0)
1215 aResult = TestResult::PassedWithQuirks;
1216 if (nNumberOfErrors > 0)
1217 aResult = TestResult::Failed;
1218 return aResult;
1221 // Check 'count' pixels from (x,y) in (addX,addY) direction, the color values must not decrease.
1222 static bool checkGradient(BitmapScopedWriteAccess& pAccess, int x, int y, int count, int addX, int addY)
1224 const bool bColorize = false;
1225 Color maxColor = COL_BLACK;
1226 for( int i = 0; i < count; ++i )
1228 Color color = pAccess->GetPixel(y, x);
1229 if( color.GetRed() < maxColor.GetRed() || color.GetGreen() < maxColor.GetGreen() || color.GetBlue() < maxColor.GetBlue())
1231 if (bColorize)
1232 pAccess->SetPixel(y, x, COL_RED);
1233 return false;
1235 maxColor = color;
1236 if (bColorize)
1237 pAccess->SetPixel(y, x, COL_LIGHTGREEN);
1238 x += addX;
1239 y += addY;
1241 return true;
1244 TestResult OutputDeviceTestCommon::checkLinearGradient(Bitmap& bitmap)
1246 BitmapScopedWriteAccess pAccess(bitmap);
1247 TestResult aResult = TestResult::Passed;
1248 int nNumberOfQuirks = 0;
1249 int nNumberOfErrors = 0;
1251 // The lowest line is missing in the default VCL implementation => quirk.
1252 checkValue(pAccess, 1, 10, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, true, 255 / 10);
1253 checkValue(pAccess, 10, 10, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, true, 255 / 10);
1254 for(int y = 1; y < 10; ++y)
1256 checkValue(pAccess, 1, y, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10);
1257 checkValue(pAccess, 10, y, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10);
1259 for(int y = 1; y < 10; ++y)
1260 if( !checkGradient( pAccess, 10, y, 10, -1, 0 ))
1261 return TestResult::Failed;
1262 if (nNumberOfQuirks > 0)
1263 checkResult(TestResult::PassedWithQuirks, aResult);
1264 if (nNumberOfErrors > 0)
1265 checkResult(TestResult::Failed, aResult);
1266 return aResult;
1269 TestResult OutputDeviceTestCommon::checkLinearGradientAngled(Bitmap& bitmap)
1271 BitmapScopedWriteAccess pAccess(bitmap);
1272 TestResult aResult = TestResult::Passed;
1273 int nNumberOfQuirks = 0;
1274 int nNumberOfErrors = 0;
1276 // The top-left pixel is not white but gray in the default VCL implementation => quirk.
1277 checkValue(pAccess, 1, 1, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 50);
1278 checkValue(pAccess, 10, 10, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 0, 255 / 10); // Bottom-right.
1279 // Main diagonal.
1280 if( !checkGradient( pAccess, 10, 10, 10, -1, -1 ))
1281 return TestResult::Failed;
1282 if (nNumberOfQuirks > 0)
1283 checkResult(TestResult::PassedWithQuirks, aResult);
1284 if (nNumberOfErrors > 0)
1285 checkResult(TestResult::Failed, aResult);
1286 return TestResult::Passed;
1289 TestResult OutputDeviceTestCommon::checkLinearGradientBorder(Bitmap& bitmap)
1291 TestResult aResult = TestResult::Passed;
1292 // Top half is border.
1293 checkResult(checkFilled(bitmap, tools::Rectangle(Point(1, 1), Size(10, 5)), COL_WHITE), aResult);
1294 BitmapScopedWriteAccess pAccess(bitmap);
1295 int nNumberOfQuirks = 0;
1296 int nNumberOfErrors = 0;
1297 for(int x = 1; x <= 10; ++x)
1299 checkValue(pAccess, x, 10, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1300 if( !checkGradient( pAccess, x, 10, 5, 0, -1 ))
1301 return TestResult::Failed;
1303 if (nNumberOfQuirks > 0)
1304 checkResult(TestResult::PassedWithQuirks, aResult);
1305 if (nNumberOfErrors > 0)
1306 checkResult(TestResult::Failed, aResult);
1307 return aResult;
1310 TestResult OutputDeviceTestCommon::checkLinearGradientIntensity(Bitmap& bitmap)
1312 BitmapScopedWriteAccess pAccess(bitmap);
1313 TestResult aResult = TestResult::Passed;
1314 int nNumberOfQuirks = 0;
1315 int nNumberOfErrors = 0;
1317 for(int x = 1; x <= 10; ++x)
1319 // The gradient starts at half intensity, i.e. white's 255's are halved.
1320 checkValue(pAccess, x, 1, Color(128,128,128), nNumberOfQuirks, nNumberOfErrors, false, 10);
1321 checkValue(pAccess, x, 10, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10);
1322 if( !checkGradient( pAccess, x, 10, 10, 0, -1 ))
1323 return TestResult::Failed;
1325 if (nNumberOfQuirks > 0)
1326 checkResult(TestResult::PassedWithQuirks, aResult);
1327 if (nNumberOfErrors > 0)
1328 checkResult(TestResult::Failed, aResult);
1329 return aResult;
1332 TestResult OutputDeviceTestCommon::checkLinearGradientSteps(Bitmap& bitmap)
1334 // Reuse the basic linear gradient check.
1335 TestResult aResult = checkLinearGradient(bitmap);
1336 // Only 4 steps in the gradient, there should be only 4 colors.
1337 if( collectColors( bitmap, tools::Rectangle( Point( 1, 1 ), Size( 10, 10 ))).size() != 4 )
1338 return TestResult::Failed;
1339 return aResult;
1342 TestResult OutputDeviceTestCommon::checkAxialGradient(Bitmap& bitmap)
1344 BitmapScopedWriteAccess pAccess(bitmap);
1345 TestResult aResult = TestResult::Passed;
1346 int nNumberOfQuirks = 0;
1347 int nNumberOfErrors = 0;
1349 for(int y = 1; y <= 11; ++y)
1351 // Middle horizontal line is white, gradients to the sides.
1352 checkValue(pAccess, 6, y, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1353 checkValue(pAccess, 1, y, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1354 checkValue(pAccess, 11, y, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1355 if( !checkGradient( pAccess, 1, y, 6, 1, 0 ))
1356 return TestResult::Failed;
1357 if( !checkGradient( pAccess, 11, y, 6, -1, 0 ))
1358 return TestResult::Failed;
1360 if (nNumberOfQuirks > 0)
1361 checkResult(TestResult::PassedWithQuirks, aResult);
1362 if (nNumberOfErrors > 0)
1363 checkResult(TestResult::Failed, aResult);
1364 return aResult;
1367 TestResult OutputDeviceTestCommon::checkRadialGradient(Bitmap& bitmap)
1369 BitmapScopedWriteAccess pAccess(bitmap);
1370 TestResult aResult = TestResult::Passed;
1371 int nNumberOfQuirks = 0;
1372 int nNumberOfErrors = 0;
1373 // The default VCL implementation is off-center in the direction to the top-left.
1374 // This means not all corners will be pure white => quirks.
1375 checkValue(pAccess, 1, 1, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 2);
1376 checkValue(pAccess, 1, 10, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1377 checkValue(pAccess, 10, 1, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1378 checkValue(pAccess, 10, 10, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1379 // And not all centers will be pure black => quirks.
1380 checkValue(pAccess, 5, 5, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1381 checkValue(pAccess, 5, 6, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 3);
1382 checkValue(pAccess, 6, 5, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 3);
1383 checkValue(pAccess, 6, 6, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 2);
1384 // Check diagonals, from the offset center.
1385 if(!checkGradient(pAccess, 5, 5, 5, -1, -1))
1386 return TestResult::Failed;
1387 if(!checkGradient(pAccess, 5, 5, 6, 1, 1))
1388 return TestResult::Failed;
1389 if(!checkGradient(pAccess, 5, 5, 5, 1, -1))
1390 return TestResult::Failed;
1391 if(!checkGradient(pAccess, 5, 5, 5, -1, 1))
1392 return TestResult::Failed;
1393 if (nNumberOfQuirks > 0)
1394 checkResult(TestResult::PassedWithQuirks, aResult);
1395 if (nNumberOfErrors > 0)
1396 checkResult(TestResult::Failed, aResult);
1397 return aResult;
1400 TestResult OutputDeviceTestCommon::checkRadialGradientOfs(Bitmap& bitmap)
1402 BitmapScopedWriteAccess pAccess(bitmap);
1403 TestResult aResult = TestResult::Passed;
1404 int nNumberOfQuirks = 0;
1405 int nNumberOfErrors = 0;
1406 checkValue(pAccess, 1, 1, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1407 checkValue(pAccess, 10, 1, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1408 checkValue(pAccess, 1, 10, COL_WHITE, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1409 checkValue(pAccess, 10, 10, COL_BLACK, nNumberOfQuirks, nNumberOfErrors, 255 / 10, 255 / 5);
1410 // Check gradients from the center (=bottom-right corner).
1411 if(!checkGradient(pAccess, 10, 10, 10, -1, -1))
1412 return TestResult::Failed;
1413 if(!checkGradient(pAccess, 10, 10, 10, -1, 0))
1414 return TestResult::Failed;
1415 if(!checkGradient(pAccess, 10, 10, 10, 0, -1))
1416 return TestResult::Failed;
1417 if (nNumberOfQuirks > 0)
1418 checkResult(TestResult::PassedWithQuirks, aResult);
1419 if (nNumberOfErrors > 0)
1420 checkResult(TestResult::Failed, aResult);
1421 return aResult;
1424 constexpr int CAPSHRINK = 25;
1425 constexpr int CAPWIDTH = 20;
1426 TestResult OutputDeviceTestCommon::checkLineCap(Bitmap& rBitmap, css::drawing::LineCap lineCap)
1428 BitmapScopedWriteAccess access(rBitmap);
1429 tools::Rectangle rectangle( Point( 0, 0 ), Size( 101, 101 ));
1430 rectangle.shrink(CAPSHRINK);
1431 rectangle = tools::Rectangle( Point(rectangle.LeftCenter().getX(), rectangle.LeftCenter().getY() - CAPWIDTH / 2),
1432 Point(rectangle.RightCenter().getX(), rectangle.RightCenter().getY() + CAPWIDTH / 2));
1433 rectangle.shrink(1);
1434 TestResult aResult = TestResult::Passed;
1435 int nNumberOfQuirks = 0;
1436 int nNumberOfErrors = 0;
1438 // the line itself
1439 checkValue(access, rectangle.TopLeft(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1440 checkValue(access, rectangle.TopRight(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1441 checkValue(access, rectangle.BottomLeft(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1442 checkValue(access, rectangle.BottomRight(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1444 // the cap in the middle
1445 Color color = ( lineCap == css::drawing::LineCap_BUTT ) ? constBackgroundColor : constLineColor;
1446 checkValue(access, rectangle.LeftCenter() - Point(CAPWIDTH/2, 0), color, nNumberOfQuirks, nNumberOfErrors, false);
1447 checkValue(access, rectangle.RightCenter() + Point(CAPWIDTH/2, 0), color, nNumberOfQuirks, nNumberOfErrors, false);
1449 // the cap corners
1450 color = ( lineCap == css::drawing::LineCap_SQUARE ) ? constLineColor : constBackgroundColor;
1451 checkValue(access, rectangle.TopLeft() - Point(CAPWIDTH/2, 0), color, nNumberOfQuirks, nNumberOfErrors, false);
1452 checkValue(access, rectangle.TopRight() + Point(CAPWIDTH/2, 0), color, nNumberOfQuirks, nNumberOfErrors, false);
1453 checkValue(access, rectangle.BottomLeft() - Point(CAPWIDTH/2, 0), color, nNumberOfQuirks, nNumberOfErrors, false);
1454 checkValue(access, rectangle.BottomRight() + Point(CAPWIDTH/2, 0), color, nNumberOfQuirks, nNumberOfErrors, false);
1456 if (nNumberOfQuirks > 0)
1457 checkResult(TestResult::PassedWithQuirks, aResult);
1458 if (nNumberOfErrors > 0)
1459 checkResult(TestResult::Failed, aResult);
1460 return aResult;
1463 TestResult OutputDeviceTestCommon::checkLineJoin(Bitmap& rBitmap, basegfx::B2DLineJoin lineJoin)
1465 BitmapScopedWriteAccess access(rBitmap);
1466 tools::Rectangle rectangle( Point( 0, 0 ), Size( 101, 101 ));
1467 rectangle.shrink(CAPSHRINK);
1468 tools::Rectangle rectangle1( Point(rectangle.TopLeft().getX(), rectangle.TopLeft().getY() - CAPWIDTH / 2),
1469 Point(rectangle.TopRight().getX(), rectangle.TopRight().getY() + CAPWIDTH / 2));
1470 tools::Rectangle rectangle2( Point(rectangle.TopRight().getX() - CAPWIDTH / 2, rectangle.TopRight().getY()),
1471 Point(rectangle.BottomRight().getX() + CAPWIDTH / 2, rectangle.BottomRight().getY()));
1472 rectangle1.shrink(1);
1473 rectangle2.shrink(1);
1474 TestResult aResult = TestResult::Passed;
1475 int nNumberOfQuirks = 0;
1476 int nNumberOfErrors = 0;
1478 // the lines themselves
1479 checkValue(access, rectangle1.TopLeft(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1480 checkValue(access, rectangle1.TopRight(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1481 checkValue(access, rectangle1.BottomLeft(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1482 checkValue(access, rectangle1.BottomRight(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1483 checkValue(access, rectangle2.TopLeft(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1484 checkValue(access, rectangle2.TopRight(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1485 checkValue(access, rectangle2.BottomLeft(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1486 checkValue(access, rectangle2.BottomRight(), constLineColor, nNumberOfQuirks, nNumberOfErrors, false);
1488 // Only miter has the corner point.
1489 Color color = ( lineJoin == basegfx::B2DLineJoin::Miter ) ? constLineColor : constBackgroundColor;
1490 checkValue(access, rectangle2.Right(), rectangle1.Top(), color, nNumberOfQuirks, nNumberOfErrors, false);
1492 // Round reaches a bit past the diagonal.
1493 Point midDiagonal = (Point( rectangle2.Right(), rectangle1.Top()) + rectangle.TopRight()) / 2;
1494 if( lineJoin == basegfx::B2DLineJoin::Round)
1495 color = constLineColor;
1496 checkValue(access, midDiagonal + Point( 2, -2 ), color, nNumberOfQuirks, nNumberOfErrors, false);
1497 // Bevel is the diagonal.
1498 if( lineJoin == basegfx::B2DLineJoin::Bevel)
1499 color = constLineColor;
1500 checkValue(access, midDiagonal + Point( -1, 1 ), color, nNumberOfQuirks, nNumberOfErrors, false);
1501 // Everything except None has at least some line join.
1502 checkValue(access, rectangle.TopRight() + Point( 1, -1 ), color, nNumberOfQuirks, nNumberOfErrors, false);
1504 if (nNumberOfQuirks > 0)
1505 checkResult(TestResult::PassedWithQuirks, aResult);
1506 if (nNumberOfErrors > 0)
1507 checkResult(TestResult::Failed, aResult);
1508 return aResult;
1511 TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDev(Bitmap& rBitmap)
1513 std::vector<Color> aExpected
1515 constBackgroundColor, constBackgroundColor,
1516 constFillColor, constFillColor, constFillColor, constFillColor, constFillColor
1518 return checkRectangles(rBitmap, aExpected);
1521 TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDevScaledClipped(Bitmap& rBitmap)
1523 TestResult aReturnValue = TestResult::Passed;
1524 TestResult eResult;
1526 eResult = checkRect(rBitmap, 0, constBackgroundColor); // outer line
1527 checkResult(eResult, aReturnValue);
1528 eResult = checkRect(rBitmap, 1, constBackgroundColor); // next outer line
1529 checkResult(eResult, aReturnValue);
1530 eResult = checkFilled(rBitmap, tools::Rectangle(Point(2, 2), Size(4, 8)), constBackgroundColor);
1531 checkResult(eResult, aReturnValue);
1532 eResult = checkFilled(rBitmap, tools::Rectangle(Point(6, 2), Size(4, 8)), constFillColor);
1533 checkResult(eResult, aReturnValue);
1535 return aReturnValue;
1538 TestResult OutputDeviceTestAnotherOutDev::checkDrawOutDevSelf(Bitmap& rBitmap)
1540 TestResult aReturnValue = TestResult::Passed;
1541 TestResult eResult;
1543 eResult = checkRect(rBitmap, 0, constBackgroundColor); // outer line
1544 checkResult(eResult, aReturnValue);
1545 eResult = checkFilled(rBitmap, tools::Rectangle(Point(1, 1), Size(4, 4)), constBackgroundColor);
1546 checkResult(eResult, aReturnValue);
1547 eResult = checkFilled(rBitmap, tools::Rectangle(Point(8, 8), Size(4, 4)), constBackgroundColor);
1548 checkResult(eResult, aReturnValue);
1550 eResult = checkFilled(rBitmap, tools::Rectangle(Point(11, 1), Size(1, 1)), COL_YELLOW);
1551 checkResult(eResult, aReturnValue);
1552 eResult = checkFilled(rBitmap, tools::Rectangle(Point(7, 5), Size(1, 1)), COL_YELLOW);
1553 checkResult(eResult, aReturnValue);
1554 eResult = checkFilled(rBitmap, tools::Rectangle(Point(1, 11), Size(1, 1)), COL_YELLOW);
1555 checkResult(eResult, aReturnValue);
1557 eResult = checkFilled(rBitmap, tools::Rectangle(Point(1, 5), Size(6, 6)), constFillColor);
1558 checkResult(eResult, aReturnValue);
1559 eResult = checkFilled(rBitmap, tools::Rectangle(Point(2, 6), Size(6, 6)), constFillColor);
1560 checkResult(eResult, aReturnValue);
1561 eResult = checkFilled(rBitmap, tools::Rectangle(Point(5, 1), Size(6, 4)), constFillColor);
1562 checkResult(eResult, aReturnValue);
1563 eResult = checkFilled(rBitmap, tools::Rectangle(Point(8, 2), Size(4, 6)), constFillColor);
1564 checkResult(eResult, aReturnValue);
1566 return aReturnValue;
1569 TestResult OutputDeviceTestAnotherOutDev::checkXOR(Bitmap& rBitmap)
1571 Color xorColor( constBackgroundColor.GetRed() ^ constFillColor.GetRed(),
1572 constBackgroundColor.GetGreen() ^ constFillColor.GetGreen(),
1573 constBackgroundColor.GetBlue() ^ constFillColor.GetBlue());
1574 std::vector<Color> aExpected
1576 constBackgroundColor, xorColor,
1577 constBackgroundColor, constBackgroundColor,
1578 constFillColor, constFillColor,
1579 constFillColor
1581 return checkRectangles(rBitmap, aExpected);
1585 TestResult OutputDeviceTestBitmap::checkTransformedBitmap(Bitmap& rBitmap)
1587 std::vector<Color> aExpected
1589 constBackgroundColor, constBackgroundColor,
1590 COL_YELLOW, constFillColor, COL_YELLOW, constFillColor, constFillColor
1592 return checkRectangles(rBitmap, aExpected);
1595 TestResult OutputDeviceTestBitmap::checkComplexTransformedBitmap(Bitmap& rBitmap)
1597 TestResult aReturnValue = TestResult::Passed;
1598 TestResult eResult;
1599 eResult = checkRectangle(rBitmap, 0, constBackgroundColor); // outer line not affected
1600 checkResult(eResult, aReturnValue);
1601 // empty "corners" should not be affected
1602 eResult = checkFilled(rBitmap, tools::Rectangle(Point(1, 11), Size(2, 2)), constBackgroundColor);
1603 checkResult(eResult, aReturnValue);
1604 eResult = checkFilled(rBitmap, tools::Rectangle(Point(14, 1), Size(2, 2)), constBackgroundColor);
1605 // check the middle
1606 eResult = checkFilled(rBitmap, tools::Rectangle(Point(4, 3), Size(9, 8)), constFillColor);
1607 checkResult(eResult, aReturnValue);
1608 checkResult(eResult, aReturnValue);
1609 int nNumberOfQuirks = 0;
1610 int nNumberOfErrors = 0;
1611 BitmapScopedWriteAccess pAccess(rBitmap);
1612 // starting and ending corner, headless draws with AA, so be lenient
1613 checkValue(pAccess, 1, 1, constFillColor, nNumberOfQuirks, nNumberOfErrors, 0, 192);
1614 checkValue(pAccess, 2, 2, constFillColor, nNumberOfQuirks, nNumberOfErrors, 0, 16);
1615 checkValue(pAccess, 14, 11, constFillColor, nNumberOfQuirks, nNumberOfErrors, 0, 16);
1616 checkValue(pAccess, 15, 12, constFillColor, nNumberOfQuirks, nNumberOfErrors, 0, 192);
1617 if (nNumberOfQuirks > 0)
1618 checkResult(TestResult::PassedWithQuirks, aReturnValue);
1619 if (nNumberOfErrors > 0)
1620 checkResult(TestResult::Failed, aReturnValue);
1621 return aReturnValue;
1624 TestResult OutputDeviceTestBitmap::checkTransformedBitmap8bppGreyScale(Bitmap& rBitmap)
1626 std::vector<Color> aExpected
1628 Color(0xC0,0xC0,0xC0), Color(0xC0,0xC0,0xC0),
1629 Color(0xE2,0xE2,0xE2), Color(0xE,0xE,0xE), Color(0xE2,0xE2,0xE2), Color(0xE,0xE,0xE), Color(0xE,0xE,0xE)
1631 return checkRectangles(rBitmap, aExpected);
1634 TestResult OutputDeviceTestBitmap::checkBitmapExWithAlpha(Bitmap& rBitmap)
1636 const Color aBlendedColor(0xEE, 0xEE, 0x33);
1638 std::vector<Color> aExpected
1640 constBackgroundColor, constBackgroundColor,
1641 aBlendedColor, constBackgroundColor, constBackgroundColor,
1642 aBlendedColor, constBackgroundColor
1644 return checkRectangles(rBitmap, aExpected);
1647 TestResult OutputDeviceTestBitmap::checkMask(Bitmap& rBitmap)
1649 return checkRectangle(rBitmap);
1652 TestResult OutputDeviceTestBitmap::checkBlend(const BitmapEx& rBitmapEx)
1654 const Color aBlendedColor(0xEE, 0xEE, 0x33);
1656 std::vector<Color> aExpected
1658 COL_WHITE, COL_WHITE, COL_YELLOW, constBackgroundColor,
1659 constBackgroundColor, aBlendedColor, constBackgroundColor
1661 Bitmap aBitmap(rBitmapEx.GetBitmap());
1662 return checkRectangles(aBitmap, aExpected);
1666 } // end namespace vcl::test
1668 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */