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