Bump version to 6.0-36
[LibreOffice.git] / slideshow / test / testshape.cxx
blobeda2fd53469b98b35bbd85fd7a058b31bdf0da8f
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <cppunit/TestAssert.h>
22 #include <cppunit/TestFixture.h>
23 #include <cppunit/extensions/HelperMacros.h>
25 #include <cppuhelper/compbase.hxx>
26 #include <cppuhelper/basemutex.hxx>
27 #include <comphelper/make_shared_from_uno.hxx>
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/range/b2drange.hxx>
32 #include "shape.hxx"
33 #include "tests.hxx"
35 namespace target = slideshow::internal;
36 using namespace ::com::sun::star;
38 // our test shape subject
39 typedef ::cppu::WeakComponentImplHelper< drawing::XShape > ShapeBase;
40 class ImplTestShape : public TestShape,
41 private cppu::BaseMutex,
42 public ShapeBase
44 typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
45 ViewVector maViewLayers;
46 const basegfx::B2DRange maRect;
47 const double mnPrio;
48 sal_Int32 mnAnimated;
49 mutable sal_Int32 mnNumUpdates;
50 mutable sal_Int32 mnNumRenders;
52 public:
53 ImplTestShape( const basegfx::B2DRange& rRect,
54 double nPrio ) :
55 ShapeBase( m_aMutex ),
56 maViewLayers(),
57 maRect( rRect ),
58 mnPrio( nPrio ),
59 mnAnimated(0),
60 mnNumUpdates(0),
61 mnNumRenders(0)
65 private:
66 // TestShape
67 virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const
69 return maViewLayers;
71 virtual sal_Int32 getNumUpdates() const
73 return mnNumUpdates;
75 virtual sal_Int32 getNumRenders() const
77 return mnNumRenders;
80 // XShape
81 virtual OUString SAL_CALL getShapeType( ) throw (uno::RuntimeException)
83 CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
84 return OUString();
87 virtual awt::Point SAL_CALL getPosition( ) throw (uno::RuntimeException)
89 CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
90 return awt::Point();
93 virtual void SAL_CALL setPosition( const awt::Point& ) throw (uno::RuntimeException)
95 CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
98 virtual awt::Size SAL_CALL getSize( ) throw (uno::RuntimeException)
100 CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
101 return awt::Size();
104 virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) throw (beans::PropertyVetoException, uno::RuntimeException)
106 CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
110 // Shape
111 virtual uno::Reference< drawing::XShape > getXShape() const
113 return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
115 virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
116 bool bRedrawLayer )
118 maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
120 virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer )
122 if( std::none_of(
123 maViewLayers.begin(),
124 maViewLayers.end(),
125 [&rNewLayer]
126 ( const ViewVector::value_type& cp )
127 { return cp.first == rNewLayer; } ) )
128 throw std::exception();
130 maViewLayers.erase(
131 std::remove_if(
132 maViewLayers.begin(),
133 maViewLayers.end(),
134 [&rNewLayer]
135 ( const ViewVector::value_type& cp )
136 { return cp.first == rNewLayer; } ) );
137 return true;
139 virtual bool clearAllViewLayers()
141 maViewLayers.clear();
142 return true;
145 virtual bool update() const
147 ++mnNumUpdates;
148 return true;
150 virtual bool render() const
152 ++mnNumRenders;
153 return true;
155 virtual bool isContentChanged() const
157 return true;
159 virtual ::basegfx::B2DRectangle getBounds() const
161 return maRect;
163 virtual ::basegfx::B2DRectangle getDomBounds() const
165 return maRect;
167 virtual ::basegfx::B2DRectangle getUpdateArea() const
169 return maRect;
172 virtual bool isVisible() const
174 return true;
176 virtual double getPriority() const
178 return mnPrio;
180 virtual bool isBackgroundDetached() const
182 return mnAnimated != 0;
185 // AnimatableShape
186 virtual void enterAnimationMode()
188 ++mnAnimated;
191 virtual void leaveAnimationMode()
193 --mnAnimated;
198 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
199 double nPrio)
201 return TestShapeSharedPtr(
202 comphelper::make_shared_from_UNO(
203 new ImplTestShape(rRect,nPrio)) );
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */