Branch libreoffice-5-0-4
[LibreOffice.git] / cppcanvas / qa / unit / test.cxx
blob6b909e058a448108392d5c40b0bda714c5eedf46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <boost/scoped_ptr.hpp>
13 #include <test/bootstrapfixture.hxx>
15 #include <osl/file.hxx>
16 #include <osl/process.h>
17 #include <vcl/svapp.hxx>
18 #include <vcl/wrkwin.hxx>
19 #include <vcl/canvastools.hxx>
21 #include <comphelper/processfactory.hxx>
22 #include <com/sun/star/lang/XInitialization.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/rendering/XBitmap.hpp>
26 #include <com/sun/star/rendering/XCanvas.hpp>
27 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
29 using namespace ::com::sun::star;
31 class CanvasTest : public test::BootstrapFixture
33 public:
34 CanvasTest() : BootstrapFixture(true, false) {}
36 void testComposite();
38 CPPUNIT_TEST_SUITE(CanvasTest);
39 CPPUNIT_TEST(testComposite);
40 CPPUNIT_TEST_SUITE_END();
43 void CanvasTest::testComposite()
45 #ifdef LINUX
46 VclPtrInstance<WorkWindow> pWin( nullptr, WB_STDWORK );
48 uno::Reference<rendering::XCanvas> xCanvas = pWin->GetCanvas ();
49 if( !xCanvas.is() )
50 return; // can't get a canvas working at all - truly headless ?
52 // a huge canvas ...
53 Size aSize (1, 1);
54 uno::Reference<rendering::XBitmap> xBitmap;
55 xBitmap = xCanvas->getDevice ()->createCompatibleAlphaBitmap(
56 vcl::unotools::integerSize2DFromSize( aSize ) );
57 CPPUNIT_ASSERT( xBitmap.is() );
59 uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( xBitmap, uno::UNO_QUERY );
60 CPPUNIT_ASSERT( xBitmapCanvas.is() );
62 BitmapEx aBitmapEx;
64 // clear the canvas and basic sanity check ...
65 xBitmapCanvas->clear();
66 CPPUNIT_ASSERT( aBitmapEx.Create( xBitmapCanvas, aSize ) );
67 CPPUNIT_ASSERT( aBitmapEx.IsAlpha() );
68 CPPUNIT_ASSERT( aBitmapEx.GetAlpha() );
72 // render something
73 rendering::RenderState aDefaultState;
74 uno::Sequence< double > aRedTransparent( 4 );
75 aRedTransparent[0] = 1.0; // R
76 aRedTransparent[1] = 0.0; // G
77 aRedTransparent[2] = 0.0; // B
78 aRedTransparent[3] = 0.5; // A
79 aDefaultState.DeviceColor = aRedTransparent;
80 #if 0
81 // words fail me to describe the sheer beauty of allocating an UNO
82 // object to represent a polygon, and manually handling the ViewState
83 // and there being no public helper for this - to render ... a rectangle.
84 XCachedPrimitive fillPolyPolygon( [in] XPolyPolygon2D xPolyPolygon, [in] ViewState aViewState, [in] RenderState aRenderState )
85 #endif
88 #endif
91 CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);
93 CPPUNIT_PLUGIN_IMPLEMENT();
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */