update dev300-m58
[ooovba.git] / basebmp / test / bmptest.cxx
bloba70288d70b561063483d874f453ce9b035bba97e
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: bmptest.cxx,v $
10 * $Revision: 1.2 $
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 BmpTest : public CppUnit::TestFixture
65 private:
66 BitmapDeviceSharedPtr mpDevice1bpp;
67 BitmapDeviceSharedPtr mpBmp1bpp;
68 BitmapDeviceSharedPtr mpDevice32bpp;
69 BitmapDeviceSharedPtr mpBmp32bpp;
71 void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
72 const BitmapDeviceSharedPtr& rBmp)
74 rDevice->clear(Color(0));
75 const Color aCol(0xFFFFFFFF);
77 const basegfx::B2IRange aSourceRect(0,0,10,10);
78 const basegfx::B2IRange aDestLeftTop(0,0,4,4);
79 const basegfx::B2IRange aDestRightTop(6,0,10,4);
80 const basegfx::B2IRange aDestLeftBottom(0,6,4,10);
81 const basegfx::B2IRange aDestRightBottom(6,6,10,10);
83 rDevice->drawBitmap(
84 rBmp,
85 aSourceRect,
86 aDestLeftTop,
87 DrawMode_PAINT );
88 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
89 countPixel( rDevice, aCol ) == 8);
91 rDevice->drawBitmap(
92 rBmp,
93 aSourceRect,
94 aDestRightTop,
95 DrawMode_PAINT );
96 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
97 countPixel( rDevice, aCol ) == 16);
99 rDevice->drawBitmap(
100 rBmp,
101 aSourceRect,
102 aDestLeftBottom,
103 DrawMode_PAINT );
104 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
105 countPixel( rDevice, aCol ) == 24);
107 rDevice->drawBitmap(
108 rBmp,
109 aSourceRect,
110 aDestRightBottom,
111 DrawMode_PAINT );
112 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
113 countPixel( rDevice, aCol ) == 32);
116 void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
117 const BitmapDeviceSharedPtr& rBmp)
119 rDevice->clear(Color(0));
120 const Color aCol(0xFFFFFFFF);
122 const basegfx::B2IRange aSourceRect(0,0,10,10);
123 const basegfx::B2IRange aDestLeftTop(-2,-2,2,2);
124 const basegfx::B2IRange aDestRightTop(8,-2,12,2);
125 const basegfx::B2IRange aDestLeftBottom(-2,8,2,12);
126 const basegfx::B2IRange aDestRightBottom(8,8,12,12);
128 rDevice->drawBitmap(
129 rBmp,
130 aSourceRect,
131 aDestLeftTop,
132 DrawMode_PAINT );
133 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
134 countPixel( rDevice, aCol ) == 4);
136 rDevice->drawBitmap(
137 rBmp,
138 aSourceRect,
139 aDestLeftBottom,
140 DrawMode_PAINT );
141 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
142 countPixel( rDevice, aCol ) == 4);
144 rDevice->drawBitmap(
145 rBmp,
146 aSourceRect,
147 aDestRightBottom,
148 DrawMode_PAINT );
149 CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
150 countPixel( rDevice, aCol ) == 8);
153 public:
154 void setUp()
156 const basegfx::B2ISize aSize(10,10);
157 mpDevice1bpp = createBitmapDevice( aSize,
158 true,
159 Format::ONE_BIT_MSB_PAL );
160 mpDevice32bpp = createBitmapDevice( aSize,
161 true,
162 Format::THIRTYTWO_BIT_TC_MASK );
164 mpBmp1bpp = createBitmapDevice( aSize,
165 true,
166 Format::ONE_BIT_MSB_PAL );
167 mpBmp32bpp = createBitmapDevice( aSize,
168 true,
169 Format::THIRTYTWO_BIT_TC_MASK );
171 ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
172 "m 0 0h5v10h5v-5h-10z" );
174 basegfx::B2DPolyPolygon aPoly;
175 basegfx::tools::importFromSvgD( aPoly, aSvg );
176 const Color aCol(0xFFFFFFFF);
177 mpBmp1bpp->fillPolyPolygon(
178 aPoly,
179 aCol,
180 DrawMode_PAINT );
181 mpBmp32bpp->fillPolyPolygon(
182 aPoly,
183 aCol,
184 DrawMode_PAINT );
187 void testBmpBasics()
189 implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
190 implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
193 void testBmpClip()
195 implTestBmpClip( mpDevice1bpp, mpBmp1bpp );
196 implTestBmpClip( mpDevice32bpp, mpBmp32bpp );
199 // Change the following lines only, if you add, remove or rename
200 // member functions of the current class,
201 // because these macros are need by auto register mechanism.
203 CPPUNIT_TEST_SUITE(BmpTest);
204 CPPUNIT_TEST(testBmpBasics);
205 CPPUNIT_TEST(testBmpClip);
206 CPPUNIT_TEST_SUITE_END();
209 // -----------------------------------------------------------------------------
210 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(BmpTest, "BmpTest");
214 // -----------------------------------------------------------------------------
216 // this macro creates an empty function, which will called by the RegisterAllFunctions()
217 // to let the user the possibility to also register some functions by hand.
218 //NOADDITIONAL;