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