1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: linetest.cxx,v $
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/point/b2ipoint.hxx>
38 #include <basebmp/color.hxx>
39 #include <basebmp/scanlineformats.hxx>
40 #include <basebmp/bitmapdevice.hxx>
41 #include <basebmp/debug.hxx>
47 using namespace ::basebmp
;
52 std::ofstream output("32bpp_test.dump");
53 debugDump( mpDevice32bpp, output );
56 class LineTest
: public CppUnit::TestFixture
59 BitmapDeviceSharedPtr mpDevice1bpp
;
60 BitmapDeviceSharedPtr mpDevice32bpp
;
62 void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr
& rDevice
)
64 rDevice
->clear(Color(0));
66 const basegfx::B2IPoint
aPt1(1,1);
67 const basegfx::B2IPoint
aPt2(9,9);
68 const Color
aCol(0xFFFFFFFF);
69 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
70 CPPUNIT_ASSERT_MESSAGE("first pixel set",
71 rDevice
->getPixel(aPt1
) == aCol
);
72 CPPUNIT_ASSERT_MESSAGE("last pixel set",
73 rDevice
->getPixel(aPt2
) == aCol
);
74 const basegfx::B2IPoint
aPt3(0,0);
75 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
76 rDevice
->getPixel(aPt3
) != aCol
);
77 const basegfx::B2IPoint
aPt4(10,10);
78 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
79 rDevice
->getPixel(aPt4
) != aCol
);
81 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
82 countPixel( rDevice
, aCol
) == 9);
84 rDevice
->drawLine( aPt2
, aPt1
, aCol
, DrawMode_PAINT
);
86 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
87 "reversed paint is not 9",
88 countPixel( rDevice
, aCol
) == 9);
91 void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr
& rDevice
)
93 rDevice
->clear(Color(0));
95 const basegfx::B2IPoint
aPt1(10,10);
96 const basegfx::B2IPoint
aPt2(0,10);
97 const Color
aCol(0xFFFFFFFF);
98 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
99 CPPUNIT_ASSERT_MESSAGE("first pixel set",
100 rDevice
->getPixel(aPt1
) == aCol
);
101 CPPUNIT_ASSERT_MESSAGE("last pixel set",
102 rDevice
->getPixel(aPt2
) == aCol
);
103 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
104 countPixel( rDevice
, aCol
) == 11);
106 rDevice
->clear(Color(0));
107 rDevice
->drawLine( aPt2
, aPt1
, aCol
, DrawMode_PAINT
);
108 CPPUNIT_ASSERT_MESSAGE("first pixel set",
109 rDevice
->getPixel(aPt1
) == aCol
);
110 CPPUNIT_ASSERT_MESSAGE("last pixel set",
111 rDevice
->getPixel(aPt2
) == aCol
);
112 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
113 countPixel( rDevice
, aCol
) == 11);
116 void implTestBasicVerticalLines(const BitmapDeviceSharedPtr
& rDevice
)
118 rDevice
->clear(Color(0));
120 const basegfx::B2IPoint
aPt1(1,1);
121 const basegfx::B2IPoint
aPt2(1,9);
122 const Color
aCol(0xFFFFFFFF);
123 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
124 CPPUNIT_ASSERT_MESSAGE("first pixel set",
125 rDevice
->getPixel(aPt1
) == aCol
);
126 CPPUNIT_ASSERT_MESSAGE("last pixel set",
127 rDevice
->getPixel(aPt2
) == aCol
);
128 const basegfx::B2IPoint
aPt3(0,0);
129 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
130 rDevice
->getPixel(aPt3
) != aCol
);
131 const basegfx::B2IPoint
aPt4(0,10);
132 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
133 rDevice
->getPixel(aPt4
) != aCol
);
135 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
136 countPixel( rDevice
, aCol
) == 9);
139 // test pixel rounding (should always tend towards start point of
141 void implTestTieBreaking(const BitmapDeviceSharedPtr
& rDevice
)
143 rDevice
->clear(Color(0));
145 const basegfx::B2IPoint
aPt1(1,1);
146 const basegfx::B2IPoint
aPt2(3,2);
147 const Color
aCol(0xFFFFFFFF);
148 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
149 CPPUNIT_ASSERT_MESSAGE("first pixel set",
150 rDevice
->getPixel(aPt1
) == aCol
);
151 CPPUNIT_ASSERT_MESSAGE("second pixel set",
152 rDevice
->getPixel(basegfx::B2IPoint(2,1)) == aCol
);
153 CPPUNIT_ASSERT_MESSAGE("last pixel set",
154 rDevice
->getPixel(aPt2
) == aCol
);
155 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
156 "reversed paint is not 3",
157 countPixel( rDevice
, aCol
) == 3);
159 rDevice
->drawLine( aPt2
, aPt1
, aCol
, DrawMode_PAINT
);
160 CPPUNIT_ASSERT_MESSAGE("alternate second pixel set",
161 rDevice
->getPixel(basegfx::B2IPoint(2,2)) == aCol
);
163 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
164 "reversed paint is not 4",
165 countPixel( rDevice
, aCol
) == 4);
171 const basegfx::B2ISize
aSize(11,11);
172 mpDevice1bpp
= createBitmapDevice( aSize
,
174 Format::ONE_BIT_MSB_PAL
);
175 mpDevice32bpp
= createBitmapDevice( aSize
,
177 Format::THIRTYTWO_BIT_TC_MASK
);
180 void testBasicDiagonalLines()
182 implTestBasicDiagonalLines( mpDevice1bpp
);
183 implTestBasicDiagonalLines( mpDevice32bpp
);
186 void testBasicHorizontalLines()
188 implTestBasicHorizontalLines( mpDevice1bpp
);
189 implTestBasicHorizontalLines( mpDevice32bpp
);
192 void testBasicVerticalLines()
194 implTestBasicVerticalLines( mpDevice1bpp
);
195 implTestBasicVerticalLines( mpDevice32bpp
);
198 // test pixel rounding (should always tend towards start point of
200 void testTieBreaking()
202 implTestTieBreaking( mpDevice1bpp
);
203 implTestTieBreaking( mpDevice32bpp
);
206 // Change the following lines only, if you add, remove or rename
207 // member functions of the current class,
208 // because these macros are need by auto register mechanism.
210 CPPUNIT_TEST_SUITE(LineTest
);
211 CPPUNIT_TEST(testBasicDiagonalLines
);
212 CPPUNIT_TEST(testBasicHorizontalLines
);
213 CPPUNIT_TEST(testBasicVerticalLines
);
214 CPPUNIT_TEST(testTieBreaking
);
215 CPPUNIT_TEST_SUITE_END();
218 // -----------------------------------------------------------------------------
219 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(LineTest
, "LineTest");
223 // -----------------------------------------------------------------------------
225 // this macro creates an empty function, which will called by the RegisterAllFunctions()
226 // to let the user the possibility to also register some functions by hand.