xref: /aoo42x/main/basebmp/test/linetest.cxx (revision 97c63c1b)
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
1069de5a4cSAndrew Rist  *
1169de5a4cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1269de5a4cSAndrew Rist  *
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.
1969de5a4cSAndrew Rist  *
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/point/b2ipoint.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <basebmp/color.hxx>
34cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
35cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx>
36cdf0e10cSrcweir #include <basebmp/debug.hxx>
37cdf0e10cSrcweir #include "tools.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <iostream>
40cdf0e10cSrcweir #include <fstream>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace ::basebmp;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace
45cdf0e10cSrcweir {
46cdf0e10cSrcweir /*
47cdf0e10cSrcweir   std::ofstream output("32bpp_test.dump");
48cdf0e10cSrcweir   debugDump( mpDevice32bpp, output );
49cdf0e10cSrcweir */
50cdf0e10cSrcweir 
51*97c63c1bSDamjan Jovanovic class LineTest : public ::testing::Test
52cdf0e10cSrcweir {
53*97c63c1bSDamjan Jovanovic protected:
54cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice1bpp;
55cdf0e10cSrcweir     BitmapDeviceSharedPtr mpDevice32bpp;
56cdf0e10cSrcweir 
implTestBasicDiagonalLines(const BitmapDeviceSharedPtr & rDevice)57cdf0e10cSrcweir     void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice)
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         rDevice->clear(Color(0));
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         const basegfx::B2IPoint aPt1(1,1);
62cdf0e10cSrcweir         const basegfx::B2IPoint aPt2(9,9);
63cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
64cdf0e10cSrcweir         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
65*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
66*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
67cdf0e10cSrcweir         const basegfx::B2IPoint aPt3(0,0);
68*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt3) != aCol) << "topmost pixel not set";
69cdf0e10cSrcweir         const basegfx::B2IPoint aPt4(10,10);
70*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt4) != aCol) << "bottommost pixel not set";
71cdf0e10cSrcweir 
72*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(countPixel( rDevice, aCol ) == 9) << "number of rendered pixel is not 9";
73cdf0e10cSrcweir 
74cdf0e10cSrcweir         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
75cdf0e10cSrcweir 
76*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(countPixel( rDevice, aCol ) == 9)
77*97c63c1bSDamjan Jovanovic             << "number of rendered pixel after reversed paint is not 9";
78cdf0e10cSrcweir     }
79cdf0e10cSrcweir 
implTestBasicHorizontalLines(const BitmapDeviceSharedPtr & rDevice)80cdf0e10cSrcweir     void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice)
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         rDevice->clear(Color(0));
83cdf0e10cSrcweir 
84cdf0e10cSrcweir         const basegfx::B2IPoint aPt1(10,10);
85cdf0e10cSrcweir         const basegfx::B2IPoint aPt2(0,10);
86cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
87cdf0e10cSrcweir         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
88*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
89*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
90*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(countPixel( rDevice, aCol ) == 11) << "number of rendered pixel is not 11";
91cdf0e10cSrcweir 
92cdf0e10cSrcweir         rDevice->clear(Color(0));
93cdf0e10cSrcweir         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
94*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
95*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
96*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(countPixel( rDevice, aCol ) == 11) << "number of rendered pixel is not 11";
97cdf0e10cSrcweir     }
98cdf0e10cSrcweir 
implTestBasicVerticalLines(const BitmapDeviceSharedPtr & rDevice)99cdf0e10cSrcweir     void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice)
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         rDevice->clear(Color(0));
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         const basegfx::B2IPoint aPt1(1,1);
104cdf0e10cSrcweir         const basegfx::B2IPoint aPt2(1,9);
105cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
106cdf0e10cSrcweir         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
107*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
108*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
109cdf0e10cSrcweir         const basegfx::B2IPoint aPt3(0,0);
110*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt3) != aCol) << "topmost pixel not set";
111cdf0e10cSrcweir         const basegfx::B2IPoint aPt4(0,10);
112*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt4) != aCol) << "bottommost pixel not set";
113cdf0e10cSrcweir 
114*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(countPixel( rDevice, aCol ) == 9) << "number of rendered pixel is not 9";
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     // test pixel rounding (should always tend towards start point of
118cdf0e10cSrcweir     // the line)
implTestTieBreaking(const BitmapDeviceSharedPtr & rDevice)119cdf0e10cSrcweir     void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice)
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         rDevice->clear(Color(0));
122cdf0e10cSrcweir 
123cdf0e10cSrcweir         const basegfx::B2IPoint aPt1(1,1);
124cdf0e10cSrcweir         const basegfx::B2IPoint aPt2(3,2);
125cdf0e10cSrcweir         const Color aCol(0xFFFFFFFF);
126cdf0e10cSrcweir         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
127*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt1) == aCol) << "first pixel set";
128*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol) << "second pixel set";
129*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(aPt2) == aCol) << "last pixel set";
130*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(countPixel( rDevice, aCol ) == 3)
131*97c63c1bSDamjan Jovanovic             << "number of rendered pixel after reversed paint is not 3";
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
134*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol)
135*97c63c1bSDamjan Jovanovic             << "alternate second pixel set";
136cdf0e10cSrcweir 
137*97c63c1bSDamjan Jovanovic         ASSERT_TRUE(countPixel( rDevice, aCol ) == 4)
138*97c63c1bSDamjan Jovanovic             << "number of rendered pixel after reversed paint is not 4";
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir public:
SetUp()142*97c63c1bSDamjan Jovanovic     virtual void SetUp()
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         const basegfx::B2ISize aSize(11,11);
145cdf0e10cSrcweir         mpDevice1bpp = createBitmapDevice( aSize,
146cdf0e10cSrcweir                                            true,
147cdf0e10cSrcweir                                            Format::ONE_BIT_MSB_PAL );
148cdf0e10cSrcweir         mpDevice32bpp = createBitmapDevice( aSize,
149cdf0e10cSrcweir                                            true,
150cdf0e10cSrcweir                                            Format::THIRTYTWO_BIT_TC_MASK );
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir };
153cdf0e10cSrcweir 
TEST_F(LineTest,testBasicDiagonalLines)154*97c63c1bSDamjan Jovanovic TEST_F(LineTest, testBasicDiagonalLines)
155*97c63c1bSDamjan Jovanovic {
156*97c63c1bSDamjan Jovanovic     implTestBasicDiagonalLines( mpDevice1bpp );
157*97c63c1bSDamjan Jovanovic     implTestBasicDiagonalLines( mpDevice32bpp );
158*97c63c1bSDamjan Jovanovic }
159*97c63c1bSDamjan Jovanovic 
TEST_F(LineTest,testBasicHorizontalLines)160*97c63c1bSDamjan Jovanovic TEST_F(LineTest, testBasicHorizontalLines)
161*97c63c1bSDamjan Jovanovic {
162*97c63c1bSDamjan Jovanovic     implTestBasicHorizontalLines( mpDevice1bpp );
163*97c63c1bSDamjan Jovanovic     implTestBasicHorizontalLines( mpDevice32bpp );
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
TEST_F(LineTest,testBasicVerticalLines)166*97c63c1bSDamjan Jovanovic TEST_F(LineTest, testBasicVerticalLines)
167*97c63c1bSDamjan Jovanovic {
168*97c63c1bSDamjan Jovanovic     implTestBasicVerticalLines( mpDevice1bpp );
169*97c63c1bSDamjan Jovanovic     implTestBasicVerticalLines( mpDevice32bpp );
170*97c63c1bSDamjan Jovanovic }
171cdf0e10cSrcweir 
172*97c63c1bSDamjan Jovanovic // test pixel rounding (should always tend towards start point of
173*97c63c1bSDamjan Jovanovic // the line)
TEST_F(LineTest,testTieBreaking)174*97c63c1bSDamjan Jovanovic TEST_F(LineTest, testTieBreaking)
175*97c63c1bSDamjan Jovanovic {
176*97c63c1bSDamjan Jovanovic     implTestTieBreaking( mpDevice1bpp );
177*97c63c1bSDamjan Jovanovic     implTestTieBreaking( mpDevice32bpp );
178*97c63c1bSDamjan Jovanovic }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181*97c63c1bSDamjan Jovanovic }
182