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 <comphelper/broadcasthelper.hxx>
24
25 #include <basegfx/matrix/b2dhommatrix.hxx>
26 #include <basegfx/range/b2drectangle.hxx>
27 #include <cppcanvas/spritecanvas.hxx>
28
29 #include "view.hxx"
30 #include "unoview.hxx"
31 #include "unoviewcontainer.hxx"
32 #include "shape.hxx"
33 #include "tests.hxx"
34 #include "../engine/slide/layermanager.hxx"
35 #include "../engine/slide/layer.hxx"
36 #include "gtest/gtest.h"
37 #include "com/sun/star/presentation/XSlideShowView.hpp"
38
39 namespace target = slideshow::internal;
40 using namespace ::com::sun::star;
41
42 // FIXME:
43 #define RUN_OLD_FAILING_TESTS 0
44
45 namespace
46 {
47
48 class LayerManagerTest : public ::testing::Test
49 {
50 protected:
51 target::UnoViewContainer maViews;
52 target::LayerManagerSharedPtr mpLayerManager;
53 TestViewSharedPtr mpTestView;
54 TestShapeSharedPtr mpTestShape;
55
56 public:
SetUp()57 virtual void SetUp()
58 {
59 mpTestShape = createTestShape(
60 basegfx::B2DRange(0.0,0.0,10.0,10.0),
61 1.0);
62 mpTestView = createTestView();
63 maViews.addView( mpTestView );
64
65 mpLayerManager.reset(
66 new target::LayerManager(
67 maViews,
68 basegfx::B2DRange(0.0,0.0,100.0,100.0),
69 false ));
70 }
71
TearDown()72 virtual void TearDown()
73 {
74 mpLayerManager.reset();
75 maViews.dispose();
76 }
77 }; // class LayerManagerTest
78
79
TEST_F(LayerManagerTest,testLayer)80 TEST_F(LayerManagerTest, testLayer)
81 {
82 target::LayerSharedPtr pBgLayer(
83 target::Layer::createBackgroundLayer( basegfx::B2DRange(0,0,100,100) ) );
84 pBgLayer->addView( mpTestView );
85
86 target::LayerSharedPtr pFgLayer(
87 target::Layer::createLayer( basegfx::B2DRange(0,0,100,100) ) );
88 pFgLayer->addView( mpTestView );
89
90 ASSERT_TRUE( pBgLayer->isBackgroundLayer() ) << "BG layer must confess that!";
91 ASSERT_TRUE( !pFgLayer->isBackgroundLayer() ) << "FG layer lies!";
92
93 ASSERT_TRUE( !pBgLayer->isUpdatePending() ) << "BG layer must not have pending updates!";
94 pBgLayer->addUpdateRange( basegfx::B2DRange(0,0,10,10) );
95 ASSERT_TRUE( pBgLayer->isUpdatePending() ) << "BG layer must have pending updates!";
96
97 TestShapeSharedPtr pTestShape = createTestShape(
98 basegfx::B2DRange(0.0,0.0,1000.0,1000.0),
99 1.0);
100 pBgLayer->updateBounds( pTestShape );
101 ASSERT_TRUE( !pBgLayer->commitBounds() ) << "BG layer must not resize!";
102
103 TestShapeSharedPtr pTestShape2 = createTestShape(
104 basegfx::B2DRange(0.0,0.0,1.0,1.0),
105 1.0);
106 pFgLayer->updateBounds( pTestShape2 );
107 ASSERT_TRUE( pFgLayer->commitBounds() ) << "FG layer must resize!";
108 }
109
TEST_F(LayerManagerTest,testBasics)110 TEST_F(LayerManagerTest, testBasics)
111 {
112 mpLayerManager->activate( false );
113
114 ASSERT_TRUE( mpTestShape->getViewLayers().empty() ) << "Un-added shape must have zero view layers";
115 mpLayerManager->addShape(mpTestShape);
116 ASSERT_TRUE( mpLayerManager->isUpdatePending() ) << "Adding a shape requires a LayerManager update";
117
118 // update does the delayed viewAdded call to the shape
119 ASSERT_TRUE( mpLayerManager->update() ) << "Update failed on LayerManager";
120 ASSERT_TRUE( mpTestShape->getViewLayers().size() == 1 ) << "Added shape must have one view layer";
121 ASSERT_TRUE( mpTestShape->getNumRenders() ) << "Shape must been rendered";
122 ASSERT_TRUE( !mpTestShape->getNumUpdates() ) << "Shape must not been updated";
123
124 // test second view, check whether shape gets additional view
125 TestViewSharedPtr pTestView( createTestView() );
126 ASSERT_TRUE( maViews.addView( pTestView ) ) << "Adding second View failed";
127 ASSERT_TRUE( maViews.end() - maViews.begin() == 2 ) << "View container must have two views";
128 mpLayerManager->viewAdded(pTestView);
129 ASSERT_TRUE( mpTestShape->getViewLayers().size() == 2 ) << "Added shape must have two view layers";
130
131 ASSERT_TRUE( maViews.removeView( pTestView ) ) << "Removing second View failed";
132 mpLayerManager->viewRemoved(pTestView);
133 ASSERT_TRUE( mpTestShape->getViewLayers().size() == 1 ) << "Added shape must have one view layer";
134
135 mpLayerManager->deactivate();
136 }
137
TEST_F(LayerManagerTest,testShapeOrdering)138 TEST_F(LayerManagerTest, testShapeOrdering)
139 {
140 TestShapeSharedPtr pShape2( createTestShape(
141 basegfx::B2DRange(0.0,0.0,10.0,10.0),
142 2.0));
143 TestShapeSharedPtr pShape3( createTestShape(
144 basegfx::B2DRange(0.0,0.0,10.0,10.0),
145 3.0));
146 TestShapeSharedPtr pShape4( createTestShape(
147 basegfx::B2DRange(0.0,0.0,10.0,10.0),
148 4.0));
149
150 mpLayerManager->addShape(mpTestShape);
151 mpLayerManager->addShape(pShape2);
152 mpLayerManager->addShape(pShape3);
153 mpLayerManager->addShape(pShape4);
154
155 mpLayerManager->activate( false );
156
157 // update does the delayed viewAdded call to the shape
158 ASSERT_TRUE( mpLayerManager->update() ) << "Update failed on LayerManager";
159 ASSERT_TRUE( mpTestView->getViewLayers().empty() ) << "View must have background layer only";
160
161 // LayerManager must now generate one extra view layer
162 mpLayerManager->enterAnimationMode(pShape2);
163 ASSERT_TRUE( mpLayerManager->isUpdatePending() ) << "No update pending on LayerManager";
164 ASSERT_TRUE( mpLayerManager->update() ) << "Update failed on LayerManager";
165 ASSERT_TRUE( mpTestView->getViewLayers().size() == 1 ) << "View must have one extra layer only";
166 ASSERT_TRUE( mpTestView->getViewLayers().at(0)->getBounds() ==
167 basegfx::B2DRange(0.0,0.0,10.0,10.0) ) << "View layer must have 10x10 size";
168
169 // LayerManager must now remove the extra view layer
170 mpLayerManager->leaveAnimationMode(pShape2);
171 ASSERT_TRUE( mpLayerManager->isUpdatePending() ) << "No update pending on LayerManager";
172 ASSERT_TRUE( mpLayerManager->update() ) << "Update failed on LayerManager #2";
173 ASSERT_TRUE( mpTestShape->getViewLayers().at(0).first == mpTestView ) << "Shape 1 must be on background layer";
174 ASSERT_TRUE( pShape2->getViewLayers().at(0).first == mpTestView ) << "Shape 2 must be on background layer";
175 ASSERT_TRUE( pShape3->getViewLayers().size() == 1 ) << "Shape 3 must have one layer";
176 ASSERT_TRUE( pShape3->getViewLayers().at(0).first == mpTestView ) << "Shape 3 must be on background layer";
177 ASSERT_TRUE( pShape4->getViewLayers().at(0).first == mpTestView ) << "Shape 4 must be on background layer";
178
179 // checking deactivation (all layers except background layer
180 // must vanish)
181 mpLayerManager->enterAnimationMode(pShape3);
182 ASSERT_TRUE( mpLayerManager->isUpdatePending() ) << "No update pending on LayerManager";
183 ASSERT_TRUE( mpLayerManager->update() ) << "Update failed on LayerManager";
184 ASSERT_TRUE( pShape4->getViewLayers().at(0).first != mpTestView ) << "Shape 4 must not be on background layer";
185 mpLayerManager->leaveAnimationMode(pShape3);
186 ASSERT_TRUE( mpLayerManager->update() ) << "Update failed on LayerManager";
187 ASSERT_TRUE( pShape4->getViewLayers().at(0).first == mpTestView ) << "Shape 4 must be on background layer";
188
189 mpLayerManager->deactivate();
190 ASSERT_TRUE( !mpLayerManager->isUpdatePending() ) << "Update pending on deactivated LayerManager";
191 }
192
TEST_F(LayerManagerTest,testShapeRepaint)193 TEST_F(LayerManagerTest, testShapeRepaint)
194 {
195 TestShapeSharedPtr pShape2( createTestShape(
196 basegfx::B2DRange(0.0,0.0,10.0,10.0),
197 2.0));
198 TestShapeSharedPtr pShape3( createTestShape(
199 basegfx::B2DRange(0.0,0.0,10.0,10.0),
200 3.0));
201 TestShapeSharedPtr pShape4( createTestShape(
202 basegfx::B2DRange(0.0,0.0,10.0,10.0),
203 4.0));
204 TestShapeSharedPtr pShape5( createTestShape(
205 basegfx::B2DRange(20.0,20.0,30.0,30.0),
206 4.0));
207
208 mpLayerManager->addShape(mpTestShape);
209 mpLayerManager->addShape(pShape2);
210 mpLayerManager->enterAnimationMode(pShape2);
211 mpLayerManager->addShape(pShape3);
212 mpLayerManager->addShape(pShape4);
213 mpLayerManager->addShape(pShape5);
214
215 mpLayerManager->activate( false );
216 mpLayerManager->update();
217
218 ASSERT_TRUE( mpTestShape->getNumRenders() == 1 ) << "First shape not rendered";
219 #if RUN_OLD_FAILING_TESTS
220 ASSERT_TRUE( pShape2->getNumRenders() == 1 ) << "Second shape not rendered";
221 #endif
222 ASSERT_TRUE( pShape3->getNumRenders() == 1 ) << "Third shape not rendered";
223 ASSERT_TRUE( pShape4->getNumRenders() == 1 ) << "Fourth shape not rendered";
224 ASSERT_TRUE( pShape5->getNumRenders() == 1 ) << "Fifth shape not rendered";
225
226 mpLayerManager->enterAnimationMode(pShape4);
227 mpLayerManager->update();
228
229 ASSERT_TRUE( mpTestShape->getNumRenders() == 1 ) << "First shape not rendered";
230 #if RUN_OLD_FAILING_TESTS
231 ASSERT_TRUE( pShape2->getNumRenders() == 1 ) << "Second shape not rendered";
232 #endif
233 ASSERT_TRUE( pShape3->getNumRenders() == 2 ) << "Third shape not rendered";
234 ASSERT_TRUE( pShape4->getNumRenders() == 2 ) << "Fourth shape not rendered";
235 ASSERT_TRUE( pShape5->getNumRenders() == 2 ) << "Fifth shape not rendered";
236
237 mpLayerManager->leaveAnimationMode(pShape2);
238 mpLayerManager->leaveAnimationMode(pShape4);
239 mpLayerManager->update();
240
241 ASSERT_TRUE( mpTestShape->getNumRenders() == 2 ) << "First shape not rendered #2";
242 #if RUN_OLD_FAILING_TESTS
243 ASSERT_TRUE( pShape2->getNumRenders() == 2 ) << "Second shape not rendered #2"
244 #endif
245 ASSERT_TRUE( pShape3->getNumRenders() == 3 ) << "Third shape not rendered #2";
246 ASSERT_TRUE( pShape4->getNumRenders() == 3 ) << "Fourth shape not rendered #2";
247 ASSERT_TRUE( pShape5->getNumRenders() == 3 ) << "Fifth shape not rendered #2";
248 }
249
TEST_F(LayerManagerTest,testRefCounting)250 TEST_F(LayerManagerTest, testRefCounting)
251 {
252 TestShapeSharedPtr pShape2( createTestShape(
253 basegfx::B2DRange(0.0,0.0,10.0,10.0),
254 2.0));
255 TestShapeSharedPtr pShape3( createTestShape(
256 basegfx::B2DRange(0.0,0.0,10.0,10.0),
257 3.0));
258 TestShapeSharedPtr pShape4( createTestShape(
259 basegfx::B2DRange(0.0,0.0,10.0,10.0),
260 4.0));
261
262 mpLayerManager->addShape(mpTestShape);
263 mpLayerManager->addShape(pShape2);
264 mpLayerManager->addShape(pShape3);
265 mpLayerManager->addShape(pShape4);
266
267 mpLayerManager->removeShape(mpTestShape);
268 mpLayerManager->removeShape(pShape2);
269 mpLayerManager->removeShape(pShape3);
270 mpLayerManager->removeShape(pShape4);
271
272 ASSERT_TRUE( mpTestShape.use_count() == 1 ) << "Shape 1 must have refcount of 1";
273 ASSERT_TRUE( pShape2.use_count() == 1 ) << "Shape 2 must have refcount of 1";
274 ASSERT_TRUE( pShape3.use_count() == 1 ) << "Shape 3 must have refcount of 1";
275 ASSERT_TRUE( pShape4.use_count() == 1 ) << "Shape 4 must have refcount of 1";
276
277
278 mpLayerManager->addShape(mpTestShape);
279 mpLayerManager->addShape(pShape2);
280 mpLayerManager->addShape(pShape3);
281 mpLayerManager->addShape(pShape4);
282
283 mpLayerManager->activate( false );
284 mpLayerManager->update();
285
286 mpLayerManager->removeShape(mpTestShape);
287 mpLayerManager->removeShape(pShape2);
288 mpLayerManager->removeShape(pShape3);
289 mpLayerManager->removeShape(pShape4);
290
291 ASSERT_TRUE( mpTestShape.use_count() == 1 ) << "Shape 1 must have refcount of 1";
292 ASSERT_TRUE( pShape2.use_count() == 1 ) << "Shape 2 must have refcount of 1";
293 ASSERT_TRUE( pShape3.use_count() == 1 ) << "Shape 3 must have refcount of 1";
294 ASSERT_TRUE( pShape4.use_count() == 1 ) << "Shape 4 must have refcount of 1";
295
296 maViews.removeView(mpTestView);
297 mpLayerManager->viewRemoved(mpTestView);
298 ASSERT_TRUE( mpTestView.use_count() == 1 ) << "View must have refcount of 1";
299 }
300
301
302 } // namespace
303
304
305