xref: /aoo42x/main/basebmp/test/bmptest.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // autogenerated file with codegen.pl
29 
30 #include "preextstl.h"
31 #include "cppunit/TestAssert.h"
32 #include "cppunit/TestFixture.h"
33 #include "cppunit/extensions/HelperMacros.h"
34 #include "postextstl.h"
35 
36 #include <basegfx/vector/b2isize.hxx>
37 #include <basegfx/range/b2irange.hxx>
38 #include <basegfx/point/b2ipoint.hxx>
39 #include <basegfx/polygon/b2dpolygon.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <basegfx/polygon/b2dpolypolygon.hxx>
42 #include <basegfx/polygon/b2dpolypolygontools.hxx>
43 
44 #include <basebmp/color.hxx>
45 #include <basebmp/scanlineformats.hxx>
46 #include <basebmp/bitmapdevice.hxx>
47 #include <basebmp/debug.hxx>
48 #include "tools.hxx"
49 
50 #include <iostream>
51 #include <fstream>
52 
53 using namespace ::basebmp;
54 
55 namespace
56 {
57 /*
58         std::ofstream output("32bpp_test.dump");
59         debugDump( rDevice, output );
60         std::ofstream output2("32bpp_bmp.dump");
61         debugDump( rBmp, output2 );
62 */
63 
64 class BmpTest : public CppUnit::TestFixture
65 {
66 private:
67     BitmapDeviceSharedPtr mpDevice1bpp;
68     BitmapDeviceSharedPtr mpBmp1bpp;
69     BitmapDeviceSharedPtr mpDevice32bpp;
70     BitmapDeviceSharedPtr mpBmp32bpp;
71 
72     void implTestBmpBasics(const BitmapDeviceSharedPtr& rDevice,
73                            const BitmapDeviceSharedPtr& rBmp)
74     {
75         rDevice->clear(Color(0));
76         const Color aCol(0xFFFFFFFF);
77 
78         const basegfx::B2IRange aSourceRect(0,0,10,10);
79         const basegfx::B2IRange aDestLeftTop(0,0,4,4);
80         const basegfx::B2IRange aDestRightTop(6,0,10,4);
81         const basegfx::B2IRange aDestLeftBottom(0,6,4,10);
82         const basegfx::B2IRange aDestRightBottom(6,6,10,10);
83 
84         rDevice->drawBitmap(
85             rBmp,
86             aSourceRect,
87             aDestLeftTop,
88             DrawMode_PAINT );
89         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
90                                countPixel( rDevice, aCol ) == 8);
91 
92         rDevice->drawBitmap(
93             rBmp,
94             aSourceRect,
95             aDestRightTop,
96             DrawMode_PAINT );
97         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 16",
98                                countPixel( rDevice, aCol ) == 16);
99 
100         rDevice->drawBitmap(
101             rBmp,
102             aSourceRect,
103             aDestLeftBottom,
104             DrawMode_PAINT );
105         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 24",
106                                countPixel( rDevice, aCol ) == 24);
107 
108         rDevice->drawBitmap(
109             rBmp,
110             aSourceRect,
111             aDestRightBottom,
112             DrawMode_PAINT );
113         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 32",
114                                countPixel( rDevice, aCol ) == 32);
115     }
116 
117     void implTestBmpClip(const BitmapDeviceSharedPtr& rDevice,
118                          const BitmapDeviceSharedPtr& rBmp)
119     {
120         rDevice->clear(Color(0));
121         const Color aCol(0xFFFFFFFF);
122 
123         const basegfx::B2IRange aSourceRect(0,0,10,10);
124         const basegfx::B2IRange aDestLeftTop(-2,-2,2,2);
125         const basegfx::B2IRange aDestRightTop(8,-2,12,2);
126         const basegfx::B2IRange aDestLeftBottom(-2,8,2,12);
127         const basegfx::B2IRange aDestRightBottom(8,8,12,12);
128 
129         rDevice->drawBitmap(
130             rBmp,
131             aSourceRect,
132             aDestLeftTop,
133             DrawMode_PAINT );
134         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4",
135                                countPixel( rDevice, aCol ) == 4);
136 
137         rDevice->drawBitmap(
138             rBmp,
139             aSourceRect,
140             aDestLeftBottom,
141             DrawMode_PAINT );
142         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 4(c)",
143                                countPixel( rDevice, aCol ) == 4);
144 
145         rDevice->drawBitmap(
146             rBmp,
147             aSourceRect,
148             aDestRightBottom,
149             DrawMode_PAINT );
150         CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8",
151                                countPixel( rDevice, aCol ) == 8);
152     }
153 
154 public:
155     void setUp()
156     {
157         const basegfx::B2ISize aSize(10,10);
158         mpDevice1bpp = createBitmapDevice( aSize,
159                                            true,
160                                            Format::ONE_BIT_MSB_PAL );
161         mpDevice32bpp = createBitmapDevice( aSize,
162                                             true,
163                                             Format::THIRTYTWO_BIT_TC_MASK );
164 
165         mpBmp1bpp = createBitmapDevice( aSize,
166                                         true,
167                                         Format::ONE_BIT_MSB_PAL );
168         mpBmp32bpp = createBitmapDevice( aSize,
169                                          true,
170                                          Format::THIRTYTWO_BIT_TC_MASK );
171 
172         ::rtl::OUString aSvg = ::rtl::OUString::createFromAscii(
173             "m 0 0h5v10h5v-5h-10z" );
174 
175         basegfx::B2DPolyPolygon aPoly;
176         basegfx::tools::importFromSvgD( aPoly, aSvg );
177         const Color aCol(0xFFFFFFFF);
178         mpBmp1bpp->fillPolyPolygon(
179             aPoly,
180             aCol,
181             DrawMode_PAINT );
182         mpBmp32bpp->fillPolyPolygon(
183             aPoly,
184             aCol,
185             DrawMode_PAINT );
186     }
187 
188     void testBmpBasics()
189     {
190         implTestBmpBasics( mpDevice1bpp, mpBmp1bpp );
191         implTestBmpBasics( mpDevice32bpp, mpBmp32bpp );
192     }
193 
194     void testBmpClip()
195     {
196         implTestBmpClip( mpDevice1bpp, mpBmp1bpp );
197         implTestBmpClip( mpDevice32bpp, mpBmp32bpp );
198     }
199 
200     // Change the following lines only, if you add, remove or rename
201     // member functions of the current class,
202     // because these macros are need by auto register mechanism.
203 
204     CPPUNIT_TEST_SUITE(BmpTest);
205     CPPUNIT_TEST(testBmpBasics);
206     CPPUNIT_TEST(testBmpClip);
207     CPPUNIT_TEST_SUITE_END();
208 };
209 
210 // -----------------------------------------------------------------------------
211 CPPUNIT_TEST_SUITE_REGISTRATION(BmpTest);
212 }
213 
214 
215 // -----------------------------------------------------------------------------
216 
217 // this macro creates an empty function, which will called by the RegisterAllFunctions()
218 // to let the user the possibility to also register some functions by hand.
219 //NOADDITIONAL;
220 
221