build fix
[LibreOffice.git] / slideshow / test / slidetest.cxx
blobdcd88856e381282d5fd59739760c2eab3fbb5bfb
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"
39 #include "com/sun/star/presentation/XSlideShowView.hpp"
41 namespace target = slideshow::internal;
42 using namespace ::com::sun::star;
44 namespace
47 class LayerManagerTest : public CppUnit::TestFixture
49 target::UnoViewContainer maViews;
50 target::LayerManagerSharedPtr mpLayerManager;
51 TestViewSharedPtr mpTestView;
52 TestShapeSharedPtr mpTestShape;
54 public:
55 void setUp()
57 mpTestShape = createTestShape(
58 basegfx::B2DRange(0.0,0.0,10.0,10.0),
59 1.0);
60 mpTestView = createTestView();
61 maViews.addView( mpTestView );
63 mpLayerManager.reset(
64 new target::LayerManager(
65 maViews,
66 basegfx::B2DRange(0.0,0.0,100.0,100.0),
67 false ));
70 void tearDown()
72 mpLayerManager.reset();
73 maViews.dispose();
76 void testLayer()
78 target::LayerSharedPtr pBgLayer(
79 target::Layer::createBackgroundLayer( basegfx::B2DRange(0,0,100,100) ) );
80 pBgLayer->addView( mpTestView );
82 target::LayerSharedPtr pFgLayer(
83 target::Layer::createLayer( basegfx::B2DRange(0,0,100,100) ) );
84 pFgLayer->addView( mpTestView );
86 CPPUNIT_ASSERT_MESSAGE( "BG layer must confess that!",
87 pBgLayer->isBackgroundLayer() );
88 CPPUNIT_ASSERT_MESSAGE( "FG layer lies!",
89 !pFgLayer->isBackgroundLayer() );
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() );
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() );
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() );
112 void testBasics()
114 mpLayerManager->activate( false );
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() );
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() );
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 );
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 );
148 mpLayerManager->deactivate();
151 void testShapeOrdering()
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));
163 mpLayerManager->addShape(mpTestShape);
164 mpLayerManager->addShape(pShape2);
165 mpLayerManager->addShape(pShape3);
166 mpLayerManager->addShape(pShape4);
168 mpLayerManager->activate( false );
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() );
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) );
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 );
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 );
220 mpLayerManager->deactivate();
221 CPPUNIT_ASSERT_MESSAGE( "Update pending on deactivated LayerManager",
222 !mpLayerManager->isUpdatePending() );
225 void testShapeRepaint()
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));
240 mpLayerManager->addShape(mpTestShape);
241 mpLayerManager->addShape(pShape2);
242 mpLayerManager->enterAnimationMode(pShape2);
243 mpLayerManager->addShape(pShape3);
244 mpLayerManager->addShape(pShape4);
245 mpLayerManager->addShape(pShape5);
247 mpLayerManager->activate( false );
248 mpLayerManager->update();
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 );
261 mpLayerManager->enterAnimationMode(pShape4);
262 mpLayerManager->update();
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 );
275 mpLayerManager->leaveAnimationMode(pShape2);
276 mpLayerManager->leaveAnimationMode(pShape4);
277 mpLayerManager->update();
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 );
291 void testRefCounting()
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));
303 mpLayerManager->addShape(mpTestShape);
304 mpLayerManager->addShape(pShape2);
305 mpLayerManager->addShape(pShape3);
306 mpLayerManager->addShape(pShape4);
308 mpLayerManager->removeShape(mpTestShape);
309 mpLayerManager->removeShape(pShape2);
310 mpLayerManager->removeShape(pShape3);
311 mpLayerManager->removeShape(pShape4);
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 );
323 mpLayerManager->addShape(mpTestShape);
324 mpLayerManager->addShape(pShape2);
325 mpLayerManager->addShape(pShape3);
326 mpLayerManager->addShape(pShape4);
328 mpLayerManager->activate( false );
329 mpLayerManager->update();
331 mpLayerManager->removeShape(mpTestShape);
332 mpLayerManager->removeShape(pShape2);
333 mpLayerManager->removeShape(pShape3);
334 mpLayerManager->removeShape(pShape4);
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 );
345 maViews.removeView(mpTestView);
346 mpLayerManager->viewRemoved(mpTestView);
347 CPPUNIT_ASSERT_MESSAGE( "View must have refcount of 1",
348 mpTestView.use_count() == 1 );
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();
360 }; // class LayerManagerTest
363 CPPUNIT_TEST_SUITE_REGISTRATION(LayerManagerTest);
364 } // namespace
366 CPPUNIT_PLUGIN_IMPLEMENT();
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */