Bump version to 6.0-36
[LibreOffice.git] / slideshow / test / slidetest.cxx
blobc5dadb8a823ec00c03aa30df19c99811ac4ef503
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/types.h>
21 #include "cppunit/TestAssert.h"
22 #include "cppunit/TestFixture.h"
23 #include "cppunit/extensions/HelperMacros.h"
24 #include "cppunit/plugin/TestPlugIn.h"
26 #include <comphelper/broadcasthelper.hxx>
28 #include <basegfx/matrix/b2dhommatrix.hxx>
29 #include <basegfx/range/b2drectangle.hxx>
30 #include <cppcanvas/spritecanvas.hxx>
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"
40 namespace target = slideshow::internal;
41 using namespace ::com::sun::star;
43 namespace
46 class LayerManagerTest : public CppUnit::TestFixture
48 target::UnoViewContainer maViews;
49 target::LayerManagerSharedPtr mpLayerManager;
50 TestViewSharedPtr mpTestView;
51 TestShapeSharedPtr mpTestShape;
53 public:
54 void setUp()
56 mpTestShape = createTestShape(
57 basegfx::B2DRange(0.0,0.0,10.0,10.0),
58 1.0);
59 mpTestView = createTestView();
60 maViews.addView( mpTestView );
62 mpLayerManager.reset(
63 new target::LayerManager(
64 maViews,
65 basegfx::B2DRange(0.0,0.0,100.0,100.0),
66 false ));
69 void tearDown()
71 mpLayerManager.reset();
72 maViews.dispose();
75 void testLayer()
77 target::LayerSharedPtr pBgLayer(
78 target::Layer::createBackgroundLayer( basegfx::B2DRange(0,0,100,100) ) );
79 pBgLayer->addView( mpTestView );
81 target::LayerSharedPtr pFgLayer(
82 target::Layer::createLayer( basegfx::B2DRange(0,0,100,100) ) );
83 pFgLayer->addView( mpTestView );
85 CPPUNIT_ASSERT_MESSAGE( "BG layer must confess that!",
86 pBgLayer->isBackgroundLayer() );
87 CPPUNIT_ASSERT_MESSAGE( "FG layer lies!",
88 !pFgLayer->isBackgroundLayer() );
90 CPPUNIT_ASSERT_MESSAGE( "BG layer must not have pending updates!",
91 !pBgLayer->isUpdatePending() );
92 pBgLayer->addUpdateRange( basegfx::B2DRange(0,0,10,10) );
93 CPPUNIT_ASSERT_MESSAGE( "BG layer must have pending updates!",
94 pBgLayer->isUpdatePending() );
96 TestShapeSharedPtr pTestShape = createTestShape(
97 basegfx::B2DRange(0.0,0.0,1000.0,1000.0),
98 1.0);
99 pBgLayer->updateBounds( pTestShape );
100 CPPUNIT_ASSERT_MESSAGE( "BG layer must not resize!",
101 !pBgLayer->commitBounds() );
103 TestShapeSharedPtr pTestShape2 = createTestShape(
104 basegfx::B2DRange(0.0,0.0,1.0,1.0),
105 1.0);
106 pFgLayer->updateBounds( pTestShape2 );
107 CPPUNIT_ASSERT_MESSAGE( "FG layer must resize!",
108 pFgLayer->commitBounds() );
111 void testBasics()
113 mpLayerManager->activate( false );
115 CPPUNIT_ASSERT_MESSAGE( "Un-added shape must have zero view layers",
116 mpTestShape->getViewLayers().empty() );
117 mpLayerManager->addShape(mpTestShape);
118 CPPUNIT_ASSERT_MESSAGE( "Adding a shape requires a LayerManager update",
119 mpLayerManager->isUpdatePending() );
121 // update does the delayed viewAdded call to the shape
122 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
123 mpLayerManager->update() );
124 CPPUNIT_ASSERT_MESSAGE( "Added shape must have one view layer",
125 mpTestShape->getViewLayers().size() == 1 );
126 CPPUNIT_ASSERT_MESSAGE( "Shape must been rendered",
127 mpTestShape->getNumRenders() );
128 CPPUNIT_ASSERT_MESSAGE( "Shape must not been updated",
129 !mpTestShape->getNumUpdates() );
131 // test second view, check whether shape gets additional view
132 TestViewSharedPtr pTestView( createTestView() );
133 CPPUNIT_ASSERT_MESSAGE( "Adding second View failed",
134 maViews.addView( pTestView ) );
135 CPPUNIT_ASSERT_MESSAGE( "View container must have two views",
136 maViews.end() - maViews.begin() == 2 );
137 mpLayerManager->viewAdded(pTestView);
138 CPPUNIT_ASSERT_MESSAGE( "Added shape must have two view layers",
139 mpTestShape->getViewLayers().size() == 2 );
141 CPPUNIT_ASSERT_MESSAGE( "Removing second View failed",
142 maViews.removeView( pTestView ) );
143 mpLayerManager->viewRemoved(pTestView);
144 CPPUNIT_ASSERT_MESSAGE( "Added shape must have one view layer",
145 mpTestShape->getViewLayers().size() == 1 );
147 mpLayerManager->deactivate();
150 void testShapeOrdering()
152 TestShapeSharedPtr pShape2( createTestShape(
153 basegfx::B2DRange(0.0,0.0,10.0,10.0),
154 2.0));
155 TestShapeSharedPtr pShape3( createTestShape(
156 basegfx::B2DRange(0.0,0.0,10.0,10.0),
157 3.0));
158 TestShapeSharedPtr pShape4( createTestShape(
159 basegfx::B2DRange(0.0,0.0,10.0,10.0),
160 4.0));
162 mpLayerManager->addShape(mpTestShape);
163 mpLayerManager->addShape(pShape2);
164 mpLayerManager->addShape(pShape3);
165 mpLayerManager->addShape(pShape4);
167 mpLayerManager->activate( false );
169 // update does the delayed viewAdded call to the shape
170 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
171 mpLayerManager->update() );
172 CPPUNIT_ASSERT_MESSAGE( "View must have background layer only",
173 mpTestView->getViewLayers().empty() );
175 // LayerManager must now generate one extra view layer
176 mpLayerManager->enterAnimationMode(pShape2);
177 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
178 mpLayerManager->isUpdatePending() );
179 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
180 mpLayerManager->update() );
181 CPPUNIT_ASSERT_MESSAGE( "View must have one extra layer only",
182 mpTestView->getViewLayers().size() == 1 );
183 CPPUNIT_ASSERT_MESSAGE( "View layer must have 10x10 size",
184 mpTestView->getViewLayers().at(0)->getBounds() ==
185 basegfx::B2DRange(0.0,0.0,10.0,10.0) );
187 // LayerManager must now remove the extra view layer
188 mpLayerManager->leaveAnimationMode(pShape2);
189 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
190 mpLayerManager->isUpdatePending() );
191 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager #2",
192 mpLayerManager->update() );
193 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must be on background layer",
194 mpTestShape->getViewLayers().at(0).first == mpTestView );
195 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must be on background layer",
196 pShape2->getViewLayers().at(0).first == mpTestView );
197 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have one layer",
198 pShape3->getViewLayers().size() == 1 );
199 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must be on background layer",
200 pShape3->getViewLayers().at(0).first == mpTestView );
201 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must be on background layer",
202 pShape4->getViewLayers().at(0).first == mpTestView );
204 // checking deactivation (all layers except background layer
205 // must vanish)
206 mpLayerManager->enterAnimationMode(pShape3);
207 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
208 mpLayerManager->isUpdatePending() );
209 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
210 mpLayerManager->update() );
211 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must not be on background layer",
212 pShape4->getViewLayers().at(0).first != mpTestView );
213 mpLayerManager->leaveAnimationMode(pShape3);
214 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
215 mpLayerManager->update() );
216 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must be on background layer",
217 pShape4->getViewLayers().at(0).first == mpTestView );
219 mpLayerManager->deactivate();
220 CPPUNIT_ASSERT_MESSAGE( "Update pending on deactivated LayerManager",
221 !mpLayerManager->isUpdatePending() );
224 void testShapeRepaint()
226 TestShapeSharedPtr pShape2( createTestShape(
227 basegfx::B2DRange(0.0,0.0,10.0,10.0),
228 2.0));
229 TestShapeSharedPtr pShape3( createTestShape(
230 basegfx::B2DRange(0.0,0.0,10.0,10.0),
231 3.0));
232 TestShapeSharedPtr pShape4( createTestShape(
233 basegfx::B2DRange(0.0,0.0,10.0,10.0),
234 4.0));
235 TestShapeSharedPtr pShape5( createTestShape(
236 basegfx::B2DRange(20.0,20.0,30.0,30.0),
237 4.0));
239 mpLayerManager->addShape(mpTestShape);
240 mpLayerManager->addShape(pShape2);
241 mpLayerManager->enterAnimationMode(pShape2);
242 mpLayerManager->addShape(pShape3);
243 mpLayerManager->addShape(pShape4);
244 mpLayerManager->addShape(pShape5);
246 mpLayerManager->activate( false );
247 mpLayerManager->update();
249 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered",
250 mpTestShape->getNumRenders() == 1 );
251 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
252 pShape2->getNumRenders() == 1 );
253 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered",
254 pShape3->getNumRenders() == 1 );
255 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered",
256 pShape4->getNumRenders() == 1 );
257 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered",
258 pShape5->getNumRenders() == 1 );
260 mpLayerManager->enterAnimationMode(pShape4);
261 mpLayerManager->update();
263 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered",
264 mpTestShape->getNumRenders() == 1 );
265 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
266 pShape2->getNumRenders() == 1 );
267 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered",
268 pShape3->getNumRenders() == 2 );
269 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered",
270 pShape4->getNumRenders() == 2 );
271 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered",
272 pShape5->getNumRenders() == 2 );
274 mpLayerManager->leaveAnimationMode(pShape2);
275 mpLayerManager->leaveAnimationMode(pShape4);
276 mpLayerManager->update();
278 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered #2",
279 mpTestShape->getNumRenders() == 2 );
280 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered #2",
281 pShape2->getNumRenders() == 2 );
282 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered #2",
283 pShape3->getNumRenders() == 3 );
284 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered #2",
285 pShape4->getNumRenders() == 3 );
286 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered #2",
287 pShape5->getNumRenders() == 3 );
290 void testRefCounting()
292 TestShapeSharedPtr pShape2( createTestShape(
293 basegfx::B2DRange(0.0,0.0,10.0,10.0),
294 2.0));
295 TestShapeSharedPtr pShape3( createTestShape(
296 basegfx::B2DRange(0.0,0.0,10.0,10.0),
297 3.0));
298 TestShapeSharedPtr pShape4( createTestShape(
299 basegfx::B2DRange(0.0,0.0,10.0,10.0),
300 4.0));
302 mpLayerManager->addShape(mpTestShape);
303 mpLayerManager->addShape(pShape2);
304 mpLayerManager->addShape(pShape3);
305 mpLayerManager->addShape(pShape4);
307 mpLayerManager->removeShape(mpTestShape);
308 mpLayerManager->removeShape(pShape2);
309 mpLayerManager->removeShape(pShape3);
310 mpLayerManager->removeShape(pShape4);
312 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must have refcount of 1",
313 mpTestShape.use_count() == 1 );
314 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must have refcount of ",
315 pShape2.use_count() == 1 );
316 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have refcount of 1",
317 pShape3.use_count() == 1 );
318 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must have refcount of",
319 pShape4.use_count() == 1 );
322 mpLayerManager->addShape(mpTestShape);
323 mpLayerManager->addShape(pShape2);
324 mpLayerManager->addShape(pShape3);
325 mpLayerManager->addShape(pShape4);
327 mpLayerManager->activate( false );
328 mpLayerManager->update();
330 mpLayerManager->removeShape(mpTestShape);
331 mpLayerManager->removeShape(pShape2);
332 mpLayerManager->removeShape(pShape3);
333 mpLayerManager->removeShape(pShape4);
335 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must have refcount of 1",
336 mpTestShape.use_count() == 1 );
337 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must have refcount of ",
338 pShape2.use_count() == 1 );
339 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have refcount of 1",
340 pShape3.use_count() == 1 );
341 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must have refcount of 1",
342 pShape4.use_count() == 1 );
344 maViews.removeView(mpTestView);
345 mpLayerManager->viewRemoved(mpTestView);
346 CPPUNIT_ASSERT_MESSAGE( "View must have refcount of 1",
347 mpTestView.use_count() == 1 );
350 // hook up the test
351 CPPUNIT_TEST_SUITE(LayerManagerTest);
352 CPPUNIT_TEST(testBasics);
353 CPPUNIT_TEST(testLayer);
354 CPPUNIT_TEST(testShapeOrdering);
355 CPPUNIT_TEST(testShapeRepaint);
356 CPPUNIT_TEST(testRefCounting);
357 CPPUNIT_TEST_SUITE_END();
359 }; // class LayerManagerTest
362 CPPUNIT_TEST_SUITE_REGISTRATION(LayerManagerTest);
363 } // namespace
365 CPPUNIT_PLUGIN_IMPLEMENT();
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */