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