1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 // autogenerated file with codegen.pl
31 #include "sal/config.h"
32 #include "sal/precppunit.hxx"
34 #include "cppunit/TestAssert.h"
35 #include "cppunit/TestFixture.h"
36 #include "cppunit/extensions/HelperMacros.h"
38 #include <basegfx/vector/b2isize.hxx>
39 #include <basegfx/range/b2ibox.hxx>
40 #include <basegfx/point/b2ipoint.hxx>
41 #include <basegfx/matrix/b2dhommatrix.hxx>
42 #include <basegfx/polygon/b2dpolygon.hxx>
43 #include <basegfx/polygon/b2dpolygontools.hxx>
44 #include <basegfx/polygon/b2dpolypolygon.hxx>
45 #include <basegfx/polygon/b2dpolypolygontools.hxx>
47 #include <basebmp/color.hxx>
48 #include <basebmp/scanlineformats.hxx>
49 #include <basebmp/bitmapdevice.hxx>
52 using namespace ::basebmp
;
56 class PolyTest
: public CppUnit::TestFixture
59 BitmapDeviceSharedPtr mpDevice1bpp
;
60 BitmapDeviceSharedPtr mpDevice32bpp
;
62 void implTestEmpty(const BitmapDeviceSharedPtr
& rDevice
)
64 const Color
aCol(0xFFFFFFFF);
65 const Color
aBgCol(0);
66 rDevice
->clear(aBgCol
);
67 basegfx::B2DPolyPolygon aPoly
;
69 basegfx::tools::importFromSvgD(
71 rtl::OUString( "M2 2 l7 7 z" ) );
72 rDevice
->fillPolyPolygon(
76 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
77 countPixel( rDevice
, aCol
) == 0);
79 // --------------------------------------------------
81 rDevice
->clear(aBgCol
);
83 basegfx::tools::importFromSvgD(
85 rtl::OUString( "M7 2 l-6 6 z" ) );
86 rDevice
->fillPolyPolygon(
90 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0(b)",
91 countPixel( rDevice
, aCol
) == 0);
94 void implTestHairline(const BitmapDeviceSharedPtr
& rDevice
)
96 const Color
aCol(0xFFFFFFFF);
97 const Color
aBgCol(0);
98 rDevice
->clear(aBgCol
);
99 basegfx::B2DPolyPolygon aPoly
;
101 basegfx::tools::importFromSvgD(
103 rtl::OUString( "M2 2 h1 l7 7 h-1 z" ) );
104 rDevice
->fillPolyPolygon(
108 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
109 countPixel( rDevice
, aCol
) == 7);
111 // --------------------------------------------------
113 rDevice
->clear(aBgCol
);
115 basegfx::tools::importFromSvgD(
117 rtl::OUString( "M7 2 h-1 l-6 6 h1 z" ) );
118 rDevice
->fillPolyPolygon(
122 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6",
123 countPixel( rDevice
, aCol
) == 6);
125 // --------------------------------------------------
127 rDevice
->clear(aBgCol
);
129 basegfx::tools::importFromSvgD(
131 rtl::OUString( "M0 0 l7 7 h-1 l-5-7 z" ) );
132 rDevice
->fillPolyPolygon(
136 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3",
137 countPixel( rDevice
, aCol
) == 3);
140 void implTestPolyPoly(const BitmapDeviceSharedPtr
& rDevice
)
142 const Color
aCol(0xFFFFFFFF);
143 const Color
aBgCol(0);
144 rDevice
->clear(aBgCol
);
145 basegfx::B2DPolyPolygon aPoly
;
147 basegfx::tools::importFromSvgD( aPoly
,
148 ::rtl::OUString( "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) );
150 rDevice
->fillPolyPolygon(
154 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40",
155 countPixel( rDevice
, aCol
) == 40);
158 void implTestPolyPolyClip(const BitmapDeviceSharedPtr
& rDevice
)
160 const Color
aCol(0xFFFFFFFF);
161 const Color
aBgCol(0);
162 rDevice
->clear(aBgCol
);
163 basegfx::B2DPolyPolygon aPoly
;
165 basegfx::tools::importFromSvgD( aPoly
,
166 ::rtl::OUString( "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ) );
167 basegfx::B2DHomMatrix aMat
;
168 aMat
.translate(-3,-3);
171 aPoly
.transform(aMat
);
173 rDevice
->fillPolyPolygon(
178 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 39",
179 countPixel( rDevice
, aCol
) == 39);
181 BitmapDeviceSharedPtr
pClippedDevice(
182 subsetBitmapDevice( rDevice
,
183 basegfx::B2IBox(3,3,5,8) ));
184 CPPUNIT_ASSERT_MESSAGE("size of subsetted device is not (2,5)",
185 pClippedDevice
->getSize() == basegfx::B2IVector(2,5));
187 rDevice
->clear(aBgCol
);
188 pClippedDevice
->fillPolyPolygon(
192 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
193 countPixel( rDevice
, aCol
) == 7);
196 void implTestLineDrawClip(const BitmapDeviceSharedPtr
& rDevice
)
198 const Color
aCol(0xFFFFFFFF);
199 const Color
aBgCol(0);
200 rDevice
->clear(aBgCol
);
202 // create rectangular subset, such that we can 'see' extra
204 BitmapDeviceSharedPtr pClippedDevice
=(
205 subsetBitmapDevice( rDevice
,
206 basegfx::B2IBox(3,3,5,9) ));
208 // trigger "alternate bresenham" case in
209 // clippedlinerenderer.hxx, first point not clipped
210 const basegfx::B2IPoint
aPt1(3,3);
211 const basegfx::B2IPoint
aPt2(4,2);
212 pClippedDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
214 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1",
215 countPixel( rDevice
, aCol
) == 1);
217 // trigger "alternate bresenham" case in
218 // clippedlinerenderer.hxx, both start and endpoint clipped
219 const basegfx::B2IPoint
aPt3(0,4);
220 pClippedDevice
->drawLine( aPt3
, aPt2
, aCol
, DrawMode_XOR
);
222 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
223 countPixel( rDevice
, aCol
) == 0);
225 // trigger "standard bresenham" case in
226 // clippedlinerenderer.hxx, first point not clipped
227 const basegfx::B2IPoint
aPt4(6,2);
228 pClippedDevice
->drawLine( aPt1
, aPt4
, aCol
, DrawMode_PAINT
);
230 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2",
231 countPixel( rDevice
, aCol
) == 2);
233 // trigger "clipCode1 & aMinFlag/bMinFlag" cases in
234 // clippedlinerenderer.hxx (note1: needs forcing end point to
235 // be clipped as well, otherwise optimisation kicks in. note2:
236 // needs forcing end point to clip on two edges, not only on
237 // one, otherwise swap kicks in)
238 const basegfx::B2IPoint
aPt5(1,1);
239 const basegfx::B2IPoint
aPt6(6,10);
240 pClippedDevice
->drawLine( aPt5
, aPt6
, aCol
, DrawMode_XOR
);
242 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6",
243 countPixel( rDevice
, aCol
) == 6);
245 // trigger "clipCode1 & (aMinFlag|aMaxFlag)" case in
246 // clippedlinerenderer.hxx that was not taken for the test
248 pClippedDevice
->drawLine( aPt3
, aPt6
, aCol
, DrawMode_XOR
);
250 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
251 countPixel( rDevice
, aCol
) == 8);
255 void implTestPolyDrawClip(const BitmapDeviceSharedPtr
& rDevice
)
257 const Color
aCol(0xFFFFFFFF);
258 const Color
aBgCol(0);
259 rDevice
->clear(aBgCol
);
260 basegfx::B2DPolyPolygon aPoly
;
262 // test all corner-touching lines of our clip rect. note that
263 // *all* of the four two-pixel lines in that polygon do *not*
264 // generate a single pixel, due to the rasterization effect.
265 basegfx::tools::importFromSvgD( aPoly
,
266 ::rtl::OUString( "M2 3 l1 -1 M4 2 l1 1 M2 8 l1 1 M5 8 l-1 1 M2 5 h4 M3 0 v10" ) );
267 BitmapDeviceSharedPtr pClippedDevice
=(
268 subsetBitmapDevice( rDevice
,
269 basegfx::B2IBox(3,3,5,9) ));
271 for( unsigned int i
=0; i
<aPoly
.count(); ++i
)
272 pClippedDevice
->drawPolygon(
273 aPoly
.getB2DPolygon(i
),
277 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7",
278 countPixel( rDevice
, aCol
) == 7);
281 void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr
& rDevice
)
283 const Color
aCol(0xFFFFFFFF);
284 const Color
aBgCol(0);
285 rDevice
->clear(aBgCol
);
286 basegfx::B2DPolyPolygon aPoly
;
288 basegfx::tools::importFromSvgD( aPoly
,
289 ::rtl::OUString( "M0 0 v2 l10 2 v-2 z"
290 "M10 6 v-2 l-10 2 v2 z"
293 "M8 0 h1 v10 h-1 z" ) );
294 rDevice
->fillPolyPolygon(
298 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 46",
299 countPixel( rDevice
, aCol
) == 46);
306 const basegfx::B2ISize
aSize(10,10);
307 mpDevice1bpp
= createBitmapDevice( aSize
,
309 Format::ONE_BIT_MSB_PAL
);
310 mpDevice32bpp
= createBitmapDevice( aSize
,
312 Format::THIRTYTWO_BIT_TC_MASK
);
317 implTestEmpty( mpDevice1bpp
);
318 implTestEmpty( mpDevice32bpp
);
323 implTestHairline( mpDevice1bpp
);
324 implTestHairline( mpDevice32bpp
);
329 implTestPolyPoly( mpDevice1bpp
);
330 implTestPolyPoly( mpDevice32bpp
);
333 void testPolyPolyClip()
335 implTestPolyPolyClip(mpDevice1bpp
);
336 implTestPolyPolyClip(mpDevice32bpp
);
339 void testLineDrawClip()
341 implTestLineDrawClip(mpDevice1bpp
);
342 implTestLineDrawClip(mpDevice32bpp
);
345 void testPolyDrawClip()
347 implTestPolyDrawClip(mpDevice1bpp
);
348 implTestPolyDrawClip(mpDevice32bpp
);
351 void testPolyPolyCrissCross()
353 implTestPolyPolyCrissCross(mpDevice1bpp
);
354 implTestPolyPolyCrissCross(mpDevice32bpp
);
357 // Change the following lines only, if you add, remove or rename
358 // member functions of the current class,
359 // because these macros are need by auto register mechanism.
361 CPPUNIT_TEST_SUITE(PolyTest
);
362 CPPUNIT_TEST(testEmpty
);
363 CPPUNIT_TEST(testHairline
);
364 CPPUNIT_TEST(testPolyPoly
);
365 CPPUNIT_TEST(testPolyPolyClip
);
366 CPPUNIT_TEST(testLineDrawClip
);
367 CPPUNIT_TEST(testPolyDrawClip
);
368 CPPUNIT_TEST(testPolyPolyCrissCross
);
369 CPPUNIT_TEST_SUITE_END();
372 CPPUNIT_TEST_SUITE_REGISTRATION(PolyTest
);
375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */