sw/qa/extras/uiwriter/uiwriter2.cxx |    4 
 sw/qa/extras/uiwriter/uiwriter4.cxx |    4 
 sw/qa/extras/uiwriter/uiwriter5.cxx |    9 -
 sw/qa/extras/uiwriter/uiwriter6.cxx |  195 +++++++++++++++---------------------
 sw/qa/inc/swmodeltestbase.hxx       |   12 ++
 sw/qa/unit/swmodeltestbase.cxx      |   18 +--
 6 files changed, 113 insertions(+), 129 deletions(-)

New commits:
commit 563e95965c1e377db8f24066627919654e21494c
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Aug 5 09:29:12 2022 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Aug 5 10:35:31 2022 +0200

    SwModelTestBase: helper methods to reduce copypaste
    
    Change-Id: I102bf95e68b628ed6a6d624e8f5d3e8b8d10cd84
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137841
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index dfecc0997d13..8a903e4988af 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -2664,9 +2664,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf122942)
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFormats.size());
 
     reload("writer8", "tdf122942.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
-    pDoc = pWrtShell->GetDoc();
+    pDoc = getSwDoc();
     const SwFrameFormats& rFormats2 = *pDoc->GetSpzFrameFormats();
     CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(2), rFormats2.size());
 
diff --git a/sw/qa/extras/uiwriter/uiwriter4.cxx 
b/sw/qa/extras/uiwriter/uiwriter4.cxx
index b92c2a2992c5..1ae2c41366b3 100644
--- a/sw/qa/extras/uiwriter/uiwriter4.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter4.cxx
@@ -601,9 +601,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest4, testTdf96479)
         // occurred because a broken bookmark was saved and loading silently
         // dropped the broken bookmark!
         reload("writer8", "testTdf96479.odt");
-        SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-        CPPUNIT_ASSERT(pTextDoc);
-        pDoc = pTextDoc->GetDocShell()->GetDoc();
+        pDoc = getSwDoc();
 
         // Lookup "replacement" bookmark
         IDocumentMarkAccess& rIDMA = *pDoc->getIDocumentMarkAccess();
diff --git a/sw/qa/extras/uiwriter/uiwriter5.cxx 
b/sw/qa/extras/uiwriter/uiwriter5.cxx
index 335ecaedd1c2..4f12060a4cf8 100644
--- a/sw/qa/extras/uiwriter/uiwriter5.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter5.cxx
@@ -1884,8 +1884,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testRedlineTableRowDeletionWithExport)
 
     // Save it and load it back.
     reload("writer8", "tdf60382_tracked_table_deletion.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    pDoc = pTextDoc->GetDocShell()->GetWrtShell()->GetDoc();
+    pDoc = getSwDoc();
 
     // accept the deletion of the content of the first cell
     SwEditShell* const pEditShell(pDoc->GetEditShell());
@@ -1940,8 +1939,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testRedlineTableRowDeletionWithDOCXExport)
     // Exporting change tracking of the row wasn't supported.
     // Also Manage Changes for the import.
     reload("Office Open XML Text", "tdf79069_tracked_table_deletion.docx");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    pDoc = pTextDoc->GetDocShell()->GetWrtShell()->GetDoc();
+    pDoc = getSwDoc();
 
     // accept the deletion of the content of the first cell
     SwEditShell* const pEditShell(pDoc->GetEditShell());
@@ -2160,8 +2158,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest5, 
testRedlineTableRowDeletionWithReject)
 
     // Save it and load it back.
     reload("writer8", "tdf60382_tracked_table_deletion.odt");
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    pDoc = pTextDoc->GetDocShell()->GetWrtShell()->GetDoc();
+    pDoc = getSwDoc();
 
     // reject the deletion of the content of the first cell
     // HasTextChangesOnly property of the table row will be true
diff --git a/sw/qa/extras/uiwriter/uiwriter6.cxx 
b/sw/qa/extras/uiwriter/uiwriter6.cxx
index 9bdc39536377..11129f9d1138 100644
--- a/sw/qa/extras/uiwriter/uiwriter6.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter6.cxx
@@ -718,10 +718,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf115013)
     }
     // Save it as DOCX & load it again
     reload("Office Open XML Text", "mm-field.docx");
