1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include <sal/types.h>
21 #include <cppunit/TestAssert.h>
22 #include <cppunit/TestFixture.h>
23 #include <cppunit/extensions/HelperMacros.h>
24
25 #include <cppuhelper/compbase.hxx>
26 #include <cppuhelper/basemutex.hxx>
27 #include <comphelper/make_shared_from_uno.hxx>
28
29 #include <basegfx/matrix/b2dhommatrix.hxx>
30 #include <basegfx/range/b2drange.hxx>
31
32 #include <shape.hxx>
33 #include "tests.hxx"
34
35 namespace target = slideshow::internal;
36 using namespace ::com::sun::star;
37
38 // our test shape subject
39 typedef ::cppu::WeakComponentImplHelper< drawing::XShape > ShapeBase;
40 class ImplTestShape : public TestShape,
41 private cppu::BaseMutex,
42 public ShapeBase
43 {
44 typedef std::vector<std::pair<target::ViewLayerSharedPtr,bool> > ViewVector;
45 ViewVector maViewLayers;
46 const basegfx::B2DRange maRect;
47 const double mnPrio;
48 sal_Int32 mnAnimated;
49 mutable sal_Int32 mnNumUpdates;
50 mutable sal_Int32 mnNumRenders;
51
52 public:
ImplTestShape(const basegfx::B2DRange & rRect,double nPrio)53 ImplTestShape( const basegfx::B2DRange& rRect,
54 double nPrio ) :
55 ShapeBase( m_aMutex ),
56 maViewLayers(),
57 maRect( rRect ),
58 mnPrio( nPrio ),
59 mnAnimated(0),
60 mnNumUpdates(0),
61 mnNumRenders(0)
62 {}
63
64
65 private:
66 // TestShape
getViewLayers() const67 virtual std::vector<std::pair<target::ViewLayerSharedPtr,bool> > getViewLayers() const override
68 {
69 return maViewLayers;
70 }
getNumUpdates() const71 virtual sal_Int32 getNumUpdates() const override
72 {
73 return mnNumUpdates;
74 }
getNumRenders() const75 virtual sal_Int32 getNumRenders() const override
76 {
77 return mnNumRenders;
78 }
79
80 // XShape
getShapeType()81 virtual OUString SAL_CALL getShapeType( ) override
82 {
83 CPPUNIT_ASSERT_MESSAGE( "TestShape::getShapeType: unexpected method call", false );
84 return OUString();
85 }
86
getPosition()87 virtual awt::Point SAL_CALL getPosition( ) override
88 {
89 CPPUNIT_ASSERT_MESSAGE( "TestShape::getPosition: unexpected method call", false );
90 return awt::Point();
91 }
92
setPosition(const awt::Point &)93 virtual void SAL_CALL setPosition( const awt::Point& ) override
94 {
95 CPPUNIT_ASSERT_MESSAGE( "TestShape::setPosition: unexpected method call", false );
96 }
97
getSize()98 virtual awt::Size SAL_CALL getSize( ) override
99 {
100 CPPUNIT_ASSERT_MESSAGE( "TestShape::getSize: unexpected method call", false );
101 return awt::Size();
102 }
103
setSize(const awt::Size &)104 virtual void SAL_CALL setSize( const awt::Size& /*aSize*/ ) override
105 {
106 CPPUNIT_ASSERT_MESSAGE( "TestShape::setSize: unexpected method call", false );
107 }
108
109
110 // Shape
getXShape() const111 virtual uno::Reference< drawing::XShape > getXShape() const override
112 {
113 return uno::Reference< drawing::XShape >( const_cast<ImplTestShape*>(this) );
114 }
addViewLayer(const target::ViewLayerSharedPtr & rNewLayer,bool bRedrawLayer)115 virtual void addViewLayer( const target::ViewLayerSharedPtr& rNewLayer,
116 bool bRedrawLayer ) override
117 {
118 maViewLayers.push_back( std::make_pair(rNewLayer,bRedrawLayer) );
119 }
removeViewLayer(const target::ViewLayerSharedPtr & rNewLayer)120 virtual bool removeViewLayer( const target::ViewLayerSharedPtr& rNewLayer ) override
121 {
122 if( std::none_of(
123 maViewLayers.begin(),
124 maViewLayers.end(),
125 [&rNewLayer]
126 ( const ViewVector::value_type& cp )
127 { return cp.first == rNewLayer; } ) )
128 throw std::exception();
129
130 maViewLayers.erase(
131 std::remove_if(
132 maViewLayers.begin(),
133 maViewLayers.end(),
134 [&rNewLayer]
135 ( const ViewVector::value_type& cp )
136 { return cp.first == rNewLayer; } ) );
137 return true;
138 }
clearAllViewLayers()139 virtual void clearAllViewLayers() override
140 {
141 maViewLayers.clear();
142 }
143
update() const144 virtual bool update() const override
145 {
146 ++mnNumUpdates;
147 return true;
148 }
render() const149 virtual bool render() const override
150 {
151 ++mnNumRenders;
152 return true;
153 }
isContentChanged() const154 virtual bool isContentChanged() const override
155 {
156 return true;
157 }
getBounds() const158 virtual ::basegfx::B2DRectangle getBounds() const override
159 {
160 return maRect;
161 }
getDomBounds() const162 virtual ::basegfx::B2DRectangle getDomBounds() const override
163 {
164 return maRect;
165 }
getUpdateArea() const166 virtual ::basegfx::B2DRectangle getUpdateArea() const override
167 {
168 return maRect;
169 }
170
isVisible() const171 virtual bool isVisible() const override
172 {
173 return true;
174 }
getPriority() const175 virtual double getPriority() const override
176 {
177 return mnPrio;
178 }
isBackgroundDetached() const179 virtual bool isBackgroundDetached() const override
180 {
181 return mnAnimated != 0;
182 }
183
184 // AnimatableShape
enterAnimationMode()185 virtual void enterAnimationMode() override
186 {
187 ++mnAnimated;
188 }
189
leaveAnimationMode()190 virtual void leaveAnimationMode() override
191 {
192 --mnAnimated;
193 }
194 };
195
196
createTestShape(const basegfx::B2DRange & rRect,double nPrio)197 TestShapeSharedPtr createTestShape(const basegfx::B2DRange& rRect,
198 double nPrio)
199 {
200 return TestShapeSharedPtr(
201 comphelper::make_shared_from_UNO(
202 new ImplTestShape(rRect,nPrio)) );
203 }
204
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
206