1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 #include <cppuhelper/compbase1.hxx>
23 #include <cppuhelper/basemutex.hxx>
24 #include <comphelper/make_shared_from_uno.hxx>
25
26 #include <basegfx/matrix/b2dhommatrix.hxx>
27 #include <basegfx/range/b2drange.hxx>
28
29 #include "gtest/gtest.h"
30 #include "shape.hxx"
31 #include "tests.hxx"
32 #include "com/sun/star/presentation/XSlideShowView.hpp"
33
34 #include <boost/bind.hpp>
35
36 namespace target = slideshow::internal;
37 using namespace ::com::sun::star;
38
39 // our test shape subject
40 typedef ::cppu::WeakComponentImplHelper1< drawing::XShape > ShapeBase;
41 class ImplTestShape : public TestShape,
42 private cppu::BaseMutex,
43 public ShapeBase
44 {
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;
52
53 public:
ImplTestShape(const basegfx::B2DRange & rRect,double nPrio)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)
63 {}
64
65
66 private:
67 // TestShape
getViewLayers() const68 virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const
69 {
70 return maViewLayers;
71 }
getNumUpdates() const72 virtual sal_Int32 getNumUpdates() const
73 {
74 return mnNumUpdates;
75 }
getNumRenders() const76 virtual sal_Int32 getNumRenders() const
77 {
78 return mnNumRenders;
79 }
getAnimationCount() const80 virtual sal_Int32 getAnimationCount() const
81 {
82 return mnAnimated;
83 }
84
85
86 // XShape
getShapeType()87 virtual ::rtl::OUString SAL_CALL getShapeType( ) throw (uno::RuntimeException)
88 {
89 ADD_FAILURE() << "TestShape::getShapeType: unexpected method call";
90 return ::rtl::OUString();
91 }
92
getPosition()93 virtual awt::Point SAL_CALL getPosition( ) throw (uno::RuntimeException)
94 {
95 ADD_FAILURE() << "TestShape::getPosition: unexpected method call";
96 return awt::Point();
97 }
98
setPosition(const awt::Point &)99 virtual void SAL_CALL setPosition( const awt::Point& ) throw (uno::RuntimeException)
100 {
101 FAIL() << "TestShape::setPosition: unexpected method call";
102 }
103
getSize()104 virtual awt::Size SAL_CALL getSize( ) throw (uno::RuntimeException)
105 {
106 ADD_FAILURE() << "TestShape::getSize: unexpected method call";
107 return awt::Size();
108 }
109
setSize(const awt::Size &)110 virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) throw (beans::PropertyVetoException, uno::RuntimeException)
111 {
112 FAIL() << "TestShape::setSize: unexpected method call";
113 }
114
115
116 //////////////////////////////////////////////////////////////////////////
117
118
119 // Shape
getXShape() const120 virtual uno::Reference< drawing::XShape > getXShape() const
121 {
122 return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
123 }
addViewLayer(const target::ViewLayerSharedPtr & rNewLayer,bool bRedrawLayer)124 virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
125 bool bRedrawLayer )
126 {
127 maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
128 }
removeViewLayer(const target::ViewLayerSharedPtr & rNewLayer)129 virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer )
130 {
131 if( std::find_if(
132 maViewLayers.begin(),
133 maViewLayers.end(),
134 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
135 boost::cref( rNewLayer ),
136 boost::bind( std::select1st<ViewVector::value_type>(),
137 _1 ))) == maViewLayers.end() )
138 throw std::exception();
139
140 maViewLayers.erase(
141 std::remove_if(
142 maViewLayers.begin(),
143 maViewLayers.end(),
144 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(),
145 boost::cref( rNewLayer ),
146 boost::bind( std::select1st<ViewVector::value_type>(),
147 _1 ))));
148 return true;
149 }
clearAllViewLayers()150 virtual bool clearAllViewLayers()
151 {
152 maViewLayers.clear();
153 return true;
154 }
155
update() const156 virtual bool update() const
157 {
158 ++mnNumUpdates;
159 return true;
160 }
render() const161 virtual bool render() const
162 {
163 ++mnNumRenders;
164 return true;
165 }
isContentChanged() const166 virtual bool isContentChanged() const
167 {
168 return true;
169 }
getBounds() const170 virtual ::basegfx::B2DRectangle getBounds() const
171 {
172 return maRect;
173 }
getDomBounds() const174 virtual ::basegfx::B2DRectangle getDomBounds() const
175 {
176 return maRect;
177 }
getUpdateArea() const178 virtual ::basegfx::B2DRectangle getUpdateArea() const
179 {
180 return maRect;
181 }
182
isVisible() const183 virtual bool isVisible() const
184 {
185 return true;
186 }
getPriority() const187 virtual double getPriority() const
188 {
189 return mnPrio;
190 }
isBackgroundDetached() const191 virtual bool isBackgroundDetached() const
192 {
193 return mnAnimated != 0;
194 }
195
196 // AnimatableShape
enterAnimationMode()197 virtual void enterAnimationMode()
198 {
199 ++mnAnimated;
200 }
201
leaveAnimationMode()202 virtual void leaveAnimationMode()
203 {
204 --mnAnimated;
205 }
206 };
207
208
createTestShape(const basegfx::B2DRange & rRect,double nPrio)209 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
210 double nPrio)
211 {
212 return TestShapeSharedPtr(
213 comphelper::make_shared_from_UNO(
214 new ImplTestShape(rRect,nPrio)) );
215 }
216