xref: /aoo42x/main/basebmp/test/basictest.cxx (revision 7a227dd4)
169de5a4cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
369de5a4cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
469de5a4cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
569de5a4cSAndrew Rist  * distributed with this work for additional information
669de5a4cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
769de5a4cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
869de5a4cSAndrew Rist  * "License"); you may not use this file except in compliance
969de5a4cSAndrew Rist  * with the License.  You may obtain a copy of the License at
1069de5a4cSAndrew Rist  *
1169de5a4cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1269de5a4cSAndrew Rist  *
1369de5a4cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
1469de5a4cSAndrew Rist  * software distributed under the License is distributed on an
1569de5a4cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1669de5a4cSAndrew Rist  * KIND, either express or implied.  See the License for the
1769de5a4cSAndrew Rist  * specific language governing permissions and limitations
1869de5a4cSAndrew Rist  * under the License.
1969de5a4cSAndrew Rist  *
2069de5a4cSAndrew Rist  *************************************************************/
2169de5a4cSAndrew Rist 
2269de5a4cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // autogenerated file with codegen.pl
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "preextstl.h"
2797c63c1bSDamjan Jovanovic #include "gtest/gtest.h"
28cdf0e10cSrcweir #include "postextstl.h"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx>
31cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <basebmp/color.hxx>
34cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx>
35cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx>
36cdf0e10cSrcweir #include <basebmp/debug.hxx>
37cdf0e10cSrcweir #include "tools.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <iostream>
40cdf0e10cSrcweir #include <fstream>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace ::basebmp;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace
45cdf0e10cSrcweir {
46cdf0e10cSrcweir /*
47cdf0e10cSrcweir   std::ofstream output("32bpp_test.dump");
48cdf0e10cSrcweir   debugDump( mpDevice32bpp, output );
49cdf0e10cSrcweir */
50cdf0e10cSrcweir 
5197c63c1bSDamjan Jovanovic class BasicTest : public ::testing::Test
52cdf0e10cSrcweir {
53cdf0e10cSrcweir public:
5497c63c1bSDamjan Jovanovic };
5597c63c1bSDamjan Jovanovic 
TEST_F(BasicTest,colorTest)5697c63c1bSDamjan Jovanovic TEST_F(BasicTest, colorTest)
5797c63c1bSDamjan Jovanovic {
5897c63c1bSDamjan Jovanovic     Color aTestColor;
5997c63c1bSDamjan Jovanovic 
6097c63c1bSDamjan Jovanovic     aTestColor = Color(0xDEADBEEF);
6197c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.toInt32() == 0xDEADBEEF ) << "unary constructor";
6297c63c1bSDamjan Jovanovic 
6397c63c1bSDamjan Jovanovic     aTestColor = Color( 0x10, 0x20, 0xFF );
6497c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.toInt32() == 0x001020FF ) << "ternary constructor";
6597c63c1bSDamjan Jovanovic 
6697c63c1bSDamjan Jovanovic     aTestColor.setRed( 0x0F );
6797c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.toInt32() == 0x00F20FF ) << "setRed()";
6897c63c1bSDamjan Jovanovic 
6997c63c1bSDamjan Jovanovic     aTestColor.setGreen( 0x0F );
7097c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.toInt32() == 0x00F0FFF ) << "setGreen()";
7197c63c1bSDamjan Jovanovic 
7297c63c1bSDamjan Jovanovic     aTestColor.setBlue( 0x10 );
7397c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.toInt32() == 0x00F0F10 ) << "setBlue()";
7497c63c1bSDamjan Jovanovic 
7597c63c1bSDamjan Jovanovic     aTestColor.setGrey( 0x13 );
7697c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.toInt32() == 0x00131313 ) << "setGrey()";
7797c63c1bSDamjan Jovanovic 
7897c63c1bSDamjan Jovanovic     aTestColor = Color( 0x10, 0x20, 0xFF );
7997c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.getRed() == 0x10 ) << "getRed()";
8097c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.getGreen() == 0x20 ) << "getGreen()";
8197c63c1bSDamjan Jovanovic     ASSERT_TRUE( aTestColor.getBlue() == 0xFF ) << "getBlue()";
8297c63c1bSDamjan Jovanovic }
8397c63c1bSDamjan Jovanovic 
TEST_F(BasicTest,testConstruction)8497c63c1bSDamjan Jovanovic TEST_F(BasicTest, testConstruction)
8597c63c1bSDamjan Jovanovic {
8697c63c1bSDamjan Jovanovic     const basegfx::B2ISize aSize(101,101);
8797c63c1bSDamjan Jovanovic     basegfx::B2ISize       aSize2(aSize);
8897c63c1bSDamjan Jovanovic     BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
8997c63c1bSDamjan Jovanovic                                                        true,
9097c63c1bSDamjan Jovanovic                                                        Format::ONE_BIT_MSB_PAL ));
9197c63c1bSDamjan Jovanovic     ASSERT_TRUE( pDevice->getSize() == aSize2 ) << "right size";
9297c63c1bSDamjan Jovanovic     ASSERT_TRUE( pDevice->isTopDown() == true ) << "Top down format";
9397c63c1bSDamjan Jovanovic     ASSERT_TRUE( pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL ) << "Scanline format";
9497c63c1bSDamjan Jovanovic     ASSERT_TRUE( pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 ) << "Scanline len";
95*7a227dd4SDamjan Jovanovic     ASSERT_TRUE( pDevice->getPalette() != NULL ) << "Palette existence";
9697c63c1bSDamjan Jovanovic     ASSERT_TRUE( (*pDevice->getPalette())[0] == Color(0) ) << "Palette entry 0 is black";
9797c63c1bSDamjan Jovanovic     ASSERT_TRUE( (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) ) << "Palette entry 1 is white";
9897c63c1bSDamjan Jovanovic }
9997c63c1bSDamjan Jovanovic 
TEST_F(BasicTest,testPixelFuncs)10097c63c1bSDamjan Jovanovic TEST_F(BasicTest, testPixelFuncs)
10197c63c1bSDamjan Jovanovic {
10297c63c1bSDamjan Jovanovic     // 1bpp
10397c63c1bSDamjan Jovanovic     const basegfx::B2ISize aSize(64,64);
10497c63c1bSDamjan Jovanovic     BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
10597c63c1bSDamjan Jovanovic                                                        true,
10697c63c1bSDamjan Jovanovic                                                        Format::ONE_BIT_MSB_PAL ));
10797c63c1bSDamjan Jovanovic 
10897c63c1bSDamjan Jovanovic     const basegfx::B2IPoint aPt(3,3);
10997c63c1bSDamjan Jovanovic     const Color aCol(0xFFFFFFFF);
11097c63c1bSDamjan Jovanovic     pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
11197c63c1bSDamjan Jovanovic     ASSERT_TRUE(pDevice->getPixel(aPt) == aCol) << "get/setPixel roundtrip #1";
11297c63c1bSDamjan Jovanovic 
11397c63c1bSDamjan Jovanovic     const basegfx::B2IPoint aPt2(0,0);
11497c63c1bSDamjan Jovanovic     const Color aCol2(0xFFFFFFFF);
11597c63c1bSDamjan Jovanovic     pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
11697c63c1bSDamjan Jovanovic     ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol2) << "get/setPixel roundtrip #2";
11797c63c1bSDamjan Jovanovic 
11897c63c1bSDamjan Jovanovic     const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
11997c63c1bSDamjan Jovanovic     const Color aCol3(0x00000000);
12097c63c1bSDamjan Jovanovic     pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
12197c63c1bSDamjan Jovanovic     ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol3) << "get/setPixel roundtrip #3";
12297c63c1bSDamjan Jovanovic 
12397c63c1bSDamjan Jovanovic     pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
12497c63c1bSDamjan Jovanovic     ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol2) << "get/setPixel roundtrip #3.5";
12597c63c1bSDamjan Jovanovic 
12697c63c1bSDamjan Jovanovic     const basegfx::B2IPoint aPt4(-100000,-100000);
12797c63c1bSDamjan Jovanovic     pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
12897c63c1bSDamjan Jovanovic     const basegfx::B2IPoint aPt5(100000,100000);
12997c63c1bSDamjan Jovanovic     pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
13097c63c1bSDamjan Jovanovic 
13197c63c1bSDamjan Jovanovic     sal_Int32 nPixel(countPixel(pDevice, aCol2));
13297c63c1bSDamjan Jovanovic     const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
13397c63c1bSDamjan Jovanovic     pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
13497c63c1bSDamjan Jovanovic     ASSERT_TRUE(countPixel(pDevice, aCol2) == nPixel) << "setPixel clipping";
13597c63c1bSDamjan Jovanovic 
13697c63c1bSDamjan Jovanovic     ASSERT_TRUE(pDevice->getBuffer()[0] == 0x80) << "raw pixel value #1";
13797c63c1bSDamjan Jovanovic 
13897c63c1bSDamjan Jovanovic     // 1bit LSB
139cdf0e10cSrcweir     {
14097c63c1bSDamjan Jovanovic         pDevice = createBitmapDevice( aSize,
14197c63c1bSDamjan Jovanovic                                       true,
14297c63c1bSDamjan Jovanovic                                       Format::ONE_BIT_LSB_PAL );
143cdf0e10cSrcweir 
14497c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
14597c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol) << "get/setPixel roundtrip #4";
146cdf0e10cSrcweir 
14797c63c1bSDamjan Jovanovic         const basegfx::B2IPoint aPt222(1,1);
14897c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
14997c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt222) == aCol) << "get/setPixel roundtrip #5";
150cdf0e10cSrcweir 
15197c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
15297c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol) << "get/setPixel roundtrip #6";
153cdf0e10cSrcweir 
15497c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getBuffer()[0] == 0x01) << "raw pixel value #2";
15597c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getBuffer()[8] == 0x02) << "raw pixel value #3";
15697c63c1bSDamjan Jovanovic     }
157cdf0e10cSrcweir 
15897c63c1bSDamjan Jovanovic     // 8bit alpha
15997c63c1bSDamjan Jovanovic     {
16097c63c1bSDamjan Jovanovic         pDevice = createBitmapDevice( aSize,
16197c63c1bSDamjan Jovanovic                                       true,
16297c63c1bSDamjan Jovanovic                                       Format::EIGHT_BIT_GREY );
163cdf0e10cSrcweir 
16497c63c1bSDamjan Jovanovic         const Color aCol4(0x010101);
16597c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
16697c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #4";
167cdf0e10cSrcweir 
16897c63c1bSDamjan Jovanovic         const Color aCol5(0x0F0F0F);
16997c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
17097c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #5";
171cdf0e10cSrcweir 
17297c63c1bSDamjan Jovanovic         const Color aCol6(0xFFFFFF);
17397c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
17497c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #6";
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir 
17797c63c1bSDamjan Jovanovic     // 16bpp
178cdf0e10cSrcweir     {
17997c63c1bSDamjan Jovanovic         pDevice = createBitmapDevice( aSize,
18097c63c1bSDamjan Jovanovic                                       true,
18197c63c1bSDamjan Jovanovic                                       Format::SIXTEEN_BIT_LSB_TC_MASK );
18297c63c1bSDamjan Jovanovic         const Color aCol7(0);
18397c63c1bSDamjan Jovanovic         pDevice->clear( aCol7 );
18497c63c1bSDamjan Jovanovic 
18597c63c1bSDamjan Jovanovic         const Color aCol4(0x00101010);
18697c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
18797c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #7";
18897c63c1bSDamjan Jovanovic 
18997c63c1bSDamjan Jovanovic         const Color aCol5(0x00F0F0F0);
19097c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
19197c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt2) != aCol7) << "get/setPixel roundtrip #8";
19297c63c1bSDamjan Jovanovic 
19397c63c1bSDamjan Jovanovic         const Color aCol6(0x00FFFFFF);
19497c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
19597c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #9";
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
19897c63c1bSDamjan Jovanovic     // 24bpp
199cdf0e10cSrcweir     {
20097c63c1bSDamjan Jovanovic         pDevice = createBitmapDevice( aSize,
20197c63c1bSDamjan Jovanovic                                       true,
20297c63c1bSDamjan Jovanovic                                       Format::TWENTYFOUR_BIT_TC_MASK );
20397c63c1bSDamjan Jovanovic 
20497c63c1bSDamjan Jovanovic         const Color aCol4(0x01010101);
20597c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
20697c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #10";
20797c63c1bSDamjan Jovanovic 
20897c63c1bSDamjan Jovanovic         const Color aCol5(0x0F3F2F1F);
20997c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
21097c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #11";
21197c63c1bSDamjan Jovanovic 
21297c63c1bSDamjan Jovanovic         const Color aCol6(0xFFFFFFFF);
21397c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
21497c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #12";
21597c63c1bSDamjan Jovanovic 
21697c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getBuffer()[2] == 0x3F
21797c63c1bSDamjan Jovanovic                                && pDevice->getBuffer()[1] == 0x2F
21897c63c1bSDamjan Jovanovic                                && pDevice->getBuffer()[0] == 0x1F) << "raw pixel value #4";
219cdf0e10cSrcweir     }
220cdf0e10cSrcweir 
22197c63c1bSDamjan Jovanovic     // 32bpp
22297c63c1bSDamjan Jovanovic     {
22397c63c1bSDamjan Jovanovic         pDevice = createBitmapDevice( aSize,
22497c63c1bSDamjan Jovanovic                                       true,
22597c63c1bSDamjan Jovanovic                                       Format::THIRTYTWO_BIT_TC_MASK );
22697c63c1bSDamjan Jovanovic 
22797c63c1bSDamjan Jovanovic         const Color aCol4(0x01010101);
22897c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
22997c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt) == aCol4) << "get/setPixel roundtrip #13";
230cdf0e10cSrcweir 
23197c63c1bSDamjan Jovanovic         const Color aCol5(0x0F0F0F0F);
23297c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
23397c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt2) == aCol5) << "get/setPixel roundtrip #14";
23497c63c1bSDamjan Jovanovic 
23597c63c1bSDamjan Jovanovic         const Color aCol6(0xFFFFFFFF);
23697c63c1bSDamjan Jovanovic         pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
23797c63c1bSDamjan Jovanovic         ASSERT_TRUE(pDevice->getPixel(aPt3) == aCol6) << "get/setPixel roundtrip #15";
23897c63c1bSDamjan Jovanovic     }
23997c63c1bSDamjan Jovanovic }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243