-
-    auto pXTextDocument = dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
-    pDoc = pXTextDocument->GetDocShell()->GetDoc();
+    pDoc = getSwDoc();
     CPPUNIT_ASSERT(pDoc);
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
@@ -1346,8 +1343,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testRedlineAutoCorrect)
 
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
 
     // show tracked deletion with enabled change tracking
     RedlineFlags const nMode(pWrtShell->GetRedlineFlags() | RedlineFlags::On);
@@ -1358,7 +1354,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testRedlineAutoCorrect)
     CPPUNIT_ASSERT_MESSAGE("redlining should be on",
                            pDoc->getIDocumentRedlineAccess().IsRedlineOn());
 
-    emulateTyping(*pXTextDocument, u" ");
+    emulateTyping(rXTextDocument, u" ");
 
     // tdf#83419 This was "Ts " removing the deletion of "t" silently by 
sentence capitalization
     OUString sReplaced("ts ");
@@ -1370,7 +1366,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testRedlineAutoCorrect)
     // repeat it with not visible redlining
     dispatchCommand(mxComponent, ".uno:Undo", {});
 
-    emulateTyping(*pXTextDocument, u" ");
+    emulateTyping(rXTextDocument, u" ");
 
     sReplaced = "S ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
@@ -1387,25 +1383,25 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testRedlineAutoCorrect)
     dispatchCommand(mxComponent, ".uno:Undo", {});
     dispatchCommand(mxComponent, ".uno:Undo", {});
 
-    emulateTyping(*pXTextDocument, u"et ");
+    emulateTyping(rXTextDocument, u"et ");
     // This was "Ttest" removing the tracked deletion silently.
     // Don't replace, if a redline starts or ends within the text.
     sReplaced = "tset ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 
     // Otherwise replace it
-    emulateTyping(*pXTextDocument, u"tset ");
+    emulateTyping(rXTextDocument, u"tset ");
     sReplaced = "tset test ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 
     // Including capitalization
-    emulateTyping(*pXTextDocument, u"end. word ");
+    emulateTyping(rXTextDocument, u"end. word ");
     sReplaced = "tset test end. Word ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 
     // tracked deletions after the correction point doesn't affect autocorrect
     dispatchCommand(mxComponent, ".uno:GoToStartOfDoc", {});
-    emulateTyping(*pXTextDocument, u"a ");
+    emulateTyping(rXTextDocument, u"a ");
     sReplaced = "A tset test end. Word ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1415,8 +1411,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testRedlineAutoCorrect2)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "redline-autocorrect2.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
 
     dispatchCommand(mxComponent, ".uno:GoToEndOfDoc", {});
 
@@ -1426,7 +1421,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testRedlineAutoCorrect2)
     pWrtShell->SetRedlineFlags(nMode);
     CPPUNIT_ASSERT(nMode & RedlineFlags::ShowDelete);
 
-    emulateTyping(*pXTextDocument, u"... ");
+    emulateTyping(rXTextDocument, u"... ");
 
     // This was "LoremLorem,…," (duplicating the deleted comma, but without 
deletion)
     // Don't replace, if a redline starts or ends within the text.
@@ -1434,7 +1429,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testRedlineAutoCorrect2)
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 
     // Continue it:
-    emulateTyping(*pXTextDocument, u"Lorem,... ");
+    emulateTyping(rXTextDocument, u"Lorem,... ");
     sReplaced = u"Lorem,... Lorem,… ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1444,14 +1439,13 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testEmojiAutoCorrect)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "redline-autocorrect2.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
 
     // Emoji replacement (:snowman: -> ☃)
 
     // without change tracking
     CPPUNIT_ASSERT(!(pWrtShell->GetRedlineFlags() & RedlineFlags::On));
-    emulateTyping(*pXTextDocument, u":snowman:");
+    emulateTyping(rXTextDocument, u":snowman:");
     OUString sReplaced = u"☃Lorem,";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 
@@ -1462,7 +1456,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testEmojiAutoCorrect)
     CPPUNIT_ASSERT(nMode & RedlineFlags::On);
     CPPUNIT_ASSERT(nMode & RedlineFlags::ShowDelete);
 
-    emulateTyping(*pXTextDocument, u":snowman:");
+    emulateTyping(rXTextDocument, u":snowman:");
     sReplaced = u"☃☃Lorem,";
 
     // tdf#140674 This was ":snowman:" instead of autocorrect
@@ -1474,14 +1468,13 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf108423)
     SwDoc* pDoc = createSwDoc();
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // testing autocorrect of i' -> I' on start of first paragraph
-    emulateTyping(*pXTextDocument, u"i'");
+    emulateTyping(rXTextDocument, u"i'");
     // The word "i" should be capitalized due to autocorrect, followed by a 
typographical apostrophe
     OUString sIApostrophe(u"I\u2019");
     CPPUNIT_ASSERT_EQUAL(sIApostrophe, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u" i'");
+    emulateTyping(rXTextDocument, u" i'");
     OUString sText(sIApostrophe + u" " + sIApostrophe);
     CPPUNIT_ASSERT_EQUAL(sText, getParagraph(1)->getString());
 }
@@ -1491,10 +1484,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf106164)
     SwDoc* pDoc = createSwDoc();
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // testing autocorrect of we're -> We're on start of first paragraph
-    emulateTyping(*pXTextDocument, u"we're ");
+    emulateTyping(rXTextDocument, u"we're ");
     CPPUNIT_ASSERT_EQUAL(OUString(u"We\u2019re "), 
getParagraph(1)->getString());
 }
 
@@ -1503,18 +1495,17 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf54409)
     SwDoc* pDoc = createSwDoc();
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // testing autocorrect of "tset -> "test with typographical double 
quotation mark U+201C
-    emulateTyping(*pXTextDocument, u"\"test ");
+    emulateTyping(rXTextDocument, u"\"test ");
     OUString sReplaced(u"\u201Ctest ");
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // testing autocorrect of test" -> test" with typographical double 
quotation mark U+201D
-    emulateTyping(*pXTextDocument, u"and tset\" ");
+    emulateTyping(rXTextDocument, u"and tset\" ");
     OUString sReplaced2(sReplaced + u"and test\u201D ");
     CPPUNIT_ASSERT_EQUAL(sReplaced2, getParagraph(1)->getString());
     // testing autocorrect of "tset" -> "test" with typographical double 
quotation mark U+201C and U+201D
-    emulateTyping(*pXTextDocument, u"\"tset\" ");
+    emulateTyping(rXTextDocument, u"\"tset\" ");
     OUString sReplaced3(sReplaced2 + u"\u201Ctest\u201D ");
     CPPUNIT_ASSERT_EQUAL(sReplaced3, getParagraph(1)->getString());
 }
@@ -1524,14 +1515,13 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf38394)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf38394.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // testing autocorrect of French l'" -> l'« (instead of l'»)
-    emulateTyping(*pXTextDocument, u"l'\"");
+    emulateTyping(rXTextDocument, u"l'\"");
     OUString sReplaced(u"l\u2019« ");
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // tdf#132301 autocorrect of qu'«
-    emulateTyping(*pXTextDocument, u" qu'\"");
+    emulateTyping(rXTextDocument, u" qu'\"");
     sReplaced += u" qu\u2019« ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1541,10 +1531,9 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf59666)
     SwDoc* pDoc = createSwDoc();
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // testing missing autocorrect of single Greek letters
-    emulateTyping(*pXTextDocument, u"π ");
+    emulateTyping(rXTextDocument, u"π ");
     CPPUNIT_ASSERT_EQUAL(OUString(u"\u03C0 "), getParagraph(1)->getString());
 }
 
@@ -1553,56 +1542,55 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf133524)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf133524.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // 1. Testing autocorrect of >> and <<
     // Example: »word«
-    emulateTyping(*pXTextDocument, u">>");
+    emulateTyping(rXTextDocument, u">>");
     OUString sReplaced(u"»");
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // <<
-    emulateTyping(*pXTextDocument, u"word<<");
+    emulateTyping(rXTextDocument, u"word<<");
     sReplaced += u"word«";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // 2. Testing autocorrect of " to >> and << inside „...”
     // Example: „Sentence and »word«.”
     // opening primary level quote
-    emulateTyping(*pXTextDocument, u" \"");
+    emulateTyping(rXTextDocument, u" \"");
     sReplaced += u" „";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // opening second level quote
-    emulateTyping(*pXTextDocument, u"Sentence and \"");
+    emulateTyping(rXTextDocument, u"Sentence and \"");
     sReplaced += u"Sentence and »";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // closing second level quote
-    emulateTyping(*pXTextDocument, u"word\"");
+    emulateTyping(rXTextDocument, u"word\"");
     sReplaced += u"word«";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // closing primary level quote
-    emulateTyping(*pXTextDocument, u".\"");
+    emulateTyping(rXTextDocument, u".\"");
     sReplaced += u".”";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // tdf#134940 avoid premature replacement of "--" in "-->"
-    emulateTyping(*pXTextDocument, u" -->");
+    emulateTyping(rXTextDocument, u" -->");
     OUString sReplaced2(sReplaced + u" -->");
     // This was "–>" instead of "-->"
     CPPUNIT_ASSERT_EQUAL(sReplaced2, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u" ");
+    emulateTyping(rXTextDocument, u" ");
     sReplaced += u" → ";
     // This was "–>" instead of "→"
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 
     // tdf#83037
-    emulateTyping(*pXTextDocument, u"-> ");
+    emulateTyping(rXTextDocument, u"-> ");
     sReplaced += u"→ ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u"<- ");
+    emulateTyping(rXTextDocument, u"<- ");
     sReplaced += u"← ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u"<-- ");
+    emulateTyping(rXTextDocument, u"<-- ");
     sReplaced += u"← ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u"<--> ");
+    emulateTyping(rXTextDocument, u"<--> ");
     sReplaced += u"↔ ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1612,32 +1600,31 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testTdf133524_Romanian)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf133524_ro.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // 1. Testing autocorrect of " to << and >> inside „...”
     // Example: „Sentence and «word».”
     // opening primary level quote
-    emulateTyping(*pXTextDocument, u"\"");
+    emulateTyping(rXTextDocument, u"\"");
     OUString sReplaced(u"„");
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // opening second level quote
-    emulateTyping(*pXTextDocument, u"Sentence and \"");
+    emulateTyping(rXTextDocument, u"Sentence and \"");
     sReplaced += u"Sentence and «";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // closing second level quote
-    emulateTyping(*pXTextDocument, u"word\"");
+    emulateTyping(rXTextDocument, u"word\"");
     sReplaced += u"word»";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // closing primary level quote
-    emulateTyping(*pXTextDocument, u".\"");
+    emulateTyping(rXTextDocument, u".\"");
     sReplaced += u".”";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // 2. Testing recognition of closing double quotation mark ”
-    emulateTyping(*pXTextDocument, u" \"");
+    emulateTyping(rXTextDocument, u" \"");
     sReplaced += u" „";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // 3. Testing recognition of alternative closing double quotation mark “
-    emulateTyping(*pXTextDocument, u"Alternative.“ \"");
+    emulateTyping(rXTextDocument, u"Alternative.“ \"");
     sReplaced += u"Alternative.“ „";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1647,18 +1634,17 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf128860)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf128860.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // Second level ending quote: ‚word' -> ,word‘
-    emulateTyping(*pXTextDocument, u",word'");
+    emulateTyping(rXTextDocument, u",word'");
     OUString sReplaced(u",word\u2019");
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // Us apostrophe without preceding starting quote: word' -> word’
-    emulateTyping(*pXTextDocument, u" word'");
+    emulateTyping(rXTextDocument, u" word'");
     sReplaced += u" word\u2019";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // But only after letters: word.' -> word.‘
-    emulateTyping(*pXTextDocument, u" word.'");
+    emulateTyping(rXTextDocument, u" word.'");
     sReplaced += u" word.‘";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1676,18 +1662,17 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf123786)
 
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // Second level ending quote: „word' -> „word“
-    emulateTyping(*pXTextDocument, u"„слово'");
+    emulateTyping(rXTextDocument, u"„слово'");
     OUString sReplaced(u"„слово“");
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // Us apostrophe without preceding starting quote: word' -> word’
-    emulateTyping(*pXTextDocument, u" слово'");
+    emulateTyping(rXTextDocument, u" слово'");
     sReplaced += u" слово’";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // But only after letters: word.' -> word.“
-    emulateTyping(*pXTextDocument, u" слово.'");
+    emulateTyping(rXTextDocument, u" слово.'");
     sReplaced += u" слово.“";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1698,56 +1683,55 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf133589)
     SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "tdf133589.fodt");
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     // translitere words to Old Hungarian
-    emulateTyping(*pXTextDocument, u"székely ");
+    emulateTyping(rXTextDocument, u"székely ");
     OUString sReplaced(u"𐳥𐳋𐳓𐳉𐳗 ");
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // disambiguate consonants: asszony -> asz|szony
-    emulateTyping(*pXTextDocument, u"asszony ");
+    emulateTyping(rXTextDocument, u"asszony ");
     sReplaced += u"𐳀𐳥𐳥𐳛𐳚 ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // disambiguate consonants: kosszarv -> kos|szarv
     // (add explicit ZWSP temporarily for consonant disambiguation, because 
the requested
     // hu_HU hyphenation dictionary isn't installed on all testing platform)
     // pWrtShell->Insert(u"kosszarv");
-    emulateTyping(*pXTextDocument, u"kos\u200Bszarv ");
+    emulateTyping(rXTextDocument, u"kos\u200Bszarv ");
     sReplaced += u"𐳓𐳛𐳤𐳥𐳀𐳢𐳮 ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // transliterate numbers to Old Hungarian
-    emulateTyping(*pXTextDocument, u"2020 ");
+    emulateTyping(rXTextDocument, u"2020 ");
     sReplaced += u"𐳺𐳺𐳿𐳼𐳼 ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 
     // tdf#147546 transliterate punctuation marks
 
     // question mark
-    emulateTyping(*pXTextDocument, u"Kérdőjel?");
+    emulateTyping(rXTextDocument, u"Kérdőjel?");
     sReplaced += u"𐲓𐳋𐳢𐳇𐳟𐳒𐳉𐳖";
     OUString sReplaced2(sReplaced + "?");
     CPPUNIT_ASSERT_EQUAL(sReplaced2, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u" ");
+    emulateTyping(rXTextDocument, u" ");
     sReplaced += u"⸮ ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // comma
-    emulateTyping(*pXTextDocument, u"Vessző,");
+    emulateTyping(rXTextDocument, u"Vessző,");
     sReplaced += u"𐲮𐳉𐳥𐳥𐳟";
     sReplaced2 = sReplaced + ",";
     CPPUNIT_ASSERT_EQUAL(sReplaced2, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u" ");
+    emulateTyping(rXTextDocument, u" ");
     sReplaced += u"⹁ ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // semicolon
-    emulateTyping(*pXTextDocument, u"pontosvessző;");
+    emulateTyping(rXTextDocument, u"pontosvessző;");
     sReplaced += u"𐳠𐳛𐳙𐳦𐳛𐳤𐳮𐳉𐳥𐳥𐳟";
     sReplaced2 = sReplaced + ";";
     CPPUNIT_ASSERT_EQUAL(sReplaced2, getParagraph(1)->getString());
-    emulateTyping(*pXTextDocument, u" ");
+    emulateTyping(rXTextDocument, u" ");
     sReplaced += u"⁏ ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
     // quotation marks
-    emulateTyping(*pXTextDocument, u"„idézőjel” ");
+    emulateTyping(rXTextDocument, u"„idézőjel” ");
     sReplaced += u"⹂𐳐𐳇𐳋𐳯𐳟𐳒𐳉𐳖‟ ";
     CPPUNIT_ASSERT_EQUAL(sReplaced, getParagraph(1)->getString());
 }
@@ -1757,21 +1741,20 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testAutoCorr)
     SwDoc* pDoc = createSwDoc();
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
 
     //Normal AutoCorrect
-    emulateTyping(*pXTextDocument, u"tset ");
+    emulateTyping(rXTextDocument, u"tset ");
     CPPUNIT_ASSERT_EQUAL(OUString("Test "), getParagraph(1)->getString());
 
     //AutoCorrect with change style to bolt
-    emulateTyping(*pXTextDocument, u"Bolt ");
+    emulateTyping(rXTextDocument, u"Bolt ");
     const uno::Reference<text::XTextRange> xRun = getRun(getParagraph(1), 2);
     CPPUNIT_ASSERT_EQUAL(OUString("Bolt"), xRun->getString());
     CPPUNIT_ASSERT_EQUAL(OUString("Arial"), getProperty<OUString>(xRun, 
"CharFontName"));
 
     //AutoCorrect inserts Table with 2 rows and 3 columns
-    emulateTyping(*pXTextDocument, u"4xx ");
+    emulateTyping(rXTextDocument, u"4xx ");
     const uno::Reference<text::XTextTable> xTable(getParagraphOrTable(2), 
uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xTable->getRows()->getCount());
     CPPUNIT_ASSERT_EQUAL(sal_Int32(3), xTable->getColumns()->getCount());
@@ -1782,22 +1765,21 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf130274)
     SwDoc* const pDoc(createSwDoc());
     SwWrtShell* const pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
 
     CPPUNIT_ASSERT(!pWrtShell->GetLayout()->IsHideRedlines());
     CPPUNIT_ASSERT(
         
!IDocumentRedlineAccess::IsRedlineOn(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
 
     // "tset" may be replaced by the AutoCorrect in the test profile
-    emulateTyping(*pXTextDocument, u"tset");
+    emulateTyping(rXTextDocument, u"tset");
     // select from left to right
     pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 4, 
/*bBasicCall=*/false);
     pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/true, 4, 
/*bBasicCall=*/false);
 
     pWrtShell->SetRedlineFlags(pWrtShell->GetRedlineFlags() | 
RedlineFlags::On);
     // this would crash in AutoCorrect
-    emulateTyping(*pXTextDocument, u".");
+    emulateTyping(rXTextDocument, u".");
 
     
CPPUNIT_ASSERT(!pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty());
 }
@@ -1807,8 +1789,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf83260)
     SwDoc* const pDoc(createSwDoc(DATA_DIRECTORY, "tdf83260-1.odt"));
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
 
     // enabled but not shown
     CPPUNIT_ASSERT(pWrtShell->GetLayout()->IsHideRedlines());
@@ -1822,7 +1803,7 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf83260)
 
     // the document contains redlines that are combined with CompressRedlines()
     // if that happens during AutoCorrect then indexes in Undo are off -> crash
-    emulateTyping(*pXTextDocument, u"tset ");
+    emulateTyping(rXTextDocument, u"tset ");
     sw::UndoManager& rUndoManager = pDoc->GetUndoManager();
     auto const nActions(rUndoManager.GetUndoActionCount());
     for (auto i = nActions; 0 < i; --i)
@@ -1866,11 +1847,10 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf74363)
     SwDoc* pDoc = createSwDoc();
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
     //testing autocorrect of initial capitals on start of first paragraph
     //Inserting one all-lowercase word into the first paragraph
-    emulateTyping(*pXTextDocument, u"testing ");
+    emulateTyping(rXTextDocument, u"testing ");
     //The word should be capitalized due to autocorrect
     CPPUNIT_ASSERT_EQUAL(OUString("Testing "), getParagraph(1)->getString());
 }
@@ -1878,13 +1858,12 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf74363)
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf139922)
 {
     createSwDoc();
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
+    SwXTextDocument& rTextDoc = getSwXTextDocument();
 
-    pTextDoc->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
+    rTextDoc.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
     Scheduler::ProcessEventsToIdle();
 
-    emulateTyping(*pTextDoc, u"this is a SEntence. this is a SEntence.");
+    emulateTyping(rTextDoc, u"this is a SEntence. this is a SEntence.");
 
     // Without the fix in place, this test would have failed with
     // - Expected: This is a Sentence. This is a Sentence.
@@ -1929,14 +1908,13 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, testTdf129270)
     CPPUNIT_ASSERT(pDoc);
     SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
     CPPUNIT_ASSERT(pWrtShell);
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
 
     // Go to document end
     pWrtShell->SttEndDoc(/*bStt=*/false);
 
     // Press enter
