sc/qa/unit/anchor.cxx |  111 ++++++++++++++++++++++++++++----------------------
 1 file changed, 63 insertions(+), 48 deletions(-)

New commits:
commit ca44f2d25b3f79d2d3f1867be540e335b9044b5b
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Mon Oct 24 13:11:46 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Mon Oct 24 19:33:30 2022 +0200

    Revert "CppunitTest_sc_anchor_test: inherit from ScBootstrapFixture"
    
    This reverts commit 4d9b83a417bbde8148b67d2ab0abe9f4ae285276.
    
    I was wrong in my previous commit. Eventually, we should get
    rid of ScBootstrapFixture instead
    
    Change-Id: I005bb95b543ad1b66330e3173ab2ea1793a4bd3e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141733
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/unit/anchor.cxx b/sc/qa/unit/anchor.cxx
index c0eb4cd1ac71..789b6d777181 100644
--- a/sc/qa/unit/anchor.cxx
+++ b/sc/qa/unit/anchor.cxx
@@ -10,7 +10,7 @@
 #include <sfx2/dispatch.hxx>
 #include <svx/svdograf.hxx>
 #include <svx/svdpage.hxx>
-#include "helper/qahelper.hxx"
+#include <test/unoapi_test.hxx>
 
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
@@ -28,7 +28,9 @@
 
 using namespace css;
 
-class ScAnchorTest : public ScBootstrapFixture
+namespace sc_apitest
+{
+class ScAnchorTest : public UnoApiTest
 {
 public:
     ScAnchorTest();
@@ -57,17 +59,23 @@ public:
 };
 
 ScAnchorTest::ScAnchorTest()
-    : ScBootstrapFixture("sc/qa/unit/data")
+    : UnoApiTest("sc/qa/unit/data/ods")
 {
 }
 
 void ScAnchorTest::testUndoAnchor()
 {
-    ScDocShellRef xDocSh
-        = loadDocAndSetupModelViewController(u"document_with_linked_graphic.", 
FORMAT_ODS);
+    loadFromURL(u"document_with_linked_graphic.ods");
+
+    // Get the document model
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(mxComponent);
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    CPPUNIT_ASSERT(pDocSh);
 
-    ScDocument& rDoc = xDocSh->GetDocument();
     // Check whether graphic imported well
+    ScDocument& rDoc = pDocSh->GetDocument();
     ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
     CPPUNIT_ASSERT(pDrawLayer);
 
@@ -83,7 +91,7 @@ void ScAnchorTest::testUndoAnchor()
     CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), 
rGraphicObj.GetGraphic().GetSizeBytes());
 
     // Get the document controller
-    ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
+    ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
     CPPUNIT_ASSERT(pViewShell);
 
     // Get the draw view of the document
@@ -147,14 +155,14 @@ void ScAnchorTest::testUndoAnchor()
     CPPUNIT_ASSERT_EQUAL(newType, ScDrawLayer::GetAnchorType(*pObject));
     CPPUNIT_ASSERT_EQUAL(int(GraphicType::Bitmap), 
int(rGraphicObj.GetGraphic().GetType()));
     CPPUNIT_ASSERT_EQUAL(sal_uLong(864900), 
rGraphicObj.GetGraphic().GetSizeBytes());
-
-    xDocSh->DoClose();
 }
 
 void ScAnchorTest::testTdf76183()
 {
-    ScDocShellRef xDocSh = loadEmptyDocument();
-    ScDocument& rDoc = xDocSh->GetDocument();
+    mxComponent = loadFromDesktop("private:factory/scalc");
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(mxComponent);
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    ScDocument& rDoc = pDocSh->GetDocument();
     ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
     SdrPage* pPage = pDrawLayer->GetPage(0);
 
@@ -169,8 +177,7 @@ void ScAnchorTest::testTdf76183()
     // Set word wrap to true
     rDoc.ApplyAttr(0, 0, 0, ScLineBreakCell(true));
     // Add multi-line text to cell to initiate optimal height change
-    uno::Reference<frame::XModel> xModel = xDocSh->GetModel();
-    uno::Reference<sheet::XSpreadsheetDocument> xDoc(xModel, 
uno::UNO_QUERY_THROW);
+    uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, 
uno::UNO_QUERY_THROW);
     uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), 
uno::UNO_QUERY_THROW);
     uno::Reference<sheet::XSpreadsheet> xSheet(xIA->getByIndex(0), 
uno::UNO_QUERY_THROW);
     uno::Reference<text::XText> xText(xSheet->getCellByPosition(0, 0), 
uno::UNO_QUERY_THROW);
@@ -180,15 +187,21 @@ void ScAnchorTest::testTdf76183()
     CPPUNIT_ASSERT(aOrigRect.Top() < rNewRect.Top());
 
     pObj.clear();
-    xDocSh->DoClose();
 }
 
 void ScAnchorTest::testODFAnchorTypes()
 {
-    ScDocShellRef xDocSh = loadDoc(u"3AnchorTypes.", FORMAT_ODS);
+    loadFromURL(u"3AnchorTypes.ods");
+
+    // Get the document model
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(mxComponent);
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    CPPUNIT_ASSERT(pDocSh);
 
-    ScDocument& rDoc = xDocSh->GetDocument();
     // Check whether graphic imported well
+    ScDocument& rDoc = pDocSh->GetDocument();
     ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
     CPPUNIT_ASSERT(pDrawLayer);
 
@@ -212,21 +225,26 @@ void ScAnchorTest::testODFAnchorTypes()
     CPPUNIT_ASSERT(pObject);
     anchorType = ScDrawLayer::GetAnchorType(*pObject);
     CPPUNIT_ASSERT_EQUAL(SCA_CELL, anchorType);
-
-    xDocSh->DoClose();
 }
 
 /// Test that copying a column with an image anchored to it also copies the 
image
 void ScAnchorTest::testCopyColumnWithImages()
 {
-    ScDocShellRef xDocSh = 
loadDocAndSetupModelViewController(u"3AnchorTypes.", FORMAT_ODS);
+    loadFromURL(u"3AnchorTypes.ods");
 
-    ScDocument& rDoc = xDocSh->GetDocument();
-    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    // Get the document model
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(mxComponent);
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    CPPUNIT_ASSERT(pDocSh);
+
+    ScDocument* pDoc = &(pDocSh->GetDocument());
+    ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
     CPPUNIT_ASSERT(pDrawLayer);
 
     // Get the document controller
-    ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
+    ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
     CPPUNIT_ASSERT(pViewShell != nullptr);
 
     ScDocument aClipDoc(SCDOCMODE_CLIP);
@@ -235,13 +253,13 @@ void ScAnchorTest::testCopyColumnWithImages()
     {
         // 1. Copy source range
         ScRange aSrcRange;
-        aSrcRange.Parse("A1:A11", rDoc, rDoc.GetAddressConvention());
+        aSrcRange.Parse("A1:A11", *pDoc, pDoc->GetAddressConvention());
         pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
         pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, 
false, true, false);
 
         // 2. Paste to target range
         ScRange aDstRange;
-        aDstRange.Parse("D1:D11", rDoc, rDoc.GetAddressConvention());
+        aDstRange.Parse("D1:D11", *pDoc, pDoc->GetAddressConvention());
         pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange);
         
pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, 
&aClipDoc);
 
@@ -258,13 +276,13 @@ void ScAnchorTest::testCopyColumnWithImages()
     {
         // 1. Copy source cells
         ScRange aSrcRange;
-        aSrcRange.Parse("A3:B3", rDoc, rDoc.GetAddressConvention());
+        aSrcRange.Parse("A3:B3", *pDoc, pDoc->GetAddressConvention());
         pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
         pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, 
false, true, false);
 
         // 2. Paste to target cells
         ScRange aDstRange;
-        aDstRange.Parse("G3:H3", rDoc, rDoc.GetAddressConvention());
+        aDstRange.Parse("G3:H3", *pDoc, pDoc->GetAddressConvention());
         pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange);
         
pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, 
&aClipDoc);
 
@@ -274,27 +292,33 @@ void ScAnchorTest::testCopyColumnWithImages()
         CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be an image anchored to 
G3", 1,
                                      static_cast<int>(aRowObjects[2].size()));
     }
-
-    xDocSh->DoClose();
 }
 
 void ScAnchorTest::testCutWithImages()
 {
-    ScDocShellRef xDocSh = 
loadDocAndSetupModelViewController(u"3AnchorTypes.", FORMAT_ODS);
+    loadFromURL(u"3AnchorTypes.ods");
+    // open the document with graphic included
 
-    ScDocument& rDoc = xDocSh->GetDocument();
-    ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+    // Get the document model
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(mxComponent);
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+    ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+    CPPUNIT_ASSERT(pDocSh);
+
+    ScDocument* pDoc = &(pDocSh->GetDocument());
+    ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
     CPPUNIT_ASSERT(pDrawLayer);
 
     // Get the document controller
-    ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
+    ScTabViewShell* pViewShell = pDocSh->GetBestViewShell(false);
     CPPUNIT_ASSERT(pViewShell != nullptr);
 
     // Cut whole column
     {
         // Cut source range
         ScRange aSrcRange;
-        aSrcRange.Parse("A1:A11", rDoc, rDoc.GetAddressConvention());
+        aSrcRange.Parse("A1:A11", *pDoc, pDoc->GetAddressConvention());
         pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
         pViewShell->GetViewData().GetView()->CutToClip();
 
@@ -312,7 +336,7 @@ void ScAnchorTest::testCutWithImages()
     {
         // Cut source cells
         ScRange aSrcRange;
-        aSrcRange.Parse("A3:B3", rDoc, rDoc.GetAddressConvention());
+        aSrcRange.Parse("A3:B3", *pDoc, pDoc->GetAddressConvention());
         pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
         pViewShell->GetViewData().GetView()->CutToClip();
 
@@ -322,55 +346,46 @@ void ScAnchorTest::testCutWithImages()
         CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be no image anchored to 
A3", 0,
                                      static_cast<int>(aRowObjects[2].size()));
     }
-
-    xDocSh->DoClose();
 }
 
 void ScAnchorTest::testTdf121963()
 {
-    ScDocShellRef xDocSh = loadDoc(u"tdf121963.", FORMAT_ODS);
+    loadFromURL(u"tdf121963.ods");
 
     // Without the accompanying fix in place, this test would have never 
returned due to an infinite
     // invalidation loop, where ScGridWindow::Paint() invalidated itself.
     Scheduler::ProcessEventsToIdle();
-
-    xDocSh->DoClose();
 }
 
 void ScAnchorTest::testTdf129552()
 {
-    ScDocShellRef xDocSh = loadDoc(u"tdf129552.", FORMAT_FODS);
+    loadFromURL(u"tdf129552.fods");
 
     // Without the accompanying fix in place, this test would have never 
returned due to an infinite
     // invalidation loop, where ScGridWindow::Paint() invalidated itself.
     Scheduler::ProcessEventsToIdle();
-
-    xDocSh->DoClose();
 }
 
 void ScAnchorTest::testTdf130556()
 {
-    ScDocShellRef xDocSh = loadDoc(u"tdf130556.", FORMAT_ODS);
+    loadFromURL(u"tdf130556.ods");
 
     // Without the accompanying fix in place, this test would have never 
returned due to an infinite
     // invalidation loop, where ScGridWindow::Paint() invalidated itself.
     Scheduler::ProcessEventsToIdle();
-
-    xDocSh->DoClose();
 }
 
 void ScAnchorTest::testTdf134161()
 {
-    ScDocShellRef xDocSh = loadDoc(u"tdf134161.", FORMAT_ODS);
+    loadFromURL(u"tdf134161.ods");
 
     // Without the accompanying fix in place, this test would have never 
returned due to an infinite
     // invalidation loop
     Scheduler::ProcessEventsToIdle();
-
-    xDocSh->DoClose();
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(ScAnchorTest);
+}
 
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sc/qa/unit/data/fods/tdf129552.fods 
b/sc/qa/unit/data/ods/tdf129552.fods
similarity index 100%
rename from sc/qa/unit/data/fods/tdf129552.fods
rename to sc/qa/unit/data/ods/tdf129552.fods

Reply via email to