merge the formfield patch from ooo-build
[ooovba.git] / basebmp / test / polytest.cxx
blobe11a91fb0592403a89d91ee477588b105406f678
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: polytest.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // autogenerated file with codegen.pl
33 #include <cppunit/simpleheader.hxx>
35 #include <basegfx/vector/b2isize.hxx>
36 #include <basegfx/range/b2irange.hxx>
37 #include <basegfx/point/b2ipoint.hxx>
38 #include <basegfx/matrix/b2dhommatrix.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>
44 #include <basebmp/color.hxx>
45 #include <basebmp/scanlineformats.hxx>
46 #include <basebmp/bitmapdevice.hxx>
47 #include <basebmp/debug.hxx>
48 #include "tools.hxx"
50 #include <iostream>
51 #include <fstream>
53 using namespace ::basebmp;
55 namespace
58 std::ofstream output("32bpp_test.dump");
59 debugDump( rDevice, output );
62 class PolyTest : public CppUnit::TestFixture
64 private:
65 BitmapDeviceSharedPtr mpDevice1bpp;
66 BitmapDeviceSharedPtr mpDevice32bpp;
68 void implTestEmpty(const BitmapDeviceSharedPtr& rDevice)
70 const Color aCol(0xFFFFFFFF);
71 const Color aBgCol(0);
72 rDevice->clear(aBgCol);
73 basegfx::B2DPolyPolygon aPoly;
74 ::rtl::OUString aSvg;
76 basegfx::tools::importFromSvgD(
77 aPoly,
78 rtl::OUString::createFromAscii(
79 "M2 2 l7 7 z" ) );
80 rDevice->fillPolyPolygon(
81 aPoly,
82 aCol,
83 DrawMode_PAINT );
84 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
85 countPixel( rDevice, aCol ) == 0);
87 // --------------------------------------------------
89 rDevice->clear(aBgCol);
90 aPoly.clear();
91 basegfx::tools::importFromSvgD(
92 aPoly,
93 rtl::OUString::createFromAscii(
94 "M7 2 l-6 6 z" ) );
95 rDevice->fillPolyPolygon(
96 aPoly,
97 aCol,
98 DrawMode_PAINT );
99 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0(b)",
100 countPixel( rDevice, aCol ) == 0);
103 void implTestHairline(const BitmapDeviceSharedPtr& rDevice)
105 const Color aCol(0xFFFFFFFF);
106 const Color aBgCol(0);
107 rDevice->clear(aBgCol);
108 basegfx::B2DPolyPolygon aPoly;
109 ::rtl::OUString aSvg;
111 basegfx::tools::importFromSvgD(
112 aPoly,
113 rtl::OUString::createFromAscii(
114 "M2 2 h1 l7 7 h-1 z" ) );
115 rDevice->fillPolyPolygon(
116 aPoly,
117 aCol,
118 DrawMode_PAINT );
119 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
120 countPixel( rDevice, aCol ) == 7);
122 // --------------------------------------------------
124 rDevice->clear(aBgCol);
125 aPoly.clear();
126 basegfx::tools::importFromSvgD(
127 aPoly,
128 rtl::OUString::createFromAscii(
129 "M7 2 h-1 l-6 6 h1 z" ) );
130 rDevice->fillPolyPolygon(
131 aPoly,
132 aCol,
133 DrawMode_PAINT );
134 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6",
135 countPixel( rDevice, aCol ) == 6);
137 // --------------------------------------------------
139 rDevice->clear(aBgCol);
140 aPoly.clear();
141 basegfx::tools::importFromSvgD(
142 aPoly,
143 rtl::OUString::createFromAscii(
144 "M0 0 l7 7 h-1 l-5-7 z" ) );
145 rDevice->fillPolyPolygon(
146 aPoly,
147 aCol,
148 DrawMode_PAINT );
149 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3",
150 countPixel( rDevice, aCol ) == 3);
153 void implTestPolyPoly(const BitmapDeviceSharedPtr& rDevice)
155 const Color aCol(0xFFFFFFFF);
156 const Color aBgCol(0);
157 rDevice->clear(aBgCol);
158 basegfx::B2DPolyPolygon aPoly;
159 ::rtl::OUString aSvg;
161 basegfx::tools::importFromSvgD( aPoly,
162 ::rtl::OUString::createFromAscii(
163 "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) );
165 rDevice->fillPolyPolygon(
166 aPoly,
167 aCol,
168 DrawMode_PAINT );
169 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40",
170 countPixel( rDevice, aCol ) == 40);
173 void implTestPolyPolyClip(const BitmapDeviceSharedPtr& rDevice)
175 const Color aCol(0xFFFFFFFF);
176 const Color aBgCol(0);
177 rDevice->clear(aBgCol);
178 basegfx::B2DPolyPolygon aPoly;
179 ::rtl::OUString aSvg;
181 basegfx::tools::importFromSvgD( aPoly,
182 ::rtl::OUString::createFromAscii(
183 "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) );
184 basegfx::B2DHomMatrix aMat;
185 aMat.translate(-3,-3);
186 aMat.rotate( 1.7 );
187 aMat.translate(6,5);
188 aPoly.transform(aMat);
190 rDevice->fillPolyPolygon(
191 aPoly,
192 aCol,
193 DrawMode_PAINT );
195 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 39",
196 countPixel( rDevice, aCol ) == 39);
198 BitmapDeviceSharedPtr pClippedDevice(
199 subsetBitmapDevice( rDevice,
200 basegfx::B2IRange(3,3,5,8) ));
202 rDevice->clear(aBgCol);
203 pClippedDevice->fillPolyPolygon(
204 aPoly,
205 aCol,
206 DrawMode_PAINT );
207 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
208 countPixel( rDevice, aCol ) == 7);
211 void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice)
213 const Color aCol(0xFFFFFFFF);
214 const Color aBgCol(0);
215 rDevice->clear(aBgCol);
216 basegfx::B2DPolyPolygon aPoly;
217 ::rtl::OUString aSvg;
219 basegfx::tools::importFromSvgD( aPoly,
220 ::rtl::OUString::createFromAscii(
221 "M0 0 v2 l10 2 v-2 z"
222 "M10 6 v-2 l-10 2 v2 z"
223 "M1 0 h1 v10 h-1 z"
224 "M4 0 h1 v10 h-1 z"
225 "M8 0 h1 v10 h-1 z" ) );
226 rDevice->fillPolyPolygon(
227 aPoly,
228 aCol,
229 DrawMode_PAINT );
230 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 46",
231 countPixel( rDevice, aCol ) == 46);
235 public:
236 void setUp()
238 const basegfx::B2ISize aSize(10,10);
239 mpDevice1bpp = createBitmapDevice( aSize,
240 true,
241 Format::ONE_BIT_MSB_PAL );
242 mpDevice32bpp = createBitmapDevice( aSize,
243 true,
244 Format::THIRTYTWO_BIT_TC_MASK );
247 void testEmpty()
249 implTestEmpty( mpDevice1bpp );
250 implTestEmpty( mpDevice32bpp );
253 void testHairline()
255 implTestHairline( mpDevice1bpp );
256 implTestHairline( mpDevice32bpp );
259 void testPolyPoly()
261 implTestPolyPoly( mpDevice1bpp );
262 implTestPolyPoly( mpDevice32bpp );
265 void testPolyPolyClip()
267 implTestPolyPolyClip(mpDevice1bpp);
268 implTestPolyPolyClip(mpDevice32bpp);
271 void testPolyPolyCrissCross()
273 implTestPolyPolyCrissCross(mpDevice1bpp);
274 implTestPolyPolyCrissCross(mpDevice32bpp);
277 // Change the following lines only, if you add, remove or rename
278 // member functions of the current class,
279 // because these macros are need by auto register mechanism.
281 CPPUNIT_TEST_SUITE(PolyTest);
282 CPPUNIT_TEST(testEmpty);
283 CPPUNIT_TEST(testHairline);
284 CPPUNIT_TEST(testPolyPoly);
285 CPPUNIT_TEST(testPolyPolyClip);
286 CPPUNIT_TEST(testPolyPolyCrissCross);
287 CPPUNIT_TEST_SUITE_END();
290 // -----------------------------------------------------------------------------
291 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(PolyTest, "PolyTest");
295 // -----------------------------------------------------------------------------
297 // this macro creates an empty function, which will called by the RegisterAllFunctions()
298 // to let the user the possibility to also register some functions by hand.
299 //NOADDITIONAL;