1*69de5a4cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*69de5a4cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*69de5a4cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*69de5a4cSAndrew Rist * distributed with this work for additional information 6*69de5a4cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*69de5a4cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*69de5a4cSAndrew Rist * "License"); you may not use this file except in compliance 9*69de5a4cSAndrew Rist * with the License. You may obtain a copy of the License at 10*69de5a4cSAndrew Rist * 11*69de5a4cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*69de5a4cSAndrew Rist * 13*69de5a4cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*69de5a4cSAndrew Rist * software distributed under the License is distributed on an 15*69de5a4cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*69de5a4cSAndrew Rist * KIND, either express or implied. See the License for the 17*69de5a4cSAndrew Rist * specific language governing permissions and limitations 18*69de5a4cSAndrew Rist * under the License. 19*69de5a4cSAndrew Rist * 20*69de5a4cSAndrew Rist *************************************************************/ 21*69de5a4cSAndrew Rist 22*69de5a4cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // autogenerated file with codegen.pl 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "preextstl.h" 27cdf0e10cSrcweir #include "cppunit/TestAssert.h" 28cdf0e10cSrcweir #include "cppunit/TestFixture.h" 29cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 30cdf0e10cSrcweir #include "cppunit/plugin/TestPlugIn.h" 31cdf0e10cSrcweir #include "postextstl.h" 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <basegfx/vector/b2isize.hxx> 34cdf0e10cSrcweir #include <basegfx/point/b2ipoint.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <basebmp/color.hxx> 37cdf0e10cSrcweir #include <basebmp/scanlineformats.hxx> 38cdf0e10cSrcweir #include <basebmp/bitmapdevice.hxx> 39cdf0e10cSrcweir #include <basebmp/debug.hxx> 40cdf0e10cSrcweir #include "tools.hxx" 41cdf0e10cSrcweir 42cdf0e10cSrcweir #include <iostream> 43cdf0e10cSrcweir #include <fstream> 44cdf0e10cSrcweir 45cdf0e10cSrcweir using namespace ::basebmp; 46cdf0e10cSrcweir 47cdf0e10cSrcweir namespace 48cdf0e10cSrcweir { 49cdf0e10cSrcweir /* 50cdf0e10cSrcweir std::ofstream output("32bpp_test.dump"); 51cdf0e10cSrcweir debugDump( mpDevice32bpp, output ); 52cdf0e10cSrcweir */ 53cdf0e10cSrcweir 54cdf0e10cSrcweir class BasicTest : public CppUnit::TestFixture 55cdf0e10cSrcweir { 56cdf0e10cSrcweir public: 57cdf0e10cSrcweir void colorTest() 58cdf0e10cSrcweir { 59cdf0e10cSrcweir Color aTestColor; 60cdf0e10cSrcweir 61cdf0e10cSrcweir aTestColor = Color(0xDEADBEEF); 62cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("unary constructor", 63cdf0e10cSrcweir aTestColor.toInt32() == 0xDEADBEEF ); 64cdf0e10cSrcweir 65cdf0e10cSrcweir aTestColor = Color( 0x10, 0x20, 0xFF ); 66cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("ternary constructor", 67cdf0e10cSrcweir aTestColor.toInt32() == 0x001020FF ); 68cdf0e10cSrcweir 69cdf0e10cSrcweir aTestColor.setRed( 0x0F ); 70cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("setRed()", 71cdf0e10cSrcweir aTestColor.toInt32() == 0x00F20FF ); 72cdf0e10cSrcweir 73cdf0e10cSrcweir aTestColor.setGreen( 0x0F ); 74cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("setGreen()", 75cdf0e10cSrcweir aTestColor.toInt32() == 0x00F0FFF ); 76cdf0e10cSrcweir 77cdf0e10cSrcweir aTestColor.setBlue( 0x10 ); 78cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("setBlue()", 79cdf0e10cSrcweir aTestColor.toInt32() == 0x00F0F10 ); 80cdf0e10cSrcweir 81cdf0e10cSrcweir aTestColor.setGrey( 0x13 ); 82cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("setGrey()", 83cdf0e10cSrcweir aTestColor.toInt32() == 0x00131313 ); 84cdf0e10cSrcweir 85cdf0e10cSrcweir aTestColor = Color( 0x10, 0x20, 0xFF ); 86cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("getRed()", 87cdf0e10cSrcweir aTestColor.getRed() == 0x10 ); 88cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("getGreen()", 89cdf0e10cSrcweir aTestColor.getGreen() == 0x20 ); 90cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("getBlue()", 91cdf0e10cSrcweir aTestColor.getBlue() == 0xFF ); 92cdf0e10cSrcweir 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir void testConstruction() 96cdf0e10cSrcweir { 97cdf0e10cSrcweir const basegfx::B2ISize aSize(101,101); 98cdf0e10cSrcweir basegfx::B2ISize aSize2(aSize); 99cdf0e10cSrcweir BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize, 100cdf0e10cSrcweir true, 101cdf0e10cSrcweir Format::ONE_BIT_MSB_PAL )); 102cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("right size", 103cdf0e10cSrcweir pDevice->getSize() == aSize2 ); 104cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Top down format", 105cdf0e10cSrcweir pDevice->isTopDown() == true ); 106cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Scanline format", 107cdf0e10cSrcweir pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL ); 108cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Scanline len", 109cdf0e10cSrcweir pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 ); 110cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Palette existence", 111cdf0e10cSrcweir pDevice->getPalette() ); 112cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black", 113cdf0e10cSrcweir (*pDevice->getPalette())[0] == Color(0) ); 114cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white", 115cdf0e10cSrcweir (*pDevice->getPalette())[1] == Color(0xFFFFFFFF) ); 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir void testPixelFuncs() 119cdf0e10cSrcweir { 120cdf0e10cSrcweir // 1bpp 121cdf0e10cSrcweir const basegfx::B2ISize aSize(64,64); 122cdf0e10cSrcweir BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize, 123cdf0e10cSrcweir true, 124cdf0e10cSrcweir Format::ONE_BIT_MSB_PAL )); 125cdf0e10cSrcweir 126cdf0e10cSrcweir const basegfx::B2IPoint aPt(3,3); 127cdf0e10cSrcweir const Color aCol(0xFFFFFFFF); 128cdf0e10cSrcweir pDevice->setPixel( aPt, aCol, DrawMode_PAINT ); 129cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1", 130cdf0e10cSrcweir pDevice->getPixel(aPt) == aCol); 131cdf0e10cSrcweir 132cdf0e10cSrcweir const basegfx::B2IPoint aPt2(0,0); 133cdf0e10cSrcweir const Color aCol2(0xFFFFFFFF); 134cdf0e10cSrcweir pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT ); 135cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2", 136cdf0e10cSrcweir pDevice->getPixel(aPt2) == aCol2); 137cdf0e10cSrcweir 138cdf0e10cSrcweir const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1); 139cdf0e10cSrcweir const Color aCol3(0x00000000); 140cdf0e10cSrcweir pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT ); 141cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3", 142cdf0e10cSrcweir pDevice->getPixel(aPt3) == aCol3); 143cdf0e10cSrcweir 144cdf0e10cSrcweir pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT ); 145cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5", 146cdf0e10cSrcweir pDevice->getPixel(aPt3) == aCol2); 147cdf0e10cSrcweir 148cdf0e10cSrcweir const basegfx::B2IPoint aPt4(-100000,-100000); 149cdf0e10cSrcweir pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT ); 150cdf0e10cSrcweir const basegfx::B2IPoint aPt5(100000,100000); 151cdf0e10cSrcweir pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir sal_Int32 nPixel(countPixel(pDevice, aCol2)); 154cdf0e10cSrcweir const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY()); 155cdf0e10cSrcweir pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT ); 156cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("setPixel clipping", 157cdf0e10cSrcweir countPixel(pDevice, aCol2) == nPixel); 158cdf0e10cSrcweir 159cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("raw pixel value #1", 160cdf0e10cSrcweir pDevice->getBuffer()[0] == 0x80); 161cdf0e10cSrcweir 162cdf0e10cSrcweir // 1bit LSB 163cdf0e10cSrcweir { 164cdf0e10cSrcweir pDevice = createBitmapDevice( aSize, 165cdf0e10cSrcweir true, 166cdf0e10cSrcweir Format::ONE_BIT_LSB_PAL ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir pDevice->setPixel( aPt2, aCol, DrawMode_PAINT ); 169cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4", 170cdf0e10cSrcweir pDevice->getPixel(aPt2) == aCol); 171cdf0e10cSrcweir 172cdf0e10cSrcweir const basegfx::B2IPoint aPt222(1,1); 173cdf0e10cSrcweir pDevice->setPixel( aPt222, aCol, DrawMode_PAINT ); 174cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5", 175cdf0e10cSrcweir pDevice->getPixel(aPt222) == aCol); 176cdf0e10cSrcweir 177cdf0e10cSrcweir pDevice->setPixel( aPt3, aCol, DrawMode_PAINT ); 178cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6", 179cdf0e10cSrcweir pDevice->getPixel(aPt3) == aCol); 180cdf0e10cSrcweir 181cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("raw pixel value #2", 182cdf0e10cSrcweir pDevice->getBuffer()[0] == 0x01); 183cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("raw pixel value #3", 184cdf0e10cSrcweir pDevice->getBuffer()[8] == 0x02); 185cdf0e10cSrcweir } 186cdf0e10cSrcweir 187cdf0e10cSrcweir // 8bit alpha 188cdf0e10cSrcweir { 189cdf0e10cSrcweir pDevice = createBitmapDevice( aSize, 190cdf0e10cSrcweir true, 191cdf0e10cSrcweir Format::EIGHT_BIT_GREY ); 192cdf0e10cSrcweir 193cdf0e10cSrcweir const Color aCol4(0x010101); 194cdf0e10cSrcweir pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 195cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4", 196cdf0e10cSrcweir pDevice->getPixel(aPt) == aCol4); 197cdf0e10cSrcweir 198cdf0e10cSrcweir const Color aCol5(0x0F0F0F); 199cdf0e10cSrcweir pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 200cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5", 201cdf0e10cSrcweir pDevice->getPixel(aPt2) == aCol5); 202cdf0e10cSrcweir 203cdf0e10cSrcweir const Color aCol6(0xFFFFFF); 204cdf0e10cSrcweir pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 205cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6", 206cdf0e10cSrcweir pDevice->getPixel(aPt3) == aCol6); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir // 16bpp 210cdf0e10cSrcweir { 211cdf0e10cSrcweir pDevice = createBitmapDevice( aSize, 212cdf0e10cSrcweir true, 213cdf0e10cSrcweir Format::SIXTEEN_BIT_LSB_TC_MASK ); 214cdf0e10cSrcweir const Color aCol7(0); 215cdf0e10cSrcweir pDevice->clear( aCol7 ); 216cdf0e10cSrcweir 217cdf0e10cSrcweir const Color aCol4(0x00101010); 218cdf0e10cSrcweir pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 219cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7", 220cdf0e10cSrcweir pDevice->getPixel(aPt) == aCol4); 221cdf0e10cSrcweir 222cdf0e10cSrcweir const Color aCol5(0x00F0F0F0); 223cdf0e10cSrcweir pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 224cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8", 225cdf0e10cSrcweir pDevice->getPixel(aPt2) != aCol7); 226cdf0e10cSrcweir 227cdf0e10cSrcweir const Color aCol6(0x00FFFFFF); 228cdf0e10cSrcweir pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 229cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9", 230cdf0e10cSrcweir pDevice->getPixel(aPt3) == aCol6); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir // 24bpp 234cdf0e10cSrcweir { 235cdf0e10cSrcweir pDevice = createBitmapDevice( aSize, 236cdf0e10cSrcweir true, 237cdf0e10cSrcweir Format::TWENTYFOUR_BIT_TC_MASK ); 238cdf0e10cSrcweir 239cdf0e10cSrcweir const Color aCol4(0x01010101); 240cdf0e10cSrcweir pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 241cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10", 242cdf0e10cSrcweir pDevice->getPixel(aPt) == aCol4); 243cdf0e10cSrcweir 244cdf0e10cSrcweir const Color aCol5(0x0F3F2F1F); 245cdf0e10cSrcweir pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 246cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11", 247cdf0e10cSrcweir pDevice->getPixel(aPt2) == aCol5); 248cdf0e10cSrcweir 249cdf0e10cSrcweir const Color aCol6(0xFFFFFFFF); 250cdf0e10cSrcweir pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 251cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12", 252cdf0e10cSrcweir pDevice->getPixel(aPt3) == aCol6); 253cdf0e10cSrcweir 254cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("raw pixel value #4", 255cdf0e10cSrcweir pDevice->getBuffer()[2] == 0x3F 256cdf0e10cSrcweir && pDevice->getBuffer()[1] == 0x2F 257cdf0e10cSrcweir && pDevice->getBuffer()[0] == 0x1F); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir 260cdf0e10cSrcweir // 32bpp 261cdf0e10cSrcweir { 262cdf0e10cSrcweir pDevice = createBitmapDevice( aSize, 263cdf0e10cSrcweir true, 264cdf0e10cSrcweir Format::THIRTYTWO_BIT_TC_MASK ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir const Color aCol4(0x01010101); 267cdf0e10cSrcweir pDevice->setPixel( aPt, aCol4, DrawMode_PAINT ); 268cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13", 269cdf0e10cSrcweir pDevice->getPixel(aPt) == aCol4); 270cdf0e10cSrcweir 271cdf0e10cSrcweir const Color aCol5(0x0F0F0F0F); 272cdf0e10cSrcweir pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT ); 273cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14", 274cdf0e10cSrcweir pDevice->getPixel(aPt2) == aCol5); 275cdf0e10cSrcweir 276cdf0e10cSrcweir const Color aCol6(0xFFFFFFFF); 277cdf0e10cSrcweir pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT ); 278cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15", 279cdf0e10cSrcweir pDevice->getPixel(aPt3) == aCol6); 280cdf0e10cSrcweir } 281cdf0e10cSrcweir } 282cdf0e10cSrcweir 283cdf0e10cSrcweir // Change the following lines only, if you add, remove or rename 284cdf0e10cSrcweir // member functions of the current class, 285cdf0e10cSrcweir // because these macros are need by auto register mechanism. 286cdf0e10cSrcweir 287cdf0e10cSrcweir CPPUNIT_TEST_SUITE(BasicTest); 288cdf0e10cSrcweir CPPUNIT_TEST(colorTest); 289cdf0e10cSrcweir CPPUNIT_TEST(testConstruction); 290cdf0e10cSrcweir CPPUNIT_TEST(testPixelFuncs); 291cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 292cdf0e10cSrcweir }; 293cdf0e10cSrcweir 294cdf0e10cSrcweir // ----------------------------------------------------------------------------- 295cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest); 296cdf0e10cSrcweir } 297cdf0e10cSrcweir 298cdf0e10cSrcweir CPPUNIT_PLUGIN_IMPLEMENT(); 299