update dev300-m58
[ooovba.git] / basebmp / test / masktest.cxx
bloba938b3f181a6ae45b9f40ca55bd636beb903e460
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: masktest.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // autogenerated file with codegen.pl
33 #include <cppunit/simpleheader.hxx>
35 #include <basegfx/vector/b2isize.hxx>
36 #include <basegfx/range/b2irange.hxx>
37 #include <basegfx/point/b2ipoint.hxx>
38 #include <basegfx/polygon/b2dpolygon.hxx>
39 #include <basegfx/polygon/b2dpolygontools.hxx>
40 #include <basegfx/polygon/b2dpolypolygon.hxx>
41 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 #include <basebmp/color.hxx>
44 #include <basebmp/scanlineformats.hxx>
45 #include <basebmp/bitmapdevice.hxx>
46 #include <basebmp/debug.hxx>
47 #include "tools.hxx"
49 #include <iostream>
50 #include <fstream>
52 using namespace ::basebmp;
54 namespace
57 std::ofstream output("32bpp_test.dump");
58 debugDump( rDevice, output );
59 std::ofstream output2("32bpp_bmp.dump");
60 debugDump( rBmp, output2 );
63 class MaskTest : public CppUnit::TestFixture
65 private:
66 BitmapDeviceSharedPtr mpDevice1bpp;
67 BitmapDeviceSharedPtr mpDevice32bpp;
68 BitmapDeviceSharedPtr mpMask;
70 void implTestMaskBasics(const BitmapDeviceSharedPtr& rDevice,
71 const BitmapDeviceSharedPtr& rBmp)
73 const Color aCol(0);
74 const Color aCol2(0xF0F0F0F0);
76 const basegfx::B2IRange aSourceRect(0,0,10,10);
77 const basegfx::B2IPoint aDestLeftTop(0,0);
78 const basegfx::B2IPoint aDestRightTop(5,0);
79 const basegfx::B2IPoint aDestLeftBottom(0,5);
80 const basegfx::B2IPoint aDestRightBottom(5,5);
82 rDevice->clear(aCol);
83 rDevice->setPixel(
84 basegfx::B2IPoint(1,1),
85 aCol2,
86 DrawMode_PAINT);
87 rDevice->drawMaskedColor(
88 aCol2,
89 rBmp,
90 aSourceRect,
91 aDestLeftTop );
92 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 50",
93 countPixel( rDevice, aCol ) == 100-50);
95 rDevice->clear(aCol);
96 rDevice->drawMaskedColor(
97 aCol2,
98 rBmp,
99 aSourceRect,
100 aDestRightTop );
101 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25",
102 countPixel( rDevice, aCol ) == 100-25);
104 rDevice->clear(aCol);
105 rDevice->drawMaskedColor(
106 aCol2,
107 rBmp,
108 aSourceRect,
109 aDestLeftBottom );
110 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(b)",
111 countPixel( rDevice, aCol ) == 100-25);
113 rDevice->clear(aCol);
114 rDevice->drawMaskedColor(
115 aCol2,
116 rBmp,
117 aSourceRect,
118 aDestRightBottom );
119 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 25(c)",
120 countPixel( rDevice, aCol ) == 100-25);
123 public:
124 void setUp()
126 const basegfx::B2ISize aSize(10,10);
127 mpDevice1bpp = createBitmapDevice( aSize,
128 true,
129 Format::ONE_BIT_MSB_PAL );
130 mpDevice32bpp = createBitmapDevice( aSize,
131 true,
132 Format::THIRTYTWO_BIT_TC_MASK );
134 mpMask = createBitmapDevice( aSize,
135 true,
136 Format::EIGHT_BIT_GREY );
138 ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
139 "m 0 0h5v10h5v-5h-10z" );
141 basegfx::B2DPolyPolygon aPoly;
142 basegfx::tools::importFromSvgD( aPoly, aSvg );
143 const Color aCol(0xFF);
144 mpMask->fillPolyPolygon(
145 aPoly,
146 aCol,
147 DrawMode_PAINT );
150 void testMaskBasics()
152 implTestMaskBasics( mpDevice32bpp, mpMask );
153 implTestMaskBasics( mpDevice1bpp, mpMask );
156 void testMaskClip()
160 // Change the following lines only, if you add, remove or rename
161 // member functions of the current class,
162 // because these macros are need by auto register mechanism.
164 CPPUNIT_TEST_SUITE(MaskTest);
165 CPPUNIT_TEST(testMaskBasics);
166 CPPUNIT_TEST(testMaskClip);
167 CPPUNIT_TEST_SUITE_END();
170 // -----------------------------------------------------------------------------
171 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MaskTest, "MaskTest");
175 // -----------------------------------------------------------------------------
177 // this macro creates an empty function, which will called by the RegisterAllFunctions()
178 // to let the user the possibility to also register some functions by hand.
179 //NOADDITIONAL;