sw/qa/core/frmedt/frmedt.cxx                  |    5 
 sw/qa/core/layout/layout.cxx                  |    9 -
 sw/qa/extras/globalfilter/globalfilter.cxx    |  136 +++++++++++---------------
 sw/qa/extras/htmlexport/htmlexport.cxx        |    4 
 sw/qa/extras/htmlimport/htmlimport.cxx        |   23 +---
 sw/qa/extras/layout/layout.cxx                |   38 ++-----
 sw/qa/extras/layout/layout2.cxx               |   22 ----
 sw/qa/extras/layout/layout3.cxx               |   83 +++------------
 sw/qa/extras/layout/layout4.cxx               |    4 
 sw/qa/extras/mailmerge/mailmerge.cxx          |   29 +----
 sw/qa/extras/odfexport/odfexport.cxx          |    7 -
 sw/qa/extras/odfimport/odfimport.cxx          |    4 
 sw/qa/extras/ooxmlexport/ooxmlexport13.cxx    |    8 -
 sw/qa/extras/ooxmlexport/ooxmlexport19.cxx    |   12 --
 sw/qa/extras/ooxmlexport/ooxmlexport20.cxx    |    4 
 sw/qa/extras/ooxmlexport/ooxmlexport3.cxx     |    4 
 sw/qa/extras/ooxmlexport/ooxmlexport7.cxx     |    4 
 sw/qa/extras/ooxmlexport/ooxmlexport8.cxx     |   11 --
 sw/qa/extras/ooxmlexport/ooxmlexport9.cxx     |    4 
 sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx |   16 ---
 sw/qa/extras/ooxmlimport/ooxmlimport2.cxx     |    4 
 sw/qa/extras/rtfexport/rtfexport4.cxx         |    7 -
 sw/qa/extras/txtimport/txtimport.cxx          |   32 +-----
 sw/qa/extras/uiwriter/uiwriter2.cxx           |    7 -
 sw/qa/extras/uiwriter/uiwriter5.cxx           |   10 -
 sw/qa/extras/unowriter/unowriter.cxx          |    4 
 sw/qa/extras/ww8export/ww8export.cxx          |   29 +----
 sw/qa/extras/ww8export/ww8export2.cxx         |   12 --
 sw/qa/extras/ww8export/ww8export3.cxx         |    4 
 sw/qa/extras/ww8export/ww8export4.cxx         |    7 -
 sw/qa/extras/ww8import/ww8import.cxx          |   23 +---
 sw/qa/filter/html/html.cxx                    |    6 -
 32 files changed, 171 insertions(+), 401 deletions(-)

New commits:
commit 64e8d5d8b9a56f31caff66675180342773f847a0
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Oct 24 14:08:06 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Oct 24 17:28:13 2024 +0200

    sw/qa: use getSwDoc() more
    
    Change-Id: I742309d99c4d9839dcd4f8b747fc9aef549998ef
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175555
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/qa/core/frmedt/frmedt.cxx b/sw/qa/core/frmedt/frmedt.cxx
index 058afa7b87a3..d84ac6bffaa9 100644
--- a/sw/qa/core/frmedt/frmedt.cxx
+++ b/sw/qa/core/frmedt/frmedt.cxx
@@ -44,8 +44,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, testTextboxReanchor)
 {
     // Load a document with a textframe and a textbox(shape+textframe).
     createSwDoc("textbox-reanchor.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SdrPage* pDrawPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     SdrObject* pDrawShape = pDrawPage->GetObj(1);
     CPPUNIT_ASSERT_EQUAL(u"draw shape"_ustr, pDrawShape->GetName());
@@ -102,7 +101,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreFrmedtTest, 
testVertPosFromBottomBoundingBox)
     SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
     SwRect aBoundRect;
     RndStdIds eAnchorType = RndStdIds::FLY_AT_CHAR;
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     const auto& rFrameFormats = *pDoc->GetFrameFormats();
     const SwFormatAnchor* pFormatAhchor = &rFrameFormats[0]->GetAnchor();
     sal_Int16 eHoriRelOrient = text::RelOrientation::PAGE_FRAME;
diff --git a/sw/qa/core/layout/layout.cxx b/sw/qa/core/layout/layout.cxx
index 45756891d3bf..4f3bc3545d74 100644
--- a/sw/qa/core/layout/layout.cxx
+++ b/sw/qa/core/layout/layout.cxx
@@ -220,8 +220,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, 
testTextBoxNotModifiedOnOpen)
     // tdf#138050: a freshly opened document containing a shape with a text box
     // should not appear to be modified
     createSwDoc("textbox-phantom-change.docx");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
 
     // Without the fix in place this test would have shown that the document
     // was modified due to a fix to tdf#135198
@@ -231,8 +230,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, 
testTextBoxNotModifiedOnOpen)
 CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testTextBoxAutoGrowVertical)
 {
     createSwDoc("textbox-autogrow-vertical.docx");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     SdrObject* pShape = pPage->GetObj(0);
     tools::Rectangle aShapeRect = pShape->GetCurrentBoundRect();
@@ -280,8 +278,7 @@ CPPUNIT_TEST_FIXTURE(SwCoreLayoutTest, testBtlrNestedCell)
 {
     // Load a document with a nested table, the inner A1 cell has a btlr text 
direction.
     createSwDoc("btlr-nested-cell.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
     SwFrame* pPage = pLayout->GetLower();
     SwFrame* pBody = pPage->GetLower();
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx 
b/sw/qa/extras/globalfilter/globalfilter.cxx
index 67f183c54728..fa60bf574f66 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -172,9 +172,7 @@ void Test::testLinkedGraphicRT()
         // Export the document and import again for a check
         saveAndReload(rFilterName);
 
-        SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pDoc);
         SwNodes& aNodes = pDoc->GetNodes();
 
@@ -200,7 +198,7 @@ void Test::testLinkedGraphicRT()
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
sal_uLong(864900), aGraphic.GetSizeBytes());
 
         // Check if linked graphic is registered in LinkManager
-        SwEditShell* const 
pEditShell(pTextDoc->GetDocShell()->GetDoc()->GetEditShell());
+        SwEditShell* const pEditShell(getSwDoc()->GetEditShell());
         CPPUNIT_ASSERT(pEditShell);
         sfx2::LinkManager& rLinkManager = pEditShell->GetLinkManager();
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), size_t(1), 
rLinkManager.GetLinks().size());
@@ -843,60 +841,6 @@ void Test::testSkipImages()
 }
 #endif
 
-auto verifyNestedFieldmark(OUString const& rTestName,
-        uno::Reference<lang::XComponent> const& xComponent) -> void
-{
-    SwDoc const*const 
pDoc(dynamic_cast<SwXTextDocument&>(*xComponent).GetDocShell()->GetDoc());
-    IDocumentMarkAccess const& rIDMA(*pDoc->getIDocumentMarkAccess());
-
-    // no spurious bookmarks have been created
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(),
-            sal_Int32(0), rIDMA.getBookmarksCount());
-
-    // check inner fieldmark
-    SwNodeIndex const 
node1(*pDoc->GetNodes().GetEndOfContent().StartOfSectionNode(), +2);
-    SwPosition const innerPos(*node1.GetNode().GetTextNode(),
-        
node1.GetNode().GetTextNode()->GetText().indexOf(CH_TXT_ATR_FIELDSTART));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(),
-            sal_Int32(1), innerPos.GetContentIndex());
-    ::sw::mark::Fieldmark *const pInner(rIDMA.getFieldmarkAt(innerPos));
-    CPPUNIT_ASSERT_MESSAGE(rTestName.toUtf8().getStr(), pInner);
-    OUString const innerString(SwPaM(pInner->GetMarkPos(), 
pInner->GetOtherMarkPos()).GetText());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(), OUString(
-        OUStringChar(CH_TXT_ATR_FIELDSTART) + u" QUOTE  \"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
-        + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"baz\" " + OUStringChar(CH_TXT_ATR_FIELDSEP) + u"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
-        + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"baz" + OUStringChar(CH_TXT_ATR_FIELDEND)), innerString);
-
-    // check outer fieldmark
-    SwNodeIndex const node2(node1, -1);
-    SwPosition const outerPos(*node2.GetNode().GetTextNode(),
-        
node2.GetNode().GetTextNode()->GetText().indexOf(CH_TXT_ATR_FIELDSTART));
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(),
-            sal_Int32(0), outerPos.GetContentIndex());
-    ::sw::mark::Fieldmark const*const pOuter(rIDMA.getFieldmarkAt(outerPos));
-    CPPUNIT_ASSERT_MESSAGE(rTestName.toUtf8().getStr(), pOuter);
-    OUString const outerString(SwPaM(pOuter->GetMarkPos(), 
pOuter->GetOtherMarkPos()).GetText());
-    CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(), OUString(
-        OUStringChar(CH_TXT_ATR_FIELDSTART) + u" QUOTE  \"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
-        + u" " + OUStringChar(CH_TXT_ATR_FIELDSTART) + u" QUOTE  \"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
-        + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"baz\" " + OUStringChar(CH_TXT_ATR_FIELDSEP) + u"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
-        + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"baz" + OUStringChar(CH_TXT_ATR_FIELDEND) + 
OUStringChar(CH_TXTATR_NEWLINE)
-        + u"bar " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"baz\" " + OUStringChar(CH_TXT_ATR_FIELDSEP) + u"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
-        + u" foo " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"baz" + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"bar " + OUStringChar(CH_TXTATR_NEWLINE)
-        + u"baz" + OUStringChar(CH_TXT_ATR_FIELDEND)), outerString);
-
-    // must return innermost mark
-    CPPUNIT_ASSERT_EQUAL(pInner, rIDMA.getInnerFieldmarkFor(innerPos));
-}
-
 void Test::testNestedFieldmark()
 {
     // experimental config setting
@@ -911,6 +855,58 @@ void Test::testNestedFieldmark()
     
officecfg::Office::Common::Filter::Microsoft::Import::ForceImportWWFieldsAsGenericFields::set(true,
 pBatch);
     pBatch->commit();
 
+    auto verify = [this](OUString const& rTestName) {
+        SwDoc* pDoc = getSwDoc();
+        IDocumentMarkAccess const& rIDMA(*pDoc->getIDocumentMarkAccess());
+
+        // no spurious bookmarks have been created
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(),
+                sal_Int32(0), rIDMA.getBookmarksCount());
+
+        // check inner fieldmark
+        SwNodeIndex const 
node1(*pDoc->GetNodes().GetEndOfContent().StartOfSectionNode(), +2);
+        SwPosition const innerPos(*node1.GetNode().GetTextNode(),
+            
node1.GetNode().GetTextNode()->GetText().indexOf(CH_TXT_ATR_FIELDSTART));
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(),
+                sal_Int32(1), innerPos.GetContentIndex());
+        ::sw::mark::Fieldmark *const pInner(rIDMA.getFieldmarkAt(innerPos));
+        CPPUNIT_ASSERT_MESSAGE(rTestName.toUtf8().getStr(), pInner);
+        OUString const innerString(SwPaM(pInner->GetMarkPos(), 
pInner->GetOtherMarkPos()).GetText());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(), OUString(
+            OUStringChar(CH_TXT_ATR_FIELDSTART) + u" QUOTE  \"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
+            + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"baz\" " + OUStringChar(CH_TXT_ATR_FIELDSEP) + u"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
+            + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"baz" + OUStringChar(CH_TXT_ATR_FIELDEND)), innerString);
+
+        // check outer fieldmark
+        SwNodeIndex const node2(node1, -1);
+        SwPosition const outerPos(*node2.GetNode().GetTextNode(),
+            
node2.GetNode().GetTextNode()->GetText().indexOf(CH_TXT_ATR_FIELDSTART));
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(),
+                sal_Int32(0), outerPos.GetContentIndex());
+        ::sw::mark::Fieldmark const*const 
pOuter(rIDMA.getFieldmarkAt(outerPos));
+        CPPUNIT_ASSERT_MESSAGE(rTestName.toUtf8().getStr(), pOuter);
+        OUString const outerString(SwPaM(pOuter->GetMarkPos(), 
pOuter->GetOtherMarkPos()).GetText());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(rTestName.toUtf8().getStr(), OUString(
+            OUStringChar(CH_TXT_ATR_FIELDSTART) + u" QUOTE  \"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
+            + u" " + OUStringChar(CH_TXT_ATR_FIELDSTART) + u" QUOTE  \"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
+            + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"baz\" " + OUStringChar(CH_TXT_ATR_FIELDSEP) + u"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
+            + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"baz" + OUStringChar(CH_TXT_ATR_FIELDEND) + 
OUStringChar(CH_TXTATR_NEWLINE)
+            + u"bar " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"baz\" " + OUStringChar(CH_TXT_ATR_FIELDSEP) + u"foo " + 
OUStringChar(CH_TXTATR_NEWLINE)
+            + u" foo " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u" bar " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"baz" + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"bar " + OUStringChar(CH_TXTATR_NEWLINE)
+            + u"baz" + OUStringChar(CH_TXT_ATR_FIELDEND)), outerString);
+
+        // must return innermost mark
+        CPPUNIT_ASSERT_EQUAL(pInner, rIDMA.getInnerFieldmarkFor(innerPos));
+    };
+
     std::pair<OUString, OUString> const aFilterNames[] = {
         {"writer8", "fieldmark_QUOTE_nest.fodt"},
         {"Office Open XML Text", "fieldmark_QUOTE_nest.docx"},
@@ -921,12 +917,12 @@ void Test::testNestedFieldmark()
     {
         createSwDoc(rFilterName.second.toUtf8().getStr());
 
-        verifyNestedFieldmark(rFilterName.first + ", load", mxComponent);
+        verify(rFilterName.first + ", load");
 
         // Export the document and import again
         saveAndReload(rFilterName.first);
 
-        verifyNestedFieldmark(rFilterName.first + " exported-reload", 
mxComponent);
+        verify(rFilterName.first + " exported-reload");
     }
 }
 
@@ -1790,9 +1786,7 @@ void Test::testTextFormField()
         saveAndReload(rFilterName);
 
         // Check the document after round trip
-        SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
 
         // We have two text form fields
@@ -1842,9 +1836,7 @@ void Test::testCheckBoxFormField()
         saveAndReload(rFilterName);
 
         // Check the document after round trip
-        SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
 
         // We have two check box form fields
@@ -1895,9 +1887,7 @@ void Test::testDropDownFormField()
         saveAndReload(rFilterName);
 
         // Check the document after round trip
-        SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-        CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
 
         CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(2), 
pMarkAccess->getAllMarksCount());
@@ -1972,9 +1962,7 @@ void Test::testDateFormField()
         // Check the document after round trip
         if (rFilterName == "writer8")
         {
-            SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
-            SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+            SwDoc* pDoc = getSwDoc();
             IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
 
             CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 
sal_Int32(5), pMarkAccess->getAllMarksCount());
@@ -2154,9 +2142,7 @@ void Test::testDateFormFieldCharacterFormatting()
         // Check the document after round trip
         if (rFilterName == "writer8")
         {
-            SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-            CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pTextDoc);
-            SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+            SwDoc* pDoc = getSwDoc();
             IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
 
             // Check that we have the field at the right place
diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx 
b/sw/qa/extras/htmlexport/htmlexport.cxx
index 132c6e7fcbbf..7aa9f9cc4705 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -2183,9 +2183,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, 
testTrailingLineBreak)
     ImportFromReqif(maTempFile.GetURL());
 
     // Then make sure that line-break is not lost:
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    pDoc = pTextDoc->GetDocShell()->GetDoc();
+    pDoc = getSwDoc();
     pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     OUString aActual = 
pWrtShell->GetCursor()->GetPointNode().GetTextNode()->GetText();
     // Without the accompanying fix in place, this test would have failed, as 
the trailing
diff --git a/sw/qa/extras/htmlimport/htmlimport.cxx 
b/sw/qa/extras/htmlimport/htmlimport.cxx
index 420cdb742d67..312b978d99ad 100644
--- a/sw/qa/extras/htmlimport/htmlimport.cxx
+++ b/sw/qa/extras/htmlimport/htmlimport.cxx
@@ -46,10 +46,8 @@ class HtmlImportTest : public SwModelTestBase
 CPPUNIT_TEST_FIXTURE(HtmlImportTest, testPictureImport)
 {
     createSwWebDoc("picture.html");
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
     // The document contains two pictures stored as a link.
-    SwEditShell* const 
pEditShell(pTextDoc->GetDocShell()->GetDoc()->GetEditShell());
+    SwEditShell* const pEditShell(getSwDoc()->GetEditShell());
     CPPUNIT_ASSERT(pEditShell);
     sfx2::LinkManager& rLinkManager = pEditShell->GetLinkManager();
     CPPUNIT_ASSERT_EQUAL(size_t(2), rLinkManager.GetLinks().size());
@@ -65,11 +63,9 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testPictureImport)
 CPPUNIT_TEST_FIXTURE(HtmlImportTest, testInlinedImage)
 {
     createSwWebDoc("inlined_image.html");
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
     // The document contains only one embedded picture inlined in img's src 
attribute.
 
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwEditShell* pEditShell = pDoc->GetEditShell();
     CPPUNIT_ASSERT(pEditShell);
 
@@ -103,12 +99,10 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testInlinedImage)
 CPPUNIT_TEST_FIXTURE(HtmlImportTest, testInlinedImagesPageAndParagraph)
 {
     createSwWebDoc("PageAndParagraphFilled.html");
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
 
     // The document contains embedded pictures inlined for PageBackground and
     // ParagraphBackground, check for their existence after import
-    SwEditShell* const 
pEditShell(pTextDoc->GetDocShell()->GetDoc()->GetEditShell());
+    SwEditShell* const pEditShell(getSwDoc()->GetEditShell());
     CPPUNIT_ASSERT(pEditShell);
 
     // images are not linked, check for zero links
@@ -209,9 +203,7 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testMetaIsoDates)
 CPPUNIT_TEST_FIXTURE(HtmlImportTest, testImageWidthAuto)
 {
     createSwWebDoc("image-width-auto.html");
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwEditShell* const 
pEditShell(pTextDoc->GetDocShell()->GetDoc()->GetEditShell());
+    SwEditShell* const pEditShell(getSwDoc()->GetEditShell());
     CPPUNIT_ASSERT(pEditShell);
     SwTextAttr const*const 
pAttr(pEditShell->GetCursor()->GetPointNode().GetTextNode()->GetTextAttrForCharAt(0,
 RES_TXTATR_FLYCNT));
     CPPUNIT_ASSERT(pAttr);
@@ -414,9 +406,7 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testTdf142781)
 CPPUNIT_TEST_FIXTURE(HtmlImportTest, testTdf122789)
 {
     createSwWebDoc("tdf122789.html");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     const auto& rFormats = *pDoc->GetSpzFrameFormats();
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), rFormats.size());
     // This failed, the image had an absolute size, not a relative one.
@@ -427,8 +417,7 @@ CPPUNIT_TEST_FIXTURE(HtmlImportTest, testTdf118579)
 {
     createSwWebDoc("tdf118579.html");
     //Without the fix in place, the file fails to load
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
+    CPPUNIT_ASSERT_EQUAL(1, getPages());
 }
 
 CPPUNIT_TEST_FIXTURE(HtmlImportTest, testReqIfPageStyle)
