2010-10-14 01:27:31 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2006-05-31 04:12:13 -05:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 02:32:10 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2006-05-31 04:12:13 -05:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2006-05-31 04:12:13 -05:00
|
|
|
*
|
2008-04-11 02:32:10 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2006-05-31 04:12:13 -05:00
|
|
|
*
|
2008-04-11 02:32:10 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2006-05-31 04:12:13 -05:00
|
|
|
*
|
2008-04-11 02:32:10 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2006-05-31 04:12:13 -05:00
|
|
|
*
|
2008-04-11 02:32:10 -05:00
|
|
|
* OpenOffice.org 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 version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2006-05-31 04:12:13 -05:00
|
|
|
*
|
2008-04-11 02:32:10 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2006-05-31 04:12:13 -05:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2011-09-12 14:24:31 -05:00
|
|
|
#include "sal/config.h"
|
|
|
|
#include "sal/precppunit.hxx"
|
|
|
|
|
2011-08-03 09:46:15 -05:00
|
|
|
#ifdef IOS
|
|
|
|
#define CPPUNIT_PLUGIN_EXPORTED_NAME cppunitTest_basebmp
|
|
|
|
#endif
|
|
|
|
|
2006-05-31 03:49:45 -05:00
|
|
|
// autogenerated file with codegen.pl
|
|
|
|
|
2009-12-11 07:29:59 -06:00
|
|
|
#include "cppunit/TestAssert.h"
|
|
|
|
#include "cppunit/TestFixture.h"
|
|
|
|
#include "cppunit/extensions/HelperMacros.h"
|
|
|
|
#include "cppunit/plugin/TestPlugIn.h"
|
2006-05-31 03:49:45 -05:00
|
|
|
|
|
|
|
#include <basegfx/vector/b2isize.hxx>
|
|
|
|
#include <basegfx/point/b2ipoint.hxx>
|
|
|
|
|
|
|
|
#include <basebmp/color.hxx>
|
|
|
|
#include <basebmp/scanlineformats.hxx>
|
|
|
|
#include <basebmp/bitmapdevice.hxx>
|
2006-06-07 08:27:36 -05:00
|
|
|
#include "tools.hxx"
|
|
|
|
|
2006-05-31 03:49:45 -05:00
|
|
|
using namespace ::basebmp;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class BasicTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
public:
|
2006-06-28 10:50:20 -05:00
|
|
|
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 );
|
|
|
|
|
2006-07-11 05:39:41 -05:00
|
|
|
aTestColor.setGrey( 0x13 );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("setGrey()",
|
2006-06-28 10:50:20 -05:00
|
|
|
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 );
|
2006-07-12 09:09:45 -05:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("Palette existence",
|
|
|
|
pDevice->getPalette() );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Palette entry 0 is black",
|
|
|
|
(*pDevice->getPalette())[0] == Color(0) );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("Palette entry 1 is white",
|
|
|
|
(*pDevice->getPalette())[1] == Color(0xFFFFFFFF) );
|
2006-05-31 03:49:45 -05:00
|
|
|
}
|
|
|
|
|
2011-11-03 08:58:40 -05:00
|
|
|
void testClone()
|
|
|
|
{
|
|
|
|
const basegfx::B2ISize aSize(101,101);
|
|
|
|
basegfx::B2ISize aSize2(3,3);
|
|
|
|
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
|
|
|
|
true,
|
|
|
|
Format::ONE_BIT_MSB_PAL ));
|
|
|
|
|
|
|
|
BitmapDeviceSharedPtr pClone( cloneBitmapDevice(
|
|
|
|
aSize2,
|
|
|
|
pDevice ));
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("right size",
|
|
|
|
pClone->getSize() == aSize2 );
|
|
|
|
}
|
|
|
|
|
2006-05-31 03:49:45 -05:00
|
|
|
void testPixelFuncs()
|
|
|
|
{
|
|
|
|
// 1bpp
|
2006-06-30 05:05:21 -05:00
|
|
|
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);
|
|
|
|
|
2006-06-30 05:05:21 -05:00
|
|
|
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 );
|
|
|
|
|
2006-06-30 05:05:21 -05:00
|
|
|
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);
|
|
|
|
|
2006-07-12 16:47:21 -05:00
|
|
|
CPPUNIT_ASSERT_MESSAGE("raw pixel value #1",
|
|
|
|
pDevice->getBuffer()[0] == 0x80);
|
|
|
|
|
|
|
|
// 1bit LSB
|
|
|
|
{
|
|
|
|
pDevice = createBitmapDevice( aSize,
|
|
|
|
true,
|
|
|
|
Format::ONE_BIT_LSB_PAL );
|
|
|
|
|
|
|
|
pDevice->setPixel( aPt2, aCol, DrawMode_PAINT );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #4",
|
|
|
|
pDevice->getPixel(aPt2) == aCol);
|
|
|
|
|
|
|
|
const basegfx::B2IPoint aPt222(1,1);
|
|
|
|
pDevice->setPixel( aPt222, aCol, DrawMode_PAINT );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #5",
|
|
|
|
pDevice->getPixel(aPt222) == aCol);
|
|
|
|
|
|
|
|
pDevice->setPixel( aPt3, aCol, DrawMode_PAINT );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #6",
|
|
|
|
pDevice->getPixel(aPt3) == aCol);
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("raw pixel value #2",
|
|
|
|
pDevice->getBuffer()[0] == 0x01);
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("raw pixel value #3",
|
|
|
|
pDevice->getBuffer()[8] == 0x02);
|
|
|
|
}
|
|
|
|
|
2006-06-07 08:27:36 -05:00
|
|
|
// 8bit alpha
|
2006-05-31 03:49:45 -05:00
|
|
|
{
|
|
|
|
pDevice = createBitmapDevice( aSize,
|
|
|
|
true,
|
2006-07-11 05:39:41 -05:00
|
|
|
Format::EIGHT_BIT_GREY );
|
2006-05-31 03:49:45 -05:00
|
|
|
|
2006-06-07 08:27:36 -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);
|
|
|
|
|
2006-06-07 08:27:36 -05:00
|
|
|
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);
|
|
|
|
|
2006-06-07 08:27:36 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2006-07-06 04:02:07 -05:00
|
|
|
// 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 );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #7",
|
|
|
|
pDevice->getPixel(aPt) == aCol4);
|
|
|
|
|
|
|
|
const Color aCol5(0x00F0F0F0);
|
|
|
|
pDevice->setPixel( aPt2, aCol5, DrawMode_PAINT );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #8",
|
2006-07-11 05:39:41 -05:00
|
|
|
pDevice->getPixel(aPt2) != aCol7);
|
2006-07-06 04:02:07 -05:00
|
|
|
|
|
|
|
const Color aCol6(0x00FFFFFF);
|
|
|
|
pDevice->setPixel( aPt3, aCol6, DrawMode_PAINT );
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("get/setPixel roundtrip #9",
|
2006-07-11 05:39:41 -05:00
|
|
|
pDevice->getPixel(aPt3) == aCol6);
|
2006-07-06 04:02:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2006-07-13 06:03:26 -05:00
|
|
|
const Color aCol5(0x0F3F2F1F);
|
2006-07-06 04:02:07 -05:00
|
|
|
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-07-13 06:03:26 -05:00
|
|
|
|
|
|
|
CPPUNIT_ASSERT_MESSAGE("raw pixel value #4",
|
|
|
|
pDevice->getBuffer()[2] == 0x3F
|
|
|
|
&& pDevice->getBuffer()[1] == 0x2F
|
|
|
|
&& pDevice->getBuffer()[0] == 0x1F);
|
2006-07-06 04:02:07 -05:00
|
|
|
}
|
|
|
|
|
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 );
|
2006-07-06 04:02:07 -05:00
|
|
|
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 );
|
2006-07-06 04:02:07 -05:00
|
|
|
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 );
|
2006-07-06 04:02:07 -05:00
|
|
|
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);
|
2006-06-28 10:50:20 -05:00
|
|
|
CPPUNIT_TEST(colorTest);
|
2006-05-31 03:49:45 -05:00
|
|
|
CPPUNIT_TEST(testConstruction);
|
2011-11-03 08:58:40 -05:00
|
|
|
CPPUNIT_TEST(testClone);
|
2006-05-31 03:49:45 -05:00
|
|
|
CPPUNIT_TEST(testPixelFuncs);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
2009-12-11 07:29:59 -06:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(BasicTest);
|
2006-05-31 03:49:45 -05:00
|
|
|
}
|
|
|
|
|
2009-12-11 07:29:59 -06:00
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
2010-10-14 01:27:31 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|