Update ooo320-m1
[ooovba.git] / slideshow / test / slidetest.cxx
blob11ba302523797f8dfaf297cd51e5d0cfda28ec0a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: slidetest.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <cppunit/simpleheader.hxx>
32 #include <cppuhelper/compbase1.hxx>
33 #include <comphelper/broadcasthelper.hxx>
35 #include <basegfx/matrix/b2dhommatrix.hxx>
36 #include <basegfx/range/b2drectangle.hxx>
37 #include <cppcanvas/spritecanvas.hxx>
39 #include "view.hxx"
40 #include "unoview.hxx"
41 #include "unoviewcontainer.hxx"
42 #include "shape.hxx"
43 #include "tests.hxx"
44 #include "../engine/slide/layermanager.hxx"
45 #include "../engine/slide/layer.hxx"
46 #include "com/sun/star/presentation/XSlideShowView.hpp"
48 namespace target = slideshow::internal;
49 using namespace ::com::sun::star;
51 namespace
54 class LayerManagerTest : public CppUnit::TestFixture
56 target::UnoViewContainer maViews;
57 target::LayerManagerSharedPtr mpLayerManager;
58 TestViewSharedPtr mpTestView;
59 TestShapeSharedPtr mpTestShape;
61 public:
62 void setUp()
64 mpTestShape = createTestShape(
65 basegfx::B2DRange(0.0,0.0,10.0,10.0),
66 1.0);
67 mpTestView = createTestView();
68 maViews.addView( mpTestView );
70 mpLayerManager.reset(
71 new target::LayerManager(
72 maViews,
73 basegfx::B2DRange(0.0,0.0,100.0,100.0),
74 false ));
77 void tearDown()
79 mpLayerManager.reset();
80 maViews.dispose();
83 void testLayer()
85 target::LayerSharedPtr pBgLayer(
86 target::Layer::createBackgroundLayer( basegfx::B2DRange(0,0,100,100) ) );
87 pBgLayer->addView( mpTestView );
89 target::LayerSharedPtr pFgLayer(
90 target::Layer::createLayer( basegfx::B2DRange(0,0,100,100) ) );
91 pFgLayer->addView( mpTestView );
93 CPPUNIT_ASSERT_MESSAGE( "BG layer must confess that!",
94 pBgLayer->isBackgroundLayer() );
95 CPPUNIT_ASSERT_MESSAGE( "FG layer lies!",
96 !pFgLayer->isBackgroundLayer() );
98 CPPUNIT_ASSERT_MESSAGE( "BG layer must not have pending updates!",
99 !pBgLayer->isUpdatePending() );
100 pBgLayer->addUpdateRange( basegfx::B2DRange(0,0,10,10) );
101 CPPUNIT_ASSERT_MESSAGE( "BG layer must have pending updates!",
102 pBgLayer->isUpdatePending() );
104 TestShapeSharedPtr pTestShape = createTestShape(
105 basegfx::B2DRange(0.0,0.0,1000.0,1000.0),
106 1.0);
107 pBgLayer->updateBounds( pTestShape );
108 CPPUNIT_ASSERT_MESSAGE( "BG layer must not resize!",
109 !pBgLayer->commitBounds() );
111 TestShapeSharedPtr pTestShape2 = createTestShape(
112 basegfx::B2DRange(0.0,0.0,1.0,1.0),
113 1.0);
114 pFgLayer->updateBounds( pTestShape2 );
115 CPPUNIT_ASSERT_MESSAGE( "FG layer must resize!",
116 pFgLayer->commitBounds() );
119 void testBasics()
121 mpLayerManager->activate( false );
123 CPPUNIT_ASSERT_MESSAGE( "Un-added shape must have zero view layers",
124 mpTestShape->getViewLayers().empty() );
125 mpLayerManager->addShape(mpTestShape);
126 CPPUNIT_ASSERT_MESSAGE( "Adding a shape requires a LayerManager update",
127 mpLayerManager->isUpdatePending() );
129 // update does the delayed viewAdded call to the shape
130 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
131 mpLayerManager->update() );
132 CPPUNIT_ASSERT_MESSAGE( "Added shape must have one view layer",
133 mpTestShape->getViewLayers().size() == 1 );
134 CPPUNIT_ASSERT_MESSAGE( "Shape must been rendered",
135 mpTestShape->getNumRenders() );
136 CPPUNIT_ASSERT_MESSAGE( "Shape must not been updated",
137 !mpTestShape->getNumUpdates() );
139 // test second view, check whether shape gets additional view
140 TestViewSharedPtr pTestView( createTestView() );
141 CPPUNIT_ASSERT_MESSAGE( "Adding second View failed",
142 maViews.addView( pTestView ) );
143 CPPUNIT_ASSERT_MESSAGE( "View container must have two views",
144 maViews.end() - maViews.begin() == 2 );
145 mpLayerManager->viewAdded(pTestView);
146 CPPUNIT_ASSERT_MESSAGE( "Added shape must have two view layers",
147 mpTestShape->getViewLayers().size() == 2 );
149 CPPUNIT_ASSERT_MESSAGE( "Removing second View failed",
150 maViews.removeView( pTestView ) );
151 mpLayerManager->viewRemoved(pTestView);
152 CPPUNIT_ASSERT_MESSAGE( "Added shape must have one view layer",
153 mpTestShape->getViewLayers().size() == 1 );
155 mpLayerManager->deactivate();
158 void testShapeOrdering()
160 TestShapeSharedPtr pShape2( createTestShape(
161 basegfx::B2DRange(0.0,0.0,10.0,10.0),
162 2.0));
163 TestShapeSharedPtr pShape3( createTestShape(
164 basegfx::B2DRange(0.0,0.0,10.0,10.0),
165 3.0));
166 TestShapeSharedPtr pShape4( createTestShape(
167 basegfx::B2DRange(0.0,0.0,10.0,10.0),
168 4.0));
170 mpLayerManager->addShape(mpTestShape);
171 mpLayerManager->addShape(pShape2);
172 mpLayerManager->addShape(pShape3);
173 mpLayerManager->addShape(pShape4);
175 mpLayerManager->activate( false );
177 // update does the delayed viewAdded call to the shape
178 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
179 mpLayerManager->update() );
180 CPPUNIT_ASSERT_MESSAGE( "View must have background layer only",
181 mpTestView->getViewLayers().empty() );
183 // LayerManager must now generate one extra view layer
184 mpLayerManager->enterAnimationMode(pShape2);
185 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
186 mpLayerManager->isUpdatePending() );
187 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
188 mpLayerManager->update() );
189 CPPUNIT_ASSERT_MESSAGE( "View must have one extra layer only",
190 mpTestView->getViewLayers().size() == 1 );
191 CPPUNIT_ASSERT_MESSAGE( "View layer must have 10x10 size",
192 mpTestView->getViewLayers().at(0)->getBounds() ==
193 basegfx::B2DRange(0.0,0.0,10.0,10.0) );
195 // LayerManager must now remove the extra view layer
196 mpLayerManager->leaveAnimationMode(pShape2);
197 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
198 mpLayerManager->isUpdatePending() );
199 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager #2",
200 mpLayerManager->update() );
201 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must be on background layer",
202 mpTestShape->getViewLayers().at(0).first == mpTestView );
203 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must be on background layer",
204 pShape2->getViewLayers().at(0).first == mpTestView );
205 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have one layer",
206 pShape3->getViewLayers().size() == 1 );
207 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must be on background layer",
208 pShape3->getViewLayers().at(0).first == mpTestView );
209 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must be on background layer",
210 pShape4->getViewLayers().at(0).first == mpTestView );
212 // checking deactivation (all layers except background layer
213 // must vanish)
214 mpLayerManager->enterAnimationMode(pShape3);
215 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
216 mpLayerManager->isUpdatePending() );
217 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
218 mpLayerManager->update() );
219 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must not be on background layer",
220 pShape4->getViewLayers().at(0).first != mpTestView );
221 mpLayerManager->leaveAnimationMode(pShape3);
222 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
223 mpLayerManager->update() );
224 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must be on background layer",
225 pShape4->getViewLayers().at(0).first == mpTestView );
227 mpLayerManager->deactivate();
228 CPPUNIT_ASSERT_MESSAGE( "Update pending on deactivated LayerManager",
229 !mpLayerManager->isUpdatePending() );
232 void testShapeRepaint()
234 TestShapeSharedPtr pShape2( createTestShape(
235 basegfx::B2DRange(0.0,0.0,10.0,10.0),
236 2.0));
237 TestShapeSharedPtr pShape3( createTestShape(
238 basegfx::B2DRange(0.0,0.0,10.0,10.0),
239 3.0));
240 TestShapeSharedPtr pShape4( createTestShape(
241 basegfx::B2DRange(0.0,0.0,10.0,10.0),
242 4.0));
243 TestShapeSharedPtr pShape5( createTestShape(
244 basegfx::B2DRange(20.0,20.0,30.0,30.0),
245 4.0));
247 mpLayerManager->addShape(mpTestShape);
248 mpLayerManager->addShape(pShape2);
249 mpLayerManager->enterAnimationMode(pShape2);
250 mpLayerManager->addShape(pShape3);
251 mpLayerManager->addShape(pShape4);
252 mpLayerManager->addShape(pShape5);
254 mpLayerManager->activate( false );
255 mpLayerManager->update();
257 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered",
258 mpTestShape->getNumRenders() == 1 );
259 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
260 pShape2->getNumRenders() == 1 );
261 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered",
262 pShape3->getNumRenders() == 1 );
263 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered",
264 pShape4->getNumRenders() == 1 );
265 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered",
266 pShape5->getNumRenders() == 1 );
268 mpLayerManager->enterAnimationMode(pShape4);
269 mpLayerManager->update();
271 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered",
272 mpTestShape->getNumRenders() == 1 );
273 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
274 pShape2->getNumRenders() == 1 );
275 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered",
276 pShape3->getNumRenders() == 2 );
277 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered",
278 pShape4->getNumRenders() == 2 );
279 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered",
280 pShape5->getNumRenders() == 2 );
282 mpLayerManager->leaveAnimationMode(pShape2);
283 mpLayerManager->leaveAnimationMode(pShape4);
284 mpLayerManager->update();
286 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered #2",
287 mpTestShape->getNumRenders() == 2 );
288 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered #2",
289 pShape2->getNumRenders() == 2 );
290 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered #2",
291 pShape3->getNumRenders() == 3 );
292 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered #2",
293 pShape4->getNumRenders() == 3 );
294 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered #2",
295 pShape5->getNumRenders() == 3 );
298 void testRefCounting()
300 TestShapeSharedPtr pShape2( createTestShape(
301 basegfx::B2DRange(0.0,0.0,10.0,10.0),
302 2.0));
303 TestShapeSharedPtr pShape3( createTestShape(
304 basegfx::B2DRange(0.0,0.0,10.0,10.0),
305 3.0));
306 TestShapeSharedPtr pShape4( createTestShape(
307 basegfx::B2DRange(0.0,0.0,10.0,10.0),
308 4.0));
310 mpLayerManager->addShape(mpTestShape);
311 mpLayerManager->addShape(pShape2);
312 mpLayerManager->addShape(pShape3);
313 mpLayerManager->addShape(pShape4);
315 mpLayerManager->removeShape(mpTestShape);
316 mpLayerManager->removeShape(pShape2);
317 mpLayerManager->removeShape(pShape3);
318 mpLayerManager->removeShape(pShape4);
320 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must have refcount of 1",
321 mpTestShape.use_count() == 1 );
322 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must have refcount of ",
323 pShape2.use_count() == 1 );
324 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have refcount of 1",
325 pShape3.use_count() == 1 );
326 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must have refcount of",
327 pShape4.use_count() == 1 );
330 mpLayerManager->addShape(mpTestShape);
331 mpLayerManager->addShape(pShape2);
332 mpLayerManager->addShape(pShape3);
333 mpLayerManager->addShape(pShape4);
335 mpLayerManager->activate( false );
336 mpLayerManager->update();
338 mpLayerManager->removeShape(mpTestShape);
339 mpLayerManager->removeShape(pShape2);
340 mpLayerManager->removeShape(pShape3);
341 mpLayerManager->removeShape(pShape4);
343 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must have refcount of 1",
344 mpTestShape.use_count() == 1 );
345 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must have refcount of ",
346 pShape2.use_count() == 1 );
347 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have refcount of 1",
348 pShape3.use_count() == 1 );
349 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must have refcount of 1",
350 pShape4.use_count() == 1 );
352 maViews.removeView(mpTestView);
353 mpLayerManager->viewRemoved(mpTestView);
354 CPPUNIT_ASSERT_MESSAGE( "View must have refcount of 1",
355 mpTestView.use_count() == 1 );
358 // hook up the test
359 CPPUNIT_TEST_SUITE(LayerManagerTest);
360 CPPUNIT_TEST(testBasics);
361 CPPUNIT_TEST(testLayer);
362 CPPUNIT_TEST(testShapeOrdering);
363 CPPUNIT_TEST(testShapeRepaint);
364 CPPUNIT_TEST(testRefCounting);
365 CPPUNIT_TEST_SUITE_END();
367 }; // class LayerManagerTest
369 // -----------------------------------------------------------------------------
370 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(LayerManagerTest, "LayerManagerTest");
371 } // namespace