diff --git a/sw/qa/extras/layout/layout.cxx b/sw/qa/extras/layout/layout.cxx
index ac340366deea..f9a932ff76e8 100644
--- a/sw/qa/extras/layout/layout.cxx
+++ b/sw/qa/extras/layout/layout.cxx
@@ -115,9 +115,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf156077)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFootnotes)
 {
     createSwDoc("redline_footnotes.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     CPPUNIT_ASSERT(pLayout->IsHideRedlines());
 
@@ -284,7 +282,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineFlysInBody)
     createSwDoc();
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
     CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
     SwRootFrame* pLayout(pWrtShell->GetLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
@@ -868,7 +866,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineFlysInHeader)
     createSwDoc();
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
     CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
     SwRootFrame* pLayout(pWrtShell->GetLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
@@ -1436,7 +1434,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineFlysInFootnote)
     createSwDoc();
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
     CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
     SwRootFrame* pLayout(pWrtShell->GetLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
@@ -2238,7 +2236,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineFlysInFlys)
     createSwDoc();
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
     CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
     SwRootFrame* pLayout(pWrtShell->GetLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
@@ -2835,7 +2833,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineFlysAtFlys)
     createSwDoc();
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
     CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
     SwRootFrame* pLayout(pWrtShell->GetLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
@@ -3179,9 +3177,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineFlysAtFlys)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineSections)
 {
     createSwDoc("redline_sections.fodt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     CPPUNIT_ASSERT(pLayout->IsHideRedlines());
 
@@ -3275,25 +3271,19 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, 
testRedlineSections)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TDF69647_images)
 {
     createSwDoc("tdf69647_images.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Number of pages does not match!", 2, 
getPages());
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, TDF69647_text)
 {
     createSwDoc("tdf69647_text.docx");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Number of pages does not match!", 2, 
getPages());
 }
 
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineTables)
 {
     createSwDoc("redline_table.fodt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     CPPUNIT_ASSERT(pLayout->IsHideRedlines());
 
@@ -3371,9 +3361,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testRedlineTables)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf144057)
 {
     createSwDoc("tdf144057.fodt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
     xmlDocUniquePtr pXmlDoc = parseLayoutDump();
@@ -3429,9 +3417,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf144057)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf144347)
 {
     createSwDoc("tdf144057.fodt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
 
     // enable redlining
@@ -3481,9 +3467,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf144347)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter, testTdf155345)
 {
     createSwDoc("tdf144057.fodt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
 
diff --git a/sw/qa/extras/layout/layout2.cxx b/sw/qa/extras/layout/layout2.cxx
index 64f5768eff42..0743cd980526 100644
--- a/sw/qa/extras/layout/layout2.cxx
+++ b/sw/qa/extras/layout/layout2.cxx
@@ -220,9 +220,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf148897)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testRedlineCharAttributes)
 {
     createSwDoc("redline_charatr.fodt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     CPPUNIT_ASSERT(pLayout->IsHideRedlines());
 
@@ -401,9 +399,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, 
testRedlineCharAttributes)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testRedlineShowHideFootnotePagination)
 {
     createSwDoc("redline_footnote_pagination.fodt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
     SwRootFrame* pLayout(pDoc->getIDocumentLayoutAccess().GetCurrentLayout());
     CPPUNIT_ASSERT(!pLayout->IsHideRedlines());
 
@@ -2431,10 +2427,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf117923)
 {
     createSwDoc("tdf117923.doc");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -2459,10 +2452,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf127606)
 {
     createSwDoc("tdf117923.docx");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -2590,9 +2580,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter2, testTdf121509)
     uno::Reference<lang::XComponent> xComponent
         = loadFromDesktop(maTempFile.GetURL(), 
u"com.sun.star.text.TextDocument"_ustr);
     uno::Reference<text::XTextDocument> xTextDoc(xComponent, uno::UNO_QUERY);
-    auto pTextDoc = dynamic_cast<SwXTextDocument*>(xTextDoc.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    auto pSecondDoc = pTextDoc->GetDocShell()->GetDoc();
+    auto pSecondDoc = getSwDoc();
     auto pSecondFormats = pSecondDoc->GetSpzFrameFormats();
 
     bool bFlyInFlyFound = false;
diff --git a/sw/qa/extras/layout/layout3.cxx b/sw/qa/extras/layout/layout3.cxx
index 4f286513106e..bcb04515d7bb 100644
--- a/sw/qa/extras/layout/layout3.cxx
+++ b/sw/qa/extras/layout/layout3.cxx
@@ -208,10 +208,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf119908)
 {
     createSwDoc("tdf130088.docx");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -229,10 +226,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158333)
 {
     createSwDoc("tdf130088.docx");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -270,10 +264,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf159085)
 {
     createSwDoc("tdf159085.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -295,10 +286,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf158419)
     SwDocShell* pShell = pDoc->GetDocShell();
 
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -337,10 +325,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf163042)
     SwDocShell* pShell = pDoc->GetDocShell();
 
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -375,10 +360,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf163060)
     createSwDoc("tdf163060.fodt");
 
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -399,10 +381,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf162109)
 {
     createSwDoc("tdf162109.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -416,10 +395,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf162220)
 {
     createSwDoc("tdf162220.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -433,10 +409,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf162725)
 {
     createSwDoc("tdf162725.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -534,10 +507,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf132599_always)
 
     createSwDoc("tdf132599_always.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -561,10 +531,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testTdf132599_frames_on_same_page_no_hyphe
 
     createSwDoc("tdf132599_frames_on_same_page_no_hyphenation.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -584,10 +551,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testTdf132599_frames_on_same_page_hyphenat
 
     createSwDoc("tdf132599_frames_on_same_page_hyphenation.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -608,10 +572,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testTdf132599_frames_on_right_pages_no_hyp
 
     createSwDoc("tdf132599_frames_on_right_pages_no_hyphenation.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -632,10 +593,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testTdf132599_frames_on_spread_hyphenation
 
     createSwDoc("tdf132599_frames_on_spread_hyphenation.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -652,10 +610,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, testTdf106234)
 {
     createSwDoc("tdf106234.fodt");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -1582,9 +1537,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testShapeAllowOverlap)
     xDrawPageSupplier->getDrawPage()->add(xShape);
 
     // Now verify that the rectangle of the anchored objects don't overlap.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
     SwFrame* pPageFrame = pLayout->GetLower();
     SwFrame* pBodyFrame = pPageFrame->GetLower();
@@ -1640,9 +1593,7 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter3, 
testShapeAllowOverlapWrap)
     xDrawPageSupplier->getDrawPage()->add(xShape);
 
     // Now verify that the rectangle of the anchored objects do overlap.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
     SwFrame* pPageFrame = pLayout->GetLower();
     SwFrame* pBodyFrame = pPageFrame->GetLower();
diff --git a/sw/qa/extras/layout/layout4.cxx b/sw/qa/extras/layout/layout4.cxx
index eabb5b63ff72..96b3ac3a4d73 100644
--- a/sw/qa/extras/layout/layout4.cxx
+++ b/sw/qa/extras/layout/layout4.cxx
@@ -484,10 +484,8 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, testTdf137185)
 {
     // First load the sample bugdoc
     createSwDoc("tdf137185.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
     // Get the doc shell
-    SwDoc* pDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDoc(getSwDoc());
 
     // Get the DrawObject from page
     auto pModel = pDoc->getIDocumentDrawModelAccess().GetDrawModel();
diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx 
b/sw/qa/extras/mailmerge/mailmerge.cxx
index 8bfa92b08931..a052cb859e14 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -52,8 +52,6 @@ DECLARE_FILE_MAILMERGE_TEST(testMissingDefaultLineColor, 
"missing-default-line-c
     uno::Reference<beans::XPropertySet> xPropertySet(getShape(5), 
uno::UNO_QUERY);
     // Lines do not have a line color.
     CPPUNIT_ASSERT( !xPropertySet->getPropertySetInfo()->hasPropertyByName( 
u"LineColor"_ustr ));
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
     uno::Reference< lang::XMultiServiceFactory > xFact( mxComponent, 
uno::UNO_QUERY );
     uno::Reference< beans::XPropertySet > xDefaults( xFact->createInstance( 
u"com.sun.star.drawing.Defaults"_ustr ), uno::UNO_QUERY );
     CPPUNIT_ASSERT( xDefaults.is());
@@ -196,9 +194,7 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf92623, "tdf92623.odt", 
"10-testing-addresses
     // copied marks were off by one
     executeMailMerge();
 
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    IDocumentMarkAccess const *pIDMA = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentMarkAccess();
+    IDocumentMarkAccess const *pIDMA = getSwDoc()->getIDocumentMarkAccess();
     // There is just one mark...
     CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pIDMA->getAllMarksCount());
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0), pIDMA->getBookmarksCount());
@@ -209,7 +205,7 @@ DECLARE_SHELL_MAILMERGE_TEST(testTdf92623, "tdf92623.odt", 
"10-testing-addresses
     SwNodeOffset src_pos = (*mark)->GetMarkPos().GetNodeIndex();
 
     // Get the size of the document in nodes
-    SwDoc *doc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc *doc = getSwDoc();
     SwNodeOffset size = doc->GetNodes().GetEndOfContent().GetIndex() - 
doc->GetNodes().GetEndOfExtras().GetIndex();
     CPPUNIT_ASSERT_EQUAL( SwNodeOffset(13), size );
     size -= SwNodeOffset(2); // For common start and end nodes
@@ -285,11 +281,8 @@ DECLARE_SHELL_MAILMERGE_TEST(test_sections_first_last, 
"sections_first_last.odt"
     // Originally we were losing the trailing section during merge
     executeMailMerge();
 
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-
     // Get the size of the document in nodes
-    SwDoc *pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc *pDoc = getSwDoc();
     SwNodeOffset nSize = pDoc->GetNodes().GetEndOfContent().GetIndex() - 
pDoc->GetNodes().GetEndOfExtras().GetIndex();
     nSize -= SwNodeOffset(2); // The common start and end node
     CPPUNIT_ASSERT_EQUAL( SwNodeOffset(13), nSize );
@@ -436,9 +429,7 @@ DECLARE_FILE_MAILMERGE_TEST(testEmptyValuesLegacyODT, 
"tdf35798-legacy.odt", "5-
     for (int doc = 0; doc < 5; ++doc)
     {
         loadMailMergeDocument(doc);
-        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         pDoc->RemoveInvisibleContent();
         CPPUNIT_ASSERT_EQUAL(1, getPages());
         for (int i = 0; i < 8; ++i)
@@ -460,9 +451,7 @@ DECLARE_FILE_MAILMERGE_TEST(testEmptyValuesNewODT, 
"tdf35798-new.odt", "5-with-b
     for (int doc = 0; doc < 5; ++doc)
     {
         loadMailMergeDocument(doc);
-        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         pDoc->RemoveInvisibleContent();
         CPPUNIT_ASSERT_EQUAL(1, getPages());
         int i;
@@ -488,9 +477,7 @@ DECLARE_FILE_MAILMERGE_TEST(testEmptyValuesLegacyFODT, 
"tdf35798-legacy.fodt", "
     for (int doc = 0; doc < 5; ++doc)
     {
         loadMailMergeDocument(doc);
-        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         pDoc->RemoveInvisibleContent();
         CPPUNIT_ASSERT_EQUAL(1, getPages());
         for (int i = 0; i < 8; ++i)
@@ -512,9 +499,7 @@ DECLARE_FILE_MAILMERGE_TEST(testEmptyValuesNewFODT, 
"tdf35798-new.fodt", "5-with
     for (int doc = 0; doc < 5; ++doc)
     {
         loadMailMergeDocument(doc);
-        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         pDoc->RemoveInvisibleContent();
         CPPUNIT_ASSERT_EQUAL(1, getPages());
         int i;
diff --git a/sw/qa/extras/odfexport/odfexport.cxx 
b/sw/qa/extras/odfexport/odfexport.cxx
index cbb9cec9e644..a50922006dbc 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -1234,7 +1234,7 @@ CPPUNIT_TEST_FIXTURE(Test, testProtectionKey)
 CPPUNIT_TEST_FIXTURE(Test, testTdf128188)
 {
     loadAndReload("footnote-collect-at-end-of-section.fodt");
-    SwDoc *const pDoc = 
dynamic_cast<SwXTextDocument&>(*mxComponent).GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
     SwFootnoteIdxs const& rFootnotes(pDoc->GetFootnoteIdxs());
     // Section1
@@ -1828,10 +1828,7 @@ CPPUNIT_TEST_FIXTURE(Test, testBtlrFrame)
         // Without the accompanying fix in place, this test would have failed, 
as the fly frame had
         // mbVertical==true, but mbVertLRBT==false, even if the writing 
direction in the doc model was
         // btlr.
-        SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         CPPUNIT_ASSERT(pDoc);
 
         SwRootFrame* pLayout = 
pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
diff --git a/sw/qa/extras/odfimport/odfimport.cxx 
b/sw/qa/extras/odfimport/odfimport.cxx
index 985e52e450e6..2eff835a0b1a 100644
--- a/sw/qa/extras/odfimport/odfimport.cxx
+++ b/sw/qa/extras/odfimport/odfimport.cxx
@@ -1142,9 +1142,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf152015)
 CPPUNIT_TEST_FIXTURE(Test, testTdf123829)
 {
     createSwDoc("tdf123829.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT_EQUAL_MESSAGE(
         "Compatibility: collapse cell paras should not be set", false,
         
pDoc->getIDocumentSettingAccess().get(DocumentSettingId::COLLAPSE_EMPTY_CELL_PARA));
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index f5968b005358..55c4be5a3140 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -370,9 +370,7 @@ DECLARE_OOXMLEXPORT_TEST(testTbrlTextbox, 
"tbrl-textbox.docx")
 
 DECLARE_OOXMLEXPORT_TEST(testBtlrShape, "btlr-textbox.docx")
 {
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     const auto& rFormats = *pDoc->GetSpzFrameFormats();
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFormats.size());
     CPPUNIT_ASSERT_EQUAL(o3tl::narrowing<sal_uInt16>(RES_DRAWFRMFMT), 
rFormats[0]->Which());
@@ -543,9 +541,7 @@ CPPUNIT_TEST_FIXTURE(Test, tdf123912_protectedForm)
 {
     loadAndReload("tdf123912_protectedForm.odt");
     CPPUNIT_ASSERT_EQUAL(1, getPages());
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Compatibility: Protect form", true,
                                  pDoc->getIDocumentSettingAccess().get( 
DocumentSettingId::PROTECT_FORM ) );
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
index 52d2e7c2b5e0..6d6462fe42b1 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
@@ -610,9 +610,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf95213, "tdf95213.docx")
 
 DECLARE_OOXMLEXPORT_TEST(testTdf97371, "tdf97371.docx")
 {
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     SdrObject* pShape = pPage->GetObj(0);
     SdrObject* pTextBox = pPage->GetObj(1);
@@ -962,9 +960,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf138093)
         }
         else
         {
-            SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-            CPPUNIT_ASSERT(pTextDoc);
-            SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+            SwDoc* pDoc = getSwDoc();
             IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), 
pMarkAccess->getAllMarksCount());
 
@@ -1062,9 +1058,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf131722)
         }
         else
         {
-            SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-            CPPUNIT_ASSERT(pTextDoc);
-            SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+            SwDoc* pDoc = getSwDoc();
             IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), 
pMarkAccess->getFieldmarksCount());
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx
index 6a5b8e6c0535..730edd6244d2 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport20.cxx
@@ -721,10 +721,8 @@ CPPUNIT_TEST_FIXTURE(Test, tdf122201_editUnprotectedText)
     loadAndReload("tdf122201_editUnprotectedText.odt");
     CPPUNIT_ASSERT_EQUAL(1, getPages());
     // get the document
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
 
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     // get two different nodes
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index ff6d169ef39d..097d68250802 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -67,9 +67,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo68787, "fdo68787.docx")
 
 DECLARE_OOXMLEXPORT_TEST(testTdf92470_footnoteRestart, 
"tdf92470_footnoteRestart.docx")
 {
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT( pTextDoc );
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT( pDoc );
     CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote doesn't restart every Page", 
FTNNUM_PAGE, pDoc->GetFootnoteInfo().m_eNum );
 
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
index 9c12e39f8ba1..8945a66534c3 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
@@ -1055,9 +1055,7 @@ CPPUNIT_TEST_FIXTURE(Test, testExportAdjustmentValue)
 DECLARE_OOXMLEXPORT_TEST(testTextVerticalAdjustment, 
"tdf36117_verticalAdjustment.docx")
 {
     //Preserve the page vertical alignment setting for .docx
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     SwPageDesc* pDesc = &pDoc->GetPageDesc( 0 );
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
index fe16a2ed47d2..284cf4a1dd94 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx
@@ -749,9 +749,7 @@ DECLARE_OOXMLEXPORT_TEST(testFdo53985, "fdo53985.docx")
     uno::Reference<container::XIndexAccess> 
xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTables->getCount()); // Only 4 tables 
were imported.
 
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT_MESSAGE("Compatibility: Protect form", 
pDoc->getIDocumentSettingAccess().get( DocumentSettingId::PROTECT_FORM ) );
 
     uno::Reference<text::XTextSectionsSupplier> 
xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
@@ -974,9 +972,7 @@ CPPUNIT_TEST_FIXTURE(Test, testN820509)
 {
     // M.d.yyyy date format was unhandled.
     createSwDoc("n820509.docx");
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
     CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount());
 
@@ -1022,8 +1018,7 @@ CPPUNIT_TEST_FIXTURE(Test, testN820509)
 
 DECLARE_OOXMLEXPORT_TEST(testTdf151548_activeContentDemo, 
"tdf151548_activeContentDemo.docm")
 {
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
     for(auto aIter = pMarkAccess->getFieldmarksBegin(); aIter != 
pMarkAccess->getFieldmarksEnd(); ++aIter)
     {
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index efce589aadb9..23502ecb5158 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -912,9 +912,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf55427_footnote2endnote)
         
xPageStyle.set(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Endnote"_ustr), 
uno::UNO_QUERY);
         CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote style is cyan3 color", 
Color(0x2BD0D2), getProperty<Color>(xPageStyle, u"CharColor"_ustr));
 
-        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         // The footnote numbering type of ARABIC will not transfer over when 
those footnotes are converted to endnotes.
         CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote numbering type", 
SVX_NUM_ARABIC, pDoc->GetFootnoteInfo().m_aFormat.GetNumberingType() );
         // The original document has a real endnote using ROMAN_LOWER 
numbering, so that setting MUST remain unchanged.
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index 3c21e915c4f1..82a90719b25d 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -589,9 +589,7 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtDateDuplicate)
         }
         else
         {
-            SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-            CPPUNIT_ASSERT(pTextDoc);
-            SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+            SwDoc* pDoc = getSwDoc();
             IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), 
pMarkAccess->getAllMarksCount());
 
@@ -801,9 +799,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateFieldInShape)
         }
         else
         {
-            SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-            CPPUNIT_ASSERT(pTextDoc);
-            SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+            SwDoc* pDoc = getSwDoc();
             IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), 
pMarkAccess->getAllMarksCount());
 
@@ -844,9 +840,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDateFieldAtEndOfParagraph)
         }
         else
         {
-            SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-            CPPUNIT_ASSERT(pTextDoc);
-            SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+            SwDoc* pDoc = getSwDoc();
             IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
             CPPUNIT_ASSERT_EQUAL(sal_Int32(2), 
pMarkAccess->getAllMarksCount());
 
@@ -871,9 +865,7 @@ CPPUNIT_TEST_FIXTURE(Test, testDropDownFieldEntryLimit)
         // In MSO, there is a limit of 25 for the items in a drop-down form 
field.
         // So we truncate the list of items to not exceed this limit.
 
-        SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
         CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
 
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
index dd8224482a66..eb3d55327f63 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport2.cxx
@@ -627,9 +627,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf112443)
     createSwDoc("tdf112443.docx");
     // the position of the flying text frame should be off page
     // 30624 below its anchor
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwRootFrame* pRootFrame = 
pDoc->getIDocumentLayoutAccess().GetCurrentLayout();
     const SwRect aPageRect = pRootFrame->getFrameArea();
     const SwRect aShapeRect(getShape(1)->getPosition().X, 
getShape(1)->getPosition().Y,
diff --git a/sw/qa/extras/rtfexport/rtfexport4.cxx 
b/sw/qa/extras/rtfexport/rtfexport4.cxx
index 1a695a62110d..6347c8845540 100644
--- a/sw/qa/extras/rtfexport/rtfexport4.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport4.cxx
@@ -157,9 +157,7 @@ CPPUNIT_TEST_FIXTURE(Test, testCjklist31)
 CPPUNIT_TEST_FIXTURE(Test, test148518)
 {
     auto verify = [this]() {
-        SwXTextDocument* const 
pTextDoc(dynamic_cast<SwXTextDocument*>(mxComponent.get()));
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* const pDoc(pTextDoc->GetDocShell()->GetDoc());
+        SwDoc* const pDoc(getSwDoc());
 
         CPPUNIT_ASSERT(pDoc->getIDocumentMarkAccess()->getFieldmarksBegin()
                        != pDoc->getIDocumentMarkAccess()->getFieldmarksEnd());
@@ -319,8 +317,7 @@ CPPUNIT_TEST_FIXTURE(Test, test150382)
 CPPUNIT_TEST_FIXTURE(Test, testAnchoredAtSamePosition)
 {
     auto verify = [this](bool bIsExport = false) {
-        SwXTextDocument* const pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        SwDoc* const pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* const pDoc = getSwDoc();
 
         CPPUNIT_ASSERT_EQUAL(u"foobar"_ustr, getParagraph(1)->getString());
 
diff --git a/sw/qa/extras/txtimport/txtimport.cxx 
b/sw/qa/extras/txtimport/txtimport.cxx
index 575b6a8d7dfd..ae38505e3cb5 100644
--- a/sw/qa/extras/txtimport/txtimport.cxx
+++ b/sw/qa/extras/txtimport/txtimport.cxx
@@ -53,9 +53,7 @@ public:
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf112191)
 {
     createSwDoc("bullets.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     // just the 5th paragraph - no bullet
@@ -83,9 +81,7 @@ CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf112191)
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf8withoutbom)
 {
     createSwDoc("UTF8WITHOUTBOM.txt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     uno::Reference<text::XTextRange> xPara(getParagraph(1));
@@ -96,9 +92,7 @@ CPPUNIT_TEST_FIXTURE(TxtImportTest, 
testTdf60145_utf8withoutbom)
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf8withbom)
 {
     createSwDoc("UTF8WITHBOM.txt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     uno::Reference<text::XTextRange> xPara(getParagraph(1));
@@ -109,9 +103,7 @@ CPPUNIT_TEST_FIXTURE(TxtImportTest, 
testTdf60145_utf8withbom)
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16lewithoutbom)
 {
     createSwDoc("UTF16LEWITHOUTBOM.txt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     uno::Reference<text::XTextRange> xPara(getParagraph(1));
@@ -122,9 +114,7 @@ CPPUNIT_TEST_FIXTURE(TxtImportTest, 
testTdf60145_utf16lewithoutbom)
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16lewithbom)
 {
     createSwDoc("UTF16LEWITHBOM.txt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     uno::Reference<text::XTextRange> xPara(getParagraph(1));
@@ -135,9 +125,7 @@ CPPUNIT_TEST_FIXTURE(TxtImportTest, 
testTdf60145_utf16lewithbom)
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf92161_gb18030)
 {
     createSwDoc("GB18030.txt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     uno::Reference<text::XTextRange> xPara(getParagraph(1));
@@ -148,9 +136,7 @@ CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf92161_gb18030)
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16bewithoutbom)
 {
     createSwDoc("UTF16BEWITHOUTBOM.txt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     uno::Reference<text::XTextRange> xPara(getParagraph(1));
@@ -161,9 +147,7 @@ CPPUNIT_TEST_FIXTURE(TxtImportTest, 
testTdf60145_utf16bewithoutbom)
 CPPUNIT_TEST_FIXTURE(TxtImportTest, testTdf60145_utf16bewithbom)
 {
     createSwDoc("UTF16BEWITHBOM.txt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     uno::Reference<text::XTextRange> xPara(getParagraph(1));
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 097aef653a88..f7b7bad4d86f 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -128,9 +128,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 
testTdfChangeNumberingListAutoFormat)
 
     // save it to DOCX
     saveAndReload(u"Office Open XML Text"_ustr);
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    pViewShell = getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     pViewShell->Reformat();
     pXmlDoc = parseLayoutDump();
     // this was 220
@@ -2293,8 +2291,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 
testTdf76817_round_trip)
     saveAndReload(u"Office Open XML Text"_ustr);
 
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     pViewShell->Reformat();
 
     CPPUNIT_ASSERT_EQUAL(u"Heading 2"_ustr,
diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index c71642a452ca..63bd58795c9a 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -3366,9 +3366,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testTdf145089_RedlineTableRowInsertionDOCX
 
     // save it to DOCX
     saveAndReload(u"Office Open XML Text"_ustr);
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     pViewShell->Reformat();
     pXmlDoc = parseLayoutDump();
 
@@ -3376,7 +3374,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testTdf145089_RedlineTableRowInsertionDOCX
     assertXPath(pXmlDoc, "//page[1]//body/tab/row", 3);
 
     // reject redlines
-    SwDoc* pDOCXDoc(pTextDoc->GetDocShell()->GetDoc());
+    SwDoc* pDOCXDoc(getSwDoc());
     SwEditShell* const pEditShell(pDOCXDoc->GetEditShell());
     CPPUNIT_ASSERT(pEditShell);
     CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(2), 
pEditShell->GetRedlineCount());
@@ -3553,9 +3551,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, testTdf145091)
 
     // save it to DOCX
     saveAndReload(u"Office Open XML Text"_ustr);
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+    SwViewShell* pViewShell = 
getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     pViewShell->Reformat();
     xmlDocUniquePtr pXmlDoc = parseLayoutDump();
 
diff --git a/sw/qa/extras/unowriter/unowriter.cxx 
b/sw/qa/extras/unowriter/unowriter.cxx
index 0179bc60273a..7cb47ce90cf0 100644
--- a/sw/qa/extras/unowriter/unowriter.cxx
+++ b/sw/qa/extras/unowriter/unowriter.cxx
@@ -1016,9 +1016,7 @@ CPPUNIT_TEST_FIXTURE(SwUnoWriter, testImageCommentAtChar)
 {
     // Load a document with an at-char image in it (and a comment on the 
image).
     createSwDoc("image-comment-at-char.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
 
     // Verify that we have an annotation mark (comment with a text range) in 
the document.
     // Without the accompanying fix in place, this test would have failed, as 
comments lost their
diff --git a/sw/qa/extras/ww8export/ww8export.cxx 
b/sw/qa/extras/ww8export/ww8export.cxx
index fec8ac56a609..8af912616b99 100644
--- a/sw/qa/extras/ww8export/ww8export.cxx
+++ b/sw/qa/extras/ww8export/ww8export.cxx
@@ -318,9 +318,7 @@ DECLARE_WW8EXPORT_TEST(testCp1000044, "cp1000044.doc")
     // It wasn't possible to fill out this form.
     CPPUNIT_ASSERT_EQUAL(false, bool(xStorable->isReadonly()));
 
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT_EQUAL( true, pDoc->getIDocumentSettingAccess().get( 
DocumentSettingId::PROTECT_FORM ) );
 
     uno::Sequence<beans::PropertyValue> aGrabBag = getProperty< 
uno::Sequence<beans::PropertyValue> >(mxComponent, u"InteropGrabBag"_ustr);
@@ -676,10 +674,7 @@ DECLARE_WW8EXPORT_TEST(testTdf128605, "tdf128605.doc")
 
 DECLARE_WW8EXPORT_TEST(testTdf112535, "tdf112535.doc")
 {
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc->GetSpzFrameFormats());
 
     auto& rFormats = *pDoc->GetSpzFrameFormats();
@@ -729,9 +724,7 @@ DECLARE_WW8EXPORT_TEST( testTdf105570, "tdf105570.doc" )
       * Table 2 has { 1, 1, 0 }
       * Table 3 has { 0, 1, 1 }
       ****/
-    SwXTextDocument* pTextDoc     = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc*           pDoc         = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc*           pDoc         = getSwDoc();
     SwWrtShell*      pWrtShell    = pDoc->GetDocShell()->GetWrtShell();
     SwShellCursor*   pShellCursor = pWrtShell->getShellCursor( false );
     SwNodeIndex      aIdx( pShellCursor->Start()->GetNode() );
@@ -779,9 +772,7 @@ DECLARE_WW8EXPORT_TEST(testTdf79639, "tdf79639.doc")
 DECLARE_WW8EXPORT_TEST(testTdf122425_2, "tdf122425_2.doc")
 {
     // This is for graphic objects in headers/footers
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false);
     // There is one fly frame in the document: the text box
     CPPUNIT_ASSERT_EQUAL(size_t(1), aPosFlyFrames.size());
@@ -1322,9 +1313,7 @@ DECLARE_WW8EXPORT_TEST(testCommentedTable, 
"commented-table.doc")
 DECLARE_WW8EXPORT_TEST(testTextVerticalAdjustment, 
"tdf36117_verticalAdjustment.doc")
 {
     //Preserve the page vertical alignment setting for .doc
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     SwPageDesc* pDesc = &pDoc->GetPageDesc( 0 );
@@ -1354,9 +1343,7 @@ DECLARE_WW8EXPORT_TEST(testTextVerticalAdjustment, 
"tdf36117_verticalAdjustment.
 
 DECLARE_WW8EXPORT_TEST(testRES_MIRROR_GRAPH_BOTH, 
"tdf56321_flipImage_both.doc")
 {
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     for (SwNodeOffset n(0); ; n++)
@@ -1581,9 +1568,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf99474)
 
 DECLARE_WW8EXPORT_TEST(testContinuousSectionsNoPageBreak, 
"continuous-sections.doc")
 {
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
 
     // Continuous section breaks should not add new pages
diff --git a/sw/qa/extras/ww8export/ww8export2.cxx 
b/sw/qa/extras/ww8export/ww8export2.cxx
index 510b522ee432..d27f28f43dca 100644
--- a/sw/qa/extras/ww8export/ww8export2.cxx
+++ b/sw/qa/extras/ww8export/ww8export2.cxx
@@ -150,9 +150,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf55427_footnote2endnote)
         
xPageStyle.set(getStyles(u"ParagraphStyles"_ustr)->getByName(u"Endnote"_ustr), 
uno::UNO_QUERY);
         CPPUNIT_ASSERT_EQUAL_MESSAGE( "Endnote style is cyan3 color", 
Color(0x2BD0D2), getProperty< Color >(xPageStyle, u"CharColor"_ustr));
 
-        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+        SwDoc* pDoc = getSwDoc();
         // The footnote numbering type of ARABIC will not transfer over when 
those footnotes are converted to endnotes.
         CPPUNIT_ASSERT_EQUAL_MESSAGE( "Footnote numbering type", 
SVX_NUM_ARABIC, pDoc->GetFootnoteInfo().m_aFormat.GetNumberingType() );
         // The original document has a real endnote using ROMAN_LOWER 
numbering, so that setting MUST remain unchanged.
@@ -537,9 +535,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf70838)
     loadAndReload("tdf70838.odt");
     CPPUNIT_ASSERT_EQUAL(1, getShapes());
     CPPUNIT_ASSERT_EQUAL(1, getPages());
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     tools::Rectangle aRect = pPage->GetObj(0)->GetSnapRect();
     CPPUNIT_ASSERT(aRect.GetHeight() > aRect.GetWidth());
@@ -550,9 +546,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf70838b_verticalRotation)
     loadAndReload("tdf70838b_verticalRotation.odt");
     CPPUNIT_ASSERT_EQUAL(3, getShapes());
     CPPUNIT_ASSERT_EQUAL(1, getPages());
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     tools::Rectangle aGroupShape = pPage->GetObj(0)->GetSnapRect();
     tools::Rectangle aLine = pPage->GetObj(2)->GetSnapRect();
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx 
b/sw/qa/extras/ww8export/ww8export3.cxx
index 880a3cb31701..445c9981ad1f 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -370,9 +370,7 @@ DECLARE_WW8EXPORT_TEST(testFdo53985, "fdo53985.doc")
     uno::Reference<container::XIndexAccess> 
xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(5), xTables->getCount()); // Only 4 tables 
were imported.
 
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     CPPUNIT_ASSERT_EQUAL_MESSAGE("Compatibility: Protect form", true, 
pDoc->getIDocumentSettingAccess().get( DocumentSettingId::PROTECT_FORM ) );
 
     uno::Reference<text::XTextSectionsSupplier> 
xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
diff --git a/sw/qa/extras/ww8export/ww8export4.cxx 
b/sw/qa/extras/ww8export/ww8export4.cxx
index 26f0fbc6343c..957941f388ab 100644
--- a/sw/qa/extras/ww8export/ww8export4.cxx
+++ b/sw/qa/extras/ww8export/ww8export4.cxx
@@ -108,8 +108,7 @@ DECLARE_WW8EXPORT_TEST(testTdf117994_CRnumformatting, 
"tdf117994_CRnumformatting
 
 DECLARE_WW8EXPORT_TEST(testTdf151548_formFieldMacros, 
"tdf151548_formFieldMacros.doc")
 {
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument 
*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
     for(auto aIter = pMarkAccess->getFieldmarksBegin(); aIter != 
pMarkAccess->getFieldmarksEnd(); ++aIter)
     {
@@ -494,9 +493,7 @@ CPPUNIT_TEST_FIXTURE(Test, testEmptyGroup)
 
     CPPUNIT_ASSERT_EQUAL(1, getPages());
     CPPUNIT_ASSERT_EQUAL(1, getShapes());
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SdrPage* pPage = 
pDoc->getIDocumentDrawModelAccess().GetDrawModel()->GetPage(0);
     SdrObject* pObject = pPage->GetObj(0);
 
diff --git a/sw/qa/extras/ww8import/ww8import.cxx 
b/sw/qa/extras/ww8import/ww8import.cxx
index 9537c99e3742..526ea4ecbc73 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -91,8 +91,7 @@ CPPUNIT_TEST_FIXTURE(Test, testImageLazyRead0size)
     createSwDoc("image-lazy-read-0size.doc");
     // Load a document with a single bitmap in it: it's declared as a WMF one, 
but actually a TGA
     // bitmap.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwNode* pNode = pDoc->GetNodes()[SwNodeOffset(6)];
     SwGrfNode* pGrfNode = pNode->GetGrfNode();
     CPPUNIT_ASSERT(pGrfNode);
@@ -107,10 +106,8 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf106799)
 {
     createSwDoc("tdf106799.doc");
     // Ensure that all text portions are calculated before testing.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
     SwViewShell* pViewShell
-        = 
pTextDoc->GetDocShell()->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
+        = getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
     CPPUNIT_ASSERT(pViewShell);
     pViewShell->Reformat();
 
@@ -131,9 +128,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf106799)
 CPPUNIT_TEST_FIXTURE(Test, testTdf121734)
 {
     createSwDoc("tdf121734.doc");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false);
     // There is only one fly frame in the document: the one with the imported 
floating table
     CPPUNIT_ASSERT_EQUAL(size_t(1), aPosFlyFrames.size());
@@ -177,8 +172,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf125281)
     // debug builds, reason is not known at the moment.
 
     // Load a .doc file which has an embedded .emf image.
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwNode* pNode = pDoc->GetNodes()[SwNodeOffset(6)];
     CPPUNIT_ASSERT(pNode->IsGrfNode());
     SwGrfNode* pGrfNode = pNode->GetGrfNode();
@@ -200,9 +194,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf122425_1)
     createSwDoc("tdf122425_1.doc");
     // This is for header text in case we use a hack for fixed-height headers
     // (see SwWW8ImplReader::Read_HdFtTextAsHackedFrame)
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     SwPosFlyFrames aPosFlyFrames = pDoc->GetAllFlyFormats(nullptr, false);
     // There are two fly frames in the document: for first page's header, and 
for other pages'
     CPPUNIT_ASSERT_EQUAL(size_t(2), aPosFlyFrames.size());
@@ -266,10 +258,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf142003)
 {
     createSwDoc("changes-in-footnote.doc");
 
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-
-    SwEditShell* const 
pEditShell(pTextDoc->GetDocShell()->GetDoc()->GetEditShell());
+    SwEditShell* const pEditShell(getSwDoc()->GetEditShell());
     CPPUNIT_ASSERT(pEditShell);
     pEditShell->AcceptRedline(0);
 
diff --git a/sw/qa/filter/html/html.cxx b/sw/qa/filter/html/html.cxx
index 40818a439926..e698dc23802d 100644
--- a/sw/qa/filter/html/html.cxx
+++ b/sw/qa/filter/html/html.cxx
@@ -66,8 +66,7 @@ CPPUNIT_TEST_FIXTURE(Test, testRelativeKeepAspect)
     createSwDoc("relative-keep-aspect.xhtml");
 
     // Then make sure that the aspect ratio of the image is kept:
-    auto pTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDocument->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     const auto& rFormats = *pDoc->GetSpzFrameFormats();
     const auto pFormat = rFormats[0];
     const SwFormatFrameSize& rSize = pFormat->GetFrameSize();
@@ -87,8 +86,7 @@ CPPUNIT_TEST_FIXTURE(Test, testRelativeKeepAspectImage)
     createSwDoc("relative-keep-aspect-image.xhtml");
 
     // Then make sure that the aspect ratio of the image is kept:
-    auto pTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    SwDoc* pDoc = pTextDocument->GetDocShell()->GetDoc();
+    SwDoc* pDoc = getSwDoc();
     const auto& rFormats = *pDoc->GetSpzFrameFormats();
     const auto pFormat = rFormats[0];
     const SwFormatFrameSize& rSize = pFormat->GetFrameSize();

Reply via email to