merge the formfield patch from ooo-build
[ooovba.git] / basebmp / test / basictest.cxx
blob93c9ec16726c156e68514ffe9dbe5464d0dd3fe8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basictest.cxx,v $
10 * $Revision: 1.12 $
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>
42 #include "tools.hxx"
44 #include <iostream>
45 #include <fstream>
47 using namespace ::basebmp;
49 namespace
52 std::ofstream output("32bpp_test.dump");
53 debugDump( mpDevice32bpp, output );
56 class BasicTest : public CppUnit::TestFixture
58 public:
59 void colorTest()
61 Color aTestColor;
63 aTestColor = Color(0xDEADBEEF);
64 CPPUNIT_ASSERT_MESSAGE("unary constructor",
65 aTestColor.toInt32() == 0xDEADBEEF );
67 aTestColor = Color( 0x10, 0x20, 0xFF );
68 CPPUNIT_ASSERT_MESSAGE("ternary constructor",
69 aTestColor.toInt32() == 0x001020FF );
71 aTestColor.setRed( 0x0F );
72 CPPUNIT_ASSERT_MESSAGE("setRed()",
73 aTestColor.toInt32() == 0x00F20FF );
75 aTestColor.setGreen( 0x0F );
76 CPPUNIT_ASSERT_MESSAGE("setGreen()",
77 aTestColor.toInt32() == 0x00F0FFF );
79 aTestColor.setBlue( 0x10 );
80 CPPUNIT_ASSERT_MESSAGE("setBlue()",
81 aTestColor.toInt32() == 0x00F0F10 );
83 aTestColor.setGrey( 0x13 );
84 CPPUNIT_ASSERT_MESSAGE("setGrey()",
85 aTestColor.toInt32() == 0x00131313 );
87 aTestColor = Color( 0x10, 0x20, 0xFF );
88 CPPUNIT_ASSERT_MESSAGE("getRed()",
89 aTestColor.getRed() == 0x10 );
90 CPPUNIT_ASSERT_MESSAGE("getGreen()",
91 aTestColor.getGreen() == 0x20 );
92 CPPUNIT_ASSERT_MESSAGE("getBlue()",
93 aTestColor.getBlue() == 0xFF );
97 void testConstruction()
99 const basegfx::B2ISize aSize(101,101);
100 basegfx::B2ISize aSize2(aSize);
101 BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
102 true,
103 Format::ONE_BIT_MSB_PAL ));
104 CPPUNIT_ASSERT_MESSAGE("right size",
105 pDevice->getSize() == aSize2 );
106 CPPUNIT_ASSERT_MESSAGE("Top down format",
107 pDevice->isTopDown() == true );
108 CPPUNIT_ASSERT_MESSAGE("Scanline format",
109 pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL );
110 CPPUNIT_ASSERT_MESSAGE("Scanline len",
111 pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 );
112 CPPUNIT_ASSERT_MESSAGE("Palette existence",
113 pDevice->getPalette() );
114 CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black",
115 (*pDevice->getPalette())[0] == Color(0) );
116 CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white",
117 (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) );
120 void testPixelFuncs()
122 // 1bpp
123 const basegfx::B2ISize aSize(64,64);
124 BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
125 true,
126 Format::ONE_BIT_MSB_PAL ));
128 const basegfx::B2IPoint aPt(3,3);
129 const Color aCol(0xFFFFFFFF);
130 pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
131 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
132 pDevice->getPixel(aPt) == aCol);
134 const basegfx::B2IPoint aPt2(0,0);
135 const Color aCol2(0xFFFFFFFF);
136 pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
137 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
138 pDevice->getPixel(aPt2) == aCol2);
140 const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
141 const Color aCol3(0x00000000);
142 pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
143 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
144 pDevice->getPixel(aPt3) == aCol3);
146 pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
147 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5",
148 pDevice->getPixel(aPt3) == aCol2);
150 const basegfx::B2IPoint aPt4(-100000,-100000);
151 pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
152 const basegfx::B2IPoint aPt5(100000,100000);
153 pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
155 sal_Int32 nPixel(countPixel(pDevice, aCol2));
156 const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
157 pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
158 CPPUNIT_ASSERT_MESSAGE("setPixel clipping",
159 countPixel(pDevice, aCol2) == nPixel);
161 CPPUNIT_ASSERT_MESSAGE("raw pixel value #1",
162 pDevice->getBuffer()[0] == 0x80);
164 // 1bit LSB
166 pDevice = createBitmapDevice( aSize,
167 true,
168 Format::ONE_BIT_LSB_PAL );
170 pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
171 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
172 pDevice->getPixel(aPt2) == aCol);
174 const basegfx::B2IPoint aPt222(1,1);
175 pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
176 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
177 pDevice->getPixel(aPt222) == aCol);
179 pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
180 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
181 pDevice->getPixel(aPt3) == aCol);
183 CPPUNIT_ASSERT_MESSAGE("raw pixel value #2",
184 pDevice->getBuffer()[0] == 0x01);
185 CPPUNIT_ASSERT_MESSAGE("raw pixel value #3",
186 pDevice->getBuffer()[8] == 0x02);
189 // 8bit alpha
191 pDevice = createBitmapDevice( aSize,
192 true,
193 Format::EIGHT_BIT_GREY );
195 const Color aCol4(0x010101);
196 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
197 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
198 pDevice->getPixel(aPt) == aCol4);
200 const Color aCol5(0x0F0F0F);
201 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
202 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
203 pDevice->getPixel(aPt2) == aCol5);
205 const Color aCol6(0xFFFFFF);
206 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
207 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
208 pDevice->getPixel(aPt3) == aCol6);
211 // 16bpp
213 pDevice = createBitmapDevice( aSize,
214 true,
215 Format::SIXTEEN_BIT_LSB_TC_MASK );
216 const Color aCol7(0);
217 pDevice->clear( aCol7 );
219 const Color aCol4(0x00101010);
220 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
221 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
222 pDevice->getPixel(aPt) == aCol4);
224 const Color aCol5(0x00F0F0F0);
225 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
226 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
227 pDevice->getPixel(aPt2) != aCol7);
229 const Color aCol6(0x00FFFFFF);
230 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
231 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
232 pDevice->getPixel(aPt3) == aCol6);
235 // 24bpp
237 pDevice = createBitmapDevice( aSize,
238 true,
239 Format::TWENTYFOUR_BIT_TC_MASK );
241 const Color aCol4(0x01010101);
242 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
243 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10",
244 pDevice->getPixel(aPt) == aCol4);
246 const Color aCol5(0x0F3F2F1F);
247 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
248 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11",
249 pDevice->getPixel(aPt2) == aCol5);
251 const Color aCol6(0xFFFFFFFF);
252 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
253 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12",
254 pDevice->getPixel(aPt3) == aCol6);
256 CPPUNIT_ASSERT_MESSAGE("raw pixel value #4",
257 pDevice->getBuffer()[2] == 0x3F
258 && pDevice->getBuffer()[1] == 0x2F
259 && pDevice->getBuffer()[0] == 0x1F);
262 // 32bpp
264 pDevice = createBitmapDevice( aSize,
265 true,
266 Format::THIRTYTWO_BIT_TC_MASK );
268 const Color aCol4(0x01010101);
269 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
270 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13",
271 pDevice->getPixel(aPt) == aCol4);
273 const Color aCol5(0x0F0F0F0F);
274 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
275 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14",
276 pDevice->getPixel(aPt2) == aCol5);
278 const Color aCol6(0xFFFFFFFF);
279 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
280 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15",
281 pDevice->getPixel(aPt3) == aCol6);
285 // Change the following lines only, if you add, remove or rename
286 // member functions of the current class,
287 // because these macros are need by auto register mechanism.
289 CPPUNIT_TEST_SUITE(BasicTest);
290 CPPUNIT_TEST(colorTest);
291 CPPUNIT_TEST(testConstruction);
292 CPPUNIT_TEST(testPixelFuncs);
293 CPPUNIT_TEST_SUITE_END();
296 // -----------------------------------------------------------------------------
297 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest");
301 // -----------------------------------------------------------------------------
303 // this macro creates an empty function, which will called by the RegisterAllFunctions()
304 // to let the user the possibility to also register some functions by hand.
305 NOADDITIONAL;