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