xref: /aoo4110/main/basebmp/test/linetest.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // autogenerated file with codegen.pl
25 
26 #include "preextstl.h"
27 #include "cppunit/TestAssert.h"
28 #include "cppunit/TestFixture.h"
29 #include "cppunit/extensions/HelperMacros.h"
30 #include "postextstl.h"
31 
32 #include <basegfx/vector/b2isize.hxx>
33 #include <basegfx/point/b2ipoint.hxx>
34 
35 #include <basebmp/color.hxx>
36 #include <basebmp/scanlineformats.hxx>
37 #include <basebmp/bitmapdevice.hxx>
38 #include <basebmp/debug.hxx>
39 #include "tools.hxx"
40 
41 #include <iostream>
42 #include <fstream>
43 
44 using namespace ::basebmp;
45 
46 namespace
47 {
48 /*
49   std::ofstream output("32bpp_test.dump");
50   debugDump( mpDevice32bpp, output );
51 */
52 
53 class LineTest : public CppUnit::TestFixture
54 {
55 private:
56     BitmapDeviceSharedPtr mpDevice1bpp;
57     BitmapDeviceSharedPtr mpDevice32bpp;
58 
implTestBasicDiagonalLines(const BitmapDeviceSharedPtr & rDevice)59     void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice)
60     {
61         rDevice->clear(Color(0));
62 
63         const basegfx::B2IPoint aPt1(1,1);
64         const basegfx::B2IPoint aPt2(9,9);
65         const Color aCol(0xFFFFFFFF);
66         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
67         CPPUNIT_ASSERT_MESSAGE("first pixel set",
68                                rDevice->getPixel(aPt1) == aCol);
69         CPPUNIT_ASSERT_MESSAGE("last pixel set",
70                                rDevice->getPixel(aPt2) == aCol);
71         const basegfx::B2IPoint aPt3(0,0);
72         CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
73                                rDevice->getPixel(aPt3) != aCol);
74         const basegfx::B2IPoint aPt4(10,10);
75         CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
76                                rDevice->getPixel(aPt4) != aCol);
77 
78         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
79                                countPixel( rDevice, aCol ) == 9);
80 
81         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
82 
83         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
84                                "reversed paint is not 9",
85                                countPixel( rDevice, aCol ) == 9);
86     }
87 
implTestBasicHorizontalLines(const BitmapDeviceSharedPtr & rDevice)88     void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice)
89     {
90         rDevice->clear(Color(0));
91 
92         const basegfx::B2IPoint aPt1(10,10);
93         const basegfx::B2IPoint aPt2(0,10);
94         const Color aCol(0xFFFFFFFF);
95         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
96         CPPUNIT_ASSERT_MESSAGE("first pixel set",
97                                rDevice->getPixel(aPt1) == aCol);
98         CPPUNIT_ASSERT_MESSAGE("last pixel set",
99                                rDevice->getPixel(aPt2) == aCol);
100         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
101                                countPixel( rDevice, aCol ) == 11);
102 
103         rDevice->clear(Color(0));
104         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
105         CPPUNIT_ASSERT_MESSAGE("first pixel set",
106                                rDevice->getPixel(aPt1) == aCol);
107         CPPUNIT_ASSERT_MESSAGE("last pixel set",
108                                rDevice->getPixel(aPt2) == aCol);
109         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
110                                countPixel( rDevice, aCol ) == 11);
111     }
112 
implTestBasicVerticalLines(const BitmapDeviceSharedPtr & rDevice)113     void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice)
114     {
115         rDevice->clear(Color(0));
116 
117         const basegfx::B2IPoint aPt1(1,1);
118         const basegfx::B2IPoint aPt2(1,9);
119         const Color aCol(0xFFFFFFFF);
120         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
121         CPPUNIT_ASSERT_MESSAGE("first pixel set",
122                                rDevice->getPixel(aPt1) == aCol);
123         CPPUNIT_ASSERT_MESSAGE("last pixel set",
124                                rDevice->getPixel(aPt2) == aCol);
125         const basegfx::B2IPoint aPt3(0,0);
126         CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
127                                rDevice->getPixel(aPt3) != aCol);
128         const basegfx::B2IPoint aPt4(0,10);
129         CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
130                                rDevice->getPixel(aPt4) != aCol);
131 
132         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
133                                countPixel( rDevice, aCol ) == 9);
134     }
135 
136     // test pixel rounding (should always tend towards start point of
137     // the line)
implTestTieBreaking(const BitmapDeviceSharedPtr & rDevice)138     void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice)
139     {
140         rDevice->clear(Color(0));
141 
142         const basegfx::B2IPoint aPt1(1,1);
143         const basegfx::B2IPoint aPt2(3,2);
144         const Color aCol(0xFFFFFFFF);
145         rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
146         CPPUNIT_ASSERT_MESSAGE("first pixel set",
147                                rDevice->getPixel(aPt1) == aCol);
148         CPPUNIT_ASSERT_MESSAGE("second pixel set",
149                                rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol);
150         CPPUNIT_ASSERT_MESSAGE("last pixel set",
151                                rDevice->getPixel(aPt2) == aCol);
152         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
153                                "reversed paint is not 3",
154                                countPixel( rDevice, aCol ) == 3);
155 
156         rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
157         CPPUNIT_ASSERT_MESSAGE("alternate second pixel set",
158                                rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol);
159 
160         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
161                                "reversed paint is not 4",
162                                countPixel( rDevice, aCol ) == 4);
163     }
164 
165 public:
setUp()166     void setUp()
167     {
168         const basegfx::B2ISize aSize(11,11);
169         mpDevice1bpp = createBitmapDevice( aSize,
170                                            true,
171                                            Format::ONE_BIT_MSB_PAL );
172         mpDevice32bpp = createBitmapDevice( aSize,
173                                            true,
174                                            Format::THIRTYTWO_BIT_TC_MASK );
175     }
176 
testBasicDiagonalLines()177     void testBasicDiagonalLines()
178     {
179         implTestBasicDiagonalLines( mpDevice1bpp );
180         implTestBasicDiagonalLines( mpDevice32bpp );
181     }
182 
testBasicHorizontalLines()183     void testBasicHorizontalLines()
184     {
185         implTestBasicHorizontalLines( mpDevice1bpp );
186         implTestBasicHorizontalLines( mpDevice32bpp );
187     }
188 
testBasicVerticalLines()189     void testBasicVerticalLines()
190     {
191         implTestBasicVerticalLines( mpDevice1bpp );
192         implTestBasicVerticalLines( mpDevice32bpp );
193     }
194 
195     // test pixel rounding (should always tend towards start point of
196     // the line)
testTieBreaking()197     void testTieBreaking()
198     {
199         implTestTieBreaking( mpDevice1bpp );
200         implTestTieBreaking( mpDevice32bpp );
201     }
202 
203     // Change the following lines only, if you add, remove or rename
204     // member functions of the current class,
205     // because these macros are need by auto register mechanism.
206 
207     CPPUNIT_TEST_SUITE(LineTest);
208     CPPUNIT_TEST(testBasicDiagonalLines);
209     CPPUNIT_TEST(testBasicHorizontalLines);
210     CPPUNIT_TEST(testBasicVerticalLines);
211     CPPUNIT_TEST(testTieBreaking);
212     CPPUNIT_TEST_SUITE_END();
213 };
214 
215 // -----------------------------------------------------------------------------
216 CPPUNIT_TEST_SUITE_REGISTRATION(LineTest);
217 }
218 
219 
220 // -----------------------------------------------------------------------------
221 
222 // this macro creates an empty function, which will called by the RegisterAllFunctions()
223 // to let the user the possibility to also register some functions by hand.
224 //NOADDITIONAL;
225 
226