Bump for 3.6-28
[LibreOffice.git] / basebmp / test / cliptest.cxx
blobdd5ff85f44d9da8e1fb2e71302d707cfe7a77f12
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/point/b2ipoint.hxx>
40 #include <basegfx/range/b2drange.hxx>
41 #include <basegfx/range/b2ibox.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>
50 #include "tools.hxx"
52 using namespace ::basebmp;
54 namespace
56 class ClipTest : public CppUnit::TestFixture
58 private:
59 BitmapDeviceSharedPtr mpClipMask;
60 BitmapDeviceSharedPtr mpDevice1bpp;
61 BitmapDeviceSharedPtr mpDevice32bpp;
63 void implTestPixelClip(const BitmapDeviceSharedPtr& rDevice)
65 const Color aBgCol(0);
66 rDevice->clear(aBgCol);
68 const basegfx::B2IPoint aPt(0,0);
69 const Color aCol(0xFFFFFFFF);
70 rDevice->setPixel( aPt, aCol, DrawMode_PAINT, mpClipMask );
71 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #1",
72 rDevice->getPixel(aPt) == aBgCol);
74 const basegfx::B2IPoint aPt2(10,10);
75 rDevice->setPixel( aPt2, aCol, DrawMode_PAINT, mpClipMask );
76 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #2",
77 rDevice->getPixel(aPt2) == aBgCol);
79 const basegfx::B2IPoint aPt1(10,0);
80 rDevice->setPixel( aPt1, aCol, DrawMode_PAINT, mpClipMask );
81 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #3",
82 rDevice->getPixel(aPt1) != aBgCol);
84 const basegfx::B2IPoint aPt3(0,10);
85 rDevice->setPixel( aPt3, aCol, DrawMode_PAINT, mpClipMask );
86 CPPUNIT_ASSERT_MESSAGE("get/setPixel clip #4",
87 rDevice->getPixel(aPt3) != aBgCol);
90 void implTestLineClip(const BitmapDeviceSharedPtr& rDevice)
92 const Color aBgCol(0);
93 rDevice->clear(aBgCol);
95 const basegfx::B2IPoint aPt1(0,0);
96 const basegfx::B2IPoint aPt2(1,9);
97 const Color aCol(0xFFFFFFFF);
98 rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT, mpClipMask );
100 const basegfx::B2IPoint aPt3(1,5);
101 CPPUNIT_ASSERT_MESSAGE("get line pixel",
102 rDevice->getPixel(aPt3) != aBgCol);
103 CPPUNIT_ASSERT_MESSAGE("number of rendered line pixel is not 4",
104 countPixel( rDevice,
105 rDevice->getPixel(aPt3) ) == 4);
107 rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_XOR, mpClipMask );
108 CPPUNIT_ASSERT_MESSAGE("number of xor-rendered line pixel is not 0",
109 countPixel( rDevice,
110 rDevice->getPixel(aPt3) ) == 121);
113 void implTestFillClip(const BitmapDeviceSharedPtr& rDevice)
115 rDevice->clear(Color(0));
117 const basegfx::B2DRange aAllOver(-10,-10,20,20);
118 const Color aCol(0xFFFFFFFF);
119 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
120 basegfx::tools::createPolygonFromRect(aAllOver)),
121 aCol,
122 DrawMode_PAINT,
123 mpClipMask );
124 const basegfx::B2IPoint aPt(0,10);
125 CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 30",
126 countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30);
128 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
129 basegfx::tools::createPolygonFromRect(aAllOver)),
130 aCol,
131 DrawMode_PAINT );
132 CPPUNIT_ASSERT_MESSAGE("number of filled pixel is not 121",
133 countPixel( rDevice, rDevice->getPixel(aPt) ) == 121);
135 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
136 basegfx::tools::createPolygonFromRect(aAllOver)),
137 aCol,
138 DrawMode_XOR,
139 mpClipMask );
140 CPPUNIT_ASSERT_MESSAGE("number of xor-cleared pixel is not 91",
141 countPixel( rDevice, rDevice->getPixel(aPt) ) == 121-30);
144 void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice)
146 BitmapDeviceSharedPtr pBmp( cloneBitmapDevice(
147 basegfx::B2IVector(3,3),
148 rDevice ));
149 Color aCol1(0);
150 Color aCol2(0xFFFFFFFF);
151 pBmp->clear(aCol1);
152 pBmp->setPixel(basegfx::B2IPoint(0,0),aCol2,DrawMode_PAINT);
153 pBmp->setPixel(basegfx::B2IPoint(1,1),aCol2,DrawMode_PAINT);
154 pBmp->setPixel(basegfx::B2IPoint(2,2),aCol2,basebmp::DrawMode_PAINT);
156 rDevice->clear(aCol1);
157 rDevice->drawBitmap(pBmp,
158 basegfx::B2IBox(0,0,3,3),
159 basegfx::B2IBox(-1,-1,4,4),
160 DrawMode_PAINT,
161 mpClipMask);
163 const basegfx::B2IPoint aPt(1,1);
164 CPPUNIT_ASSERT_MESSAGE("number of clipped pixel is not 5",
165 countPixel( rDevice,
166 rDevice->getPixel(aPt) ) == 5);
169 void implTestMaskColorClip(const BitmapDeviceSharedPtr& rDevice)
171 BitmapDeviceSharedPtr pBmp( createBitmapDevice( rDevice->getSize(),
172 true,
173 Format::EIGHT_BIT_GREY ));
175 ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0h5v10h5v-5h-10z" ));
177 basegfx::B2DPolyPolygon aPoly;
178 basegfx::tools::importFromSvgD( aPoly, aSvg );
179 const basebmp::Color aCol(0xFF);
180 pBmp->clear( basebmp::Color(0) );
181 pBmp->fillPolyPolygon(
182 aPoly,
183 aCol,
184 basebmp::DrawMode_PAINT );
186 const basegfx::B2IBox aSourceRect(0,0,10,10);
187 const basegfx::B2IPoint aDestLeftTop(0,0);
188 const Color aCol2(0xF0F0F0F0);
189 rDevice->drawMaskedColor(
190 aCol2,
191 pBmp,
192 aSourceRect,
193 aDestLeftTop,
194 mpClipMask );
195 const basegfx::B2IPoint aPt(1,1);
196 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 41",
197 countPixel( rDevice, rDevice->getPixel(aPt) ) == 41);
201 public:
202 void setUp()
204 const basegfx::B2ISize aSize(11,11);
205 mpClipMask = createBitmapDevice( aSize,
206 true,
207 Format::ONE_BIT_MSB_GREY );
208 mpDevice1bpp = createBitmapDevice( aSize,
209 true,
210 Format::ONE_BIT_MSB_PAL );
211 mpDevice32bpp = createBitmapDevice( aSize,
212 true,
213 Format::THIRTYTWO_BIT_TC_MASK );
215 ::rtl::OUString aSvg( RTL_CONSTASCII_USTRINGPARAM( "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" ));
216 basegfx::B2DPolyPolygon aPoly;
217 basegfx::tools::importFromSvgD( aPoly, aSvg );
218 mpClipMask->clear(Color(0));
219 mpClipMask->drawPolygon(
220 aPoly.getB2DPolygon(0),
221 Color(0xFFFFFFFF),
222 DrawMode_PAINT );
225 void testPixelClip()
227 implTestPixelClip( mpDevice1bpp );
228 implTestPixelClip( mpDevice32bpp );
231 void testLineClip()
233 implTestLineClip( mpDevice1bpp );
234 implTestLineClip( mpDevice32bpp );
237 void testFillClip()
239 implTestFillClip( mpDevice1bpp );
240 implTestFillClip( mpDevice32bpp );
243 void testBmpClip()
245 implTestBmpClip( mpDevice1bpp );
246 implTestBmpClip( mpDevice32bpp );
249 void testMaskColorClip()
251 implTestMaskColorClip( mpDevice1bpp );
252 implTestMaskColorClip( mpDevice32bpp );
255 // Change the following lines only, if you add, remove or rename
256 // member functions of the current class,
257 // because these macros are need by auto register mechanism.
259 CPPUNIT_TEST_SUITE(ClipTest);
260 CPPUNIT_TEST(testPixelClip);
261 CPPUNIT_TEST(testLineClip);
262 CPPUNIT_TEST(testFillClip);
263 CPPUNIT_TEST(testBmpClip);
264 CPPUNIT_TEST(testMaskColorClip);
265 CPPUNIT_TEST_SUITE_END();
268 CPPUNIT_TEST_SUITE_REGISTRATION(ClipTest);
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */