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