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