fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / basebmp / test / basictest.cxx
blob293fbe5d1c1770a235282ebb90a7e26023036b1f
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 basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_MSB_PAL, aSize.getX())));
88 CPPUNIT_ASSERT_MESSAGE("right size",
89 pDevice->getSize() == aSize2 );
90 CPPUNIT_ASSERT_MESSAGE("Top down format",
91 pDevice->isTopDown() );
92 CPPUNIT_ASSERT_MESSAGE("Scanline format",
93 pDevice->getScanlineFormat() == FORMAT_ONE_BIT_MSB_PAL );
94 CPPUNIT_ASSERT_MESSAGE("Scanline len",
95 pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 );
96 CPPUNIT_ASSERT_MESSAGE("Palette existence",
97 pDevice->getPalette() );
98 CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black",
99 (*pDevice->getPalette())[0] == Color(0) );
100 CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white",
101 (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) );
104 void testClone()
106 const basegfx::B2ISize aSize(101,101);
107 basegfx::B2ISize aSize2(3,3);
108 BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
109 true,
110 FORMAT_ONE_BIT_MSB_PAL,
111 basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_MSB_PAL, aSize.getX())));
113 BitmapDeviceSharedPtr pClone( cloneBitmapDevice(
114 aSize2,
115 pDevice ));
116 CPPUNIT_ASSERT_MESSAGE("right size",
117 pClone->getSize() == aSize2 );
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,
127 basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_MSB_PAL, aSize.getX())));
129 const basegfx::B2IPoint aPt(3,3);
130 CPPUNIT_ASSERT_MESSAGE("getPixelData for virgin device",
131 pDevice->getPixelData(aPt) == 0);
133 const Color aCol(0xFFFFFFFF);
134 pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
135 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
136 pDevice->getPixel(aPt) == aCol);
137 CPPUNIT_ASSERT_MESSAGE("getPixelData for white pixel",
138 pDevice->getPixelData(aPt) == 1);
140 const basegfx::B2IPoint aPt2(0,0);
141 const Color aCol2(0xFFFFFFFF);
142 pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
143 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
144 pDevice->getPixel(aPt2) == aCol2);
146 const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
147 const Color aCol3(0x00000000);
148 pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
149 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
150 pDevice->getPixel(aPt3) == aCol3);
152 pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
153 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5",
154 pDevice->getPixel(aPt3) == aCol2);
156 const basegfx::B2IPoint aPt4(-100000,-100000);
157 pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
158 const basegfx::B2IPoint aPt5(100000,100000);
159 pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
161 sal_Int32 nPixel(countPixel(pDevice, aCol2));
162 const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
163 pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
164 CPPUNIT_ASSERT_MESSAGE("setPixel clipping",
165 countPixel(pDevice, aCol2) == nPixel);
167 CPPUNIT_ASSERT_MESSAGE("raw pixel value #1",
168 pDevice->getBuffer()[0] == 0x80);
170 // 1bit LSB
172 pDevice = createBitmapDevice( aSize,
173 true,
174 FORMAT_ONE_BIT_LSB_PAL,
175 basebmp::getBitmapDeviceStrideForWidth(FORMAT_ONE_BIT_LSB_PAL, aSize.getX()));
177 pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
178 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
179 pDevice->getPixel(aPt2) == aCol);
181 const basegfx::B2IPoint aPt222(1,1);
182 pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
183 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
184 pDevice->getPixel(aPt222) == aCol);
186 pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
187 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
188 pDevice->getPixel(aPt3) == aCol);
190 CPPUNIT_ASSERT_MESSAGE("raw pixel value #2",
191 pDevice->getBuffer()[0] == 0x01);
192 CPPUNIT_ASSERT_MESSAGE("raw pixel value #3",
193 pDevice->getBuffer()[8] == 0x02);
196 // 8bit alpha
198 pDevice = createBitmapDevice( aSize,
199 true,
200 FORMAT_EIGHT_BIT_GREY,
201 basebmp::getBitmapDeviceStrideForWidth(FORMAT_EIGHT_BIT_GREY, aSize.getX()));
203 const Color aCol4(0x010101);
204 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
205 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
206 pDevice->getPixel(aPt) == aCol4);
208 const Color aCol5(0x0F0F0F);
209 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
210 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
211 pDevice->getPixel(aPt2) == aCol5);
213 const Color aCol6(0xFFFFFF);
214 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
215 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
216 pDevice->getPixel(aPt3) == aCol6);
219 // 16bpp
221 pDevice = createBitmapDevice( aSize,
222 true,
223 FORMAT_SIXTEEN_BIT_LSB_TC_MASK,
224 basebmp::getBitmapDeviceStrideForWidth(FORMAT_SIXTEEN_BIT_LSB_TC_MASK, aSize.getX()));
225 const Color aCol7(0);
226 pDevice->clear( aCol7 );
228 const Color aCol4(0x00101010);
229 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
230 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
231 pDevice->getPixel(aPt) == aCol4);
233 const Color aCol5(0x00F0F0F0);
234 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
235 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
236 pDevice->getPixel(aPt2) != aCol7);
238 const Color aCol6(0x00FFFFFF);
239 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
240 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
241 pDevice->getPixel(aPt3) == aCol6);
244 // 24bpp
246 pDevice = createBitmapDevice( aSize,
247 true,
248 FORMAT_TWENTYFOUR_BIT_TC_MASK,
249 basebmp::getBitmapDeviceStrideForWidth(FORMAT_TWENTYFOUR_BIT_TC_MASK, aSize.getX()));
251 const Color aCol4(0x01010101);
252 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
253 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10",
254 pDevice->getPixel(aPt) == aCol4);
256 const Color aCol5(0x0F3F2F1F);
257 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
258 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11",
259 pDevice->getPixel(aPt2) == aCol5);
261 const Color aCol6(0xFFFFFFFF);
262 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
263 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12",
264 pDevice->getPixel(aPt3) == aCol6);
266 CPPUNIT_ASSERT_MESSAGE("raw pixel value #4",
267 pDevice->getBuffer()[2] == 0x3F
268 && pDevice->getBuffer()[1] == 0x2F
269 && pDevice->getBuffer()[0] == 0x1F);
272 // 32bpp
274 pDevice = createBitmapDevice( aSize,
275 true,
276 FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA,
277 basebmp::getBitmapDeviceStrideForWidth(FORMAT_THIRTYTWO_BIT_TC_MASK_BGRA, aSize.getX()));
279 const Color aCol4(0x01010101);
280 pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
281 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13",
282 pDevice->getPixel(aPt) == aCol4);
284 const Color aCol5(0x0F0F0F0F);
285 pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
286 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14",
287 pDevice->getPixel(aPt2) == aCol5);
289 const Color aCol6(0xFFFFFFFF);
290 pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
291 CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15",
292 pDevice->getPixel(aPt3) == aCol6);
296 // Change the following lines only, if you add, remove or rename
297 // member functions of the current class,
298 // because these macros are need by auto register mechanism.
300 CPPUNIT_TEST_SUITE(BasicTest);
301 CPPUNIT_TEST(colorTest);
302 CPPUNIT_TEST(testConstruction);
303 CPPUNIT_TEST(testClone);
304 CPPUNIT_TEST(testPixelFuncs);
305 CPPUNIT_TEST_SUITE_END();
308 CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest);
311 CPPUNIT_PLUGIN_IMPLEMENT();
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */