Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : // autogenerated file with codegen.pl
21 : :
22 : : #include "cppunit/TestAssert.h"
23 : : #include "cppunit/TestFixture.h"
24 : : #include "cppunit/extensions/HelperMacros.h"
25 : : #include "cppunit/plugin/TestPlugIn.h"
26 : :
27 : : #include <basegfx/vector/b2isize.hxx>
28 : : #include <basegfx/point/b2ipoint.hxx>
29 : :
30 : : #include <basebmp/color.hxx>
31 : : #include <basebmp/scanlineformats.hxx>
32 : : #include <basebmp/bitmapdevice.hxx>
33 : : #include "tools.hxx"
34 : :
35 : : using namespace ::basebmp;
36 : :
37 : : namespace
38 : : {
39 [ - + ]: 60 : class BasicTest : public CppUnit::TestFixture
40 : : {
41 : : public:
42 : 5 : void colorTest()
43 : : {
44 : 5 : Color aTestColor;
45 : :
46 : 5 : aTestColor = Color(0xDEADBEEF);
47 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("unary constructor",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
48 [ + - ]: 5 : aTestColor.toInt32() == 0xDEADBEEF );
49 : :
50 : 5 : aTestColor = Color( 0x10, 0x20, 0xFF );
51 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("ternary constructor",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
52 [ + - ]: 5 : aTestColor.toInt32() == 0x001020FF );
53 : :
54 : 5 : aTestColor.setRed( 0x0F );
55 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("setRed()",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
56 [ + - ]: 5 : aTestColor.toInt32() == 0x00F20FF );
57 : :
58 : 5 : aTestColor.setGreen( 0x0F );
59 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("setGreen()",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
60 [ + - ]: 5 : aTestColor.toInt32() == 0x00F0FFF );
61 : :
62 : 5 : aTestColor.setBlue( 0x10 );
63 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("setBlue()",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
64 [ + - ]: 5 : aTestColor.toInt32() == 0x00F0F10 );
65 : :
66 : 5 : aTestColor.setGrey( 0x13 );
67 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("setGrey()",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
68 [ + - ]: 5 : aTestColor.toInt32() == 0x00131313 );
69 : :
70 : 5 : aTestColor = Color( 0x10, 0x20, 0xFF );
71 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("getRed()",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
72 [ + - ]: 5 : aTestColor.getRed() == 0x10 );
73 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("getGreen()",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
74 [ + - ]: 5 : aTestColor.getGreen() == 0x20 );
75 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("getBlue()",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
76 [ + - ]: 5 : aTestColor.getBlue() == 0xFF );
77 : :
78 : 5 : }
79 : :
80 : 5 : void testConstruction()
81 : : {
82 : 5 : const basegfx::B2ISize aSize(101,101);
83 : 5 : basegfx::B2ISize aSize2(aSize);
84 : : BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
85 : : true,
86 [ + - ]: 5 : Format::ONE_BIT_MSB_PAL ));
87 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("right size",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
88 [ + - ]: 5 : pDevice->getSize() == aSize2 );
89 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("Top down format",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
90 [ + - ]: 5 : pDevice->isTopDown() == true );
91 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("Scanline format",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
92 [ + - ]: 5 : pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL );
93 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("Scanline len",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
94 [ + - ]: 5 : pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 );
95 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("Palette existence",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
96 [ + - ]: 5 : pDevice->getPalette() );
97 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
98 [ + - ]: 5 : (*pDevice->getPalette())[0] == Color(0) );
99 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
100 [ + - + - ]: 10 : (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) );
101 : 5 : }
102 : :
103 : 5 : void testClone()
104 : : {
105 : 5 : const basegfx::B2ISize aSize(101,101);
106 : 5 : basegfx::B2ISize aSize2(3,3);
107 : : BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
108 : : true,
109 [ + - ]: 5 : Format::ONE_BIT_MSB_PAL ));
110 : :
111 : : BitmapDeviceSharedPtr pClone( cloneBitmapDevice(
112 : : aSize2,
113 [ + - ]: 5 : pDevice ));
114 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("right size",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
115 [ + - ]: 10 : pClone->getSize() == aSize2 );
[ + - + - ]
116 : 5 : }
117 : :
118 : 5 : void testPixelFuncs()
119 : : {
120 : : // 1bpp
121 : 5 : const basegfx::B2ISize aSize(64,64);
122 : : BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
123 : : true,
124 [ + - ]: 5 : Format::ONE_BIT_MSB_PAL ));
125 : :
126 : 5 : const basegfx::B2IPoint aPt(3,3);
127 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("getPixelData for virgin device",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
128 [ + - ]: 5 : pDevice->getPixelData(aPt) == 0);
129 : :
130 : 5 : const Color aCol(0xFFFFFFFF);
131 [ + - ]: 5 : pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
132 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
133 [ + - ]: 5 : pDevice->getPixel(aPt) == aCol);
134 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("getPixelData for white pixel",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
135 [ + - ]: 5 : pDevice->getPixelData(aPt) == 1);
136 : :
137 : 5 : const basegfx::B2IPoint aPt2(0,0);
138 : 5 : const Color aCol2(0xFFFFFFFF);
139 [ + - ]: 5 : pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
140 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
141 [ + - ]: 5 : pDevice->getPixel(aPt2) == aCol2);
142 : :
143 : 5 : const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
144 : 5 : const Color aCol3(0x00000000);
145 [ + - ]: 5 : pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
146 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
147 [ + - ]: 5 : pDevice->getPixel(aPt3) == aCol3);
148 : :
149 [ + - ]: 5 : pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
150 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
151 [ + - ]: 5 : pDevice->getPixel(aPt3) == aCol2);
152 : :
153 : 5 : const basegfx::B2IPoint aPt4(-100000,-100000);
154 [ + - ]: 5 : pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
155 : 5 : const basegfx::B2IPoint aPt5(100000,100000);
156 [ + - ]: 5 : pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
157 : :
158 [ + - ]: 5 : sal_Int32 nPixel(countPixel(pDevice, aCol2));
159 : 5 : const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
160 [ + - ]: 5 : pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
161 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("setPixel clipping",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
162 [ + - ]: 5 : countPixel(pDevice, aCol2) == nPixel);
163 : :
164 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("raw pixel value #1",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
165 [ + - ]: 5 : pDevice->getBuffer()[0] == 0x80);
166 : :
167 : : // 1bit LSB
168 : : {
169 : : pDevice = createBitmapDevice( aSize,
170 : : true,
171 [ + - ][ + - ]: 5 : Format::ONE_BIT_LSB_PAL );
[ + - ]
172 : :
173 [ + - ]: 5 : pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
174 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
175 [ + - ]: 5 : pDevice->getPixel(aPt2) == aCol);
176 : :
177 : 5 : const basegfx::B2IPoint aPt222(1,1);
178 [ + - ]: 5 : pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
179 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
180 [ + - ]: 5 : pDevice->getPixel(aPt222) == aCol);
181 : :
182 [ + - ]: 5 : pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
183 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
184 [ + - ]: 5 : pDevice->getPixel(aPt3) == aCol);
185 : :
186 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("raw pixel value #2",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
187 [ + - ]: 5 : pDevice->getBuffer()[0] == 0x01);
188 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("raw pixel value #3",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
189 [ + - ]: 10 : pDevice->getBuffer()[8] == 0x02);
190 : : }
191 : :
192 : : // 8bit alpha
193 : : {
194 : : pDevice = createBitmapDevice( aSize,
195 : : true,
196 [ + - ][ + - ]: 5 : Format::EIGHT_BIT_GREY );
[ + - ]
197 : :
198 : 5 : const Color aCol4(0x010101);
199 [ + - ]: 5 : pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
200 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
201 [ + - ]: 5 : pDevice->getPixel(aPt) == aCol4);
202 : :
203 : 5 : const Color aCol5(0x0F0F0F);
204 [ + - ]: 5 : pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
205 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
206 [ + - ]: 5 : pDevice->getPixel(aPt2) == aCol5);
207 : :
208 : 5 : const Color aCol6(0xFFFFFF);
209 [ + - ]: 5 : pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
210 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
211 [ + - ]: 5 : pDevice->getPixel(aPt3) == aCol6);
212 : : }
213 : :
214 : : // 16bpp
215 : : {
216 : : pDevice = createBitmapDevice( aSize,
217 : : true,
218 [ + - ][ + - ]: 5 : Format::SIXTEEN_BIT_LSB_TC_MASK );
[ + - ]
219 : 5 : const Color aCol7(0);
220 [ + - ]: 5 : pDevice->clear( aCol7 );
221 : :
222 : 5 : const Color aCol4(0x00101010);
223 [ + - ]: 5 : pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
224 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
225 [ + - ]: 5 : pDevice->getPixel(aPt) == aCol4);
226 : :
227 : 5 : const Color aCol5(0x00F0F0F0);
228 [ + - ]: 5 : pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
229 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
230 [ + - ]: 5 : pDevice->getPixel(aPt2) != aCol7);
231 : :
232 : 5 : const Color aCol6(0x00FFFFFF);
233 [ + - ]: 5 : pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
234 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
235 [ + - ]: 5 : pDevice->getPixel(aPt3) == aCol6);
236 : : }
237 : :
238 : : // 24bpp
239 : : {
240 : : pDevice = createBitmapDevice( aSize,
241 : : true,
242 [ + - ][ + - ]: 5 : Format::TWENTYFOUR_BIT_TC_MASK );
[ + - ]
243 : :
244 : 5 : const Color aCol4(0x01010101);
245 [ + - ]: 5 : pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
246 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
247 [ + - ]: 5 : pDevice->getPixel(aPt) == aCol4);
248 : :
249 : 5 : const Color aCol5(0x0F3F2F1F);
250 [ + - ]: 5 : pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
251 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
252 [ + - ]: 5 : pDevice->getPixel(aPt2) == aCol5);
253 : :
254 : 5 : const Color aCol6(0xFFFFFFFF);
255 [ + - ]: 5 : pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
256 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
257 [ + - ]: 5 : pDevice->getPixel(aPt3) == aCol6);
258 : :
259 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("raw pixel value #4",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ - + ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ # #
# # # # ]
[ + - ]
260 : : pDevice->getBuffer()[2] == 0x3F
261 : : && pDevice->getBuffer()[1] == 0x2F
262 [ + - ]: 5 : && pDevice->getBuffer()[0] == 0x1F);
263 : : }
264 : :
265 : : // 32bpp
266 : : {
267 : : pDevice = createBitmapDevice( aSize,
268 : : true,
269 [ + - ][ + - ]: 5 : Format::THIRTYTWO_BIT_TC_MASK );
[ + - ]
270 : :
271 : 5 : const Color aCol4(0x01010101);
272 [ + - ]: 5 : pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
273 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
274 [ + - ]: 5 : pDevice->getPixel(aPt) == aCol4);
275 : :
276 : 5 : const Color aCol5(0x0F0F0F0F);
277 [ + - ]: 5 : pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
278 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
279 [ + - ]: 5 : pDevice->getPixel(aPt2) == aCol5);
280 : :
281 : 5 : const Color aCol6(0xFFFFFFFF);
282 [ + - ]: 5 : pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
283 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15",
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
284 [ + - ]: 5 : pDevice->getPixel(aPt3) == aCol6);
285 [ + - ]: 5 : }
286 : 5 : }
287 : :
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.
291 : :
292 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(BasicTest);
[ + - ][ + - ]
[ # # ]
293 [ + - ][ + - ]: 5 : CPPUNIT_TEST(colorTest);
[ + - ][ + - ]
[ + - ][ + - ]
294 [ + - ][ + - ]: 5 : CPPUNIT_TEST(testConstruction);
[ + - ][ + - ]
[ + - ][ + - ]
295 [ + - ][ + - ]: 5 : CPPUNIT_TEST(testClone);
[ + - ][ + - ]
[ + - ][ + - ]
296 [ + - ][ + - ]: 5 : CPPUNIT_TEST(testPixelFuncs);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
297 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
298 : : };
299 : :
300 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest);
301 : : }
302 : :
303 [ + - ][ + - ]: 20 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
304 : :
305 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|