1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // autogenerated file with codegen.pl
30 #include "cppunit/TestAssert.h"
31 #include "cppunit/TestFixture.h"
32 #include "cppunit/extensions/HelperMacros.h"
34 #include <basegfx/vector/b2isize.hxx>
35 #include <basegfx/point/b2ipoint.hxx>
37 #include <basebmp/color.hxx>
38 #include <basebmp/scanlineformats.hxx>
39 #include <basebmp/bitmapdevice.hxx>
40 #include <basebmp/debug.hxx>
46 using namespace ::basebmp
;
51 std::ofstream output("32bpp_test.dump");
52 debugDump( mpDevice32bpp, output );
55 class LineTest
: public CppUnit::TestFixture
58 BitmapDeviceSharedPtr mpDevice1bpp
;
59 BitmapDeviceSharedPtr mpDevice32bpp
;
61 void implTestBasicDiagonalLines(const BitmapDeviceSharedPtr
& rDevice
)
63 rDevice
->clear(Color(0));
65 const basegfx::B2IPoint
aPt1(1,1);
66 const basegfx::B2IPoint
aPt2(9,9);
67 const Color
aCol(0xFFFFFFFF);
68 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
69 CPPUNIT_ASSERT_MESSAGE("first pixel set",
70 rDevice
->getPixel(aPt1
) == aCol
);
71 CPPUNIT_ASSERT_MESSAGE("last pixel set",
72 rDevice
->getPixel(aPt2
) == aCol
);
73 const basegfx::B2IPoint
aPt3(0,0);
74 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
75 rDevice
->getPixel(aPt3
) != aCol
);
76 const basegfx::B2IPoint
aPt4(10,10);
77 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
78 rDevice
->getPixel(aPt4
) != aCol
);
80 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
81 countPixel( rDevice
, aCol
) == 9);
83 rDevice
->drawLine( aPt2
, aPt1
, aCol
, DrawMode_PAINT
);
85 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
86 "reversed paint is not 9",
87 countPixel( rDevice
, aCol
) == 9);
90 void implTestBasicHorizontalLines(const BitmapDeviceSharedPtr
& rDevice
)
92 rDevice
->clear(Color(0));
94 const basegfx::B2IPoint
aPt1(10,10);
95 const basegfx::B2IPoint
aPt2(0,10);
96 const Color
aCol(0xFFFFFFFF);
97 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
98 CPPUNIT_ASSERT_MESSAGE("first pixel set",
99 rDevice
->getPixel(aPt1
) == aCol
);
100 CPPUNIT_ASSERT_MESSAGE("last pixel set",
101 rDevice
->getPixel(aPt2
) == aCol
);
102 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
103 countPixel( rDevice
, aCol
) == 11);
105 rDevice
->clear(Color(0));
106 rDevice
->drawLine( aPt2
, aPt1
, aCol
, DrawMode_PAINT
);
107 CPPUNIT_ASSERT_MESSAGE("first pixel set",
108 rDevice
->getPixel(aPt1
) == aCol
);
109 CPPUNIT_ASSERT_MESSAGE("last pixel set",
110 rDevice
->getPixel(aPt2
) == aCol
);
111 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 11",
112 countPixel( rDevice
, aCol
) == 11);
115 void implTestBasicVerticalLines(const BitmapDeviceSharedPtr
& rDevice
)
117 rDevice
->clear(Color(0));
119 const basegfx::B2IPoint
aPt1(1,1);
120 const basegfx::B2IPoint
aPt2(1,9);
121 const Color
aCol(0xFFFFFFFF);
122 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
123 CPPUNIT_ASSERT_MESSAGE("first pixel set",
124 rDevice
->getPixel(aPt1
) == aCol
);
125 CPPUNIT_ASSERT_MESSAGE("last pixel set",
126 rDevice
->getPixel(aPt2
) == aCol
);
127 const basegfx::B2IPoint
aPt3(0,0);
128 CPPUNIT_ASSERT_MESSAGE("topmost pixel not set",
129 rDevice
->getPixel(aPt3
) != aCol
);
130 const basegfx::B2IPoint
aPt4(0,10);
131 CPPUNIT_ASSERT_MESSAGE("bottommost pixel not set",
132 rDevice
->getPixel(aPt4
) != aCol
);
134 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 9",
135 countPixel( rDevice
, aCol
) == 9);
138 // test pixel rounding (should always tend towards start point of
140 void implTestTieBreaking(const BitmapDeviceSharedPtr
& rDevice
)
142 rDevice
->clear(Color(0));
144 const basegfx::B2IPoint
aPt1(1,1);
145 const basegfx::B2IPoint
aPt2(3,2);
146 const Color
aCol(0xFFFFFFFF);
147 rDevice
->drawLine( aPt1
, aPt2
, aCol
, DrawMode_PAINT
);
148 CPPUNIT_ASSERT_MESSAGE("first pixel set",
149 rDevice
->getPixel(aPt1
) == aCol
);
150 CPPUNIT_ASSERT_MESSAGE("second pixel set",
151 rDevice
->getPixel(basegfx::B2IPoint(2,1)) == aCol
);
152 CPPUNIT_ASSERT_MESSAGE("last pixel set",
153 rDevice
->getPixel(aPt2
) == aCol
);
154 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
155 "reversed paint is not 3",
156 countPixel( rDevice
, aCol
) == 3);
158 rDevice
->drawLine( aPt2
, aPt1
, aCol
, DrawMode_PAINT
);
159 CPPUNIT_ASSERT_MESSAGE("alternate second pixel set",
160 rDevice
->getPixel(basegfx::B2IPoint(2,2)) == aCol
);
162 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel after "
163 "reversed paint is not 4",
164 countPixel( rDevice
, aCol
) == 4);
170 const basegfx::B2ISize
aSize(11,11);
171 mpDevice1bpp
= createBitmapDevice( aSize
,
173 Format::ONE_BIT_MSB_PAL
);
174 mpDevice32bpp
= createBitmapDevice( aSize
,
176 Format::THIRTYTWO_BIT_TC_MASK
);
179 void testBasicDiagonalLines()
181 implTestBasicDiagonalLines( mpDevice1bpp
);
182 implTestBasicDiagonalLines( mpDevice32bpp
);
185 void testBasicHorizontalLines()
187 implTestBasicHorizontalLines( mpDevice1bpp
);
188 implTestBasicHorizontalLines( mpDevice32bpp
);
191 void testBasicVerticalLines()
193 implTestBasicVerticalLines( mpDevice1bpp
);
194 implTestBasicVerticalLines( mpDevice32bpp
);
197 // test pixel rounding (should always tend towards start point of
199 void testTieBreaking()
201 implTestTieBreaking( mpDevice1bpp
);
202 implTestTieBreaking( mpDevice32bpp
);
205 // Change the following lines only, if you add, remove or rename
206 // member functions of the current class,
207 // because these macros are need by auto register mechanism.
209 CPPUNIT_TEST_SUITE(LineTest
);
210 CPPUNIT_TEST(testBasicDiagonalLines
);
211 CPPUNIT_TEST(testBasicHorizontalLines
);
212 CPPUNIT_TEST(testBasicVerticalLines
);
213 CPPUNIT_TEST(testTieBreaking
);
214 CPPUNIT_TEST_SUITE_END();
217 // -----------------------------------------------------------------------------
218 CPPUNIT_TEST_SUITE_REGISTRATION(LineTest
);
222 // -----------------------------------------------------------------------------
224 // this macro creates an empty function, which will called by the RegisterAllFunctions()
225 // to let the user the possibility to also register some functions by hand.