nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / unit / scshapetest.cxx
blobff156cc65df38f4b7c0a193dfb39c83ed2a8593e
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/.
8 */
10 #include <sal/config.h>
12 #include <cstdlib>
14 #include <test/calc_unoapi_test.hxx>
16 #include <comphelper/dispatchcommand.hxx>
17 #include <comphelper/propertyvalue.hxx>
18 #include <sfx2/dispatch.hxx>
19 #include <sfx2/request.hxx>
20 #include <svx/svdoashp.hxx>
21 #include <svx/svdomeas.hxx>
22 #include <svx/svdpage.hxx>
23 #include <svx/svdorect.hxx>
24 #include <unotools/tempfile.hxx>
25 #include <vcl/keycodes.hxx>
27 #include <docsh.hxx>
28 #include <drwlayer.hxx>
29 #include <tabvwsh.hxx>
30 #include <userdat.hxx>
32 #include <sc.hrc> // defines of slot-IDs
34 using namespace css;
36 namespace sc_apitest
38 class ScShapeTest : public CalcUnoApiTest
40 public:
41 ScShapeTest();
42 void saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent,
43 const OUString& rFilter);
44 void testTdf143619_validation_circle_pos();
45 void testTdf137082_LTR_to_RTL();
46 void testTdf137082_RTL_cell_anchored();
47 void testTdf137081_RTL_page_anchored();
48 void testTdf139583_Rotate180deg();
49 void testTdf137033_FlipHori_Resize();
50 void testTdf137033_RotShear_ResizeHide();
51 void testTdf137033_RotShear_Hide();
52 // this test has starting failing under OSX
53 #if !defined MACOSX
54 void testTdf137576_LogicRectInDefaultMeasureline();
55 #endif
56 void testTdf137576_LogicRectInNewMeasureline();
57 void testMeasurelineHideColSave();
58 void testHideColsShow();
59 void testTdf138138_MoveCellWithRotatedShape();
60 void testLoadVerticalFlip();
61 void testTdf117948_CollapseBeforeShape();
62 void testTdf137355_UndoHideRows();
63 void testTdf115655_HideDetail();
64 void testFitToCellSize();
65 void testCustomShapeCellAnchoredRotatedShape();
67 CPPUNIT_TEST_SUITE(ScShapeTest);
68 CPPUNIT_TEST(testTdf143619_validation_circle_pos);
69 CPPUNIT_TEST(testTdf137082_LTR_to_RTL);
70 CPPUNIT_TEST(testTdf137082_RTL_cell_anchored);
71 CPPUNIT_TEST(testTdf137081_RTL_page_anchored);
72 CPPUNIT_TEST(testTdf139583_Rotate180deg);
73 CPPUNIT_TEST(testTdf137033_FlipHori_Resize);
74 CPPUNIT_TEST(testTdf137033_RotShear_ResizeHide);
75 CPPUNIT_TEST(testTdf137033_RotShear_Hide);
76 // this test has starting failing under OSX
77 #if !defined MACOSX
78 CPPUNIT_TEST(testTdf137576_LogicRectInDefaultMeasureline);
79 #endif
80 CPPUNIT_TEST(testTdf137576_LogicRectInNewMeasureline);
81 CPPUNIT_TEST(testMeasurelineHideColSave);
82 CPPUNIT_TEST(testHideColsShow);
83 CPPUNIT_TEST(testTdf138138_MoveCellWithRotatedShape);
84 CPPUNIT_TEST(testLoadVerticalFlip);
85 CPPUNIT_TEST(testTdf117948_CollapseBeforeShape);
86 CPPUNIT_TEST(testTdf137355_UndoHideRows);
87 CPPUNIT_TEST(testTdf115655_HideDetail);
88 CPPUNIT_TEST(testFitToCellSize);
89 CPPUNIT_TEST(testCustomShapeCellAnchoredRotatedShape);
90 CPPUNIT_TEST_SUITE_END();
93 ScShapeTest::ScShapeTest()
94 : CalcUnoApiTest("sc/qa/unit/data/ods")
98 void ScShapeTest::saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent,
99 const OUString& rFilter)
101 utl::TempFile aTempFile;
102 aTempFile.EnableKillingFile();
103 css::uno::Sequence<css::beans::PropertyValue> aArgs(1);
104 aArgs[0].Name = "FilterName";
105 aArgs[0].Value <<= rFilter; // e.g. "calc8"
106 css::uno::Reference<css::frame::XStorable> xStorable(xComponent, css::uno::UNO_QUERY_THROW);
107 xStorable->storeAsURL(aTempFile.GetURL(), aArgs);
108 css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW);
109 xCloseable->close(true);
111 xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument");
114 static void lcl_AssertRectEqualWithTolerance(const OString& sInfo,
115 const tools::Rectangle& rExpected,
116 const tools::Rectangle& rActual,
117 const sal_Int32 nTolerance)
119 // Left
120 OString sMsg = sInfo + " Left expected " + OString::number(rExpected.Left()) + " actual "
121 + OString::number(rActual.Left()) + " Tolerance " + OString::number(nTolerance);
122 CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(),
123 std::abs(rExpected.Left() - rActual.Left()) <= nTolerance);
125 // Top
126 sMsg = sInfo + " Top expected " + OString::number(rExpected.Top()) + " actual "
127 + OString::number(rActual.Top()) + " Tolerance " + OString::number(nTolerance);
128 CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), std::abs(rExpected.Top() - rActual.Top()) <= nTolerance);
130 // Width
131 sMsg = sInfo + " Width expected " + OString::number(rExpected.GetWidth()) + " actual "
132 + OString::number(rActual.GetWidth()) + " Tolerance " + OString::number(nTolerance);
133 CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(),
134 std::abs(rExpected.GetWidth() - rActual.GetWidth()) <= nTolerance);
136 // Height
137 sMsg = sInfo + " Height expected " + OString::number(rExpected.GetHeight()) + " actual "
138 + OString::number(rActual.GetHeight()) + " Tolerance " + OString::number(nTolerance);
139 CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(),
140 std::abs(rExpected.GetHeight() - rActual.GetHeight()) <= nTolerance);
143 static void lcl_AssertPointEqualWithTolerance(const OString& sInfo, const Point rExpected,
144 const Point rActual, const sal_Int32 nTolerance)
146 // X
147 OString sMsg = sInfo + " X expected " + OString::number(rExpected.X()) + " actual "
148 + OString::number(rActual.X()) + " Tolerance " + OString::number(nTolerance);
149 CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), std::abs(rExpected.X() - rActual.X()) <= nTolerance);
150 // Y
151 sMsg = sInfo + " Y expected " + OString::number(rExpected.Y()) + " actual "
152 + OString::number(rActual.Y()) + " Tolerance " + OString::number(nTolerance);
153 CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), std::abs(rExpected.Y() - rActual.Y()) <= nTolerance);
156 static ScDocShell*
157 lcl_getScDocShellWithAssert(css::uno::Reference<css::lang::XComponent>& xComponent)
159 SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
160 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
161 ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
162 CPPUNIT_ASSERT(pDocSh);
163 return pDocSh;
166 static ScTabViewShell* lcl_getScTabViewShellWithAssert(ScDocShell* pDocSh)
168 ScTabViewShell* pTabViewShell = pDocSh->GetBestViewShell(false);
169 CPPUNIT_ASSERT_MESSAGE("No ScTabViewShell", pTabViewShell);
170 return pTabViewShell;
173 static SdrPage* lcl_getSdrPageWithAssert(ScDocument& rDoc)
175 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
176 CPPUNIT_ASSERT_MESSAGE("No ScDrawLayer", pDrawLayer);
177 SdrPage* pPage = pDrawLayer->GetPage(0);
178 CPPUNIT_ASSERT_MESSAGE("No draw page", pPage);
179 return pPage;
182 static SdrObject* lcl_getSdrObjectWithAssert(ScDocument& rDoc, sal_uInt16 nObjNumber)
184 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
185 CPPUNIT_ASSERT_MESSAGE("No ScDrawLayer", pDrawLayer);
186 const SdrPage* pPage = pDrawLayer->GetPage(0);
187 CPPUNIT_ASSERT_MESSAGE("No draw page", pPage);
188 SdrObject* pObj = pPage->GetObj(nObjNumber);
189 OString sMsg = "no Object " + OString::number(nObjNumber);
190 CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), pObj);
191 return pObj;
194 void ScShapeTest::testTdf143619_validation_circle_pos()
196 // Load a document, which has validation circle around cell E6.
198 OUString aFileURL;
199 createFileURL(u"tdf143619_validationCirclePos.ods", aFileURL);
200 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
202 // Get document
203 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
204 ScDocument& rDoc = pDocSh->GetDocument();
206 // Get shape. That is the validation circle.
207 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
209 // Error was, that deleting row and col before E6 does not move circle to D5, but to B3.
210 // Delete first row and first column.
211 uno::Sequence<beans::PropertyValue> aPropertyValues = {
212 comphelper::makePropertyValue("ToPoint", OUString("$A$1")),
214 dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues);
215 dispatchCommand(xComponent, ".uno:DeleteRows", {});
216 dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues);
217 dispatchCommand(xComponent, ".uno:DeleteColumns", {});
219 // Without fix in place the position was (2007, 833)
220 Point aPos = pObj->GetSnapRect().TopLeft();
221 lcl_AssertPointEqualWithTolerance("after row and col delete", Point(6523, 1736), aPos, 1);
223 pDocSh->DoClose();
226 void ScShapeTest::testTdf137082_LTR_to_RTL()
228 // Before the fix for tdf137081 and tdf137082, when flipping sheet from LTR to RTL, page anchored
229 // shapes were mirrored, but cell anchored shapes not. This was changed so, that shapes are always
230 // mirrored. Graphics are still not mirrored but shifted. This test makes sure a shape is mirrored
231 // and an image is not mirrored.
233 OUString aFileURL;
234 createFileURL(u"tdf137082_LTR_arrow_image.ods", aFileURL);
235 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
236 CPPUNIT_ASSERT(xComponent.is());
238 // Get document
239 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
240 ScDocument& rDoc = pDocSh->GetDocument();
242 // Get objects and their transformation angles
243 SdrObject* pObjCS = lcl_getSdrObjectWithAssert(rDoc, 0);
244 const tools::Long nRotateLTR = pObjCS->GetRotateAngle();
245 SdrObject* pObjImage = lcl_getSdrObjectWithAssert(rDoc, 1);
246 const tools::Long nShearLTR = pObjImage->GetShearAngle();
248 // Switch to RTL
249 ScTabViewShell* pViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
250 pViewShell->GetViewData().GetDispatcher().Execute(FID_TAB_RTL);
252 // Check custom shape is mirrored, image not.
253 const tools::Long nShearRTLActual = pObjImage->GetShearAngle();
254 CPPUNIT_ASSERT_EQUAL_MESSAGE("image should not be mirrored", nShearLTR, nShearRTLActual);
255 const tools::Long nRotateRTLExpected = 36000.00 - nRotateLTR;
256 const tools::Long nRotateRTLActual = pObjCS->GetRotateAngle();
257 CPPUNIT_ASSERT_EQUAL_MESSAGE("custom shape should be mirrored", nRotateRTLExpected,
258 nRotateRTLActual);
260 pDocSh->DoClose();
263 void ScShapeTest::testTdf137082_RTL_cell_anchored()
265 // Error was, that cell anchored custom shapes wrote wrong offsets to file and thus were wrong on
266 // reloading. The file contains one custome shape with "resize" and another one without.
267 OUString aFileURL;
268 createFileURL(u"tdf137082_RTL_cell_anchored.ods", aFileURL);
269 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
270 CPPUNIT_ASSERT(xComponent.is());
272 // Get document
273 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
274 ScDocument& rDoc = pDocSh->GetDocument();
276 // Expected values.
277 const Point aTopLeftA(-20500, 3500); // shape A without "resize"
278 const Point aTopLeftB(-9500, 3500); // shape B with "resize"
279 const Size aSize(2278, 5545); // both
280 const tools::Rectangle aSnapRectA(aTopLeftA, aSize);
281 const tools::Rectangle aSnapRectB(aTopLeftB, aSize);
283 // Test reading was correct
284 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
285 lcl_AssertRectEqualWithTolerance("load shape A: ", aSnapRectA, pObj->GetSnapRect(), 1);
286 pObj = lcl_getSdrObjectWithAssert(rDoc, 1);
287 lcl_AssertRectEqualWithTolerance("load shape B: ", aSnapRectB, pObj->GetSnapRect(), 1);
289 // Save and reload.
290 saveAndReload(xComponent, "calc8");
291 CPPUNIT_ASSERT(xComponent);
293 // Get document
294 pDocSh = lcl_getScDocShellWithAssert(xComponent);
295 ScDocument& rDoc2 = pDocSh->GetDocument();
297 // And test again
298 pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
299 lcl_AssertRectEqualWithTolerance("reload shape A: ", aSnapRectA, pObj->GetSnapRect(), 1);
300 pObj = lcl_getSdrObjectWithAssert(rDoc2, 1);
301 lcl_AssertRectEqualWithTolerance("reload shape B: ", aSnapRectB, pObj->GetSnapRect(), 1);
303 pDocSh->DoClose();
306 void ScShapeTest::testTdf137081_RTL_page_anchored()
308 // Error was, that page anchored lines and custom shapes were mirrored on opening. The document
309 // contains measure line, polyline and transformed custom shape.
310 OUString aFileURL;
311 createFileURL(u"tdf137081_RTL_page_anchored.ods", aFileURL);
312 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
313 CPPUNIT_ASSERT(xComponent.is());
315 // Get document
316 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
317 ScDocument& rDoc = pDocSh->GetDocument();
319 // Expected values.
320 // Measure line
321 const Point aStart(-3998, 2490);
322 const Point aEnd(-8488, 5490);
323 // Polyline
324 const Point aFirst(-10010, 2500);
325 const Point aSecond(-14032, 5543);
326 const Point aThird(-14500, 3500);
327 // Custom shape
328 const Point aTopLeft(-20500, 4583);
330 // Test reading was correct
331 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
332 // Measure line
333 lcl_AssertPointEqualWithTolerance("measure line start", aStart, pObj->GetPoint(0), 1);
334 lcl_AssertPointEqualWithTolerance("measure line end", aEnd, pObj->GetPoint(1), 1);
335 // Polyline
336 pObj = lcl_getSdrObjectWithAssert(rDoc, 1);
337 lcl_AssertPointEqualWithTolerance("polyline 1: ", aFirst, pObj->GetPoint(0), 1);
338 lcl_AssertPointEqualWithTolerance("polyline 2: ", aSecond, pObj->GetPoint(1), 1);
339 lcl_AssertPointEqualWithTolerance("polyline 3: ", aThird, pObj->GetPoint(2), 1);
340 //Custom shape
341 SdrObjCustomShape* pObjCS
342 = static_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc, 2));
343 CPPUNIT_ASSERT(!pObjCS->IsMirroredX());
344 lcl_AssertPointEqualWithTolerance("custom shape top left: ", aTopLeft,
345 pObjCS->GetLogicRect().TopLeft(), 1);
347 // Save and reload.
348 saveAndReload(xComponent, "calc8");
349 CPPUNIT_ASSERT(xComponent);
351 // Get document
352 pDocSh = lcl_getScDocShellWithAssert(xComponent);
353 ScDocument& rDoc2 = pDocSh->GetDocument();
355 // And test again
356 pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
357 // Measure line
358 lcl_AssertPointEqualWithTolerance("measure line start", aStart, pObj->GetPoint(0), 1);
359 lcl_AssertPointEqualWithTolerance("measure line end", aEnd, pObj->GetPoint(1), 1);
360 // Polyline
361 pObj = lcl_getSdrObjectWithAssert(rDoc2, 1);
362 lcl_AssertPointEqualWithTolerance("polyline 1: ", aFirst, pObj->GetPoint(0), 1);
363 lcl_AssertPointEqualWithTolerance("polyline 2: ", aSecond, pObj->GetPoint(1), 1);
364 lcl_AssertPointEqualWithTolerance("polyline 3: ", aThird, pObj->GetPoint(2), 1);
365 //Custom shape
366 pObjCS = static_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc2, 2));
367 CPPUNIT_ASSERT(!pObjCS->IsMirroredX());
368 lcl_AssertPointEqualWithTolerance("custom shape top left: ", aTopLeft,
369 pObjCS->GetLogicRect().TopLeft(), 1);
371 pDocSh->DoClose();
374 void ScShapeTest::testTdf139583_Rotate180deg()
376 // Load an empty document.
377 OUString aFileURL;
378 createFileURL(u"ManualColWidthRowHeight.ods", aFileURL);
379 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
380 CPPUNIT_ASSERT(xComponent.is());
382 // Get document and draw page
383 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
384 ScDocument& rDoc = pDocSh->GetDocument();
385 SdrPage* pPage = lcl_getSdrPageWithAssert(rDoc);
387 // Insert Shape
388 const tools::Rectangle aRect(Point(3000, 4000), Size(5000, 2000));
389 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
390 CPPUNIT_ASSERT_MESSAGE("No ScDrawLayer", pDrawLayer);
391 SdrRectObj* pObj = new SdrRectObj(*pDrawLayer, aRect);
392 CPPUNIT_ASSERT_MESSAGE("Could not create rectangle", pObj);
393 pPage->InsertObject(pObj);
395 // Anchor "to cell (resize with cell)" and then rotate it by 180deg around center
396 // The order is important here.
397 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0 /*SCTAB*/, true /*bResizeWithCell*/);
398 pObj->Rotate(aRect.Center(), 18000.0, 0.0, -1.0);
400 // Save and reload.
401 saveAndReload(xComponent, "calc8");
402 CPPUNIT_ASSERT(xComponent);
404 // Get document and object
405 pDocSh = lcl_getScDocShellWithAssert(xComponent);
406 ScDocument& rDoc2 = pDocSh->GetDocument();
407 pObj = static_cast<SdrRectObj*>(lcl_getSdrObjectWithAssert(rDoc2, 0));
409 // Without the fix in place, the shape would have nearly zero size.
410 lcl_AssertRectEqualWithTolerance("Show: Object geometry should not change", aRect,
411 pObj->GetSnapRect(), 1);
414 void ScShapeTest::testTdf137033_FlipHori_Resize()
416 // Load a document, which has a rotated custom shape, which is horizontal flipped. Error was, that
417 // if such shape was anchored "resize with cell", then after save and reload it was destorted.
418 OUString aFileURL;
419 createFileURL("tdf137033_FlipHoriRotCustomShape.ods", aFileURL);
420 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
421 CPPUNIT_ASSERT(xComponent.is());
423 // Get document and shape
424 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
425 ScDocument& rDoc = pDocSh->GetDocument();
426 SdrObjCustomShape* pObj = static_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc, 0));
428 // Verify shape is correctly loaded. Then set shape to "resize with cell".
429 tools::Rectangle aSnapRect(pObj->GetSnapRect());
430 const tools::Rectangle aExpectRect(Point(4998, 7000), Size(9644, 6723));
431 lcl_AssertRectEqualWithTolerance("Load, wrong pos or size: ", aExpectRect, aSnapRect, 1);
432 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0 /*SCTAB*/, true /*bResizeWithCell*/);
434 // Save and reload.
435 saveAndReload(xComponent, "calc8");
436 CPPUNIT_ASSERT(xComponent);
438 // Get document and shape
439 pDocSh = lcl_getScDocShellWithAssert(xComponent);
440 ScDocument& rDoc2 = pDocSh->GetDocument();
441 pObj = static_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc2, 0));
443 // Check shape has the original geometry, besides rounding and unit conversion errors
444 aSnapRect = pObj->GetSnapRect();
445 lcl_AssertRectEqualWithTolerance("Reload, wrong pos or size: ", aExpectRect, aSnapRect, 1);
447 pDocSh->DoClose();
450 void ScShapeTest::testTdf137033_RotShear_ResizeHide()
452 // For rotated or sheared shapes anchored "To Cell (resize with cell) hiding rows or columns will
453 // not only change size but rotation and shear angle too. Error was, that not the original angles
454 // of the full sized shape were written to file but the changed one.
456 // Load a document, which has a rotated and sheared shape, anchored to cell with resize.
457 OUString aFileURL;
458 createFileURL("tdf137033_RotShearResizeAnchor.ods", aFileURL);
459 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
460 CPPUNIT_ASSERT(xComponent.is());
462 // Get document
463 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
464 ScDocument& rDoc = pDocSh->GetDocument();
466 // Hide rows 4 and 5 (UI number), which are inside the shape and thus change shape geometry
467 rDoc.SetRowHidden(3, 4, 0, true);
468 rDoc.SetDrawPageSize(0); // trigger recalcpos, otherwise shapes are not changed
470 // Get shape
471 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
473 // Verify hiding has changed shape geometry as expected
474 tools::Rectangle aSnapRect(pObj->GetSnapRect());
475 tools::Long aRotateAngle(pObj->GetRotateAngle());
476 tools::Long aShearAngle(pObj->GetShearAngle());
477 // mathematical exact would be Point(3868, 4795), Size(9763, 1909)
478 // current values as of LO 7.2
479 const tools::Rectangle aExpectRect(Point(3871, 4796), Size(9764, 1910));
480 const tools::Long aExpectRotateAngle(20923);
481 const tools::Long aExpectShearAngle(-6572);
482 CPPUNIT_ASSERT_MESSAGE("Hide rows, shear angle: ", abs(aShearAngle - aExpectShearAngle) <= 1);
483 CPPUNIT_ASSERT_MESSAGE("Hide rows, rotate angle: ",
484 abs(aRotateAngle - aExpectRotateAngle) <= 1);
485 lcl_AssertRectEqualWithTolerance("Reload: wrong pos or size", aExpectRect, aSnapRect, 1);
487 // Save and reload.
488 saveAndReload(xComponent, "calc8");
489 CPPUNIT_ASSERT(xComponent);
491 // Get document and shape
492 pDocSh = lcl_getScDocShellWithAssert(xComponent);
493 ScDocument& rDoc2 = pDocSh->GetDocument();
494 pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
496 // Check shape has the original geometry, besides heavy rounding and unit conversion errors
497 aSnapRect = pObj->GetSnapRect();
498 aRotateAngle = pObj->GetRotateAngle();
499 aShearAngle = pObj->GetShearAngle();
500 CPPUNIT_ASSERT_MESSAGE("Reload, shear angle: ", abs(aShearAngle - aExpectShearAngle) <= 3);
501 CPPUNIT_ASSERT_MESSAGE("Reload, rotate angle: ", abs(aRotateAngle - aExpectRotateAngle) <= 3);
502 lcl_AssertRectEqualWithTolerance("Reload: wrong pos or size", aExpectRect, aSnapRect, 4);
504 pDocSh->DoClose();
507 void ScShapeTest::testTdf137033_RotShear_Hide()
509 // Hiding row or columns affect cell anchored shape based on their snap rectangle. The first
510 // attempt to fix lost position has used the logic rect instead. For rotated or sheared shape it
511 // makes a difference.
513 // Load a document, which has a rotated and sheared shape, anchored to cell, without resize.
514 OUString aFileURL;
515 createFileURL("tdf137033_RotShearCellAnchor.ods", aFileURL);
516 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
517 CPPUNIT_ASSERT(xComponent.is());
519 // Get document
520 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
521 ScDocument& rDoc = pDocSh->GetDocument();
523 // Hide column C, which is left from logic rect, but right from left edge of snap rect
524 rDoc.SetColHidden(2, 2, 0, true);
525 rDoc.SetDrawPageSize(0); // trigger recalcpos, otherwise shapes are not changed
527 // Save and reload.
528 saveAndReload(xComponent, "calc8");
529 CPPUNIT_ASSERT(xComponent);
531 // Get document and shape
532 pDocSh = lcl_getScDocShellWithAssert(xComponent);
533 ScDocument& rDoc2 = pDocSh->GetDocument();
534 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
536 // Check shape is visible. With the old version, the shape was moved to column C and
537 // thus hidden on reload.
538 CPPUNIT_ASSERT_MESSAGE("Reload: Shape has to be visible", pObj->IsVisible());
539 // Verify position and size are unchanged besides rounding and unit conversion errors
540 // Values are manually taken from shape before hiding column C.
541 const tools::Rectangle aExpectRect(Point(4500, 3500), Size(15143, 5187));
542 const tools::Rectangle aSnapRect = pObj->GetSnapRect();
543 lcl_AssertRectEqualWithTolerance("Reload: wrong pos and size", aExpectRect, aSnapRect, 1);
545 pDocSh->DoClose();
548 // this test has starting failing under OSX
549 #if !defined MACOSX
550 void ScShapeTest::testTdf137576_LogicRectInDefaultMeasureline()
552 // Error was, that the empty logical rectangle of a default measure line (Ctrl+Click)
553 // resulted in zeros in NonRotatedAnchor and a wrong position when reloading.
555 // Load an empty document.
556 OUString aFileURL;
557 createFileURL("ManualColWidthRowHeight.ods", aFileURL);
558 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
559 CPPUNIT_ASSERT(xComponent.is());
561 // Get ScDocShell
562 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
564 // Create default measureline by SfxRequest that corresponds to Ctrl+Click
565 ScTabViewShell* pTabViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
566 SfxRequest aReq(pTabViewShell->GetViewFrame(), SID_DRAW_MEASURELINE);
567 aReq.SetModifier(KEY_MOD1); // Ctrl
568 pTabViewShell->ExecDraw(aReq);
570 // Get document and newly created measure line.
571 ScDocument& rDoc = pDocSh->GetDocument();
572 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
574 // Anchor "to Cell (resize with cell)"
575 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0 /*SCTAB*/, true /*bResizeWithCell*/);
576 // Deselect shape and switch to object selection type "Cell".
577 pTabViewShell->SetDrawShell(false);
579 // Hide column A.
580 uno::Sequence<beans::PropertyValue> aPropertyValues = {
581 comphelper::makePropertyValue("ToPoint", OUString("$A$1")),
583 dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues);
584 dispatchCommand(xComponent, ".uno:HideColumn", {});
586 // Get current position. I will not use absolute values for comparison, because document is loaded
587 // in full screen mode of unknown size and default object is placed in center of window.
588 Point aOldPos = pObj->GetRelativePos();
590 // Save and reload, get ScDocShell
591 saveAndReload(xComponent, "calc8");
592 CPPUNIT_ASSERT(xComponent);
593 pDocSh = lcl_getScDocShellWithAssert(xComponent);
595 // Get document and object
596 ScDocument& rDoc2 = pDocSh->GetDocument();
597 pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
599 // Assert object position is unchanged, besides Twips<->Hmm inaccuracy.
600 Point aNewPos = pObj->GetRelativePos();
601 lcl_AssertPointEqualWithTolerance("after reload", aOldPos, aNewPos, 1);
603 pDocSh->DoClose();
605 #endif
607 void ScShapeTest::testTdf137576_LogicRectInNewMeasureline()
609 // Error was, that a new measure line had no logical rectangle. This resulted in zeros in
610 // NonRotatedAnchor. As a result the position was wrong when reloading.
612 // Load an empty document
613 OUString aFileURL;
614 createFileURL("ManualColWidthRowHeight.ods", aFileURL);
615 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
616 CPPUNIT_ASSERT(xComponent.is());
618 // Get document and draw page
619 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
620 ScDocument& rDoc = pDocSh->GetDocument();
621 SdrPage* pPage = lcl_getSdrPageWithAssert(rDoc);
623 // Create a new measure line and insert it
624 Point aStartPoint(5000, 5500);
625 Point aEndPoint(13000, 8000);
626 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
627 CPPUNIT_ASSERT_MESSAGE("No ScDrawLayer", pDrawLayer);
628 SdrMeasureObj* pObj = new SdrMeasureObj(*pDrawLayer, aStartPoint, aEndPoint);
629 CPPUNIT_ASSERT_MESSAGE("Could not create measure line", pObj);
630 pPage->InsertObject(pObj);
632 // Anchor "to cell (resize with cell)" and examine NonRotatedAnchor
633 ScDrawLayer::SetCellAnchoredFromPosition(*pObj, rDoc, 0 /*SCTAB*/, true /*bResizeWithCell*/);
634 ScDrawObjData* pNData = ScDrawLayer::GetNonRotatedObjData(pObj);
635 CPPUNIT_ASSERT_MESSAGE("Failed to get NonRotatedAnchor", pNData);
636 // Without the fix all four values would be zero.
637 CPPUNIT_ASSERT(pNData->maStart.Col() == 1 && pNData->maStart.Row() == 2);
638 CPPUNIT_ASSERT(pNData->maEnd.Col() == 7 && pNData->maEnd.Row() == 2);
640 pDocSh->DoClose();
643 void ScShapeTest::testMeasurelineHideColSave()
645 // The document contains a SdrMeasureObj anchored "To Cell (resive with cell)" with start in cell
646 // D11 and end in cell I5. Error was, that after hiding col A and saving, start and end point
647 // position were lost.
648 OUString aFileURL;
649 createFileURL("measurelineHideColSave.ods", aFileURL);
650 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
651 CPPUNIT_ASSERT(xComponent.is());
653 // Get document and shape
654 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
655 ScDocument& rDoc = pDocSh->GetDocument();
656 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
658 // Make sure loading is correct
659 Point aStartPoint(7500, 15000); // according UI
660 Point aEndPoint(17500, 8000);
661 lcl_AssertPointEqualWithTolerance("Load start: ", aStartPoint, pObj->GetPoint(0), 1);
662 lcl_AssertPointEqualWithTolerance("Load end: ", aEndPoint, pObj->GetPoint(1), 1);
664 // Hide column A
665 rDoc.SetColHidden(0, 0, 0, true);
666 rDoc.SetDrawPageSize(0); // trigger recalcpos, otherwise shapes are not changed
667 // Shape should move by column width, here 3000
668 aStartPoint.Move(-3000, 0);
669 aEndPoint.Move(-3000, 0);
670 lcl_AssertPointEqualWithTolerance("Hide col A: ", aStartPoint, pObj->GetPoint(0), 1);
671 lcl_AssertPointEqualWithTolerance("Hide col A: ", aEndPoint, pObj->GetPoint(1), 1);
673 // save and reload
674 saveAndReload(xComponent, "calc8");
675 CPPUNIT_ASSERT(xComponent);
677 // Get document and shape
678 pDocSh = lcl_getScDocShellWithAssert(xComponent);
679 ScDocument& rDoc2 = pDocSh->GetDocument();
680 pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
682 // Check that start and end point are unchanged besides rounding and unit conversion errors
683 lcl_AssertPointEqualWithTolerance("Reload start: ", aStartPoint, pObj->GetPoint(0), 2);
684 lcl_AssertPointEqualWithTolerance("Reload end: ", aEndPoint, pObj->GetPoint(1), 2);
686 pDocSh->DoClose();
689 void ScShapeTest::testHideColsShow()
691 // The document contains a shape anchored "To Cell (resize with cell)" with starts in cell C3 and
692 //ends in cell D5. Error was, that hiding cols C and D and then show them again extends the shape
693 // to column E
695 OUString aFileURL;
696 createFileURL("hideColsShow.ods", aFileURL);
697 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
698 CPPUNIT_ASSERT(xComponent.is());
700 // Get document and shape
701 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
702 ScDocument& rDoc = pDocSh->GetDocument();
703 SdrObjCustomShape* pObj = static_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc, 0));
705 CPPUNIT_ASSERT_MESSAGE("Load: Object should be visible", pObj->IsVisible());
706 tools::Rectangle aSnapRectOrig(pObj->GetSnapRect());
708 // Hide cols C and D.
709 uno::Sequence<beans::PropertyValue> aPropertyValues = {
710 comphelper::makePropertyValue("ToPoint", OUString("$C$1:$D$1")),
712 dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues);
714 ScTabViewShell* pViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
715 pViewShell->GetViewData().GetDispatcher().Execute(FID_COL_HIDE);
717 // Check object is invisible
718 CPPUNIT_ASSERT_MESSAGE("Hide: Object should be invisible", !pObj->IsVisible());
720 // Show cols C and D
721 aPropertyValues = {
722 comphelper::makePropertyValue("ToPoint", OUString("$C$1:$D$1")),
724 dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues);
725 pViewShell->GetViewData().GetDispatcher().Execute(FID_COL_SHOW);
727 // Check object is visible and has old size
728 CPPUNIT_ASSERT_MESSAGE("Show: Object should be visible", pObj->IsVisible());
729 tools::Rectangle aSnapRectShow(pObj->GetSnapRect());
730 lcl_AssertRectEqualWithTolerance("Show: Object geometry should not change", aSnapRectOrig,
731 aSnapRectShow, 1);
733 pDocSh->DoClose();
736 void ScShapeTest::testTdf138138_MoveCellWithRotatedShape()
738 // The document contains a 90deg rotated, cell-anchored rectangle in column D. Insert 2 columns
739 // after column B, save and reload. The shape was not correctly moved to column F.
740 OUString aFileURL;
741 createFileURL("tdf138138_MoveCellWithRotatedShape.ods", aFileURL);
742 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
743 CPPUNIT_ASSERT(xComponent.is());
745 // Get document and shape
746 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
747 ScDocument& rDoc = pDocSh->GetDocument();
748 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
750 // Check anchor and position of shape. The expected values are taken from UI.
751 tools::Rectangle aSnapRect = pObj->GetSnapRect();
752 tools::Rectangle aExpectedRect(Point(10000, 3000), Size(1000, 7500));
753 lcl_AssertRectEqualWithTolerance("Load original: ", aExpectedRect, aSnapRect, 1);
755 // Insert two columns after column B
756 uno::Sequence<beans::PropertyValue> aPropertyValues = {
757 comphelper::makePropertyValue("ToPoint", OUString("$A$1:$B$1")),
759 dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues);
761 ScTabViewShell* pViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
762 pViewShell->GetViewData().GetDispatcher().Execute(FID_INS_COLUMNS_AFTER);
763 aExpectedRect = tools::Rectangle(Point(16000, 3000), Size(1000, 7500)); // col width 3000
764 aSnapRect = pObj->GetSnapRect();
765 lcl_AssertRectEqualWithTolerance("Shift: Wrong after insert of columns ", aExpectedRect,
766 aSnapRect, 1);
768 // Save and reload
769 saveAndReload(xComponent, "calc8");
770 CPPUNIT_ASSERT(xComponent);
772 // Get document and shape
773 pDocSh = lcl_getScDocShellWithAssert(xComponent);
774 ScDocument& rDoc2 = pDocSh->GetDocument();
775 pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
777 // Assert objects size is unchanged, position is shifted.
778 aSnapRect = pObj->GetSnapRect();
779 lcl_AssertRectEqualWithTolerance("Reload: Shape geometry has changed.", aExpectedRect,
780 aSnapRect, 1);
782 pDocSh->DoClose();
785 void ScShapeTest::testLoadVerticalFlip()
787 // The document has a cell anchored custom shape with vertical flip. Error was, that the
788 // flip was lost on loading.
789 OUString aFileURL;
790 createFileURL("loadVerticalFlip.ods", aFileURL);
791 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
792 CPPUNIT_ASSERT(xComponent.is());
794 // Get document and shape
795 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
796 ScDocument& rDoc = pDocSh->GetDocument();
797 SdrObjCustomShape* pObj = static_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc, 0));
799 // Check that shape is flipped
800 CPPUNIT_ASSERT_MESSAGE("Load: Object should be vertically flipped", pObj->IsMirroredY());
802 pDocSh->DoClose();
805 void ScShapeTest::testTdf117948_CollapseBeforeShape()
807 // The document contains a column group left from the image. The group is expanded. Collapse the
808 // group, save and reload. The original error was, that the line was on wrong position after reload.
809 // After the fix for 'resize with cell', the custom shape had wrong position and size too.
810 OUString aFileURL;
811 createFileURL("tdf117948_CollapseBeforeShape.ods", aFileURL);
812 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
813 CPPUNIT_ASSERT(xComponent.is());
815 // Get document and objects
816 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
817 ScDocument& rDoc = pDocSh->GetDocument();
818 SdrObject* pObj0 = lcl_getSdrObjectWithAssert(rDoc, 0);
819 SdrObject* pObj1 = lcl_getSdrObjectWithAssert(rDoc, 1);
821 // Collapse the group
822 ScTabViewShell* pViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
823 pViewShell->GetViewData().SetCurX(1);
824 pViewShell->GetViewData().SetCurY(0);
825 pViewShell->GetViewData().GetDispatcher().Execute(SID_OUTLINE_HIDE);
827 // Check anchor and position of shape. The expected values are taken from UI before saving.
828 tools::Rectangle aSnapRect0Collapse = pObj0->GetSnapRect();
829 tools::Rectangle aExpectedRect0(Point(4672, 1334), Size(1787, 1723));
830 lcl_AssertRectEqualWithTolerance("Collapse: Custom shape", aExpectedRect0, aSnapRect0Collapse,
832 tools::Rectangle aSnapRect1Collapse = pObj1->GetSnapRect();
833 tools::Rectangle aExpectedRect1(Point(5647, 4172), Size(21, 3441));
834 lcl_AssertRectEqualWithTolerance("Collapse: Line", aExpectedRect1, aSnapRect1Collapse, 1);
836 // Save and reload
837 saveAndReload(xComponent, "calc8");
838 CPPUNIT_ASSERT(xComponent);
840 // Get document and objects
841 pDocSh = lcl_getScDocShellWithAssert(xComponent);
842 ScDocument& rDoc2 = pDocSh->GetDocument();
843 pObj0 = lcl_getSdrObjectWithAssert(rDoc2, 0);
844 pObj1 = lcl_getSdrObjectWithAssert(rDoc2, 1);
846 // Assert objects size and position are not changed. Actual values differ a little bit
847 // because of cumulated Twips-Hmm conversion errors.
848 tools::Rectangle aSnapRect0Reload = pObj0->GetSnapRect();
849 lcl_AssertRectEqualWithTolerance("Reload: Custom shape geometry has changed.", aExpectedRect0,
850 aSnapRect0Reload, 2);
852 tools::Rectangle aSnapRect1Reload = pObj1->GetSnapRect();
853 lcl_AssertRectEqualWithTolerance("Reload: Line geometry has changed.", aExpectedRect1,
854 aSnapRect1Reload, 2);
856 pDocSh->DoClose();
859 void ScShapeTest::testTdf137355_UndoHideRows()
861 // The document contains a shape anchored "To Cell" with start in cell C3 and end in cell D6.
862 // Error was, that hiding rows 3 to 6 and undo that action "lost" the shape.
863 // Actually it was not lost but hidden.
864 OUString aFileURL;
865 createFileURL("tdf137355_UndoHideRows.ods", aFileURL);
866 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
867 CPPUNIT_ASSERT(xComponent.is());
869 // Get document and shape
870 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
871 ScDocument& rDoc = pDocSh->GetDocument();
872 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
874 CPPUNIT_ASSERT_MESSAGE("Load: Object should be visible", pObj->IsVisible());
875 tools::Rectangle aSnapRectOrig(pObj->GetSnapRect());
877 // Hide rows 3 to 6 in UI. [Note: Simple rDoc.SetRowHidden(2,5,0,true) does not work, because it
878 // does not produce the needed undo items.]
879 uno::Sequence<beans::PropertyValue> aPropertyValues = {
880 comphelper::makePropertyValue("ToPoint", OUString("$A$3:$A$6")),
882 dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues);
883 ScTabViewShell* pViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
884 pViewShell->GetViewData().GetDispatcher().Execute(FID_ROW_HIDE);
886 // Check object is invisible
887 CPPUNIT_ASSERT_MESSAGE("Hide: Object should be invisible", !pObj->IsVisible());
889 // Undo
890 pViewShell->GetViewData().GetDispatcher().Execute(SID_UNDO);
892 // Check object is visible and has old size
893 CPPUNIT_ASSERT_MESSAGE("Undo: Object should exist", pObj);
894 CPPUNIT_ASSERT_MESSAGE("Undo: Object should be visible", pObj->IsVisible());
895 tools::Rectangle aSnapRectUndo(pObj->GetSnapRect());
896 lcl_AssertRectEqualWithTolerance("Undo: Object geometry should not change", aSnapRectOrig,
897 aSnapRectUndo, 1);
899 pDocSh->DoClose();
902 void ScShapeTest::testTdf115655_HideDetail()
904 // The document contains an image inside a cell anchored "To Cell (resize with cell)". The cell
905 // belongs to a group. On loading the group is expanded.
906 // Error was, that after collapsing the group, save and reload, and expanding the group, the image
907 // was "lost". Actually is was resized to zero height.
908 OUString aFileURL;
909 createFileURL("tdf115655_HideDetail.ods", aFileURL);
910 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
911 CPPUNIT_ASSERT(xComponent.is());
913 // Get document and image
914 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
915 ScDocument& rDoc = pDocSh->GetDocument();
916 SdrObject* pObj = lcl_getSdrObjectWithAssert(rDoc, 0);
918 // Get image size
919 tools::Rectangle aSnapRectOrig = pObj->GetSnapRect();
921 // Collapse the group
922 ScTabViewShell* pViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
923 pViewShell->GetViewData().SetCurX(0);
924 pViewShell->GetViewData().SetCurY(1);
925 pViewShell->GetViewData().GetDispatcher().Execute(SID_OUTLINE_HIDE);
926 CPPUNIT_ASSERT_MESSAGE("Collapse: Image should not be visible", !pObj->IsVisible());
928 // Save and reload
929 saveAndReload(xComponent, "calc8");
930 CPPUNIT_ASSERT(xComponent);
932 // Get document and image
933 pDocSh = lcl_getScDocShellWithAssert(xComponent);
934 ScDocument& rDoc2 = pDocSh->GetDocument();
935 pObj = lcl_getSdrObjectWithAssert(rDoc2, 0);
937 // Expand the group
938 pViewShell = pDocSh->GetBestViewShell(false);
939 CPPUNIT_ASSERT_MESSAGE("Reload: No ScTabViewShell", pViewShell);
940 pViewShell->GetViewData().SetCurX(0);
941 pViewShell->GetViewData().SetCurY(1);
942 pViewShell->GetViewData().GetDispatcher().Execute(SID_OUTLINE_SHOW);
943 CPPUNIT_ASSERT_MESSAGE("Expand: Image should be visible", pObj->IsVisible());
945 // Assert image size is not changed
946 tools::Rectangle aSnapRectReload = pObj->GetSnapRect();
947 lcl_AssertRectEqualWithTolerance("Reload: Object geometry has changed.", aSnapRectOrig,
948 aSnapRectReload, 1);
950 pDocSh->DoClose();
953 void ScShapeTest::testFitToCellSize()
955 // The document has a cell anchored custom shape. Applying
956 // FitToCellSize should resize and position the shape so,
957 // that it fits into its anchor cell. That did not happened.
958 OUString aFileURL;
959 createFileURL("tdf119191_FitToCellSize.ods", aFileURL);
960 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
961 CPPUNIT_ASSERT(xComponent.is());
963 // Get document and shape
964 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
965 ScDocument& rDoc = pDocSh->GetDocument();
966 SdrObjCustomShape* pObj = dynamic_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc, 0));
968 // Get the draw view of the document
969 ScTabViewShell* pViewShell = lcl_getScTabViewShellWithAssert(pDocSh);
970 ScDrawView* pDrawView = pViewShell->GetViewData().GetScDrawView();
971 CPPUNIT_ASSERT(pDrawView);
973 // Select the shape
974 pDrawView->MarkNextObj();
975 CPPUNIT_ASSERT(pDrawView->AreObjectsMarked());
977 // Fit selected shape into cell
978 pViewShell->GetViewData().GetDispatcher().Execute(SID_FITCELLSIZE);
980 const tools::Rectangle& rShapeRect(pObj->GetSnapRect());
981 const tools::Rectangle aCellRect = rDoc.GetMMRect(1, 1, 1, 1, 0);
982 lcl_AssertRectEqualWithTolerance("Cell and SnapRect should be equal", aCellRect, rShapeRect, 1);
984 pDocSh->DoClose();
987 void ScShapeTest::testCustomShapeCellAnchoredRotatedShape()
989 // The example doc contains a cell anchored custom shape that is rotated
990 // and sheared. Error was, that the shape lost position and size on
991 // loading.
992 OUString aFileURL;
993 createFileURL("tdf119191_transformedShape.ods", aFileURL);
994 uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
995 CPPUNIT_ASSERT(xComponent.is());
997 // Get document and shape
998 ScDocShell* pDocSh = lcl_getScDocShellWithAssert(xComponent);
999 ScDocument& rDoc = pDocSh->GetDocument();
1000 SdrObjCustomShape* pObj = dynamic_cast<SdrObjCustomShape*>(lcl_getSdrObjectWithAssert(rDoc, 0));
1002 // Check Position and Size
1003 rDoc.SetDrawPageSize(0); // trigger recalcpos
1004 tools::Rectangle aRect(2400, 751, 5772, 3694); // expected snap rect from values in file
1005 const tools::Rectangle& rShapeRect(pObj->GetSnapRect());
1006 lcl_AssertRectEqualWithTolerance("Load: wrong pos and size", aRect, rShapeRect, 1);
1008 // Check anchor
1009 ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj);
1010 CPPUNIT_ASSERT_MESSAGE("expected object meta data", pData);
1012 const OUString sActual("start col " + OUString::number(pData->maStart.Col()) + " row "
1013 + OUString::number(pData->maStart.Row()) + " end col "
1014 + OUString::number(pData->maEnd.Col()) + " row "
1015 + OUString::number(pData->maEnd.Row()));
1016 CPPUNIT_ASSERT_EQUAL(OUString("start col 1 row 1 end col 2 row 8"), sActual);
1018 pDocSh->DoClose();
1021 CPPUNIT_TEST_SUITE_REGISTRATION(ScShapeTest);
1024 CPPUNIT_PLUGIN_IMPLEMENT();
1026 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */