Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / cppcanvas / qa / unit / test.cxx
blobaf652a3cf727a41b672df8b1a9640b92b80cf231
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 <test/bootstrapfixture.hxx>
12 #include <osl/file.hxx>
13 #include <osl/process.h>
14 #include <vcl/svapp.hxx>
15 #include <vcl/wrkwin.hxx>
16 #include <vcl/canvastools.hxx>
18 #include <comphelper/processfactory.hxx>
19 #include <com/sun/star/lang/XInitialization.hpp>
20 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/rendering/XBitmap.hpp>
23 #include <com/sun/star/rendering/XCanvas.hpp>
24 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
26 using namespace ::com::sun::star;
28 class CanvasTest : public test::BootstrapFixture
30 public:
31 CanvasTest() : BootstrapFixture(true, false) {}
33 void testComposite();
35 CPPUNIT_TEST_SUITE(CanvasTest);
36 CPPUNIT_TEST(testComposite);
37 CPPUNIT_TEST_SUITE_END();
40 void CanvasTest::testComposite()
42 #ifdef LINUX
43 Window* pWin = new WorkWindow( (Window *)NULL );
44 CPPUNIT_ASSERT( pWin != NULL );
46 uno::Reference<rendering::XCanvas> xCanvas = pWin->GetCanvas ();
47 if( !xCanvas.is() )
48 return; // can't get a canvas working at all - truly headless ?
50 // a huge canvas ...
51 Size aSize (1, 1);
52 uno::Reference<rendering::XBitmap> xBitmap;
53 xBitmap = xCanvas->getDevice ()->createCompatibleAlphaBitmap(
54 vcl::unotools::integerSize2DFromSize( aSize ) );
55 CPPUNIT_ASSERT( xBitmap.is() );
57 uno::Reference< rendering::XBitmapCanvas > xBitmapCanvas( xBitmap, uno::UNO_QUERY );
58 CPPUNIT_ASSERT( xBitmapCanvas.is() );
60 BitmapEx aBitmapEx;
62 // clear the canvas and basic sanity check ...
63 xBitmapCanvas->clear();
64 CPPUNIT_ASSERT( aBitmapEx.Create( xBitmapCanvas, aSize ) );
65 CPPUNIT_ASSERT( aBitmapEx.IsAlpha() );
66 CPPUNIT_ASSERT( aBitmapEx.GetAlpha() );
70 // render something
71 rendering::RenderState aDefaultState;
72 uno::Sequence< double > aRedTransparent( 4 );
73 aRedTransparent[0] = 1.0; // R
74 aRedTransparent[1] = 0.0; // G
75 aRedTransparent[2] = 0.0; // B
76 aRedTransparent[3] = 0.5; // A
77 aDefaultState.DeviceColor = aRedTransparent;
78 #if 0
79 // words fail me to describe the sheer beauty of allocating an UNO
80 // object to represent a polygon, and manually handling the ViewState
81 // and there being no public helper for this - to render ... a rectangle.
82 XCachedPrimitive fillPolyPolygon( [in] XPolyPolygon2D xPolyPolygon, [in] ViewState aViewState, [in] RenderState aRenderState )
83 #endif
86 #endif
89 CPPUNIT_TEST_SUITE_REGISTRATION(CanvasTest);
91 CPPUNIT_PLUGIN_IMPLEMENT();
93 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */