Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / slideshow / test / testshape.cxx
blobdb7031070ba85bd4ed36f71b804b44a079475ebb
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>
23 #include <cppuhelper/compbase.hxx>
24 #include <cppuhelper/basemutex.hxx>
25 #include <comphelper/make_shared_from_uno.hxx>
27 #include <basegfx/range/b2drange.hxx>
29 #include "tests.hxx"
31 namespace target = slideshow::internal;
32 using namespace ::com::sun::star;
34 // our test shape subject
35 typedef ::cppu::WeakComponentImplHelper< drawing::XShape > ShapeBase;
37 namespace {
39 class ImplTestShape : public TestShape,
40 private cppu::BaseMutex,
41 public ShapeBase
43 typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
44 ViewVector maViewLayers;
45 const basegfx::B2DRange maRect;
46 const double mnPrio;
47 sal_Int32 mnAnimated;
48 mutable sal_Int32 mnNumUpdates;
49 mutable sal_Int32 mnNumRenders;
51 public:
52 ImplTestShape( const basegfx::B2DRange& rRect,
53 double nPrio ) :
54 ShapeBase( m_aMutex ),
55 maViewLayers(),
56 maRect( rRect ),
57 mnPrio( nPrio ),
58 mnAnimated(0),
59 mnNumUpdates(0),
60 mnNumRenders(0)
64 private:
65 // TestShape
66 virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const override
68 return maViewLayers;
70 virtual sal_Int32 getNumUpdates() const override
72 return mnNumUpdates;
74 virtual sal_Int32 getNumRenders() const override
76 return mnNumRenders;
79 // XShape
80 virtual OUString SAL_CALL getShapeType( ) override
82 CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
83 return OUString();
86 virtual awt::Point SAL_CALL getPosition( ) override
88 CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
89 return awt::Point();
92 virtual void SAL_CALL setPosition( const awt::Point& ) override
94 CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
97 virtual awt::Size SAL_CALL getSize( ) override
99 CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
100 return awt::Size();
103 virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) override
105 CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
109 // Shape
110 virtual uno::Reference< drawing::XShape > getXShape() const override
112 return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
114 virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
115 bool bRedrawLayer ) override
117 maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
119 virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer ) override
121 if( std::none_of(
122 maViewLayers.begin(),
123 maViewLayers.end(),
124 [&rNewLayer]
125 ( const ViewVector::value_type& cp )
126 { return cp.first == rNewLayer; } ) )
127 throw std::exception();
129 maViewLayers.erase(
130 std::remove_if(
131 maViewLayers.begin(),
132 maViewLayers.end(),
133 [&rNewLayer]
134 ( const ViewVector::value_type& cp )
135 { return cp.first == rNewLayer; } ) );
136 return true;
138 virtual void clearAllViewLayers() override
140 maViewLayers.clear();
143 virtual bool update() const override
145 ++mnNumUpdates;
146 return true;
148 virtual bool render() const override
150 ++mnNumRenders;
151 return true;
153 virtual bool isContentChanged() const override
155 return true;
157 virtual ::basegfx::B2DRectangle getBounds() const override
159 return maRect;
161 virtual ::basegfx::B2DRectangle getDomBounds() const override
163 return maRect;
165 virtual ::basegfx::B2DRectangle getUpdateArea() const override
167 return maRect;
170 virtual bool isVisible() const override
172 return true;
174 virtual double getPriority() const override
176 return mnPrio;
178 virtual bool isBackgroundDetached() const override
180 return mnAnimated != 0;
183 // AnimatableShape
184 virtual void enterAnimationMode() override
186 ++mnAnimated;
189 virtual void leaveAnimationMode() override
191 --mnAnimated;
197 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
198 double nPrio)
200 return TestShapeSharedPtr(
201 comphelper::make_shared_from_UNO(
202 new ImplTestShape(rRect,nPrio)) );
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */