bump product version to 6.4.0.3
[LibreOffice.git] / slideshow / test / slidetest.cxx
blob7b3691a96ec27eda3e78f08b4868ce875df247ec
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 <basegfx/matrix/b2dhommatrix.hxx>
27 #include <basegfx/range/b2drectangle.hxx>
28 #include <cppcanvas/spritecanvas.hxx>
30 #include <view.hxx>
31 #include <unoview.hxx>
32 #include <unoviewcontainer.hxx>
33 #include <shape.hxx>
34 #include "tests.hxx"
35 #include <../engine/slide/layermanager.hxx>
36 #include <../engine/slide/layer.hxx>
38 namespace target = slideshow::internal;
39 using namespace ::com::sun::star;
41 namespace
44 class LayerManagerTest : public CppUnit::TestFixture
46 target::UnoViewContainer maViews;
47 target::LayerManagerSharedPtr mpLayerManager;
48 TestViewSharedPtr mpTestView;
49 TestShapeSharedPtr mpTestShape;
51 public:
52 void setUp() override
54 mpTestShape = createTestShape(
55 basegfx::B2DRange(0.0,0.0,10.0,10.0),
56 1.0);
57 mpTestView = createTestView();
58 maViews.addView( mpTestView );
60 mpLayerManager.reset(
61 new target::LayerManager(
62 maViews,
63 false ));
66 void tearDown() override
68 mpLayerManager.reset();
69 maViews.dispose();
72 void testLayer()
74 target::LayerSharedPtr pBgLayer(
75 target::Layer::createBackgroundLayer() );
76 pBgLayer->addView( mpTestView );
78 target::LayerSharedPtr pFgLayer(
79 target::Layer::createLayer() );
80 pFgLayer->addView( mpTestView );
82 CPPUNIT_ASSERT_MESSAGE( "BG layer must confess that!",
83 pBgLayer->isBackgroundLayer() );
84 CPPUNIT_ASSERT_MESSAGE( "FG layer lies!",
85 !pFgLayer->isBackgroundLayer() );
87 CPPUNIT_ASSERT_MESSAGE( "BG layer must not have pending updates!",
88 !pBgLayer->isUpdatePending() );
89 pBgLayer->addUpdateRange( basegfx::B2DRange(0,0,10,10) );
90 CPPUNIT_ASSERT_MESSAGE( "BG layer must have pending updates!",
91 pBgLayer->isUpdatePending() );
93 TestShapeSharedPtr pTestShape = createTestShape(
94 basegfx::B2DRange(0.0,0.0,1000.0,1000.0),
95 1.0);
96 pBgLayer->updateBounds( pTestShape );
97 CPPUNIT_ASSERT_MESSAGE( "BG layer must not resize!",
98 !pBgLayer->commitBounds() );
100 TestShapeSharedPtr pTestShape2 = createTestShape(
101 basegfx::B2DRange(0.0,0.0,1.0,1.0),
102 1.0);
103 pFgLayer->updateBounds( pTestShape2 );
104 CPPUNIT_ASSERT_MESSAGE( "FG layer must resize!",
105 pFgLayer->commitBounds() );
108 void testBasics()
110 mpLayerManager->activate();
112 CPPUNIT_ASSERT_MESSAGE( "Un-added shape must have zero view layers",
113 mpTestShape->getViewLayers().empty() );
114 mpLayerManager->addShape(mpTestShape);
115 CPPUNIT_ASSERT_MESSAGE( "Adding a shape requires a LayerManager update",
116 mpLayerManager->isUpdatePending() );
118 // update does the delayed viewAdded call to the shape
119 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
120 mpLayerManager->update() );
121 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added shape must have one view layer",
122 size_t(1), mpTestShape->getViewLayers().size() );
123 CPPUNIT_ASSERT_MESSAGE( "Shape must been rendered",
124 mpTestShape->getNumRenders() );
125 CPPUNIT_ASSERT_MESSAGE( "Shape must not been updated",
126 !mpTestShape->getNumUpdates() );
128 // test second view, check whether shape gets additional view
129 TestViewSharedPtr pTestView( createTestView() );
130 CPPUNIT_ASSERT_MESSAGE( "Adding second View failed",
131 maViews.addView( pTestView ) );
132 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View container must have two views",
133 std::ptrdiff_t(2),
134 maViews.end() - maViews.begin() );
135 mpLayerManager->viewAdded(pTestView);
136 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added shape must have two view layers",
137 size_t(2),
138 mpTestShape->getViewLayers().size() );
140 mpLayerManager->deactivate();
143 void testShapeOrdering()
145 TestShapeSharedPtr pShape2( createTestShape(
146 basegfx::B2DRange(0.0,0.0,10.0,10.0),
147 2.0));
148 TestShapeSharedPtr pShape3( createTestShape(
149 basegfx::B2DRange(0.0,0.0,10.0,10.0),
150 3.0));
151 TestShapeSharedPtr pShape4( createTestShape(
152 basegfx::B2DRange(0.0,0.0,10.0,10.0),
153 4.0));
155 mpLayerManager->addShape(mpTestShape);
156 mpLayerManager->addShape(pShape2);
157 mpLayerManager->addShape(pShape3);
158 mpLayerManager->addShape(pShape4);
160 mpLayerManager->activate();
162 // update does the delayed viewAdded call to the shape
163 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
164 mpLayerManager->update() );
165 CPPUNIT_ASSERT_MESSAGE( "View must have background layer only",
166 mpTestView->getViewLayers().empty() );
168 // LayerManager must now generate one extra view layer
169 mpLayerManager->enterAnimationMode(pShape2);
170 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
171 mpLayerManager->isUpdatePending() );
172 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
173 mpLayerManager->update() );
174 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View must have one extra layer only",
175 size_t(1), mpTestView->getViewLayers().size() );
176 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View layer must have 10x10 size",
177 basegfx::B2DRange(0.0,0.0,10.0,10.0),
178 mpTestView->getViewLayers().at(0)->getBounds() );
180 // LayerManager must now remove the extra view layer
181 mpLayerManager->leaveAnimationMode(pShape2);
182 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
183 mpLayerManager->isUpdatePending() );
184 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager #2",
185 mpLayerManager->update() );
186 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must be on background layer",
187 static_cast<slideshow::internal::ViewLayer*>(mpTestView.get()),
188 mpTestShape->getViewLayers().at(0).first.get() );
189 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must be on background layer",
190 static_cast<slideshow::internal::ViewLayer*>(mpTestView.get()),
191 pShape2->getViewLayers().at(0).first.get() );
192 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have one layer",
193 size_t(1), pShape3->getViewLayers().size() );
194 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must be on background layer",
195 static_cast<slideshow::internal::ViewLayer*>(mpTestView.get()),
196 pShape3->getViewLayers().at(0).first.get() );
197 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must be on background layer",
198 static_cast<slideshow::internal::ViewLayer*>(mpTestView.get()),
199 pShape4->getViewLayers().at(0).first.get() );
201 // checking deactivation (all layers except background layer
202 // must vanish)
203 mpLayerManager->enterAnimationMode(pShape3);
204 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
205 mpLayerManager->isUpdatePending() );
206 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
207 mpLayerManager->update() );
208 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must not be on background layer",
209 pShape4->getViewLayers().at(0).first != mpTestView );
210 mpLayerManager->leaveAnimationMode(pShape3);
211 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
212 mpLayerManager->update() );
213 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must be on background layer",
214 static_cast<slideshow::internal::ViewLayer*>(mpTestView.get()),
215 pShape4->getViewLayers().at(0).first.get() );
217 mpLayerManager->deactivate();
218 CPPUNIT_ASSERT_MESSAGE( "Update pending on deactivated LayerManager",
219 !mpLayerManager->isUpdatePending() );
222 void testShapeRepaint()
224 TestShapeSharedPtr pShape2( createTestShape(
225 basegfx::B2DRange(0.0,0.0,10.0,10.0),
226 2.0));
227 TestShapeSharedPtr pShape3( createTestShape(
228 basegfx::B2DRange(0.0,0.0,10.0,10.0),
229 3.0));
230 TestShapeSharedPtr pShape4( createTestShape(
231 basegfx::B2DRange(0.0,0.0,10.0,10.0),
232 4.0));
233 TestShapeSharedPtr pShape5( createTestShape(
234 basegfx::B2DRange(20.0,20.0,30.0,30.0),
235 4.0));
237 mpLayerManager->addShape(mpTestShape);
238 mpLayerManager->addShape(pShape2);
239 mpLayerManager->addShape(pShape3);
240 mpLayerManager->addShape(pShape4);
241 mpLayerManager->addShape(pShape5);
243 mpLayerManager->activate();
245 mpLayerManager->enterAnimationMode(pShape2);
246 mpLayerManager->update();
248 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered",
249 sal_Int32(1), mpTestShape->getNumRenders() );
250 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
251 // pShape2->getNumRenders() == 1 );
252 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered",
253 sal_Int32(0), pShape2->getNumRenders() );
254 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered",
255 sal_Int32(1), pShape3->getNumRenders() );
256 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered",
257 sal_Int32(1), pShape4->getNumRenders() );
258 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered",
259 sal_Int32(1), pShape5->getNumRenders() );
261 mpLayerManager->enterAnimationMode(pShape4);
262 mpLayerManager->update();
264 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered",
265 sal_Int32(1), mpTestShape->getNumRenders() );
266 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
267 // pShape2->getNumRenders() == 1 );
268 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered",
269 sal_Int32(0), pShape2->getNumRenders() );
270 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered",
271 sal_Int32(2), pShape3->getNumRenders() );
272 // interesting - windows does not render this? # == 1...
273 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered",
274 // sal_Int32(2), pShape4->getNumRenders() );
275 // interesting - windows does not render this? # == 1...
276 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered",
277 // sal_Int32(2), pShape5->getNumRenders() );
279 mpLayerManager->leaveAnimationMode(pShape2);
280 mpLayerManager->leaveAnimationMode(pShape4);
281 mpLayerManager->update();
283 // first shape is on slide background, *now* gets rendered
284 // CPPUNIT_ASSERT_MESSAGE( "First shape not rendered #2",
285 // mpTestShape->getNumRenders() == 1 );
286 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered #2",
287 sal_Int32(2), mpTestShape->getNumRenders() );
288 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered #2",
289 // pShape2->getNumRenders() == 2 );
290 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered #2",
291 sal_Int32(1), pShape2->getNumRenders() );
292 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered #2",
293 sal_Int32(3), pShape3->getNumRenders() );
294 // interesting - windows does not render this? # == 2...
295 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered #2",
296 // sal_Int32(3), pShape4->getNumRenders() );
297 // interesting - windows does not render this? # == 2...
298 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered #2",
299 // sal_Int32(3), pShape5->getNumRenders() );
302 void testRefCounting()
304 TestShapeSharedPtr pShape2( createTestShape(
305 basegfx::B2DRange(0.0,0.0,10.0,10.0),
306 2.0));
307 TestShapeSharedPtr pShape3( createTestShape(
308 basegfx::B2DRange(0.0,0.0,10.0,10.0),
309 3.0));
310 TestShapeSharedPtr pShape4( createTestShape(
311 basegfx::B2DRange(0.0,0.0,10.0,10.0),
312 4.0));
314 mpLayerManager->addShape(mpTestShape);
315 mpLayerManager->addShape(pShape2);
316 mpLayerManager->addShape(pShape3);
317 mpLayerManager->addShape(pShape4);
319 mpLayerManager->removeShape(mpTestShape);
320 mpLayerManager->removeShape(pShape2);
321 mpLayerManager->removeShape(pShape3);
322 mpLayerManager->removeShape(pShape4);
324 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must have refcount of 1",
325 long(1), mpTestShape.use_count() );
326 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must have refcount of ",
327 long(1), pShape2.use_count() );
328 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have refcount of 1",
329 long(1), pShape3.use_count() );
330 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must have refcount of",
331 long(1), pShape4.use_count() );
334 mpLayerManager->addShape(mpTestShape);
335 mpLayerManager->addShape(pShape2);
336 mpLayerManager->addShape(pShape3);
337 mpLayerManager->addShape(pShape4);
339 mpLayerManager->activate();
340 mpLayerManager->update();
342 mpLayerManager->removeShape(mpTestShape);
343 mpLayerManager->removeShape(pShape2);
344 mpLayerManager->removeShape(pShape3);
345 mpLayerManager->removeShape(pShape4);
347 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must have refcount of 1",
348 long(1), mpTestShape.use_count() );
349 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must have refcount of ",
350 long(1), pShape2.use_count() );
351 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have refcount of 1",
352 long(1), pShape3.use_count() );
353 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must have refcount of 1",
354 long(1), pShape4.use_count() );
357 // hook up the test
358 CPPUNIT_TEST_SUITE(LayerManagerTest);
359 CPPUNIT_TEST(testBasics);
360 CPPUNIT_TEST(testLayer);
361 CPPUNIT_TEST(testShapeOrdering);
362 CPPUNIT_TEST(testShapeRepaint);
363 CPPUNIT_TEST(testRefCounting);
364 CPPUNIT_TEST_SUITE_END();
366 }; // class LayerManagerTest
369 CPPUNIT_TEST_SUITE_REGISTRATION(LayerManagerTest);
370 } // namespace
372 CPPUNIT_PLUGIN_IMPLEMENT();
374 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */