bump product version to 5.0.4.1
[LibreOffice.git] / basebmp / test / filltest.cxx
blob875a27dac2e579f706b4318d2789a11e127da02e
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 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppunit/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
24 #include <basegfx/vector/b2isize.hxx>
25 #include <basegfx/range/b2drange.hxx>
26 #include <basegfx/point/b2ipoint.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <basegfx/polygon/b2dpolygontools.hxx>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
30 #include <basegfx/polygon/b2dpolypolygontools.hxx>
32 #include <basebmp/color.hxx>
33 #include <basebmp/scanlineformats.hxx>
34 #include <basebmp/bitmapdevice.hxx>
35 #include "tools.hxx"
37 using namespace ::basebmp;
39 namespace
41 class FillTest : public CppUnit::TestFixture
43 private:
44 BitmapDeviceSharedPtr mpDevice1bpp;
45 BitmapDeviceSharedPtr mpDevice32bpp;
47 void implTestRectFill(const BitmapDeviceSharedPtr& rDevice)
49 rDevice->clear(Color(0));
51 const basegfx::B2DRange aRect(1,1,10,10);
53 const Color aCol(0xFFFFFFFF);
54 rDevice->fillPolyPolygon(
55 basegfx::B2DPolyPolygon(
56 basegfx::tools::createPolygonFromRect( aRect )),
57 aCol,
58 DrawMode_PAINT );
60 const basegfx::B2IPoint aPt1(1,1);
61 CPPUNIT_ASSERT_MESSAGE("first pixel set",
62 rDevice->getPixel(aPt1) == aCol);
63 const basegfx::B2IPoint aPt2(9,9);
64 CPPUNIT_ASSERT_MESSAGE("last pixel set",
65 rDevice->getPixel(aPt2) == aCol);
66 const basegfx::B2IPoint aPt3(0,0);
67 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
68 rDevice->getPixel(aPt3) != aCol);
69 const basegfx::B2IPoint aPt4(10,10);
70 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
71 rDevice->getPixel(aPt4) != aCol);
73 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 81",
74 countPixel( rDevice, aCol ) == 81);
77 void implTestCornerCases(const BitmapDeviceSharedPtr& rDevice)
79 rDevice->clear(Color(0));
81 const basegfx::B2DRange aEmpty1(0,0,0,11);
82 const basegfx::B2DRange aEmpty2(0,0,11,0);
83 const basegfx::B2DRange aVertLineLeft(0,0,1,11);
84 const basegfx::B2DRange aVertLineRight(10,0,11,11);
85 const basegfx::B2DRange aHorzLineTop(0,0,11,1);
86 const basegfx::B2DRange aHorzLineBottom(0,10,11,11);
88 const Color aCol(0xFFFFFFFF);
89 rDevice->fillPolyPolygon(
90 basegfx::B2DPolyPolygon(
91 basegfx::tools::createPolygonFromRect( aEmpty1 )),
92 aCol,
93 DrawMode_PAINT );
94 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
95 countPixel( rDevice, aCol ) == 0);
97 rDevice->fillPolyPolygon(
98 basegfx::B2DPolyPolygon(
99 basegfx::tools::createPolygonFromRect( aEmpty2 )),
100 aCol,
101 DrawMode_PAINT );
102 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
103 countPixel( rDevice, aCol ) == 0);
105 rDevice->fillPolyPolygon(
106 basegfx::B2DPolyPolygon(
107 basegfx::tools::createPolygonFromRect( aVertLineLeft )),
108 aCol,
109 DrawMode_PAINT );
110 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
111 countPixel( rDevice, aCol ) == 11);
112 const basegfx::B2IPoint aPt1(0,0);
113 CPPUNIT_ASSERT_MESSAGE("first pixel set",
114 rDevice->getPixel(aPt1) == aCol);
116 rDevice->fillPolyPolygon(
117 basegfx::B2DPolyPolygon(
118 basegfx::tools::createPolygonFromRect( aVertLineRight )),
119 aCol,
120 DrawMode_PAINT );
121 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 22",
122 countPixel( rDevice, aCol ) == 22);
123 const basegfx::B2IPoint aPt2(10,10);
124 CPPUNIT_ASSERT_MESSAGE("last pixel set",
125 rDevice->getPixel(aPt2) == aCol);
127 rDevice->fillPolyPolygon(
128 basegfx::B2DPolyPolygon(
129 basegfx::tools::createPolygonFromRect( aHorzLineTop )),
130 aCol,
131 DrawMode_PAINT );
132 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 31",
133 countPixel( rDevice, aCol ) == 31);
134 const basegfx::B2IPoint aPt3(5,0);
135 CPPUNIT_ASSERT_MESSAGE("top-middle pixel set",
136 rDevice->getPixel(aPt3) == aCol);
138 rDevice->fillPolyPolygon(
139 basegfx::B2DPolyPolygon(
140 basegfx::tools::createPolygonFromRect( aHorzLineBottom )),
141 aCol,
142 DrawMode_PAINT );
143 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40",
144 countPixel( rDevice, aCol ) == 40);
145 const basegfx::B2IPoint aPt4(5,10);
146 CPPUNIT_ASSERT_MESSAGE("bottom-middle pixel set",
147 rDevice->getPixel(aPt4) == aCol);
149 OUString aSvg( "m 0 0l7 7h-1z" );
151 basegfx::B2DPolyPolygon aPoly;
152 basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
153 rDevice->fillPolyPolygon(
154 aPoly,
155 aCol,
156 DrawMode_PAINT );
157 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 43",
158 countPixel( rDevice, aCol ) == 43);
161 void implTestClipping(const BitmapDeviceSharedPtr& rDevice)
163 rDevice->clear(Color(0));
165 const basegfx::B2DRange aLeftTop(-10,-10,1,1);
166 const basegfx::B2DRange aRightTop(10,-10,20,1);
167 const basegfx::B2DRange aLeftBottom(-10,10,1,20);
168 const basegfx::B2DRange aRightBottom(10,10,20,20);
169 const basegfx::B2DRange aAllOver(-10,-10,20,20);
171 const Color aCol(0xFFFFFFFF);
172 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
173 basegfx::tools::createPolygonFromRect(aLeftTop)),
174 aCol,
175 DrawMode_PAINT );
176 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1",
177 countPixel( rDevice, aCol ) == 1);
179 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
180 basegfx::tools::createPolygonFromRect(aRightTop)),
181 aCol,
182 DrawMode_PAINT );
183 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2",
184 countPixel( rDevice, aCol ) == 2);
186 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
187 basegfx::tools::createPolygonFromRect(aLeftBottom)),
188 aCol,
189 DrawMode_PAINT );
190 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3",
191 countPixel( rDevice, aCol ) == 3);
193 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
194 basegfx::tools::createPolygonFromRect(aRightBottom)),
195 aCol,
196 DrawMode_PAINT );
197 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
198 countPixel( rDevice, aCol ) == 4);
200 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
201 basegfx::tools::createPolygonFromRect(aAllOver)),
202 aCol,
203 DrawMode_PAINT );
204 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 121",
205 countPixel( rDevice, aCol ) == 121);
208 public:
209 void setUp() SAL_OVERRIDE
211 const basegfx::B2ISize aSize(11,11);
212 mpDevice1bpp = createBitmapDevice( aSize,
213 true,
214 FORMAT_ONE_BIT_MSB_PAL,
215 basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_MSB_PAL, aSize.getX()));
216 mpDevice32bpp = createBitmapDevice( aSize,
217 true,
218 FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA,
219 basebmp::getBitmapDeviceStrideForWidth(FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA, aSize.getX()));
222 void testRectFill()
224 implTestRectFill( mpDevice1bpp );
225 implTestRectFill( mpDevice32bpp );
228 void testClipping()
230 implTestClipping( mpDevice1bpp );
231 implTestClipping( mpDevice32bpp );
234 void testCornerCases()
236 implTestCornerCases( mpDevice1bpp );
237 implTestCornerCases( mpDevice32bpp );
240 // Change the following lines only, if you add, remove or rename
241 // member functions of the current class,
242 // because these macros are need by auto register mechanism.
244 CPPUNIT_TEST_SUITE(FillTest);
245 CPPUNIT_TEST(testRectFill);
246 CPPUNIT_TEST(testClipping);
247 CPPUNIT_TEST(testCornerCases);
248 CPPUNIT_TEST_SUITE_END();
251 CPPUNIT_TEST_SUITE_REGISTRATION(FillTest);
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */