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 <tools/long.hxx>
22 #include <cppunit/TestAssert.h>
23 #include <cppunit/TestFixture.h>
24 #include <cppunit/extensions/HelperMacros.h>
25 #include <cppunit/plugin/TestPlugIn.h>
27 #include <unoview.hxx>
28 #include <unoviewcontainer.hxx>
30 #include <../engine/slide/layermanager.hxx>
31 #include <../engine/slide/layer.hxx>
33 namespace target
= slideshow::internal
;
34 using namespace ::com::sun::star
;
39 class LayerManagerTest
: public CppUnit::TestFixture
41 target::UnoViewContainer maViews
;
42 target::LayerManagerSharedPtr mpLayerManager
;
43 TestViewSharedPtr mpTestView
;
44 TestShapeSharedPtr mpTestShape
;
49 mpTestShape
= createTestShape(
50 basegfx::B2DRange(0.0,0.0,10.0,10.0),
52 mpTestView
= createTestView();
53 maViews
.addView( mpTestView
);
56 std::make_shared
<target::LayerManager
>(
61 void tearDown() override
63 mpLayerManager
.reset();
69 target::LayerSharedPtr
pBgLayer(
70 target::Layer::createBackgroundLayer() );
71 pBgLayer
->addView( mpTestView
);
73 target::LayerSharedPtr
pFgLayer(
74 target::Layer::createLayer() );
75 pFgLayer
->addView( mpTestView
);
77 CPPUNIT_ASSERT_MESSAGE( "BG layer must confess that!",
78 pBgLayer
->isBackgroundLayer() );
79 CPPUNIT_ASSERT_MESSAGE( "FG layer lies!",
80 !pFgLayer
->isBackgroundLayer() );
82 CPPUNIT_ASSERT_MESSAGE( "BG layer must not have pending updates!",
83 !pBgLayer
->isUpdatePending() );
84 pBgLayer
->addUpdateRange( basegfx::B2DRange(0,0,10,10) );
85 CPPUNIT_ASSERT_MESSAGE( "BG layer must have pending updates!",
86 pBgLayer
->isUpdatePending() );
88 TestShapeSharedPtr pTestShape
= createTestShape(
89 basegfx::B2DRange(0.0,0.0,1000.0,1000.0),
91 pBgLayer
->updateBounds( pTestShape
);
92 CPPUNIT_ASSERT_MESSAGE( "BG layer must not resize!",
93 !pBgLayer
->commitBounds() );
95 TestShapeSharedPtr pTestShape2
= createTestShape(
96 basegfx::B2DRange(0.0,0.0,1.0,1.0),
98 pFgLayer
->updateBounds( pTestShape2
);
99 CPPUNIT_ASSERT_MESSAGE( "FG layer must resize!",
100 pFgLayer
->commitBounds() );
105 mpLayerManager
->activate();
107 CPPUNIT_ASSERT_MESSAGE( "Un-added shape must have zero view layers",
108 mpTestShape
->getViewLayers().empty() );
109 mpLayerManager
->addShape(mpTestShape
);
110 CPPUNIT_ASSERT_MESSAGE( "Adding a shape requires a LayerManager update",
111 mpLayerManager
->isUpdatePending() );
113 // update does the delayed viewAdded call to the shape
114 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
115 mpLayerManager
->update() );
116 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added shape must have one view layer",
117 size_t(1), mpTestShape
->getViewLayers().size() );
118 CPPUNIT_ASSERT_MESSAGE( "Shape must been rendered",
119 mpTestShape
->getNumRenders() );
120 CPPUNIT_ASSERT_MESSAGE( "Shape must not been updated",
121 !mpTestShape
->getNumUpdates() );
123 // test second view, check whether shape gets additional view
124 TestViewSharedPtr
pTestView( createTestView() );
125 CPPUNIT_ASSERT_MESSAGE( "Adding second View failed",
126 maViews
.addView( pTestView
) );
127 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View container must have two views",
129 maViews
.end() - maViews
.begin() );
130 mpLayerManager
->viewAdded(pTestView
);
131 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Added shape must have two view layers",
133 mpTestShape
->getViewLayers().size() );
135 mpLayerManager
->deactivate();
138 void testShapeOrdering()
140 TestShapeSharedPtr
pShape2( createTestShape(
141 basegfx::B2DRange(0.0,0.0,10.0,10.0),
143 TestShapeSharedPtr
pShape3( createTestShape(
144 basegfx::B2DRange(0.0,0.0,10.0,10.0),
146 TestShapeSharedPtr
pShape4( createTestShape(
147 basegfx::B2DRange(0.0,0.0,10.0,10.0),
150 mpLayerManager
->addShape(mpTestShape
);
151 mpLayerManager
->addShape(pShape2
);
152 mpLayerManager
->addShape(pShape3
);
153 mpLayerManager
->addShape(pShape4
);
155 mpLayerManager
->activate();
157 // update does the delayed viewAdded call to the shape
158 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
159 mpLayerManager
->update() );
160 CPPUNIT_ASSERT_MESSAGE( "View must have background layer only",
161 mpTestView
->getViewLayers().empty() );
163 // LayerManager must now generate one extra view layer
164 mpLayerManager
->enterAnimationMode(pShape2
);
165 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
166 mpLayerManager
->isUpdatePending() );
167 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
168 mpLayerManager
->update() );
169 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View must have one extra layer only",
170 size_t(1), mpTestView
->getViewLayers().size() );
171 CPPUNIT_ASSERT_EQUAL_MESSAGE( "View layer must have 10x10 size",
172 basegfx::B2DRange(0.0,0.0,10.0,10.0),
173 mpTestView
->getViewLayers().at(0)->getBounds() );
175 // LayerManager must now remove the extra view layer
176 mpLayerManager
->leaveAnimationMode(pShape2
);
177 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
178 mpLayerManager
->isUpdatePending() );
179 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager #2",
180 mpLayerManager
->update() );
181 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must be on background layer",
182 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
183 mpTestShape
->getViewLayers().at(0).first
.get() );
184 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must be on background layer",
185 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
186 pShape2
->getViewLayers().at(0).first
.get() );
187 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have one layer",
188 size_t(1), pShape3
->getViewLayers().size() );
189 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must be on background layer",
190 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
191 pShape3
->getViewLayers().at(0).first
.get() );
192 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must be on background layer",
193 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
194 pShape4
->getViewLayers().at(0).first
.get() );
196 // checking deactivation (all layers except background layer
198 mpLayerManager
->enterAnimationMode(pShape3
);
199 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
200 mpLayerManager
->isUpdatePending() );
201 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
202 mpLayerManager
->update() );
203 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must not be on background layer",
204 pShape4
->getViewLayers().at(0).first
!= mpTestView
);
205 mpLayerManager
->leaveAnimationMode(pShape3
);
206 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
207 mpLayerManager
->update() );
208 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must be on background layer",
209 static_cast<slideshow::internal::ViewLayer
*>(mpTestView
.get()),
210 pShape4
->getViewLayers().at(0).first
.get() );
212 mpLayerManager
->deactivate();
213 CPPUNIT_ASSERT_MESSAGE( "Update pending on deactivated LayerManager",
214 !mpLayerManager
->isUpdatePending() );
217 void testShapeRepaint()
219 TestShapeSharedPtr
pShape2( createTestShape(
220 basegfx::B2DRange(0.0,0.0,10.0,10.0),
222 TestShapeSharedPtr
pShape3( createTestShape(
223 basegfx::B2DRange(0.0,0.0,10.0,10.0),
225 TestShapeSharedPtr
pShape4( createTestShape(
226 basegfx::B2DRange(0.0,0.0,10.0,10.0),
228 TestShapeSharedPtr
pShape5( createTestShape(
229 basegfx::B2DRange(20.0,20.0,30.0,30.0),
232 mpLayerManager
->addShape(mpTestShape
);
233 mpLayerManager
->addShape(pShape2
);
234 mpLayerManager
->addShape(pShape3
);
235 mpLayerManager
->addShape(pShape4
);
236 mpLayerManager
->addShape(pShape5
);
238 mpLayerManager
->activate();
240 mpLayerManager
->enterAnimationMode(pShape2
);
241 mpLayerManager
->update();
243 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered",
244 sal_Int32(1), mpTestShape
->getNumRenders() );
245 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
246 // pShape2->getNumRenders() == 1 );
247 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered",
248 sal_Int32(0), pShape2
->getNumRenders() );
249 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered",
250 sal_Int32(1), pShape3
->getNumRenders() );
251 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered",
252 sal_Int32(1), pShape4
->getNumRenders() );
253 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered",
254 sal_Int32(1), pShape5
->getNumRenders() );
256 mpLayerManager
->enterAnimationMode(pShape4
);
257 mpLayerManager
->update();
259 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered",
260 sal_Int32(1), mpTestShape
->getNumRenders() );
261 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
262 // pShape2->getNumRenders() == 1 );
263 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered",
264 sal_Int32(0), pShape2
->getNumRenders() );
265 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered",
266 sal_Int32(2), pShape3
->getNumRenders() );
267 // interesting - windows does not render this? # == 1...
268 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered",
269 // sal_Int32(2), pShape4->getNumRenders() );
270 // interesting - windows does not render this? # == 1...
271 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered",
272 // sal_Int32(2), pShape5->getNumRenders() );
274 mpLayerManager
->leaveAnimationMode(pShape2
);
275 mpLayerManager
->leaveAnimationMode(pShape4
);
276 mpLayerManager
->update();
278 // first shape is on slide background, *now* gets rendered
279 // CPPUNIT_ASSERT_MESSAGE( "First shape not rendered #2",
280 // mpTestShape->getNumRenders() == 1 );
281 CPPUNIT_ASSERT_EQUAL_MESSAGE( "First shape not rendered #2",
282 sal_Int32(2), mpTestShape
->getNumRenders() );
283 // CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered #2",
284 // pShape2->getNumRenders() == 2 );
285 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Second shape not rendered #2",
286 sal_Int32(1), pShape2
->getNumRenders() );
287 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Third shape not rendered #2",
288 sal_Int32(3), pShape3
->getNumRenders() );
289 // interesting - windows does not render this? # == 2...
290 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fourth shape not rendered #2",
291 // sal_Int32(3), pShape4->getNumRenders() );
292 // interesting - windows does not render this? # == 2...
293 // CPPUNIT_ASSERT_EQUAL_MESSAGE( "Fifth shape not rendered #2",
294 // sal_Int32(3), pShape5->getNumRenders() );
297 void testRefCounting()
299 TestShapeSharedPtr
pShape2( createTestShape(
300 basegfx::B2DRange(0.0,0.0,10.0,10.0),
302 TestShapeSharedPtr
pShape3( createTestShape(
303 basegfx::B2DRange(0.0,0.0,10.0,10.0),
305 TestShapeSharedPtr
pShape4( createTestShape(
306 basegfx::B2DRange(0.0,0.0,10.0,10.0),
309 mpLayerManager
->addShape(mpTestShape
);
310 mpLayerManager
->addShape(pShape2
);
311 mpLayerManager
->addShape(pShape3
);
312 mpLayerManager
->addShape(pShape4
);
314 mpLayerManager
->removeShape(mpTestShape
);
315 mpLayerManager
->removeShape(pShape2
);
316 mpLayerManager
->removeShape(pShape3
);
317 mpLayerManager
->removeShape(pShape4
);
319 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must have refcount of 1",
320 1L, mpTestShape
.use_count() );
321 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must have refcount of ",
322 1L, pShape2
.use_count() );
323 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have refcount of 1",
324 1L, pShape3
.use_count() );
325 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must have refcount of",
326 1L, pShape4
.use_count() );
329 mpLayerManager
->addShape(mpTestShape
);
330 mpLayerManager
->addShape(pShape2
);
331 mpLayerManager
->addShape(pShape3
);
332 mpLayerManager
->addShape(pShape4
);
334 mpLayerManager
->activate();
335 mpLayerManager
->update();
337 mpLayerManager
->removeShape(mpTestShape
);
338 mpLayerManager
->removeShape(pShape2
);
339 mpLayerManager
->removeShape(pShape3
);
340 mpLayerManager
->removeShape(pShape4
);
342 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 1 must have refcount of 1",
343 1L, mpTestShape
.use_count() );
344 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 2 must have refcount of ",
345 1L, pShape2
.use_count() );
346 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 3 must have refcount of 1",
347 1L, pShape3
.use_count() );
348 CPPUNIT_ASSERT_EQUAL_MESSAGE( "Shape 4 must have refcount of 1",
349 1L, pShape4
.use_count() );
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
);
367 CPPUNIT_PLUGIN_IMPLEMENT();
369 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */