basictest.cxx (69de5a4c) basictest.cxx (97c63c1b)
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23
24// autogenerated file with codegen.pl
25
26#include "preextstl.h"
1/**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance

--- 10 unchanged lines hidden (view full) ---

19 *
20 *************************************************************/
21
22
23
24// autogenerated file with codegen.pl
25
26#include "preextstl.h"
27#include "cppunit/TestAssert.h"
28#include "cppunit/TestFixture.h"
29#include "cppunit/extensions/HelperMacros.h"
30#include "cppunit/plugin/TestPlugIn.h"
27#include "gtest/gtest.h"
31#include "postextstl.h"
32
33#include <basegfx/vector/b2isize.hxx>
34#include <basegfx/point/b2ipoint.hxx>
35
36#include <basebmp/color.hxx>
37#include <basebmp/scanlineformats.hxx>
38#include <basebmp/bitmapdevice.hxx>

--- 7 unchanged lines hidden (view full) ---

46
47namespace
48{
49/*
50 std::ofstream output("32bpp_test.dump");
51 debugDump( mpDevice32bpp, output );
52*/
53
28#include "postextstl.h"
29
30#include <basegfx/vector/b2isize.hxx>
31#include <basegfx/point/b2ipoint.hxx>
32
33#include <basebmp/color.hxx>
34#include <basebmp/scanlineformats.hxx>
35#include <basebmp/bitmapdevice.hxx>

--- 7 unchanged lines hidden (view full) ---

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