oovbaapi: hack Excel / OptionButton compatibility into Button for now.
[LibreOffice.git] / slideshow / test / slidetest.cxx
blob2804e79a77e06418e746eff9f1eabbc6ee74e02b
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()
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 basegfx::B2DRange(0.0,0.0,100.0,100.0),
64 false ));
67 void tearDown()
69 mpLayerManager.reset();
70 maViews.dispose();
73 void testLayer()
75 target::LayerSharedPtr pBgLayer(
76 target::Layer::createBackgroundLayer( basegfx::B2DRange(0,0,100,100) ) );
77 pBgLayer->addView( mpTestView );
79 target::LayerSharedPtr pFgLayer(
80 target::Layer::createLayer( basegfx::B2DRange(0,0,100,100) ) );
81 pFgLayer->addView( mpTestView );
83 CPPUNIT_ASSERT_MESSAGE( "BG layer must confess that!",
84 pBgLayer->isBackgroundLayer() );
85 CPPUNIT_ASSERT_MESSAGE( "FG layer lies!",
86 !pFgLayer->isBackgroundLayer() );
88 CPPUNIT_ASSERT_MESSAGE( "BG layer must not have pending updates!",
89 !pBgLayer->isUpdatePending() );
90 pBgLayer->addUpdateRange( basegfx::B2DRange(0,0,10,10) );
91 CPPUNIT_ASSERT_MESSAGE( "BG layer must have pending updates!",
92 pBgLayer->isUpdatePending() );
94 TestShapeSharedPtr pTestShape = createTestShape(
95 basegfx::B2DRange(0.0,0.0,1000.0,1000.0),
96 1.0);
97 pBgLayer->updateBounds( pTestShape );
98 CPPUNIT_ASSERT_MESSAGE( "BG layer must not resize!",
99 !pBgLayer->commitBounds() );
101 TestShapeSharedPtr pTestShape2 = createTestShape(
102 basegfx::B2DRange(0.0,0.0,1.0,1.0),
103 1.0);
104 pFgLayer->updateBounds( pTestShape2 );
105 CPPUNIT_ASSERT_MESSAGE( "FG layer must resize!",
106 pFgLayer->commitBounds() );
109 void testBasics()
111 mpLayerManager->activate( false );
113 CPPUNIT_ASSERT_MESSAGE( "Un-added shape must have zero view layers",
114 mpTestShape->getViewLayers().empty() );
115 mpLayerManager->addShape(mpTestShape);
116 CPPUNIT_ASSERT_MESSAGE( "Adding a shape requires a LayerManager update",
117 mpLayerManager->isUpdatePending() );
119 // update does the delayed viewAdded call to the shape
120 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
121 mpLayerManager->update() );
122 CPPUNIT_ASSERT_MESSAGE( "Added shape must have one view layer",
123 mpTestShape->getViewLayers().size() == 1 );
124 CPPUNIT_ASSERT_MESSAGE( "Shape must been rendered",
125 mpTestShape->getNumRenders() );
126 CPPUNIT_ASSERT_MESSAGE( "Shape must not been updated",
127 !mpTestShape->getNumUpdates() );
129 // test second view, check whether shape gets additional view
130 TestViewSharedPtr pTestView( createTestView() );
131 CPPUNIT_ASSERT_MESSAGE( "Adding second View failed",
132 maViews.addView( pTestView ) );
133 CPPUNIT_ASSERT_MESSAGE( "View container must have two views",
134 maViews.end() - maViews.begin() == 2 );
135 mpLayerManager->viewAdded(pTestView);
136 CPPUNIT_ASSERT_MESSAGE( "Added shape must have two view layers",
137 mpTestShape->getViewLayers().size() == 2 );
139 CPPUNIT_ASSERT_MESSAGE( "Removing second View failed",
140 maViews.removeView( pTestView ) );
141 mpLayerManager->viewRemoved(pTestView);
142 CPPUNIT_ASSERT_MESSAGE( "Added shape must have one view layer",
143 mpTestShape->getViewLayers().size() == 1 );
145 mpLayerManager->deactivate();
148 void testShapeOrdering()
150 TestShapeSharedPtr pShape2( createTestShape(
151 basegfx::B2DRange(0.0,0.0,10.0,10.0),
152 2.0));
153 TestShapeSharedPtr pShape3( createTestShape(
154 basegfx::B2DRange(0.0,0.0,10.0,10.0),
155 3.0));
156 TestShapeSharedPtr pShape4( createTestShape(
157 basegfx::B2DRange(0.0,0.0,10.0,10.0),
158 4.0));
160 mpLayerManager->addShape(mpTestShape);
161 mpLayerManager->addShape(pShape2);
162 mpLayerManager->addShape(pShape3);
163 mpLayerManager->addShape(pShape4);
165 mpLayerManager->activate( false );
167 // update does the delayed viewAdded call to the shape
168 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
169 mpLayerManager->update() );
170 CPPUNIT_ASSERT_MESSAGE( "View must have background layer only",
171 mpTestView->getViewLayers().empty() );
173 // LayerManager must now generate one extra view layer
174 mpLayerManager->enterAnimationMode(pShape2);
175 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
176 mpLayerManager->isUpdatePending() );
177 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
178 mpLayerManager->update() );
179 CPPUNIT_ASSERT_MESSAGE( "View must have one extra layer only",
180 mpTestView->getViewLayers().size() == 1 );
181 CPPUNIT_ASSERT_MESSAGE( "View layer must have 10x10 size",
182 mpTestView->getViewLayers().at(0)->getBounds() ==
183 basegfx::B2DRange(0.0,0.0,10.0,10.0) );
185 // LayerManager must now remove the extra view layer
186 mpLayerManager->leaveAnimationMode(pShape2);
187 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
188 mpLayerManager->isUpdatePending() );
189 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager #2",
190 mpLayerManager->update() );
191 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must be on background layer",
192 mpTestShape->getViewLayers().at(0).first == mpTestView );
193 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must be on background layer",
194 pShape2->getViewLayers().at(0).first == mpTestView );
195 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have one layer",
196 pShape3->getViewLayers().size() == 1 );
197 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must be on background layer",
198 pShape3->getViewLayers().at(0).first == mpTestView );
199 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must be on background layer",
200 pShape4->getViewLayers().at(0).first == mpTestView );
202 // checking deactivation (all layers except background layer
203 // must vanish)
204 mpLayerManager->enterAnimationMode(pShape3);
205 CPPUNIT_ASSERT_MESSAGE( "No update pending on LayerManager",
206 mpLayerManager->isUpdatePending() );
207 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
208 mpLayerManager->update() );
209 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must not be on background layer",
210 pShape4->getViewLayers().at(0).first != mpTestView );
211 mpLayerManager->leaveAnimationMode(pShape3);
212 CPPUNIT_ASSERT_MESSAGE( "Update failed on LayerManager",
213 mpLayerManager->update() );
214 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must be on background layer",
215 pShape4->getViewLayers().at(0).first == mpTestView );
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->enterAnimationMode(pShape2);
240 mpLayerManager->addShape(pShape3);
241 mpLayerManager->addShape(pShape4);
242 mpLayerManager->addShape(pShape5);
244 mpLayerManager->activate( false );
245 mpLayerManager->update();
247 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered",
248 mpTestShape->getNumRenders() == 1 );
249 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
250 pShape2->getNumRenders() == 1 );
251 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered",
252 pShape3->getNumRenders() == 1 );
253 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered",
254 pShape4->getNumRenders() == 1 );
255 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered",
256 pShape5->getNumRenders() == 1 );
258 mpLayerManager->enterAnimationMode(pShape4);
259 mpLayerManager->update();
261 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered",
262 mpTestShape->getNumRenders() == 1 );
263 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered",
264 pShape2->getNumRenders() == 1 );
265 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered",
266 pShape3->getNumRenders() == 2 );
267 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered",
268 pShape4->getNumRenders() == 2 );
269 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered",
270 pShape5->getNumRenders() == 2 );
272 mpLayerManager->leaveAnimationMode(pShape2);
273 mpLayerManager->leaveAnimationMode(pShape4);
274 mpLayerManager->update();
276 CPPUNIT_ASSERT_MESSAGE( "First shape not rendered #2",
277 mpTestShape->getNumRenders() == 2 );
278 CPPUNIT_ASSERT_MESSAGE( "Second shape not rendered #2",
279 pShape2->getNumRenders() == 2 );
280 CPPUNIT_ASSERT_MESSAGE( "Third shape not rendered #2",
281 pShape3->getNumRenders() == 3 );
282 CPPUNIT_ASSERT_MESSAGE( "Fourth shape not rendered #2",
283 pShape4->getNumRenders() == 3 );
284 CPPUNIT_ASSERT_MESSAGE( "Fifth shape not rendered #2",
285 pShape5->getNumRenders() == 3 );
288 void testRefCounting()
290 TestShapeSharedPtr pShape2( createTestShape(
291 basegfx::B2DRange(0.0,0.0,10.0,10.0),
292 2.0));
293 TestShapeSharedPtr pShape3( createTestShape(
294 basegfx::B2DRange(0.0,0.0,10.0,10.0),
295 3.0));
296 TestShapeSharedPtr pShape4( createTestShape(
297 basegfx::B2DRange(0.0,0.0,10.0,10.0),
298 4.0));
300 mpLayerManager->addShape(mpTestShape);
301 mpLayerManager->addShape(pShape2);
302 mpLayerManager->addShape(pShape3);
303 mpLayerManager->addShape(pShape4);
305 mpLayerManager->removeShape(mpTestShape);
306 mpLayerManager->removeShape(pShape2);
307 mpLayerManager->removeShape(pShape3);
308 mpLayerManager->removeShape(pShape4);
310 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must have refcount of 1",
311 mpTestShape.use_count() == 1 );
312 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must have refcount of ",
313 pShape2.use_count() == 1 );
314 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have refcount of 1",
315 pShape3.use_count() == 1 );
316 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must have refcount of",
317 pShape4.use_count() == 1 );
320 mpLayerManager->addShape(mpTestShape);
321 mpLayerManager->addShape(pShape2);
322 mpLayerManager->addShape(pShape3);
323 mpLayerManager->addShape(pShape4);
325 mpLayerManager->activate( false );
326 mpLayerManager->update();
328 mpLayerManager->removeShape(mpTestShape);
329 mpLayerManager->removeShape(pShape2);
330 mpLayerManager->removeShape(pShape3);
331 mpLayerManager->removeShape(pShape4);
333 CPPUNIT_ASSERT_MESSAGE( "Shape 1 must have refcount of 1",
334 mpTestShape.use_count() == 1 );
335 CPPUNIT_ASSERT_MESSAGE( "Shape 2 must have refcount of ",
336 pShape2.use_count() == 1 );
337 CPPUNIT_ASSERT_MESSAGE( "Shape 3 must have refcount of 1",
338 pShape3.use_count() == 1 );
339 CPPUNIT_ASSERT_MESSAGE( "Shape 4 must have refcount of 1",
340 pShape4.use_count() == 1 );
342 maViews.removeView(mpTestView);
343 mpLayerManager->viewRemoved(mpTestView);
344 CPPUNIT_ASSERT_MESSAGE( "View must have refcount of 1",
345 mpTestView.use_count() == 1 );
348 // hook up the test
349 CPPUNIT_TEST_SUITE(LayerManagerTest);
350 CPPUNIT_TEST(testBasics);
351 CPPUNIT_TEST(testLayer);
352 CPPUNIT_TEST(testShapeOrdering);
353 CPPUNIT_TEST(testShapeRepaint);
354 CPPUNIT_TEST(testRefCounting);
355 CPPUNIT_TEST_SUITE_END();
357 }; // class LayerManagerTest
360 CPPUNIT_TEST_SUITE_REGISTRATION(LayerManagerTest);
361 } // namespace
363 CPPUNIT_PLUGIN_IMPLEMENT();
365 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */