xref: /aoo41x/main/basebmp/test/polytest.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/b2irange.hxx>
34cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx>
35cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
37cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
38cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
39cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <basebmp/color.hxx>
42cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
43cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx>
44cdf0e10cSrcweir #include <basebmp/debug.hxx>
45cdf0e10cSrcweir #include "tools.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <iostream>
48cdf0e10cSrcweir #include <fstream>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace ::basebmp;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir namespace
53cdf0e10cSrcweir {
54cdf0e10cSrcweir /*
55cdf0e10cSrcweir         std::ofstream output("32bpp_test.dump");
56cdf0e10cSrcweir         debugDump( rDevice, output );
57cdf0e10cSrcweir */
58cdf0e10cSrcweir 
59cdf0e10cSrcweir class PolyTest : public CppUnit::TestFixture
60cdf0e10cSrcweir {
61cdf0e10cSrcweir private:
62cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice1bpp;
63cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice32bpp;
64cdf0e10cSrcweir 
implTestEmpty(const BitmapDeviceSharedPtr & rDevice)65cdf0e10cSrcweir     void implTestEmpty(const BitmapDeviceSharedPtr& rDevice)
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
68cdf0e10cSrcweir         const Color aBgCol(0);
69cdf0e10cSrcweir         rDevice->clear(aBgCol);
70cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
71cdf0e10cSrcweir         ::rtl::OUString aSvg;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir         basegfx::tools::importFromSvgD(
74cdf0e10cSrcweir             aPoly,
75cdf0e10cSrcweir             rtl::OUString::createFromAscii(
76cdf0e10cSrcweir                 "M2 2 l7 7 z" ) );
77cdf0e10cSrcweir         rDevice->fillPolyPolygon(
78cdf0e10cSrcweir             aPoly,
79cdf0e10cSrcweir             aCol,
80cdf0e10cSrcweir             DrawMode_PAINT );
81cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
82cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 0);
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         // --------------------------------------------------
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         rDevice->clear(aBgCol);
87cdf0e10cSrcweir         aPoly.clear();
88cdf0e10cSrcweir         basegfx::tools::importFromSvgD(
89cdf0e10cSrcweir             aPoly,
90cdf0e10cSrcweir             rtl::OUString::createFromAscii(
91cdf0e10cSrcweir             "M7 2 l-6 6 z" ) );
92cdf0e10cSrcweir         rDevice->fillPolyPolygon(
93cdf0e10cSrcweir             aPoly,
94cdf0e10cSrcweir             aCol,
95cdf0e10cSrcweir             DrawMode_PAINT );
96cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0(b)",
97cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 0);
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir 
implTestHairline(const BitmapDeviceSharedPtr & rDevice)100cdf0e10cSrcweir     void implTestHairline(const BitmapDeviceSharedPtr& rDevice)
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
103cdf0e10cSrcweir         const Color aBgCol(0);
104cdf0e10cSrcweir         rDevice->clear(aBgCol);
105cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
106cdf0e10cSrcweir         ::rtl::OUString aSvg;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir         basegfx::tools::importFromSvgD(
109cdf0e10cSrcweir             aPoly,
110cdf0e10cSrcweir             rtl::OUString::createFromAscii(
111cdf0e10cSrcweir                 "M2 2 h1 l7 7 h-1 z" ) );
112cdf0e10cSrcweir         rDevice->fillPolyPolygon(
113cdf0e10cSrcweir             aPoly,
114cdf0e10cSrcweir             aCol,
115cdf0e10cSrcweir             DrawMode_PAINT );
116cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
117cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 7);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         // --------------------------------------------------
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         rDevice->clear(aBgCol);
122cdf0e10cSrcweir         aPoly.clear();
123cdf0e10cSrcweir         basegfx::tools::importFromSvgD(
124cdf0e10cSrcweir             aPoly,
125cdf0e10cSrcweir             rtl::OUString::createFromAscii(
126cdf0e10cSrcweir             "M7 2 h-1 l-6 6 h1 z" ) );
127cdf0e10cSrcweir         rDevice->fillPolyPolygon(
128cdf0e10cSrcweir             aPoly,
129cdf0e10cSrcweir             aCol,
130cdf0e10cSrcweir             DrawMode_PAINT );
131cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6",
132cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 6);
133cdf0e10cSrcweir 
134cdf0e10cSrcweir         // --------------------------------------------------
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         rDevice->clear(aBgCol);
137cdf0e10cSrcweir         aPoly.clear();
138cdf0e10cSrcweir         basegfx::tools::importFromSvgD(
139cdf0e10cSrcweir             aPoly,
140cdf0e10cSrcweir             rtl::OUString::createFromAscii(
141cdf0e10cSrcweir             "M0 0 l7 7 h-1 l-5-7 z" ) );
142cdf0e10cSrcweir         rDevice->fillPolyPolygon(
143cdf0e10cSrcweir             aPoly,
144cdf0e10cSrcweir             aCol,
145cdf0e10cSrcweir             DrawMode_PAINT );
146cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3",
147cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 3);
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
implTestPolyPoly(const BitmapDeviceSharedPtr & rDevice)150cdf0e10cSrcweir     void implTestPolyPoly(const BitmapDeviceSharedPtr& rDevice)
151cdf0e10cSrcweir     {
152cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
153cdf0e10cSrcweir         const Color aBgCol(0);
154cdf0e10cSrcweir         rDevice->clear(aBgCol);
155cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
156cdf0e10cSrcweir         ::rtl::OUString aSvg;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         basegfx::tools::importFromSvgD( aPoly,
159cdf0e10cSrcweir                                         ::rtl::OUString::createFromAscii(
160cdf0e10cSrcweir                                             "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir         rDevice->fillPolyPolygon(
163cdf0e10cSrcweir             aPoly,
164cdf0e10cSrcweir             aCol,
165cdf0e10cSrcweir             DrawMode_PAINT );
166cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40",
167cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 40);
168cdf0e10cSrcweir     }
169cdf0e10cSrcweir 
implTestPolyPolyClip(const BitmapDeviceSharedPtr & rDevice)170cdf0e10cSrcweir     void implTestPolyPolyClip(const BitmapDeviceSharedPtr& rDevice)
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
173cdf0e10cSrcweir         const Color aBgCol(0);
174cdf0e10cSrcweir         rDevice->clear(aBgCol);
175cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
176cdf0e10cSrcweir         ::rtl::OUString aSvg;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir         basegfx::tools::importFromSvgD( aPoly,
179cdf0e10cSrcweir                                         ::rtl::OUString::createFromAscii(
180cdf0e10cSrcweir                                             "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) );
181cdf0e10cSrcweir         basegfx::B2DHomMatrix aMat;
182cdf0e10cSrcweir         aMat.translate(-3,-3);
183cdf0e10cSrcweir         aMat.rotate( 1.7 );
184cdf0e10cSrcweir         aMat.translate(6,5);
185cdf0e10cSrcweir         aPoly.transform(aMat);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         rDevice->fillPolyPolygon(
188cdf0e10cSrcweir             aPoly,
189cdf0e10cSrcweir             aCol,
190cdf0e10cSrcweir             DrawMode_PAINT );
191cdf0e10cSrcweir 
192cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 39",
193cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 39);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         BitmapDeviceSharedPtr pClippedDevice(
196cdf0e10cSrcweir             subsetBitmapDevice( rDevice,
197cdf0e10cSrcweir                                 basegfx::B2IRange(3,3,5,8) ));
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         rDevice->clear(aBgCol);
200cdf0e10cSrcweir         pClippedDevice->fillPolyPolygon(
201cdf0e10cSrcweir             aPoly,
202cdf0e10cSrcweir             aCol,
203cdf0e10cSrcweir             DrawMode_PAINT );
204cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
205cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 7);
206cdf0e10cSrcweir     }
207cdf0e10cSrcweir 
implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr & rDevice)208cdf0e10cSrcweir     void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice)
209cdf0e10cSrcweir     {
210cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
211cdf0e10cSrcweir         const Color aBgCol(0);
212cdf0e10cSrcweir         rDevice->clear(aBgCol);
213cdf0e10cSrcweir         basegfx::B2DPolyPolygon aPoly;
214cdf0e10cSrcweir         ::rtl::OUString aSvg;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir         basegfx::tools::importFromSvgD( aPoly,
217cdf0e10cSrcweir                                         ::rtl::OUString::createFromAscii(
218cdf0e10cSrcweir                                             "M0 0 v2 l10 2 v-2 z"
219cdf0e10cSrcweir                                             "M10 6 v-2 l-10 2 v2 z"
220cdf0e10cSrcweir                                             "M1 0 h1 v10 h-1 z"
221cdf0e10cSrcweir                                             "M4 0 h1 v10 h-1 z"
222cdf0e10cSrcweir                                             "M8 0 h1 v10 h-1 z" ) );
223cdf0e10cSrcweir         rDevice->fillPolyPolygon(
224cdf0e10cSrcweir             aPoly,
225cdf0e10cSrcweir             aCol,
226cdf0e10cSrcweir             DrawMode_PAINT );
227cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 46",
228cdf0e10cSrcweir                                countPixel( rDevice, aCol ) == 46);
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232cdf0e10cSrcweir public:
setUp()233cdf0e10cSrcweir     void setUp()
234cdf0e10cSrcweir     {
235cdf0e10cSrcweir         const basegfx::B2ISize aSize(10,10);
236cdf0e10cSrcweir         mpDevice1bpp = createBitmapDevice( aSize,
237cdf0e10cSrcweir                                            true,
238cdf0e10cSrcweir                                            Format::ONE_BIT_MSB_PAL );
239cdf0e10cSrcweir         mpDevice32bpp = createBitmapDevice( aSize,
240cdf0e10cSrcweir                                             true,
241cdf0e10cSrcweir                                             Format::THIRTYTWO_BIT_TC_MASK );
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir 
testEmpty()244cdf0e10cSrcweir     void testEmpty()
245cdf0e10cSrcweir     {
246cdf0e10cSrcweir         implTestEmpty( mpDevice1bpp );
247cdf0e10cSrcweir         implTestEmpty( mpDevice32bpp );
248cdf0e10cSrcweir     }
249cdf0e10cSrcweir 
testHairline()250cdf0e10cSrcweir     void testHairline()
251cdf0e10cSrcweir     {
252cdf0e10cSrcweir         implTestHairline( mpDevice1bpp );
253cdf0e10cSrcweir         implTestHairline( mpDevice32bpp );
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir 
testPolyPoly()256cdf0e10cSrcweir     void testPolyPoly()
257cdf0e10cSrcweir     {
258cdf0e10cSrcweir         implTestPolyPoly( mpDevice1bpp );
259cdf0e10cSrcweir         implTestPolyPoly( mpDevice32bpp );
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
testPolyPolyClip()262cdf0e10cSrcweir     void testPolyPolyClip()
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         implTestPolyPolyClip(mpDevice1bpp);
265cdf0e10cSrcweir         implTestPolyPolyClip(mpDevice32bpp);
266cdf0e10cSrcweir     }
267cdf0e10cSrcweir 
testPolyPolyCrissCross()268cdf0e10cSrcweir     void testPolyPolyCrissCross()
269cdf0e10cSrcweir     {
270cdf0e10cSrcweir         implTestPolyPolyCrissCross(mpDevice1bpp);
271cdf0e10cSrcweir         implTestPolyPolyCrissCross(mpDevice32bpp);
272cdf0e10cSrcweir     }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
275cdf0e10cSrcweir     // member functions of the current class,
276cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
277cdf0e10cSrcweir 
278cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(PolyTest);
279cdf0e10cSrcweir     CPPUNIT_TEST(testEmpty);
280cdf0e10cSrcweir     CPPUNIT_TEST(testHairline);
281cdf0e10cSrcweir     CPPUNIT_TEST(testPolyPoly);
282cdf0e10cSrcweir     CPPUNIT_TEST(testPolyPolyClip);
283cdf0e10cSrcweir     CPPUNIT_TEST(testPolyPolyCrissCross);
284cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
285cdf0e10cSrcweir };
286cdf0e10cSrcweir 
287cdf0e10cSrcweir // -----------------------------------------------------------------------------
288cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(PolyTest);
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 
292cdf0e10cSrcweir // -----------------------------------------------------------------------------
293cdf0e10cSrcweir 
294cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
295cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
296cdf0e10cSrcweir //NOADDITIONAL;
297cdf0e10cSrcweir 
298