Bump for 3.6-28
[LibreOffice.git] / basebmp / test / linetest.cxx
blob6e0297848c810ae524d38c88922e18598e567e98
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>
41 #include <basebmp/color.hxx>
42 #include <basebmp/scanlineformats.hxx>
43 #include <basebmp/bitmapdevice.hxx>
44 #include "tools.hxx"
46 using namespace ::basebmp;
48 namespace
50 class LineTest : public CppUnit::TestFixture
52 private:
53 BitmapDeviceSharedPtr mpDevice1bpp;
54 BitmapDeviceSharedPtr mpDevice32bpp;
56 void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr& rDevice)
58 rDevice->clear(Color(0));
60 const basegfx::B2IPoint aPt1(1,1);
61 const basegfx::B2IPoint aPt2(9,9);
62 const Color aCol(0xFFFFFFFF);
63 rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
64 CPPUNIT_ASSERT_MESSAGE("first pixel set",
65 rDevice->getPixel(aPt1) == aCol);
66 CPPUNIT_ASSERT_MESSAGE("last pixel set",
67 rDevice->getPixel(aPt2) == aCol);
68 const basegfx::B2IPoint aPt3(0,0);
69 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
70 rDevice->getPixel(aPt3) != aCol);
71 const basegfx::B2IPoint aPt4(10,10);
72 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
73 rDevice->getPixel(aPt4) != aCol);
75 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
76 countPixel( rDevice, aCol ) == 9);
78 rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
80 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
81 "reversed paint is not 9",
82 countPixel( rDevice, aCol ) == 9);
85 void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr& rDevice)
87 rDevice->clear(Color(0));
89 const basegfx::B2IPoint aPt1(10,10);
90 const basegfx::B2IPoint aPt2(0,10);
91 const Color aCol(0xFFFFFFFF);
92 rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
93 CPPUNIT_ASSERT_MESSAGE("first pixel set",
94 rDevice->getPixel(aPt1) == aCol);
95 CPPUNIT_ASSERT_MESSAGE("last pixel set",
96 rDevice->getPixel(aPt2) == aCol);
97 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
98 countPixel( rDevice, aCol ) == 11);
100 rDevice->clear(Color(0));
101 rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
102 CPPUNIT_ASSERT_MESSAGE("first pixel set",
103 rDevice->getPixel(aPt1) == aCol);
104 CPPUNIT_ASSERT_MESSAGE("last pixel set",
105 rDevice->getPixel(aPt2) == aCol);
106 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
107 countPixel( rDevice, aCol ) == 11);
110 void implTestBasicVerticalLines(const BitmapDeviceSharedPtr& rDevice)
112 rDevice->clear(Color(0));
114 const basegfx::B2IPoint aPt1(1,1);
115 const basegfx::B2IPoint aPt2(1,9);
116 const Color aCol(0xFFFFFFFF);
117 rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
118 CPPUNIT_ASSERT_MESSAGE("first pixel set",
119 rDevice->getPixel(aPt1) == aCol);
120 CPPUNIT_ASSERT_MESSAGE("last pixel set",
121 rDevice->getPixel(aPt2) == aCol);
122 const basegfx::B2IPoint aPt3(0,0);
123 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
124 rDevice->getPixel(aPt3) != aCol);
125 const basegfx::B2IPoint aPt4(0,10);
126 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
127 rDevice->getPixel(aPt4) != aCol);
129 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
130 countPixel( rDevice, aCol ) == 9);
133 // test pixel rounding (should always tend towards start point of
134 // the line)
135 void implTestTieBreaking(const BitmapDeviceSharedPtr& rDevice)
137 rDevice->clear(Color(0));
139 const basegfx::B2IPoint aPt1(1,1);
140 const basegfx::B2IPoint aPt2(3,2);
141 const Color aCol(0xFFFFFFFF);
142 rDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
143 CPPUNIT_ASSERT_MESSAGE("first pixel set",
144 rDevice->getPixel(aPt1) == aCol);
145 CPPUNIT_ASSERT_MESSAGE("second pixel set",
146 rDevice->getPixel(basegfx::B2IPoint(2,1)) == aCol);
147 CPPUNIT_ASSERT_MESSAGE("last pixel set",
148 rDevice->getPixel(aPt2) == aCol);
149 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
150 "reversed paint is not 3",
151 countPixel( rDevice, aCol ) == 3);
153 rDevice->drawLine( aPt2, aPt1, aCol, DrawMode_PAINT );
154 CPPUNIT_ASSERT_MESSAGE("alternate second pixel set",
155 rDevice->getPixel(basegfx::B2IPoint(2,2)) == aCol);
157 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
158 "reversed paint is not 4",
159 countPixel( rDevice, aCol ) == 4);
162 public:
163 void setUp()
165 const basegfx::B2ISize aSize(11,11);
166 mpDevice1bpp = createBitmapDevice( aSize,
167 true,
168 Format::ONE_BIT_MSB_PAL );
169 mpDevice32bpp = createBitmapDevice( aSize,
170 true,
171 Format::THIRTYTWO_BIT_TC_MASK );
174 void testCornerCases()
176 const basegfx::B2ISize aSize(1,1);
177 BitmapDeviceSharedPtr pDevice = createBitmapDevice(
178 aSize,
179 true,
180 Format::ONE_BIT_MSB_PAL );
182 const basegfx::B2IPoint aPt1(0,0);
183 const basegfx::B2IPoint aPt2(10,10);
184 CPPUNIT_ASSERT_MESSAGE("only pixel cleared",
185 pDevice->getPixelData(aPt1) == 0);
187 const Color aCol(0xFFFFFFFF);
188 pDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
189 CPPUNIT_ASSERT_MESSAGE("only pixel set",
190 pDevice->getPixelData(aPt1) == 1);
192 const basegfx::B2ISize aSize2(1,0);
193 pDevice = createBitmapDevice(
194 aSize2,
195 true,
196 Format::ONE_BIT_MSB_PAL );
198 CPPUNIT_ASSERT_MESSAGE("only pixel cleared",
199 pDevice->getPixelData(aPt1) == 0);
201 pDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT );
202 CPPUNIT_ASSERT_MESSAGE("only pixel still cleared",
203 pDevice->getPixelData(aPt1) == 0);
206 void testBasicDiagonalLines()
208 implTestBasicDiagonalLines( mpDevice1bpp );
209 implTestBasicDiagonalLines( mpDevice32bpp );
212 void testBasicHorizontalLines()
214 implTestBasicHorizontalLines( mpDevice1bpp );
215 implTestBasicHorizontalLines( mpDevice32bpp );
218 void testBasicVerticalLines()
220 implTestBasicVerticalLines( mpDevice1bpp );
221 implTestBasicVerticalLines( mpDevice32bpp );
224 // test pixel rounding (should always tend towards start point of
225 // the line)
226 void testTieBreaking()
228 implTestTieBreaking( mpDevice1bpp );
229 implTestTieBreaking( mpDevice32bpp );
232 // Change the following lines only, if you add, remove or rename
233 // member functions of the current class,
234 // because these macros are need by auto register mechanism.
236 CPPUNIT_TEST_SUITE(LineTest);
237 CPPUNIT_TEST(testCornerCases);
238 CPPUNIT_TEST(testBasicDiagonalLines);
239 CPPUNIT_TEST(testBasicHorizontalLines);
240 CPPUNIT_TEST(testBasicVerticalLines);
241 CPPUNIT_TEST(testTieBreaking);
242 CPPUNIT_TEST_SUITE_END();
245 CPPUNIT_TEST_SUITE_REGISTRATION(LineTest);
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */