1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <unoview.hxx>
27 #include <unoviewcontainer.hxx>
29 #include <../engine/slide/layermanager.hxx>
30 #include <../engine/slide/layer.hxx>
32 namespace target
= slideshow::internal
;
33 using namespace ::com::sun::star
;
38 class LayerManagerTest
: public CppUnit::TestFixture
40 target::UnoViewContainer maViews
;
41 target::LayerManagerSharedPtr mpLayerManager
;
42 TestViewSharedPtr mpTestView
;
43 TestShapeSharedPtr mpTestShape
;
48 mpTestShape
= createTestShape(
49 basegfx::B2DRange(0.0,0.0,10.0,10.0),
51 mpTestView
= createTestView();
52 maViews
.addView( mpTestView
);
55 std::make_shared
<target::LayerManager
>(
60 void tearDown() override
62 mpLayerManager
.reset();
68 target::LayerSharedPtr
pBgLayer(
69 target::Layer::createBackgroundLayer() );
70 pBgLayer
->addView( mpTestView
);
72 target::LayerSharedPtr
pFgLayer(
73 target::Layer::createLayer() );
74 pFgLayer
->addView( mpTestView
);
76 CPPUNIT_ASSERT_MESSAGE( "BG layer must confess that!",
77 pBgLayer
->isBackgroundLayer() );
78 CPPUNIT_ASSERT_MESSAGE( "FG layer lies!",
79 !pFgLayer
->isBackgroundLayer() );
81 CPPUNIT_ASSERT_MESSAGE( "BG layer must not have pending updates!",
82 !pBgLayer
->isUpdatePending() );
83 pBgLayer
->addUpdateRange( basegfx::B2DRange(0,0,10,10) );
84 CPPUNIT_ASSERT_MESSAGE( "BG layer must have pending updates!",
85 pBgLayer
->isUpdatePending() );
87 TestShapeSharedPtr pTestShape
= createTestShape(
88 basegfx::B2DRange(0.0,0.0,1000.0,1000.0),
90 pBgLayer
->updateBounds( pTestShape
);
91 CPPUNIT_ASSERT_MESSAGE( "BG layer must not resize!",
92 !pBgLayer
->commitBounds() );
94 TestShapeSharedPtr pTestShape2
= createTestShape(
95 basegfx::B2DRange(0.0,0.0,1.0,1.0),
97 pFgLayer
->updateBounds( pTestShape2
);
98 CPPUNIT_ASSERT_MESSAGE( "FG layer must resize!",
99 pFgLayer
->commitBounds() );
104 mpLayerManager
->activate();
106 CPPUNIT_ASSERT_MESSAGE( "Un-added shape must have zero view layers",
107 mpTestShape
->getViewLayers().empty() );
108 mpLayerManager
->addShape(mpTestShape
);
109 CPPUNIT_ASSERT_MESSAGE( "Adding a shape requires a LayerManager update",
110 mpLayerManager
->isUpdatePending() );
112 // update does the delayed viewAdded call to the shape
113 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
114 mpLayerManager
->update() );
115 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added shape must have one view layer",
116 size_t(1), mpTestShape
->getViewLayers().size() );
117 CPPUNIT_ASSERT_MESSAGE( "Shape must been rendered",
118 mpTestShape
->getNumRenders() );
119 CPPUNIT_ASSERT_MESSAGE( "Shape must not been updated",
120 !mpTestShape
->getNumUpdates() );
122 // test second view, check whether shape gets additional view
123 TestViewSharedPtr
pTestView( createTestView() );
124 CPPUNIT_ASSERT_MESSAGE( "Adding second View failed",
125 maViews
.addView( pTestView
) );
126 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View container must have two views",
128 maViews
.end() - maViews
.begin() );
129 mpLayerManager
->viewAdded(pTestView
);
130 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added shape must have two view layers",
132 mpTestShape
->getViewLayers().size() );
134 mpLayerManager
->deactivate();
137 void testShapeOrdering()
139 TestShapeSharedPtr
pShape2( createTestShape(
140 basegfx::B2DRange(0.0,0.0,10.0,10.0),
142 TestShapeSharedPtr
pShape3( createTestShape(
143 basegfx::B2DRange(0.0,0.0,10.0,10.0),
145 TestShapeSharedPtr
pShape4( createTestShape(
146 basegfx::B2DRange(0.0,0.0,10.0,10.0),
149 mpLayerManager
->addShape(mpTestShape
);
150 mpLayerManager
->addShape(pShape2
);
151 mpLayerManager
->addShape(pShape3
);
152 mpLayerManager
->addShape(pShape4
);
154 mpLayerManager
->activate();
156 // update does the delayed viewAdded call to the shape
157 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
158 mpLayerManager
->update() );
159 CPPUNIT_ASSERT_MESSAGE( "View must have background layer only",
160 mpTestView
->getViewLayers().empty() );
162 // LayerManager must now generate one extra view layer
163 mpLayerManager
->enterAnimationMode(pShape2
);
164 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
165 mpLayerManager
->isUpdatePending() );
166 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
167 mpLayerManager
->update() );
168 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View must have one extra layer only",
169 size_t(1), mpTestView
->getViewLayers().size() );
170 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View layer must have 10x10 size",
171 basegfx::B2DRange(0.0,0.0,10.0,10.0),
172 mpTestView
->getViewLayers().at(0)->getBounds() );
174 // LayerManager must now remove the extra view layer
175 mpLayerManager
->leaveAnimationMode(pShape2
);
176 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
177 mpLayerManager
->isUpdatePending() );
178 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager #2",
179 mpLayerManager
->update() );
180 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must be on background layer",
181 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
182 mpTestShape
->getViewLayers().at(0).first
.get() );
183 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must be on background layer",
184 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
185 pShape2
->getViewLayers().at(0).first
.get() );
186 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have one layer",
187 size_t(1), pShape3
->getViewLayers().size() );
188 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must be on background layer",
189 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
190 pShape3
->getViewLayers().at(0).first
.get() );
191 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must be on background layer",
192 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
193 pShape4
->getViewLayers().at(0).first
.get() );
195 // checking deactivation (all layers except background layer
197 mpLayerManager
->enterAnimationMode(pShape3
);
198 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
199 mpLayerManager
->isUpdatePending() );
200 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
201 mpLayerManager
->update() );
202 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must not be on background layer",
203 pShape4
->getViewLayers().at(0).first
!= mpTestView
);
204 mpLayerManager
->leaveAnimationMode(pShape3
);
205 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
206 mpLayerManager
->update() );
207 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must be on background layer",
208 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
209 pShape4
->getViewLayers().at(0).first
.get() );
211 mpLayerManager
->deactivate();
212 CPPUNIT_ASSERT_MESSAGE( "Update pending on deactivated LayerManager",
213 !mpLayerManager
->isUpdatePending() );
216 void testShapeRepaint()
218 TestShapeSharedPtr
pShape2( createTestShape(
219 basegfx::B2DRange(0.0,0.0,10.0,10.0),
221 TestShapeSharedPtr
pShape3( createTestShape(
222 basegfx::B2DRange(0.0,0.0,10.0,10.0),
224 TestShapeSharedPtr
pShape4( createTestShape(
225 basegfx::B2DRange(0.0,0.0,10.0,10.0),
227 TestShapeSharedPtr
pShape5( createTestShape(
228 basegfx::B2DRange(20.0,20.0,30.0,30.0),
231 mpLayerManager
->addShape(mpTestShape
);
232 mpLayerManager
->addShape(pShape2
);
233 mpLayerManager
->addShape(pShape3
);
234 mpLayerManager
->addShape(pShape4
);
235 mpLayerManager
->addShape(pShape5
);
237 mpLayerManager
->activate();
239 mpLayerManager
->enterAnimationMode(pShape2
);
240 mpLayerManager
->update();
242 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered",
243 sal_Int32(1), mpTestShape
->getNumRenders() );
244 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
245 // pShape2->getNumRenders() == 1 );
246 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered",
247 sal_Int32(0), pShape2
->getNumRenders() );
248 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered",
249 sal_Int32(1), pShape3
->getNumRenders() );
250 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered",
251 sal_Int32(1), pShape4
->getNumRenders() );
252 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered",
253 sal_Int32(1), pShape5
->getNumRenders() );
255 mpLayerManager
->enterAnimationMode(pShape4
);
256 mpLayerManager
->update();
258 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered",
259 sal_Int32(1), mpTestShape
->getNumRenders() );
260 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
261 // pShape2->getNumRenders() == 1 );
262 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered",
263 sal_Int32(0), pShape2
->getNumRenders() );
264 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered",
265 sal_Int32(2), pShape3
->getNumRenders() );
266 // interesting - windows does not render this? # == 1...
267 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered",
268 // sal_Int32(2), pShape4->getNumRenders() );
269 // interesting - windows does not render this? # == 1...
270 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered",
271 // sal_Int32(2), pShape5->getNumRenders() );
273 mpLayerManager
->leaveAnimationMode(pShape2
);
274 mpLayerManager
->leaveAnimationMode(pShape4
);
275 mpLayerManager
->update();
277 // first shape is on slide background, *now* gets rendered
278 // CPPUNIT_ASSERT_MESSAGE( "First shape not rendered #2",
279 // mpTestShape->getNumRenders() == 1 );
280 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered #2",
281 sal_Int32(2), mpTestShape
->getNumRenders() );
282 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered #2",
283 // pShape2->getNumRenders() == 2 );
284 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered #2",
285 sal_Int32(1), pShape2
->getNumRenders() );
286 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered #2",
287 sal_Int32(3), pShape3
->getNumRenders() );
288 // interesting - windows does not render this? # == 2...
289 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered #2",
290 // sal_Int32(3), pShape4->getNumRenders() );
291 // interesting - windows does not render this? # == 2...
292 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered #2",
293 // sal_Int32(3), pShape5->getNumRenders() );
296 void testRefCounting()
298 TestShapeSharedPtr
pShape2( createTestShape(
299 basegfx::B2DRange(0.0,0.0,10.0,10.0),
301 TestShapeSharedPtr
pShape3( createTestShape(
302 basegfx::B2DRange(0.0,0.0,10.0,10.0),
304 TestShapeSharedPtr
pShape4( createTestShape(
305 basegfx::B2DRange(0.0,0.0,10.0,10.0),
308 mpLayerManager
->addShape(mpTestShape
);
309 mpLayerManager
->addShape(pShape2
);
310 mpLayerManager
->addShape(pShape3
);
311 mpLayerManager
->addShape(pShape4
);
313 mpLayerManager
->removeShape(mpTestShape
);
314 mpLayerManager
->removeShape(pShape2
);
315 mpLayerManager
->removeShape(pShape3
);
316 mpLayerManager
->removeShape(pShape4
);
318 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must have refcount of 1",
319 1L, mpTestShape
.use_count() );
320 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must have refcount of ",
321 1L, pShape2
.use_count() );
322 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have refcount of 1",
323 1L, pShape3
.use_count() );
324 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must have refcount of",
325 1L, pShape4
.use_count() );
328 mpLayerManager
->addShape(mpTestShape
);
329 mpLayerManager
->addShape(pShape2
);
330 mpLayerManager
->addShape(pShape3
);
331 mpLayerManager
->addShape(pShape4
);
333 mpLayerManager
->activate();
334 mpLayerManager
->update();
336 mpLayerManager
->removeShape(mpTestShape
);
337 mpLayerManager
->removeShape(pShape2
);
338 mpLayerManager
->removeShape(pShape3
);
339 mpLayerManager
->removeShape(pShape4
);
341 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must have refcount of 1",
342 1L, mpTestShape
.use_count() );
343 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must have refcount of ",
344 1L, pShape2
.use_count() );
345 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have refcount of 1",
346 1L, pShape3
.use_count() );
347 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must have refcount of 1",
348 1L, pShape4
.use_count() );
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
);
366 CPPUNIT_PLUGIN_IMPLEMENT();
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */