diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2020-11-03 19:51:51 +0100 |
---|---|---|
committer | Regina Henschel <rb.henschel@t-online.de> | 2020-11-04 22:16:54 +0100 |
commit | 804c1b77f26bd36895c77586ba4fb43a8b84bec8 (patch) | |
tree | c8e757b9f577c36a9b791b7bfe7e1c446adc1062 /sc | |
parent | cec71744c5fc20e9aedd444372348b562b6c6b79 (diff) |
Unit tests for: Improve 'resize with cell' handling
These tests belong to commit 1f0b3c7a40edfa81bbc7a58d123a6a2dfd83e4ca
They cover tdf#137576, tdf#137216, tdf#137044, tdf#137020, tdf#137355
and tdf#115655.
I have replaced the rectangle comparison in scshapetest.cxx with the
same one as used in bugfix-test.cxx
Change-Id: I71b4499077e461fe826e6d8d29f801bc66da89fa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105270
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/bugfix-test.cxx | 216 | ||||
-rw-r--r-- | sc/qa/unit/data/ods/tdf115655_HideDetail.ods | bin | 0 -> 28062 bytes | |||
-rw-r--r-- | sc/qa/unit/data/ods/tdf137020_FlipVertical.ods | bin | 0 -> 8893 bytes | |||
-rw-r--r-- | sc/qa/unit/data/ods/tdf137044_CoverHiddenRows.ods | bin | 0 -> 8726 bytes | |||
-rw-r--r-- | sc/qa/unit/data/ods/tdf137216_HideCol.ods | bin | 0 -> 8666 bytes | |||
-rw-r--r-- | sc/qa/unit/data/ods/tdf137355_UndoHideRows.ods | bin | 0 -> 10794 bytes | |||
-rw-r--r-- | sc/qa/unit/data/ods/tdf137576_Measureline.ods | bin | 0 -> 8875 bytes | |||
-rw-r--r-- | sc/qa/unit/scshapetest.cxx | 200 |
8 files changed, 392 insertions, 24 deletions
diff --git a/sc/qa/unit/bugfix-test.cxx b/sc/qa/unit/bugfix-test.cxx index 30164e920ba5..2d815bb10c93 100644 --- a/sc/qa/unit/bugfix-test.cxx +++ b/sc/qa/unit/bugfix-test.cxx @@ -19,6 +19,10 @@ #include <svx/xflclit.hxx> #include <svx/xflgrit.hxx> #include <svx/xflhtit.hxx> +#include <drwlayer.hxx> +#include <svx/svdpage.hxx> +#include <svx/svdomeas.hxx> +#include <userdat.hxx> using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -26,11 +30,14 @@ using namespace ::com::sun::star::uno; class ScFiltersTest : public ScBootstrapFixture { public: - ScFiltersTest(); virtual void setUp() override; + void testTdf137576_Measureline(); + void testTdf137216_HideCol(); + void testTdf137044_CoverHiddenRows(); + void testTdf137020_FlipVertical(); void testTdf64229(); void testTdf36933(); void testTdf43700(); @@ -49,6 +56,10 @@ public: void testTdf130725(); CPPUNIT_TEST_SUITE(ScFiltersTest); + CPPUNIT_TEST(testTdf137576_Measureline); + CPPUNIT_TEST(testTdf137216_HideCol); + CPPUNIT_TEST(testTdf137044_CoverHiddenRows); + CPPUNIT_TEST(testTdf137020_FlipVertical); CPPUNIT_TEST(testTdf64229); CPPUNIT_TEST(testTdf36933); CPPUNIT_TEST(testTdf43700); @@ -66,10 +77,213 @@ public: CPPUNIT_TEST(testTdf129789); CPPUNIT_TEST(testTdf130725); CPPUNIT_TEST_SUITE_END(); + private: uno::Reference<uno::XInterface> m_xCalcComponent; }; +static void lcl_AssertRectEqualWithTolerance(const OString& sInfo, + const tools::Rectangle& rExpected, + const tools::Rectangle& rActual, + const sal_Int32 nTolerance) +{ + // Left + OString sMsg = sInfo + " Left expected " + OString::number(rExpected.Left()) + " actual " + + OString::number(rActual.Left()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), labs(rExpected.Left() - rActual.Left()) <= nTolerance); + + // Top + sMsg = sInfo + " Top expected " + OString::number(rExpected.Top()) + " actual " + + OString::number(rActual.Top()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), labs(rExpected.Top() - rActual.Top()) <= nTolerance); + + // Width + sMsg = sInfo + " Width expected " + OString::number(rExpected.GetWidth()) + " actual " + + OString::number(rActual.GetWidth()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), + labs(rExpected.GetWidth() - rActual.GetWidth()) <= nTolerance); + + // Height + sMsg = sInfo + " Height expected " + OString::number(rExpected.GetHeight()) + " actual " + + OString::number(rActual.GetHeight()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), + labs(rExpected.GetHeight() - rActual.GetHeight()) <= nTolerance); +} + +static void lcl_AssertPointEqualWithTolerance(const OString& sInfo, const Point rExpected, + const Point rActual, const sal_Int32 nTolerance) +{ + // X + OString sMsg = sInfo + " X expected " + OString::number(rExpected.X()) + " actual " + + OString::number(rActual.X()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), labs(rExpected.X() - rActual.X()) <= nTolerance); + // Y + sMsg = sInfo + " Y expected " + OString::number(rExpected.Y()) + " actual " + + OString::number(rActual.Y()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), labs(rExpected.Y() - rActual.Y()) <= nTolerance); +} + +void ScFiltersTest::testTdf137576_Measureline() +{ + // The document contains a vertical measure line, anchored "To Cell (resize with cell)" with + // length 37mm. Save and reload had resulted in a line of 0mm length. + + // Get document + ScDocShellRef xDocSh = loadDoc("tdf137576_Measureline.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf137576_Measureline.ods", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Get shape + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage); + SdrMeasureObj* pObj = static_cast<SdrMeasureObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT_MESSAGE("Load: No measure object", pObj); + + // Check start and end point of measureline + const Point aStart = pObj->GetPoint(0); + lcl_AssertPointEqualWithTolerance("Load, start point: ", Point(4800, 1500), aStart, 1); + const Point aEnd = pObj->GetPoint(1); + lcl_AssertPointEqualWithTolerance("Load, end point: ", Point(4800, 5200), aEnd, 1); + + // Save and reload + xDocSh = saveAndReload(&(*xDocSh), FORMAT_ODS); + ScDocument& rDoc2 = xDocSh->GetDocument(); + + // Get shape + pDrawLayer = rDoc2.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer); + pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage); + pObj = static_cast<SdrMeasureObj*>(pPage->GetObj(0)); + CPPUNIT_ASSERT_MESSAGE("Reload: No measure object", pObj); + + // Check start and end point of measureline, should be unchanged + const Point aStart2 = pObj->GetPoint(0); + lcl_AssertPointEqualWithTolerance("Reload start point: ", Point(4800, 1500), aStart2, 1); + const Point aEnd2 = pObj->GetPoint(1); + lcl_AssertPointEqualWithTolerance("Reload end point: ", Point(4800, 5200), aEnd2, 1); + + xDocSh->DoClose(); +} + +void ScFiltersTest::testTdf137216_HideCol() +{ + // The document contains a shape anchored "To Cell (resize with cell)" with start in C3. + // Error was, that hiding column C did not make the shape invisible. + + // Get document + ScDocShellRef xDocSh = loadDoc("tdf137216_HideCol.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf137216_HideCol.ods", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Get shape + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer); + const SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage); + SdrObject* pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Load: No object found", pObj); + + // Assert object is visible before and invisible after hiding column. + CPPUNIT_ASSERT_MESSAGE("before column hide: Object should be visible", pObj->IsVisible()); + rDoc.SetColHidden(2, 2, 0, true); // col C in UI = col index 2 to 2. + CPPUNIT_ASSERT_MESSAGE("after column hide: Object should be invisible", !pObj->IsVisible()); +} + +void ScFiltersTest::testTdf137044_CoverHiddenRows() +{ + // The document contains a shape anchored "To Cell (resize with cell)" with start in cell A4 and + // end in cell A7. Row height is 30mm. Hiding rows 5 and 6, then saving and reload had resulted + // in a wrong end cell offset and thus a wrong height of the shape. + + // Get document + ScDocShellRef xDocSh = loadDoc("tdf137044_CoverHiddenRows.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf137044_CoverHiddenRows.ods", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Get shape + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage); + SdrObject* pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Load: No object", pObj); + + // Get original object values + tools::Rectangle aSnapRectOrig = pObj->GetSnapRect(); + Point aOriginalEndOffset = ScDrawLayer::GetObjData(pObj)->maEndOffset; + lcl_AssertRectEqualWithTolerance("Load:", tools::Rectangle(Point(500, 3500), Size(1501, 11001)), + aSnapRectOrig, 1); + lcl_AssertPointEqualWithTolerance("Load: end offset", Point(2000, 2499), aOriginalEndOffset, 1); + + // Hide rows 5 and 6 in UI = row index 4 to 5. + rDoc.SetRowHidden(4, 5, 0, true); + + // Save and reload + xDocSh = saveAndReload(&(*xDocSh), FORMAT_ODS); + ScDocument& rDoc2 = xDocSh->GetDocument(); + + // Get shape + pDrawLayer = rDoc2.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer); + pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage); + pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Reload: No object", pObj); + + // Get new values and compare. End offset should be the same, height should be 6000 smaller. + tools::Rectangle aSnapRectReload = pObj->GetSnapRect(); + Point aReloadEndOffset = ScDrawLayer::GetObjData(pObj)->maEndOffset; + lcl_AssertRectEqualWithTolerance( + "Reload:", tools::Rectangle(Point(500, 3500), Size(1501, 5001)), aSnapRectReload, 1); + lcl_AssertPointEqualWithTolerance("Reload: end offset", Point(2000, 2499), aReloadEndOffset, 1); + + xDocSh->DoClose(); +} + +void ScFiltersTest::testTdf137020_FlipVertical() +{ + // Get document + ScDocShellRef xDocSh = loadDoc("tdf137020_FlipVertical.", FORMAT_ODS); + CPPUNIT_ASSERT_MESSAGE("Failed to load tdf137020_FlipVertical.ods", xDocSh.is()); + ScDocument& rDoc = xDocSh->GetDocument(); + + // Get shape + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer); + SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage); + SdrObject* pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Load: No object", pObj); + + const tools::Rectangle aSnapRectOrig = pObj->GetSnapRect(); + + // Vertical mirror on center should not change the snap rect. + pObj->Mirror(aSnapRectOrig.LeftCenter(), aSnapRectOrig.RightCenter()); + const tools::Rectangle aSnapRectFlip = pObj->GetSnapRect(); + lcl_AssertRectEqualWithTolerance("Mirror:", aSnapRectOrig, aSnapRectFlip, 1); + + // Save and reload + xDocSh = saveAndReload(&(*xDocSh), FORMAT_ODS); + ScDocument& rDoc2 = xDocSh->GetDocument(); + + // Get shape + pDrawLayer = rDoc2.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer); + pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage); + pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Reload: No object", pObj); + + // Check pos and size of shape again, should be unchanged + const tools::Rectangle aSnapRectReload = pObj->GetSnapRect(); + lcl_AssertRectEqualWithTolerance("Reload:", aSnapRectOrig, aSnapRectReload, 1); + + xDocSh->DoClose(); +} + void ScFiltersTest::testTdf64229() { ScDocShellRef xDocSh = loadDoc("fdo64229b.", FORMAT_ODS); diff --git a/sc/qa/unit/data/ods/tdf115655_HideDetail.ods b/sc/qa/unit/data/ods/tdf115655_HideDetail.ods Binary files differnew file mode 100644 index 000000000000..a72b9a9cdd74 --- /dev/null +++ b/sc/qa/unit/data/ods/tdf115655_HideDetail.ods diff --git a/sc/qa/unit/data/ods/tdf137020_FlipVertical.ods b/sc/qa/unit/data/ods/tdf137020_FlipVertical.ods Binary files differnew file mode 100644 index 000000000000..8b4042ecf482 --- /dev/null +++ b/sc/qa/unit/data/ods/tdf137020_FlipVertical.ods diff --git a/sc/qa/unit/data/ods/tdf137044_CoverHiddenRows.ods b/sc/qa/unit/data/ods/tdf137044_CoverHiddenRows.ods Binary files differnew file mode 100644 index 000000000000..130f970b9057 --- /dev/null +++ b/sc/qa/unit/data/ods/tdf137044_CoverHiddenRows.ods diff --git a/sc/qa/unit/data/ods/tdf137216_HideCol.ods b/sc/qa/unit/data/ods/tdf137216_HideCol.ods Binary files differnew file mode 100644 index 000000000000..7e8cf80cb42a --- /dev/null +++ b/sc/qa/unit/data/ods/tdf137216_HideCol.ods diff --git a/sc/qa/unit/data/ods/tdf137355_UndoHideRows.ods b/sc/qa/unit/data/ods/tdf137355_UndoHideRows.ods Binary files differnew file mode 100644 index 000000000000..ae63e7d607a8 --- /dev/null +++ b/sc/qa/unit/data/ods/tdf137355_UndoHideRows.ods diff --git a/sc/qa/unit/data/ods/tdf137576_Measureline.ods b/sc/qa/unit/data/ods/tdf137576_Measureline.ods Binary files differnew file mode 100644 index 000000000000..fd859c86bf10 --- /dev/null +++ b/sc/qa/unit/data/ods/tdf137576_Measureline.ods diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx index 5efad446a70f..15d083e17380 100644 --- a/sc/qa/unit/scshapetest.cxx +++ b/sc/qa/unit/scshapetest.cxx @@ -9,9 +9,12 @@ #include <test/calc_unoapi_test.hxx> +#include <comphelper/dispatchcommand.hxx> +#include <comphelper/propertyvalue.hxx> #include <sfx2/dispatch.hxx> #include <svx/svdoashp.hxx> #include <svx/svdpage.hxx> +#include <unotools/tempfile.hxx> #include <docsh.hxx> #include <drwlayer.hxx> @@ -28,11 +31,17 @@ class ScShapeTest : public CalcUnoApiTest { public: ScShapeTest(); + void saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent, + const OUString& rFilter); + void testTdf137355_UndoHideRows(); + void testTdf115655_HideDetail(); void testFitToCellSize(); void testCustomShapeCellAnchoredRotatedShape(); CPPUNIT_TEST_SUITE(ScShapeTest); + CPPUNIT_TEST(testTdf137355_UndoHideRows); + CPPUNIT_TEST(testTdf115655_HideDetail); CPPUNIT_TEST(testFitToCellSize); CPPUNIT_TEST(testCustomShapeCellAnchoredRotatedShape); CPPUNIT_TEST_SUITE_END(); @@ -43,27 +52,174 @@ ScShapeTest::ScShapeTest() { } -static OUString lcl_compareRectWithTolerance(const tools::Rectangle& rExpected, +void ScShapeTest::saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent, + const OUString& rFilter) +{ + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + css::uno::Sequence<css::beans::PropertyValue> aArgs(1); + aArgs[0].Name = "FilterName"; + aArgs[0].Value <<= rFilter; // e.g. "calc8" + css::uno::Reference<css::frame::XStorable> xStorable(xComponent, css::uno::UNO_QUERY_THROW); + xStorable->storeAsURL(aTempFile.GetURL(), aArgs); + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); + + xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.sheet.SpreadsheetDocument"); +} + +static void lcl_AssertRectEqualWithTolerance(const OString& sInfo, + const tools::Rectangle& rExpected, const tools::Rectangle& rActual, const sal_Int32 nTolerance) { - OUString sErrors; - if (labs(rExpected.Left() - rActual.Left()) > nTolerance) - sErrors += "\nLeft expected " + OUString::number(rExpected.Left()) + " actual " - + OUString::number(rActual.Left()) + " Tolerance " - + OUString::number(nTolerance); - if (labs(rExpected.Top() - rActual.Top()) > nTolerance) - sErrors += "\nTop expected " + OUString::number(rExpected.Top()) + " actual " - + OUString::number(rActual.Top()) + " Tolerance " + OUString::number(nTolerance); - if (labs(rExpected.GetWidth() - rActual.GetWidth()) > nTolerance) - sErrors += "\nWidth expected " + OUString::number(rExpected.GetWidth()) + " actual " - + OUString::number(rActual.GetWidth()) + " Tolerance " - + OUString::number(nTolerance); - if (labs(rExpected.GetHeight() - rActual.GetHeight()) > nTolerance) - sErrors += "\nHeight expected " + OUString::number(rExpected.GetHeight()) + " actual " - + OUString::number(rActual.GetHeight()) + " Tolerance " - + OUString::number(nTolerance); - return sErrors; + // Left + OString sMsg = sInfo + " Left expected " + OString::number(rExpected.Left()) + " actual " + + OString::number(rActual.Left()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), labs(rExpected.Left() - rActual.Left()) <= nTolerance); + + // Top + sMsg = sInfo + " Top expected " + OString::number(rExpected.Top()) + " actual " + + OString::number(rActual.Top()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), labs(rExpected.Top() - rActual.Top()) <= nTolerance); + + // Width + sMsg = sInfo + " Width expected " + OString::number(rExpected.GetWidth()) + " actual " + + OString::number(rActual.GetWidth()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), + labs(rExpected.GetWidth() - rActual.GetWidth()) <= nTolerance); + + // Height + sMsg = sInfo + " Height expected " + OString::number(rExpected.GetHeight()) + " actual " + + OString::number(rActual.GetHeight()) + " Tolerance " + OString::number(nTolerance); + CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), + labs(rExpected.GetHeight() - rActual.GetHeight()) <= nTolerance); +} + +void ScShapeTest::testTdf137355_UndoHideRows() +{ + // The document contains a shape anchored "To Cell" with start in cell C3 and end in cell D6. + // Error was, that hiding rows 3 to 6 and undo that action "lost" the shape. + // Actually it was not lost but hidden. + OUString aFileURL; + createFileURL("tdf137355_UndoHideRows.ods", aFileURL); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get the document model + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Get document and shape + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("No ScDrawLayer", pDrawLayer); + const SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("No draw page", pPage); + SdrObject* pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("No object found", pObj); + CPPUNIT_ASSERT_MESSAGE("Load: Object should be visible", pObj->IsVisible()); + tools::Rectangle aSnapRectOrig(pObj->GetSnapRect()); + + // Hide rows 3 to 6 in UI. [Note: Simple rDoc.SetRowHidden(2,5,0,true) does not work, because it + // does not produce the needed undo items.] + uno::Sequence<beans::PropertyValue> aPropertyValues = { + comphelper::makePropertyValue("ToPoint", OUString("$A$3:$A$6")), + }; + dispatchCommand(xComponent, ".uno:GoToCell", aPropertyValues); + + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT_MESSAGE("No ScTabViewShell", pViewShell); + pViewShell->GetViewData().GetDispatcher().Execute(FID_ROW_HIDE); + + // Check object is invisible + CPPUNIT_ASSERT_MESSAGE("Hide: Object should be invisible", !pObj->IsVisible()); + + // Undo + pViewShell->GetViewData().GetDispatcher().Execute(SID_UNDO); + + // Check object is visible and has old size + CPPUNIT_ASSERT_MESSAGE("Undo: Object should exist", pObj); + CPPUNIT_ASSERT_MESSAGE("Undo: Object should be visible", pObj->IsVisible()); + tools::Rectangle aSnapRectUndo(pObj->GetSnapRect()); + lcl_AssertRectEqualWithTolerance("Undo: Object geometry should not change", aSnapRectOrig, + aSnapRectUndo, 1); + + pDocSh->DoClose(); +} + +void ScShapeTest::testTdf115655_HideDetail() +{ + // The document contains an image inside a cell anchored "To Cell (resize with cell)". The cell + // belongs to a group. On loading the group is expanded. + // Error was, that after collapsing the group, save and reload, and exanding the group, the image + // was "lost". Actually is was resized to zero height. + OUString aFileURL; + createFileURL("tdf115655_HideDetail.ods", aFileURL); + uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL); + CPPUNIT_ASSERT(xComponent.is()); + + // Get ScDocShell + SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell); + ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Get document and image + ScDocument& rDoc = pDocSh->GetDocument(); + ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer); + const SdrPage* pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage); + SdrObject* pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Load: No object found", pObj); + + // Get image size + tools::Rectangle aSnapRectOrig = pObj->GetSnapRect(); + + // Collapse the group + ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT_MESSAGE("Load: No ScTabViewShell", pViewShell); + pViewShell->GetViewData().SetCurX(0); + pViewShell->GetViewData().SetCurY(1); + pViewShell->GetViewData().GetDispatcher().Execute(SID_OUTLINE_HIDE); + CPPUNIT_ASSERT_MESSAGE("Collapse: Image should not be visible", !pObj->IsVisible()); + + // Save and reload + saveAndReload(xComponent, "calc8"); + CPPUNIT_ASSERT(xComponent); + + // Get ScDocShell + pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent); + CPPUNIT_ASSERT_MESSAGE("Reload: Failed to access document shell", pFoundShell); + pDocSh = dynamic_cast<ScDocShell*>(pFoundShell); + CPPUNIT_ASSERT(pDocSh); + + // Get document and image + ScDocument& rDoc2 = pDocSh->GetDocument(); + pDrawLayer = rDoc2.GetDrawLayer(); + CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer); + pPage = pDrawLayer->GetPage(0); + CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage); + pObj = pPage->GetObj(0); + CPPUNIT_ASSERT_MESSAGE("Reload: Image no longer exists", pObj); + + // Expand the group + pViewShell = pDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT_MESSAGE("Reload: No ScTabViewShell", pViewShell); + pViewShell->GetViewData().SetCurX(0); + pViewShell->GetViewData().SetCurY(1); + pViewShell->GetViewData().GetDispatcher().Execute(SID_OUTLINE_SHOW); + CPPUNIT_ASSERT_MESSAGE("Expand: Image should be visible", pObj->IsVisible()); + + // Assert image size is not changed + tools::Rectangle aSnapRectReload = pObj->GetSnapRect(); + lcl_AssertRectEqualWithTolerance("Reload: Object geometry has changed.", aSnapRectOrig, + aSnapRectReload, 1); + + pDocSh->DoClose(); } void ScShapeTest::testFitToCellSize() @@ -111,8 +267,7 @@ void ScShapeTest::testFitToCellSize() const tools::Rectangle& rShapeRect(pObj->GetSnapRect()); const tools::Rectangle aCellRect = rDoc.GetMMRect(1, 1, 1, 1, 0); - const OUString sErrors(lcl_compareRectWithTolerance(aCellRect, rShapeRect, 1)); - CPPUNIT_ASSERT_EQUAL(OUString(), sErrors); + lcl_AssertRectEqualWithTolerance("Cell and SnapRect should be equal", aCellRect, rShapeRect, 1); pDocSh->DoClose(); } @@ -146,11 +301,10 @@ void ScShapeTest::testCustomShapeCellAnchoredRotatedShape() CPPUNIT_ASSERT(pObj); // Check Position and Size - tools::Rectangle aRect(2400, 751, 5772, 3693); // expected snap rect rDoc.SetDrawPageSize(0); // trigger recalcpos + tools::Rectangle aRect(2400, 751, 5772, 3694); // expected snap rect from values in file const tools::Rectangle& rShapeRect(pObj->GetSnapRect()); - const OUString sPosSizeErrors(lcl_compareRectWithTolerance(aRect, rShapeRect, 1)); - CPPUNIT_ASSERT_EQUAL(OUString(), sPosSizeErrors); + lcl_AssertRectEqualWithTolerance("Load: wrong pos and size", aRect, rShapeRect, 1); // Check anchor ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj); |