169de5a4cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
369de5a4cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
469de5a4cSAndrew Rist * or more contributor license agreements. See the NOTICE file
569de5a4cSAndrew Rist * distributed with this work for additional information
669de5a4cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
769de5a4cSAndrew Rist * to you under the Apache License, Version 2.0 (the
869de5a4cSAndrew Rist * "License"); you may not use this file except in compliance
969de5a4cSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
1169de5a4cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
1369de5a4cSAndrew Rist * Unless required by applicable law or agreed to in writing,
1469de5a4cSAndrew Rist * software distributed under the License is distributed on an
1569de5a4cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1669de5a4cSAndrew Rist * KIND, either express or implied. See the License for the
1769de5a4cSAndrew Rist * specific language governing permissions and limitations
1869de5a4cSAndrew Rist * under the License.
19cdf0e10cSrcweir *
2069de5a4cSAndrew Rist *************************************************************/
2169de5a4cSAndrew Rist
2269de5a4cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // autogenerated file with codegen.pl
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "preextstl.h"
27*97c63c1bSDamjan Jovanovic #include "gtest/gtest.h"
28cdf0e10cSrcweir #include "postextstl.h"
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx>
31cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
32cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx>
33cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
34cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
35cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
36cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <basebmp/color.hxx>
39cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
40cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx>
41cdf0e10cSrcweir #include <basebmp/debug.hxx>
42cdf0e10cSrcweir #include "tools.hxx"
43cdf0e10cSrcweir
44cdf0e10cSrcweir #include <iostream>
45cdf0e10cSrcweir #include <fstream>
46cdf0e10cSrcweir
47cdf0e10cSrcweir using namespace ::basebmp;
48cdf0e10cSrcweir
49cdf0e10cSrcweir namespace
50cdf0e10cSrcweir {
51cdf0e10cSrcweir /*
52cdf0e10cSrcweir std::ofstream output("32bpp_test.dump");
53cdf0e10cSrcweir debugDump( mpDevice32bpp, output );
54cdf0e10cSrcweir */
55cdf0e10cSrcweir
56*97c63c1bSDamjan Jovanovic class FillTest : public ::testing::Test
57cdf0e10cSrcweir {
58*97c63c1bSDamjan Jovanovic protected:
59cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice1bpp;
60cdf0e10cSrcweir BitmapDeviceSharedPtr mpDevice32bpp;
61cdf0e10cSrcweir
implTestRectFill(const BitmapDeviceSharedPtr & rDevice)62cdf0e10cSrcweir void implTestRectFill(const BitmapDeviceSharedPtr& rDevice)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir rDevice->clear(Color(0));
65cdf0e10cSrcweir
66cdf0e10cSrcweir const basegfx::B2DRange aRect(1,1,10,10);
67cdf0e10cSrcweir
68cdf0e10cSrcweir const Color aCol(0xFFFFFFFF);
69cdf0e10cSrcweir rDevice->fillPolyPolygon(
70cdf0e10cSrcweir basegfx::B2DPolyPolygon(
71cdf0e10cSrcweir basegfx::tools::createPolygonFromRect( aRect )),
72cdf0e10cSrcweir aCol,
73cdf0e10cSrcweir DrawMode_PAINT );
74cdf0e10cSrcweir
75cdf0e10cSrcweir const basegfx::B2IPoint aPt1(1,1);
76*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
77cdf0e10cSrcweir const basegfx::B2IPoint aPt2(9,9);
78*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
79cdf0e10cSrcweir const basegfx::B2IPoint aPt3(0,0);
80*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt3) != aCol) << "topmost pixel not set";
81cdf0e10cSrcweir const basegfx::B2IPoint aPt4(10,10);
82*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt4) != aCol) << "bottommost pixel not set";
83cdf0e10cSrcweir
84*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 81) << "number of rendered pixel is not 81";
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
implTestCornerCases(const BitmapDeviceSharedPtr & rDevice)87cdf0e10cSrcweir void implTestCornerCases(const BitmapDeviceSharedPtr& rDevice)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir rDevice->clear(Color(0));
90cdf0e10cSrcweir
91cdf0e10cSrcweir const basegfx::B2DRange aEmpty1(0,0,0,11);
92cdf0e10cSrcweir const basegfx::B2DRange aEmpty2(0,0,11,0);
93cdf0e10cSrcweir const basegfx::B2DRange aVertLineLeft(0,0,1,11);
94cdf0e10cSrcweir const basegfx::B2DRange aVertLineRight(10,0,11,11);
95cdf0e10cSrcweir const basegfx::B2DRange aHorzLineTop(0,0,11,1);
96cdf0e10cSrcweir const basegfx::B2DRange aHorzLineBottom(0,10,11,11);
97cdf0e10cSrcweir
98cdf0e10cSrcweir const Color aCol(0xFFFFFFFF);
99cdf0e10cSrcweir rDevice->fillPolyPolygon(
100cdf0e10cSrcweir basegfx::B2DPolyPolygon(
101cdf0e10cSrcweir basegfx::tools::createPolygonFromRect( aEmpty1 )),
102cdf0e10cSrcweir aCol,
103cdf0e10cSrcweir DrawMode_PAINT );
104*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 0) << "number of rendered pixel is not 0";
105cdf0e10cSrcweir
106cdf0e10cSrcweir rDevice->fillPolyPolygon(
107cdf0e10cSrcweir basegfx::B2DPolyPolygon(
108cdf0e10cSrcweir basegfx::tools::createPolygonFromRect( aEmpty2 )),
109cdf0e10cSrcweir aCol,
110cdf0e10cSrcweir DrawMode_PAINT );
111*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 0) << "number of rendered pixel is not 0";
112cdf0e10cSrcweir
113cdf0e10cSrcweir rDevice->fillPolyPolygon(
114cdf0e10cSrcweir basegfx::B2DPolyPolygon(
115cdf0e10cSrcweir basegfx::tools::createPolygonFromRect( aVertLineLeft )),
116cdf0e10cSrcweir aCol,
117cdf0e10cSrcweir DrawMode_PAINT );
118*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 11) << "number of rendered pixel is not 11";
119cdf0e10cSrcweir const basegfx::B2IPoint aPt1(0,0);
120*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
121cdf0e10cSrcweir
122cdf0e10cSrcweir rDevice->fillPolyPolygon(
123cdf0e10cSrcweir basegfx::B2DPolyPolygon(
124cdf0e10cSrcweir basegfx::tools::createPolygonFromRect( aVertLineRight )),
125cdf0e10cSrcweir aCol,
126cdf0e10cSrcweir DrawMode_PAINT );
127*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 22) << "number of rendered pixel is not 22";
128cdf0e10cSrcweir const basegfx::B2IPoint aPt2(10,10);
129*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
130cdf0e10cSrcweir
131cdf0e10cSrcweir rDevice->fillPolyPolygon(
132cdf0e10cSrcweir basegfx::B2DPolyPolygon(
133cdf0e10cSrcweir basegfx::tools::createPolygonFromRect( aHorzLineTop )),
134cdf0e10cSrcweir aCol,
135cdf0e10cSrcweir DrawMode_PAINT );
136*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 31) << "number of rendered pixel is not 31";
137cdf0e10cSrcweir const basegfx::B2IPoint aPt3(5,0);
138*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt3) == aCol) << "top-middle pixel set";
139cdf0e10cSrcweir
140cdf0e10cSrcweir rDevice->fillPolyPolygon(
141cdf0e10cSrcweir basegfx::B2DPolyPolygon(
142cdf0e10cSrcweir basegfx::tools::createPolygonFromRect( aHorzLineBottom )),
143cdf0e10cSrcweir aCol,
144cdf0e10cSrcweir DrawMode_PAINT );
145*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 40) << "number of rendered pixel is not 40";
146cdf0e10cSrcweir const basegfx::B2IPoint aPt4(5,10);
147*97c63c1bSDamjan Jovanovic ASSERT_TRUE(rDevice->getPixel(aPt4) == aCol) << "bottom-middle pixel set";
148cdf0e10cSrcweir
149cdf0e10cSrcweir ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
150cdf0e10cSrcweir "m 0 0l7 7h-1z" );
151cdf0e10cSrcweir
152cdf0e10cSrcweir basegfx::B2DPolyPolygon aPoly;
153*97c63c1bSDamjan Jovanovic basegfx::tools::importFromSvgD( aPoly, aSvg, false, NULL );
154cdf0e10cSrcweir rDevice->fillPolyPolygon(
155cdf0e10cSrcweir aPoly,
156cdf0e10cSrcweir aCol,
157cdf0e10cSrcweir DrawMode_PAINT );
158*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 43) << "number of rendered pixel is not 43";
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
implTestClipping(const BitmapDeviceSharedPtr & rDevice)161cdf0e10cSrcweir void implTestClipping(const BitmapDeviceSharedPtr& rDevice)
162cdf0e10cSrcweir {
163cdf0e10cSrcweir rDevice->clear(Color(0));
164cdf0e10cSrcweir
165cdf0e10cSrcweir const basegfx::B2DRange aLeftTop(-10,-10,1,1);
166cdf0e10cSrcweir const basegfx::B2DRange aRightTop(10,-10,20,1);
167cdf0e10cSrcweir const basegfx::B2DRange aLeftBottom(-10,10,1,20);
168cdf0e10cSrcweir const basegfx::B2DRange aRightBottom(10,10,20,20);
169cdf0e10cSrcweir const basegfx::B2DRange aAllOver(-10,-10,20,20);
170cdf0e10cSrcweir
171cdf0e10cSrcweir const Color aCol(0xFFFFFFFF);
172cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
173cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aLeftTop)),
174cdf0e10cSrcweir aCol,
175cdf0e10cSrcweir DrawMode_PAINT );
176*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 1) << "number of rendered pixel is not 1";
177cdf0e10cSrcweir
178cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
179cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aRightTop)),
180cdf0e10cSrcweir aCol,
181cdf0e10cSrcweir DrawMode_PAINT );
182*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 2) << "number of rendered pixel is not 2";
183cdf0e10cSrcweir
184cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
185cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aLeftBottom)),
186cdf0e10cSrcweir aCol,
187cdf0e10cSrcweir DrawMode_PAINT );
188*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 3) << "number of rendered pixel is not 3";
189cdf0e10cSrcweir
190cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
191cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aRightBottom)),
192cdf0e10cSrcweir aCol,
193cdf0e10cSrcweir DrawMode_PAINT );
194*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 4) << "number of rendered pixel is not 4";
195cdf0e10cSrcweir
196cdf0e10cSrcweir rDevice->fillPolyPolygon( basegfx::B2DPolyPolygon(
197cdf0e10cSrcweir basegfx::tools::createPolygonFromRect(aAllOver)),
198cdf0e10cSrcweir aCol,
199cdf0e10cSrcweir DrawMode_PAINT );
200*97c63c1bSDamjan Jovanovic ASSERT_TRUE(countPixel( rDevice, aCol ) == 121) << "number of rendered pixel is not 121";
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
203cdf0e10cSrcweir public:
SetUp()204*97c63c1bSDamjan Jovanovic virtual void SetUp()
205cdf0e10cSrcweir {
206cdf0e10cSrcweir const basegfx::B2ISize aSize(11,11);
207cdf0e10cSrcweir mpDevice1bpp = createBitmapDevice( aSize,
208cdf0e10cSrcweir true,
209cdf0e10cSrcweir Format::ONE_BIT_MSB_PAL );
210cdf0e10cSrcweir mpDevice32bpp = createBitmapDevice( aSize,
211cdf0e10cSrcweir true,
212cdf0e10cSrcweir Format::THIRTYTWO_BIT_TC_MASK );
213cdf0e10cSrcweir }
214*97c63c1bSDamjan Jovanovic };
215cdf0e10cSrcweir
TEST_F(FillTest,testRectFill)216*97c63c1bSDamjan Jovanovic TEST_F(FillTest, testRectFill)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir implTestRectFill( mpDevice1bpp );
219cdf0e10cSrcweir implTestRectFill( mpDevice32bpp );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
TEST_F(FillTest,testClipping)222*97c63c1bSDamjan Jovanovic TEST_F(FillTest, testClipping)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir implTestClipping( mpDevice1bpp );
225cdf0e10cSrcweir implTestClipping( mpDevice32bpp );
226cdf0e10cSrcweir }
227cdf0e10cSrcweir
TEST_F(FillTest,testCornerCases)228*97c63c1bSDamjan Jovanovic TEST_F(FillTest, testCornerCases)
229cdf0e10cSrcweir {
230cdf0e10cSrcweir implTestCornerCases( mpDevice1bpp );
231cdf0e10cSrcweir implTestCornerCases( mpDevice32bpp );
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
234cdf0e10cSrcweir
235cdf0e10cSrcweir }
236