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