bump product version to 4.2.0.1
[LibreOffice.git] / basebmp / test / basictest.cxx
blob4290ed7a865a80c2bbeee444574a6a9f8348b909
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 // autogenerated file with codegen.pl
22 #include <cppunit/TestAssert.h>
23 #include <cppunit/TestFixture.h>
24 #include <cppunit/extensions/HelperMacros.h>
25 #include <cppunit/plugin/TestPlugIn.h>
27 #include <basegfx/vector/b2isize.hxx>
28 #include <basegfx/point/b2ipoint.hxx>
30 #include <basebmp/color.hxx>
31 #include <basebmp/scanlineformats.hxx>
32 #include <basebmp/bitmapdevice.hxx>
33 #include "tools.hxx"
35 using namespace ::basebmp;
37 namespace
39 class BasicTest : public CppUnit::TestFixture
41 public:
42 void colorTest()
44 Color aTestColor;
46 aTestColor = Color(0xDEADBEEF);
47 CPPUNIT_ASSERT_MESSAGE("unary constructor",
48 aTestColor.toInt32() == 0xDEADBEEF );
50 aTestColor = Color( 0x10, 0x20, 0xFF );
51 CPPUNIT_ASSERT_MESSAGE("ternary constructor",
52 aTestColor.toInt32() == 0x001020FF );
54 aTestColor.setRed( 0x0F );
55 CPPUNIT_ASSERT_MESSAGE("setRed()",
56 aTestColor.toInt32() == 0x00F20FF );
58 aTestColor.setGreen( 0x0F );
59 CPPUNIT_ASSERT_MESSAGE("setGreen()",
60 aTestColor.toInt32() == 0x00F0FFF );
62 aTestColor.setBlue( 0x10 );
63 CPPUNIT_ASSERT_MESSAGE("setBlue()",
64 aTestColor.toInt32() == 0x00F0F10 );
66 aTestColor.setGrey( 0x13 );
67 CPPUNIT_ASSERT_MESSAGE("setGrey()",
68 aTestColor.toInt32() == 0x00131313 );
70 aTestColor = Color( 0x10, 0x20, 0xFF );
71 CPPUNIT_ASSERT_MESSAGE("getRed()",
72 aTestColor.getRed() == 0x10 );
73 CPPUNIT_ASSERT_MESSAGE("getGreen()",
74 aTestColor.getGreen() == 0x20 );
75 CPPUNIT_ASSERT_MESSAGE("getBlue()",
76 aTestColor.getBlue() == 0xFF );
80 void testConstruction()
82 const basegfx::B2ISize aSize(101,101);
83 basegfx::B2ISize aSize2(aSize);
84 BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
85 true,
86 FORMAT_ONE_BIT_MSB_PAL ));
87 CPPUNIT_ASSERT_MESSAGE("right size",
88 pDevice->getSize() == aSize2 );
89 CPPUNIT_ASSERT_MESSAGE("Top down format",
90 pDevice->isTopDown() == true );
91 CPPUNIT_ASSERT_MESSAGE("Scanline format",
92 pDevice->getScanlineFormat() == FORMAT_ONE_BIT_MSB_PAL );
93 CPPUNIT_ASSERT_MESSAGE("Scanline len",
94 pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 );
95 CPPUNIT_ASSERT_MESSAGE("Palette existence",
96 pDevice->getPalette() );
97 CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black",
98 (*pDevice->getPalette())[0] == Color(0) );
99 CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white",
100 (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) );
103 void testClone()
105 const basegfx::B2ISize aSize(101,101);
106 basegfx::B2ISize aSize2(3,3);
107 BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
108 true,
109 FORMAT_ONE_BIT_MSB_PAL ));
111 BitmapDeviceSharedPtr pClone( cloneBitmapDevice(
112 aSize2,
113 pDevice ));
114 CPPUNIT_ASSERT_MESSAGE("right size",
115 pClone->getSize() == aSize2 );
118 void testPixelFuncs()
120 // 1bpp
121 const basegfx::B2ISize aSize(64,64);
122 BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
123 true,
124 FORMAT_ONE_BIT_MSB_PAL ));
126 const basegfx::B2IPoint aPt(3,3);
127 CPPUNIT_ASSERT_MESSAGE("getPixelData for virgin device",
128 pDevice->getPixelData(aPt) == 0);
130 const Color aCol(0xFFFFFFFF);
131 pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
132 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
133 pDevice->getPixel(aPt) == aCol);
134 CPPUNIT_ASSERT_MESSAGE("getPixelData for white pixel",
135 pDevice->getPixelData(aPt) == 1);
137 const basegfx::B2IPoint aPt2(0,0);
138 const Color aCol2(0xFFFFFFFF);
139 pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
140 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
141 pDevice->getPixel(aPt2) == aCol2);
143 const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
144 const Color aCol3(0x00000000);
145 pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
146 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
147 pDevice->getPixel(aPt3) == aCol3);
149 pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
150 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5",
151 pDevice->getPixel(aPt3) == aCol2);
153 const basegfx::B2IPoint aPt4(-100000,-100000);
154 pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
155 const basegfx::B2IPoint aPt5(100000,100000);
156 pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
158 sal_Int32 nPixel(countPixel(pDevice, aCol2));
159 const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
160 pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
161 CPPUNIT_ASSERT_MESSAGE("setPixel clipping",
162 countPixel(pDevice, aCol2) == nPixel);
164 CPPUNIT_ASSERT_MESSAGE("raw pixel value #1",
165 pDevice->getBuffer()[0] == 0x80);
167 // 1bit LSB
169 pDevice = createBitmapDevice( aSize,
170 true,
171 FORMAT_ONE_BIT_LSB_PAL );
173 pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
174 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
175 pDevice->getPixel(aPt2) == aCol);
177 const basegfx::B2IPoint aPt222(1,1);
178 pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
179 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
180 pDevice->getPixel(aPt222) == aCol);
182 pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
183 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
184 pDevice->getPixel(aPt3) == aCol);
186 CPPUNIT_ASSERT_MESSAGE("raw pixel value #2",
187 pDevice->getBuffer()[0] == 0x01);
188 CPPUNIT_ASSERT_MESSAGE("raw pixel value #3",
189 pDevice->getBuffer()[8] == 0x02);
192 // 8bit alpha
194 pDevice = createBitmapDevice( aSize,
195 true,
196 FORMAT_EIGHT_BIT_GREY );
198 const Color aCol4(0x010101);
199 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
200 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
201 pDevice->getPixel(aPt) == aCol4);
203 const Color aCol5(0x0F0F0F);
204 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
205 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
206 pDevice->getPixel(aPt2) == aCol5);
208 const Color aCol6(0xFFFFFF);
209 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
210 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
211 pDevice->getPixel(aPt3) == aCol6);
214 // 16bpp
216 pDevice = createBitmapDevice( aSize,
217 true,
218 FORMAT_SIXTEEN_BIT_LSB_TC_MASK );
219 const Color aCol7(0);
220 pDevice->clear( aCol7 );
222 const Color aCol4(0x00101010);
223 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
224 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
225 pDevice->getPixel(aPt) == aCol4);
227 const Color aCol5(0x00F0F0F0);
228 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
229 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
230 pDevice->getPixel(aPt2) != aCol7);
232 const Color aCol6(0x00FFFFFF);
233 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
234 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
235 pDevice->getPixel(aPt3) == aCol6);
238 // 24bpp
240 pDevice = createBitmapDevice( aSize,
241 true,
242 FORMAT_TWENTYFOUR_BIT_TC_MASK );
244 const Color aCol4(0x01010101);
245 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
246 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10",
247 pDevice->getPixel(aPt) == aCol4);
249 const Color aCol5(0x0F3F2F1F);
250 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
251 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11",
252 pDevice->getPixel(aPt2) == aCol5);
254 const Color aCol6(0xFFFFFFFF);
255 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
256 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12",
257 pDevice->getPixel(aPt3) == aCol6);
259 CPPUNIT_ASSERT_MESSAGE("raw pixel value #4",
260 pDevice->getBuffer()[2] == 0x3F
261 && pDevice->getBuffer()[1] == 0x2F
262 && pDevice->getBuffer()[0] == 0x1F);
265 // 32bpp
267 pDevice = createBitmapDevice( aSize,
268 true,
269 FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA );
271 const Color aCol4(0x01010101);
272 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
273 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13",
274 pDevice->getPixel(aPt) == aCol4);
276 const Color aCol5(0x0F0F0F0F);
277 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
278 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14",
279 pDevice->getPixel(aPt2) == aCol5);
281 const Color aCol6(0xFFFFFFFF);
282 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
283 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15",
284 pDevice->getPixel(aPt3) == aCol6);
288 // Change the following lines only, if you add, remove or rename
289 // member functions of the current class,
290 // because these macros are need by auto register mechanism.
292 CPPUNIT_TEST_SUITE(BasicTest);
293 CPPUNIT_TEST(colorTest);
294 CPPUNIT_TEST(testConstruction);
295 CPPUNIT_TEST(testClone);
296 CPPUNIT_TEST(testPixelFuncs);
297 CPPUNIT_TEST_SUITE_END();
300 CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest);
303 CPPUNIT_PLUGIN_IMPLEMENT();
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */