build fix
[LibreOffice.git] / slideshow / test / testshape.cxx
blobbfa05fd00b44b4fb5a2ceb2f04542254b0053d3d
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"
34 #include "com/sun/star/presentation/XSlideShowView.hpp"
36 namespace target = slideshow::internal;
37 using namespace ::com::sun::star;
39 // our test shape subject
40 typedef ::cppu::WeakComponentImplHelper< drawing::XShape > ShapeBase;
41 class ImplTestShape : public TestShape,
42 private cppu::BaseMutex,
43 public ShapeBase
45 typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
46 ViewVector maViewLayers;
47 const basegfx::B2DRange maRect;
48 const double mnPrio;
49 sal_Int32 mnAnimated;
50 mutable sal_Int32 mnNumUpdates;
51 mutable sal_Int32 mnNumRenders;
53 public:
54 ImplTestShape( const basegfx::B2DRange& rRect,
55 double nPrio ) :
56 ShapeBase( m_aMutex ),
57 maViewLayers(),
58 maRect( rRect ),
59 mnPrio( nPrio ),
60 mnAnimated(0),
61 mnNumUpdates(0),
62 mnNumRenders(0)
66 private:
67 // TestShape
68 virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const
70 return maViewLayers;
72 virtual sal_Int32 getNumUpdates() const
74 return mnNumUpdates;
76 virtual sal_Int32 getNumRenders() const
78 return mnNumRenders;
81 // XShape
82 virtual OUString SAL_CALL getShapeType( ) throw (uno::RuntimeException)
84 CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
85 return OUString();
88 virtual awt::Point SAL_CALL getPosition( ) throw (uno::RuntimeException)
90 CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
91 return awt::Point();
94 virtual void SAL_CALL setPosition( const awt::Point& ) throw (uno::RuntimeException)
96 CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
99 virtual awt::Size SAL_CALL getSize( ) throw (uno::RuntimeException)
101 CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
102 return awt::Size();
105 virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) throw (beans::PropertyVetoException, uno::RuntimeException)
107 CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
111 // Shape
112 virtual uno::Reference< drawing::XShape > getXShape() const
114 return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
116 virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
117 bool bRedrawLayer )
119 maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
121 virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer )
123 if( std::none_of(
124 maViewLayers.begin(),
125 maViewLayers.end(),
126 [&rNewLayer]
127 ( const ViewVector::value_type& cp )
128 { return cp.first == rNewLayer; } ) )
129 throw std::exception();
131 maViewLayers.erase(
132 std::remove_if(
133 maViewLayers.begin(),
134 maViewLayers.end(),
135 [&rNewLayer]
136 ( const ViewVector::value_type& cp )
137 { return cp.first == rNewLayer; } ) );
138 return true;
140 virtual bool clearAllViewLayers()
142 maViewLayers.clear();
143 return true;
146 virtual bool update() const
148 ++mnNumUpdates;
149 return true;
151 virtual bool render() const
153 ++mnNumRenders;
154 return true;
156 virtual bool isContentChanged() const
158 return true;
160 virtual ::basegfx::B2DRectangle getBounds() const
162 return maRect;
164 virtual ::basegfx::B2DRectangle getDomBounds() const
166 return maRect;
168 virtual ::basegfx::B2DRectangle getUpdateArea() const
170 return maRect;
173 virtual bool isVisible() const
175 return true;
177 virtual double getPriority() const
179 return mnPrio;
181 virtual bool isBackgroundDetached() const
183 return mnAnimated != 0;
186 // AnimatableShape
187 virtual void enterAnimationMode()
189 ++mnAnimated;
192 virtual void leaveAnimationMode()
194 --mnAnimated;
199 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
200 double nPrio)
202 return TestShapeSharedPtr(
203 comphelper::make_shared_from_UNO(
204 new ImplTestShape(rRect,nPrio)) );
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */