xref: /aoo41x/main/basebmp/test/filltest.cxx (revision 69de5a4c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // autogenerated file with codegen.pl
25 
26 #include "preextstl.h"
27 #include "cppunit/TestAssert.h"
28 #include "cppunit/TestFixture.h"
29 #include "cppunit/extensions/HelperMacros.h"
30 #include "postextstl.h"
31 
32 #include <basegfx/vector/b2isize.hxx>
33 #include <basegfx/range/b2drange.hxx>
34 #include <basegfx/point/b2ipoint.hxx>
35 #include <basegfx/polygon/b2dpolygon.hxx>
36 #include <basegfx/polygon/b2dpolygontools.hxx>
37 #include <basegfx/polygon/b2dpolypolygon.hxx>
38 #include <basegfx/polygon/b2dpolypolygontools.hxx>
39 
40 #include <basebmp/color.hxx>
41 #include <basebmp/scanlineformats.hxx>
42 #include <basebmp/bitmapdevice.hxx>
43 #include <basebmp/debug.hxx>
44 #include "tools.hxx"
45 
46 #include <iostream>
47 #include <fstream>
48 
49 using namespace ::basebmp;
50 
51 namespace
52 {
53 /*
54   std::ofstream output("32bpp_test.dump");
55   debugDump( mpDevice32bpp, output );
56 */
57 
58 class FillTest : public CppUnit::TestFixture
59 {
60 private:
61     BitmapDeviceSharedPtr mpDevice1bpp;
62     BitmapDeviceSharedPtr mpDevice32bpp;
63 
implTestRectFill(const BitmapDeviceSharedPtr & rDevice)64     void implTestRectFill(const BitmapDeviceSharedPtr& rDevice)
65     {
66         rDevice->clear(Color(0));
67 
68         const basegfx::B2DRange   aRect(1,1,10,10);
69 
70         const Color aCol(0xFFFFFFFF);
71         rDevice->fillPolyPolygon(
72             basegfx::B2DPolyPolygon(
73                 basegfx::tools::createPolygonFromRect( aRect )),
74             aCol,
75             DrawMode_PAINT );
76 
77         const basegfx::B2IPoint aPt1(1,1);
78         CPPUNIT_ASSERT_MESSAGE("first pixel set",
79                                rDevice->getPixel(aPt1) == aCol);
80         const basegfx::B2IPoint aPt2(9,9);
81         CPPUNIT_ASSERT_MESSAGE("last pixel set",
82                                rDevice->getPixel(aPt2) == aCol);
83         const basegfx::B2IPoint aPt3(0,0);
84         CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
85                                rDevice->getPixel(aPt3) != aCol);
86         const basegfx::B2IPoint aPt4(10,10);
87         CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
88                                rDevice->getPixel(aPt4) != aCol);
89 
90         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 81",
91                                countPixel( rDevice, aCol ) == 81);
92     }
93 
implTestCornerCases(const BitmapDeviceSharedPtr & rDevice)94     void implTestCornerCases(const BitmapDeviceSharedPtr& rDevice)
95     {
96         rDevice->clear(Color(0));
97 
98         const basegfx::B2DRange aEmpty1(0,0,0,11);
99         const basegfx::B2DRange aEmpty2(0,0,11,0);
100         const basegfx::B2DRange aVertLineLeft(0,0,1,11);
101         const basegfx::B2DRange aVertLineRight(10,0,11,11);
102         const basegfx::B2DRange aHorzLineTop(0,0,11,1);
103         const basegfx::B2DRange aHorzLineBottom(0,10,11,11);
104 
105         const Color aCol(0xFFFFFFFF);
106         rDevice->fillPolyPolygon(
107             basegfx::B2DPolyPolygon(
108                 basegfx::tools::createPolygonFromRect( aEmpty1 )),
109             aCol,
110             DrawMode_PAINT );
111         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
112                                countPixel( rDevice, aCol ) == 0);
113 
114         rDevice->fillPolyPolygon(
115             basegfx::B2DPolyPolygon(
116                 basegfx::tools::createPolygonFromRect( aEmpty2 )),
117             aCol,
118             DrawMode_PAINT );
119         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
120                                countPixel( rDevice, aCol ) == 0);
121 
122         rDevice->fillPolyPolygon(
123             basegfx::B2DPolyPolygon(
124                 basegfx::tools::createPolygonFromRect( aVertLineLeft )),
125             aCol,
126             DrawMode_PAINT );
127         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
128                                countPixel( rDevice, aCol ) == 11);
129         const basegfx::B2IPoint aPt1(0,0);
130         CPPUNIT_ASSERT_MESSAGE("first pixel set",
131                                rDevice->getPixel(aPt1) == aCol);
132 
133         rDevice->fillPolyPolygon(
134             basegfx::B2DPolyPolygon(
135                 basegfx::tools::createPolygonFromRect( aVertLineRight )),
136             aCol,
137             DrawMode_PAINT );
138         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 22",
139                                countPixel( rDevice, aCol ) == 22);
140         const basegfx::B2IPoint aPt2(10,10);
141         CPPUNIT_ASSERT_MESSAGE("last pixel set",
142                                rDevice->getPixel(aPt2) == aCol);
143 
144         rDevice->fillPolyPolygon(
145             basegfx::B2DPolyPolygon(
146                 basegfx::tools::createPolygonFromRect( aHorzLineTop )),
147             aCol,
148             DrawMode_PAINT );
149         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 31",
150                                countPixel( rDevice, aCol ) == 31);
151         const basegfx::B2IPoint aPt3(5,0);
152         CPPUNIT_ASSERT_MESSAGE("top-middle pixel set",
153                                rDevice->getPixel(aPt3) == aCol);
154 
155         rDevice->fillPolyPolygon(
156             basegfx::B2DPolyPolygon(
157                 basegfx::tools::createPolygonFromRect( aHorzLineBottom )),
158             aCol,
159             DrawMode_PAINT );
160         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40",
161                                countPixel( rDevice, aCol ) == 40);
162         const basegfx::B2IPoint aPt4(5,10);
163         CPPUNIT_ASSERT_MESSAGE("bottom-middle pixel set",
164                                rDevice->getPixel(aPt4) == aCol);
165 
166         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
167             "m 0 0l7 7h-1z" );
168 
169         basegfx::B2DPolyPolygon aPoly;
170         basegfx::tools::importFromSvgD( aPoly, aSvg );
171         rDevice->fillPolyPolygon(
172             aPoly,
173             aCol,
174             DrawMode_PAINT );
175         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 43",
176                                countPixel( rDevice, aCol ) == 43);
177     }
178 
implTestClipping(const BitmapDeviceSharedPtr & rDevice)179     void implTestClipping(const BitmapDeviceSharedPtr& rDevice)
180     {
181         rDevice->clear(Color(0));
182 
183         const basegfx::B2DRange   aLeftTop(-10,-10,1,1);
184         const basegfx::B2DRange   aRightTop(10,-10,20,1);
185         const basegfx::B2DRange   aLeftBottom(-10,10,1,20);
186         const basegfx::B2DRange   aRightBottom(10,10,20,20);
187         const basegfx::B2DRange   aAllOver(-10,-10,20,20);
188 
189         const Color aCol(0xFFFFFFFF);
190         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
191                                       basegfx::tools::createPolygonFromRect(aLeftTop)),
192                                   aCol,
193                                   DrawMode_PAINT );
194         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1",
195                                countPixel( rDevice, aCol ) == 1);
196 
197         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
198                                       basegfx::tools::createPolygonFromRect(aRightTop)),
199                                   aCol,
200                                   DrawMode_PAINT );
201         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2",
202                                countPixel( rDevice, aCol ) == 2);
203 
204         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
205                                       basegfx::tools::createPolygonFromRect(aLeftBottom)),
206                                   aCol,
207                                   DrawMode_PAINT );
208         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3",
209                                countPixel( rDevice, aCol ) == 3);
210 
211         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
212                                       basegfx::tools::createPolygonFromRect(aRightBottom)),
213                                   aCol,
214                                   DrawMode_PAINT );
215         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
216                                countPixel( rDevice, aCol ) == 4);
217 
218         rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
219                                       basegfx::tools::createPolygonFromRect(aAllOver)),
220                                   aCol,
221                                   DrawMode_PAINT );
222         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 121",
223                                countPixel( rDevice, aCol ) == 121);
224     }
225 
226 public:
setUp()227     void setUp()
228     {
229         const basegfx::B2ISize aSize(11,11);
230         mpDevice1bpp = createBitmapDevice( aSize,
231                                            true,
232                                            Format::ONE_BIT_MSB_PAL );
233         mpDevice32bpp = createBitmapDevice( aSize,
234                                            true,
235                                            Format::THIRTYTWO_BIT_TC_MASK );
236     }
237 
testRectFill()238     void testRectFill()
239     {
240         implTestRectFill( mpDevice1bpp );
241         implTestRectFill( mpDevice32bpp );
242     }
243 
testClipping()244     void testClipping()
245     {
246         implTestClipping( mpDevice1bpp );
247         implTestClipping( mpDevice32bpp );
248     }
249 
testCornerCases()250     void testCornerCases()
251     {
252         implTestCornerCases( mpDevice1bpp );
253         implTestCornerCases( mpDevice32bpp );
254     }
255 
256     // Change the following lines only, if you add, remove or rename
257     // member functions of the current class,
258     // because these macros are need by auto register mechanism.
259 
260     CPPUNIT_TEST_SUITE(FillTest);
261     CPPUNIT_TEST(testRectFill);
262     CPPUNIT_TEST(testClipping);
263     CPPUNIT_TEST(testCornerCases);
264     CPPUNIT_TEST_SUITE_END();
265 };
266 
267 // -----------------------------------------------------------------------------
268 CPPUNIT_TEST_SUITE_REGISTRATION(FillTest);
269 }
270 
271 
272 // -----------------------------------------------------------------------------
273 
274 // this macro creates an empty function, which will called by the RegisterAllFunctions()
275 // to let the user the possibility to also register some functions by hand.
276 //NOADDITIONAL;
277 
278