office-gobmx/basebmp/test/basictest.cxx

275 lines
10 KiB
C++
Raw Normal View History

/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: basictest.cxx,v $
*
* $Revision: 1.7 $
*
* last change: $Author: thb $ $Date: 2006-07-06 10:00:41 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
2006-05-31 03:49:45 -05:00
// autogenerated file with codegen.pl
#include <cppunit/simpleheader.hxx>
#include <basegfx/vector/b2isize.hxx>
#include <basegfx/point/b2ipoint.hxx>
#include <basebmp/color.hxx>
#include <basebmp/scanlineformats.hxx>
#include <basebmp/bitmapdevice.hxx>
#include <basebmp/debug.hxx>
#include "tools.hxx"
#include <iostream>
#include <fstream>
2006-05-31 03:49:45 -05:00
using namespace ::basebmp;
namespace
{
/*
std::ofstream output("32bpp_test.dump");
debugDump( mpDevice32bpp, output );
*/
2006-05-31 03:49:45 -05:00
class BasicTest : public CppUnit::TestFixture
{
public:
void colorTest()
{
Color aTestColor;
aTestColor = Color(0xDEADBEEF);
CPPUNIT_ASSERT_MESSAGE("unary constructor",
aTestColor.toInt32() == 0xDEADBEEF );
aTestColor = Color( 0x10, 0x20, 0xFF );
CPPUNIT_ASSERT_MESSAGE("ternary constructor",
aTestColor.toInt32() == 0x001020FF );
aTestColor.setRed( 0x0F );
CPPUNIT_ASSERT_MESSAGE("setRed()",
aTestColor.toInt32() == 0x00F20FF );
aTestColor.setGreen( 0x0F );
CPPUNIT_ASSERT_MESSAGE("setGreen()",
aTestColor.toInt32() == 0x00F0FFF );
aTestColor.setBlue( 0x10 );
CPPUNIT_ASSERT_MESSAGE("setBlue()",
aTestColor.toInt32() == 0x00F0F10 );
aTestColor.setGray( 0x13 );
CPPUNIT_ASSERT_MESSAGE("setGray()",
aTestColor.toInt32() == 0x00131313 );
aTestColor = Color( 0x10, 0x20, 0xFF );
CPPUNIT_ASSERT_MESSAGE("getRed()",
aTestColor.getRed() == 0x10 );
CPPUNIT_ASSERT_MESSAGE("getGreen()",
aTestColor.getGreen() == 0x20 );
CPPUNIT_ASSERT_MESSAGE("getBlue()",
aTestColor.getBlue() == 0xFF );
}
2006-05-31 03:49:45 -05:00
void testConstruction()
{
const basegfx::B2ISize aSize(101,101);
basegfx::B2ISize aSize2(aSize);
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
true,
Format::ONE_BIT_MSB_PAL ));
CPPUNIT_ASSERT_MESSAGE("right size",
pDevice->getSize() == aSize2 );
CPPUNIT_ASSERT_MESSAGE("Top down format",
pDevice->isTopDown() == true );
CPPUNIT_ASSERT_MESSAGE("Scanline format",
pDevice->getScanlineFormat() == Format::ONE_BIT_MSB_PAL );
CPPUNIT_ASSERT_MESSAGE("Scanline len",
pDevice->getScanlineStride() == (aSize2.getY() + 7)/8 );
}
void testPixelFuncs()
{
// 1bpp
const basegfx::B2ISize aSize(64,64);
2006-05-31 03:49:45 -05:00
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
true,
Format::ONE_BIT_MSB_PAL ));
const basegfx::B2IPoint aPt(3,3);
const Color aCol(0xFFFFFFFF);
pDevice->setPixel( aPt, aCol, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #1",
pDevice->getPixel(aPt) == aCol);
const basegfx::B2IPoint aPt2(0,0);
const Color aCol2(0xFFFFFFFF);
pDevice->setPixel( aPt2, aCol2, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #2",
pDevice->getPixel(aPt2) == aCol2);
const basegfx::B2IPoint aPt3(aSize.getX()-1,aSize.getY()-1);
const Color aCol3(0x00000000);
pDevice->setPixel( aPt3, aCol3, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3",
pDevice->getPixel(aPt3) == aCol3);
pDevice->setPixel( aPt3, aCol2, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #3.5",
pDevice->getPixel(aPt3) == aCol2);
2006-05-31 03:49:45 -05:00
const basegfx::B2IPoint aPt4(-100000,-100000);
pDevice->setPixel( aPt4, aCol3, DrawMode_PAINT );
const basegfx::B2IPoint aPt5(100000,100000);
pDevice->setPixel( aPt5, aCol3, DrawMode_PAINT );
sal_Int32 nPixel(countPixel(pDevice, aCol2));
const basegfx::B2IPoint aPt6(aSize.getX(),aSize.getY());
pDevice->setPixel( aPt6, aCol2, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("setPixel clipping",
countPixel(pDevice, aCol2) == nPixel);
// 8bit alpha
2006-05-31 03:49:45 -05:00
{
pDevice = createBitmapDevice( aSize,
true,
Format::EIGHT_BIT_GRAY );
2006-05-31 03:49:45 -05:00
const Color aCol4(0x010101);
2006-05-31 03:49:45 -05:00
pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
pDevice->getPixel(aPt) == aCol4);
const Color aCol5(0x0F0F0F);
2006-05-31 03:49:45 -05:00
pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
pDevice->getPixel(aPt2) == aCol5);
const Color aCol6(0xFFFFFF);
2006-05-31 03:49:45 -05:00
pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
pDevice->getPixel(aPt3) == aCol6);
}
// 16bpp
{
pDevice = createBitmapDevice( aSize,
true,
Format::SIXTEEN_BIT_LSB_TC_MASK );
const Color aCol7(0);
pDevice->clear( aCol7 );
const Color aCol4(0x00101010);
pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
std::ofstream output("16bpp_test.dump");
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
pDevice->getPixel(aPt) == aCol4);
const Color aCol5(0x00F0F0F0);
pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
debugDump( pDevice, output );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
pDevice->getPixel(aPt2) == aCol5);
const Color aCol6(0x00FFFFFF);
pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
pDevice->getPixel(aPt3) != aCol7);
}
// 24bpp
{
pDevice = createBitmapDevice( aSize,
true,
Format::TWENTYFOUR_BIT_TC_MASK );
const Color aCol4(0x01010101);
pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #10",
pDevice->getPixel(aPt) == aCol4);
const Color aCol5(0x0F0F0F0F);
pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #11",
pDevice->getPixel(aPt2) == aCol5);
const Color aCol6(0xFFFFFFFF);
pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #12",
pDevice->getPixel(aPt3) == aCol6);
}
2006-05-31 03:49:45 -05:00
// 32bpp
{
pDevice = createBitmapDevice( aSize,
true,
Format::THIRTYTWO_BIT_TC_MASK );
const Color aCol4(0x01010101);
pDevice->setPixel( aPt, aCol4, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #13",
2006-05-31 03:49:45 -05:00
pDevice->getPixel(aPt) == aCol4);
const Color aCol5(0x0F0F0F0F);
pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #14",
2006-05-31 03:49:45 -05:00
pDevice->getPixel(aPt2) == aCol5);
const Color aCol6(0xFFFFFFFF);
pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #15",
2006-05-31 03:49:45 -05:00
pDevice->getPixel(aPt3) == aCol6);
}
}
// Change the following lines only, if you add, remove or rename
// member functions of the current class,
// because these macros are need by auto register mechanism.
CPPUNIT_TEST_SUITE(BasicTest);
CPPUNIT_TEST(colorTest);
2006-05-31 03:49:45 -05:00
CPPUNIT_TEST(testConstruction);
CPPUNIT_TEST(testPixelFuncs);
CPPUNIT_TEST_SUITE_END();
};
// -----------------------------------------------------------------------------
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BasicTest, "BasicTest");
}
// -----------------------------------------------------------------------------
// this macro creates an empty function, which will called by the RegisterAllFunctions()
// to let the user the possibility to also register some functions by hand.
NOADDITIONAL;