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 #include "sal/config.h"
30 #include "sal/precppunit.hxx"
33 #define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTest_basebmp
36 // autogenerated file with codegen.pl
38 #include "cppunit/TestAssert.h"
39 #include "cppunit/TestFixture.h"
40 #include "cppunit/extensions/HelperMacros.h"
41 #include "cppunit/plugin/TestPlugIn.h"
43 #include <basegfx/vector/b2isize.hxx>
44 #include <basegfx/point/b2ipoint.hxx>
46 #include <basebmp/color.hxx>
47 #include <basebmp/scanlineformats.hxx>
48 #include <basebmp/bitmapdevice.hxx>
51 using namespace ::basebmp
;
55 class BasicTest
: public CppUnit::TestFixture
62 aTestColor
= Color(0xDEADBEEF);
63 CPPUNIT_ASSERT_MESSAGE("unary constructor",
64 aTestColor
.toInt32() == 0xDEADBEEF );
66 aTestColor
= Color( 0x10, 0x20, 0xFF );
67 CPPUNIT_ASSERT_MESSAGE("ternary constructor",
68 aTestColor
.toInt32() == 0x001020FF );
70 aTestColor
.setRed( 0x0F );
71 CPPUNIT_ASSERT_MESSAGE("setRed()",
72 aTestColor
.toInt32() == 0x00F20FF );
74 aTestColor
.setGreen( 0x0F );
75 CPPUNIT_ASSERT_MESSAGE("setGreen()",
76 aTestColor
.toInt32() == 0x00F0FFF );
78 aTestColor
.setBlue( 0x10 );
79 CPPUNIT_ASSERT_MESSAGE("setBlue()",
80 aTestColor
.toInt32() == 0x00F0F10 );
82 aTestColor
.setGrey( 0x13 );
83 CPPUNIT_ASSERT_MESSAGE("setGrey()",
84 aTestColor
.toInt32() == 0x00131313 );
86 aTestColor
= Color( 0x10, 0x20, 0xFF );
87 CPPUNIT_ASSERT_MESSAGE("getRed()",
88 aTestColor
.getRed() == 0x10 );
89 CPPUNIT_ASSERT_MESSAGE("getGreen()",
90 aTestColor
.getGreen() == 0x20 );
91 CPPUNIT_ASSERT_MESSAGE("getBlue()",
92 aTestColor
.getBlue() == 0xFF );
96 void testConstruction()
98 const basegfx::B2ISize
aSize(101,101);
99 basegfx::B2ISize
aSize2(aSize
);
100 BitmapDeviceSharedPtr
pDevice( createBitmapDevice( aSize
,
102 Format::ONE_BIT_MSB_PAL
));
103 CPPUNIT_ASSERT_MESSAGE("right size",
104 pDevice
->getSize() == aSize2
);
105 CPPUNIT_ASSERT_MESSAGE("Top down format",
106 pDevice
->isTopDown() == true );
107 CPPUNIT_ASSERT_MESSAGE("Scanline format",
108 pDevice
->getScanlineFormat() == Format::ONE_BIT_MSB_PAL
);
109 CPPUNIT_ASSERT_MESSAGE("Scanline len",
110 pDevice
->getScanlineStride() == (aSize2
.getY() + 7)/8 );
111 CPPUNIT_ASSERT_MESSAGE("Palette existence",
112 pDevice
->getPalette() );
113 CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black",
114 (*pDevice
->getPalette())[0] == Color(0) );
115 CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white",
116 (*pDevice
->getPalette())[1] == Color(0xFFFFFFFF) );
121 const basegfx::B2ISize
aSize(101,101);
122 basegfx::B2ISize
aSize2(3,3);
123 BitmapDeviceSharedPtr
pDevice( createBitmapDevice( aSize
,
125 Format::ONE_BIT_MSB_PAL
));
127 BitmapDeviceSharedPtr
pClone( cloneBitmapDevice(
130 CPPUNIT_ASSERT_MESSAGE("right size",
131 pClone
->getSize() == aSize2
);
134 void testPixelFuncs()
137 const basegfx::B2ISize
aSize(64,64);
138 BitmapDeviceSharedPtr
pDevice( createBitmapDevice( aSize
,
140 Format::ONE_BIT_MSB_PAL
));
142 const basegfx::B2IPoint
aPt(3,3);
143 CPPUNIT_ASSERT_MESSAGE("getPixelData for virgin device",
144 pDevice
->getPixelData(aPt
) == 0);
146 const Color
aCol(0xFFFFFFFF);
147 pDevice
->setPixel( aPt
, aCol
, DrawMode_PAINT
);
148 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
149 pDevice
->getPixel(aPt
) == aCol
);
150 CPPUNIT_ASSERT_MESSAGE("getPixelData for white pixel",
151 pDevice
->getPixelData(aPt
) == 1);
153 const basegfx::B2IPoint
aPt2(0,0);
154 const Color
aCol2(0xFFFFFFFF);
155 pDevice
->setPixel( aPt2
, aCol2
, DrawMode_PAINT
);
156 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
157 pDevice
->getPixel(aPt2
) == aCol2
);
159 const basegfx::B2IPoint
aPt3(aSize
.getX()-1,aSize
.getY()-1);
160 const Color
aCol3(0x00000000);
161 pDevice
->setPixel( aPt3
, aCol3
, DrawMode_PAINT
);
162 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
163 pDevice
->getPixel(aPt3
) == aCol3
);
165 pDevice
->setPixel( aPt3
, aCol2
, DrawMode_PAINT
);
166 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5",
167 pDevice
->getPixel(aPt3
) == aCol2
);
169 const basegfx::B2IPoint
aPt4(-100000,-100000);
170 pDevice
->setPixel( aPt4
, aCol3
, DrawMode_PAINT
);
171 const basegfx::B2IPoint
aPt5(100000,100000);
172 pDevice
->setPixel( aPt5
, aCol3
, DrawMode_PAINT
);
174 sal_Int32
nPixel(countPixel(pDevice
, aCol2
));
175 const basegfx::B2IPoint
aPt6(aSize
.getX(),aSize
.getY());
176 pDevice
->setPixel( aPt6
, aCol2
, DrawMode_PAINT
);
177 CPPUNIT_ASSERT_MESSAGE("setPixel clipping",
178 countPixel(pDevice
, aCol2
) == nPixel
);
180 CPPUNIT_ASSERT_MESSAGE("raw pixel value #1",
181 pDevice
->getBuffer()[0] == 0x80);
185 pDevice
= createBitmapDevice( aSize
,
187 Format::ONE_BIT_LSB_PAL
);
189 pDevice
->setPixel( aPt2
, aCol
, DrawMode_PAINT
);
190 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
191 pDevice
->getPixel(aPt2
) == aCol
);
193 const basegfx::B2IPoint
aPt222(1,1);
194 pDevice
->setPixel( aPt222
, aCol
, DrawMode_PAINT
);
195 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
196 pDevice
->getPixel(aPt222
) == aCol
);
198 pDevice
->setPixel( aPt3
, aCol
, DrawMode_PAINT
);
199 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
200 pDevice
->getPixel(aPt3
) == aCol
);
202 CPPUNIT_ASSERT_MESSAGE("raw pixel value #2",
203 pDevice
->getBuffer()[0] == 0x01);
204 CPPUNIT_ASSERT_MESSAGE("raw pixel value #3",
205 pDevice
->getBuffer()[8] == 0x02);
210 pDevice
= createBitmapDevice( aSize
,
212 Format::EIGHT_BIT_GREY
);
214 const Color
aCol4(0x010101);
215 pDevice
->setPixel( aPt
, aCol4
, DrawMode_PAINT
);
216 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
217 pDevice
->getPixel(aPt
) == aCol4
);
219 const Color
aCol5(0x0F0F0F);
220 pDevice
->setPixel( aPt2
, aCol5
, DrawMode_PAINT
);
221 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
222 pDevice
->getPixel(aPt2
) == aCol5
);
224 const Color
aCol6(0xFFFFFF);
225 pDevice
->setPixel( aPt3
, aCol6
, DrawMode_PAINT
);
226 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
227 pDevice
->getPixel(aPt3
) == aCol6
);
232 pDevice
= createBitmapDevice( aSize
,
234 Format::SIXTEEN_BIT_LSB_TC_MASK
);
235 const Color
aCol7(0);
236 pDevice
->clear( aCol7
);
238 const Color
aCol4(0x00101010);
239 pDevice
->setPixel( aPt
, aCol4
, DrawMode_PAINT
);
240 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
241 pDevice
->getPixel(aPt
) == aCol4
);
243 const Color
aCol5(0x00F0F0F0);
244 pDevice
->setPixel( aPt2
, aCol5
, DrawMode_PAINT
);
245 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
246 pDevice
->getPixel(aPt2
) != aCol7
);
248 const Color
aCol6(0x00FFFFFF);
249 pDevice
->setPixel( aPt3
, aCol6
, DrawMode_PAINT
);
250 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
251 pDevice
->getPixel(aPt3
) == aCol6
);
256 pDevice
= createBitmapDevice( aSize
,
258 Format::TWENTYFOUR_BIT_TC_MASK
);
260 const Color
aCol4(0x01010101);
261 pDevice
->setPixel( aPt
, aCol4
, DrawMode_PAINT
);
262 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10",
263 pDevice
->getPixel(aPt
) == aCol4
);
265 const Color
aCol5(0x0F3F2F1F);
266 pDevice
->setPixel( aPt2
, aCol5
, DrawMode_PAINT
);
267 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11",
268 pDevice
->getPixel(aPt2
) == aCol5
);
270 const Color
aCol6(0xFFFFFFFF);
271 pDevice
->setPixel( aPt3
, aCol6
, DrawMode_PAINT
);
272 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12",
273 pDevice
->getPixel(aPt3
) == aCol6
);
275 CPPUNIT_ASSERT_MESSAGE("raw pixel value #4",
276 pDevice
->getBuffer()[2] == 0x3F
277 && pDevice
->getBuffer()[1] == 0x2F
278 && pDevice
->getBuffer()[0] == 0x1F);
283 pDevice
= createBitmapDevice( aSize
,
285 Format::THIRTYTWO_BIT_TC_MASK
);
287 const Color
aCol4(0x01010101);
288 pDevice
->setPixel( aPt
, aCol4
, DrawMode_PAINT
);
289 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13",
290 pDevice
->getPixel(aPt
) == aCol4
);
292 const Color
aCol5(0x0F0F0F0F);
293 pDevice
->setPixel( aPt2
, aCol5
, DrawMode_PAINT
);
294 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14",
295 pDevice
->getPixel(aPt2
) == aCol5
);
297 const Color
aCol6(0xFFFFFFFF);
298 pDevice
->setPixel( aPt3
, aCol6
, DrawMode_PAINT
);
299 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15",
300 pDevice
->getPixel(aPt3
) == aCol6
);
304 // Change the following lines only, if you add, remove or rename
305 // member functions of the current class,
306 // because these macros are need by auto register mechanism.
308 CPPUNIT_TEST_SUITE(BasicTest
);
309 CPPUNIT_TEST(colorTest
);
310 CPPUNIT_TEST(testConstruction
);
311 CPPUNIT_TEST(testClone
);
312 CPPUNIT_TEST(testPixelFuncs
);
313 CPPUNIT_TEST_SUITE_END();
316 CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest
);
319 CPPUNIT_PLUGIN_IMPLEMENT();
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */