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 23 24 #include <cppuhelper/compbase1.hxx> 25 #include <cppuhelper/basemutex.hxx> 26 #include <comphelper/make_shared_from_uno.hxx> 27 28 #include <basegfx/matrix/b2dhommatrix.hxx> 29 #include <basegfx/range/b2drange.hxx> 30 31 #include "gtest/gtest.h" 32 #include "shape.hxx" 33 #include "tests.hxx" 34 #include "com/sun/star/presentation/XSlideShowView.hpp" 35 36 #include <boost/bind.hpp> 37 38 namespace target = slideshow::internal; 39 using namespace ::com::sun::star; 40 41 // our test shape subject 42 typedef ::cppu::WeakComponentImplHelper1< drawing::XShape > ShapeBase; 43 class ImplTestShape : public TestShape, 44 private cppu::BaseMutex, 45 public ShapeBase 46 { 47 typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector; 48 ViewVector maViewLayers; 49 const basegfx::B2DRange maRect; 50 const double mnPrio; 51 sal_Int32 mnAnimated; 52 mutable sal_Int32 mnNumUpdates; 53 mutable sal_Int32 mnNumRenders; 54 55 public: 56 ImplTestShape( const basegfx::B2DRange& rRect, 57 double nPrio ) : 58 ShapeBase( m_aMutex ), 59 maViewLayers(), 60 maRect( rRect ), 61 mnPrio( nPrio ), 62 mnAnimated(0), 63 mnNumUpdates(0), 64 mnNumRenders(0) 65 {} 66 67 68 private: 69 // TestShape 70 virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const 71 { 72 return maViewLayers; 73 } 74 virtual sal_Int32 getNumUpdates() const 75 { 76 return mnNumUpdates; 77 } 78 virtual sal_Int32 getNumRenders() const 79 { 80 return mnNumRenders; 81 } 82 virtual sal_Int32 getAnimationCount() const 83 { 84 return mnAnimated; 85 } 86 87 88 // XShape 89 virtual ::rtl::OUString SAL_CALL getShapeType( ) throw (uno::RuntimeException) 90 { 91 ADD_FAILURE() << "TestShape::getShapeType: unexpected method call"; 92 return ::rtl::OUString(); 93 } 94 95 virtual awt::Point SAL_CALL getPosition( ) throw (uno::RuntimeException) 96 { 97 ADD_FAILURE() << "TestShape::getPosition: unexpected method call"; 98 return awt::Point(); 99 } 100 101 virtual void SAL_CALL setPosition( const awt::Point& ) throw (uno::RuntimeException) 102 { 103 FAIL() << "TestShape::setPosition: unexpected method call"; 104 } 105 106 virtual awt::Size SAL_CALL getSize( ) throw (uno::RuntimeException) 107 { 108 ADD_FAILURE() << "TestShape::getSize: unexpected method call"; 109 return awt::Size(); 110 } 111 112 virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) throw (beans::PropertyVetoException, uno::RuntimeException) 113 { 114 FAIL() << "TestShape::setSize: unexpected method call"; 115 } 116 117 118 ////////////////////////////////////////////////////////////////////////// 119 120 121 // Shape 122 virtual uno::Reference< drawing::XShape > getXShape() const 123 { 124 return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) ); 125 } 126 virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer, 127 bool bRedrawLayer ) 128 { 129 maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) ); 130 } 131 virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer ) 132 { 133 if( std::find_if( 134 maViewLayers.begin(), 135 maViewLayers.end(), 136 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(), 137 boost::cref( rNewLayer ), 138 boost::bind( std::select1st<ViewVector::value_type>(), 139 _1 ))) == maViewLayers.end() ) 140 throw std::exception(); 141 142 maViewLayers.erase( 143 std::remove_if( 144 maViewLayers.begin(), 145 maViewLayers.end(), 146 boost::bind( std::equal_to< target::ViewLayerSharedPtr >(), 147 boost::cref( rNewLayer ), 148 boost::bind( std::select1st<ViewVector::value_type>(), 149 _1 )))); 150 return true; 151 } 152 virtual bool clearAllViewLayers() 153 { 154 maViewLayers.clear(); 155 return true; 156 } 157 158 virtual bool update() const 159 { 160 ++mnNumUpdates; 161 return true; 162 } 163 virtual bool render() const 164 { 165 ++mnNumRenders; 166 return true; 167 } 168 virtual bool isContentChanged() const 169 { 170 return true; 171 } 172 virtual ::basegfx::B2DRectangle getBounds() const 173 { 174 return maRect; 175 } 176 virtual ::basegfx::B2DRectangle getDomBounds() const 177 { 178 return maRect; 179 } 180 virtual ::basegfx::B2DRectangle getUpdateArea() const 181 { 182 return maRect; 183 } 184 185 virtual bool isVisible() const 186 { 187 return true; 188 } 189 virtual double getPriority() const 190 { 191 return mnPrio; 192 } 193 virtual bool isBackgroundDetached() const 194 { 195 return mnAnimated != 0; 196 } 197 198 // AnimatableShape 199 virtual void enterAnimationMode() 200 { 201 ++mnAnimated; 202 } 203 204 virtual void leaveAnimationMode() 205 { 206 --mnAnimated; 207 } 208 }; 209 210 211 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect, 212 double nPrio) 213 { 214 return TestShapeSharedPtr( 215 comphelper::make_shared_from_UNO( 216 new ImplTestShape(rRect,nPrio)) ); 217 } 218