update dev300-m58
[ooovba.git] / basebmp / test / filltest.cxx
blob10cbf8a372b662ba5fb5fd2a9ac8292a1f3698a1
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: filltest.cxx,v $
10 * $Revision: 1.6 $
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/b2drange.hxx>
37 #include <basegfx/point/b2ipoint.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
39 #include <basegfx/polygon/b2dpolygontools.hxx>
40 #include <basegfx/polygon/b2dpolypolygon.hxx>
41 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 #include <basebmp/color.hxx>
44 #include <basebmp/scanlineformats.hxx>
45 #include <basebmp/bitmapdevice.hxx>
46 #include <basebmp/debug.hxx>
47 #include "tools.hxx"
49 #include <iostream>
50 #include <fstream>
52 using namespace ::basebmp;
54 namespace
57 std::ofstream output("32bpp_test.dump");
58 debugDump( mpDevice32bpp, output );
61 class FillTest : public CppUnit::TestFixture
63 private:
64 BitmapDeviceSharedPtr mpDevice1bpp;
65 BitmapDeviceSharedPtr mpDevice32bpp;
67 void implTestRectFill(const BitmapDeviceSharedPtr& rDevice)
69 rDevice->clear(Color(0));
71 const basegfx::B2DRange aRect(1,1,10,10);
73 const Color aCol(0xFFFFFFFF);
74 rDevice->fillPolyPolygon(
75 basegfx::B2DPolyPolygon(
76 basegfx::tools::createPolygonFromRect( aRect )),
77 aCol,
78 DrawMode_PAINT );
80 const basegfx::B2IPoint aPt1(1,1);
81 CPPUNIT_ASSERT_MESSAGE("first pixel set",
82 rDevice->getPixel(aPt1) == aCol);
83 const basegfx::B2IPoint aPt2(9,9);
84 CPPUNIT_ASSERT_MESSAGE("last pixel set",
85 rDevice->getPixel(aPt2) == aCol);
86 const basegfx::B2IPoint aPt3(0,0);
87 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
88 rDevice->getPixel(aPt3) != aCol);
89 const basegfx::B2IPoint aPt4(10,10);
90 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
91 rDevice->getPixel(aPt4) != aCol);
93 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 81",
94 countPixel( rDevice, aCol ) == 81);
97 void implTestCornerCases(const BitmapDeviceSharedPtr& rDevice)
99 rDevice->clear(Color(0));
101 const basegfx::B2DRange aEmpty1(0,0,0,11);
102 const basegfx::B2DRange aEmpty2(0,0,11,0);
103 const basegfx::B2DRange aVertLineLeft(0,0,1,11);
104 const basegfx::B2DRange aVertLineRight(10,0,11,11);
105 const basegfx::B2DRange aHorzLineTop(0,0,11,1);
106 const basegfx::B2DRange aHorzLineBottom(0,10,11,11);
108 const Color aCol(0xFFFFFFFF);
109 rDevice->fillPolyPolygon(
110 basegfx::B2DPolyPolygon(
111 basegfx::tools::createPolygonFromRect( aEmpty1 )),
112 aCol,
113 DrawMode_PAINT );
114 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
115 countPixel( rDevice, aCol ) == 0);
117 rDevice->fillPolyPolygon(
118 basegfx::B2DPolyPolygon(
119 basegfx::tools::createPolygonFromRect( aEmpty2 )),
120 aCol,
121 DrawMode_PAINT );
122 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0",
123 countPixel( rDevice, aCol ) == 0);
125 rDevice->fillPolyPolygon(
126 basegfx::B2DPolyPolygon(
127 basegfx::tools::createPolygonFromRect( aVertLineLeft )),
128 aCol,
129 DrawMode_PAINT );
130 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
131 countPixel( rDevice, aCol ) == 11);
132 const basegfx::B2IPoint aPt1(0,0);
133 CPPUNIT_ASSERT_MESSAGE("first pixel set",
134 rDevice->getPixel(aPt1) == aCol);
136 rDevice->fillPolyPolygon(
137 basegfx::B2DPolyPolygon(
138 basegfx::tools::createPolygonFromRect( aVertLineRight )),
139 aCol,
140 DrawMode_PAINT );
141 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 22",
142 countPixel( rDevice, aCol ) == 22);
143 const basegfx::B2IPoint aPt2(10,10);
144 CPPUNIT_ASSERT_MESSAGE("last pixel set",
145 rDevice->getPixel(aPt2) == aCol);
147 rDevice->fillPolyPolygon(
148 basegfx::B2DPolyPolygon(
149 basegfx::tools::createPolygonFromRect( aHorzLineTop )),
150 aCol,
151 DrawMode_PAINT );
152 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 31",
153 countPixel( rDevice, aCol ) == 31);
154 const basegfx::B2IPoint aPt3(5,0);
155 CPPUNIT_ASSERT_MESSAGE("top-middle pixel set",
156 rDevice->getPixel(aPt3) == aCol);
158 rDevice->fillPolyPolygon(
159 basegfx::B2DPolyPolygon(
160 basegfx::tools::createPolygonFromRect( aHorzLineBottom )),
161 aCol,
162 DrawMode_PAINT );
163 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 40",
164 countPixel( rDevice, aCol ) == 40);
165 const basegfx::B2IPoint aPt4(5,10);
166 CPPUNIT_ASSERT_MESSAGE("bottom-middle pixel set",
167 rDevice->getPixel(aPt4) == aCol);
169 ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
170 "m 0 0l7 7h-1z" );
172 basegfx::B2DPolyPolygon aPoly;
173 basegfx::tools::importFromSvgD( aPoly, aSvg );
174 rDevice->fillPolyPolygon(
175 aPoly,
176 aCol,
177 DrawMode_PAINT );
178 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 43",
179 countPixel( rDevice, aCol ) == 43);
182 void implTestClipping(const BitmapDeviceSharedPtr& rDevice)
184 rDevice->clear(Color(0));
186 const basegfx::B2DRange aLeftTop(-10,-10,1,1);
187 const basegfx::B2DRange aRightTop(10,-10,20,1);
188 const basegfx::B2DRange aLeftBottom(-10,10,1,20);
189 const basegfx::B2DRange aRightBottom(10,10,20,20);
190 const basegfx::B2DRange aAllOver(-10,-10,20,20);
192 const Color aCol(0xFFFFFFFF);
193 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
194 basegfx::tools::createPolygonFromRect(aLeftTop)),
195 aCol,
196 DrawMode_PAINT );
197 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1",
198 countPixel( rDevice, aCol ) == 1);
200 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
201 basegfx::tools::createPolygonFromRect(aRightTop)),
202 aCol,
203 DrawMode_PAINT );
204 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2",
205 countPixel( rDevice, aCol ) == 2);
207 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
208 basegfx::tools::createPolygonFromRect(aLeftBottom)),
209 aCol,
210 DrawMode_PAINT );
211 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 3",
212 countPixel( rDevice, aCol ) == 3);
214 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
215 basegfx::tools::createPolygonFromRect(aRightBottom)),
216 aCol,
217 DrawMode_PAINT );
218 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
219 countPixel( rDevice, aCol ) == 4);
221 rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
222 basegfx::tools::createPolygonFromRect(aAllOver)),
223 aCol,
224 DrawMode_PAINT );
225 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 121",
226 countPixel( rDevice, aCol ) == 121);
229 public:
230 void setUp()
232 const basegfx::B2ISize aSize(11,11);
233 mpDevice1bpp = createBitmapDevice( aSize,
234 true,
235 Format::ONE_BIT_MSB_PAL );
236 mpDevice32bpp = createBitmapDevice( aSize,
237 true,
238 Format::THIRTYTWO_BIT_TC_MASK );
241 void testRectFill()
243 implTestRectFill( mpDevice1bpp );
244 implTestRectFill( mpDevice32bpp );
247 void testClipping()
249 implTestClipping( mpDevice1bpp );
250 implTestClipping( mpDevice32bpp );
253 void testCornerCases()
255 implTestCornerCases( mpDevice1bpp );
256 implTestCornerCases( mpDevice32bpp );
259 // Change the following lines only, if you add, remove or rename
260 // member functions of the current class,
261 // because these macros are need by auto register mechanism.
263 CPPUNIT_TEST_SUITE(FillTest);
264 CPPUNIT_TEST(testRectFill);
265 CPPUNIT_TEST(testClipping);
266 CPPUNIT_TEST(testCornerCases);
267 CPPUNIT_TEST_SUITE_END();
270 // -----------------------------------------------------------------------------
271 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(FillTest, "FillTest");
275 // -----------------------------------------------------------------------------
277 // this macro creates an empty function, which will called by the RegisterAllFunctions()
278 // to let the user the possibility to also register some functions by hand.
279 //NOADDITIONAL;