-    pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
+    rXTextDocument.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RETURN);
     Scheduler::ProcessEventsToIdle();
 
     // Numbering for previous outline should remain the same "2"
@@ -2042,9 +2020,8 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest6, 
testNestedGroupTextBoxCopyCrash)
     dispatchCommand(mxComponent, ".uno:Copy", {});
     Scheduler::ProcessEventsToIdle();
     // This crashed here before the fix.
-    SwXTextDocument* pXTextDocument = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pXTextDocument);
-    pXTextDocument->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_ESCAPE);
+    SwXTextDocument& rXTextDocument = getSwXTextDocument();
+    rXTextDocument.postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_ESCAPE);
     Scheduler::ProcessEventsToIdle();
     dispatchCommand(mxComponent, ".uno:Paste", {});
     Scheduler::ProcessEventsToIdle();
diff --git a/sw/qa/inc/swmodeltestbase.hxx b/sw/qa/inc/swmodeltestbase.hxx
index 15980cdfda84..5b3cde89314f 100644
--- a/sw/qa/inc/swmodeltestbase.hxx
+++ b/sw/qa/inc/swmodeltestbase.hxx
@@ -83,6 +83,8 @@
     CPPUNIT_TEST_SUITE_REGISTRATION(TestName); \
     void TestName::verify()
 
+class SwXTextDocument;
+
 /// Base class for filter tests loading or roundtripping a document, then 
asserting the document model.
 class SWQAHELPER_DLLPUBLIC SwModelTestBase : public test::BootstrapFixture, 
public unotest::MacrosTest, public XmlTestTools
 {
@@ -382,6 +384,16 @@ protected:
      */
     SwDoc* createSwWebDoc(
         std::u16string_view rDataDirectory = std::u16string_view(), const 
char* pName = nullptr);
+
+    /**
+     * Gets SwXTextDocument from loaded component
+     */
+    SwXTextDocument& getSwXTextDocument();
+
+    /**
+     * Gets SwDoc from loaded component
+     */
+    SwDoc* getSwDoc();
 };
 
 /**
diff --git a/sw/qa/unit/swmodeltestbase.cxx b/sw/qa/unit/swmodeltestbase.cxx
index e5c6e2cbde15..cdbdf6c391f5 100644
--- a/sw/qa/unit/swmodeltestbase.cxx
+++ b/sw/qa/unit/swmodeltestbase.cxx
@@ -166,10 +166,7 @@ void SwModelTestBase::discardDumpedLayout()
 
 void SwModelTestBase::calcLayout()
 {
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
-    pDoc->getIDocumentLayoutAccess().GetCurrentViewShell()->CalcLayout();
+    getSwDoc()->getIDocumentLayoutAccess().GetCurrentViewShell()->CalcLayout();
 }
 
 int SwModelTestBase::getLength() const { return getBodyText().getLength(); }
@@ -730,9 +727,7 @@ SwDoc* SwModelTestBase::createSwDoc(std::u16string_view 
rDataDirectory, const ch
     else
         load(rDataDirectory, pName);
 
-    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    return pTextDoc->GetDocShell()->GetDoc();
+    return getSwDoc();
 }
 
 SwDoc* SwModelTestBase::createSwWebDoc(std::u16string_view rDataDirectory, 
const char* pName)
@@ -742,9 +737,16 @@ SwDoc* SwModelTestBase::createSwWebDoc(std::u16string_view 
rDataDirectory, const
     else
         load_web(rDataDirectory, pName);
 
+    return getSwDoc();
+}
+
+SwXTextDocument& SwModelTestBase::getSwXTextDocument()
+{
     SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
     CPPUNIT_ASSERT(pTextDoc);
-    return pTextDoc->GetDocShell()->GetDoc();
+    return *pTextDoc;
 }
 
+SwDoc* SwModelTestBase::getSwDoc() { return 
getSwXTextDocument().GetDocShell()->GetDoc(); }
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to